Skip to content

Commit

Permalink
do not remove all rows when one under obs limit
Browse files Browse the repository at this point in the history
  • Loading branch information
mschubert committed Nov 3, 2023
1 parent 5e19eea commit 86eb76c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion genesets/test_fet.r
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ test_fet = function(valid, hits, sets, min=2, max=Inf) {
setNames(names(sets)) %>%
dplyr::bind_rows(.id="label") %>%
as_tibble() %>%
na.omit() %>%
filter(size >= min) %>%
select(label, size, size_used, everything()) %>%
mutate(adj.p = p.adjust(p.value, method="fdr")) %>%
arrange(adj.p, p.value)
Expand Down
7 changes: 4 additions & 3 deletions genesets/test_lm.r
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ test_lm = function(genes, sets,
min_n=2, add_means=c(), trim=0, cl=0) {
test_one = function(res, set) {
dset = res %>% mutate(in_set = !! rlang::sym(label) %in% set + 0)
if (sum(dset$in_set, na.rm=TRUE) < min_n)
return(data.frame(estimate=NA, size=length(set), size_used=NA))
sz_use = sum(dset$in_set, na.rm=TRUE)
if (sz_use < min_n)
return(data.frame(size=length(set), size_used=sz_use))

sums = dset %>% group_by(in_set) %>%
summarize_at(vars(all_of(add_means)), function(x) mean(x, na.rm=TRUE, trim=trim)) %>%
Expand Down Expand Up @@ -70,7 +71,7 @@ test_lm = function(genes, sets,
setNames(names(sets)) %>%
dplyr::bind_rows(.id="label") %>%
as_tibble() %>%
na.omit() %>%
filter(size_used >= min_n) %>%
select(label, size, size_used, !!! rlang::syms(add_means), everything()) %>%
mutate(adj.p = p.adjust(p.value, method="fdr")) %>%
arrange(adj.p, p.value)
Expand Down

0 comments on commit 86eb76c

Please sign in to comment.