Write summary of level and depth counts for active GO Terms.
353819
def _prttex_summary_cnts(self, prt, cnts):
        """"""
        # Count level(shortest path to root) and depth(longest path to root)
        # values for all unique GO Terms.
        prt.write("\n\n% LaTeX Table for GO counts at each level and depth in the GO DAG\n")
        prt.write(r"\begin{table}[bt]" "\n")
        prt.write(r"\begin{tabular}{|r |r |r |r |r |r |r|}" "\n")

        title = self.title.replace('_', r'\_')
        prt.write(r"\hline" "\n")
        prt.write(r"\rowcolor{gray!10}" "\n")
        prt.write(" ".join([r"\multicolumn{7}{|l|}{", title, r"} \\", "\n"]))
        prt.write(r"\hline" "\n")
        prt.write(r"\rowcolor{gray!10}" "\n")
        prt.write(r"Depth &" "\n")
        prt.write(r"\multicolumn{3}{c|}{Depth} &" "\n")
        prt.write(r"\multicolumn{3}{c|}{Level} \\" "\n")
        prt.write(r"\cline{2-7}" "\n")
        prt.write(r"\rowcolor{gray!10}" "\n")
        prt.write(r"or Level & BP & MF & CC & BP & MF & CC \\" "\n")
        prt.write(r"\hline" "\n")

        max_val = max(max(dep for dep in cnts['depth']), max(lev for lev in cnts['level']))
        for i in range(max_val+1):
            vals = ['{:>5}'.format(cnts[desc][i][ns]) for desc in cnts for ns in self.nss]
            self.log.write('{:>02} & {} \\\\\n'.format(i, ' & '.join(vals)))
            if i%2 == 0:
                prt.write(r"\rowcolor{gray!7}" "\n")
        prt.write(r"\hline" "\n")
        prt.write(r"\end{tabular}" "\n")
        prt.write(r"\end{table}" "\n")
1226523
def prt_hier_rec(self, item_id, depth=1):
        """"""
        # Shortens hierarchy report by only printing the hierarchy
        # for the sub-set of user-specified GO terms which are connected.
        if self.include_only and item_id not in self.include_only:
            return

        obj = self.id2obj[item_id]
        # Optionally space the branches for readability
        if self.space_branches:
            if depth == 1 and obj.children:
                self.prt.write("\n")
        # Print marks if provided
        if self.item_marks:
            self.prt.write('{MARK} '.format(
                MARK=self.item_marks.get(item_id, self.mark_dflt)))

        no_repeat = self.concise_prt and item_id in self.items_printed
        # Print content
        dashes = self._str_dash(depth, no_repeat, obj)
        if self.do_prtfmt:
            self._prtfmt(item_id, dashes)
        else:
            self._prtstr(obj, dashes)
        self.items_printed.add(item_id)
        self.items_list.append(item_id)
        # Do not print hierarchy below this turn if it has already been printed
        if no_repeat:
            return
        depth += 1
        if self.max_indent is not None and depth > self.max_indent:
            return
        children = obj.children if self.sortby is None else sorted(obj.children, key=self.sortby)
        for child in children:
            self.prt_hier_rec(child.item_id, depth)
