Skip to article frontmatterSkip to article content

Tutorial

Installing QIIME 2

This tutorial uses the command line interface or cli. If you are uncomfortable with using the cli, this video serves as an introduction to basic cli usage.

Make sure you have conda installed by running the command conda --version. If you do not have conda installed follow the instructions here.

conda env create -n q2-amf-tutorial -f https://raw.githubusercontent.com/caporaso-lab/amf-tutorial/refs/heads/main/book/_static/environment.yml
conda activate q2-amf-tutorial

In order to use q2-fondue, you will first need to configure fondue. Instructions for doing so may be found here.

Sample metadata

This study investigates differences in AMF communities between modern high-yielding rice varieties (BR28, BR29, BR58) and local traditional varieties (Shampakatar, Ushapari), sampled from eight rice fields with five soil samples each. A total of 200 samples were collected, of which subsample of 143 AMF-relevant samples (79 from modern and 64 from traditional varieties), to test the hypothesis recorded in the metadata file. Before starting the analysis, explore the sample metadata to familiarize yourself with the samples used in this study. The following command will download the sample metadata as tab-separated text and save it in the file sample-metadata.tsv. This sample-metadata.tsv file is used throughout the rest of the tutorial.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
wget -O 'metadata.tsv' \
  'https://amf-tutorial.readthedocs.io/en/latest/data/amf-tutorial/metadata.tsv'

Obtaining the data

In this tutorial, we will use q2-fondue to download our publicly available data and import them into QIIME 2. The data we use in this tutorial has already been imported into QIIME 2 for you. This video gives a basic overview of what importing data into QIIME 2 using a manifest file looks like.

First, let’s download the metadata containing the NCBI SRA project, accession number SRR13445888.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
wget -O 'project-accession.qza' \
  'https://amf-tutorial.readthedocs.io/en/latest/data/amf-tutorial/project-accession.qza'

Then we can visualize it using qiime metadata tabulate.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime metadata tabulate \
  --m-input-file project-accession.qza \
  --o-visualization project-accession.qzv

We can use q2-fondue 🫕 to easily import the data using this command:

qiime fondue get-sequences \
    --i-accession-ids project-accession.qza \
    --p-email [Insert Your Email] \
    --o-single-reads single-reads-demux.qza \
    --o-paired-reads demux.qza \
    --o-failed-runs failed-runs.qza

or you can download the demux artifact here:

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
wget -O 'demux.qza' \
  'https://amf-tutorial.readthedocs.io/en/latest/data/amf-tutorial/demux.qza'

Now, let’s visualize our data using demux summarize to assess sequencing quality.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime demux summarize \
  --i-data demux.qza \
  --o-visualization demux.qzv

Understanding the Data

If you downloaded your data from NCBI-SRA, or received it from a sequencing facility, you will typically need three key files:

Metadata file – This mapping file provides contextual information about your experiment, including hypotheses, treatments, and sample details.

Classifier file – Used for assigning taxonomy during analysis.

Sequence files – These are usually in FASTQ format or already imported into QIIME 2 as .qza files.

To begin exploring your data and assessing its quality, open the demux.qzv file in QIIME 2 View. This visualization helps you evaluate read quality, which is critical for determining appropriate trimming parameters in downstream steps.

Revision Questions

  1. What is the minimum and maximum number of reads in our samples?

  2. Do any of the samples have fewer than 1,000 sequences?

  3. At which position does the median quality score drop below 30?

Note: If any of the samples have very few sequences (e.g., fewer than 1,000), you may want to omit them from downstream analysis, as they could negatively affect data interpretation.

Denoising Using DADA2

Denoising is the process of correcting errors in the sequencing data and delimitating ASVs (amplicon sequence variants). The Non-biological sequences (e.g., adapters, primers, linker pads, etc.) and errors created by sequencing machines, such as incorrect base calls or random noise which can lead to inaccurate results if not corrected. For a more detailed lecture on this process, watch this video.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime dada2 denoise-paired \
  --i-demultiplexed-seqs demux.qza \
  --p-trunc-len-f 240 \
  --p-trunc-len-r 220 \
  --o-table table.qza \
  --o-denoising-stats denoising-stats.qza \
  --o-representative-sequences representative-sequences.qza

Revision Questions

  1. How did we decide the truncation parameters, --p-trunc-len-f 240 --p-trunc-len-r 220? Hint: At what base pair does the median quality drop below 30?
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime metadata tabulate \
  --m-input-file denoising-stats.qza \
  --o-visualization stats-dada2.qzv

Note- If a large number (e.g. >50%) of sequences are lost during denoising/filtering the settings may be too stringent.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime feature-table tabulate-seqs \
  --i-data representative-sequences.qza \
  --o-visualization rep-seqs.qzv

Revision Questions

  1. Do BLAST searches of the representative sequences make sense? Are the features what you would expect like AMF or not?
  2. How many features (ASVs) were generated? Are the communities high or low diversity?
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime feature-table summarize \
  --i-table table.qza \
  --o-visualization table.qzv

Taxonomic assignment

In order to understand which microbes are in the environment we sampled, we need to taxonomically annotate our sequences. More information on this process may be found here.

Classifications with fit-classifier-naive-bayes

To construct a taxonomic classifier using the MaarjAM database, two primary input files are required:

  1. A FASTA file containing the reference sequences
  2. A taxonomy file mapping those sequences to their taxonomic lineages

These resources can be downloaded from the official MaarjAM database website. Alternatively, pre-imported .qza files are also be downloaded from here:

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
wget -O 'maarjam-ref-seq.qza' \
  'https://amf-tutorial.readthedocs.io/en/latest/data/amf-tutorial/maarjam-ref-seq.qza'
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
wget -O 'ref-taxonomy-maarjam.qza' \
  'https://amf-tutorial.readthedocs.io/en/latest/data/amf-tutorial/ref-taxonomy-maarjam.qza'

Next step is building the classifier file. Building an accurate classifier file is crucial for reliable taxonomic analysis, as it can significantly influence your results. An incorrect or poorly trained classifier may lead to unassigned or misclassified sequences. It’s recommended to run your data using both the vsearch and sklearn methods for comparison.

qiime feature-classifier fit-classifier-naive-bayes \
    --i-reference-reads maarjam-ref-seq.qza \
    --i-reference-taxonomy ref-taxonomy-maarjam.qza \
    --o-classifier classifier-maarjam.qza
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
wget -O 'classifier-maarjam.qza' \
  'https://amf-tutorial.readthedocs.io/en/latest/data/amf-tutorial/classifier-maarjam.qza'
qiime feature-classifier classify-sklearn \
    --i-reads representative-sequences.qza \
    --i-classifier classifier-maarjam.qza \
    --p-confidence 0.7 \
    --o-classification taxonomy-maarjam.qza
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
wget -O 'taxonomy-maarjam.qza' \
  'https://amf-tutorial.readthedocs.io/en/latest/data/amf-tutorial/taxonomy-maarjam.qza'
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime metadata tabulate \
  --m-input-file taxonomy-maarjam.qza \
  --o-visualization taxonomy-maarjam-md.qzv

For convenience value of p-confidence is kept 0.7; however, it would be ideal to keep this at 0.97.

Revision Questions

  1. How many of your ASVs were taxonomically assigned? note :view your taxonomy.qzv file

  2. What was the difference in the number of ASVs when you used p-confidence of 0.97

Classifications with classify-consensus-vsearch

Classification with maarjAM

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime feature-classifier classify-consensus-vsearch \
  --i-query representative-sequences.qza \
  --i-reference-reads maarjam-ref-seq.qza \
  --i-reference-taxonomy ref-taxonomy-maarjam.qza \
  --p-maxaccepts 1 \
  --p-perc-identity 0.7 \
  --p-strand both \
  --p-top-hits-only \
  --p-unassignable-label Unassigned \
  --o-classification rice-taxonomy-vsearch.qza \
  --o-search-results rice-search-results-vsearch.qza
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime metadata tabulate \
  --m-input-file rice-taxonomy-vsearch.qza \
  --o-visualization rice-taxonomy-vsearch.qzv

Revision Questions

  1. How many of your ASVs were taxonomically assigned by this method. Is there a difference in output between fit-classifier-naive-bayes and classify-consensus-vsearch?

Taxonomy Bar Plot

