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.3.0 RC (2023-04-13 r84269)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 22.04.2 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.17-bioc/R/lib/libRblas.so 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
#> 
#> 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       
#> 
#> time zone: America/New_York
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] tidyr_1.3.0                    ggplot2_3.4.2                 
#>  [3] dplyr_1.1.2                    purrr_1.0.1                   
#>  [5] MicrobiomeBenchmarkData_1.2.0  TreeSummarizedExperiment_2.8.0
#>  [7] Biostrings_2.68.0              XVector_0.40.0                
#>  [9] SingleCellExperiment_1.22.0    SummarizedExperiment_1.30.0   
#> [11] Biobase_2.60.0                 GenomicRanges_1.52.0          
#> [13] GenomeInfoDb_1.36.0            IRanges_2.34.0                
#> [15] S4Vectors_0.38.0               BiocGenerics_0.46.0           
#> [17] MatrixGenerics_1.12.0          matrixStats_0.63.0            
#> [19] BiocStyle_2.28.0              
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.2.0        farver_2.1.1            blob_1.2.4             
#>  [4] filelock_1.0.2          bitops_1.0-7            fastmap_1.1.1          
#>  [7] lazyeval_0.2.2          RCurl_1.98-1.12         BiocFileCache_2.8.0    
#> [10] digest_0.6.31           lifecycle_1.0.3         tidytree_0.4.2         
#> [13] RSQLite_2.3.1           magrittr_2.0.3          compiler_4.3.0         
#> [16] rlang_1.1.0             sass_0.4.5              tools_4.3.0            
#> [19] utf8_1.2.3              yaml_2.3.7              knitr_1.42             
#> [22] labeling_0.4.2          bit_4.0.5               curl_5.0.0             
#> [25] DelayedArray_0.26.0     BiocParallel_1.34.0     withr_2.5.0            
#> [28] grid_4.3.0              fansi_1.0.4             colorspace_2.1-0       
#> [31] scales_1.2.1            cli_3.6.1               rmarkdown_2.21         
#> [34] crayon_1.5.2            treeio_1.24.0           generics_0.1.3         
#> [37] httr_1.4.5              DBI_1.1.3               ape_5.7-1              
#> [40] cachem_1.0.7            zlibbioc_1.46.0         parallel_4.3.0         
#> [43] BiocManager_1.30.20     yulab.utils_0.0.6       vctrs_0.6.2            
#> [46] Matrix_1.5-4            jsonlite_1.8.4          bookdown_0.33          
#> [49] bit64_4.0.5             magick_2.7.4            jquerylib_0.1.4        
#> [52] glue_1.6.2              codetools_0.2-19        gtable_0.3.3           
#> [55] munsell_0.5.0           tibble_3.2.1            pillar_1.9.0           
#> [58] htmltools_0.5.5         GenomeInfoDbData_1.2.10 R6_2.5.1               
#> [61] dbplyr_2.3.2            evaluate_0.20           lattice_0.21-8         
#> [64] highr_0.10              memoise_2.0.1           bslib_0.4.2            
#> [67] Rcpp_1.0.10             nlme_3.1-162            xfun_0.39              
#> [70] pkgconfig_2.0.3