예제 #1
0
 def _plt_gogrouped(self, goids, go2color_usr, **kws):
     """Plot grouped GO IDs."""
     fout_img = self.get_outfile(kws['outfile'], goids)
     sections = read_sections(kws['sections'], exclude_ungrouped=True)
     print("KWWSSSSSSSS", kws)
     # kws_plt = {k:v for k, v in kws.items if k in self.kws_plt}
     grprobj_cur = self._get_grprobj(goids, sections)
     # GO: purple=hdr-only, green=hdr&usr, yellow=usr-only
     # BORDER: Black=hdr Blu=hdr&usr
     grpcolor = GrouperColors(
         grprobj_cur)  # get_bordercolor get_go2color_users
     grp_go2color = grpcolor.get_go2color_users()
     grp_go2bordercolor = grpcolor.get_bordercolor()
     for goid, color in go2color_usr.items():
         grp_go2color[goid] = color
     objcolor = Go2Color(self.gosubdag,
                         objgoea=None,
                         go2color=grp_go2color,
                         go2bordercolor=grp_go2bordercolor)
     go2txt = GrouperPlot.get_go2txt(grprobj_cur, grp_go2color,
                                     grp_go2bordercolor)
     objplt = GoSubDagPlot(self.gosubdag,
                           Go2Color=objcolor,
                           go2txt=go2txt,
                           **kws)
     objplt.prt_goids(sys.stdout)
     objplt.plt_dag(fout_img)
     sys.stdout.write("{N:>6} sections read\n".format(
         N="NO" if sections is None else len(sections)))
     return fout_img
예제 #2
0
def _read_sections(sec):
    """Get sections variable from file."""
    if '/' in sec:
        sec = os.path.join(REPO, sec)
    var = read_sections(sec)
    assert var, "EMPTY SECTIONS FILE({})".format(sec)
    return var
예제 #3
0
def _read_sections(sec):
    """Get sections variable from file."""
    if '/' in sec:
        sec = os.path.join(REPO, sec)
    var = read_sections(sec)
    assert var, "EMPTY SECTIONS FILE({})".format(sec)
    return var
예제 #4
0
 def _get_objpltg(self, goids, go2color_usr, **kws):
     """Plot grouped GO IDs."""
     #### fout_img = self.get_outfile(kws['outfile'], goids)
     sections = read_sections(kws['sections'], exclude_ungrouped=True)
     # print ("KWWSSSSSSSS", kws)
     # kws_plt = {k:v for k, v in kws.items if k in self.kws_plt}
     grprobj_cur = self._get_grprobj(goids, sections)
     # GO: purple=hdr-only, green=hdr&usr, yellow=usr-only
     # BORDER: Black=hdr Blu=hdr&usr
     grpcolor = GrouperColors(
         grprobj_cur)  # get_bordercolor get_go2color_users
     grp_go2color = grpcolor.get_go2color_users()
     grp_go2bordercolor = grpcolor.get_bordercolor()
     for goid, color in go2color_usr.items():
         grp_go2color[goid] = color
     objcolor = Go2Color(self.gosubdag,
                         objgoea=None,
                         go2color=grp_go2color,
                         go2bordercolor=grp_go2bordercolor)
     go2txt = GrouperPlot.get_go2txt(grprobj_cur, grp_go2color,
                                     grp_go2bordercolor)
     return GoSubDagPlot(self.gosubdag,
                         Go2Color=objcolor,
                         go2txt=go2txt,
                         **kws)
예제 #5
0
 def __init__(self, gosubdag, godag_version, **kws):
     _kws = {k: v for k, v in kws.items() if k in self.kws_dict}
     self.grprdflt = GrouperDflts(gosubdag, _kws['slims'])
     self.ver_list = [godag_version, self.grprdflt.ver_goslims]
     self.sections = read_sections(self._get_secstr(**_kws),
                                   exclude_ungrouped=False)
     self.hdrobj = HdrgosSections(gosubdag, self.grprdflt.hdrgos_dflt,
                                  self.sections)
     _go2nt = _kws.get('go2nt')
     self.grprobj = Grouper("all",
                            gosubdag.go_sources,
                            self.hdrobj,
                            gosubdag,
                            go2nt=_go2nt)
예제 #6
0
 def __init__(self, args):
     self.args = args
     self.sections = read_sections(self.args.sections) if self.args.sections else None
     _optional_attrs = ['relationship'] if self.sections else None
     self.godag = GODag(obo_file=self.args.obo, optional_attrs=_optional_attrs)
     # Get GOEnrichmentStudy
     _study, _pop, _assoc = self.rd_files()
     if not self.args.compare:  # sanity check
         self.chk_genes(_study, _pop)
     self.methods = self.args.method.split(",")
     self.itemid2name = self._init_itemid2name()
     self.objgoea = self._init_objgoea(_pop, _assoc)
     # Run GOEA
     self.results_all = self.objgoea.run_study(_study)
     # Prepare for grouping, if user-specified. Create GroupItems
     self.prepgrp = GroupItems(_assoc, self, self.godag.version) if self.sections else None
예제 #7
0
def _wr_sections_txt(fout_txt, usrgos, sections_file, grprdflt):
    """Given a list of usrgos and sections, write text file."""
    try:
        sections = read_sections(sections_file)
        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)
        WrSections(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)))
