Collect counts of GO terms at all levels and depths.
432816
def get_data(self):
        """"""
        # Count level(shortest path to root) and depth(longest path to root)
        # values for all unique GO Terms.
        data = []
        ntobj = cx.namedtuple("NtGoCnt", "Depth_Level BP_D MF_D CC_D BP_L MF_L CC_L")
        cnts = self.get_cnts_levels_depths_recs(set(self.obo.values()))
        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 = [i] + [cnts[desc][i][ns] for desc in cnts for ns in self.nss]
            data.append(ntobj._make(vals))
        return data
500390
def get_grouped(self, go_ntsets, go_all, gosubdag, **kws):
        """"""
        kws_grpd = {k:v for k, v in kws.items() if k in Grouped.kws_dict}
        kws_grpd['go2nt'] = self._init_go2ntpresent(go_ntsets, go_all, gosubdag)
        return Grouped(gosubdag, self.godag.version, **kws_grpd)
651654
function collect() {
		$inc_failed = count($this->_failed['inc']);
		$dec_failed = count($this->_failed['dec']);
		$n_saved    = count($this->_saved);
		$n_inc      = count($this->_increased);
		$n_dec      = count($this->_decreased);
		$n_fetched  = count($this->_fetched);
		$n_deleted  = count($this->_deleted);
		$data = array(
			'count'       =>0,
			'messages'    =>array(),
		);
		if ( $inc_failed+$dec_failed>0 ) {
			$data['messages'][] =  array(
				'message'  => "Caches Failed: [ Inc:{$inc_failed} , Dec:{$dec_failed} ]",
				'is_string'=> true,
				'label'    => 'Caches Summary'
			);
		}
		$message = "Caches Count: [ Saved:{$n_saved} ; Gets:{$n_fetched}";
		if ( $this->_nulls>0 ) {
			$message .= "(nulls:{$this->_nulls})";
		}
		if ( $n_inc>0 ) {
			$message .= " ; Inc:{$n_inc}";
		}
		if ( $n_dec>0 ) {
			$message .= " ; Dec:{$n_dec}";
		}
		if ( $n_deleted>0 ) {
			$message .= " ; Deleted:{$n_deleted}";
		}
		if ( $this->_flushed ) {
			$message .= " ; Has Flushed";
		}
		$data['messages'][] = array(
			'message'  => $message.' ]',
			'is_string'=> true,
			'label'    => 'Caches Summary'
		);

		if ( !$this->_mode && $this->_messagesCollector ) {
			foreach ( $data['messages'] as $value ) {
				$this->_messagesCollector->addMessage($value['message'],$value['label'],$value['is_string']);
			}
			return array();
		}

		$messages = array();
		foreach ( $this->_saved as $key=>$value ) {
			$lifetime = '';
			if ( $value['lifetime']!==null ) {
				$lifetime = "Lifetime=>"."{$value['lifetime']}";
			}
			$content    = $value['content'];
			if ( !is_string( $content ) ) {
				$content = $this->formatVars($content);
				$message= "Saved: [ Key=>\"$key\"  $lifetime  Value=> $content[0] ]";
			}else{
				$message= "Saved: [ Key=>\"$key\"  $lifetime  Value=> \"$content\" ]";
			}
			$messages[] = array(
				'message'   => $message,
				'is_string' => mb_strlen($message)>100?false:true,
				'label'     => 'Saved',
				'time'      =>$value['time'],
			);
		}
		foreach ( $this->_fetched as $key=>$value ) {
			$content = $value['value'];
			if ( !is_string( $value ) ) {
				$content = $this->formatVars($content);
				$message= "Gets: [ Key=>\"$key\"   Value=> $content[0] ]";
			}else{
				$message= "Gets: [ Key=>\"$key\"   Value=> \"$content\" ]";
			}
			$messages[] = array(
				'message'   => $message,
				'is_string' => mb_strlen($message)>100?false:true,
				'label'     => 'Gets',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_deleted as $value ) {
			$messages[] = array(
				'message'   => 'DeletedKey: [ '.$value['key'].' ]',
				'is_string' => true,
				'label'     => 'Deleted',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_increased as $value ) {
			$messages[] = array(
				'message'   => "Increased: [ Key:{$value['key']} , Step:{$value['step']} , NewValue:{$value['new_value']}] ",
				'is_string' => true,
				'label'     => 'Increased',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_decreased as $value ) {
			$messages[] = array(
				'message'   => "Decreased: [ Key:{$value['key']} , Step:{$value['step']} , NewValue:{$value['new_value']}] ",
				'is_string' => true,
				'label'     => 'Decreased',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_failed['inc'] as $value ) {
			$messages[] = array(
				'message'   => "IncFailed: [ Key:{$value['key']} , Step:{$value['step']}] ",
				'is_string' => true,
				'label'     => 'IncFailed',
				'time'      => $value['time'],
			);
		}
		foreach ( $this->_failed['dec'] as $value ) {
			$messages[] = array(
				'message'   => "DecFailed: [ Key:{$value['key']} , Step:{$value['step']}] ",
				'is_string' => true,
				'label'     => 'DecFailed',
				'time'      => $value['time'],
			);
		}
		$data['messages'] = array_merge($data['messages'],  $this->sort($messages));
		$data['count'] = count($messages);
		return $data;
	}
725574
def count_all(self):
        
        return sum(x.func.count_all() if x.is_subchain else 1 for x in self)
598396
def index():
    """"""
    stats = dict((k, {"count": 0}) for k, tt in conf.InputTables)
    countminmax = "SUM(count) AS count, MIN(day) AS first, MAX(day) AS last"
    for input, table in [(x, t) for x, tt in conf.InputTables for t in tt]:
        row = db.fetchone("counts", countminmax, type=table)
        if not row["count"]: continue # for input, table
        stats[input]["count"] += row["count"]
        for func, key in [(min, "first"), (max, "last")]:
            stats[input][key] = (row[key] if key not in stats[input]
                                 else func(stats[input][key], row[key]))
    return bottle.template("index.tpl", locals(), conf=conf)
637905
def count(self, strg, case_sensitive=False, *args, **kwargs):
    
    if not case_sensitive:
        return [word.lower() for word in self].count(strg.lower(), *args,
                **kwargs)
    return self._collection.count(strg, *args, **kwargs)
860991
def dflt_sortby_objgoea(goea_res):
        """"""
        return [getattr(goea_res, 'enrichment'),
                getattr(goea_res, 'namespace'),
                getattr(goea_res, 'p_uncorrected'),
                getattr(goea_res, 'depth'),
                getattr(goea_res, 'GO')]
36846
def phrases_reduce(key, values):
  """"""
  if len(values) < 10:
    return
  counts = {}
  for filename in values:
    counts[filename] = counts.get(filename, 0) + 1

  words = re.sub(r":", " ", key)
  threshold = len(values) / 2
  for filename, count in counts.items():
    if count > threshold:
      yield "%s:%s\n" % (words, filename)
1093750
def count_items(self):
        """"""
        soup_items = self.soup.findAll('item')
        full_soup_items = self.full_soup.findAll('item')
        return len(soup_items), len(full_soup_items)
768215
def _get_go2nt_all(self, rcntobj):
        """"""
        ### tic = timeit.default_timer()
        go2nt = {}
        ntobj = cx.namedtuple("NtGo", " ".join(self.prt_flds))
        ### tic = _rpt_hms(tic, "GoSubDag: _Init::get_go2nt")
        tcntobj = self.kws['tcntobj'] if 'tcntobj' in self.kws else None
        b_tcnt = tcntobj is not None
        # b_rcnt = rcntobj is not None and rcntobj
        objrelstr = RelationshipStr(self.relationships)
        namespace2ns = objrelstr.consts.NAMESPACE2NS
        for goid, goobj in self.go2obj.items():
            ns_go = namespace2ns[goobj.namespace]
            fld2vals = {
                'NS' : ns_go,
                'level' : goobj.level,
                'depth' : goobj.depth,
                'GO' : goid,
                'alt' : '' if goid == goobj.id else 'a',
                'id' : goobj.id,
                'GO_name' : goobj.name}
            if 'dcnt' in self.kw_elems:
                fld2vals['dcnt'] = rcntobj.go2dcnt.get(goid)
            if 'D1' in self.kw_elems:
                fld2vals['D1'] = rcntobj.get_d1str(goobj)
            if b_tcnt:
                tcnt = tcntobj.gocnts[goid]
                num_ns = float(tcntobj.aspect_counts[goobj.namespace])
                tfreq = float(tcnt)/num_ns if num_ns != 0 else 0
                fld2vals['tcnt'] = tcnt
                fld2vals['tfreq'] = tfreq
                fld2vals['tinfo'] = -1.0 * math.log(tfreq) if tfreq else 0
            if self.relationships:
                fld2vals['childcnt'] = len(goobj.children)
                fld2vals['reldepth'] = goobj.reldepth
                fld2vals['REL'] = objrelstr.str_relationships(goobj)
                fld2vals['REL_short'] = objrelstr.str_rel_short(goobj)
                fld2vals['rel'] = objrelstr.str_relationships_rev(goobj)
            go2nt[goid] = ntobj(**fld2vals)
        ### tic = _rpt_hms(tic, "GoSubDag: _Init::get_go2nt")
        return go2nt
536182
def _getValueCounts(mapping):
    
    return Counter({k: len(v) for k, v in viewitems(mapping)})
711604
def _init_count_terms(self, annots):
        '''
            
        '''
        gonotindag = set()
        gocnts = self.gocnts
        go2obj = self.go2obj
        # Fill gocnts with GO IDs in annotations and their corresponding counts
        for terms in annots.values(): # key is 'gene'
            # Make a union of all the terms for a gene, if term parents are
            # propagated but they won't get double-counted for the gene
            allterms = set()
            for go_id in terms:
                goobj = go2obj.get(go_id, None)
                if goobj is not None:
                    allterms.add(go_id)
                    allterms |= goobj.get_all_parents()
                else:
                    gonotindag.add(go_id)
            for parent in allterms:
                gocnts[parent] += 1
        if gonotindag:
            print("{N} Assc. GO IDs not found in the GODag\n".format(N=len(gonotindag)))
237135
def get_count(self, prefix=''):
        """"""
        return sum([self.counters[key]
                    for key in self.messages if key.startswith(prefix)])
484124
def _get_all_relationships(self):
        """"""
        relationships_all = set()
        for goterm in self.go2obj.values():
            if goterm.relationship:
                relationships_all.update(goterm.relationship)
            if goterm.relationship_rev:
                relationships_all.update(goterm.relationship_rev)
        return relationships_all
789977
def all(self):
    " "
    query,inputs = self._toedn()
    return self.db.q(query,
      inputs  = inputs,
      limit   = self._limit,
      offset  = self._offset,
      history = self._history)
1231508
def _load_type_counts(self):
		""""""

		rel_path = os.path.join(CLTK_DATA_DIR,
                                'old_english',
                                'model',
                                'old_english_models_cltk',
                                'data',
                                'oe.counts')
		path = os.path.expanduser(rel_path)

		self.type_counts = {}

		with open(path, 'r') as infile:
			lines = infile.read().splitlines()
			for line in lines:
				count, word = line.split()
				self.type_counts[word] = int(count)
831990
def count(self, Class, set=None, recursive=True,ignore=True):
        """"""
        if self.mode == Mode.MEMORY:
            s = 0
            for t in self.data:
                s +=  sum( 1 for e in t.select(Class,recursive,True ) )
            return s