Skip to content

Simplify Fisher's test section in GO over-enrichment analysis episode #129

Description

@js2264

Regarding the Fisher's exact test section, I would propose to largely simplify the section by presenting the problem through 2 questions : "1) for every gene in my universe, is the gene DE (TRUE/FALSE)? ; and 2) for every gene in my universe, is the gene in my gene set of interest (TRUE/FALSE)?". This can be done by creating a 2-column data.frame, then doing a table of it.

universe = rownames(se)
df <- data.frame(
    isSE = universe %in% sexDEgenes, 
    isGS = universe %in% XYGeneSet
)
# then 
table(df) |> fisher.test()

This has several advantages:

  • Explicitly requiring to define the universe (currently, the n value is used to calculate the intermediate n_20 and n_02 values, but not explicitly when filling out the matrix for the test).
  • Using table to do the calculation, rather than manually trying to calculate each value by hand (1 operation, vs 9 individual operations with not-so-easy variable names) -> less error-prone

This has the downside that it's not as easy to explain how to calculate the calculation for phypher section (or maybe actually easier? I don't know):

# Question: are DE genes over-represented within a gene set of interest? 
1 - phyper(
    sum(universe %in% sexDEgenes & rownames(se) %in% XYGeneSet) - 1,           # genes DE AND in gene set of interest
    sum(universe %in% sexDEgenes),       # genes DE
    sum(! universe %in% sexDEgenes),     # genes not DE
    length(XYGeneSet)                                # gene set of interest
)

Let me know if you would like this to be changed, in which case I can work on a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions