Skip to content

Commit

Permalink
adjust FDR calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
LKremer committed Apr 24, 2023
1 parent 282f6eb commit 692b488
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 42 deletions.
64 changes: 26 additions & 38 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions scbs/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,23 +38,23 @@ def permuted_indices(idx_celltypes, celltype_1, celltype_2, total_cells):
return index_g1, index_g2


# @njit("float64(boolean)")
@njit
def calc_fdr(bools):
"""
Calculates an adjusted p-value for each DMR using the Benjamini-Hochberg method.
Input is an array of boolean values, where each value represents a DMR.
The array is sorted by absolute t-statistic and the boolean indicates whether the
the DMR was found in a permutation (False) or in the real comparison (True).
"""
n_t = sum(bools) # number of DMRs in the real comparison
n_t = bools.sum() # number of DMRs in the real comparison
n_t_null = len(bools) - n_t # number of DMRs in the permutation
fdisc = 0 # number of false discoveries up until a certain threshold
tdisc = 0
adj_p_vals = np.empty(bools.shape, dtype=np.float64)
for i in range(len(bools)):
if bools[i]:
if bools[i]: # it's from the real comparison
tdisc += 1
else:
else: # it's from the permutation
fdisc += 1
adj_p_val = (fdisc / n_t_null) / (tdisc / n_t)
adj_p_vals[i] = adj_p_val
Expand Down

0 comments on commit 692b488

Please sign in to comment.