Skip to content

Instantly share code, notes, and snippets.

@tkosciol
Last active August 13, 2020 13:26
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tkosciol/29de5198a4be81559a075756c2490fde to your computer and use it in GitHub Desktop.
Save tkosciol/29de5198a4be81559a075756c2490fde to your computer and use it in GitHub Desktop.
QIIME2 Moving Pictures tutorial via Python API (alpha version)
Display the source blob
Display the rendered blob
Raw
{
"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. 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 you start:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**close this notebook and jupyter session, and run `jupyter serverextension enable --py qiime2 --sys-prefix`. Then, restart this notebook**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's import all necessary modules"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"%matplotlib inline\n",
"import qiime2\n",
"from tempfile import mkdtemp\n",
"from qiime2.plugins import demux, deblur, quality_filter, \\\n",
" metadata, feature_table, alignment, \\\n",
" phylogeny, diversity, emperor, feature_classifier, \\\n",
" taxa, composition"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Before beginning this tutorial, create a new directory and change to that directory. \n",
"**make sure to change the path in `workdir`**"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"!mkdir qiime2-moving-pictures-tutorial"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial\n"
]
}
],
"source": [
"workdir='/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial'\n",
"%cd $workdir"
]
},
{
"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": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2018-04-13 09:22:54-- https://data.qiime2.org/2018.2/tutorials/moving-pictures/sample_metadata.tsv\n",
"Resolving data.qiime2.org... 2400:cb00:2048:1::681b:ab9e, 2400:cb00:2048:1::681b:aa9e, 104.27.170.158, ...\n",
"Connecting to data.qiime2.org|2400:cb00:2048:1::681b:ab9e|:443... connected.\n",
"HTTP request sent, awaiting response... 302 FOUND\n",
"Location: https://docs.google.com/spreadsheets/d/1LpGUOdXwCs6m4xR9DoB8yOl_22v1hczjZHyA41DhDXg/export?gid=0&format=tsv [following]\n",
"--2018-04-13 09:22:54-- https://docs.google.com/spreadsheets/d/1LpGUOdXwCs6m4xR9DoB8yOl_22v1hczjZHyA41DhDXg/export?gid=0&format=tsv\n",
"Resolving docs.google.com... 2607:f8b0:4007:80b::200e, 216.58.193.206\n",
"Connecting to docs.google.com|2607:f8b0:4007:80b::200e|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: unspecified [text/tab-separated-values]\n",
"Saving to: '/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial/sample-metadata.tsv'\n",
"\n",
"/Users/tomasz/tmp/q [ <=> ] 3.70K --.-KB/s in 0.001s \n",
"\n",
"2018-04-13 09:22:54 (2.57 MB/s) - '/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial/sample-metadata.tsv' saved [3785]\n",
"\n"
]
}
],
"source": [
"!wget -O $workdir/\"sample-metadata.tsv\" \"https://data.qiime2.org/2018.2/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": 7,
"metadata": {},
"outputs": [],
"source": [
"!mkdir $workdir/emp-single-end-sequences"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2018-04-13 09:22:55-- https://data.qiime2.org/2018.2/tutorials/moving-pictures/emp-single-end-sequences/barcodes.fastq.gz\n",
"Resolving data.qiime2.org... 2400:cb00:2048:1::681b:ab9e, 2400:cb00:2048:1::681b:aa9e, 104.27.170.158, ...\n",
"Connecting to data.qiime2.org|2400:cb00:2048:1::681b:ab9e|:443... connected.\n",
"HTTP request sent, awaiting response... 302 FOUND\n",
"Location: https://s3-us-west-2.amazonaws.com/qiime2-data/2018.2/tutorials/moving-pictures/emp-single-end-sequences/barcodes.fastq.gz [following]\n",
"--2018-04-13 09:22:56-- https://s3-us-west-2.amazonaws.com/qiime2-data/2018.2/tutorials/moving-pictures/emp-single-end-sequences/barcodes.fastq.gz\n",
"Resolving s3-us-west-2.amazonaws.com... 52.218.213.16\n",
"Connecting to s3-us-west-2.amazonaws.com|52.218.213.16|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 3783785 (3.6M) [application/x-gzip]\n",
"Saving to: '/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial/emp-single-end-sequences/barcodes.fastq.gz'\n",
"\n",
"/Users/tomasz/tmp/q 100%[===================>] 3.61M 4.62MB/s in 0.8s \n",
"\n",
"2018-04-13 09:22:57 (4.62 MB/s) - '/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial/emp-single-end-sequences/barcodes.fastq.gz' saved [3783785/3783785]\n",
"\n"
]
}
],
"source": [
"!wget -O $workdir/\"emp-single-end-sequences/barcodes.fastq.gz\" \"https://data.qiime2.org/2018.2/tutorials/moving-pictures/emp-single-end-sequences/barcodes.fastq.gz\""
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2018-04-13 09:22:57-- https://data.qiime2.org/2018.2/tutorials/moving-pictures/emp-single-end-sequences/sequences.fastq.gz\n",
"Resolving data.qiime2.org... 2400:cb00:2048:1::681b:ab9e, 2400:cb00:2048:1::681b:aa9e, 104.27.170.158, ...\n",
"Connecting to data.qiime2.org|2400:cb00:2048:1::681b:ab9e|:443... connected.\n",
"HTTP request sent, awaiting response... 302 FOUND\n",
"Location: https://s3-us-west-2.amazonaws.com/qiime2-data/2018.2/tutorials/moving-pictures/emp-single-end-sequences/sequences.fastq.gz [following]\n",
"--2018-04-13 09:22:57-- https://s3-us-west-2.amazonaws.com/qiime2-data/2018.2/tutorials/moving-pictures/emp-single-end-sequences/sequences.fastq.gz\n",
"Resolving s3-us-west-2.amazonaws.com... 52.218.213.16\n",
"Connecting to s3-us-west-2.amazonaws.com|52.218.213.16|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 25303756 (24M) [binary/octet-stream]\n",
"Saving to: '/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial/emp-single-end-sequences/sequences.fastq.gz'\n",
"\n",
"/Users/tomasz/tmp/q 100%[===================>] 24.13M 10.0MB/s in 2.4s \n",
"\n",
"2018-04-13 09:23:00 (10.0 MB/s) - '/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial/emp-single-end-sequences/sequences.fastq.gz' saved [25303756/25303756]\n",
"\n"
]
}
],
"source": [
"!wget -O $workdir/\"emp-single-end-sequences/sequences.fastq.gz\" \"https://data.qiime2.org/2018.2/tutorials/moving-pictures/emp-single-end-sequences/sequences.fastq.gz\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### import data as a qiime2 artifact"
]
},
{
"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.\n",
"\n",
"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": 3,
"metadata": {},
"outputs": [],
"source": [
"single_end_sequences = qiime2.Artifact.import_data('EMPSingleEndSequences', workdir+'/emp-single-end-sequences')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### read metadata into `qiime2.Metadata` object"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"sample_metadata = qiime2.Metadata.load(workdir+'/sample-metadata.tsv')"
]
},
{
"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": 5,
"metadata": {},
"outputs": [],
"source": [
"demux_sequences = demux.methods.emp_single(single_end_sequences,\n",
" sample_metadata.get_column('BarcodeSequence'))"
]
},
{
"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": 6,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/anaconda/envs/q2/lib/python3.5/site-packages/matplotlib/axes/_axes.py:6462: UserWarning: The 'normed' kwarg is deprecated, and has been replaced by the 'density' kwarg.\n",
" warnings.warn(\"The 'normed' kwarg is deprecated, and has been \"\n"
]
},
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-kwnrovgu')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 7347b4d6-91de-4677-b1c4-9fd79d2db691>"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYIAAAEKCAYAAAAfGVI8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAFaFJREFUeJzt3XuUZWV95vHvQ6MiBgVCawiKDY6SsIhA20QTohguBhGv0YSLSpSRjMFbHDPC4Chr1spacYzGOGYFG0UuAirihXgZIQzCOAsaG2wE5I4EEQKlZETUgMBv/ti75HTZVX26us451f1+P2udVfu8tc9+f7X7dD317r3Pu1NVSJLatcWkC5AkTZZBIEmNMwgkqXEGgSQ1ziCQpMYZBJLUOINAkhpnEEhS4wwCSWrclpMuYBg77LBDLVu2bNJlSNIm5YorrvhhVS1d33qbRBAsW7aM1atXT7oMSdqkJPmXYdbz0JAkNc4gkKTGGQSS1DiDQJIaZxBIUuMMAklqnEEgSY0zCCSpcQaBJDVuk/hk8cY4a9Xtky5hk3LEc3eedAmSxswRgSQ1ziCQpMYZBJLUOINAkhpnEEhS4wwCSWqcQSBJjTMIJKlxBoEkNc4gkKTGGQSS1LiRBUGSU5Lck+SagbYPJLk+yXeSfCHJtqPqX5I0nFGOCE4FDp7RdgGwR1U9G7gROH6E/UuShjCyIKiqS4B7Z7SdX1UP9U8vA546qv4lScOZ5DmCNwJfm2D/kiQmFARJTgAeAs6cY51jkqxOsnpqamp8xUlSY8YeBEmOAg4Fjqyqmm29qlpZVSuqasXSpUvHV6AkNWasdyhLcjDwbmC/qvrZ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x8KcnldL+sZvtrfS430P3CfgrdbJH/nuTjdOcOruxHGlOs5xaBVXVXkuPppjoO8NWqWt+UwS8E/irJL4D7gddX1VSSPwPOTvK4fr33VNWN6e4695UkPwS+CezRf/9cuqmv19Adbrqxr+m7Sd5Dd9e6LehmyDwWmOt2oG8HViY5mm6k8OaqunSW7fwc+GTfBrCukYc2U84+Kk1Yf5jqXVV16KRrUZs8NCRJjXNEIEmNc0QgSY0zCCSpcQaBJDXOIJCkxhkEktQ4g0CSGvf/AYtnvA9Ggnk8AAAAAElFTkSuQmCC\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"demux_summary = demux.visualizers.summarize(demux_sequences.per_sample_sequences)\n",
"demux_summary.visualization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Sequence quality control and feature table construction\n",
"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": [
"## Option 1: DADA2\n",
"skipped"
]
},
{
"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": 7,
"metadata": {},
"outputs": [],
"source": [
"demux_filter_stats = quality_filter.methods.q_score(demux_sequences.per_sample_sequences)"
]
},
{
"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": 8,
"metadata": {},
"outputs": [],
"source": [
"deblur_sequences = deblur.methods.denoise_16S(demux_sequences.per_sample_sequences,\n",
" trim_length=120,\n",
" sample_stats=True)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-kmz7ikrv')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 0970a3ab-755f-4dd7-bf1e-f07eb6526a0f>"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"filter_stats = metadata.visualizers.tabulate(demux_filter_stats.filter_stats.view(qiime2.Metadata))\n",
"filter_stats.visualization"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-c_yj1i_b')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 1db8d0c7-8fba-44f5-9c0c-6254825022b1>"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"deblur_stats = deblur.visualizers.visualize_stats(deblur_sequences.stats)\n",
"deblur_stats.visualization"
]
},
{
"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": 12,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/anaconda/envs/q2/lib/python3.5/site-packages/matplotlib/axes/_axes.py:6462: UserWarning: The 'normed' kwarg is deprecated, and has been replaced by the 'density' kwarg.\n",
" warnings.warn(\"The 'normed' kwarg is deprecated, and has been \"\n"
]
},
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-bn3vvyxp')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: ac575a48-f206-44e6-b3bb-5875d4a1279e>"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAYgAAAEOCAYAAACTqoDjAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAFaBJREFUeJzt3X2wZHV95/H3BwRFHMY8aEqBERQwktUVvYDolpGsElAHlJAgaBKVMJIIkbLiiquRZK0sRRJTWTY+TQyOpgQCJIuMoqhEJHERZoan8FgQVmWCJSDWEBDk6bt/dI80N+f2PT0z53bf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/APwX4FHg5fQCA2An4K7++o8Bf9/i5/ivQ9r4jSSr6P1+P4feLGNN4TXMeQOntw4BDt98dAY8DVhBb9wfTTEDQpNq8F+nAU6rqk8NrpDkZAbGvZ/lUZ44hfq0WW2dVFUXz2rrNcBPBhY9Ru/3I02fUVU/TvI1ejN3DZuPefa21W/zs1X1gYb1HxrsdxiisY0kewJ/AOxfVT/qnzZ6WsP2s2ubvc7s7//XquqWFnVpitgHocXgYuCdSZ4BkGTXJM8GLgPenGSnJMuAlQPbfIfev7ABjprV1u8m2aHf1j5Jdh7y2TcDz02yf3/9ZUk2/8Pq0/QmMlo3cLQz2+uS/GySnYA30Tt1dQlwVP9noP/+8+b/Gp5krjZ2offHfVOSX6A3T/Fm/07vqGuzHyR5UXpTUb6ZuV0MnDTQJ7PfiLVqkfIIQhOvqr7aP+d+ef9v1P3A26rqqiR/B1wDfBf4p4HN/hw4N8lvAv84sPzT9E4dXdX/g3c3vT/cc332w0mOBv53/4/8g/SmP72/qjYkuQ/4zJDy/xn4W2Av4KyqWg+Q5EPAV/t/nB8B3t3/GVqpqhub2qiqbye5GrgBuJ1eIG22Gvhyku9X1cHAKcAX6U1XeT29U3dNPgL8JXBd/zv7DvDGtrVq8fIyV02NJH9EvxN3gT7vufSm2/zFpvl+05sLeGbz3MDSYuMpJmkLJPkt4Ap6VwyNPBm8tBh4BCFJauQRhCSpkQEhSWpkQEiSGhkQkqRGBoQkqZEBIUlq9P8BewEJ8pmbEacAAAAASUVORK5CYII=\n",
"text/plain": [
"<Figure size 432x288 with 1 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"output_viz = feature_table.visualizers.summarize(deblur_sequences.table)\n",
"output_viz.visualization"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-p7ot_zlz')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 84ee1200-fbe9-4e05-8f39-6b7a0ee0c792>"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"deblur_feature_table_summary = feature_table.visualizers.tabulate_seqs(deblur_sequences.representative_sequences)\n",
"deblur_feature_table_summary.visualization"
]
},
{
"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": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running external command line application. This may print messages to stdout and/or stderr.\n",
"The command being run is below. This command cannot be manually re-run as it will depend on temporary files that no longer exist.\n",
"\n",
"Command: mafft --preservecase --inputorder --thread 1 /var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-io5r0vbw/e6a7504d-a0ee-40fe-b7aa-01f8fbf84be7/data/dna-sequences.fasta\n",
"\n"
]
}
],
"source": [
"mafft_alignment = alignment.methods.mafft(deblur_sequences.representative_sequences)"
]
},
{
"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": 15,
"metadata": {},
"outputs": [],
"source": [
"masked_mafft_alignment = alignment.methods.mask(mafft_alignment.alignment)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Next, we’ll apply FastTree to generate a phylogenetic tree from the masked alignment."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Running external command line application. This may print messages to stdout and/or stderr.\n",
"The command being run is below. This command cannot be manually re-run as it will depend on temporary files that no longer exist.\n",
"\n",
"Command: FastTree -quote -nt /var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-g6we_m2e/7dc837c9-7f30-4197-a4cd-7870ce4fb6f2/data/aligned-dna-sequences.fasta\n",
"\n"
]
}
],
"source": [
"unrooted_tree = phylogeny.methods.fasttree(masked_mafft_alignment.masked_alignment)"
]
},
{
"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": 17,
"metadata": {},
"outputs": [],
"source": [
"rooted_tree = phylogeny.methods.midpoint_root(unrooted_tree.tree)"
]
},
{
"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-phylogenetic method, which rarefies a FeatureTable[Frequency] to a user-specified depth, computes several alpha and beta diversity metrics, and generates principle coordinates analysis (PCoA) plots using Emperor for each of the 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",
"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",
"An important 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.\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/anaconda/envs/q2/lib/python3.5/site-packages/sklearn/utils/validation.py:475: DataConversionWarning: Data with input dtype int64 was converted to bool by check_pairwise_arrays.\n",
" warnings.warn(msg, DataConversionWarning)\n",
"/Library/anaconda/envs/q2/lib/python3.5/site-packages/skbio/stats/ordination/_principal_coordinate_analysis.py:111: RuntimeWarning: The result contains negative eigenvalues. Please compare their magnitude with the magnitude of some of the largest positive eigenvalues. If the negative ones are smaller, it's probably safe to ignore them, but if they are large in magnitude, the results won't be useful. See the Notes section for more details. The smallest eigenvalue is -0.008563532415852653 and the largest is 3.611060441022501.\n",
" RuntimeWarning\n",
"/Library/anaconda/envs/q2/lib/python3.5/site-packages/skbio/stats/ordination/_principal_coordinate_analysis.py:111: RuntimeWarning: The result contains negative eigenvalues. Please compare their magnitude with the magnitude of some of the largest positive eigenvalues. If the negative ones are smaller, it's probably safe to ignore them, but if they are large in magnitude, the results won't be useful. See the Notes section for more details. The smallest eigenvalue is -0.01123443509133009 and the largest is 2.56654644566679.\n",
" RuntimeWarning\n",
"/Library/anaconda/envs/q2/lib/python3.5/site-packages/skbio/stats/ordination/_principal_coordinate_analysis.py:111: RuntimeWarning: The result contains negative eigenvalues. Please compare their magnitude with the magnitude of some of the largest positive eigenvalues. If the negative ones are smaller, it's probably safe to ignore them, but if they are large in magnitude, the results won't be useful. See the Notes section for more details. The smallest eigenvalue is -0.025966599256815274 and the largest is 3.5210610377665543.\n",
" RuntimeWarning\n"
]
}
],
"source": [
"core_metrics = diversity.pipelines.core_metrics_phylogenetic(table = deblur_sequences.table,\n",
" phylogeny = rooted_tree.rooted_tree,\n",
" sampling_depth = 1109,\n",
" metadata = sample_metadata)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here we set the --p-sampling-depth parameter to 1109. This value was chosen based on the number of sequences in the L3S341 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-phylogenetic analyses and anything that uses these results."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### alpha group significance"
]
},
{
"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 categorical metadata columns 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": 19,
"metadata": {},
"outputs": [],
"source": [
"faith_pd_group_significance = diversity.actions.alpha_group_significance(core_metrics.faith_pd_vector,\n",
" sample_metadata)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"evenness_group_significance = diversity.actions.alpha_group_significance(core_metrics.evenness_vector,\n",
" sample_metadata)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualize group significance results"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-pm6l5_hn')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: dd67dcf1-b68f-4929-8eb2-7d93a23d4dae>"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"faith_pd_group_significance.visualization"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-bsvzm7m0')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 292de9aa-1f4e-4c99-a04d-a34f3bc79742>"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"evenness_group_significance.visualization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### beta group significance"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this data set, no continuous sample metadata columns (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 categorical 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 columns of metadata that we’re interested in exploring, rather than all metadata columns that it’s applicable to. Here we’ll apply this to our unweighted UniFrac distances, using two sample metadata columns, as follows."
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Figure size 432x288 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"uUniFrac_BodySite_significance = diversity.actions.beta_group_significance(core_metrics.unweighted_unifrac_distance_matrix,\n",
" sample_metadata.get_column('BodySite'))"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<Figure size 432x288 with 0 Axes>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"uUniFrac_Subject_significance = diversity.actions.beta_group_significance(core_metrics.unweighted_unifrac_distance_matrix,\n",
" sample_metadata.get_column('Subject'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Visualize"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-2m4mqrde')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: a69cabd7-c213-4b75-bcd5-2acdb1cb9862>"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"uUniFrac_BodySite_significance.visualization"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-psbr_aex')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 1a3cb046-bd18-4290-a3e6-7156e6c4e476>"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"uUniFrac_Subject_significance.visualization"
]
},
{
"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 metadata distance-matrix in combination with qiime diversity mantel 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. While our core-metrics-phylogenetic command did already generate some Emperor plots, we want to pass an optional parameter, --p-custom-axes, which is very useful for exploring time series data. The PCoA results that were used in core-metrics-phylogeny are also available, making it easy to generate new visualizations with Emperor. We will generate Emperor plots for unweighted UniFrac and Bray-Curtis so that the resulting plot will contain axes for principal coordinate 1, principal coordinate 2, and days since the experiment start. We will use that last axis to explore how these samples changed over time."
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-oe7v8_o8')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: ace1839e-ae23-4b1d-b2ee-bfc3a0ce0aef>"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"emperor_plot = emperor.visualizers.plot(core_metrics.unweighted_unifrac_pcoa_results,\n",
" sample_metadata,\n",
" custom_axes=['DaysSinceExperimentStart'])\n",
"emperor_plot.visualization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Alpha rarefaction plotting"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In this section we’ll explore alpha diversity as a function of sampling depth using the qiime diversity alpha-rarefaction visualizer. This visualizer computes one or more alpha diversity metrics at multiple sampling depths, in steps between 1 (optionally controlled with --p-min-depth) and the value provided as --p-max-depth. At each sampling depth step, 10 rarefied tables will be generated, and the diversity metrics will be computed for all samples in the tables. The number of iterations (rarefied tables computed at each sampling depth) can be controlled with --p-iterations. Average diversity values will be plotted for each sample at each even sampling depth, and samples can be grouped based on metadata in the resulting visualization if sample metadata is provided with the --m-metadata-file parameter."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [],
"source": [
"rarefaction = diversity.actions.alpha_rarefaction(table = deblur_sequences.table,\n",
" max_depth = 4000,\n",
" phylogeny = rooted_tree.rooted_tree,\n",
" metadata = sample_metadata)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-4s1_iclq')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: b1ea260b-8ca7-4270-809a-1a9d374984ae>"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rarefaction.visualization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The visualization will have two plots. The top plot is an alpha rarefaction plot, and is primarily used to determine if the richness of the samples has been fully observed or sequenced. If the lines in the plot appear to “level out” (i.e., approach a slope of zero) at some sampling depth along the x-axis, that suggests that collecting additional sequences beyond that sampling depth would not be likely to result in the observation of additional features. If the lines in a plot don’t level out, this may be because the richness of the samples hasn’t been fully observed yet (because too few sequences were collected), or it could be an indicator that a lot of sequencing error remains in the data (which is being mistaken for novel diversity).\n",
"\n",
"The bottom plot in this visualization is important when grouping samples by metadata. It illustrates the number of samples that remain in each group when the feature table is rarefied to each sampling depth. If a given sampling depth d is larger than the total frequency of a sample s (i.e., the number of sequences that were obtained for sample s), it is not possible to compute the diversity metric for sample s at sampling depth d. If many of the samples in a group have lower total frequencies than d, the average diversity presented for that group at d in the top plot will be unreliable because it will have been computed on relatively few samples. When grouping samples by metadata, it is therefore essential to look at the bottom plot to ensure that the data presented in the top plot is reliable."
]
},
{
"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": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"--2018-05-10 14:28:32-- https://data.qiime2.org/2018.2/common/gg-13-8-99-515-806-nb-classifier.qza\n",
"Resolving data.qiime2.org... 2400:cb00:2048:1::681b:ab9e, 2400:cb00:2048:1::681b:aa9e, 104.27.170.158, ...\n",
"Connecting to data.qiime2.org|2400:cb00:2048:1::681b:ab9e|:443... connected.\n",
"HTTP request sent, awaiting response... 302 FOUND\n",
"Location: https://s3-us-west-2.amazonaws.com/qiime2-data/2018.2/common/gg-13-8-99-515-806-nb-classifier.qza [following]\n",
"--2018-05-10 14:28:33-- https://s3-us-west-2.amazonaws.com/qiime2-data/2018.2/common/gg-13-8-99-515-806-nb-classifier.qza\n",
"Resolving s3-us-west-2.amazonaws.com... 52.218.209.72\n",
"Connecting to s3-us-west-2.amazonaws.com|52.218.209.72|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 29848502 (28M) [binary/octet-stream]\n",
"Saving to: '/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial/gg-13-8-99-515-806-nb-classifier.qza'\n",
"\n",
"/Users/tomasz/tmp/q 100%[===================>] 28.46M 15.1MB/s in 1.9s \n",
"\n",
"2018-05-10 14:28:35 (15.1 MB/s) - '/Users/tomasz/tmp/qiime2_workshop/qiime2-moving-pictures-tutorial/gg-13-8-99-515-806-nb-classifier.qza' saved [29848502/29848502]\n",
"\n"
]
}
],
"source": [
"!wget -O $workdir\"/gg-13-8-99-515-806-nb-classifier.qza\" \"https://data.qiime2.org/2018.2/common/gg-13-8-99-515-806-nb-classifier.qza\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"unfortunately you have to do this first:"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"!qiime tools export $workdir/gg-13-8-99-515-806-nb-classifier.qza --output-dir $workdir/classifier"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"gg_classifier = qiime2.Artifact.import_data('TaxonomicClassifier', workdir+'/classifier/')"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"taxonomy = feature_classifier.methods.classify_sklearn(reads = deblur_sequences.representative_sequences,\n",
" classifier = gg_classifier)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-lur5ydd7')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 8e694477-164f-4c71-916f-0e3cfc6d5f10>"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"taxonomy_classification = metadata.visualizers.tabulate(taxonomy.classification.view(qiime2.Metadata))\n",
"taxonomy_classification.visualization"
]
},
{
"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": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-ny5lcjui')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 0d2a3d22-f73a-4639-b463-80e7788e3ddc>"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"taxa_bar_plot = taxa.visualizers.barplot(deblur_sequences.table, taxonomy.classification, sample_metadata)\n",
"taxa_bar_plot.visualization"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Differential abundance testing with ANCOM"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ANCOM can be applied to identify features that are differentially abundant (i.e. present in different abundances) across sample groups. As with any bioinformatics method, you should be aware of the assumptions and limitations of ANCOM before using it. We recommend reviewing the ANCOM paper before using this method."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"ANCOM is implemented in the q2-composition plugin. ANCOM assumes that few (less than about 25%) of the features are changing between groups. If you expect that more features are changing between your groups, you should not use ANCOM as it will be more error-prone (an increase in both Type I and Type II errors is possible). Because we expect a lot of features to change in abundance across body sites, in this tutorial we’ll filter our full feature table to only contain gut samples. We’ll then apply ANCOM to determine which, if any, sequence variants and genera are differentially abundant across the gut samples of our two subjects.\n",
"\n",
"We’ll start by creating a feature table that contains only the gut samples. (To learn more about filtering, see the Filtering Data tutorial.)"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
"gut_deblur = feature_table.methods.filter_samples(deblur_sequences.table,\n",
" metadata = sample_metadata,\n",
" where = \"BodySite='gut'\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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."
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Library/anaconda/envs/q2/lib/python3.5/site-packages/scipy/stats/stats.py:2968: RuntimeWarning: invalid value encountered in double_scalars\n",
" f = msb / msw\n"
]
}
],
"source": [
"gut_deblur_composition = composition.actions.add_pseudocount(gut_deblur.filtered_table)\n",
"\n",
"ancom_gut_deblur = composition.actions.ancom(table = gut_deblur_composition.composition_table,\n",
" metadata = sample_metadata.get_column('Subject'))"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-6n8yj4tg')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: a1503901-66fb-4ecb-b981-ed26cb98aac6>"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ancom_gut_deblur.visualization"
]
},
{
"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. In this tutorial, we collapse our feature table at the genus level (i.e. level 6 of the Greengenes taxonomy)."
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"gut_table_l6 = taxa.methods.collapse(table = gut_deblur.filtered_table,\n",
" taxonomy = taxonomy.classification,\n",
" level = 6)"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [],
"source": [
"gut_table_l6_composition = composition.actions.add_pseudocount(gut_table_l6.collapsed_table)\n",
"\n",
"ancom_gut_table_l6 = composition.actions.ancom(table = gut_table_l6_composition.composition_table,\n",
" metadata = sample_metadata.get_column('Subject'))"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div><img onload=\"(function(div, url){\n",
"if (typeof require !== 'undefined') {\n",
" var baseURL = require.toUrl('').split('/').slice(0, -2).join('/');\n",
"} else {\n",
" var baseURL = JSON.parse(\n",
" document.getElementById('jupyter-config-data').innerHTML\n",
" ).baseUrl.slice(0, -1);\n",
"}\n",
"url = baseURL + url;\n",
"fetch(url).then(function(res) {\n",
" if (res.status === 404) {\n",
" div.innerHTML = 'Install QIIME 2 Jupyter extension with:<br />' +\n",
" '<code>jupyter serverextension enable --py qiime2' +\n",
" ' --sys-prefix</code><br />then restart your server.' +\n",
" '<br /><br />(Interactive output not available on ' +\n",
" 'static notebook viewer services like nbviewer.)';\n",
" } else if (res.status === 409) {\n",
" div.innerHTML = 'Visualization no longer in scope. Re-run this cell' +\n",
" ' to see the visualization.';\n",
" } else if (res.ok) {\n",
" url = res.url;\n",
" div.innerHTML = '<iframe src=\\'' + url + '\\' style=\\'' +\n",
" 'width: 100%; height: 700px; border: 0;\\'>' +\n",
" '</iframe><hr />Open in a: <a href=\\'' + url + '\\'' +\n",
" ' target=\\'_blank\\'>new window</a>'\n",
" } else {\n",
" div.innerHTML = 'Something has gone wrong. Check notebook server for' +\n",
" ' errors.';\n",
" }\n",
"});\n",
"})(this.parentElement, '/qiime2/redirect?location=/var/folders/5_/4__v28lj2k97wr8fxprwv0g40000gp/T/qiime2-archive-ywdwb_ae')\" src=\"data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==\" /></div>"
],
"text/plain": [
"<visualization: Visualization uuid: 0ac066cb-e797-4d88-866b-ef9194ffbf9e>"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ancom_gut_table_l6.visualization"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment