Return a flat list of sections (wo/section names) with GO terms grouped and sorted.
485550
def get_sorted_nts_omit_section(self, hdrgo_prt, hdrgo_sort):
        """"""
        nts_flat = []
        # print("SSSS SorterNts:get_sorted_nts_omit_section(hdrgo_prt={}, hdrgo_sort={})".format(
        #     hdrgo_prt, hdrgo_sort))
        hdrgos_seen = set()
        hdrgos_actual = self.sortgos.grprobj.get_hdrgos()
        for _, section_hdrgos_all in self.sections:
            #section_hdrgos_act = set(section_hdrgos_all).intersection(hdrgos_actual)
            section_hdrgos_act = [h for h in section_hdrgos_all if h in hdrgos_actual]
            hdrgos_seen |= set(section_hdrgos_act)
            self.sortgos.get_sorted_hdrgo2usrgos(
                section_hdrgos_act, nts_flat, hdrgo_prt, hdrgo_sort)
        remaining_hdrgos = set(self.sortgos.grprobj.get_hdrgos()).difference(hdrgos_seen)
        self.sortgos.get_sorted_hdrgo2usrgos(remaining_hdrgos, nts_flat, hdrgo_prt, hdrgo_sort)
        return nts_flat
782296
def dflt_sortby_ntgoea(ntgoea):
        """"""
        return [ntgoea.enrichment,
                ntgoea.namespace,
                ntgoea.p_uncorrected,
                ntgoea.depth,
                ntgoea.GO]
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}
688076
def sections(self):
    """"""
    if not self._is_parsed:
      self._Parse()
      self._is_parsed = True

    return self._sections
1183784
def get_list(self, section, option):
        
        if self.has_option(section, option):
            return self.get(section, option).replace(' ', '').split(',')
        else:
            raise KeyError('{} with {} does not exist.'.format(section,
                                                               option))
393649
def get_fields(desc2nts):
        """"""
        if 'flat' in desc2nts:
            nts_flat = desc2nts.get('flat')
            if nts_flat:
                return nts_flat[0]._fields
        if 'sections' in desc2nts:
            nts_sections = desc2nts.get('sections')
            if nts_sections:
                return nts_sections[0][1][0]._fields
740705
def read_sections(self, sections_file, get_goids_only, exclude_ungrouped):
        """"""
        ext = os.path.splitext(sections_file)[1]
        file_contents = None
        if ext == '.py':
            file_contents = self.read_py(sections_file, get_goids_only, exclude_ungrouped)
        else:
            file_contents = self.read_txt(sections_file, get_goids_only, exclude_ungrouped)
        if file_contents:
            return file_contents.get('sections', None)
1032483
def wr_py_sections(self, fout_py, sections, doc=None):
        """"""
        if sections is None:
            sections = self.grprobj.get_sections_2d()
        sec2d_nt = self.get_sections_2dnt(sections)  # lists of GO Grouper namedtuples
        with open(fout_py, 'w') as prt:
            self._prt_py_sections(sec2d_nt, prt, doc)
            dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sections)
            sys.stdout.write(self.grprobj.fmtsum.format(
                GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']),
                UNGRP=len(dat['U']), undesc="unused",
                ACTION="WROTE:", FILE=fout_py))
727212
def _get_grprobj(self, goids, sections):
        """"""
        grprdflt = GrouperDflts(self.gosubdag, "goslim_generic.obo")
        hdrobj = HdrgosSections(self.gosubdag, grprdflt.hdrgos_dflt, sections)
        return Grouper("sections", goids, hdrobj, self.gosubdag)
660643
def formula_sections(self):
        
        if self.dtree is not None:
            return self.dtree.order
        else:
            return [s for s in self.manifest.sections() if s != "config"]
432830
def rows(self):
        """"""
        for t in self.terms:

            for row in t.rows:
                term, value = row  # Value can either be a string, or a dict

                if isinstance(value, dict):  # Dict is for properties, which might be arg-children
                    term, args, remain = self._args(term, value)
                    yield term, args

                    # 'remain' is all of the children that didn't have an arg-child column -- the
                    # section didn't have a column heder for that ther.
                    for k, v in remain.items():
                        yield term.split('.')[-1] + '.' + k, v
                else:
                    yield row
1003635
def prt_outfiles_flat(self, goea_results, outfiles):
        """"""
        kws = {'indent':self.args.indent, 'itemid2name':self.itemid2name}
        for outfile in outfiles:
            if outfile.endswith(".xlsx"):
                self.objgoea.wr_xlsx(outfile, goea_results, **kws)
            #elif outfile.endswith(".txt"):  # TBD
            #    pass
            else:
                self.objgoea.wr_tsv(outfile, goea_results, **kws)
1341654
def generate_sections(self):
        """"""
        authors = Dataset.objects.values(
            'uploaded_by'
        ).annotate(
            upload_count=Count(
                'uploaded_by'
            )
        ).order_by('-upload_count')

        email_name_map = grab_names_from_emails(
            [row['uploaded_by'] for row in authors]
        )

        for author in authors:
            for emailKey in email_name_map:
                if author['uploaded_by'] == emailKey:
                    author['name'] = email_name_map[emailKey]

        return [
            {
                'slug': author['uploaded_by'],
                'name': author['name'],
                'count': author['upload_count']

            }
            for author in authors
        ]
500648
def wr_txt_gos(self, fout_txt, **kws_usr):
        """"""
        # Keyword arguments: control content: hdrgo_prt section_prt top_n use_sections
        desc2nts = self.sortobj.get_desc2nts(**kws_usr)
        # Keyword arguments: control txt format
        self.wr_txt_nts(fout_txt, desc2nts)
        return desc2nts
226850
def get_sortobj(self, goea_results, **kws):
        """"""
        nts_goea = MgrNtGOEAs(goea_results).get_goea_nts_prt(**kws)
        goids = set(nt.GO for nt in nts_goea)
        go2nt = {nt.GO:nt for nt in nts_goea}
        grprobj = Grouper("GOEA", goids, self.hdrobj, self.grprdflt.gosubdag, go2nt=go2nt)
        grprobj.prt_summary(sys.stdout)
        # hdrgo_prt", "section_prt", "top_n", "use_sections"
        sortobj = Sorter(grprobj, section_sortby=lambda nt: getattr(nt, self.pval_fld))
        return sortobj
701089
def _fmto_groups(self):
        """"""
        ret = defaultdict(set)
        for key in self:
            ret[getattr(self, key).group].add(getattr(self, key))
        return dict(ret)
40045
def term_counts(self):

        

        counts = OrderedDict()
        for term in self.terms:
            counts[term] = len(self.terms[term])

        return utils.sort_dict(counts)