Print grouped and sorted GO IDs.
486484
def prt_txt_desc2nts(self, prt, desc2nts, prtfmt):
        """"""
        # 1-D: data to print is a flat list of namedtuples
        if 'flat' in desc2nts:
            nts = desc2nts.get('flat')
            # sys.stdout.write("FLAT NTS: {FLDS}\n".format(FLDS=" ".join(next(iter(nts))._fields)))
            prt_txt(prt, nts, prtfmt)
        # 2-D: data to print is a list of [(section, nts), ...
        else:
            for section, nts in desc2nts['sections']:
                prt.write("\nSECTION: {SEC}\n".format(SEC=section))
                prt_txt(prt, nts, prtfmt)
            grprobj = self.sortobj.grprobj
            dat = SummarySec2dHdrGos().summarize_sec2hdrnts(desc2nts['sections'])
            ugos_y = dat['G'].intersection(grprobj.usrgos)
            ugos_n = dat['U'].intersection(grprobj.usrgos)
            return {'GO_DESC':'usr', 'SECs':len(dat['S']), 'GOs':len(ugos_y),
                    'UNGRP':len(ugos_n), 'undesc':'ungrpd'}
1041988
def _get_go2nt(self, goids):
        """"""
        go2nt_all = self.grprobj.go2nt
        return {go:go2nt_all[go] for go in goids}
771908
def print_desc(desc, verbose=False):
    '''
    
    '''
    if desc['class'] in ['project', 'workspace', 'container']:
        print_project_desc(desc, verbose=verbose)
    elif desc['class'] == 'app':
        print_app_desc(desc, verbose=verbose)
    elif desc['class'] == 'globalworkflow':
        print_globalworkflow_desc(desc, verbose=verbose)
    elif desc['class'] in ['job', 'analysis']:
        print_execution_desc(desc)
    elif desc['class'] == 'user':
        print_user_desc(desc)
    elif desc['class'] in ['org', 'team']:
        print_generic_desc(desc)
    else:
        print_data_obj_desc(desc, verbose=verbose)
891444
def _adj_item_marks(self):
        """"""
        if 'item_marks' in self.kws:
            # Process GO IDs specified in item_marks
            goids = self._get_goids(self.kws['item_marks'])
            # item_marks can take a list of GO IDs on cmdline or in a file.
            #     --item_marks=GO:0043473,GO:0009987
            #     --item_marks=item_marks.txt
            if goids:
                self.kws['item_marks'] = {go:'>' for go in goids}
            else:
                raise Exception("NO GO IDs FOUND IN item_marks")
1050372
def _print_map_dict(self, argkey, filename, append):
        """"""
        result = []
        skeys = list(sorted(self.curargs[argkey].keys()))
        for key in skeys:
            result.append("'{}' => {}".format(key, self.curargs[argkey][key]))
        self._redirect_output('\n'.join(result), filename, append, msg.info)
232404
def iddtxt2groups(txt):
    """"""
    try:
        txt = txt.decode('ISO-8859-2')
    except AttributeError as e:
        pass # for python 3
    txt = nocomment(txt, '!')
    txt = txt.replace("\\group", "!-group") # retains group in next line
    txt = nocomment(txt, '\\') # remove all other idd info
    lines = txt.splitlines()
    lines = [line.strip() for line in lines] # cleanup
    lines = [line for line in lines if line != ''] # cleanup
    txt = '\n'.join(lines)
    gsplits = txt.split('!') # split into groups, since we have !-group
    gsplits = [gsplit.splitlines() for gsplit in gsplits] # split group

    gsplits[0].insert(0, None)
        # Put None for the first group that does nothave a group name
    gdict = {}
    for gsplit in gsplits:
        gdict.update({gsplit[0]:gsplit[1:]})
        # makes dict {groupname:[k1, k2], groupname2:[k3, k4]}

    gdict = {k:'\n'.join(v) for k, v in gdict.items()}# joins lines back
    gdict = {k:v.split(';') for k, v in gdict.items()} # splits into idfobjects
    gdict = {k:[i.strip() for i in v] for k, v in gdict.items()} # cleanup
    gdict = {k:[i.splitlines() for i in v] for k, v in gdict.items()}
        # splits idfobjects into lines
    gdict = {k:[i for i in v if len(i) > 0] for k, v in gdict.items()}
        # cleanup - removes blank lines
    gdict = {k:[i[0] for i in v] for k, v in gdict.items()} # use first line
    gdict = {k:[i.split(',')[0] for i in v] for k, v in gdict.items()}
        # remove ','
    nvalue = gdict.pop(None) # remove group with no name
    gdict = {k[len('-group '):]:v for k, v in gdict.items()} # get group name
    gdict.update({None:nvalue}) # put back group with no name
    return gdict
91444
def pprint(self):
        """"""

        items = sorted(self.items())
        return u"\n".join(u"%s=%s" % (k, v.pprint()) for k, v in items)
