Write GO DAG version and key indicating presence of GO ID in a list.
189558
def _wr_ver_n_key(self, fout_txt, verbose):
        """"""
        with open(fout_txt, 'w') as prt:
            self._prt_ver_n_key(prt, verbose)
            print('               WROTE: {TXT}'.format(TXT=fout_txt))
1081613
def cli(self, prt=sys.stdout):
        """"""
        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))
1328137
def _init_go2nt_aug(self, go2nt):
        """"""
        go2obj = self.gosubdag.go2obj
        # Get alt GO IDs
        go2nt_aug = {}
        # NOW
        for goid_usr, nt_usr in go2nt.items():
            goobj = go2obj[goid_usr]
            if goobj.alt_ids:
                alts = set(goobj.alt_ids)
                alts.add(goobj.id)
                for goid_alt in alts:
                    if goid_alt not in go2nt:
                        go2nt_aug[goid_alt] = nt_usr
        # WAS
        # Add alt GO IDs to go2nt
        for goid, gont in go2nt_aug.items():
            go2nt[goid] = gont
        return go2nt
1002646
def write_concrete_dag(self):
    
    if not self.__dag_file_path:
      raise CondorDAGError, "No path for DAG file"
    try:
      dagfile = open( self.__dag_file_path, 'w' )
    except:
      raise CondorDAGError, "Cannot open file " + self.__dag_file_path
    for node in self.__nodes:
      node.write_job(dagfile)
      node.write_vars(dagfile)
      if node.get_category():
        node.write_category(dagfile)
      if node.get_priority():
        node.write_priority(dagfile)
      node.write_pre_script(dagfile)
      node.write_post_script(dagfile)
      node.write_input_files(dagfile)
      node.write_output_files(dagfile)
    for node in self.__nodes:
      node.write_parents(dagfile)
    for category in self.__maxjobs_categories:
      self.write_maxjobs(dagfile, category)
    dagfile.close()
794507
def update_association(self, association):
        """"""
        bad_goids = set()
        # Loop through all sets of GO IDs for all genes
        for goids in association.values():
            parents = set()
            # Iterate thru each GO ID in the current gene's association
            for goid in goids:
                try:
                    parents.update(self[goid].get_all_parents())
                except:
                    bad_goids.add(goid.strip())
            # Add the GO parents of all GO IDs in the current gene's association
            goids.update(parents)
        if bad_goids:
            sys.stdout.write("{N} GO IDs in assc. are not found in the GO-DAG: {GOs}\n".format(
                N=len(bad_goids), GOs=" ".join(bad_goids)))
883680
def _plt_gogrouped(self, goids, go2color_usr, **kws):
        """"""
        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
1136129
def _chk_hdrgoids(hdrgos):
        """"""
        goid = next(iter(hdrgos))
        if isinstance(goid, str) and goid[:3] == "GO:":
            return
        assert False, "HDRGOS DO NOT CONTAIN GO IDs: {E}".format(E=goid)
1279474
def _check_args(*argl, **argd):
    
    args = {"_": []}
    for item in argl:
        args["_"].append(_tracker_str(item))
           
    for key, item in argd.items():
        args[key] = _tracker_str(item)
        
    return args
1032670
def get_go2obj(self, goids):
        """"""
        go2obj = self.go2obj
        return {go:go2obj[go] for go in goids}
1175668
def _get_go2nthdridx(self, gos_all):
        """"""
        go2nthdridx = {}
        # NtHdrIdx Namedtuple fields:
        #   * format_txt: Used to determine the format when writing Excel cells
        #   * hdr_idx: Value printed in an Excel cell
        # shortcuts
        obj = GrouperInit.NtMaker(self)
        # Create go2nthdridx
        for goid in gos_all:
            go2nthdridx[goid] = obj.get_nt(goid)
        return go2nthdridx
1033011
def get_gos_d0d1(self):
        """"""
        return set([o.id for d in [0, 1] for o in self.gosubdag.rcntobj.depth2goobjs.get(d)])
