Taxonomy: Kraken2
Overview
After assembly quality control, we can classify the assembled genome to check the likely taxonomic identity of the sample.
In this lesson, we will use Kraken2 to classify the filtered assembly file and Krona to create an interactive taxonomic visualization.
Learning objectives
By the end of this lesson, you should be able to:
- create a folder for taxonomic classification results
- activate the
classifyenvironment - run
Kraken2on an assembled genome - generate a Kraken2 taxonomic report
- convert the Kraken2 report into Krona format
- create and download an interactive Krona HTML plot
Input file
In the previous assembly QC lesson, we created a filtered assembly file:
assemblies/S1_contigs_filtered.fasta
Check that the file exists:
ls assembliesYou should see:
S1_contigs_filtered.fasta
For this lesson, we will use the filtered assembly file:
assemblies/S1_contigs_filtered.fasta
Create a classification directory
Create a directory named classify:
mkdir -p classifyCheck that the directory was created:
lsActivate the classify environment
Activate the classify environment:
conda activate classifyCheck that kraken2 is available:
kraken2 --versionCheck that the Krona tools are available:
ktImportTextIf the command prints help text or usage information, Krona is available.
Run Kraken2
Run Kraken2 on the filtered assembly:
kraken2 \
--db ~/databases/kraken2db \
--threads 4 \
--report classify/S1.kraken2.report \
--output classify/S1.kraken2.output \
assemblies/S1_contigs_filtered.fastaUnderstanding the Kraken2 command
| Option | Meaning |
|---|---|
kraken2 |
Runs Kraken2 |
--db ~/databases/kraken2db |
Path to the Kraken2 database |
--threads 4 |
Use 4 CPU threads |
--report classify/S1.kraken2.report |
Summary taxonomic report |
--output classify/S1.kraken2.output |
Detailed classification output |
assemblies/S1_contigs_filtered.fasta |
Input assembly file |
If you see errors in terminal mentioning that Kraken2 cannot run due to memory insufficiency, use the flag --memory-mapping to run efficiently
kraken2 \
--db ~/databases/kraken2db \
--memory-mapping \
--threads 4 \
--report classify/S1.kraken2.report \
--output classify/S1.kraken2.output \
assemblies/S1_contigs_filtered.fastaCheck Kraken2 outputs
List the classify directory:
ls classifyYou should see:
S1.kraken2.output
S1.kraken2.report
View the first few lines of the report:
head classify/S1.kraken2.report100.00 80 0 R 1 root
100.00 80 0 R1 131567 cellular organisms
100.00 80 0 D 2 Bacteria
100.00 80 0 K 3379134 Pseudomonadati
100.00 80 0 P 1224 Pseudomonadota
100.00 80 0 C 1236 Gammaproteobacteria
100.00 80 0 O 135623 Vibrionales
100.00 80 0 F 641 Vibrionaceae
100.00 80 6 G 662 Vibrio
92.50 74 65 S 666 Vibrio cholerae
The Kraken2 report contains taxonomic classification information, including the percentage of sequences assigned to different taxa.
Kraken2 report columns
A Kraken2 report usually contains columns similar to:
| Column | Meaning |
|---|---|
| Percentage | Percentage of sequences assigned to the taxon |
| Clade reads | Reads/sequences assigned to the taxon and its descendants |
| Taxon reads | Reads/sequences assigned directly to the taxon |
| Rank code | Taxonomic rank |
| NCBI taxonomic ID | Taxonomy ID |
| Scientific name | Taxon name |
Which genus or species has the highest assignment?
In this example, most classified sequences belong to:
Vibrio cholerae
This suggests that sample S1 is likely Vibrio cholerae.
What is the main species-level taxonomic assignment in this report?
The main species-level assignment is:
Vibrio cholerae
It has 92.50% assignment in this example.
Create Krona input file
To visualize the Kraken2 report interactively, first convert it into Krona-compatible format.
kreport2krona.py \
-r classify/S1.kraken2.report \
-o classify/S1.kronaCheck that the Krona input file was created:
ls classifyYou should see:
S1.krona
Create Krona HTML plot
Now create an interactive Krona HTML plot:
ktImportText \
-o classify/S1.krona.html \
classify/S1.kronaCheck that the HTML file was created:
ls classifyYou should see:
S1.krona.html
Open S1.krona.html manually from File Explorer using a web browser.
Use:
open S1.krona.htmlUse:
xdg-open S1.krona.html![Krona output]
Compare Kraken2 report and Krona plot
The Kraken2 report is useful for checking exact taxonomic assignments in text format.
The Krona plot is useful for interactively exploring the taxonomic hierarchy.
| Output | Use |
|---|---|
S1.kraken2.report |
Text summary of taxonomic classification |
S1.kraken2.output |
Detailed sequence-level classification output |
S1.krona |
Intermediate Krona input file |
S1.krona.html |
Interactive Krona visualization |
Compare the Kraken2 report and Krona plot.
Do they suggest the same main organism?
Both outputs should point to the same main organism if the classification is consistent. The Kraken2 report gives the detailed text summary, while Krona provides an interactive visualization of the same taxonomic information.
Organize classification results
Your working directory should now contain:
classify
Check the folder:
ls classifyExpected files:
S1.kraken2.output
S1.kraken2.report
S1.krona
S1.krona.html
Deactivate the classify environment:
conda deactivateFinal directory structure
At the end of this lesson, your directory should look like this:
.
├── assemblies
│ ├── S1_contigs.fasta
│ └── S1_contigs_filtered.fasta
└── classify
├── S1.kraken2.output
├── S1.kraken2.report
├── S1.krona
└── S1.krona.html
Practical exercise
Complete the following tasks for sample S1:
- Create the
classifydirectory. - Activate the
classifyenvironment. - Run
Kraken2onS1_contigs_filtered.fasta. - Open the Kraken2 report.
- Convert the Kraken2 report to Krona format.
- Create a Krona HTML plot.
- Download the Krona HTML file to your local computer.
- Open the Krona plot in a browser.
Create a small table in your notes:
| Sample | Main taxonomic assignment | Evidence from Kraken2 | Evidence from Krona |
|---|---|---|---|
| S1 |
Fill in the table using S1.kraken2.report and S1.krona.html.
Key points
Kraken2can classify sequences using a reference taxonomy database.- The input for this lesson is the filtered assembly file.
- The Kraken2 report gives a text summary of taxonomic classification.
- Krona creates an interactive HTML visualization.
- Download the
.htmlKrona file to visualize it on your local computer.
Next step
In the next lesson, we will continue downstream analysis using the filtered assembly file.