예제 #1
0
 def get_go_color(self, **kws):
     """Return source GO IDs and GO color, if provided."""
     ret = {'GOs': set(), 'go2color': {}}
     if 'go_color_file' in kws:
         _, go2color = ClassGetGOs.rdtxt_gos_color(kws['go_color_file'])
         self._update_ret(ret, None, go2color)
     if 'GO' in kws:
         # goids, go2color = self._goargs(ret, kws['GO'])
         goids, go2color = ClassGetGOs.get_goargs(kws['GO'], prt=sys.stdout)
         self._update_ret(ret, goids, go2color)
     if 'go_file' in kws:
         goids, go2color = ClassGetGOs.rdtxt_gos_color(kws['go_file'])
         self._update_ret(ret, goids, go2color)
     if 'draw-children' in kws:
         ret['GOs'].update(get_leaf_children(ret['GOs'], self.go2obj))
     # If there have been no GO IDs explicitly specified by the user
     if not ret['GOs']:
         # If the GO-DAG is sufficiently small, print all GO IDs
         if len(self.go2obj) < self.max_gos:
             main_gos = set(o.id for go, o in self.go2obj.items()
                            if go != o.id)
             go_leafs = set(go for go, o in self.go2obj.items()
                            if not o.children)
             ret['GOs'] = go_leafs.difference(main_gos)
     go2obj = {go: self.go2obj[go] for go in ret['GOs']}
     ret['GOs'] = set(get_go2obj_unique(go2obj))
     return [ret['GOs'], ret['go2color']]
예제 #2
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
예제 #3
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
예제 #4
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
예제 #5
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)
예제 #6
0
 def _get_remove_goids(self):
     """Get arguments to get a list of broad GO IDs to remove"""
     # None: (Default) Remove a small number (~14) of broad GO IDs from the association
     if self.args.remove_goids is None:
         return self.args.remove_goids
     # True: Remove a slightly larger number of broad GO IDs (~100)
     if self.args.remove_goids.lower() == 'true':
         return True
     # False: Do not remove any broad GO IDs
     if self.args.remove_goids.lower() == 'false':
         return False
     if os.path.exists(self.args.remove_goids):
         GetGOs.rdtxt_gos(self.args.remove_goids, sys.stdout)
     if isinstance(self.args.remove_goids,
                   str) and 'GO' in self.args.remove_goids:
         return self.args.remove_goids.split(',')
     return None
예제 #7
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))
예제 #8
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)
예제 #9
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
예제 #10
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