46025
def write_details(fw, details, bed):
    
    for a, b, depth in details:
        for i in xrange(a, b):
            gi = bed[i].accn
            print("\t".join((gi, str(depth))), file=fw)
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
1010094
def get_hdr(self, goid, goobj):
        """'"""
        hdr = []
        ntgo = self.gosubdag.go2nt.get(goid)
        prt_flds = self._get_prtflds()
        # Add letter to depth-01 GO Node.
        if 'D1' in prt_flds and goobj.depth == 1:
            hdr.append("{ABC} ".format(ABC=ntgo.D1))
        hdr.append(self.str_fmthdr(goid, goobj))
        if 'level' in prt_flds:
            hdr.append("L{level}".format(level=goobj.level))
        if 'depth' in prt_flds:
            hdr.append("D{depth}".format(depth=goobj.depth))
        if 'reldepth' in prt_flds:
            hdr.append("R{reldepth}".format(reldepth=goobj.reldepth))
        # Print count of parents for this GO term
        if 'c2ps' in self.kws:
            self._add_parent_cnt(hdr, goobj, self.kws['c2ps'])
        # Print count of children for this GO term
        childcnt_str = self._get_hdr_childcnt(goobj, ntgo)
        if childcnt_str:
            hdr.append(childcnt_str)
        # Print count of all descendants down to the leaf-level for this GO term
        if 'dcnt' in prt_flds:
            hdr.append("d{N}".format(N=ntgo.dcnt))
        if 'tinfo' in prt_flds:
            hdr.append("i{I:4.02f}".format(I=ntgo.tinfo))
        if 'REL' in prt_flds:
            hdr.append("{R}".format(R=ntgo.REL_short))
        return " ".join(hdr)
141820
def wr_tex(self, fout_tex="gos_depth01.tex"):
        """"""
        data_nts = self.get_d1nts()
        joinchr = " & "
        #pylint: disable=anomalous-backslash-in-string
        eol = " \\\\\n"
        with open(fout_tex, 'w') as prt:
            prt.write("\\begin{table}[!ht]\n")
            prt.write("\\begin{tabular}{|p{.5cm} | p{.5cm} | >{\\raggedleft}p{.9cm} ")
            prt.write("|p{.7cm} |p{1.8cm} |p{9cm}|}\n")
            prt.write("\multicolumn{6}{c}{} \\\\\n")
            prt.write("\hline\n")
            prt.write("\\rowcolor{gray!10}\n")
            prt.write("{HDRS}{EOL}".format(
                HDRS=joinchr.join(next(iter(data_nts))._fields), EOL=eol))
            prt.write("\hline\n")
            for idx, line in enumerate(get_lines(data_nts, joinchr=joinchr, eol=eol)):
                if idx%2 == 1:
                    prt.write("\\rowcolor{gray!7}\n")
                line.replace('_', '\\_')
                prt.write(line)
            prt.write("\hline\n")
            prt.write("\end{tabular}\n")
            caption = ("The descendant counts of GO terms at depth-01 are highly skewed. The "
                       "root term, \textit{biological\_process} has over twenty GO children at "
                       "depth-01 shown in the table sorted by their number of descendants "
                       "(dcnt) with \textit{cellular process} at the top having 18k+ "
                       "descendants and \textit{cell killing} near the bottom having only "
                       "about 100 descendants. The first column (D1) contains a letter used as "
                       "an alias for each depth-01 GO term. The second column represents the "
                       "number of descendants from the specified GO term from down to the total  "
                       "of its descendant leaf-level GO terms, which have no child GO terms.")
            prt.write("\caption{{{TEXT}}}\n\n".format(TEXT=caption))
            prt.write("\label{table:supptbl_d1}\n")
            prt.write("\end{table}\n")
            sys.stdout.write("  {N:>5} items WROTE: {TXT}\n".format(
                N=len(data_nts), TXT=fout_tex))
1315693
def write_hier(self, GO_id, out=sys.stdout,
                       len_dash=1, max_depth=None, num_child=None, short_prt=False,
                       include_only=None, go_marks=None):
        """"""
        gos_printed = set()
        self[GO_id].write_hier_rec(gos_printed, out, len_dash, max_depth, num_child,
            short_prt, include_only, go_marks)
110237
def _show_stat(self):
        
        _show_stat_wrapper_multi_Progress(self.count,
                                          self.last_count, 
                                          self.start_time, 
                                          self.max_count, 
                                          self.speed_calc_cycles,
                                          self.width,
                                          self.q,
                                          self.last_speed,
                                          self.prepend,
                                          self.show_stat,
                                          self.len, 
                                          self.add_args,
                                          self.lock,
                                          self.info_line,
                                          no_move_up=True)
