Home › Bioinformatics Tutorial › Metagenomics Workflow Using QIIME 2 and Kraken2

Metagenomics Workflow Using QIIME 2 and Kraken2

⏱ 9 min read Updated: 03 Nov 2026

Metagenomics: 16S rRNA (QIIME 2) and Shotgun (Kraken2)

Metagenomics is a bioinformatics technique used to study microorganisms directly from environmental samples. It helps researchers identify bacteria, archaea, fungi, and viruses without growing them in a laboratory.

In this article, we will learn two important metagenomic approaches: 16S rRNA sequencing using QIIME 2 and shotgun metagenomics using Kraken2. We will also understand their workflows, important commands, differences, and applications.

If you are new to bioinformatics, start with our Bioinformatics Tutorial.

What is Metagenomics?

Metagenomics is the study of genetic material collected directly from a sample containing multiple microorganisms. Researchers extract DNA, sequence it, and use bioinformatics tools to identify microorganisms and study their genetic functions.

For example, metagenomics can be used to study gut bacteria, soil microorganisms, water quality, and antibiotic resistance.

Important Terms in Metagenomics

TermMeaning
MetagenomeGenetic material from all microorganisms in a sample.
Taxonomic ProfilingIdentifying microorganisms present in a sample.
Functional ProfilingStudying genes and their biological functions.
Relative AbundanceProportion of a particular microorganism in a community.
MicrobiomeCommunity of microorganisms living in a particular environment.

16S rRNA vs Shotgun Metagenomics

Both methods help researchers study microbial communities, but they differ in their sequencing approaches.

Feature16S rRNAShotgun
SequencingSpecific marker geneAll DNA
Main PurposeMicrobial identificationIdentification and functional analysis
ResolutionUsually genusSpecies and sometimes strain
OrganismsBacteria and archaeaBacteria, archaea, fungi, viruses
CostLowerHigher
ToolQIIME 2Kraken2

What Is 16S rRNA Sequencing?

16S rRNA sequencing is a molecular technique used mainly to identify bacteria and archaea. The 16S rRNA gene contains approximately 1,500 base pairs and consists of conserved and variable regions.

  • Conserved Regions: Similar DNA sequences across different microorganisms. They help researchers design PCR primers.
  • Variable Regions: Differ between microorganisms and help identify bacterial groups.

The gene contains nine variable regions, V1 to V9. Researchers commonly sequence regions such as V4 or V3-V4 using Illumina technology. The resulting sequences are compared with reference databases such as SILVA, Greengenes2, and RDP.

OTUs vs ASVs

During sequencing, errors can produce incorrect DNA sequences. Two approaches are commonly used to process these sequences.

OTUsASVs
Group similar sequences, commonly at 97% similarity.Represent exact error-corrected sequences.
Traditional clustering method.Modern denoising approach.
Less precise.Provides better sequence-level resolution.

Tools such as DADA2 and Deblur generate ASVs by identifying and correcting sequencing errors. In this tutorial, we will use DADA2.

16S rRNA Analysis Using QIIME 2

QIIME 2 is an open-source bioinformatics platform used to analyze microbiome sequencing data. It helps researchers process DNA sequences, identify microorganisms, measure microbial diversity, and compare microbial communities.

QIIME 2 mainly uses two file formats:

FormatDescription
.qzaStores analysis data and results.
.qzvStores visualizations such as graphs and plots.

You can view .qzv files using QIIME 2 View.

Step 1: Prepare Manifest and Metadata Files

A manifest file contains the location of sequencing reads, while a metadata file stores sample information such as diet, age, or treatment group.

Example manifest file:

sample-id    forward-absolute-filepath    reverse-absolute-filepath S1           /data/S1_R1.fastq.gz         /data/S1_R2.fastq.gz S2           /data/S2_R1.fastq.gz         /data/S2_R2.fastq.gz

Example metadata file:

sample-id    diet         age-group S1           high-fibre   adult S2           low-fibre    adult

Both files should use tab-separated columns, and sample IDs must match.

Step 2: Import Reads and Check Quality

Import paired-end sequencing reads into QIIME 2:

qiime tools import \  --type "SampleData[PairedEndSequencesWithQuality]" \  --input-path manifest.tsv \  --input-format PairedEndFastqManifestPhred33V2 \  --output-path demux.qza

Generate a quality summary:

qiime demux summarize \  --i-data demux.qza \  --o-visualization demux.qzv

Open demux.qzv in QIIME 2 View to examine sequence quality scores and select suitable read-truncation lengths.

Step 3: Remove Sequencing Errors Using DADA2

DADA2 removes low-quality reads, corrects sequencing errors, and identifies chimeric sequences. It also identifies unique DNA sequences called Amplicon Sequence Variants (ASVs).

