Beispiel #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']]
Beispiel #2
0
 def _add_gochildleaf(self, ret):
     """Add leaf-level GO children to GO list colored uniquely."""
     leaf_gos = get_leaf_children(ret['GOs'], self.go2obj)
     if leaf_gos:
         ret['GOs'].update(leaf_gos)
         leaf_go_color = Go2Color.key2col['go_leafchild']
         go2color = ret['go2color']
         for goid in leaf_gos:
             if goid not in go2color:
                 go2color[goid] = leaf_go_color
Beispiel #3
0
 def _init_go_sources(self, go_sources_arg, go2obj_arg):
     """Return GO sources which are present in GODag."""
     gos_user = set(go_sources_arg)
     if 'children' in self.kws and self.kws['children']:
         gos_user |= get_leaf_children(gos_user, go2obj_arg)
     gos_godag = set(go2obj_arg)
     gos_source = gos_user.intersection(gos_godag)
     gos_missing = gos_user.difference(gos_godag)
     if not gos_missing:
         return gos_source
     sys.stdout.write("{N} GO IDs NOT FOUND IN GO DAG: {GOs}\n".format(
         N=len(gos_missing), GOs=" ".join([str(e) for e in gos_missing])))
     return gos_source
Beispiel #4
0
 def get_go_color(self, **kws):
     """Return source GO IDs ."""
     ret = {'GOs':set(), 'go2color':{}}
     if 'GO' in kws:
         self._goargs(ret, kws['GO'])
     if 'go_file' in kws:
         self._rdtxt_gos(ret, kws['go_file'])
     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)
         else:
             raise RuntimeError("GO IDs NEEDED")
     go2obj = {go:self.go2obj[go] for go in ret['GOs']}
     ret['GOs'] = set(get_go2obj_unique(go2obj))
     return [ret['GOs'], ret['go2color']]