SIAMCAT: Statistical Inference of Associations between Microbial Communities And host phenoTypes (original) (raw)
Contents
- 1 About This Vignette
- 2 Introduction
- 3 Quick Start
- 4 Association Testing
- 5 Confounder Testing
- 6 Model Building
- 7 Model Evaluation and Interpretation
- 8 Session Info
About This Vignette
This vignette aims to be a short tutorial for the main functionalities ofSIAMCAT
. Examples of additional workflows or more detailed tutorials can be found in other vignettes (see theBioConductor page).
SIAMCAT
is part of the suite of computational microbiome analysis tools hosted at EMBL by the groups ofPeer Bork andGeorg Zeller. Find out more at EMBL-microbiome tools.
Introduction
Associations between microbiome and host phenotypes are ideally described by quantitative models able to predict host status from microbiome composition.SIAMCAT
can do so for data from hundreds of thousands of microbial taxa, gene families, or metabolic pathways over hundreds of samples. SIAMCAT
produces graphical output for convenient assessment of the quality of the input data and statistical associations, for model diagnostics and inference revealing the most predictive microbial biomarkers.
Quick Start
For this vignette, we use an example dataset included in the SIAMCAT
package. As example dataset we use the data from the publication ofZeller et al, which demonstrated the potential of microbial species in fecal samples to distinguish patients with colorectal cancer (CRC) from healthy controls.
library("SIAMCAT")
data("feat_crc_zeller", package="SIAMCAT")
data("meta_crc_zeller", package="SIAMCAT")
First, SIAMCAT
needs a feature matrix (can be either a matrix
, adata.frame
, or a phyloseq-otu_table
), which contains values of different features (in rows) for different samples (in columns). For example, the feature matrix included here contains relative abundances for bacterial species calculated with the mOTU profiler for 141 samples:
feat.crc.zeller[1:3, 1:3]
## CCIS27304052ST-3-0 CCIS15794887ST-4-0
## UNMAPPED 0.589839 0.7142157
## Methanoculleus marisnigri [h:1] 0.000000 0.0000000
## Methanococcoides burtonii [h:10] 0.000000 0.0000000
## CCIS74726977ST-3-0
## UNMAPPED 0.7818674
## Methanoculleus marisnigri [h:1] 0.0000000
## Methanococcoides burtonii [h:10] 0.0000000
dim(feat.crc.zeller)
## [1] 1754 141
Please note that
SIAMCAT
is supposed to work with relative abundances. Other types of data (e.g. counts) will also work, but not all functions of the package will result in meaningful outputs.
Secondly, we also have metadata about the samples in another data.frame
:
head(meta.crc.zeller)
## Age BMI Gender AJCC_stage FOBT Group
## CCIS27304052ST-3-0 52 20 F -1 Negative CTR
## CCIS15794887ST-4-0 37 18 F -1 Negative CTR
## CCIS74726977ST-3-0 66 24 M -1 Negative CTR
## CCIS16561622ST-4-0 54 26 M -1 Negative CTR
## CCIS79210440ST-3-0 65 30 M -1 Positive CTR
## CCIS82507866ST-3-0 57 24 M -1 Negative CTR
In order to tell SIAMCAT
, which samples are cancer cases and which are healthy controls, we can construct a label object from the Group
column in the metadata.
label.crc.zeller <- create.label(meta=meta.crc.zeller,
label='Group', case='CRC')
## Label used as case:
## CRC
## Label used as control:
## CTR
## + finished create.label.from.metadata in 0.001 s
Now we have all the ingredients to create a SIAMCAT
object. Please have a look at the vignette about input formats for more information about supported formats and other ways to create a SIAMCAT
object.
sc.obj <- siamcat(feat=feat.crc.zeller,
label=label.crc.zeller,
meta=meta.crc.zeller)
## + starting validate.data
## +++ checking overlap between labels and features
## + Keeping labels of 141 sample(s).
## +++ checking sample number per class
## +++ checking overlap between samples and metadata
## + finished validate.data in 0.028 s
A few information about the SIAMCAT
object can be accessed with the show
function from phyloseq
(SIAMCAT
builds on the phyloseq
data structure):
show(sc.obj)
## siamcat-class object
## label() Label object: 88 CTR and 53 CRC samples
##
## contains phyloseq-class experiment-level object @phyloseq:
## phyloseq@otu_table() OTU Table: [ 1754 taxa and 141 samples ]
## phyloseq@sam_data() Sample Data: [ 141 samples by 6 sample variables ]
Since we have quite a lot of microbial species in the dataset at the moment, we can perform unsupervised feature selection using the function filter.features
.
sc.obj <- filter.features(sc.obj,
filter.method = 'abundance',
cutoff = 0.001)
## Features successfully filtered
Association Testing
Associations between microbial species and the label can be tested with the check.associations
function. The function computes for each species the significance using a non-parametric Wilcoxon test and different effect sizes for the association (e.g. AUC or fold change).
sc.obj <- check.associations(sc.obj, log.n0 = 1e-06, alpha = 0.05)
association.plot(sc.obj, sort.by = 'fc',
panels = c('fc', 'prevalence', 'auroc'))
The function produces a pdf file as output, since the plot is optimized for a landscape DIN-A4 layout, but can also used to plot on an active graphic device, e.g. in RStudio. The resulting plot then looks like that:
Confounder Testing
As many biological and technical factors beyond the primary phenotype of interest can influence microbiome composition, simple association studies may suffer confounding by other variables, which can lead to spurious results. The check.confounders
function provides the option to test the associated metadata variables for potential confounding influence. No information is stored in the SIAMCAT
object, but the different analyses are visualized and saved to a combined pdf file for qualitative interpretation.
check.confounders(sc.obj, fn.plot = 'confounder_plots.pdf',
meta.in = NULL, feature.type = 'filtered')
The conditional entropy check primarily serves to remove nonsensical variables from subsequent checks. Conditional entropy quantifies the unique information contained in one variable (row) respective to another (column). Identical variables and derived variables which share the exact same information will have a value of zero. In this example, the label was derived from the Group variable which was determined from AJCC stage, so both are excluded.
Conditional Entropy Plot
To better quantify potential confounding effects of metadata variables on individual microbial features, check.confounder
plots the variance explained by the label in comparison with the variance explained by the metadata variable for each individual feature. Variables with many features in the upper left corner might be confounding the label associations.
Variance Explained Plot
Model Building
One strength of SIAMCAT
is the versatile but easy-to-use interface for the construction of machine learning models on the basis of microbial species.SIAMCAT
contains functions for data normalization, splitting the data into cross-validation folds, training the model, and making predictions based on cross-validation instances and the trained models.
Data Normalization
Data normalization is performed with the normalize.features
function. Here, we use the log.unit
method, but several other methods and customization options are available (please check the documentation).
sc.obj <- normalize.features(sc.obj, norm.method = "log.unit",
norm.param = list(log.n0 = 1e-06, n.p = 2,norm.margin = 1))
## Features normalized successfully.
Prepare Cross-Validation
Preparation of the cross-validation fold is a crucial step in machine learning.SIAMCAT
greatly simplifies the set-up of cross-validation schemes, including stratification of samples or keeping samples inseperable based on metadata. For this small example, we choose a twice-repeated 5-fold cross-validation scheme. The data-split will be saved in the data_split
slot of the SIAMCAT
object.
sc.obj <- create.data.split(sc.obj, num.folds = 5, num.resample = 2)
## Features splitted for cross-validation successfully.
Model Training
The actual model training is performed using the function train.model
. Again, multiple options for customization are available, ranging from the machine learning method to the measure for model selection or customizable parameter set for hyperparameter tuning.
sc.obj <- train.model(sc.obj, method = "lasso")
The models are saved in the model_list
slot of the SIAMCAT
object. The model building is performed using the mlr
R package. All models can easily be accessed.
# get information about the model type
model_type(sc.obj)
## [1] "lasso"
# access the models
models <- models(sc.obj)
models[[1]]$model
## <LearnerClassifCVGlmnet:classif.cv_glmnet>: GLM with Elastic Net Regularization
## * Model: cv.glmnet
## * Parameters: alpha=1, use_pred_offset=TRUE, s=0.02451
## * Packages: mlr3, mlr3learners, glmnet
## * Predict Types: response, [prob]
## * Feature Types: logical, integer, numeric
## * Properties: multiclass, offset, selected_features, twoclass, weights
Make Predictions
Using the data-split and the models trained in previous step, we can use the function make.predictions
in order to apply the models on the test instances in the data-split. The predictions will be saved in the pred_matrix
slot of the SIAMCAT
object.
sc.obj <- make.predictions(sc.obj)
pred_matrix <- pred_matrix(sc.obj)
head(pred_matrix)
## CV_rep1 CV_rep2
## CCIS27304052ST-3-0 0.1540914 0.2314017
## CCIS15794887ST-4-0 0.1168539 0.2222033
## CCIS74726977ST-3-0 0.5387291 0.5015390
## CCIS16561622ST-4-0 0.1735637 0.2879345
## CCIS79210440ST-3-0 0.1556684 0.2266513
## CCIS82507866ST-3-0 0.1667249 0.1962567
Model Evaluation and Interpretation
In the final part, we want to find out how well the model performed and which microbial species had been selected in the model. In order to do so, we first calculate how well the predictions fit the real data using the functionevaluate.predictions
. This function calculates the Area Under the Receiver Operating Characteristic (ROC) Curve (AU-ROC) and the Precision Recall (PR) Curve for each resampled cross-validation run.
sc.obj <- evaluate.predictions(sc.obj)
## Evaluated predictions successfully.
Evaluation Plot
To plot the results of the evaluation, we can use the functionmodel.evaluation.plot
, which produces a pdf-file showing the ROC and PR Curves for the different resamples runs as well as the mean ROC and PR Curve.
model.evaluation.plot(sc.obj)
Interpretation Plot
The final plot produced by SIAMCAT
is the model interpretation plot, created by the model.interpretation.plot
function. The plot shows for the top selected features the
- model weights (and how robust they are) as a barplot,
- a heatmap with the z-scores or fold changes for the top selected features, and
- a boxplot showing the proportions of weight per model which is captured by the top selected features.
Additionally, the distribution of metadata is shown in a heatmap below.
The function again produces a pdf-file optimized for a landscape DIN-A4 plotting region.
model.interpretation.plot(sc.obj, fn.plot = 'interpretation.pdf',
consens.thres = 0.5, limits = c(-3, 3), heatmap.type = 'zscore')
The resulting plot looks like this:
Session Info
sessionInfo()
## R version 4.5.0 RC (2025-04-04 r88126)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.2 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.21-bioc/R/lib/libRblas.so
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0 LAPACK version 3.12.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] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] ggpubr_0.6.0 SIAMCAT_2.12.0 phyloseq_1.52.0 mlr3_0.23.0
## [5] lubridate_1.9.4 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4
## [9] purrr_1.0.4 readr_2.1.5 tidyr_1.3.1 tibble_3.2.1
## [13] ggplot2_3.5.2 tidyverse_2.0.0 BiocStyle_2.36.0
##
## loaded via a namespace (and not attached):
## [1] RColorBrewer_1.1-3 jsonlite_2.0.0 shape_1.4.6.1
## [4] magrittr_2.0.3 magick_2.8.6 farver_2.1.2
## [7] corrplot_0.95 nloptr_2.2.1 rmarkdown_2.29
## [10] vctrs_0.6.5 multtest_2.64.0 minqa_1.2.8
## [13] PRROC_1.4 tinytex_0.57 rstatix_0.7.2
## [16] htmltools_0.5.8.1 progress_1.2.3 curl_6.2.2
## [19] broom_1.0.8 Rhdf5lib_1.30.0 Formula_1.2-5
## [22] rhdf5_2.52.0 pROC_1.18.5 sass_0.4.10
## [25] parallelly_1.43.0 bslib_0.9.0 plyr_1.8.9
## [28] palmerpenguins_0.1.1 mlr3tuning_1.3.0 cachem_1.1.0
## [31] uuid_1.2-1 igraph_2.1.4 lifecycle_1.0.4
## [34] iterators_1.0.14 pkgconfig_2.0.3 Matrix_1.7-3
## [37] R6_2.6.1 fastmap_1.2.0 GenomeInfoDbData_1.2.14
## [40] rbibutils_2.3 future_1.40.0 digest_0.6.37
## [43] numDeriv_2016.8-1.1 colorspace_2.1-1 S4Vectors_0.46.0
## [46] mlr3misc_0.16.0 vegan_2.6-10 labeling_0.4.3
## [49] timechange_0.3.0 httr_1.4.7 abind_1.4-8
## [52] mgcv_1.9-3 compiler_4.5.0 beanplot_1.3.1
## [55] bit64_4.6.0-1 withr_3.0.2 backports_1.5.0
## [58] carData_3.0-5 ggsignif_0.6.4 LiblineaR_2.10-24
## [61] MASS_7.3-65 biomformat_1.36.0 permute_0.9-7
## [64] tools_4.5.0 ape_5.8-1 glue_1.8.0
## [67] lgr_0.4.4 nlme_3.1-168 rhdf5filters_1.20.0
## [70] grid_4.5.0 checkmate_2.3.2 gridBase_0.4-7
## [73] cluster_2.1.8.1 reshape2_1.4.4 ade4_1.7-23
## [76] generics_0.1.3 gtable_0.3.6 tzdb_0.5.0
## [79] data.table_1.17.0 hms_1.1.3 utf8_1.2.4
## [82] car_3.1-3 XVector_0.48.0 BiocGenerics_0.54.0
## [85] foreach_1.5.2 pillar_1.10.2 vroom_1.6.5
## [88] bbotk_1.5.0 splines_4.5.0 lattice_0.22-7
## [91] bit_4.6.0 survival_3.8-3 tidyselect_1.2.1
## [94] Biostrings_2.76.0 knitr_1.50 reformulas_0.4.0
## [97] infotheo_1.2.0.1 gridExtra_2.3 bookdown_0.43
## [100] IRanges_2.42.0 stats4_4.5.0 xfun_0.52
## [103] Biobase_2.68.0 matrixStats_1.5.0 stringi_1.8.7
## [106] UCSC.utils_1.4.0 yaml_2.3.10 boot_1.3-31
## [109] evaluate_1.0.3 codetools_0.2-20 archive_1.1.12
## [112] BiocManager_1.30.25 cli_3.6.4 Rdpack_2.6.4
## [115] munsell_0.5.1 jquerylib_0.1.4 mlr3learners_0.10.0
## [118] Rcpp_1.0.14 GenomeInfoDb_1.44.0 globals_0.16.3
## [121] parallel_4.5.0 prettyunits_1.2.0 paradox_1.0.1
## [124] lme4_1.1-37 listenv_0.9.1 glmnet_4.1-8
## [127] lmerTest_3.1-3 scales_1.3.0 crayon_1.5.3
## [130] rlang_1.1.6 mlr3measures_1.0.0