Skip to content

Commit 8424434

Browse files
added enrich vignette in examples and fixed some issues in enrich.test
1 parent 54e2578 commit 8424434

File tree

2 files changed

+384
-5
lines changed

2 files changed

+384
-5
lines changed

diffxpy/enrichment/enrich.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def test(
190190
gene_ids: list = None,
191191
de_threshold=0.05,
192192
all_ids = None,
193-
clean_ref = True
193+
clean_ref = True,
194+
upper = False
194195
):
195196
""" Perform gene set enrichment.
196197
@@ -219,6 +220,8 @@ def test(
219220
:param clean_ref:
220221
Whether or not to only retain gene identifiers in RefSets that occur in
221222
the background set of identifiers supplied here through all_ids.
223+
:param upper:
224+
Make all gene IDs captial.
222225
"""
223226
return Enrich(
224227
RefSets = RefSets,
@@ -227,7 +230,8 @@ def test(
227230
gene_ids = gene_ids,
228231
de_threshold = de_threshold,
229232
all_ids = all_ids,
230-
clean_ref = clean_ref)
233+
clean_ref = clean_ref,
234+
upper = upper)
231235

232236
class Enrich():
233237
"""
@@ -241,7 +245,8 @@ def __init__(
241245
gene_ids: list = None,
242246
de_threshold=0.05,
243247
all_ids = None,
244-
clean_ref = True
248+
clean_ref = True,
249+
upper = False
245250
):
246251
self._n_overlaps = None
247252
self._pval_enrich = None
@@ -272,6 +277,10 @@ def __init__(
272277
else:
273278
self._all_ids = set(self._gene_ids)
274279

280+
if upper==True:
281+
self._gene_ids = [x.upper() for x in self._gene_ids]
282+
self._all_ids = set([x.upper() for x in self._all_ids])
283+
275284
# Generate diagnostic statistic of number of possible overlaps in total.
276285
print(str(len(set(self._all_ids).intersection(set(RefSets._genes))))+
277286
' overlaps found between refset ('+str(len(RefSets._genes))+
@@ -285,9 +294,9 @@ def __init__(
285294
idx_nonempty = np.where([len(x.genes)>0 for x in self.RefSets.sets])[0]
286295
if len(self.RefSets.sets)-len(idx_nonempty) > 0:
287296
print('Found '+str(len(self.RefSets.sets)-len(idx_nonempty))+
288-
' empty sets after cleaning, removing those.')
297+
' empty sets, removing those.')
289298
self.RefSets = self.RefSets.subset(idx=idx_nonempty)
290-
else:
299+
elif len(idx_nonempty)==0:
291300
raise ValueError('all RefSets were empty')
292301

293302
@property

0 commit comments

Comments
 (0)