Abundance of one resistance gene, gene family or drug class in each sample
Source:R/rgi_feature.R
rgi_feature_abundance.RdSums the abundance of the genes matching feature in each sample,
optionally as a centred log-ratio (CLR). Samples where no matching gene
was detected (including samples with no resistance genes at all) get an
abundance of 0. This is the table behind rgi_feature_plot(), and is
useful for modelling on its own.
Usage
rgi_feature_abundance(
data,
feature,
level = "aro_term",
abundance = "rpkm",
sample = "sample_id",
match = c("exact", "regex", "fixed"),
clr = FALSE,
clr_level = "aro_term",
pseudocount = NULL,
keep = NULL
)Arguments
- data
A data frame from
rgi_aggregate(), or any data frame with sample, feature and abundance columns, one row per sample and gene, with a single set of results per sample.- feature
The gene, family, drug class or mechanism to look for in
level, e.g."ErmB"or"carbapenem". Withmatch = "exact", may be a vector of several.- level
Column to search for
feature. Defaults to"aro_term". Any column works, e.g."amr_gene_family","drug_class"or"resistance_mechanism".- abundance
Abundance column:
"rpkm"(reads per kilobase per million, the default),"relative_abundance"(% of the sample's resistance gene content) or"all_mapped_reads"(raw read counts).- sample
Column identifying the sample. Defaults to
"sample_id".- match
How
featureis matched:"exact","regex"or"fixed"; see Details.- clr
If
TRUE, also return the CLR-transformed abundance; see Details.- clr_level
Column defining the other parts of the composition for the CLR, with one value per gene. Defaults to
"aro_term"(each gene).- pseudocount
Value that replaces zeros before the CLR. Defaults to half the smallest non-zero abundance in
data.- keep
Other columns to carry into the result, e.g. subject, group or date. They must have one value per sample.
Value
A tibble with one row per sample: the sample column, the keep
columns, abundance (the summed abundance, in the units of the
abundance column), n_genes (the number of matching genes detected),
and with clr = TRUE, clr.
Details
Genes match when feature is found in their level column. How it is
found depends on match:
"exact"(the default)featuremust equal the whole value, or, for CARD's multi-valued columns (amr_gene_family,drug_class,resistance_mechanism), one of its"; "-separated values, ignoring case. Several features can be given as a vector, e.g.c("mecA", "mecC"). Best for ARO terms such as"tet(Q)"or"APH(3')-IIIa", whose brackets are special in regular expressions."regex"featureis a regular expression, matched anywhere in the value, ignoring case:"^tet"matches all genes whose ARO term starts with "tet", and"beta-lactamase"withlevel = "amr_gene_family"all beta-lactamase families."fixed"featureis found anywhere in the value, exactly as written (case-sensitive).
With level = "aro_term" (the default), feature = "ErmB" picks one
gene. With level = "drug_class", feature = "carbapenem" sums all
genes conferring resistance to carbapenems; each gene is counted once,
however many of its values match.
CLR. With clr = TRUE, each sample's composition is built from the
matching genes, added together into one part, and every other gene (by
default; see clr_level) as a part of its own; genes not detected in a
sample are 0 there. Zeros are replaced with pseudocount, and the CLR of
the feature is
$$\log(x_{feature}) - \frac{1}{D}\sum_{j=1}^{D} \log(x_j)$$
over the sample's \(D\) parts. The composition is the resistome (the
resistance genes detected anywhere in data), not the whole metagenome,
so the CLR says how prominent the feature is among the sample's
resistance genes; it depends on which samples are included and on the
pseudocount, so report both. Samples with no resistance genes have no
composition, and their clr is NA. For depth-normalised abundance
comparable between samples, use rpkm without CLR.
See also
rgi_feature_plot() to plot it.
Examples
genes <- rgi_aggregate(rgi_example("results"),
metadata = rgi_example("runs"))
#> 1221 of 2469 gene detections were below `min_coverage` = 50% or `min_reads` = 0 and were left out.
# ErmB, a macrolide resistance gene
rgi_feature_abundance(genes, "ErmB",
keep = c("host_subject_id", "isolation_source"),
clr = TRUE)
#> # A tibble: 18 × 6
#> sample_id host_subject_id isolation_source abundance n_genes clr
#> <chr> <chr> <chr> <dbl> <int> <dbl>
#> 1 SRR41520862 GOL_019 Stool Swab 29.6 1 4.37
#> 2 SRR41520863 GOL_017 Stool Swab 45.8 1 4.70
#> 3 SRR41520865 GOL_017 Perirectal Swab 28.0 1 4.91
#> 4 SRR41520867 GOL_015 Stool Swab 1.95 1 2.19
#> 5 SRR41520868 GOL_019 Stool Swab 46.7 1 4.23
#> 6 SRR41520869 GOL_016 Perirectal Swab 61.6 1 3.80
#> 7 SRR41520870 GOL_016 Perirectal Swab 3.65 1 1.98
#> 8 SRR41520873 GOL_017 Groin Swab 1.26 1 1.66
#> 9 SRR41520874 GOL_034 Groin Swab 1.69 1 2.04
#> 10 SRR41520876 GOL_015 Stool Swab 8.37 1 3.81
#> 11 SRR41520878 GOL_017 Perirectal Swab 41.6 1 4.56
#> 12 SRR41520879 GOL_017 Stool Swab 57.2 1 4.93
#> 13 SRR41520882 GOL_017 Perirectal Swab 36.6 1 4.31
#> 14 SRR41520884 GOL_003 Stool Swab 9.37 1 4.25
#> 15 SRR41520894 GOL_018 Stool Swab 0 0 -0.606
#> 16 SRR41520897 GOL_015 Axilla Swab 17.0 1 4.43
#> 17 SRR41520902 GOL_003 Stool Swab 25.2 1 3.41
#> 18 SRR41520919 GOL_016 Axilla Swab 0 0 -0.502
# all genes conferring resistance to tetracyclines
rgi_feature_abundance(genes, "tetracycline antibiotic",
level = "drug_class")
#> # A tibble: 18 × 3
#> sample_id abundance n_genes
#> <chr> <dbl> <int>
#> 1 SRR41520862 246. 25
#> 2 SRR41520863 407. 25
#> 3 SRR41520865 169. 16
#> 4 SRR41520867 178. 16
#> 5 SRR41520868 588. 29
#> 6 SRR41520869 708. 53
#> 7 SRR41520870 290. 28
#> 8 SRR41520873 246. 3
#> 9 SRR41520874 279. 6
#> 10 SRR41520876 162. 13
#> 11 SRR41520878 558. 24
#> 12 SRR41520879 348. 27
#> 13 SRR41520882 767. 25
#> 14 SRR41520884 17.5 7
#> 15 SRR41520894 44.3 14
#> 16 SRR41520897 366. 3
#> 17 SRR41520902 659. 41
#> 18 SRR41520919 273. 2
# all tet genes, by regular expression
rgi_feature_abundance(genes, "^tet", match = "regex")
#> # A tibble: 18 × 3
#> sample_id abundance n_genes
#> <chr> <dbl> <int>
#> 1 SRR41520862 170. 14
#> 2 SRR41520863 90.2 10
#> 3 SRR41520865 159. 12
#> 4 SRR41520867 174. 10
#> 5 SRR41520868 160. 10
#> 6 SRR41520869 240. 13
#> 7 SRR41520870 9.85 5
#> 8 SRR41520873 6.38 2
#> 9 SRR41520874 5.62 3
#> 10 SRR41520876 162. 13
#> 11 SRR41520878 95.6 8
#> 12 SRR41520879 94.3 10
#> 13 SRR41520882 69.8 8
#> 14 SRR41520884 15.6 5
#> 15 SRR41520894 12.1 3
#> 16 SRR41520897 7.68 1
#> 17 SRR41520902 136. 13
#> 18 SRR41520919 0.407 1