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.
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 |
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
sessionInfo()
#> R version 4.4.2 (2024-10-31)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.1 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so; LAPACK version 3.12.0
#>
#> locale:
#> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
#> [3] LC_TIME=en_US.UTF-8 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: Etc/UTC
#> tzcode source: system (glibc)
#>
#> attached base packages:
#> [1] stats4 stats graphics grDevices utils datasets methods
#> [8] base
#>
#> other attached packages:
#> [1] tidyr_1.3.1 ggplot2_3.5.1
#> [3] dplyr_1.1.4 purrr_1.0.2
#> [5] MicrobiomeBenchmarkData_1.9.0 TreeSummarizedExperiment_2.15.0
#> [7] Biostrings_2.75.1 XVector_0.47.0
#> [9] SingleCellExperiment_1.29.1 SummarizedExperiment_1.37.0
#> [11] Biobase_2.67.0 GenomicRanges_1.59.0
#> [13] GenomeInfoDb_1.43.1 IRanges_2.41.1
#> [15] S4Vectors_0.45.2 BiocGenerics_0.53.3
#> [17] generics_0.1.3 MatrixGenerics_1.19.0
#> [19] matrixStats_1.4.1 BiocStyle_2.35.0
#>
#> loaded via a namespace (and not attached):
#> [1] tidyselect_1.2.1 farver_2.1.2 blob_1.2.4
#> [4] filelock_1.0.3 fastmap_1.2.0 lazyeval_0.2.2
#> [7] BiocFileCache_2.15.0 digest_0.6.37 lifecycle_1.0.4
#> [10] tidytree_0.4.6 RSQLite_2.3.8 magrittr_2.0.3
#> [13] compiler_4.4.2 rlang_1.1.4 sass_0.4.9
#> [16] tools_4.4.2 utf8_1.2.4 yaml_2.3.10
#> [19] knitr_1.49 labeling_0.4.3 S4Arrays_1.7.1
#> [22] bit_4.5.0 curl_6.0.1 DelayedArray_0.33.2
#> [25] abind_1.4-8 BiocParallel_1.41.0 withr_3.0.2
#> [28] sys_3.4.3 grid_4.4.2 fansi_1.0.6
#> [31] colorspace_2.1-1 scales_1.3.0 cli_3.6.3
#> [34] rmarkdown_2.29 crayon_1.5.3 treeio_1.31.0
#> [37] httr_1.4.7 DBI_1.2.3 ape_5.8
#> [40] cachem_1.1.0 zlibbioc_1.52.0 parallel_4.4.2
#> [43] BiocManager_1.30.25 vctrs_0.6.5 yulab.utils_0.1.8
#> [46] Matrix_1.7-1 jsonlite_1.8.9 bit64_4.5.2
#> [49] maketools_1.3.1 jquerylib_0.1.4 glue_1.8.0
#> [52] codetools_0.2-20 gtable_0.3.6 UCSC.utils_1.3.0
#> [55] munsell_0.5.1 tibble_3.2.1 pillar_1.9.0
#> [58] htmltools_0.5.8.1 GenomeInfoDbData_1.2.13 R6_2.5.1
#> [61] dbplyr_2.5.0 evaluate_1.0.1 lattice_0.22-6
#> [64] memoise_2.0.1 bslib_0.8.0 Rcpp_1.0.13-1
#> [67] SparseArray_1.7.2 nlme_3.1-166 xfun_0.49
#> [70] fs_1.6.5 buildtools_1.0.0 pkgconfig_2.0.3