Contents

One of the main characteristics of the Stammler_2016_16S_spikein dataset is the presence of spike-in bacteria with a known fixed amount of bacterial cells. These known loads of bacteria can be used to recalibrate the raw counts of the matrix and obtain recalibrated absolute counts. In this vignette, we provide an example of how to recalibrate the counts of the count matrix based on the read counts of Salinibacter ruber. This procedure is referred to as Spike-in-based calibration to total microbial load (SCML) in Sammler et al., 2016.

library(MicrobiomeBenchmarkData)
library(dplyr)
library(ggplot2)
library(tidyr)

0.1 Import data

tse <- getBenchmarkData('Stammler_2016_16S_spikein', dryrun = FALSE)[[1]]
#> Warning: No taxonomy_tree available for Stammler_2016_16S_spikein.
#> Finished Stammler_2016_16S_spikein.
counts <- assay(tse)

0.2 Ids of the spike-in bacteria

Identifiers of the spiked-in bacteria have the suffix ‘XXXX’.

Bacteria ID Load
Salinibacter ruber AF323500XXXX 3.0 x 108
Rhizobium radiobacter AB247615XXXX 5.0 x 108
Alicyclobacillus acidiphilus AB076660XXXX 1.0 x 108

0.3 Recalibrate based on Salinibacter ruber abundance.

This recalibration is based on the original article. The only difference is that the numbers have been rounded up to obtain counts.

## AF323500XXXX is the unique OTU corresponding to S. ruber
s_ruber <- counts['AF323500XXXX', ]
size_factor <- s_ruber/mean(s_ruber)

SCML_data <- counts 
for(i in seq(ncol(SCML_data))){
    SCML_data[,i] <- round(SCML_data[,i] / size_factor[i])
}

Brief comparison of counts


no_cal <- counts |> 
    colSums() |> 
    as.data.frame() |> 
    tibble::rownames_to_column(var = 'sample_id') |> 
    magrittr::set_colnames(c('sample_id', 'colSum')) |> 
    mutate(calibrated = 'no') |> 
    as_tibble()

cal <-  SCML_data |> 
    colSums() |> 
    as.data.frame() |> 
    tibble::rownames_to_column(var = 'sample_id') |> 
    magrittr::set_colnames(c('sample_id', 'colSum')) |> 
    mutate(calibrated = 'yes') |> 
    as_tibble()

data <- bind_rows(no_cal, cal)

data |> 
    ggplot(aes(sample_id, colSum)) + 
    geom_col(aes(fill = calibrated), position = 'dodge') +
    theme_bw() +
    theme(axis.text.x = element_text(angle = 90, hjust = 1))

The counts matrix can be replaced in the original tse in order to preserve the same metadata.

assay(tse) <- SCML_data
tse
#> class: TreeSummarizedExperiment 
#> dim: 4036 17 
#> metadata(0):
#> assays(1): counts
#> rownames(4036): GQ448052 EU458484 ... DQ795992 GQ492848
#> rowData names(1): taxonomy
#> colnames(17): MID26 MID27 ... MID42 MID43
#> colData names(12): dataset subject_id ... country description
#> reducedDimNames(0):
#> mainExpName: NULL
#> altExpNames(0):
#> rowLinks: NULL
#> rowTree: NULL
#> colLinks: NULL
#> colTree: NULL

1 Session information

sessionInfo()
#> R version 4.2.1 (2022-06-23)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.5 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB              LC_COLLATE=C              
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] tidyr_1.2.1                    ggplot2_3.3.6                 
#>  [3] dplyr_1.0.10                   purrr_0.3.5                   
#>  [5] MicrobiomeBenchmarkData_1.0.0  TreeSummarizedExperiment_2.6.0
#>  [7] Biostrings_2.66.0              XVector_0.38.0                
#>  [9] SingleCellExperiment_1.20.0    SummarizedExperiment_1.28.0   
#> [11] Biobase_2.58.0                 GenomicRanges_1.50.0          
#> [13] GenomeInfoDb_1.34.0            IRanges_2.32.0                
#> [15] S4Vectors_0.36.0               BiocGenerics_0.44.0           
#> [17] MatrixGenerics_1.10.0          matrixStats_0.62.0            
#> [19] BiocStyle_2.26.0              
#> 
#> loaded via a namespace (and not attached):
#>  [1] httr_1.4.4             sass_0.4.2             bit64_4.0.5           
#>  [4] jsonlite_1.8.3         bslib_0.4.0            assertthat_0.2.1      
#>  [7] highr_0.9              BiocManager_1.30.19    BiocFileCache_2.6.0   
#> [10] yulab.utils_0.0.5      blob_1.2.3             GenomeInfoDbData_1.2.9
#> [13] yaml_2.3.6             pillar_1.8.1           RSQLite_2.2.18        
#> [16] lattice_0.20-45        glue_1.6.2             digest_0.6.30         
#> [19] colorspace_2.0-3       htmltools_0.5.3        Matrix_1.5-1          
#> [22] pkgconfig_2.0.3        magick_2.7.3           bookdown_0.29         
#> [25] zlibbioc_1.44.0        scales_1.2.1           tidytree_0.4.1        
#> [28] BiocParallel_1.32.0    tibble_3.1.8           farver_2.1.1          
#> [31] generics_0.1.3         withr_2.5.0            cachem_1.0.6          
#> [34] lazyeval_0.2.2         cli_3.4.1              magrittr_2.0.3        
#> [37] crayon_1.5.2           memoise_2.0.1          evaluate_0.17         
#> [40] fansi_1.0.3            nlme_3.1-160           tools_4.2.1           
#> [43] lifecycle_1.0.3        stringr_1.4.1          munsell_0.5.0         
#> [46] DelayedArray_0.24.0    compiler_4.2.1         jquerylib_0.1.4       
#> [49] rlang_1.0.6            grid_4.2.1             RCurl_1.98-1.9        
#> [52] rappdirs_0.3.3         labeling_0.4.2         bitops_1.0-7          
#> [55] rmarkdown_2.17         gtable_0.3.1           codetools_0.2-18      
#> [58] DBI_1.1.3              curl_4.3.3             R6_2.5.1              
#> [61] knitr_1.40             fastmap_1.1.0          bit_4.0.4             
#> [64] utf8_1.2.2             filelock_1.0.2         treeio_1.22.0         
#> [67] ape_5.6-2              stringi_1.7.8          parallel_4.2.1        
#> [70] Rcpp_1.0.9             vctrs_0.5.0            dbplyr_2.2.1          
#> [73] tidyselect_1.2.0       xfun_0.34