1340361
def _print_counts(self):
        
        print "#  ",
        for i in range(self.width):
            print "  %4d   "%i,
        print
        for L in ['A', 'C', 'T', 'G']:
            print "#%s "%L,
            for i in range(self.width):
                print  "%8.3f "%self.counts[i][L],
            print
26922
def _ids(self):
        """"""
        for pk in self._pks:
            yield getattr(self, pk)

        for pk in self._pks:

            try:
                yield str(getattr(self, pk))
            except ValueError:
                pass
371726
def print_cliques(cliques, next_cliques, node_id_map):
    """"""
    n_cliques = len(cliques)
    format_str = '{:<' + str(n_cliques * 2) + '}  {} {}'
    branches = ['|'] * len(cliques)
    for i, clique in enumerate(cliques):
        block_id, nodes = clique
        print(format_str.format(
            ' '.join(branches[:i] + ['*'] + branches[i + 1:]),
            block_id[:8], format_siblings(nodes, node_id_map)))
        if block_id not in next_cliques:
            branches[i] = ' '
42092
def make_summary_funcs(rows, ids):
    """"""
    return {
        'len': len,
        'list': lambda *x: filter(None, list(x)),
        'max': max,
        'min': min,
        'rows': partial(summary_rows, rows, ids),
        'sum': sum,
        'trace': print_trace
    }
236726
def read_goids(fin_txt, get_goids_only=False, exclude_ungrouped=False, prt=sys.stdout):
    """"""
    return ReadGoids().read_txt(fin_txt, get_goids_only, exclude_ungrouped, prt)
277132
def plot_grouped_gos(self, fout_img=None, exclude_hdrs=None, **kws_usr):
        """"""
        # kws_plt -> go2color go2bordercolor
        kws_plt, kws_dag = self._get_kws_plt(self.grprobj.usrgos, **kws_usr)
        pltgosusr = self.grprobj.usrgos
        if exclude_hdrs is not None:
            pltgosusr = pltgosusr.difference(self.grprobj.get_usrgos_g_hdrgos(exclude_hdrs))
        if fout_img is None:
            fout_img = "{GRP_NAME}.png".format(GRP_NAME=self.grprobj.grpname)
        # Split one plot into potentially three (BP, MF, CC) if png filename contains '{NS}'
        if '{NS}' in fout_img:
            go2nt = self.grprobj.gosubdag.get_go2nt(pltgosusr)
            for namespace in ['BP', 'MF', 'CC']:
                pltgos_ns = [go for go in pltgosusr if go2nt[go].NS == namespace]
                if pltgos_ns:
                    png = fout_img.format(NS=namespace)
                    self._plot_grouped_gos(png, pltgos_ns, kws_plt, kws_dag)
        # Plot all user GO IDs into a single plot, regardless of their namespace
        else:
            self._plot_grouped_gos(fout_img, pltgosusr, kws_plt, kws_dag)
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))
1283182
def get_go_color(self, **kws):
        """"""
        ret = {'GOs':set(), 'go2color':{}}
        if 'GO' in kws:
            self._goargs(ret, kws['GO'])
        if 'go_file' in kws:
            self._rdtxt_gos(ret, kws['go_file'])
        if 'draw-children' in kws:
            ret['GOs'].update(get_leaf_children(ret['GOs'], self.go2obj))
        # If there have been no GO IDs explicitly specified by the user
        if not ret['GOs']:
            # If the GO-DAG is sufficiently small, print all GO IDs
            if len(self.go2obj) < self.max_gos:
                main_gos = set(o.id for go, o in self.go2obj.items() if go != o.id)
                go_leafs = set(go for go, o in self.go2obj.items() if not o.children)
                ret['GOs'] = go_leafs.difference(main_gos)
            else:
                raise RuntimeError("GO IDs NEEDED")
        go2obj = {go:self.go2obj[go] for go in ret['GOs']}
        ret['GOs'] = set(get_go2obj_unique(go2obj))
        return [ret['GOs'], ret['go2color']]
1343691
def print_sorted_counter(counter, tab=1):
    """"""
    for key, count in sorted(counter.items(), key=itemgetter(1), reverse=True):
        print "{0}{1} - {2}".format('\t'*tab, key, count)
1001863
def _get_kwsdag(self, goids, go2obj, **kws_all):
        """"""
        kws_dag = {}
        # Term Counts for GO Term information score
        tcntobj = self._get_tcntobj(goids, go2obj, **kws_all)  # TermCounts or None
        if tcntobj is not None:
            kws_dag['tcntobj'] = tcntobj
        # GO letters specified by the user
        if 'go_aliases' in kws_all:
            fin_go_aliases = kws_all['go_aliases']
            if os.path.exists(fin_go_aliases):
                go2letter = read_d1_letter(fin_go_aliases)
                if go2letter:
                    kws_dag['go2letter'] = go2letter
        return kws_dag