Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
zqfang committed Jun 15, 2023
1 parent 0008ae0 commit 77e2dc3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 2 additions & 0 deletions gseapy/biomart.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from collections.abc import Iterable
from io import StringIO
from typing import Any, AnyStr, Dict, Iterable, List, Optional, Set, Tuple, Union
Expand Down Expand Up @@ -271,6 +272,7 @@ def query(
self.results = df
# save file to cache path.
if filename is not None:
mkdirs(os.path.dirname(filename))
df.to_csv(filename, sep="\t", index=False)

return df
Expand Down
13 changes: 9 additions & 4 deletions gseapy/enrichr.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ def parse_background(self, gmt: Dict[str, List[str]] = None):
"""
set background genes
"""
if hasattr(self, "_bg") and self._bg:
return self._bg

self._bg = set()
if self.background is None:
# use all genes in the dict input as background if background is None
Expand Down Expand Up @@ -519,6 +522,8 @@ def parse_background(self, gmt: Dict[str, List[str]] = None):
except TypeError:
self._logger.error("Unsupported background data type")

return self._bg

def enrich(self, gmt: Dict[str, List[str]]):
"""use local mode
Expand All @@ -533,9 +538,9 @@ def enrich(self, gmt: Dict[str, List[str]]):
Term Overlap P-value Odds Ratio Combinde Score Adjusted_P-value Genes
"""
self.parse_background(gmt)
bg = self.parse_background(gmt)
# statistical testing
hgtest = list(calc_pvalues(query=self._gls, gene_sets=gmt, background=self._bg))
hgtest = list(calc_pvalues(query=self._gls, gene_sets=gmt, background=bg))
if len(hgtest) > 0:
terms, pvals, oddr, olsz, gsetsz, genes = hgtest
fdrs, rej = multiple_testing_correction(
Expand Down Expand Up @@ -595,9 +600,9 @@ def run(self):
self._gs = name
self._logger.debug("Enrichr service using library: %s" % (name))
# self._logger.info("Enrichr Library: %s"% self._gs)
self.parse_background()
bg = self.parse_background()
# whether user input background
if isinstance(self._bg, set) and len(self._bg) > 0:
if isinstance(bg, set) and len(bg) > 0:
shortID, res = self.get_results_with_background(
genes_list, self._bg
)
Expand Down

0 comments on commit 77e2dc3

Please sign in to comment.