-
Notifications
You must be signed in to change notification settings - Fork 5
MIC Module 2 tutorial
This lab is based on the 16S rRNA gene analysis method originally developed by Michael Hall and Robert Beiko, and was updated and modified by Diana Haider for the 2021 Microbiome workshop.
The lab in this module is a walkthrough of an end-to-end pipeline using the command line interface for the analysis of high-throughput marker gene data including diversity, taxonomic and statistical explorations. The pipeline described is embedded in the latest version of QIIME2 (version 2021.4, and stands for Quantitative Insights into Microbial Ecology) which is a popular microbiome bioinformatics platform for microbial ecology. It uses software packages called plugins that can be developed by anyone and generates zipped artifacts that can be tracked through a provenance file automatically generated by QIIME2. Two scripts, accessible here, make the whole thing work: “download_Willis_et_al_data.sh” retrieves the sequences from the European Bioinformatics Institute through their relatively awesome API, and “qiime_commands.sh” to execute a chain of QIIME2 commands and generate a number of .qza and .qzv files. These files can be unzipped to reveal the sweet contents inside in case you want to (hypothetically, of course) feed them to a non-QIIME2 application. For this tutorial, we will go through each step individually after the import section, starting with the CBW_Willis_reads.qza file.
Commonly used marker genes for microbiome analysis include the 16S ribosomal RNA (rRNA) for prokaryotes, 18S rRNA for eukaryotes, and the internal transcribed spacer (ITS) for fungi. In this tutorial, we will explore a 16S rRNA dataset from environmental samples collected along three stations from the Halifax Line at four different depths, amplified using two different primers. One interesting question is whether the primer choice under- or overrepresents certain taxa groups, and then impacts diversity measurements. Details on the data collection and processing can be found in the original paper that published the data.
After this lab you will be able to: * * *
QIIME2 is recommended to be run in an independent conda environment to ensure consistency between different versions of the packages it uses. Here are the instructions for installation. For this instance, a qiime2 environment was already installed, it just needs to be activated.
source activate qiime2-2021.4
You can visualize all available plugins by typing qiime. Your command line should look like this.
To start your analysis, two files are required:
- Sequencing data
- Metadata
The sequencing data will be in multiple FASTQ files. Each FASTQ file contains the raw DNA sequences, and information on the sequences, such as an identifier, the DNA sequence and the quality score of each called bases in text format. These files are usually very large, and are an intermediate for further analyses. The metadata file contains information about the samples allowing us to interpret the data in their biological context.
The structure of your folders should look like this
<ROOT>
|-- sequence data/ # Folder with collected data
`-- raw reads/ # Folder with the raw reads in FASTQ format
`-- manifest.txt # Manifest file
`-- run*_ # Fastqs
`-- METADATA.txt # The metadata file
|-- qiime_artifacts/ # Folder containing the results
`-- CBW_Willis_reads.qza # Reads artifact imported in QIIME2 that you need to download
`-- DADA2_results/ # Results from denoising the sequencing data
`-- table.qza
`-- stats.qza
`-- representative_sequences.qza
|-- qiime_solutions/ # Intermediate files of expected outputs
In the interest of time, we will skip the import step, and the denoising step. The files required will be linked in the tutorial, and available in the qiime_artifacts folder.
You can do this step yourself, but for this live lab, we will start with the already imported CBW_Willis_reads.qza file.
If you want to fetch the dataset from EBI yourself, you can run bash download_Willis_et_al_data.sh bash script, but it is time consuming (~30 mins). The script downloads the FASTQ files from the EBI database, and creates a manifest file which is a text file with three columns. It guides the import in QIIME2 by providing the sample name, the file path and the direction of the read if the data has paired reads (either reverse or forward).
Once the manifest file is ready, you can just use the qiime import function:
qiime tools import \
--type 'SampleData[PairedEndSequencesWithQuality]' \
--input-path import_to_qiime \
--output-path CBW_Willis_reads
Output
- CBW_Willis_reads.qza: download
Since we won't run the import step ourselves to save time, we can just download the CBW_Willis_reads.qza file using wget:
wget http://quoc.ca/static/CBW_Willis_reads.qza
Let's start here. The sequences first undergo quality control, where we decide on a quality trimming threshold based on the quality profiles of the reads. During sequencing, each base called is given a base calling accuracy metric measured with Phred quality scores. The goal is to retain the most bases so the read is long enough to be informative, while removing bases that have low quality scores since they can increase the risk of false-positives. QIIME2 has a visualizer that helps you decide on a threshold.
This table adapted from Wikipedia can help us interpret quality scores. Generally, a score >20 is acceptable, and >30 is really good.
| Phred Quality Score | Error | Accuracy (1 - Error) |
|---|---|---|
| 10 | 1/10 = 10% | 90% |
| 20 | 1/100 = 1% | 99% |
| 30 | 1/1000 = 0.1% | 99.9% |
| 40 | 1/10000 = 0.01% | 99.99% |
| 50 | 1/100000 = 0.001% | 99.999% |
| 60 | 1/1000000 = 0.0001% | 99.9999% |
To run this, make sure you are in the qiime_artifacts/ directory, that's where the reads are.
qiime demux summarize \
--p-n 10000 \
--i-data CBW_Willis_reads.qza \
--o-visualization qual_viz.qzv
Output
- qual_viz.qzv: download
From the terminal, you can open the QIIME2 viewer by using the view function:
qiime tools view \
qual_viz.qzv
Question : How many samples are there?
Question : Inspect the quality plots, what do you think would be a good trim length for the forward and reverse reads?
This function randomly samples 10 000 of your reads without replacement, and presents the Q scores in a boxplot. Each bar represents the distribution of quality scores from the subsampled reads for one base position. A drop in quality is expected towards the 3' end of reads due to phasing (Schirmer et al. 2016). Since we have paired-end reads, we need to be cautious about trimming too much since we need to have enough overlapping regions between forward and reverse reads for the joining step. Reads that are shorther than the selected trim length will be discarded, and reads that fail to join are also discarded.
From the quality score boxplot, we decided to trim our sequences at 240 for both forward and reverse reads. While the original authors clustered their sequences into OTUs, we will make ASVs using DADA2. DADA2 clusters sequences based on quality score, and discards reads that have a high probability to be an error.
qiime dada2 denoise-paired \
--i-demultiplexed-seqs CBW_Willis_reads.qza \
--p-trunc-len-f 240 \
--p-trunc-len-r 240 \
--p-n-threads 4 \
--o-representative-sequences representative_sequences.qza \
--o-table unfiltered_table.qza \
--o-denoising-stats denoise_stats.qza \
--verbose #verbose can be added to any command line to print the details of what the computer is doing
Output
Denoising can take ~30mins, so we will use the outputs above that we cooked in advance! The outputs are the foundation for the rest of this analysis.
From the feature table
The feature table is a BIOM table of samples x ASVs. ASVs can be referred as the features, and each one has a strictly positive frequency per sample. Remember, this data is compositional, meaning they have an irrelevant constant sum imposed by the sequencer, independent from the initial microbial load. We can inspect the summary statistics:
qiime feature-table summarize --i-table unfiltered_table.qza --o-visualization table_summary
Output
- table_summary.qzv: download
qiime tools view \
qual_viz.qzv
Question : Did we lose any samples during denoising? In which scenario would you lose a sample during denoising?
Question : What observation can you make on the ratio of abundant vs rare ASVs?
It's hard to make ASVs interesting, so let's add their taxonomic identification. Naive Bayes Classifiers provide highly accurate taxonomic classification along with low run times for microbiome studies. It is recommended to use a classifier trained on your own data, but there are pre-trained classifiers available on QIIME2's resources page, such as the greengenes and SILVA classifiers. Greengenes is a smaller database for Archaea and Bacteria, and was last updated in 2013. SILVA is a is regurlarly updated and includes eukaryotes. If you have limited memory, it's better to use greengenes, but for this tutorial we will use a classifier trained on SILVA.
First, we need to download the classifier from QIIME2's database.
wget https://data.qiime2.org/2021.4/common/silva-138-99-nb-classifier.qza
Then, we can classify our data.
qiime feature-classifier classify-sklearn \
--i-classifier silva-138-99-nb-classifier.qza \
--i-reads representative_sequences.qza \
--o-classification taxonomy.qza
Output
- taxonomy.qza: [download](
qiime taxa barplot \
--i-table table.qza \
--i-taxonomy taxonomy.qza \
--m-metadata-file METADATA.txt \
--o-visualization taxa-bar-plots
Before calculating diversity metrics, we need to correct for unequal sampling effort by rarefying our data. Rarefaction randomly subsamples all samples at the same read depth without replacement, resulting in all samples having the same read depth. We need to be careful at this step, because samples with a read depth smaller than the chosen subsampling depth will be discarded. To choose a the value, we will refer to our summarized table under the Interactive Sample Detail tab. The goal is to keep the most reads, and the most samples.
QIIME2 has a diversity plugin which generates alpha and beta diversity metrics on the data rarefied at a given depth.
qiime diversity core-metrics-phylogenetic \
--i-phylogeny rooted_tree.qza \
--i-table unfiltered_table.qza \
--p-sampling-depth 2000 \
--output-dir diversity_2000 \
--m-metadata-file METADATA.txt
Visualization outputs
- bray_curtis_emperor.qzv : download
- jaccard_emperor.qzv : download
- unweighted_unifrac_emperor.qzv : download
- weighted_unifrac_emperor.qzv : download
Artifact outputs
- bray_curtis_distance_matrix.qza : download
- bray_curtis_pcoa_results.qza : download
- evenness_vector.qza : download
- faith_pd_vector.qza : download
- jaccard_distance_matrix.qza : download
- jaccard_pcoa_results.qza : download
- observed_features_vector.qza : download
- rarefied_table.qza : download
- shannon_vector.qza : download
- unweighted_unifrac_distance_matrix.qza : download
- unweighted_unifrac_pcoa_results.qza : download
- weighted_unifrac_distance_matrix.qza : download
- weighted_unifrac_pcoa_results.qza : download
This is A LOT of information. We can start by looking at the beta-diversity plots. Remember, beta-diversity calculates the distance between two communities to tell us how similar (jaccard index) or dissimilar (bray-curtis index) they are. By including taxonomic information, we can calculate the UniFrac distance which uses the branch length between a set of taxa to determine if two communities are significantly different. The unweighted UniFrac distance uses presence/absence information of the taxa, whereas the weighted unifrac takes into consideration the relative abundances of each taxa to measure the differences between the microbial communities (eg. different environments). Each of these metrics are calculated between pairs of samples, therefore, they output a distance matrix. The distance matrix is used to make a PCoA plot that we can now visualize!
Question : Do you see different groupings with different beta diversity metrics (ie. Bray-Curtis, Jaccard and UniFrac)?
Question :
We can now investigate alpha diversity! Alpha diversity gives us information on the observed richness (Shannon), evenness (Pielou) or phylogenetic diversity (faith pd). We can compare the alpha diversity between groups by using the alpha-group-significance plugin:
qiime diversity alpha-group-significance \
--i-alpha-diversity diversity_2000/faith_pd_vector.qza \
--m-metadata-file METADATA.txt \
--o-visualization diversity_2000/alpha_PD_significance
Visualization outputs
- alpha_PD_significance.qzv : download
qiime diversity alpha-group-significance \
--i-alpha-diversity diversity_2000/shannon_vector.qza \
--m-metadata-file METADATA.txt \
--o-visualization diversity_2000/alpha_shannon_significance
Visualization outputs
- alpha_shannon_significance.qzv : download
Question : Are the beta and alpha diversity giving you the same patterns? Why or why not?
Question :
qiime diversity alpha-rarefaction \
--i-table unfiltered_table.qza \
--i-phylogeny rooted_tree.qza \
--p-max-depth 2000 \
--m-metadata-file METADATA.txt \
--o-visualization diversity_2000/alpha_rarefaction.qzv
Going back to our DNA sequences, we can align our sequences using MAFFT to inspect evolutionary relationships between the microbes in the sampled community.
qiime alignment mafft \
--i-sequences representative_sequences.qza \
--o-alignment aligned_representative_sequences \
Artifact outputs
- aligned_representative_sequences.qza : download
You can also run a masked alignment if you want to mask certain patterns (eg. repetitions or conserved regions) in the sequences before the alignment:
qiime alignment mask \
--i-alignment aligned_representative_sequences.qza \
--o-masked-alignment masked_aligned_representative_sequences
Artifact outputs
- masked_aligned_representative_sequences.qza : download
We can visualize the alignment using a phylogenetic tree built with FastTree. The tree can be unrooted, or rooted. QIIME doesn't have a function to visualize the trees, but we can export them and visualize them using other popular programs such as iTOL web interface or ggtree in R.
qiime phylogeny fasttree \
--i-alignment masked_aligned_representative_sequences.qza \
--o-tree unrooted_tree
Artifact outputs
- unrooted_tree.qza : download
qiime phylogeny midpoint-root \
--i-tree unrooted_tree.qza \
--o-rooted-tree rooted_tree
Artifact outputs
- rooted_tree.qza : download
Compositional data can be corrected by rarefaction to calculate alpha and beta diversity metrics like the Shannon diversity index, or the Bray-Curtis dissimilarity index we calculated just above. Another way is to take a compositional approach to the statistical analysis by using Compositional Data Analysis (CoDA) methods which are methods based on ratios instead of proportions. These methods are based on data transformations (CLR, ILR, ALR...) presented in module 5. QIIME2 has two CoDA methods that identify which microbes have significantly different abundances between two communities: ANCOM and ALDEx2. We will use both and compare their results.
If you remember from the lecture, log-transformations don't tolerate 0s so we need to add a small pseudo-counts to our tables.
qiime composition add-pseudocount
--i-table unfiltered_table.qza
--o-composition-table comp-table
Artifact outputs
- comp-table.qza : download
qiime composition ancom
--i-table comp-gut-table.qza
--m-metadata-file sample-metadata.tsv
--m-metadata-column subject
--o-visualization ancom-subject.qzv
Artifact outputs
- comp-table.qza : download
Question : Which taxa are significantly different across samples?
Let's try ALDEx2. This plugins also adds a pseudo-count, but it's integral in the plugin, so we will use the unfiltered_table as an input.
qiime aldex2 aldex2
--i-table unfiltered_table.qza
--m-metadata-file METADATA.txt
--m-metadata-column depth
--o-
Artifact outputs
- comp-table.qza : download
Question : Do you get the same result when using different methods? Question : If you had to repeat this analysis, which tools would you use?