Key Points
Introduction to microbiome data
- A microbiome study goes from data generation and pre-processing to the data object, data processing and statistical analysis. This lesson covers the data object, data processing and statistical analysis steps; data integration is covered in the follow-up multi-omics lesson.
- Microbiome data consists of an abundance table (taxa × samples), taxonomy, sample information and often a phylogenetic tree.
- The number of reads per sample depends on sequencing depth, so we usually compare relative abundances.
- Relative abundances are compositional: they add up to 100 %, so a change in one taxon changes the shares of all others.
- Microbiome data contains many zeros and many more taxa than samples.
- Alpha diversity, beta diversity and differential abundance are the standard first analyses of a microbiome study, and for some studies they are enough.
- This lesson follows one study, on colorectal cancer, from data to results. Other differences between the groups, such as where people live, can confound the comparison.
From samples to tables
- Choices made during data generation, such as sample storage, DNA extraction and batches, leave a mark on the data. Read how the samples were collected and processed before you analyse them.
- Pre-processing turns raw reads (FASTQ files) into tables of taxa. It is usually done outside R, before the analysis that this lesson covers.
- The numbers in the abundance table describe the sequenced DNA, and their total depends on the sequencing depth.
- The outputs go into the parts of a TreeSE: the abundance table into
assay, the taxonomy intorowData, the sample information intocolDataand the tree intorowTree. - mia has import functions, such as
importQIIME2(),importMetaPhlAn()andconvertFromPhyloseq(), that build a TreeSE directly from pipeline output.
RStudio project and experimental data
- Use an RStudio project to keep the data, code and results of an analysis together.
- Use
download.file()to download data from the internet, andfile.path()to build file paths. - The main packages of this lesson are mia and miaViz from the OMA framework; later episodes also use ape, scater, bluster, daa, maaslin3 and mikropml.
Importing data into TreeSummarizedExperiment
- A
TreeSummarizedExperimentkeeps the abundance table, taxonomy, sample information and tree together and in sync. - Rows are taxa and columns are samples.
-
assay(),rowData()andcolData()access the abundance table, the taxonomy and the sample information. - Subsetting with
[rows, columns]keeps all parts of the object in sync. -
plotBarplot()gives a quick overview of the study groups. In our study, the groups differ in more than disease: most healthy people come from Bhopal.
Exploring and preparing microbiome data
- Library sizes differ between samples, so we compare relative values instead of raw counts.
-
agglomerateByRank()combines taxa into a higher taxonomic rank. - (Bonus)
agglomerateByRanks()stores the data at every rank as alternative experiments in one object;altExp()picks one, andswapAltExp()makes one the main data. -
transformAssay()adds transformed tables, such as relative abundance and robust CLR (rclr), and keeps the original counts. - rclr compares each taxon to the average taxon of its sample on a log scale. It fills in the zeros with estimates, so single rclr values are estimates, not measurements.
- Which table to use depends on the method and its assumptions. The rclr values are closer to a normal distribution than the counts.
-
plotAbundance()shows the community composition of each sample, andplotBoxplot()the abundance of a single taxon by group. -
subsetByPrevalent()removes rare taxa. Use it for differential abundance, but not for diversity. - In our study, one species, Prevotella copri, dominates the gut of many healthy people.
Alpha diversity
- Alpha diversity describes the diversity within a sample: richness (how many taxa), evenness (how equal), both (Shannon), or the share of the tree of life covered (Faith). The indices give complementary information.
-
addAlpha()calculates diversity indices and adds them tocolData. -
plotBoxplot()anddaa::getWilcoxonTest()compare alpha diversity between two groups. The Wilcoxon test does not assume normally distributed values. - In our study, people with CRC have a higher diversity, partly because the gut of many healthy people is dominated by one species. Higher diversity is not automatically healthier.
- Check for confounding: in our study, the CRC patients are also older than the healthy people.
Beta diversity
- Beta diversity compares whole communities between samples, using a dissimilarity such as Bray–Curtis.
-
addMDS()calculates a PCoA from any dissimilarity,runPCA()a PCA from rclr values, andplotOrdination()draws them as a map of the samples. PCA and PCoA are complementary, and PCA loadings show which taxa drive the axes. - UniFrac uses the phylogenetic tree, so that closely related taxa count as similar. Unweighted UniFrac uses presence and absence; weighted UniFrac also uses the abundances.
- PERMANOVA (
getPERMANOVA()) tests whether groups differ in composition; R2 tells how much of the differences the group explains. Always check whether the groups differ in spread, because this affects the PERMANOVA result. - dbRDA (
addRDA()) takes other variables into account, which is important when groups differ in more than one way. - (Bonus) Clustering (
addCluster()) finds groups of similar samples without using the sample information. Cluster the data itself, never the ordination axes, and use the ordination only to show the clusters. - In our study, the gut microbiome of people with CRC differs from that of healthy people, even when the location is taken into account. The samples fall into a Prevotella and a non-Prevotella community type, which is strongly linked to the disease.
Differential abundance and prevalence analysis
- Differential abundance analysis tests whether the differences we see in plots are statistically significant.
- At its core, DAA is a simple test: a t-test is a linear model with one two-group variable, and a linear model can add covariates, such as the location. Most DAA methods are based on this under the hood.
- Testing many taxa produces false positives, so we use q-values that are corrected for multiple testing.
- Dedicated methods, such as MaAsLin 3, extend the linear model to take the specific nature of microbiome data into account: relative values, many zeros and noisy abundances.
- A taxon can differ in abundance, in prevalence (how often it is present), or both. MaAsLin 3 tests both.
- Look at the data behind the results, and treat significant taxa as candidates for further study.
- In our study, Prevotella copri and butyrate-producing species are less abundant in people with CRC, and Flavonifractor plautii is found much more often in CRC.
Machine learning: predicting an outcome
- Machine learning asks how well we can predict an outcome, such as a disease, from features, such as taxon abundances.
- Always evaluate a model on samples it has not seen: cross-validation on the training data and a separate test set.
- Hyperparameters, such as
mtryof a random forest, are chosen by cross-validation on the training data only. - mikropml works directly with a TreeSE:
run_ml()trains, tunes and tests a model in one call, andpreprocess_data()prepares the data when a model needs it. Random forests work on raw counts. - The AUC measures how well the predictions separate the groups. With a small test set, it varies a lot between random splits.
- Feature importance shows which taxa the model relies on. In our study, many of them, such as Roseburia faecis, also differ in abundance.
- Confounders and small sample sizes can make a model look better than it is; independent validation is needed.
Capstone: analyse a new dataset
- The same workflow (explore, alpha diversity, beta diversity, differential abundance) works for new datasets, including amplicon data.
- With real read counts and very different library sizes, rarefaction is an option for richness.
- Include technical variables such as the cohort or batch in the models.
- Non-significant results are results too. Report them together with the sample size and the limitations.
- A short written report forces you to state the question, the methods, the results and the limitations clearly.
Next steps
- A typical microbiome analysis goes from import and preparation to alpha diversity, beta diversity and differential abundance.
- These three analyses are what most studies report. They are sometimes enough on their own, and they are always the first steps before more advanced analyses.
- The OMA book is the place to continue learning, and the follow-up multi-omics lesson shows how to combine the microbiome with other data types.