Skip to content

Commit 1816e77

Browse files
changed enrich score terminology to also include cases that are not pvalues.
1 parent c44898a commit 1816e77

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

diffxpy/enrichment/enrich.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ def overlap(self, enq_set: set, set_id=None):
194194
def test(
195195
ref: RefSets,
196196
det: Union[_DifferentialExpressionTest, None] = None,
197-
pval: Union[np.array, None] = None,
197+
scores: Union[np.array, None] = None,
198198
gene_ids: Union[list, None] = None,
199-
de_threshold=0.05,
199+
threshold=0.05,
200200
incl_all_zero=False,
201201
all_ids=None,
202202
clean_ref=False,
@@ -211,12 +211,14 @@ def test(
211211
:param ref: The annotated gene sets against which enrichment is tested.
212212
:param det: The differential expression results object which is tested
213213
for enrichment in the gene sets.
214-
:param pval: Alternative to DETest, vector of p-values for differential expression.
214+
:param scores: Alternative to DETest, vector of scores (scalar per gene) which are then
215+
used to discretize gene list. This can for example be corrected p-values from a differential expression
216+
test, in that case the parameter threshold would be a significance threshold.
215217
:param gene_ids: If pval was supplied instead of DETest, use gene_ids to supply the
216218
vector of gene identifiers (strings) that correspond to the p-values
217219
which can be matched against the identifieres in the sets in RefSets.
218-
:param de_threshold: Significance threshold at which a differential test (a multiple-testing
219-
corrected p-value) is called siginficant. T
220+
:param threshold: Threshold of parameter scores at which a gene is included as a hit: In the case
221+
of differential test p-values in scores, threshold is the siginficance threshold.
220222
:param incl_all_zero: Wehther to include genes in gene universe which were all zero.
221223
:param all_ids: Set of all gene identifiers, this is used as the background set in the
222224
hypergeometric test. Only supply this if not all genes were tested
@@ -228,9 +230,9 @@ def test(
228230
return Enrich(
229231
ref=ref,
230232
det=det,
231-
pval=pval,
233+
scores=scores,
232234
gene_ids=gene_ids,
233-
de_threshold=de_threshold,
235+
threshold=threshold,
234236
incl_all_zero=incl_all_zero,
235237
all_ids=all_ids,
236238
clean_ref=clean_ref,
@@ -246,9 +248,9 @@ def __init__(
246248
self,
247249
ref: RefSets,
248250
det: Union[_DifferentialExpressionTest, None],
249-
pval: Union[np.array, None],
251+
scores: Union[np.array, None],
250252
gene_ids: Union[list, np.ndarray, None],
251-
de_threshold,
253+
threshold,
252254
incl_all_zero,
253255
all_ids,
254256
clean_ref,
@@ -269,8 +271,8 @@ def __init__(
269271
idx_not_all_zero = np.where(np.logical_not(det.summary()["zero_mean"].values))[0]
270272
self._qval_de = det.qval[idx_not_all_zero]
271273
self._gene_ids = det.gene_ids[idx_not_all_zero]
272-
elif pval is not None and gene_ids is not None:
273-
self._qval_de = np.asarray(pval)
274+
elif scores is not None and gene_ids is not None:
275+
self._qval_de = np.asarray(scores)
274276
self._gene_ids = gene_ids
275277
else:
276278
raise ValueError('Supply either DETest or pval and gene_ids to Enrich().')
@@ -286,7 +288,7 @@ def __init__(
286288
self._qval_de = self._qval_de[idx_notnan]
287289
self._gene_ids = self._gene_ids[idx_notnan]
288290

289-
self._significant_de = self._qval_de <= de_threshold
291+
self._significant_de = self._qval_de <= threshold
290292
self._significant_ids = set(self._gene_ids[np.where(self._significant_de)[0]])
291293
if all_ids is not None:
292294
self._all_ids = set(all_ids)

diffxpy/unit_test/test_enrich.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def test_for_fatal(self):
4141
enrich_test_i = de.enrich.test(
4242
ref=rs,
4343
det=test,
44-
de_threshold=0.05,
44+
threshold=0.05,
4545
incl_all_zero=i,
4646
clean_ref=j,
4747
)

0 commit comments

Comments
 (0)