Get sections and GO grouping hdrgos from file, if sections exist.
484421
def read_sections(sections_file, exclude_ungrouped=False, prt=sys.stdout):
    """"""
    if sections_file is None:
        return None
    assert isinstance(sections_file, str), "BAD SECTIONS FILENAME({S})".format(
        S=sections_file)
    if os.path.exists(sections_file):
        return ReadGoids().read_sections(sections_file, False, exclude_ungrouped)
    # Is 'sections_file' a module string?
    if '/' not in sections_file and r'\\' not in sections_file and \
            pkgutil.find_loader(sections_file) is not None:
        mod = importlib.import_module(sections_file)
        var = getattr(mod, 'SECTIONS', None)
        if var is not None:
            dat = SummarySec2dHdrGos().summarize_sec2hdrgos(var)
            print(Grouper.fmtsum.format(
                GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']),
                UNGRP="N/A", undesc="unused", ACTION="IMPORTED: ", FILE=sections_file))
            return var
        raise RuntimeError("NO 'SECTIONS' VARIABLE FOUND IN MODULE({M})".format(M=sections_file))
    if prt:
        prt.write("CANNOT READ: {SEC}\n".format(SEC=sections_file))
956964
def get_flat_groups(self, field=None):
        '''
        
        '''
        field = field if field else self._determine_group_field(field)
        temp_groups = self.data['grouped'][field]['groups']
        return [y for x in temp_groups for y in x['doclist']['docs']]
911601
def _prt_read_msg(self, prt, fin_txt, exclude_ungrouped):
        """"""
        if self.sections_seen or exclude_ungrouped:
            # dat = Grouper.get_summary_data(self.section2goids.items(), HdrgosSections.secdflt)
            dat = SummarySec2dHdrGos().summarize_sec2hdrgos(self.section2goids.items())
            sys.stdout.write(Grouper.fmtsum.format(
                GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']),
                UNGRP="N/A", undesc="unused", ACTION="READ: ", FILE=fin_txt))
        elif self.goids_fin:
            prt.write("  {G} GO IDs READ: {FIN}\n".format(G=len(self.goids_fin), FIN=fin_txt))
588594
def wr_txt_section_hdrgos(self, fout_txt, sortby=None, prt_section=True):
        """"""
        sec2d_go = self.grprobj.get_sections_2d()    # lists of GO IDs
        sec2d_nt = self.get_sections_2dnt(sec2d_go)  # lists of GO Grouper namedtuples
        if sortby is None:
            sortby = self.fncsortnt
        with open(fout_txt, 'w') as prt:
            self.prt_ver(prt)
            prt.write("# GROUP NAME: {NAME}\n".format(NAME=self.grprobj.grpname))
            for section_name, nthdrgos_actual in sec2d_nt:
                if prt_section:
                    prt.write("# SECTION: {SECTION}\n".format(SECTION=section_name))
                self.prt_ntgos(prt, nthdrgos_actual)
                if prt_section:
                    prt.write("\n")
            dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sec2d_go)
            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_txt))
        return sec2d_nt
589308
def _init_hdrgos(self, hdrgos_dflt, hdrgos_usr=None, add_dflt=True):
        """"""
        # Use default GO group header values
        if (hdrgos_usr is None or hdrgos_usr is False) and not self.sections:
            return set(hdrgos_dflt)
        # Get GO group headers provided by user
        hdrgos_init = set()
        if hdrgos_usr:
            chk_goids(hdrgos_usr, "User-provided GO group headers")
            hdrgos_init |= set(hdrgos_usr)
        if self.sections:
            self._chk_sections(self.sections)
            hdrgos_sec = set([hg for _, hdrgos in self.sections for hg in hdrgos])
            chk_goids(hdrgos_sec, "User-provided GO group headers in sections")
            hdrgos_init |= hdrgos_sec
        # Add default depth-01 GOs to headers, if desired
        if add_dflt:
            return set(hdrgos_init).union(hdrgos_dflt)
        # Return user-provided GO grouping headers
        return hdrgos_init
442472
def get_sections(self, section_name):
        
        sections = []
        for timer in self.timers():
            for sect in timer.sections:
                if sect.name == section_name:
                    sections.append(sect)
                    break
            else:
                sections.append(AbinitTimerSection.fake())

        return sections
