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.
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
tableof it.This has several advantages:
nvalue is used to calculate the intermediaten_20andn_02values, but not explicitly when filling out the matrix for the test).tableto 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-proneThis has the downside that it's not as easy to explain how to calculate the calculation for
phyphersection (or maybe actually easier? I don't know):Let me know if you would like this to be changed, in which case I can work on a PR.