{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# “Moving Pictures” tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this tutorial you’ll use QIIME 2 to perform an analysis of human microbiome samples from two individuals at four body sites at five timepoints, the first of which immediately followed antibiotic usage.\n", "A study based on these samples was originally published in Caporaso et al. (2011). The data used in this tutorial were sequenced on an Illumina HiSeq using the Earth Microbiome Project hypervariable region 4 (V4) 16S rRNA sequencing protocol." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before beginning this tutorial, create a new directory and change to that directory." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "mkdir qiime2-moving-pictures-tutorial\n", "cd qiime2-moving-pictures-tutorial" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sample metadata" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Before starting the analysis, explore the sample metadata to familiarize yourself with the samples used in this study. The sample metadata is available as a Google Sheet. You can download this file as tab-separated text by selecting File > Download as > Tab-separated values. Alternatively, 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." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wget -O \"sample-metadata.tsv\" \"https://data.qiime2.org/2017.5/tutorials/moving-pictures/sample_metadata.tsv\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Obtaining and importing data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Download the sequence reads that we’ll use in this analysis. In this tutorial we’ll work with a small subset of the complete sequence data so that the commands will run quickly." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mkdir emp-single-end-sequences\n", "wget -O \"emp-single-end-sequences/barcodes.fastq.gz\" \"https://data.qiime2.org/2017.5/tutorials/moving-pictures/emp-single-end-sequences/barcodes.fastq.gz\"\n", "wget -O \"emp-single-end-sequences/sequences.fastq.gz\" \"https://data.qiime2.org/2017.5/tutorials/moving-pictures/emp-single-end-sequences/sequences.fastq.gz\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All data that is used as input to QIIME 2 is in form of QIIME 2 artifacts, which contain information about the type of data and the source of the data. So, the first thing we need to do is import these sequence data files into a QIIME 2 artifact. The semantic type of this QIIME 2 artifact is EMPSingleEndSequences. EMPSingleEndSequences QIIME 2 artifacts contain sequences that are multiplexed, meaning that the sequences have not yet been assigned to samples (hence the inclusion of both sequences.fastq.gz and barcodes.fastq.gz files, where the barcodes.fastq.gz contains the barcode read associated with each sequence in sequences.fastq.gz.) To learn about how to import sequence data in other formats, see the importing data tutorial." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime tools import \\\n", " --type EMPSingleEndSequences \\\n", " --input-path emp-single-end-sequences \\\n", " --output-path emp-single-end-sequences.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Output artifacts: emp-single-end-sequences.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Tip:\n", "Links are included to view and download precomputed QIIME 2 artifacts and visualizations created by commands in the documentation. For example, the command above created a single emp-single-end-sequences.qza file, and a corresponding precomputed file is linked above. You can view precomputed QIIME 2 artifacts and visualizations without needing to install additional software (e.g. QIIME 2)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "QIIME 1 Users\n", "In QIIME 1, we generally suggested performing demultiplexing through QIIME (e.g., with split_libraries.py or split_libraries_fastq.py) as this step also performed quality control of sequences. We now separate the demultiplexing and quality control steps, so you can begin QIIME 2 with either multiplexed sequences (as we’re doing here) or demultiplexed sequences." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Demultiplexing sequences" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To demultiplex sequences we need to know which barcode sequence is associated with each sample. This information is contained in the sample metadata file. You can run the following commands to demultiplex the sequences (the demux emp-single command refers to the fact that these sequences are barcoded according to the Earth Microbiome Project protocol, and are single-end reads). The demux.qza QIIME 2 artifact will contain the demultiplexed sequences." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime demux emp-single \\\n", " --i-seqs emp-single-end-sequences.qza \\\n", " --m-barcodes-file sample-metadata.tsv \\\n", " --m-barcodes-category BarcodeSequence \\\n", " --o-per-sample-sequences demux.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After demultiplexing, it’s useful to generate a summary of the demultiplexing results. This allows you to determine how many sequences were obtained per sample, and also to get a summary of the distribution of sequence qualities at each position in your sequence data." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime demux summarize \\\n", " --i-data demux.qza \\\n", " --o-visualization demux.qzv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note:\n", "All QIIME 2 visualizers (i.e., commands that take a --o-visualization parameter) will generate a .qzv file. You can view these files with qiime tools view. We provide the command to view this first visualization, but for the remainder of this tutorial we’ll tell you to view the resulting visualization after running a visualizer, which means that you should run qiime tools view on the .qzv file that was generated." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime tools view demux.qzv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, you can view QIIME 2 artifacts and visualizations at view.qiime2.org by uploading files or providing URLs. There are also precomputed results that can be viewed or downloaded after each step in the tutorial. These can be used if you’re reading the tutorial, but not running the commands yourself." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Sequence quality control and feature table construction¶" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "QIIME 2 plugins are available for several quality control methods, including DADA2, Deblur, and basic quality-score-based filtering. In this tutorial we present this step using DADA2 and Deblur. These steps are interchangeable, so you can use whichever of these you prefer. The result of both of these methods will be a FeatureTable[Frequency] QIIME 2 artifact, which contains counts (frequencies) of each unique sequence in each sample in the dataset, and a FeatureData[Sequence] QIIME 2 artifact, which maps feature identifiers in the FeatureTable to the sequences they represent." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note\n", "As you work through one or both of the options in this section, you’ll create artifacts with filenames that are specific to the method that you’re running (e.g., the feature table that you generate with dada2 denoise-single will be called table-dada2.qza). After creating these artifacts you’ll rename the artifacts from one of the two options to more generic filenames (e.g., table.qza). This process of creating a specific name for an artifact and then renaming it is only done to allow you to choose which of the two options you’d like to use for this step, and then complete the tutorial without paying attention to that choice again. It’s important to note that in this step, or any step in QIIME 2, the filenames that you’re giving to artifacts or visualizations are not important." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "QIIME 1 Users\n", "The FeatureTable[Frequency] QIIME 2 artifact is the equivalent of the QIIME 1 OTU or BIOM table, and the FeatureData[Sequence] QIIME 2 artifact is the equivalent of the QIIME 1 representative sequences file. Because the “OTUs” resulting from DADA2 and Deblur are created by grouping unique sequences, these are the equivalent of 100% OTUs from QIIME 1, and are generally referred to as sequence variants. In QIIME 2, these OTUs are higher resolution than the QIIME 1 default of 97% OTUs, and they’re higher quality since these quality control steps are better than those implemented in QIIME 1. This should therefore result in more accurate estimates of diversity and taxonomic composition of samples than was achieved with QIIME 1." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Option 1: DADA2¶" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "DADA2 is a pipeline for detecting and correcting (where possible) Illumina amplicon sequence data. As implemented in the q2-dada2 plugin, this quality control process will additionally filter any phiX reads (commonly present in marker gene Illumina sequence data) that are identified in the sequencing data, and will filter chimeric sequences.\n", "\n", "The dada2 denoise-single method requires two parameters that are used in quality filtering: --p-trim-left m, which trims off the first m bases of each sequence, and --p-trunc-len n which truncates each sequence at position n. This allows the user to remove low quality regions of the sequences. To determine what values to pass for these two parameters, you should review the Interactive Quality Plot tab in the demux.qzv file that was generated by qiime demux summarize above." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the demux.qzv quality plots, we see that the quality of the initial bases seems to be high, so we won’t trim any bases from the beginning of the sequences. The quality seems to drop off around position 120, so we’ll truncate our sequences at 120 bases. This next command may take up to 10 minutes to run, and is the slowest step in this tutorial." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime dada2 denoise-single \\\n", " --i-demultiplexed-seqs demux.qza \\\n", " --p-trim-left 0 \\\n", " --p-trunc-len 120 \\\n", " --o-representative-sequences rep-seqs-dada2.qza \\\n", " --o-table table-dada2.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you’d like to continue the tutorial using this FeatureTable (opposed to the Deblur feature table generated in Option 2), run the following commands." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "mv rep-seqs-dada2.qza rep-seqs.qza\n", "mv table-dada2.qza table.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Output artifacts:\n", "\n", "rep-seqs.qza\n", "table.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Option 2: Deblur" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Deblur uses sequence error profiles to associate erroneous sequence reads with the true biological sequence from which they are derived, resulting in high quality sequence variant data. This is applied in two steps. First, an initial quality filtering process based on quality scores is applied. This method is an implementation of the quality filtering approach described by Bokulich et al. (2013)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime quality-filter q-score \\\n", " --i-demux demux.qza \\\n", " --o-filtered-sequences demux-filtered.qza \\\n", " --o-filter-stats demux-filter-stats.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note\n", "In the Deblur paper, the authors used different quality-filtering parameters than what they currently recommend after additional analysis. The parameters used here are based on those more recent recommendations." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, the Deblur workflow is applied using the qiime deblur denoise-16S method. This method requires one parameter that is used in quality filtering, --p-trim-length n which truncates the sequences at position n. In general, the Deblur developers recommend setting this value to a length where the median quality score begins to drop too low. On these data, the quality plots (prior to quality filtering) suggest a reasonable choice is in the 115 to 130 sequence position range. This is a subjective assessment. One situation where you might deviate from that recommendation is when performing a meta-analysis across multiple sequencing runs. In this type of meta-analysis, it is critical that the read lengths be the same for all of the sequencing runs being compared to avoid introducing a study-specific bias. Since we already using a trim length of 120 for qiime dada2 denoise-single, and since 120 is reasonable given the quality plots, we’ll pass --p-trim-length 120. This next command may take up to 10 minutes to run." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime deblur denoise-16S \\\n", " --i-demultiplexed-seqs demux-filtered.qza \\\n", " --p-trim-length 120 \\\n", " --o-representative-sequences rep-seqs-deblur.qza \\\n", " --o-table table-deblur.qza \\\n", " --o-stats deblur-stats.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note\n", "The two commands used in this section generate QIIME 2 artifacts containing summary statistics. To view those summary statistics, you can visualize them using qiime quality-filter visualize-stats and qiime deblur visualize-stats, respectively." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you’d like to continue the tutorial using this FeatureTable (opposed to the DADA2 feature table generated in Option 1), run the following commands." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mv rep-seqs-deblur.qza rep-seqs.qza\n", "mv table-deblur.qza table.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## FeatureTable and FeatureData summaries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After the quality filtering step completes, you’ll want to explore the resulting data. You can do this using the following two commands, which will create visual summaries of the data. The feature-table summarize command will give you information on how many sequences are associated with each sample and with each feature, histograms of those distributions, and some related summary statistics. The feature-table tabulate-seqs command will provide a mapping of feature IDs to sequences, and provide links to easily BLAST each sequence against the NCBI nt database. The latter visualization will be very useful later in the tutorial, when you want to learn more about specific features that are important in the data set." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime feature-table summarize \\\n", " --i-table table.qza \\\n", " --o-visualization table.qzv \\\n", " --m-sample-metadata-file sample-metadata.tsv\n", "qiime feature-table tabulate-seqs \\\n", " --i-data rep-seqs.qza \\\n", " --o-visualization rep-seqs.qzv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate a tree for phylogenetic diversity analyses¶" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "QIIME supports several phylogenetic diversity metrics, including Faith’s Phylogenetic Diversity and weighted and unweighted UniFrac. In addition to counts of features per sample (i.e., the data in the FeatureTable[Frequency] QIIME 2 artifact), these metrics require a rooted phylogenetic tree relating the features to one another. This information will be stored in a Phylogeny[Rooted] QIIME 2 artifact. The following steps will generate this QIIME 2 artifact.\n", "\n", "First, we perform a multiple sequence alignment of the sequences in our FeatureData[Sequence] to create a FeatureData[AlignedSequence] QIIME 2 artifact. Here we do this with the mafft program." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime alignment mafft \\\n", " --i-sequences rep-seqs.qza \\\n", " --o-alignment aligned-rep-seqs.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we mask (or filter) the alignment to remove positions that are highly variable. These positions are generally considered to add noise to a resulting phylogenetic tree." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "qiime alignment mask \\\n", " --i-alignment aligned-rep-seqs.qza \\\n", " --o-masked-alignment masked-aligned-rep-seqs.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we’ll apply FastTree to generate a phylogenetic tree from the masked alignment." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime phylogeny fasttree \\\n", " --i-alignment masked-aligned-rep-seqs.qza \\\n", " --o-tree unrooted-tree.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The FastTree program creates an unrooted tree, so in the final step in this section we apply midpoint rooting to place the root of the tree at the midpoint of the longest tip-to-tip distance in the unrooted tree." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime phylogeny midpoint-root \\\n", " --i-tree unrooted-tree.qza \\\n", " --o-rooted-tree rooted-tree.qza" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Alpha and beta diversity analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "QIIME 2’s diversity analyses are available through the q2-diversity plugin, which supports computing alpha and beta diversity metrics, applying related statistical tests, and generating interactive visualizations. We’ll first apply the core-metrics method, which rarefies a FeatureTable[Frequency] to a user-specified depth, and then computes a series of alpha and beta diversity metrics. The metrics computed by default are:\n", "\n", "Alpha diversity\n", "Shannon’s diversity index (a quantitative measure of community richness)\n", "Observed OTUs (a qualitative measure of community richness)\n", "Faith’s Phylogenetic Diversity (a qualitiative measure of community richness that incorporates phylogenetic relationships between the features)\n", "Evenness (or Pielou’s Evenness; a measure of community evenness)\n", "\n", "Beta diversity\n", "Jaccard distance (a qualitative measure of community dissimilarity)\n", "Bray-Curtis distance (a quantitative measure of community dissimilarity)\n", "unweighted UniFrac distance (a qualitative measure of community dissimilarity that incorporates phylogenetic relationships between the features)\n", "weighted UniFrac distance (a quantitative measure of community dissimilarity that incorporates phylogenetic relationships between the features)\n", "\n", "The only parameter that needs to be provided to this script is --p-sampling-depth, which is the even sampling (i.e. rarefaction) depth. Because most diversity metrics are sensitive to different sampling depths across different samples, this script will randomly subsample the counts from each sample to the value provided for this parameter. For example, if you provide --p-sampling-depth 500, this step will subsample the counts in each sample without replacement so that each sample in the resulting table has a total count of 500. If the total count for any sample(s) are smaller than this value, those samples will be dropped from the diversity analysis. Choosing this value is tricky. We recommend making your choice by reviewing the information presented in the table.qzv file that was created above and choosing a value that is as high as possible (so you retain more sequences per sample) while excluding as few samples as possible." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime diversity core-metrics \\\n", " --i-phylogeny rooted-tree.qza \\\n", " --i-table table.qza \\\n", " --p-sampling-depth 1080 \\\n", " --output-dir core-metrics-results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here we set the --p-sampling-depth parameter to 1080. This value was chosen based on the number of sequences in the L3S360 sample because it’s close to the number of sequences in the next few samples that have higher sequence counts, and because it is considerably higher (relatively) than the number of sequences in the one sample that has fewer sequences. This will allow us to retain most of our samples. The one sample that has fewer sequences will be dropped from the core-metrics analyses and anything that uses these results." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note\n", "The sampling depth of 1080 was chosen based on the DADA2 feature table summary. If you are using a Deblur feature table rather than a DADA2 feature table, you might want to choose a different even sampling depth. Apply the logic from the previous paragraph to help you choose an even sampling depth." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note\n", "In many Illumina runs you’ll observe a few samples that have very low sequence counts. You will typically want to exclude those from the analysis by choosing a larger value for the sampling depth at this stage." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After computing diversity metrics, we can begin to explore the microbial composition of the samples in the context of the sample metadata. This information is present in the sample metadata file that was downloaded earlier.\n", "\n", "We’ll first test for associations between discrete metadata categories and alpha diversity data. We’ll do that here for the Faith Phylogenetic Diversity (a measure of community richness) and evenness metrics." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime diversity alpha-group-significance \\\n", " --i-alpha-diversity core-metrics-results/faith_pd_vector.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --o-visualization core-metrics-results/faith-pd-group-significance.qzv\n", "\n", "qiime diversity alpha-group-significance \\\n", " --i-alpha-diversity core-metrics-results/evenness_vector.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --o-visualization core-metrics-results/evenness-group-significance.qzv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this data set, no continuous sample metadata categories (e.g., DaysSinceExperimentStart) are correlated with alpha diversity, so we won’t test for those associations here. If you’re interested in performing those tests (for this data set, or for others), you can use the qiime diversity alpha-correlation command.\n", "\n", "Next we’ll analyze sample composition in the context of discrete metadata using PERMANOVA (first described in Anderson (2001)) using the beta-group-significance command. The following commands will test whether distances between samples within a group, such as samples from the same body site (e.g., gut), are more similar to each other then they are to samples from the other groups (e.g., tongue, left palm, and right palm). If you call this command with the --p-pairwise parameter, as we’ll do here, it will also perform pairwise tests that will allow you to determine which specific pairs of groups (e.g., tongue and gut) differ from one another, if any. This command can be slow to run, especially when passing --p-pairwise, since it is based on permutation tests. So, unlike the previous commands, we’ll run this on specific categories of metadata that we’re interested in exploring, rather than all metadata categories that it’s applicable to. Here we’ll apply this to our unweighted UniFrac distances, using two sample metadata categories, as follows." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime diversity beta-group-significance \\\n", " --i-distance-matrix core-metrics-results/unweighted_unifrac_distance_matrix.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --m-metadata-category BodySite \\\n", " --o-visualization core-metrics-results/unweighted-unifrac-body-site-significance.qzv \\\n", " --p-pairwise\n", "\n", "qiime diversity beta-group-significance \\\n", " --i-distance-matrix core-metrics-results/unweighted_unifrac_distance_matrix.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --m-metadata-category Subject \\\n", " --o-visualization core-metrics-results/unweighted-unifrac-subject-group-significance.qzv \\\n", " --p-pairwise" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, none of the continuous sample metadata that we have for this data set are correlated with sample composition, so we won’t test for those associations here. If you’re interested in performing those tests, you can use the qiime diversity beta-correlation and qiime diversity bioenv commands.\n", "\n", "Finally, ordination is a popular approach for exploring microbial community composition in the context of sample metadata. We can use the Emperor tool to explore principal coordinates (PCoA) plots in the context of sample metadata. PCoA is run as part of the core-metrics command, so we can generate these plots for unweighted UniFrac and Bray-Curtis as follows. The --p-custom-axis parameter that we pass here is very useful for exploring temporal data. The resulting plot will contain axes for principal coordinate 1, principal coordinate 2, and days since the experiment start. This is useful for exploring how the samples change over time." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime emperor plot \\\n", " --i-pcoa core-metrics-results/unweighted_unifrac_pcoa_results.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --p-custom-axis DaysSinceExperimentStart \\\n", " --o-visualization core-metrics-results/unweighted-unifrac-emperor.qzv\n", "\n", "qiime emperor plot \\\n", " --i-pcoa core-metrics-results/bray_curtis_pcoa_results.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --p-custom-axis DaysSinceExperimentStart \\\n", " --o-visualization core-metrics-results/bray-curtis-emperor.qzv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Taxonomic analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the next sections we’ll begin to explore the taxonomic composition of the samples, and again relate that to sample metadata. The first step in this process is to assign taxonomy to the sequences in our FeatureData[Sequence] QIIME 2 artifact. We’ll do that using a pre-trained Naive Bayes classifier and the q2-feature-classifier plugin. This classifier was trained on the Greengenes 13_8 99% OTUs, where the sequences have been trimmed to only include 250 bases from the region of the 16S that was sequenced in this analysis (the V4 region, bound by the 515F/806R primer pair). We’ll apply this classifier to our sequences, and we can generate a visualization of the resulting mapping from sequence to taxonomy." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note\n", "Taxonomic classifiers perform best when they are trained based on your specific sample preparation and sequencing parameters, including the primers that were used for amplification and the length of your sequence reads. Therefore in general you should follow the instructions in Training feature classifiers with q2-feature-classifier to train your own taxonomic classifiers. We provide some common classifiers on our data resources page, including Silva-based 16S classifiers, though in the future we may stop providing these in favor of having users train their own classifiers which will be most relevant to their sequence data." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Please select a download option that is most appropriate for your environment:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "wget -O \"gg-13-8-99-515-806-nb-classifier.qza\" \"https://data.qiime2.org/2017.5/common/gg-13-8-99-515-806-nb-classifier.qza\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime feature-classifier classify-sklearn \\\n", " --i-classifier gg-13-8-99-515-806-nb-classifier.qza \\\n", " --i-reads rep-seqs.qza \\\n", " --o-classification taxonomy.qza\n", "\n", "qiime taxa tabulate \\\n", " --i-data taxonomy.qza \\\n", " --o-visualization taxonomy.qzv\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Next, we can view the taxonomic composition of our samples with interactive bar plots. Generate those plots with the following command and then open the visualization." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime taxa barplot \\\n", " --i-table table.qza \\\n", " --i-taxonomy taxonomy.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --o-visualization taxa-bar-plots.qzv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Differential abundance analysis" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, we can quantify the process of identifying taxa that are differentially abundant (or present in different abundances) across sample groups. We do that using ANCOM (Mandal et al. (2015)), which is implemented in the q2-composition plugin. ANCOM operates on a FeatureTable[Composition] QIIME 2 artifact, which is based on frequencies of features on a per-sample basis, but cannot tolerate frequencies of zero. To build the composition artifact, a FeatureTable[Frequency] artifact must be provided to add-pseudocount (an imputation method), which will produce the FeatureTable[Composition] artifact. We can then run ANCOM on the BodySite category to determine what features differ in abundance across body sites. This step may take about 5 minutes to complete. .. command-block:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime composition add-pseudocount \\\n", " --i-table table.qza \\\n", " --o-composition-table comp-table.qza\n", "\n", "qiime composition ancom \\\n", " --i-table comp-table.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --m-metadata-category BodySite \\\n", " --o-visualization ancom-BodySite.qzv" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We’re also often interested in performing a differential abundance test at a specific taxonomic level. To do this, we can collapse the features in our FeatureTable[Frequency] at the taxonomic level of interest, and then re-run the above steps." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "qiime taxa collapse \\\n", " --i-table table.qza \\\n", " --i-taxonomy taxonomy.qza \\\n", " --p-level 2 \\\n", " --o-collapsed-table table-l2.qza\n", "\n", "qiime composition add-pseudocount \\\n", " --i-table table-l2.qza \\\n", " --o-composition-table comp-table-l2.qza\n", "\n", "qiime composition ancom \\\n", " --i-table comp-table-l2.qza \\\n", " --m-metadata-file sample-metadata.tsv \\\n", " --m-metadata-category BodySite \\\n", " --o-visualization l2-ancom-BodySite.qzv" ] } ], "metadata": { "kernelspec": { "display_name": "Bash", "language": "bash", "name": "bash" }, "language_info": { "codemirror_mode": "shell", "file_extension": ".sh", "mimetype": "text/x-sh", "name": "bash" } }, "nbformat": 4, "nbformat_minor": 2 }