qiime dada2 denoise-paired \  --i-demultiplexed-seqs demux.qza \  --p-trunc-len-f 240 \  --p-trunc-len-r 200 \  --p-n-threads 4 \  --o-table table.qza \  --o-representative-sequences rep-seqs.qza \  --o-denoising-stats denoising-stats.qza

Main output files:

  • table.qza: Stores ASV counts for each sample.
  • rep-seqs.qza: Contains representative DNA sequences.
  • denoising-stats.qza: Shows reads retained during processing.

Truncation lengths should be selected using the quality plots while maintaining sufficient overlap between paired-end reads.

Step 4: Assign Taxonomy

Taxonomy assignment identifies microorganisms by comparing their DNA sequences with reference databases such as SILVA.

qiime feature-classifier classify-sklearn \  --i-classifier silva-138-99-nb-classifier.qza \  --i-reads rep-seqs.qza \  --o-classification taxonomy.qza

Generate a taxonomic bar plot:

qiime taxa barplot \  --i-table table.qza \  --i-taxonomy taxonomy.qza \  --m-metadata-file metadata.tsv \  --o-visualization taxa-barplot.qzv

The visualization shows the relative abundance of microorganisms at different taxonomic levels, such as phylum, family, and genus.

Step 5: Construct a Phylogenetic Tree

A phylogenetic tree represents evolutionary relationships between microorganisms.

QIIME 2 uses MAFFT for sequence alignment and FastTree for tree construction.

qiime phylogeny align-to-tree-mafft-fasttree \  --i-sequences rep-seqs.qza \  --o-alignment aligned-rep-seqs.qza \  --o-masked-alignment masked-aligned-rep-seqs.qza \  --o-tree unrooted-tree.qza \  --o-rooted-tree rooted-tree.qza

The resulting rooted tree is used for phylogenetic diversity analysis.

Step 6: Perform Diversity Analysis

Microbial diversity analysis has two main types:

Alpha Diversity: Measures microbial diversity within a single sample.

  • Observed Features: Counts different ASVs.
  • Shannon Index: Measures richness and evenness.
  • Faith's PD: Measures evolutionary diversity.

Beta Diversity: Measures differences between microbial communities.

  • Bray-Curtis: Compares microbial abundance.
  • Jaccard: Compares presence and absence.
  • UniFrac: Considers evolutionary relationships.

Run diversity analysis using:

qiime diversity core-metrics-phylogenetic \  --i-phylogeny rooted-tree.qza \  --i-table table.qza \  --p-sampling-depth 10000 \  --m-metadata-file metadata.tsv \  --output-dir core-metrics-results

Rarefaction standardizes sequencing depth across samples. Choose the sampling depth based on the feature table.

The results include diversity measurements, distance matrices, and PCoA plots. In a PCoA plot, closer points represent more similar microbial communities.

Step 7: Perform Statistical Analysis

Statistical analysis helps determine whether microbial diversity differs between experimental groups.

Alpha Diversity:

qiime diversity alpha-group-significance \  --i-alpha-diversity core-metrics-results/shannon_vector.qza \  --m-metadata-file metadata.tsv \  --o-visualization shannon-significance.qzv

Beta Diversity:

qiime diversity beta-group-significance \  --i-distance-matrix core-metrics-results/bray_curtis_distance_matrix.qza \  --m-metadata-file metadata.tsv \  --m-metadata-column diet \  --p-method permanova \  --o-visualization bray-curtis-diet-significance.qzv

PERMANOVA tests whether microbial community composition differs between groups. A p-value below 0.05 is commonly considered statistically significant. Results should also be interpreted based on sample size and statistical assumptions.

Summary of 16S rRNA Analysis

StepProcessPurpose
1Prepare filesOrganize sequencing data and metadata.
2Import and quality checkExamine sequence quality.
3DADA2Remove errors and identify ASVs.
4Taxonomy assignmentIdentify microorganisms.
5Phylogenetic treeStudy evolutionary relationships.
6Diversity analysisMeasure microbial diversity.
7Statistical analysisCompare microbial communities.

What is Shotgun Metagenomics?

Shotgun metagenomics is a sequencing method that analyzes all DNA present in a sample rather than targeting a specific marker gene.

The extracted DNA is fragmented into smaller pieces and sequenced. Bioinformatics tools then identify microorganisms and analyze their genetic information.

Advantages of Shotgun Metagenomics

  • Identifies microorganisms at species and sometimes strain level.
  • Detects bacteria, archaea, fungi, and viruses.
  • Helps identify antibiotic resistance and metabolic genes.
  • Supports functional profiling and genome reconstruction.
  • Provides broader genetic information than 16S sequencing.

However, shotgun sequencing generally costs more and requires greater computational resources. Human and animal samples may also contain host DNA that must be removed.

