Step 6: Taxonomy assignment - shenjean/diversity GitHub Wiki
-
In QIIME2, taxonomy is assigned to each reference sequence using a pre-trained Naïve Bayesian classifier. Here is a list of available classifiers and references sequences: https://library.qiime2.org/data-resources.
-
QIIME2's latest suggestion on region-specific vs full-length classifiers
"It is not necessary to use a classifier that was trained on sequences that were trimmed based on the primers you sequenced with. In practice we notice very minor differences, if any, relative to those trained on full-length sequences. We are therefore no longer providing region-specific classifiers, such as the 515F/806R region-specific classifiers, that we have provided in the past. Far more impactful is the use of environment-weighted classifiers, as described in Kaehler et al., (2019). We now distribute these, and currently have these tagged as EXPERIMENTAL."
I. 18S rRNA gene classifier from PR2 database
The PR2 database seems to yield better taxonomic assignment (more classified taxa) based on the 18S rRNA gene.
- The reference database can be downloaded from: https://github.com/pr2database/pr2database/releases
wget https://github.com/pr2database/pr2database/releases/download/v5.1.1/pr2_version_5.1.1_SSU_mothur.tax.gz
wget https://github.com/pr2database/pr2database/releases/download/v5.1.1/pr2_version_5.1.1_SSU_mothur.fasta.gz
gunzip pr2_version_5.1.1_SSU_mothur.tax.gz
gunzip pr2_version_5.1.1_SSU_mothur.fasta.gz
-
Add header line to taxonomy file: ['Feature ID', 'Taxon'] must be the first two header values.
-
Import unzipped files to QIIME2
qiime tools import --type 'FeatureData[Sequence]' --input-path pr2_version_5.1.1_SSU_mothur.fasta --output-path PR2-seqs.qza
qiime tools import --type 'FeatureData[Taxonomy]' --input-path pr2_version_5.1.1_SSU_mothur.tax --output-path PR2-tax.qza
- Extract primer region 18S rRNA gene V4 primer sequences TAReuk454FWD1 and TAReuk454REV3.1 are from https://doi.org/10.3389/fmicb.2018.01998
qiime feature-classifier extract-reads --i-sequences PR2-seqs.qza \
--p-f-primer CCAGCASCYGCGGTAATTCC --p-r-primer ACTTTCGTTCTTGATYR \
--p-n-jobs 8 --o-reads PR2-v4-seqs.qza
- Dereplicate
qiime rescript dereplicate \
--i-sequences PR2-v4-seqs.qza --i-taxa PR2-tax.qza --p-mode 'uniq' \
--o-dereplicated-sequences PR2-seqs-v4-uniq.qza \
--o-dereplicated-taxa PR2-tax-v4-uniq.qza
II. Naive Bayes classifiers
I would probably recommend using the GTDB and SILVA classifiers available at https://library.qiime2.org/data-resources, then curating and merging the taxonomies.
To assign taxonomy to your representative sequences using a pre-trained or self-trained classifier:
- SILVA sklearn classifier
qiime feature-classifier classify-sklearn \
--i-classifier silva-138-99-nb-classifier.qza \
--i-reads pe.repseqs.qza \
--o-classification taxonomy.SILVA.qza
- GTDB sklearn classifier
qiime feature-classifier classify-sklearn \
--i-classifier gtdb_classifier_r220.qzaa \
--i-reads pe.repseqs.qza \
--o-classification taxonomy.SILVA.qza
III. BLAST classifiers
Another alternative is to perform taxonomic classification using BLAST, but always check the taxonomic resolution and annotations manually
- Download sequence and taxonomy data from SILVA
wget https://data.qiime2.org/2024.5/common/silva-138-99-seqs.qza
wget https://data.qiime2.org/2024.5/common/silva-138-99-tax.qza
- Classify sequences with BLAST
qiime feature-classifier classify-consensus-blast --i-query pe.repseqs.qza \
--i-reference-reads silva-138-99-seqs.qza --i-reference-taxonomy silva-138-99-tax.qza \
--o-classification taxonomy.blast.qza --o-search-results blast-results.qza
IV. Visualize taxonomy data
Get list of taxonomic names and confidence for each feature
qiime metadata tabulate \
--m-input-file taxonomy.sklearn.qza \
--o-visualization taxonomy.sklearn.qzv
View the taxonomic composition of each sample with interactive bar plots.
qiime taxa barplot \
--i-table pe.dada2.qza \
--i-taxonomy taxonomy.sklearn.qza \
--m-metadata-file metadata.txt \
--o-visualization taxa-bar-plots.qzv
IV. Merge taxonomies predicted by different methods
How to merge feature taxonomies
lenwill select the taxonomy with the most elements (e.g., species level will beat genus level)lcawill find the least common ancestor and report this consensus taxonomyscorewill select the taxonomy with the highest score (e.g., confidence or consensus score). Note that "score" assumes that this score is always contained as the second column in a feature taxonomy dataframemajorityfinds the LCA consensus while giving preference to majority labels.superfinds the LCA consensus while giving preference to majority labels and collapsing substrings into superstrings. For example, when a more specific taxonomy does not contradict a less specific taxonomy, the more specific is chosen. That is, "g__Faecalibacterium; s__prausnitzii", will be preferred over "g__Faecalibacterium; s__"
For SILVA taxonomy:
qiime rescript merge-taxa \
--i-data taxonomy.blast.qza taxonomy.sklearn.qza \
--p-mode len --o-merged-data taxonomy.merged.qza
For other taxonomies, you will need to modify the --p-rank-handle-regex arguments to recognize rank handles, e.g. For example, ^[dkpcofgs]__ will recognize greengenes or silva rank handles. For eukaryotic databases (e.g. PR2), you may also want to disable the --p-new-rank-handles option to prevent trimming of the taxonomy to the given levels.
qiime rescript merge-taxa --i-data 18S.PR2.blast.taxonomy.qza 18S.PR2.sklearn.taxonomy.qza \
--p-mode len --o-merged-data 18S.PR2.taxonomy.merged.qza --p-new-rank-handles disable
Get list of taxonomic names and confidence for each feature
qiime metadata tabulate \
--m-input-file taxonomy.merged.qza \
--o-visualization taxonomy.merged.qzv
View the taxonomic composition of each sample with interactive bar plots.
qiime taxa barplot \
--i-table pe.dada2.qza \
--i-taxonomy taxonomy.merged.qza \
--m-metadata-file metadata.txt \
--o-visualization taxa-merged-bar-plots.qzv
V. Filtering the count table by taxonomy
The command below keeps ASVs with phylum-level annotations and removes ASVs annotated as “archaea”, “chloroplast”, “eukaryota”, and “mitochondria”
qiime taxa filter-table \
--i-table pe.dada2.qza \
--i-taxonomy taxonomy.qza \
--p-include p__ \
--p-exclude mitochondria,chloroplast,eukaryota,archaea \
--o-filtered-table bacteriatable.qza
Check the taxonomy bar plots again
qiime taxa barplot \
--i-table bacteriatable.qza \
--i-taxonomy taxonomy.qza \
--m-metadata-file metadata.txt \
--o-visualization bacteria-taxa-bar-plots.qzv
VI. Summarize ASV abundance of bacteria table
qiime feature-table summarize \
--i-table bacteriatable.qza \
--o-feature-frequencies feature-frequencies.qza \
--o-sample-frequencies sample-frequencies.qza \
--o-summary bacteria-summary.qzv
VII. Collapse features by their taxonomy
This example command collapses ASVs to the genus level
qiime taxa collapse --i-table bacteriatable.qza --i-taxonomy taxonomy.qza --p-level 6 --o-collapsed-table genustable.qza
Summarize ASV abundance of genus table
qiime feature-table summarize --i-table genustable.qza --o-feature-frequencies genus-feature-frequencies.qza --o-sample-frequencies genus-sample-frequencies.qza --o-summary genustable.qzv
VIII. Export taxonomy file
qiime tools export --input-path taxonomy.qza --output-path taxonomy_export