692946
def get_goargs(self, go_args, prt):
        """"""
        goids = set()
        go2color = {}
        # Match on "GO ID" or "GO ID and color"
        re_gocolor = re.compile(r'(GO:\d{7})((?:#[0-9a-fA-F]{6})?)')
        for go_arg in go_args:
            mtch = re_gocolor.match(go_arg)
            if mtch:
                goid, color = mtch.groups()
                goids.add(goid)
                if color:
                    go2color[goid] = color
            elif go_arg in self.godagconsts.NS2GO:
                goids.add(self.godagconsts.NS2GO[go_arg])
            elif prt:
                prt.write("WARNING: UNRECOGNIZED ARG({})\n".format(go_arg))
        return goids
420485
def _init_go2obj(self, **kws):
        """"""
        if 'goids' in kws and 'obodag' in kws:
            self.godag.go_sources = kws['goids']
            obo = kws['obodag']
            for goid in self.godag.go_sources:
                self.godag.go2obj[goid] = obo[goid]
        elif 'goid2goobj' in kws:
            goid2goobj = kws['goid2goobj']
            self.godag.go_sources = goid2goobj.keys()
            for goid, goobj in goid2goobj.items():
                self.godag.go2obj[goid] = goobj
        elif 'goea_results' in kws:
            goea_results = kws['goea_results']
            self.godag.go_sources = [rec.GO for rec in goea_results]
            self.godag.go2obj = {rec.GO:rec.goterm for rec in goea_results}
993855
def _rdtxt_gos(self, ret, go_file):
        """"""
        if not os.path.exists(go_file):
            raise RuntimeError("CAN NOT READ: {FILE}\n".format(FILE=go_file))
        goids = set()
        go2color = {}
        with open(go_file) as ifstrm:
            for line in ifstrm:
                goids_found = self.re_goids.findall(line)
                if goids_found:
                    goids.update(goids_found)
                    colors = self.re_color.findall(line)
                    if colors:
                        if len(goids_found) == len(colors):
                            for goid, color in zip(goids_found, colors):
                                go2color[goid] = color
                        else:
                            print("IGNORING: {L}".format(L=line),)
        self._update_ret(ret, goids, go2color)
812378
def get_paths_goobjs(go_objs, go_top=None, go2obj=None):
    """"""
    go_paths = []  # Collect all paths for go_objs
    go_all = set() # Collect all GO terms in all paths
    pathobj = GoPaths()
    for go_obj in go_objs:
        #print "?FIND PATHS FOR {}?".format(go_obj.id)
        if go_obj.id not in go_all: # GO not yet seen in paths already found
            #print "!FIND PATHS FOR {}!".format(go_obj.id)
            paths_curr = pathobj.get_paths_from_to(go_obj, go_top, True)
            if paths_curr:
                for path_goobjs in paths_curr:
                    for path_goobj in path_goobjs:
                        goid = path_goobj.id
                        if goid not in go_all:
                            go_all.add(goid)
                            go2obj[goid] = path_goobj
                # go_all.update(GO.id for path in paths_curr for GO in path)
                go_paths.extend(path for path in paths_curr)
    return go_paths, go_all
622953
def _init_go_sources(self, go_sources_arg, go2obj_arg):
        """"""
        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
47260
def _init_go2ntpresent(go_ntsets, go_all, gosubdag):
        """"""
        go2ntpresent = {}
        ntobj = namedtuple('NtPresent', " ".join(nt.hdr for nt in go_ntsets))
        # Get present marks for GO sources
        for goid_all in go_all:
            present_true = [goid_all in nt.go_set for nt in go_ntsets]
            present_str = ['X' if tf else '.' for tf in present_true]
            go2ntpresent[goid_all] = ntobj._make(present_str)
        # Get present marks for all other GO ancestors
        goids_ancestors = set(gosubdag.go2obj).difference(go2ntpresent)
        assert not goids_ancestors.intersection(go_all)
        strmark = ['.' for _ in range(len(go_ntsets))]
        for goid in goids_ancestors:
            go2ntpresent[goid] = ntobj._make(strmark)
        return go2ntpresent