1066922
def _parseSections(self, data):
        
        section_dict = {}
        lines = data.splitlines()
        idx = 0
        numlines = len(lines)
        section = None
        while idx < numlines:
            line = lines[idx]
            idx += 1
            mobj = re.match('^(\w[\w\s\(\)]+[\w\)])\s*:$', line)
            if mobj:
                section = mobj.group(1)
                section_dict[section] = []
            else:
                mobj = re.match('(\t|\s)\s*(\w.*)$', line)
                if mobj:
                    section_dict[section].append(mobj.group(2))
                else:
                    mobj = re.match('^(\w[\w\s\(\)]+[\w\)])\s*:\s*(\S.*)$', line)
                    if mobj:
                        section = None
                        if not section_dict.has_key(section):
                            section_dict[section] = []
                        section_dict[section].append(line)
                    else:
                        if not section_dict.has_key('PARSEERROR'):
                            section_dict['PARSEERROR'] = []
                        section_dict['PARSEERROR'].append(line)   
        return section_dict
1105227
def groups(self):
        """"""
        self._prep_pandas_groupby()

        def extract_group_labels(frame):
            return (frame[0], frame[1].index.values)

        return self._mergedRDD.map(extract_group_labels).collectAsMap()
607392
def section(self, section, skip=['type', 'order']):
        
        return [(key, val) for key, val in self.parser.items(section)
                if key not in skip]
38223
def list_sections(self):
        """"""
        if not os.path.exists(self._full_base):
            return []
        return [
            name for name in os.listdir(self._full_base)
            if os.path.isdir(os.path.join(self._full_base, name))
        ]
12479
def getdirs(self, section, option, raw=False, vars=None, fallback=[]):
        
        globs = self.getlist(section, option, fallback=[])
        return [f for g in globs for f in glob.glob(g) if os.path.isdir(f)]
687612
def get_sec2gos(sortobj):
        """"""
        sec_gos = []
        for section_name, nts in sortobj.get_desc2nts_fnc(hdrgo_prt=True)['sections']:
            sec_gos.append((section_name, set(nt.GO for nt in nts)))
        return cx.OrderedDict(sec_gos)
173800
def get_sections_flattened(section_nts):
        """"""
        nt_flds = list(section_nts[0][1][0]._fields)
        # Flatten section_nts 2-D list
        if 'section' in nt_flds:
            return [nt for _, nts in section_nts for nt in nts]
        # Flatten section_nts 2-D list, and add sections to each namedtuple
        nt_flds.append('section')
        nts_flat = []
        ntobj = cx.namedtuple("Nt", " ".join(nt_flds))
        for section_name, nts in section_nts:
            for nt_go in nts:
                vals = list(nt_go) + [section_name]
                nts_flat.append(ntobj._make(vals))
        return nts_flat
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
351548
def get_goids_sections(sections):
        """"""
        goids_all = set()
        for _, goids_sec in sections:
            goids_all |= set(goids_sec)
        return goids_all
1313155
def get_section_hdrgos_nts(self, sortby=None):
        """"""
        nts_all = []
        section_hdrgos_actual = self.get_sections_2d()
        flds_all = ['Section'] + self.gosubdag.prt_attr['flds']
        ntobj = cx.namedtuple("NtGoSec", " ".join(flds_all))
        flds_go = None
        if sortby is None:
            sortby = lambda nt: -1*nt.dcnt
        for section_name, hdrgos_actual in section_hdrgos_actual:
            nts_sec = []
            for hdrgo_nt in self.gosubdag.get_go2nt(hdrgos_actual).values():
                if flds_go is None:
                    flds_go = hdrgo_nt._fields
                key2val = {key:val for key, val in zip(flds_go, list(hdrgo_nt))}
                key2val['Section'] = section_name
                nts_sec.append(ntobj(**key2val))
            nts_all.extend(sorted(nts_sec, key=sortby))
        return nts_all
248141
def get_usrgos_g_hdrgos(self, hdrgos):
        """"""
        usrgos_all = set()
        if isinstance(hdrgos, str):
            hdrgos = [hdrgos]
        for hdrgo in hdrgos:
            usrgos_cur = self.hdrgo2usrgos.get(hdrgo, None)
            if usrgos_cur is not None:
                usrgos_all |= usrgos_cur
            if hdrgo in self.hdrgo_is_usrgo:
                usrgos_all.add(hdrgo)
        return usrgos_all