Return a sort function for sorting header GO IDs found in sections.
961478
def _init_fncsortnt(flds):
        """"""
        if 'tinfo' in flds:
            if 'D1' in flds:
                return lambda ntgo: [ntgo.NS, -1*ntgo.tinfo, ntgo.depth, ntgo.D1, ntgo.alt]
            else:
                return lambda ntgo: [ntgo.NS, -1*ntgo.tinfo, ntgo.depth, ntgo.alt]
        if 'dcnt' in flds:
            if 'D1' in flds:
                return lambda ntgo: [ntgo.NS, -1*ntgo.dcnt, ntgo.depth, ntgo.D1, ntgo.alt]
            else:
                return lambda ntgo: [ntgo.NS, -1*ntgo.dcnt, ntgo.depth, ntgo.alt]
        else:
            return lambda ntgo: [ntgo.NS, -1*ntgo.depth, ntgo.alt]
1170818
def sort_items(items):
    """"""

    sorted_items = {}
    for item in items:
        category = lookup(item, 'itemCategory', 'categoryCode')
        if sorted_items.get(category) is None:
            sorted_items[category] = []
        sorted_items[category].append(item)

    return sorted_items
62928
def prt_goids(self, goids=None, prtfmt=None, sortby=True, prt=sys.stdout):
        """"""
        if goids is None:
            goids = self.go_sources
        nts = self.get_nts(goids, sortby)
        if prtfmt is None:
            prtfmt = self.prt_attr['fmta']
        for ntgo in nts:
            key2val = ntgo._asdict()
            prt.write("{GO}\n".format(GO=prtfmt.format(**key2val)))
        return nts
1108084
def sorted(self):
        
        if self.start < self.end:
            return self.start, self.end
        else:
            return self.end, self.start
548601
def prt_gos_flat(self, prt):
        """"""
        prtfmt = self.datobj.kws['fmtgo']
        _go2nt = self.sortobj.grprobj.go2nt
        go2nt = {go:_go2nt[go] for go in self.go2nt}
        prt.write("\n{N} GO IDs:\n".format(N=len(go2nt)))
        _sortby = self._get_sortgo()
        for ntgo in sorted(go2nt.values(), key=_sortby):
            prt.write(prtfmt.format(**ntgo._asdict()))
528062
def ordered_dirs(self):
        
        return [item[0] for item in sorted(
            self.byte_contents.items(), key=lambda entry: entry[1].st_ino)]
772199
def get_headers_in_order(self):
        
        res = list()
        #Scan through self.headers_in_order and just bolt on the actual header info
        for bucket in sorted(self.headers_in_order):
            for idx, k in self.headers_in_order[bucket]:
                res.append( (idx, k, self.headers[idx][k]) )
        return res
188689
def _sortObjects(orderby='created', **kwargs):
    """"""
    o = []
    
    for m in kwargs.values():
        for l in iter(m):
            o.append(l)
    o = list(set(o))
    sortfunc = _sortByCreated if orderby == 'created' else _sortByModified
    if six.PY2:
        o.sort(sortfunc)
    else:
        o.sort(key=functools.cmp_to_key(sortfunc))

    return o
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)
660964
def get_go2sectiontxt(self):
        """"""
        go2txt = {}
        _get_secs = self.hdrobj.get_sections
        hdrgo2sectxt = {h:" ".join(_get_secs(h)) for h in self.get_hdrgos()}
        usrgo2hdrgo = self.get_usrgo2hdrgo()
        for goid, ntgo in self.go2nt.items():
            hdrgo = ntgo.GO if ntgo.is_hdrgo else usrgo2hdrgo[ntgo.GO]
            go2txt[goid] = hdrgo2sectxt[hdrgo]
        return go2txt
607392
def section(self, section, skip=['type', 'order']):
        
        return [(key, val) for key, val in self.parser.items(section)
                if key not in skip]
443034
def SortBy(*qs):
    """"""

    sort = []
    for q in qs:
        if q._path.endswith('.desc'):
            sort.append((q._path[:-5], DESCENDING))
        else:
            sort.append((q._path, ASCENDING))
    return sort
677059
def _get_goids(gostr):
        """"""
        if 'GO:' in gostr:
            return gostr.split(',')
        elif os.path.exists(gostr):
            return GetGOs().get_goids(None, gostr, sys.stdout)
915795
def _entries_sorted(self):
        """"""
        return sorted(self.entries.values(), key=lambda e: (e.path, e.stage))
855128
def get_section_hdrgos(self):
        """"""
        return set([h for _, hs in self.sections for h in hs]) if self.sections else set()
776761
def get_nts_sections(self, sections, sortby=None):
        """"""
        goids = self.get_goids_sections(sections)
        gosubdag = GoSubDag(goids, self.go2obj)
        return [(sec, gosubdag.get_nts(gos, sortby)) for sec, gos in sections]
59754
def sort(self, ids):
        
        def extract_int(string):
            """
            Extract an integer from the given string.

            :param string string: the identifier string
            :rtype: int
            """
            return int(re.sub(r"[^0-9]", "", string))

        tmp = list(ids)
        if self.algorithm == IDSortingAlgorithm.UNSORTED:
            self.log(u"Sorting using UNSORTED")
        elif self.algorithm == IDSortingAlgorithm.LEXICOGRAPHIC:
            self.log(u"Sorting using LEXICOGRAPHIC")
            tmp = sorted(ids)
        elif self.algorithm == IDSortingAlgorithm.NUMERIC:
            self.log(u"Sorting using NUMERIC")
            tmp = ids
            try:
                tmp = sorted(tmp, key=extract_int)
            except (ValueError, TypeError) as exc:
                self.log_exc(u"Not all id values contain a numeric part. Returning the id list unchanged.", exc, False, None)
        return tmp