Beispiel #1
0
 def _get_goids(gostr):
     """Return GO IDs from a GO str (e.g., GO:0043473,GO:0009987) or a file."""
     if 'GO:' in gostr:
         return gostr.split(',')
     elif os.path.exists(gostr):
         return GetGOs().get_goids(None, gostr, sys.stdout)
     return None
Beispiel #2
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 = self._read_sections(kws['ifile'])
     # print("SECSECSEC", sections)
     hdrobj = HdrgosSections(self.gosubdag, grprdflt.hdrgos_dflt, sections)
     grprobj = Grouper("init", usrgos, hdrobj, self.gosubdag)
     # Write sections
     objsecwr = WrSectionsTxt(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 = WrSectionsPy(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)
Beispiel #3
0
 def cli(self, prt=sys.stdout):
     """Command-line interface to print specified GO Terms from the DAG source ."""
     kws = self.objdoc.get_docargs(prt=None)
     print("KWS", kws)
     goids = GetGOs().get_goids(kws.get('GO'), kws.get('GO_FILE'),
                                sys.stdout)
     if not goids and 'name' in kws:
         goids = self.objsub.get_goids(kws['obo'], kws['name'])
     self.objsub.prt_goterms(kws['obo'], goids, prt, b_prt=False)
     print("Printing {N:6} GO IDs: {GOs}".format(N=len(goids), GOs=goids))
Beispiel #4
0
 def _init_go_sets(self, go_fins):
     """Get lists of GO IDs."""
     go_sets = []
     assert go_fins, "EXPECTED FILES CONTAINING GO IDs"
     assert len(go_fins) >= 2, "EXPECTED 2+ GO LISTS. FOUND: {L}".format(
         L=' '.join(go_fins))
     obj = GetGOs(self.godag)
     for fin in go_fins:
         assert os.path.exists(fin), "GO FILE({F}) DOES NOT EXIST".format(F=fin)
         go_sets.append(obj.get_usrgos(fin, sys.stdout))
     return go_sets
Beispiel #5
0
 def __init__(self, args=None, prt=sys.stdout):
     self.kws = DocOptParse(__doc__, self.kws_dct_all,
                            self.kws_set_all).get_docargs(
                                args,
                                intvals=set(['max_indent', 'dash_len']))
     opt_attrs = OboOptionalAttrs.attributes.intersection(self.kws.keys())
     godag = get_godag(self.kws['dag'], prt, optional_attrs=opt_attrs)
     self.gosubdag = GoSubDag(godag.keys(),
                              godag,
                              relationships='relationship' in opt_attrs,
                              tcntobj=get_tcntobj(godag, **self.kws),
                              children=True,
                              prt=prt)
     self.goids = GetGOs().get_goids(self.kws.get('GO'), self.kws.get('i'),
                                     sys.stdout)
Beispiel #6
0
 def _init_goids(self):
     goids_ret = []
     if 'GO' in self.kws:
         for goid in self.kws['GO']:
             if goid[:3] == "GO:":
                 assert len(goid) == 10, "BAD GO ID({GO})".format(GO=goid)
                 goids_ret.append(goid)
             elif goid in NS2GO:
                 goids_ret.append(NS2GO[goid])
     if 'i' in self.kws:
         goids_fin = GetGOs().rdtxt_gos(self.kws['i'], sys.stdout)
         if goids_fin:
             goids_ret.extend(list(goids_fin))
     if goids_ret:
         return goids_ret
     # If GO DAG is small, print hierarchy for the entire DAG
     if len(self.gosubdag.go2nt) < 100:
         return set(self.gosubdag.go2nt.keys())
     return None
Beispiel #7
0
 def init_goids(goids_args, infile, go2nt):
     """Extract GO IDs in the report from arguments"""
     goids_ret = []
     if goids_args is not None:
         for goid in goids_args:
             if goid[:3] == "GO:":
                 assert len(goid) == 10, "BAD GO ID({GO})".format(GO=goid)
                 goids_ret.append(goid)
             elif goid in NS2GO:
                 goids_ret.append(NS2GO[goid])
     if infile is not None:
         goids_fin = GetGOs().rdtxt_gos(infile, sys.stdout)
         if goids_fin:
             goids_ret.extend(list(goids_fin))
     if goids_ret:
         return goids_ret
     # If GO DAG is small, print hierarchy for the entire DAG
     if len(go2nt) < 100:
         return set(go2nt.keys())
     return None