1021497
def stats_on_depth(d, depth):
        
        root_nodes, leaf_nodes = 0, 0
        for _, node in DictTree.kv_depth(d, depth):
            if DictTree.length(node) == 0:
                leaf_nodes += 1
            else:
                root_nodes += 1
        total = root_nodes + leaf_nodes
        print("On depth %s, having %s root nodes, %s leaf nodes. "
              "%s nodes in total." % (depth, root_nodes, leaf_nodes, total))
461903
def prt_info(self, prt, sections=None):
        """"""
        if sections is None:
            sections = self.grprobj.get_sections_2d()
        num_goids = 0
        for section_name, nts_flat in sections:
            num_nts = len(nts_flat)
            num_goids += num_nts
            prt.write("{N:3} GO IDs in section({SEC})\n".format(N=num_nts, SEC=section_name))
        prt.write("{N:3} GO IDs\n".format(N=num_goids))
1187646
def prt_paths(paths, prt=sys.stdout):
        """"""
        pat = "PATHES: {GO} L{L:02} D{D:02}\n"
        for path in paths:
            for go_obj in path:
                prt.write(pat.format(GO=go_obj.id, L=go_obj.level, D=go_obj.depth))
            prt.write("\n")
449969
def statistics(stats)
      traverse do |node, position, stack|
        if position == 0
          if node.is_leaf?
            stats.leaf_nodes += 1
            depth = stack.size + 1
            if stats.min_depth.nil? || stats.min_depth < depth
              stats.min_depth = depth
            end
            if stats.max_depth.nil? || stats.max_depth > depth
              stats.max_depth = depth
            end
          else
            stats.branch_nodes += 1
          end
        end
      end
    end
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
373322
def _tick(self):
        """"""
        if (self.verbose >= 3 and not IS_REDIRECTED) or self.options.get("progress"):
            stats = self.get_stats()
            prefix = DRY_RUN_PREFIX if self.dry_run else ""
            sys.stdout.write(
                "{}Touched {}/{} entries in {} directories...\r".format(
                    prefix,
                    stats["entries_touched"],
                    stats["entries_seen"],
                    stats["local_dirs"],
                )
            )
        sys.stdout.flush()
        return
1310497
def entry_stats(entries, top_n=10):
    """"""

    wc = Counter()  # A Word counter
    for content in entries.values_list("rendered_content", flat=True):
        # Do a little cleanup
        content = strip_tags(content)  # remove all html tags
        content = re.sub('\s+', ' ', content)  # condense all whitespace
        content = re.sub('[^A-Za-z ]+', '', content)  # remove non-alpha chars

        words = [w.lower() for w in content.split()]
        wc.update([w for w in words if w not in IGNORE_WORDS])

    return {
        "total_words": len(wc.values()),
        "most_common": wc.most_common(top_n),
    }
745552
def print_summary(self, stream=sys.stdout, indent=""):
        
        stream.write("%sTotal files      : %i\n" %
                     (indent, len(self.file_dict)))
        stream.write("%s  Input files    : %i\n" %
                     (indent, len(self.input_files)))
        stream.write("%s  Output files   : %i\n" %
                     (indent, len(self.output_files)))
        stream.write("%s  Internal files : %i\n" %
                     (indent, len(self.internal_files)))
        stream.write("%s  Temp files     : %i\n" %
                     (indent, len(self.temp_files)))
536562
def summarize_taxa(biom):
    
    tamtcounts = defaultdict(int)
    tot_seqs = 0.0

    for row, col, amt in biom['data']:
        tot_seqs += amt
        rtax = biom['rows'][row]['metadata']['taxonomy']
        for i, t in enumerate(rtax):
            t = t.strip()
            if i == len(rtax)-1 and len(t) > 3 and len(rtax[-1]) > 3:
                t = 's__'+rtax[i-1].strip().split('_')[-1]+'_'+t.split('_')[-1]
            tamtcounts[t] += amt

    lvlData = {lvl: levelData(tamtcounts, tot_seqs, lvl) for lvl in ['k', 'p', 'c', 'o', 'f', 'g', 's']}

    return tot_seqs, lvlData