Aggregate and visualize antimicrobial resistance genes found with RGI’s read-mapping command, rgi bwt, against the Comprehensive Antibiotic Resistance Database (CARD), in R. rgi2lab picks up where the RGI functions of sra2lab (rgi_runs(), rgi_local()) leave off. It is the resistance gene counterpart of sylph2lab, for taxonomic profiles, and funprofiler2lab, for functional profiles.
Documentation, with a worked vignette for each function: https://bjklab.github.io/rgi2lab/.
Functions
| Function | What it does |
|---|---|
rgi_aggregate() |
Reads the per-sample gene_mapping_data.txt files into one tibble (one row per sample and gene, with each sample’s aligner and mapping options), drops genes below a coverage threshold, adds RPKM and each gene’s share of the resistome, and joins sample metadata (e.g. an sra2lab run table). |
rgi_timeline() |
Cohort sampling timeline: one row per subject, one point per sample, on subject-day, study-day or calendar-date axes, coloured and optionally split into panels by sampling site or a subject feature (e.g. treatment arm). The same function as sylph2lab::sylph_timeline() and funprofiler2lab::funprofiler_timeline(). |
rgi_heatmap() |
Samples x features geom_tile() heatmap of resistance genes, AMR gene families, drug classes or resistance mechanisms, as log10, raw or CLR-transformed abundance or presence/absence, with optional clustering and panels by group. |
rgi_feature_plot() |
Focused plot of one gene’s, family’s or drug class’s abundance (RPKM or CLR): per group, per-subject trajectories, and first-to-last change. rgi_feature_abundance() returns the values behind it. |
rgi_mapping_stats() reads each sample’s total and mapped reads. All plots are ordinary ggplot2 objects, so they can be extended with + and saved with ggsave().
Example
The package ships the rgi bwt results (KMA, CARD 4.0.2) of 18 runs of BioProject PRJNA1556220 (the runs of the sylph2lab and funprofiler2lab example data) and the BioProject’s run table.
library(rgi2lab)
genes <- rgi_aggregate(
rgi_example("results"), # e.g. "data/rgi"
metadata = rgi_example("runs") # e.g. "data/PRJNA1556220_runs.csv"
)
rgi_timeline(genes, subject = "host_subject_id",
date = "collection_date", site = "isolation_source")
rgi_heatmap(genes, group = "isolation_source")
rgi_heatmap(genes, feature = "drug_class", group = "isolation_source")
rgi_feature_plot(genes, "ErmB", group = "isolation_source",
log10 = TRUE, italic = TRUE)Vignettes
Each function has a vignette, worked through on the example data:
-
vignette("rgi-aggregate", package = "rgi2lab"): combining results with metadata, filtering and normalising -
vignette("rgi-timeline", package = "rgi2lab"): cohort sampling timelines -
vignette("rgi-heatmap", package = "rgi2lab"): gene and drug class heatmaps -
vignette("rgi-feature-plot", package = "rgi2lab"): one gene or drug class, with or without CLR
Install with remotes::install_github("bjklab/rgi2lab", build_vignettes = TRUE) to have them available locally.
Notes on abundances and CLR
rgi bwt reports raw read counts per gene, which grow with sequencing depth and gene length. rgi2lab adds rpkm, reads per kilobase of gene per million sequenced reads (using each sample’s total reads from overall_mapping_stats.txt), which can be compared between samples and genes and is what the plots use by default, and relative_abundance, each gene’s share (%) of the sample’s length-normalised resistance gene reads. By default, genes covered over less than 50% of their length are dropped (min_coverage), since reads from shared stretches can map to genes that are not there.
The CLR is computed over the resistome (the resistance genes detected in data), not the whole metagenome, after replacing zeros with a pseudocount (by default half the smallest non-zero abundance). CLR values therefore depend on the set of samples and on the pseudocount; see ?rgi_feature_abundance.
rgi2lab works with read-level results only. Contig-level results of rgi main (Perfect/Strict/Loose hits on assembled contigs) are a different format and are not read.