Get high GO IDs that are actually used to group current set of GO IDs.
178132
def get_sections_2d_nts(self, sortby=None):
        """"""
        sections_2d_nts = []
        for section_name, hdrgos_actual in self.get_sections_2d():
            hdrgo_nts = self.gosubdag.get_nts(hdrgos_actual, sortby=sortby)
            sections_2d_nts.append((section_name, hdrgo_nts))
        return sections_2d_nts
913904
def get_goids(self, go_args, fin_goids, prt):
        """"""
        goids = set()
        if fin_goids is not None:
            goids.update(self.rdtxt_gos(fin_goids, prt))
        if go_args:
            goids.update(self.get_goargs(go_args, prt))
        return goids
109144
def get_go2obj(self, goids):
        """"""
        goids = goids.intersection(self.go2obj.keys())
        if len(goids) != len(goids):
            goids_missing = goids.difference(goids)
            print("  {N} MISSING GO IDs: {GOs}".format(N=len(goids_missing), GOs=goids_missing))
        return {go:self.go2obj[go] for go in goids}
284356
def chk_goids(goids, msg=None, raise_except=True):
    """"""
    for goid in goids:
        if not goid_is_valid(goid):
            if raise_except:
                raise RuntimeError("BAD GO({GO}): {MSG}".format(GO=goid, MSG=msg))
            else:
                return goid
746038
def get_unique_groups(input_list):
    """"""
    out_list = []
    for item in input_list:
        if item not in out_list:
            out_list.append(item)
    return out_list
282236
def get_goobjs_altgo2goobj(go2obj):
    """"""
    goobjs = set()
    altgo2goobj = {}
    for goid, goobj in go2obj.items():
        goobjs.add(goobj)
        if goid != goobj.id:
            altgo2goobj[goid] = goobj
    return goobjs, altgo2goobj
141965
def get_go2obj_unique(go2obj):
    """"""
    # Find the unique GO Terms that are represented for each GO in go2obj
    goid2gokeys = cx.defaultdict(set)
    for goid, goobj in go2obj.items():
        goid2gokeys[goobj.id].add(goid)
    go_unique = set()
    for goid, gos_seen in goid2gokeys.items():
        # Return main GO ID, if it is present in the go2obj keys
        if goid in gos_seen:
            go_unique.add(goid)
        # Otherwise return an alternate GO ID
        else:
            go_unique.add(next(iter(gos_seen)))
    return go_unique
453102
def get_go2txt(grprobj_cur, grp_go2color, grp_go2bordercolor):
        """"""
        goids_main = set(o.id for o in grprobj_cur.gosubdag.go2obj.values())
        hdrobj = grprobj_cur.hdrobj
        grprobj_all = Grouper("all",
                              grprobj_cur.usrgos.union(goids_main), hdrobj, grprobj_cur.gosubdag)
        # Adds section text to all GO terms in plot (misses middle GO terms)
        _secdflt = hdrobj.secdflt
        _hilight = set(grp_go2color.keys()).union(grp_go2bordercolor)
        ret_go2txt = {}
        # Keep sections text only if GO header, GO user, or not Misc.
        if hdrobj.sections:
            for goid, txt in grprobj_all.get_go2sectiontxt().items():
                if txt == 'broad':
                    continue
                if txt != _secdflt or goid in _hilight:
                    ret_go2txt[goid] = txt
        return ret_go2txt
314378
def rm_gos(self, rm_goids):
        """"""
        self.edges = self._rm_gos_edges(rm_goids, self.edges)
        self.edges_rel = self._rm_gos_edges_rel(rm_goids, self.edges_rel)
766346
def get_id2gos_all(taxid2asscs_a2b):
        """"""
        id2gos_all = {}
        for a2b in taxid2asscs_a2b.values():
            for geneid, gos in a2b['ID2GOs'].items():
                id2gos_all[geneid] = gos
        return id2gos_all
1252733
def internal_get_goids_or_sections(self):
        """"""
        if self.goids_fin:
            chk_goids(self.goids_fin, "read_goids")
            return {'goids' : self.goids_fin}
        else:
            # Convert dict into 2D list retaining original section order
            sections_2d = []
            for section_name in self.sections_seen:
                if section_name in self.section2goids:
                    goids = self.section2goids.get(section_name)
                    chk_goids(goids, "GO IDs IN SECTION({S})".format(S=section_name))
                    sections_2d.append((section_name, goids))
            return {'sections' : sections_2d}
179548
def get_usrgo2hdrgo(self):
        """"""
        usrgo2hdrgo = {}
        for hdrgo, usrgos in self.hdrgo2usrgos.items():
            for usrgo in usrgos:
                assert usrgo not in usrgo2hdrgo
                usrgo2hdrgo[usrgo] = hdrgo
        # Add usrgos which are also a hdrgo and the GO group contains no other GO IDs
        for goid in self.hdrgo_is_usrgo:
            usrgo2hdrgo[goid] = goid
        assert len(self.usrgos) <= len(usrgo2hdrgo), \
            "USRGOS({U}) != USRGO2HDRGO({H}): {GOs}".format(
                U=len(self.usrgos),
                H=len(usrgo2hdrgo),
                GOs=self.usrgos.symmetric_difference(set(usrgo2hdrgo.keys())))
        return usrgo2hdrgo
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
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
1143886
def get_go_ntsets(self, go_fins):
        """"""
        nts = []
        ntobj = namedtuple('NtGOFiles', 'hdr go_set, go_fin')
        go_sets = self._init_go_sets(go_fins)
        hdrs = [os.path.splitext(os.path.basename(f))[0] for f in go_fins]
        assert len(go_fins) == len(go_sets)
        assert len(go_fins) == len(hdrs)
        for hdr, go_set, go_fin in zip(hdrs, go_sets, go_fins):
            nts.append(ntobj(hdr=hdr, go_set=go_set, go_fin=go_fin))
        return nts
334757
def wr_txt_grouping_gos(self):
        """"""
        prt_goids = self.grprobj.gosubdag.prt_goids
        for hdrgo, usrgos in self.grprobj.hdrgo2usrgos.items():
            keygos = usrgos.union([hdrgo])
            fout_txt = "{BASE}.txt".format(BASE=self.grprobj.get_fout_base(hdrgo))
            with open(fout_txt, 'w') as prt:
                prt_goids(keygos, prt=prt)
                sys.stdout.write("  {N:5,} GO IDs WROTE: {TXT}\n".format(
                    N=len(keygos), TXT=fout_txt))
233149
def next_group_id(self) -> int:
        
        ids: typing.Set[int] = set()
        for group in chain(self._blue_coa.groups, self._red_coa.groups):  # type: ignore

            id_ = group.group_id
            if id_ in ids:
                raise IndexError(group.group_name)
            ids.add(id_)
        return max(ids) + 1