The output of of feature-classifier classify-sklearn is used for the rest of the tutorial over the vsearch output.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime taxa barplot \
  --i-table table.qza \
  --i-taxonomy taxonomy-maarjam.qza \
  --m-metadata-file metadata.tsv \
  --o-visualization taxa-bar-plots.qzv

Revision Questions

  1. What are the dominant phyla in each in each group ?

Visualize the samples at Level 6 (which corresponds to the genus of AMF in this analysis), and then sort the samples by  env_broad_level, You can add as many taxonomic levels levels you want. If it’s hard to visualize the dominant phyla in each in each group, download the csv file on left hand side and use this to plot a relative abundance chart.

Filtering Tables

You can filter table if you want to work with specific group of taxa. You can create separate files for traditional and modern varieties if you want to.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime feature-table filter-samples \
  --i-table table.qza \
  --m-metadata-file metadata.tsv \
  --p-where '[env_broad_scale]='"'"'Traditional rice root'"'"'' \
  --o-filtered-table traditional-rice-table.qza
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime feature-table summarize \
  --i-table traditional-rice-table.qza \
  --o-visualization traditional-rice-table.qzv
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime feature-table filter-samples \
  --i-table table.qza \
  --m-metadata-file metadata.tsv \
  --p-where '[env_broad_scale]='"'"'Modern rice root'"'"'' \
  --o-filtered-table modern-rice-table.qza
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime feature-table summarize \
  --i-table modern-rice-table.qza \
  --o-visualization modern-rice-table.qzv

Differential abundance (ANCOM-BC)

Accurately identifying features that are differentially abundant across sample types in microbiome data is a challenging problem and an open area of research. Analysis of Compositions of Microbiomes with Bias Correction (ANCOM-BC) is a methodology for differential abundance (DA) testing that corrects bias in microbiome data. Here we will use ANCOM-BC to identify taxa that are differentially abundant in modern or traditional rice varieties. For more information on this process watch this video.

We need to filter our table so we can investigate only Glomeromycetes class features.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime taxa filter-table \
  --i-table table.qza \
  --i-taxonomy taxonomy-maarjam.qza \
  --p-include c__Glomeromycetes \
  --o-filtered-table glomeromycetes-table.qza
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime taxa collapse \
  --i-table glomeromycetes-table.qza \
  --i-taxonomy taxonomy-maarjam.qza \
  --p-level 6 \
  --o-collapsed-table collapsed-table-level-6.qza
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime composition ancombc \
  --i-table collapsed-table-level-6.qza \
  --m-metadata-file metadata.tsv \
  --p-formula env_broad_scale \
  --o-differentials l6-ancombc-differentials.qza
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime composition da-barplot \
  --i-data l6-ancombc-differentials.qza \
  --p-significance-threshold 0.05 \
  --p-level-delimiter ';' \
  --o-visualization l6-da-barplot.qzv

Revision Questions

  1. Which taxa are enriched in traditional varieties? Note: try changing sample_name to column ‘env_broad_scale’; try with significance threshold of 0.01 also.

Diversity Analysis

Now let’s investigate community richness i.e. alpha diversity and the compositional differences of the AMF communities associates with different rice varieties i.e. beta diversity. Watch this video for more information.

Phylogenetic tree

Both rooted and unrooted trees can be generated by this command.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime phylogeny align-to-tree-mafft-fasttree \
  --i-sequences representative-sequences.qza \
  --o-rooted-tree rooted-tree.qza \
  --o-tree unrooted-tree.qza \
  --o-alignment aligned-rep-seqs.qza \
  --o-masked-alignment masked-aligned-rep-seqs.qza

Alpha rarefaction Plot

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime diversity alpha-rarefaction \
  --i-table table.qza \
  --i-phylogeny rooted-tree.qza \
  --p-max-depth 1321 \
  --m-metadata-file metadata.tsv \
  --p-steps 4 \
  --p-iterations 4 \
  --o-visualization alpha-rarefaction.qzv

Revision Questions

  1. How did we decide as maximum depth 1321 ?

