Differential Abundance with ANCOM-BC2¶
ANCOM-BC2 (Analysis of Compositions of Microbiomes with Bias Correction) identifies taxa that are significantly more or less abundant between groups, while accounting for compositionality and sampling fraction bias.
We are going to practice using the ANCOM-BC2 visualizer within the composition plugin. This plugin focuses on methods that account for the compositional nature of microbiome data. Here is a paper that explains what this means and why we have to deal with this when analyzing microbiome data.
https://www.frontiersin.org/journals/microbiology/articles/10.3389/fmicb.2017.02224/full. If you have questions about what it means for data to be compositional, this paper is worth a read. Recall that microbiome data is compositional, because 16S sequencing alone cannot capture absolute abundance of an organism, thus we get relative abundance.
The ANCOM-BC2 pipeline is a differential abundance test that lets us investigate whether individual ASVs or taxa are more or less abundant in different sample groups. Microbiome data present several challenges for performing differential abundance using conventional methods. Microbiome abundance data are inherently sparse (having a lot of zeros) and compositional. Because of this, traditional statistical methods that you may be familiar with such as ANOVA, Kruskal-Wallis, and t-tests are not appropriate for performing differential abundance tests of microbiome data and lead to a high false-positive rate. ANCOM-BC2 is a compositionally aware method that extends ANCOM-BC by improving bias correction and allowing for more flexible study designs (e.g., multiple groups and complex models) The paper can be found here: https://www.nature.com/articles/s41592-023-02092-7. Microbiome data are typically subject to two sources of biases: unequal sampling fractions (sample-specific biases) and differential sequencing efficiencies (taxon-specific biases). In short, it is a tool that identifies features that are significantly different in abundance between groups using bias-corrected log fold changes.
Before we start, once again make sure you are in your decomp_tutorial directory and make sure your QIIME2 environment is activated.
Filter Low-Frequency Samples and Features¶
Lets start by making an ancombc2 directory and navigating into that directory.
Remove samples below the rarefaction threshold and then remove rare ASVs:
qiime feature-table filter-samples \
--i-table ../dada2/table_nomitochloro_nocontrol.qza \
--p-min-frequency 5000 \
--o-filtered-table table_nomitochloro_nocontrol_5000.qza
Then, we will filter out low abundance/low prevalence ASVs. Filtering can provide better resolution and limit false discovery rate (FDR) penalty on features that are too far below the noise threshold to be applicable to a statistical test. A feature that shows up with 10 counts may be a real feature that is present only in that sample, it may be a feature that’s present in several samples but only got amplified and sequenced in one sample because PCR is a somewhat stochastic process, or it may be noise. It’s not possible to tell, so feature-based analysis may be better after filtering low-abundance features. However, filtering also shifts the composition of a sample, further disrupting the relationship. Here, the filtering is performed as a trade-off between the model, computational efficiency, and statistical practicality. (You don’t need to apply as stringent filtering for ANCOM-BC2 since it is more robust, but it is still good practice to understand and apply appropriate filtering).
qiime feature-table filter-features \
--i-table table_nomitochloro_nocontrol_5000.qza \
--p-min-frequency 50 \
--p-min-samples 4 \
--o-filtered-table table_nomitochloro_nocontrol_5000_abund.qza
Why Filter Features?
ANCOM-BC is sensitive to very rare taxa that appear in only a few samples, filtering to features with at least 50 total reads present in at least 4 samples improves statistical power and reduces spurious findings.
Collapse to Species Level¶
You don’t have to collapse to the species level—you can run ANCOM-BC directly on table_nomitochloro_nocontrol_5000_abund.qza to identify differentially abundant ASVs. However, collapsing to the species level makes it easier to interpret results by linking those ASVs to taxonomy. You can also collapse to the genus level or any other taxonomic level relevant to your research question by adjusting the --p-level parameter.
Aggregate ASVs to GreenGenes2 taxonomy level 7 (species):
qiime taxa collapse \
--i-table table_nomitochloro_nocontrol_5000_abund.qza \
--i-taxonomy ../taxonomy/taxonomy_gg2.qza \
--p-level 7 \
--o-collapsed-table table_nomitochloro_nocontrol_5000_abund_L7.qza
Get Metadata Without Environmental Controls¶
Time to run ANCOM-BC2! Let's first see if there are any ASVs that are differentially abundant across the sample types and facility.
First, we need to get metadata that doesn't have controls
cp /pl/active/courses/2026_summer/CSU_2026/q2_workshop_final/QIIME2/metadata_q2_workshop_noECs.txt .
ANCOM-BC2¶
Sample type + facility, adjusting for ADD
Test for differentially abundant taxa across sample type and facility in a single model, adjusting for accumulated degree days (add_0c):
qiime composition ancombc2 \
--i-table table_nomitochloro_nocontrol_5000_abund_L7.qza \
--m-metadata-file metadata_q2_workshop_noECs.txt \
--p-fixed-effects-formula 'sample_type + facility + add_0c' \
--p-reference-levels sample_type::soil facility::STAFS \
--o-ancombc2-output ancombc2_sampletype_facility_add_L7.qza
Why no random effect for host_subject_id?
You might expect a --p-random-effects-formula '(1 | host_subject_id)' term to account for repeatedly sampling the same individual. It is deliberately left out in this case, since facility is constant within each host_subject_id (every cadaver sits at one facility), so it is nested in the host grouping. Passing a nested variable to ANCOM-BC2's mixed-model engine makes it fail with contrasts can be applied only to factors with 2 or more levels, because facility has only one level within each host. Dropping the random term fits the model as standard fixed effects and avoids that clash; and since the host grouping is largely redundant with facility here, little is lost. The tradeoff is that repeated within-cadaver sampling is not explicitly modeled, so p-values are slightly anti-conservative.
Visualize the results:
qiime composition tabulate \
--i-data ancombc2_sampletype_facility_add_L7.qza \
--o-visualization ancombc2_sampletype_facility_add_L7.qzv
qiime composition ancombc2-visualizer \
--i-data ancombc2_sampletype_facility_add_L7.qza \
--o-visualization ancombc2_barplot_sampletype_facility_add_L7.qzv
Interpreting Results¶
When reviewing the barplots and tabulated results, work through this checklist:
Outputs¶
| File | Type | Description |
|---|---|---|
table_nomitochloro_nocontrol_5000.qza |
Artifact | Samples filtered to ≥5000 reads |
table_nomitochloro_nocontrol_5000_abund.qza |
Artifact | Features filtered by frequency and prevalence |
table_nomitochloro_nocontrol_5000_abund_L7.qza |
Artifact | Collapsed to species level |
ancombc2_sampletype_facility_add_L7.qza |
Artifact | ANCOM-BC2 results — sample type & facility, adjusting for ADD |
ancombc2_sampletype_facility_add_L7.qzv |
Visualization | Tabulated results |
ancombc2_barplot_sampletype_facility_add_L7.qzv |
Visualization | Barplot — sample type & facility |
Next: Machine Learning