enrichmentTest: enrichmentTest

View source: R/enrichment.R

enrichmentTestR Documentation



Perform the Fisher exact test for all the possible 2x2 contingency tables, considering differential abundance direction and enrichment variable.


enrichmentTest(method, enrichmentCol, alternative = "greater")



Output of differential abundance detection method in which DA information is extracted by the getDA function and the information related to enrichment is appropriately added through the addKnowledge.


name of the column containing information for enrichment analysis.


indicates the alternative hypothesis and must be one of "two.sided", "greater" or "less". You can specify just the initial letter. Only used in the 2 by 2 case.


a list of objects:

  • data a data.frame object with DA directions, statistics, and feature names;

  • tables a list of 2x2 contingency tables;

  • tests the list of Fisher exact tests' p-values for each contingency table;

  • summaries a list with the first element of each contingency table and its p-value (for graphical purposes);

See Also

extractDA, addKnowledge, and createEnrichment



# Extract genera from the phyloseq tax_table slot
genera <- phyloseq::tax_table(ps_plaque_16S)[, "GENUS"]
# Genera as rownames of microbial_metabolism data.frame
rownames(microbial_metabolism) <- microbial_metabolism$Genus
# Match OTUs to their metabolism
priorInfo <- data.frame(genera,
    "Type" =  microbial_metabolism[genera, "Type"])
# Unmatched genera becomes "Unknown"
unknown_metabolism <- is.na(priorInfo$Type)
priorInfo[unknown_metabolism, "Type"] <- "Unknown"
priorInfo$Type <- factor(priorInfo$Type)
# Add a more informative names column
priorInfo[, "newNames"] <- paste0(rownames(priorInfo), priorInfo[, "GENUS"])

# DA Analysis

# Make sure the subject ID variable is a factor
phyloseq::sample_data(ps_plaque_16S)[, "RSID"] <- as.factor(
# Add scaling factors
ps_plaque_16S <- norm_edgeR(object = ps_plaque_16S, method = "TMM")

# DA analysis
da.limma <- DA_limma(
    object = ps_plaque_16S,
    design = ~ 1 + RSID + HMP_BODY_SUBSITE,
    coef = "HMP_BODY_SUBSITESupragingival Plaque",
    norm = "TMM"

DA <- getDA(method = da.limma, slot = "pValMat", colName = "adjP",
    type = "pvalue", direction = "logFC", threshold_pvalue = 0.05,
    threshold_logfc = 1, top = NULL)
# Add a priori information
DA_info <- addKnowledge(method = DA, priorKnowledge = priorInfo,
    enrichmentCol = "Type", namesCol = "newNames")
# Create contingency tables and compute F tests
DA_info_enriched <- enrichmentTest(method = DA_info, enrichmentCol = "Type",
    alternative = "greater")

mcalgaro93/benchdamic documentation built on Nov. 28, 2022, 6:55 p.m.