예제 #8
0
 def __init__(self, args):
     self.args = args
     self.sections = read_sections(self.args.sections) if self.args.sections else None
     _optional_attrs = ['relationship'] if self.sections else None
     self.godag = GODag(obo_file=self.args.obo, optional_attrs=_optional_attrs)
     # Get GOEnrichmentStudy
     print('ARGS GoeaCliFnc', self.args)
     self.objanno = self._get_objanno(self.args.filenames[2])
     _ns2assoc = self.objanno.get_ns2assc(**self._get_anno_kws())
     _study, _pop = self.rd_files(*self.args.filenames[:2])
     if not self.args.compare:  # sanity check
         self.chk_genes(_study, _pop, self.objanno.associations)
     self.methods = self.args.method.split(",")
     self.itemid2name = self._init_itemid2name()
     self.objgoeans = self._init_objgoeans(_pop, _ns2assoc)
     # Run GOEA
     self.results_all = self.objgoeans.run_study(_study)
     # Prepare for grouping, if user-specified. Create GroupItems
     self.prepgrp = GroupItems(self, self.godag.version) if self.sections else None
예제 #9
0
 def __init__(self, args):
     self.args = args
     self.sections = read_sections(
         self.args.sections) if self.args.sections else None
     _optional_attrs = ['relationship'] if self.sections else None
     self.godag = GODag(obo_file=self.args.obo,
                        optional_attrs=_optional_attrs)
     # Get GOEnrichmentStudy
     # print('ARGS GoeaCliFnc ', self.args)
     self.objanno = self._get_objanno(self.args.filenames[2])
     _ns2assoc = self.objanno.get_ns2assc(**self._get_anno_kws())
     _study, _pop = self.rd_files(*self.args.filenames[:2])
     if not self.args.compare:  # sanity check
         self.chk_genes(_study, _pop, self.objanno.associations)
     self.methods = self.args.method.split(",")
     self.itemid2name = self._init_itemid2name()
     self.objgoeans = self._init_objgoeans(_pop, _ns2assoc)
     # Run GOEA
     self.results_all = self.objgoeans.run_study(_study)
     # Prepare for grouping, if user-specified. Create GroupItems
     self.prepgrp = GroupItems(
         self, self.godag.version) if self.sections else None
예제 #10
0
 def cli(self, prt=sys.stdout):
     """Command-line interface for go_draw script."""
     kws = self.objdoc.get_docargs(prt=None)
     godag = get_godag(kws['obo'],
                       prt=None,
                       loading_bar=False,
                       optional_attrs=['relationship'])
     usrgos = GetGOs(godag, max_gos=200).get_usrgos(kws.get('GO_FILE'), prt)
     tcntobj = self._get_tcntobj(usrgos, godag,
                                 **kws)  # Gets TermCounts or None
     self.gosubdag = GoSubDag(usrgos,
                              godag,
                              relationships=True,
                              tcntobj=tcntobj,
                              prt=None)
     grprdflt = GrouperDflts(self.gosubdag, kws['slims'])
     ver_list = [godag.version, grprdflt.ver_goslims]
     prt.write("{VER}\n".format(VER="\n".join(ver_list)))
     sections = read_sections(kws['ifile'],
                              exclude_ungrouped=True,
                              prt=None)
     # print("SECSECSEC", sections)
     hdrobj = HdrgosSections(self.gosubdag, grprdflt.hdrgos_dflt, sections)
     grprobj = Grouper("init", usrgos, hdrobj, self.gosubdag)
     # Write sections
     objsecwr = WrSections(grprobj, ver_list)
     if not os.path.exists(kws['ifile']):
         objsecwr.wr_txt_section_hdrgos(kws['ifile'])
     objsecwr.wr_txt_section_hdrgos(kws['ofile'])
     objsecpy = WrPySections(grprobj, ver_list)
     if 'py' in kws:
         objsecpy.wr_py_sections(kws['py'], sections, doc=godag.version)
     # Write user GO IDs in sections
     sortobj = Sorter(grprobj)
     objgowr = WrXlsxSortedGos("init", sortobj, ver_list)
     objgowr.wr_txt_gos(kws['txt'], sortby=objsecpy.fncsortnt)
     #objwr.wr_txt_section_hdrgos(kws['ofile'], sortby=objwr.fncsortnt)
     self._prt_cnt_usrgos(usrgos, sys.stdout)
예제 #11
0
 def __init__(self, args):
     self.args = args
     self.sections = read_sections(
         self.args.sections) if self.args.sections else None
     godag_optional_attrs = self._get_optional_attrs()
     self.godag = GODag(obo_file=self.args.obo,
                        optional_attrs=godag_optional_attrs)
     ## print('ARGS GoeaCliFnc ', self.args)
     # GET: Gene2GoReader, GafReader, GpadReader, or IdToGosReader
     self.objanno = self._get_objanno(self.args.filenames[2])
     _study, _pop = self.rd_files(*self.args.filenames[:2])
     if not self.args.compare:
         # Compare population and study gene product sets
         self.chk_genes(_study, _pop, self.objanno.associations)
     self.methods = self.args.method.split(",")
     self.itemid2name = self._init_itemid2name()
     # Get GOEnrichmentStudyNS
     self.objgoeans = self._init_objgoeans(_pop)
     # Run GOEA
     self.results_all = self.objgoeans.run_study(_study)
     # Prepare for grouping, if user-specified. Create GroupItems
     self.prepgrp = GroupItems(
         self, self.godag.version) if self.sections else None
예제 #12
0
def _read_sections(fin):
    """Get sections variable from file."""
    sec = os.path.join(REPO, fin)
    assert read_sections(sec), "EMPTY SECTIONS FILE({})".format(sec)
    return sec
예제 #13
0
 def _read_sections(ifile):
     """Read sections_in.txt file, if it exists."""
     if os.path.exists(ifile):
         return read_sections(ifile, exclude_ungrouped=True, prt=None)