Shotgun Metagenomics Workflow

StepProcessTools
1Quality ControlFastQC, fastp
2Host DNA RemovalBowtie2
3Taxonomic ProfilingKraken2, Bracken
4Functional ProfilingHUMAnN
5Genome AssemblyMEGAHIT, metaSPAdes

Step 1: Remove Host DNA Using Bowtie2

Host DNA can interfere with microbial analysis. Bowtie2 aligns sequencing reads against a reference host genome.

bowtie2 -x human_index -p 4 --very-sensitive \  -1 clean_R1.fastq.gz \  -2 clean_R2.fastq.gz \  --un-conc-gz nonhost_R%.fastq.gz \  -S /dev/null

The --un-conc-gz parameter saves read pairs that do not align to the host reference. These non-host reads are used for further microbial analysis.

Step 2: Build a Kraken2 Database

Kraken2 is a taxonomic classification tool that identifies microorganisms using short DNA sequences called k-mers.

Build a standard database using:

kraken2-build --standard \  --db kraken_db \  --threads 8

You can also use pre-built databases to reduce database preparation time and memory requirements.

Step 3: Classify Reads Using Kraken2

Run Kraken2 on the filtered sequencing reads:

kraken2 --db kraken_db \  --threads 8 \  --paired \  --gzip-compressed \  --confidence 0.1 \  --report sample.kreport \  --output sample.kraken.out \  nonhost_R1.fastq.gz nonhost_R2.fastq.gz

Important parameters:

ParameterPurpose
--dbSpecifies the reference database.
--pairedProcesses paired-end reads.
--threadsSets processing threads.
--confidenceSets the classification confidence threshold.
--reportGenerates a taxonomic summary.
--outputSaves read-level classification results.

Kraken2 assigns reads to taxonomic groups using database matches. Reads matching multiple related organisms may be assigned to their Lowest Common Ancestor (LCA).

Step 4: Improve Abundance Estimates Using Bracken

Bracken works with Kraken2 results to improve taxonomic abundance estimates at selected levels.

Prepare the database for 150-base reads:

bracken-build -d kraken_db -t 8 -k 35 -l 150

Generate species-level abundance estimates:

bracken -d kraken_db \  -i sample.kreport \  -o sample.bracken \  -r 150 \  -l S \  -t 10

Here, -r specifies read length, -l S selects species level, and -t sets the minimum read-count threshold.

16S rRNA vs Shotgun: Which Should You Choose?

The choice depends on your research objective and available budget.

Requirement16S rRNAShotgun
Microbial DiversitySuitableSuitable
Species IdentificationLimitedMore detailed
Functional AnalysisPredictedDirect gene analysis
CostLowerHigher
Host DNA RemovalUsually less importantOften necessary
Best ApplicationCommunity comparisonFunctional and detailed analysis

Choose 16S sequencing for cost-effective bacterial and archaeal diversity studies. Choose shotgun metagenomics when you need detailed taxonomic information and functional gene analysis.

Best Practices for Metagenomic Analysis

Follow these practices to improve the reliability of your results:

  1. Include negative controls to identify contamination.
  2. Collect sufficient samples for meaningful comparisons.
  3. Maintain sample metadata, including age, diet, and collection date.
  4. Check sequencing quality before downstream analysis.
  5. Select appropriate rarefaction depth.
  6. Use consistent reference databases and software versions.
  7. Save commands and analysis parameters for reproducibility.
  8. Remember that relative abundance does not represent actual microbial cell counts.

Frequently Asked Questions (FAQs)

1. What is the difference between 16S and shotgun metagenomics?

16S sequencing analyzes a specific marker gene, mainly for bacterial and archaeal identification. Shotgun sequencing analyzes all DNA and provides broader taxonomic and functional information.

2. What are ASVs in QIIME 2?

ASVs are exact, error-corrected DNA sequences generated using tools such as DADA2. They provide better sequence-level resolution than traditional OTUs.

3. What is QIIME 2 used for?

QIIME 2 is used for microbiome analysis, including sequence processing, taxonomy classification, diversity analysis, and visualization.

4. What does Kraken2 do?

Kraken2 classifies metagenomic sequencing reads by comparing their k-mers with a reference database.

5. Why is Bracken used with Kraken2?

Bracken improves taxonomic abundance estimates by redistributing reads among possible lower-level taxa, such as species.

Conclusion

Metagenomics helps researchers study microbial communities directly from environmental and biological samples.

16S rRNA sequencing with QIIME 2 is useful for microbial diversity analysis, while shotgun metagenomics with Kraken2 provides broader taxonomic and genetic information.

Understanding both approaches helps bioinformatics researchers select suitable tools for microbiome research, environmental studies, and clinical applications.