Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_grprobj():
"""Get object for grouping GO IDs."""
fin_obo = os.path.join(REPO, "go-basic.obo")
godag = get_godag(fin_obo, prt=None, loading_bar=False, optional_attrs=['relationship'])
gosubdag = GoSubDag(USER_GOS, godag, relationships=True, tcntobj=None)
grprdflt = GrouperDflts(gosubdag)
hdrobj = HdrgosSections(gosubdag, grprdflt.hdrgos_dflt, SECTIONS)
return Grouper("wrusrgos", USER_GOS, hdrobj, gosubdag)
def _wr_sections_txt(fout_txt, usrgos, sections, grprdflt):
"""Given a list of usrgos and sections, write text file."""
try:
hdrobj = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=sections)
grprobj = Grouper(fout_txt, usrgos, hdrobj, grprdflt.gosubdag, go2nt=None)
full_txt = os.path.join(REPO, fout_txt)
WrSectionsTxt(grprobj).wr_txt_section_hdrgos(full_txt, sortby=None, prt_section=True)
assert os.path.exists(full_txt)
except RuntimeError as inst:
sys.stdout.write("\n **FATAL: {MSG}\n\n".format(MSG=str(inst)))
"GO:0050794", # BP 8,031 L02 D02 AB regulation of cellular process
"GO:0019222", # BP 3,227 L02 D02 AB regulation of metabolic process
"GO:0048583", # BP 2,377 L02 D02 AB regulation of response to stimulus
"GO:0050793", # BP 1,789 L02 D02 AB regulation of developmental process
"GO:0023051", # BP 1,364 L02 D02 AB regulation of signaling
"GO:0002682", # BP 1,183 L02 D02 AB regulation of immune system process
"GO:0007155", # BP 165 L02 D02 P cell adhesion
"GO:0080134", # BP 940 L03 D03 AB regulation of response to stress
"GO:0007165", # BP 717 L03 D03 AB signal transduction
"GO:0050877", # BP 96 L03 D03 K neurological system process
"GO:0007267"]) # BP 99 L03 D04 CDR cell-cell signaling
# Since no "GO group headers" (None) were provided, depth-01 GOs are used for grouping.
hdrobj0 = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=None)
grprobj0 = Grouper("dflt", data, hdrobj0, grprdflt.gosubdag, go2nt=None)
_, _, nts0_go, act_hdrs0 = run(grprobj0, hdrobj0, exp_hdrs0)
# Grouping GOs are provided, these are added to the depth-01 defaults GOs are used for grouping.
hdrgos = set([
"GO:0099536", # BP 40 L04 D05 CDR regulation of response to stimulus
"GO:0051239", # BP 2,532 L02 D02 AB regulation of multicellular organismal process
"GO:0048519", # BP 3,293 L02 D02 AB negative regulation of biological process
"GO:0048518"])# BP 3,353 L02 D02 AB positive regulation of biological process
exp_hdrs1 = exp_hdrs0.union(hdrgos)
name = "usrhdrs4"
hdrobj1 = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=hdrgos)
grprobj1 = Grouper(name, data, hdrobj1, grprdflt.gosubdag, go2nt=None)
sortobj1, _, nts1_go, act_hdrs1 = run(grprobj1, hdrobj1, exp_hdrs1)
if do_plt:
f_sec_rd = os.path.join(REPO, "data/gjoneska_pfenning/sections_in.txt")
f_sec_wr = os.path.join(REPO, "tmp_test_sections_out.txt")
# Travis-CI path is cwd
f_sec_py = os.path.join(REPO, "tmp_test_sections.py")
# f_sec_mod = "tmp_test_sections"
# Read user GO IDs. Setup to write sections text file and Python file
usrgos = [getattr(nt, 'GO') for nt in goea_results]
sec_rd = _read_sections(f_sec_rd)
# Do preliminaries
godag = _get_godag()
gosubdag = GoSubDag(usrgos, godag, relationships=True, tcntobj=None)
grprdflt = _get_grprdflt(gosubdag)
# Exclude ungrouped "Misc." section of sections var(sec_rd)
hdrobj = HdrgosSections(gosubdag, grprdflt.hdrgos_dflt, sec_rd[:-1])
assert sec_rd[-1][0] == hdrobj.secdflt, sec_rd[-1][0]
grprobj = Grouper("test", usrgos, hdrobj, gosubdag)
# Create text and Python sections files
objsecwr = WrSectionsTxt(grprobj)
objsecwr.wr_txt_section_hdrgos(os.path.join(REPO, f_sec_wr))
objsecpy = WrSectionsPy(grprobj)
objsecpy.wr_py_sections(os.path.join(REPO, f_sec_py), sec_rd, doc=godag.version)
# Read text and Python sections files
sec_wr = _read_sections(f_sec_wr)
sec_py = _read_sections(f_sec_py)
# sec_mod = _read_sections(f_sec_mod)
def test_grouper_d2(do_plot=False):
"""Group depth-02 GO terms under their most specific depth-01 GO parent(s)."""
print('CWD', os.getcwd())
# Get GOs to be grouped
# Since no "Grouping GOs" were provided, depth-01 GOs are used for grouping.
grprdflt = _get_grprdflt()
hdrobj = HdrgosSections(grprdflt.gosubdag, grprdflt.hdrgos_dflt, sections=None, hdrgos=None)
grprobj = Grouper("Transient Increase", get_data0(), hdrobj, _get_gosubdag(), go2nt=None)
objwr = WrSectionsTxt(grprobj)
objwr.wr_txt_section_hdrgos("transient_increase_hdrgos.txt")
objwr.wr_txt_grouping_gos()
if do_plot:
# Don't run in Travis-CI because it does not contain 'dot'
from goatools.grouper.grprplt import GrouperPlot
GrouperPlot(grprobj).plot_groups_unplaced()
chk_hdrs(grprobj)
def _get_sortobj():
"""Get object for grouping GO IDs."""
fin_godag = os.path.join(REPO, "go-basic.obo")
godag = get_godag(fin_godag, prt=None, loading_bar=False, optional_attrs=['relationship'])
gosubdag = GoSubDag(USER_GOS, godag, relationships=True, tcntobj=None)
grprdflt = GrouperDflts(gosubdag)
hdrobj = HdrgosSections(gosubdag, grprdflt.hdrgos_dflt, SECTIONS)
grprobj = Grouper("wrusrgos", USER_GOS, hdrobj, gosubdag)
return Sorter(grprobj)
def get_sortobj(self, goea_results, **kws):
"""Return a Grouper object, given a list of GOEnrichmentRecord."""
nts_goea = MgrNtGOEAs(goea_results).get_goea_nts_prt(**kws)
goids = set(nt.GO for nt in nts_goea)
go2nt = {nt.GO:nt for nt in nts_goea}
grprobj = Grouper("GOEA", goids, self.hdrobj, self.grprdflt.gosubdag, go2nt=go2nt)
grprobj.prt_summary(sys.stdout)
# hdrgo_prt", "section_prt", "top_n", "use_sections"
sortobj = Sorter(grprobj, section_sortby=lambda nt: getattr(nt, self.pval_fld))
return sortobj
def _get_grprobj(self, goids, sections):
"""Get Grouper, given GO IDs and sections."""
grprdflt = GrouperDflts(self.gosubdag, "goslim_generic.obo")
hdrobj = HdrgosSections(self.gosubdag, grprdflt.hdrgos_dflt, sections)
return Grouper("sections", goids, hdrobj, self.gosubdag)