The max depth setting will depend on the number of sequences in your samples. The value that you provide for –p-max-depth should be determined by reviewing the OTU Frequency per sample information presented in the table.qzv file that was created above. Also observe that, do the refraction curves for each sample plateau? If they don’t, the samples haven’t been sequenced deeply enough to capture the full diversity of the AM fungal communities, which is shown on the y-axis. At what sequencing depth (x-axis) do your curves plateau? This value will be important for downstream analyses, particularly for alpha diversity analyses. Considering both features and samples retained is very important.

You may want to increase that value if the lines in the resulting rarefaction plot don’t appear to be leveling out, or decrease that value if you seem to be losing many of your samples due to low total frequencies closer to the minimum sampling depth than the maximum sampling depth.

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime diversity core-metrics-phylogenetic \
  --i-table table.qza \
  --i-phylogeny rooted-tree.qza \
  --p-sampling-depth 401 \
  --m-metadata-file metadata.tsv \
  --output-dir diversity-core-metrics-phylogenetic
  • diversity-core-metrics-phylogenetic/evenness_vector.qza | download | view
  • diversity-core-metrics-phylogenetic/faith_pd_vector.qza | download | view
  • diversity-core-metrics-phylogenetic/unweighted_unifrac_distance_matrix.qza | download | view
  • diversity-core-metrics-phylogenetic/bray_curtis_pcoa_results.qza | download | view
  • diversity-core-metrics-phylogenetic/shannon_vector.qza | download | view
  • diversity-core-metrics-phylogenetic/rarefied_table.qza | download | view
  • diversity-core-metrics-phylogenetic/weighted_unifrac_distance_matrix.qza | download | view
  • diversity-core-metrics-phylogenetic/jaccard_pcoa_results.qza | download | view
  • diversity-core-metrics-phylogenetic/unweighted_unifrac_emperor.qzv | download | view
  • diversity-core-metrics-phylogenetic/weighted_unifrac_pcoa_results.qza | download | view
  • diversity-core-metrics-phylogenetic/observed_features_vector.qza | download | view
  • diversity-core-metrics-phylogenetic/jaccard_distance_matrix.qza | download | view
  • diversity-core-metrics-phylogenetic/jaccard_emperor.qzv | download | view
  • diversity-core-metrics-phylogenetic/bray_curtis_emperor.qzv | download | view
  • diversity-core-metrics-phylogenetic/weighted_unifrac_emperor.qzv | download | view
  • diversity-core-metrics-phylogenetic/bray_curtis_distance_matrix.qza | download | view
  • diversity-core-metrics-phylogenetic/unweighted_unifrac_pcoa_results.qza | download | view

Alpha Diversity and Community Richness

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime diversity alpha-group-significance \
  --i-alpha-diversity diversity-core-metrics-phylogenetic/shannon_vector.qza \
  --m-metadata-file metadata.tsv \
  --o-visualization shannon-group-significance.qzv
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime diversity alpha-group-significance \
  --i-alpha-diversity diversity-core-metrics-phylogenetic/evenness_vector.qza \
  --m-metadata-file metadata.tsv \
  --o-visualization evenness-group-significance.qzv
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime diversity alpha-group-significance \
  --i-alpha-diversity diversity-core-metrics-phylogenetic/faith_pd_vector.qza \
  --m-metadata-file metadata.tsv \
  --o-visualization faith-group.qzv

Revision Questions

  1. Is species richness same as number of ASVs ?

Beta Diversity

[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime diversity beta-group-significance \
  --i-distance-matrix diversity-core-metrics-phylogenetic/unweighted_unifrac_distance_matrix.qza \
  --m-metadata-file metadata.tsv \
  --m-metadata-column env_broad_scale \
  --p-method permanova \
  --p-pairwise \
  --p-permutations 999 \
  --o-visualization unweighted-unifrac-env-broad-scale-significance.qzv
  • unweighted-unifrac-env-broad-scale-significance.qzv | download | view
[Command Line]
[Python API]
[Galaxy]
[R API]
[View Source]
qiime diversity beta-group-significance \
  --i-distance-matrix diversity-core-metrics-phylogenetic/unweighted_unifrac_distance_matrix.qza \
  --m-metadata-file metadata.tsv \
  --m-metadata-column Sample_Name \
  --p-method permanova \
  --p-pairwise \
  --p-permutations 999 \
  --o-visualization unweighted-unifrac-sample-name-significance.qzv
  • unweighted-unifrac-sample-name-significance.qzv | download | view