Taxonomic Classification¶
Reconstruct rRNA using PhyloFlash-EMIRGE¶
Another method that we can use to obtain taxonomic composition of our metagenomic libraries is to extract/reconstruct the 16S and 18S ribosomal RNA gene. However, modern assemblers often struggle to produce contiguous 16S rRNA genes due to (1) taxa harbouring multiple copies of the gene and (2) repeat regions that short reads cannot span (see here for details). As such, software such as EMIRGE (Miller et al., 2011) and PhyloFlash (Gruber-Vodicka et al., 2020) were developed to reconstruct 16S and 18S rRNA genes. These methods leverage the expansive catalogue of 16S rRNA genes available in databases such as SILVA in order to subset reads and then reconstruct the full-length gene.
For this workshop, we will use PhyloFlash to obtain sequences and abundances of 16S rRNA sequences. The reason being that PhyloFlash can also run EMIRGE as part of its routine, compare those reconstructions with sequences generated by PhyloFlash's map-assemble, and produce a set of 16S rRNA gene sequences as well as estimate relative abundances via coverage estimation.
-lib
A quirk of PhyloFlash is that all outputs will be placed in the current running directory. The only punctuation allowed is "-" and "_". Make sure to name your "LIB" sensibly so you can track which library you're working with.
slurm script
A successful run of PhyloFlash (lines 24-29) would have generated the following per-sample outputs:
tar.gzarchive containing relevant data files- An
.htmlpage summary - A timestamped
.logdetailing what was done
The reconstructed 16S rRNA sequences are stored in the per-sample archive. We will extract them to explore the data files inside.
Terminal
The reconstructed sequences based on the phyloFlash and EMIRGE workflows are stored in sample?.phyloFlash/sample?.all.final.fasta.
In lines 32-34 of our slurm script, we also ran a cross-sample comparison script. This generated 4 files:
allsamples_compare.barplot.pdfA relative abundance barplot of identified taxaallsamples_compare.heatmap.pdfA heatmap of identified taxaallsamples_compare.matrix.tsvA dissimilarity matrix (abundance-weighted, UniFrac-like)allsamples_compare.ntu_table.tsv(long/tidy-format table of relative abundance per sample per taxa)
The allsamples_compare.ntu_table.tsv is especially useful if you intend to perform downstream diversity analyses in R.
Sequence taxonomic classification using Kraken2¶
Most, if not all, of the time, we never know the taxonomic composition of our metagenomic reads a priori. For some environments, we can make good guesses (e.g., Prochlorococcus in marine samples, members of the Actinobacteriota in soil samples, various Bacteroidota in the gut microbiome, etc.). Here, we can use Kraken2, a k-mer based taxonomic classifier to help us interrogate the taxonomic composition of our samples. This is helpful if there are targets we might be looking for (e.g. working hypotheses, well characterised microbiome). Furthermore, we can estimate the abundance of the classified taxa using Bracken.
slurm script
The main output is quite dense and verbose with columns indicated here. The report is more human-readable, with nicely spaced columns that indicate:
- Percentage reads mapped to taxon
- Number of reads mapped to taxon
- Number of reads directly assigned to taxon
- Rank of taxon
- NCBI taxonomy ID
- Scientific name of taxon
Remember to produce the --report as Bracken bases its estimation on the report
The code tells Kraken2 that the inputs ${r1} and ${r1/R1/R2} are paired-end reads. The # after ${base} will be replaced with the read orientation (i.e., forward _1 or reverse _2).
The Bracken outputs provides us with adjusted number (columns added_reads and new_est_reads) and fraction of reads that were assigned to each species identified by Kraken2 for downstream analyses.
Database construction for Kraken2 and Bracken
For this workshop (and most applications), the standard or other extensive pre-built Kraken2 databases are sufficient. However, if you require specific reference sequences to be present, the database building process (outlined here) can be quite time and resource intensive.
The Kraken2 database also comes with a few pre-built Bracken databases (filenames look like this: database100mers.kmer_distrib). Note that the "100mers" doesn't refer to k-mers (oligonucleotide frequency), but it is the length of the read the database was built for. In this workshop, we've used the 100bp database to estimate abundances for 126bp reads. According to the developers, this is acceptable. As long as the read length of the built database is \(\le\) than the length of reads to be classified, Bracken will provide good enough estimates.
If you want to build your own Bracken database based on your library minimum read lengths, you can follow the process here. Take note that you will require the initial sequence and taxonomy files used for building the Kraken2 database (not part of the files in the pre-built databases) and these (especially for NCBI nt and bacterial databses) will take a long time to download and lots of memory to build.