Skip to contents

Sums the abundance of the KOs matching feature in each sample, optionally as a centred log-ratio (CLR). Samples where no matching KO was detected get an abundance of 0. This is the table behind funprofiler_feature_plot(), and is useful for modelling on its own.

Usage

funprofiler_feature_abundance(
  data,
  feature,
  level = "ko",
  abundance = "relative_abundance",
  sample = "sample_id",
  fixed = FALSE,
  clr = FALSE,
  clr_level = "ko",
  pseudocount = NULL,
  keep = NULL
)

Arguments

data

A data frame from funprofiler_aggregate(), or any data frame with sample, feature and abundance columns, one row per sample and KO, with a single profile per sample.

feature

Text (a regular expression unless fixed = TRUE) to look for in level, e.g. "K01990" or "beta-Lactam resistance".

level

Column to search for feature. Defaults to "ko". Any column works, e.g. "pathway", "pathway_class", "ko_name" or "ko_symbol".

abundance

Abundance column: "relative_abundance" (%, the default) or "abundance" (proportion).

sample

Column identifying the sample. Defaults to "sample_id".

fixed

If TRUE, match feature exactly as written (case-sensitive, not a regular expression).

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 KO. Defaults to "ko" (each KO).

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_kos (the number of matching KOs detected), and with clr = TRUE, clr.

Details

KOs match when feature is found in their level column, a regular expression match ignoring case unless fixed = TRUE. With level = "ko" (the default), feature = "K01990" picks one KO, and "K01990|K01992" two. After funprofiler_aggregate() with kegg:

  • level = "pathway", feature = "beta-Lactam resistance" sums the KOs of a pathway (pathway lists all of a KO's pathways, so a KO matches if any of them does);

  • level = "pathway_class", feature = "Drug resistance: antimicrobial" sums a class of pathways;

  • level = "ko_name" or "ko_symbol" match gene names, e.g. "^bla" with level = "ko_symbol".

Each KO is counted once, however many of its pathways match. In regular expressions, escape special characters ("Glycolysis / Gluconeogenesis" is fine, but parentheses need \\(), or use fixed = TRUE.

CLR. With clr = TRUE, each sample's composition is built from the matching KOs, added together into one part, and every other KO (by default; see clr_level) as a part of its own; KOs 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. Because funprofiler reports only KOs detected in a sample, \(D\) is the number of KOs detected anywhere in data, and the CLR depends on which samples are included and on the pseudocount; report both.

See also

Examples

profiles <- funprofiler_aggregate(funprofiler_example("profiles"),
                                  metadata = funprofiler_example("runs"))

# K01990, ABC-2 type transport system ATP-binding protein
funprofiler_feature_abundance(profiles, "K01990",
                              keep = c("host_subject_id",
                                       "isolation_source"),
                              clr = TRUE)
#> # A tibble: 18 × 6
#>    sample_id   host_subject_id isolation_source abundance n_kos   clr
#>    <chr>       <chr>           <chr>                <dbl> <int> <dbl>
#>  1 SRR41520862 GOL_019         Stool Swab          0.344      1  4.00
#>  2 SRR41520863 GOL_017         Stool Swab          0.320      1  3.81
#>  3 SRR41520865 GOL_017         Perirectal Swab     0.333      1  3.90
#>  4 SRR41520867 GOL_015         Stool Swab          0.272      1  3.78
#>  5 SRR41520868 GOL_019         Stool Swab          0.304      1  3.84
#>  6 SRR41520869 GOL_016         Perirectal Swab     0.365      1  3.98
#>  7 SRR41520870 GOL_016         Perirectal Swab     0.288      1  3.76
#>  8 SRR41520873 GOL_017         Groin Swab          0.506      1  4.71
#>  9 SRR41520874 GOL_034         Groin Swab          0.0727     1  2.67
#> 10 SRR41520876 GOL_015         Stool Swab          0.318      1  3.99
#> 11 SRR41520878 GOL_017         Perirectal Swab     0.314      1  3.81
#> 12 SRR41520879 GOL_017         Stool Swab          0.325      1  3.83
#> 13 SRR41520882 GOL_017         Perirectal Swab     0.298      1  3.71
#> 14 SRR41520884 GOL_003         Stool Swab          0.215      1  3.83
#> 15 SRR41520894 GOL_018         Stool Swab          0.0775     1  2.60
#> 16 SRR41520897 GOL_015         Axilla Swab         0.328      1  4.27
#> 17 SRR41520902 GOL_003         Stool Swab          0.290      1  3.74
#> 18 SRR41520919 GOL_016         Axilla Swab         0.219      1  3.73

if (FALSE) { # \dontrun{
profiles <- funprofiler_aggregate(
  funprofiler_example("profiles"), metadata = funprofiler_example("runs"),
  kegg = funprofiler_kegg("data/kegg/ko00001.keg")
)
funprofiler_feature_abundance(profiles, "beta-Lactam resistance",
                              level = "pathway", clr = TRUE)
} # }