id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
242,300
tanghaibao/goatools
goatools/go_search.py
GoSearch._search_vals
def _search_vals(self, compiled_pattern, fld_val): """Search for user-regex in scalar or iterable data values.""" matches = [] if isinstance(fld_val, set): for val in fld_val: self._search_val(matches, compiled_pattern, val) elif isinstance(fld_val, str): self._search_val(matches, compiled_pattern, fld_val) return matches
python
def _search_vals(self, compiled_pattern, fld_val): matches = [] if isinstance(fld_val, set): for val in fld_val: self._search_val(matches, compiled_pattern, val) elif isinstance(fld_val, str): self._search_val(matches, compiled_pattern, fld_val) return matches
[ "def", "_search_vals", "(", "self", ",", "compiled_pattern", ",", "fld_val", ")", ":", "matches", "=", "[", "]", "if", "isinstance", "(", "fld_val", ",", "set", ")", ":", "for", "val", "in", "fld_val", ":", "self", ".", "_search_val", "(", "matches", "...
Search for user-regex in scalar or iterable data values.
[ "Search", "for", "user", "-", "regex", "in", "scalar", "or", "iterable", "data", "values", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L57-L65
242,301
tanghaibao/goatools
goatools/go_search.py
GoSearch._search_val
def _search_val(matches, compiled_pattern, fld_val): """Search for user-regex in scalar data values.""" mtch = compiled_pattern.search(fld_val) if mtch: matches.append(fld_val)
python
def _search_val(matches, compiled_pattern, fld_val): mtch = compiled_pattern.search(fld_val) if mtch: matches.append(fld_val)
[ "def", "_search_val", "(", "matches", ",", "compiled_pattern", ",", "fld_val", ")", ":", "mtch", "=", "compiled_pattern", ".", "search", "(", "fld_val", ")", "if", "mtch", ":", "matches", ".", "append", "(", "fld_val", ")" ]
Search for user-regex in scalar data values.
[ "Search", "for", "user", "-", "regex", "in", "scalar", "data", "values", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L68-L72
242,302
tanghaibao/goatools
goatools/go_search.py
GoSearch.add_children_gos
def add_children_gos(self, gos): """Return children of input gos plus input gos.""" lst = [] obo_dag = self.obo_dag get_children = lambda go_obj: list(go_obj.get_all_children()) + [go_obj.id] for go_id in gos: go_obj = obo_dag[go_id] lst.extend(get_children(go_obj)) return set(lst)
python
def add_children_gos(self, gos): lst = [] obo_dag = self.obo_dag get_children = lambda go_obj: list(go_obj.get_all_children()) + [go_obj.id] for go_id in gos: go_obj = obo_dag[go_id] lst.extend(get_children(go_obj)) return set(lst)
[ "def", "add_children_gos", "(", "self", ",", "gos", ")", ":", "lst", "=", "[", "]", "obo_dag", "=", "self", ".", "obo_dag", "get_children", "=", "lambda", "go_obj", ":", "list", "(", "go_obj", ".", "get_all_children", "(", ")", ")", "+", "[", "go_obj",...
Return children of input gos plus input gos.
[ "Return", "children", "of", "input", "gos", "plus", "input", "gos", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L74-L82
242,303
tanghaibao/goatools
goatools/go_search.py
GoSearch.get_items
def get_items(self, gos): """Given GO terms, return genes or gene products for the GOs.""" items = [] for go_id in gos: items.extend(self.go2items.get(go_id, [])) return set(items)
python
def get_items(self, gos): items = [] for go_id in gos: items.extend(self.go2items.get(go_id, [])) return set(items)
[ "def", "get_items", "(", "self", ",", "gos", ")", ":", "items", "=", "[", "]", "for", "go_id", "in", "gos", ":", "items", ".", "extend", "(", "self", ".", "go2items", ".", "get", "(", "go_id", ",", "[", "]", ")", ")", "return", "set", "(", "ite...
Given GO terms, return genes or gene products for the GOs.
[ "Given", "GO", "terms", "return", "genes", "or", "gene", "products", "for", "the", "GOs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L84-L89
242,304
tanghaibao/goatools
goatools/gosubdag/plot/goea_results.py
GoeaResults.prt_summary
def prt_summary(self, prt=sys.stdout): """Print summary of GOEA plotting object.""" desc = "NtGoeaResults" if self.is_goterm else "namedtuple" prt.write("{N} GOEA results from {O}. P-values stored in {P}.\n".format( N=len(self.go2res), O=desc, P=self.pval_name))
python
def prt_summary(self, prt=sys.stdout): desc = "NtGoeaResults" if self.is_goterm else "namedtuple" prt.write("{N} GOEA results from {O}. P-values stored in {P}.\n".format( N=len(self.go2res), O=desc, P=self.pval_name))
[ "def", "prt_summary", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "desc", "=", "\"NtGoeaResults\"", "if", "self", ".", "is_goterm", "else", "\"namedtuple\"", "prt", ".", "write", "(", "\"{N} GOEA results from {O}. P-values stored in {P}.\\n\"", "...
Print summary of GOEA plotting object.
[ "Print", "summary", "of", "GOEA", "plotting", "object", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/goea_results.py#L40-L44
242,305
tanghaibao/goatools
goatools/gosubdag/plot/goea_results.py
GoeaResults.set_goid2color_pval
def set_goid2color_pval(self, goid2color): """Fill missing colors based on p-value of an enriched GO term.""" alpha2col = self.alpha2col if self.pval_name is not None: pval_name = self.pval_name for goid, res in self.go2res.items(): pval = getattr(res, pval_name, None) if pval is not None: for alpha, color in alpha2col.items(): if pval <= alpha and res.study_count != 0: if goid not in goid2color: goid2color[goid] = color
python
def set_goid2color_pval(self, goid2color): alpha2col = self.alpha2col if self.pval_name is not None: pval_name = self.pval_name for goid, res in self.go2res.items(): pval = getattr(res, pval_name, None) if pval is not None: for alpha, color in alpha2col.items(): if pval <= alpha and res.study_count != 0: if goid not in goid2color: goid2color[goid] = color
[ "def", "set_goid2color_pval", "(", "self", ",", "goid2color", ")", ":", "alpha2col", "=", "self", ".", "alpha2col", "if", "self", ".", "pval_name", "is", "not", "None", ":", "pval_name", "=", "self", ".", "pval_name", "for", "goid", ",", "res", "in", "se...
Fill missing colors based on p-value of an enriched GO term.
[ "Fill", "missing", "colors", "based", "on", "p", "-", "value", "of", "an", "enriched", "GO", "term", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/goea_results.py#L55-L66
242,306
tanghaibao/goatools
goatools/gosubdag/plot/goea_results.py
GoeaResults.get_goid2color_pval
def get_goid2color_pval(self): """Return a go2color dict containing GO colors determined by P-value.""" go2color = {} self.set_goid2color_pval(go2color) color_dflt = self.alpha2col[1.000] for goid in self.go2res: if goid not in go2color: go2color[goid] = color_dflt return go2color
python
def get_goid2color_pval(self): go2color = {} self.set_goid2color_pval(go2color) color_dflt = self.alpha2col[1.000] for goid in self.go2res: if goid not in go2color: go2color[goid] = color_dflt return go2color
[ "def", "get_goid2color_pval", "(", "self", ")", ":", "go2color", "=", "{", "}", "self", ".", "set_goid2color_pval", "(", "go2color", ")", "color_dflt", "=", "self", ".", "alpha2col", "[", "1.000", "]", "for", "goid", "in", "self", ".", "go2res", ":", "if...
Return a go2color dict containing GO colors determined by P-value.
[ "Return", "a", "go2color", "dict", "containing", "GO", "colors", "determined", "by", "P", "-", "value", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/goea_results.py#L68-L76
242,307
tanghaibao/goatools
goatools/rpt/rpt_lev_depth.py
RptLevDepth.prttex_summary_cnts_all
def prttex_summary_cnts_all(self, prt=sys.stdout): """Print LaTeX format summary of level and depth counts for all active GO Terms.""" cnts = self.get_cnts_levels_depths_recs(set(self.obo.values())) self._prttex_summary_cnts(prt, cnts)
python
def prttex_summary_cnts_all(self, prt=sys.stdout): cnts = self.get_cnts_levels_depths_recs(set(self.obo.values())) self._prttex_summary_cnts(prt, cnts)
[ "def", "prttex_summary_cnts_all", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "cnts", "=", "self", ".", "get_cnts_levels_depths_recs", "(", "set", "(", "self", ".", "obo", ".", "values", "(", ")", ")", ")", "self", ".", "_prttex_summary...
Print LaTeX format summary of level and depth counts for all active GO Terms.
[ "Print", "LaTeX", "format", "summary", "of", "level", "and", "depth", "counts", "for", "all", "active", "GO", "Terms", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L82-L85
242,308
tanghaibao/goatools
goatools/rpt/rpt_lev_depth.py
RptLevDepth.write_summary_cnts_all
def write_summary_cnts_all(self): """Write summary of level and depth counts for all active GO Terms.""" cnts = self.get_cnts_levels_depths_recs(set(self.obo.values())) self._write_summary_cnts(cnts)
python
def write_summary_cnts_all(self): cnts = self.get_cnts_levels_depths_recs(set(self.obo.values())) self._write_summary_cnts(cnts)
[ "def", "write_summary_cnts_all", "(", "self", ")", ":", "cnts", "=", "self", ".", "get_cnts_levels_depths_recs", "(", "set", "(", "self", ".", "obo", ".", "values", "(", ")", ")", ")", "self", ".", "_write_summary_cnts", "(", "cnts", ")" ]
Write summary of level and depth counts for all active GO Terms.
[ "Write", "summary", "of", "level", "and", "depth", "counts", "for", "all", "active", "GO", "Terms", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L87-L90
242,309
tanghaibao/goatools
goatools/rpt/rpt_lev_depth.py
RptLevDepth.write_summary_cnts
def write_summary_cnts(self, go_ids): """Write summary of level and depth counts for specific GO ids.""" obo = self.obo cnts = self.get_cnts_levels_depths_recs([obo.get(GO) for GO in go_ids]) self._write_summary_cnts(cnts)
python
def write_summary_cnts(self, go_ids): obo = self.obo cnts = self.get_cnts_levels_depths_recs([obo.get(GO) for GO in go_ids]) self._write_summary_cnts(cnts)
[ "def", "write_summary_cnts", "(", "self", ",", "go_ids", ")", ":", "obo", "=", "self", ".", "obo", "cnts", "=", "self", ".", "get_cnts_levels_depths_recs", "(", "[", "obo", ".", "get", "(", "GO", ")", "for", "GO", "in", "go_ids", "]", ")", "self", "....
Write summary of level and depth counts for specific GO ids.
[ "Write", "summary", "of", "level", "and", "depth", "counts", "for", "specific", "GO", "ids", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L92-L96
242,310
tanghaibao/goatools
goatools/rpt/rpt_lev_depth.py
RptLevDepth.get_cnts_levels_depths_recs
def get_cnts_levels_depths_recs(recs): """Collect counts of levels and depths in a Group of GO Terms.""" cnts = cx.defaultdict(lambda: cx.defaultdict(cx.Counter)) for rec in recs: if rec is not None and not rec.is_obsolete: cnts['level'][rec.level][rec.namespace] += 1 cnts['depth'][rec.depth][rec.namespace] += 1 return cnts
python
def get_cnts_levels_depths_recs(recs): cnts = cx.defaultdict(lambda: cx.defaultdict(cx.Counter)) for rec in recs: if rec is not None and not rec.is_obsolete: cnts['level'][rec.level][rec.namespace] += 1 cnts['depth'][rec.depth][rec.namespace] += 1 return cnts
[ "def", "get_cnts_levels_depths_recs", "(", "recs", ")", ":", "cnts", "=", "cx", ".", "defaultdict", "(", "lambda", ":", "cx", ".", "defaultdict", "(", "cx", ".", "Counter", ")", ")", "for", "rec", "in", "recs", ":", "if", "rec", "is", "not", "None", ...
Collect counts of levels and depths in a Group of GO Terms.
[ "Collect", "counts", "of", "levels", "and", "depths", "in", "a", "Group", "of", "GO", "Terms", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L149-L156
242,311
tanghaibao/goatools
goatools/rpt/rpt_lev_depth.py
RptLevDepth.get_data
def get_data(self): """Collect counts of GO terms at all levels and depths.""" # 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
python
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
[ "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_...
Collect counts of GO terms at all levels and depths.
[ "Collect", "counts", "of", "GO", "terms", "at", "all", "levels", "and", "depths", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L158-L169
242,312
tanghaibao/goatools
scripts/find_enrichment.py
main
def main(): """Run gene enrichment analysis.""" # Load study, population, associations, and GoDag. Run GOEA. obj = GoeaCliFnc(GoeaCliArgs().args) # Reduce results to significant results (pval<value) results_specified = obj.get_results() # Print results in a flat list obj.prt_results(results_specified)
python
def main(): # Load study, population, associations, and GoDag. Run GOEA. obj = GoeaCliFnc(GoeaCliArgs().args) # Reduce results to significant results (pval<value) results_specified = obj.get_results() # Print results in a flat list obj.prt_results(results_specified)
[ "def", "main", "(", ")", ":", "# Load study, population, associations, and GoDag. Run GOEA.", "obj", "=", "GoeaCliFnc", "(", "GoeaCliArgs", "(", ")", ".", "args", ")", "# Reduce results to significant results (pval<value)", "results_specified", "=", "obj", ".", "get_results...
Run gene enrichment analysis.
[ "Run", "gene", "enrichment", "analysis", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/scripts/find_enrichment.py#L28-L35
242,313
tanghaibao/goatools
goatools/anno/factory.py
get_objanno
def get_objanno(fin_anno, anno_type=None, **kws): """Read annotations in GAF, GPAD, Entrez gene2go, or text format.""" # kws get_objanno: taxids hdr_only prt allow_missing_symbol anno_type = get_anno_desc(fin_anno, anno_type) if anno_type is not None: if anno_type == 'gene2go': # kws: taxid taxids return Gene2GoReader(fin_anno, **kws) if anno_type == 'gaf': return GafReader(fin_anno, hdr_only=kws.get('hdr_only', False), prt=kws.get('prt', sys.stdout), allow_missing_symbol=kws.get('allow_missing_symbol', False)) if anno_type == 'gpad': hdr_only = kws.get('hdr_only', False) return GpadReader(fin_anno, hdr_only) if anno_type == 'id2gos': return IdToGosReader(fin_anno) raise RuntimeError('UNEXPECTED ANNOTATION FILE FORMAT: {F} {D}'.format( F=fin_anno, D=anno_type))
python
def get_objanno(fin_anno, anno_type=None, **kws): # kws get_objanno: taxids hdr_only prt allow_missing_symbol anno_type = get_anno_desc(fin_anno, anno_type) if anno_type is not None: if anno_type == 'gene2go': # kws: taxid taxids return Gene2GoReader(fin_anno, **kws) if anno_type == 'gaf': return GafReader(fin_anno, hdr_only=kws.get('hdr_only', False), prt=kws.get('prt', sys.stdout), allow_missing_symbol=kws.get('allow_missing_symbol', False)) if anno_type == 'gpad': hdr_only = kws.get('hdr_only', False) return GpadReader(fin_anno, hdr_only) if anno_type == 'id2gos': return IdToGosReader(fin_anno) raise RuntimeError('UNEXPECTED ANNOTATION FILE FORMAT: {F} {D}'.format( F=fin_anno, D=anno_type))
[ "def", "get_objanno", "(", "fin_anno", ",", "anno_type", "=", "None", ",", "*", "*", "kws", ")", ":", "# kws get_objanno: taxids hdr_only prt allow_missing_symbol", "anno_type", "=", "get_anno_desc", "(", "fin_anno", ",", "anno_type", ")", "if", "anno_type", "is", ...
Read annotations in GAF, GPAD, Entrez gene2go, or text format.
[ "Read", "annotations", "in", "GAF", "GPAD", "Entrez", "gene2go", "or", "text", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/factory.py#L13-L32
242,314
tanghaibao/goatools
goatools/anno/gpad_reader.py
GpadReader.get_relation_cnt
def get_relation_cnt(self): """Return a Counter containing all relations contained in the Annotation Extensions.""" ctr = cx.Counter() for ntgpad in self.associations: if ntgpad.Extension is not None: ctr += ntgpad.Extension.get_relations_cnt() return ctr
python
def get_relation_cnt(self): ctr = cx.Counter() for ntgpad in self.associations: if ntgpad.Extension is not None: ctr += ntgpad.Extension.get_relations_cnt() return ctr
[ "def", "get_relation_cnt", "(", "self", ")", ":", "ctr", "=", "cx", ".", "Counter", "(", ")", "for", "ntgpad", "in", "self", ".", "associations", ":", "if", "ntgpad", ".", "Extension", "is", "not", "None", ":", "ctr", "+=", "ntgpad", ".", "Extension", ...
Return a Counter containing all relations contained in the Annotation Extensions.
[ "Return", "a", "Counter", "containing", "all", "relations", "contained", "in", "the", "Annotation", "Extensions", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/gpad_reader.py#L24-L30
242,315
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._get_id2gos
def _get_id2gos(self): """Return annotations as id2gos""" kws = {} if self.args.ev_inc is not None: kws['ev_include'] = set(self.args.ev_inc.split(',')) if self.args.ev_exc is not None: kws['ev_exclude'] = set(self.args.ev_exc.split(',')) return self.objanno.get_id2gos(**kws)
python
def _get_id2gos(self): kws = {} if self.args.ev_inc is not None: kws['ev_include'] = set(self.args.ev_inc.split(',')) if self.args.ev_exc is not None: kws['ev_exclude'] = set(self.args.ev_exc.split(',')) return self.objanno.get_id2gos(**kws)
[ "def", "_get_id2gos", "(", "self", ")", ":", "kws", "=", "{", "}", "if", "self", ".", "args", ".", "ev_inc", "is", "not", "None", ":", "kws", "[", "'ev_include'", "]", "=", "set", "(", "self", ".", "args", ".", "ev_inc", ".", "split", "(", "','",...
Return annotations as id2gos
[ "Return", "annotations", "as", "id2gos" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L182-L189
242,316
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._get_objanno
def _get_objanno(self, assoc_fn): """Get an annotation object""" # Determine annotation file format from filename, if possible anno_type = get_anno_desc(assoc_fn, None) # Default annotation file format is id2gos if anno_type is None: anno_type = self.args.annofmt if self.args.annofmt else 'id2gos' kws = {'taxid': self.args.taxid} if anno_type == 'gene2go' else {} return get_objanno(assoc_fn, anno_type, **kws)
python
def _get_objanno(self, assoc_fn): # Determine annotation file format from filename, if possible anno_type = get_anno_desc(assoc_fn, None) # Default annotation file format is id2gos if anno_type is None: anno_type = self.args.annofmt if self.args.annofmt else 'id2gos' kws = {'taxid': self.args.taxid} if anno_type == 'gene2go' else {} return get_objanno(assoc_fn, anno_type, **kws)
[ "def", "_get_objanno", "(", "self", ",", "assoc_fn", ")", ":", "# Determine annotation file format from filename, if possible", "anno_type", "=", "get_anno_desc", "(", "assoc_fn", ",", "None", ")", "# Default annotation file format is id2gos", "if", "anno_type", "is", "None...
Get an annotation object
[ "Get", "an", "annotation", "object" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L191-L199
242,317
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._init_itemid2name
def _init_itemid2name(self): """Print gene symbols instead of gene IDs, if provided.""" if not hasattr(self.args, 'id2sym'): return None fin_id2sym = self.args.id2sym if fin_id2sym is not None and os.path.exists(fin_id2sym): id2sym = {} cmpl = re.compile(r'^\s*(\S+)[\s,;]+(\S+)') with open(fin_id2sym) as ifstrm: for line in ifstrm: mtch = cmpl.search(line) if mtch: id2sym[mtch.group(1)] = mtch.group(2) return id2sym
python
def _init_itemid2name(self): if not hasattr(self.args, 'id2sym'): return None fin_id2sym = self.args.id2sym if fin_id2sym is not None and os.path.exists(fin_id2sym): id2sym = {} cmpl = re.compile(r'^\s*(\S+)[\s,;]+(\S+)') with open(fin_id2sym) as ifstrm: for line in ifstrm: mtch = cmpl.search(line) if mtch: id2sym[mtch.group(1)] = mtch.group(2) return id2sym
[ "def", "_init_itemid2name", "(", "self", ")", ":", "if", "not", "hasattr", "(", "self", ".", "args", ",", "'id2sym'", ")", ":", "return", "None", "fin_id2sym", "=", "self", ".", "args", ".", "id2sym", "if", "fin_id2sym", "is", "not", "None", "and", "os...
Print gene symbols instead of gene IDs, if provided.
[ "Print", "gene", "symbols", "instead", "of", "gene", "IDs", "if", "provided", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L201-L214
242,318
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.prt_results
def prt_results(self, goea_results): """Print GOEA results to the screen or to a file.""" # objaart = self.prepgrp.get_objaart(goea_results) if self.prepgrp is not None else None if self.args.outfile is None: self._prt_results(goea_results) else: # Users can print to both tab-separated file and xlsx file in one run. outfiles = self.args.outfile.split(",") grpwr = self.prepgrp.get_objgrpwr(goea_results) if self.prepgrp else None if grpwr is None: self.prt_outfiles_flat(goea_results, outfiles) else: grpwr.prt_outfiles_grouped(outfiles)
python
def prt_results(self, goea_results): # objaart = self.prepgrp.get_objaart(goea_results) if self.prepgrp is not None else None if self.args.outfile is None: self._prt_results(goea_results) else: # Users can print to both tab-separated file and xlsx file in one run. outfiles = self.args.outfile.split(",") grpwr = self.prepgrp.get_objgrpwr(goea_results) if self.prepgrp else None if grpwr is None: self.prt_outfiles_flat(goea_results, outfiles) else: grpwr.prt_outfiles_grouped(outfiles)
[ "def", "prt_results", "(", "self", ",", "goea_results", ")", ":", "# objaart = self.prepgrp.get_objaart(goea_results) if self.prepgrp is not None else None", "if", "self", ".", "args", ".", "outfile", "is", "None", ":", "self", ".", "_prt_results", "(", "goea_results", ...
Print GOEA results to the screen or to a file.
[ "Print", "GOEA", "results", "to", "the", "screen", "or", "to", "a", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L216-L228
242,319
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._prt_results
def _prt_results(self, goea_results): """Print GOEA results to the screen.""" min_ratio = self.args.ratio if min_ratio is not None: assert 1 <= min_ratio <= 2 self.objgoea.print_date(min_ratio=min_ratio, pval=self.args.pval) results_adj = self.objgoea.get_adj_records(goea_results, min_ratio, self.args.pval) if results_adj: if not self.prepgrp: self.objgoea.print_results_adj(results_adj, indent=self.args.indent) else: grpwr = self.prepgrp.get_objgrpwr(results_adj) grpwr.prt_txt(sys.stdout)
python
def _prt_results(self, goea_results): min_ratio = self.args.ratio if min_ratio is not None: assert 1 <= min_ratio <= 2 self.objgoea.print_date(min_ratio=min_ratio, pval=self.args.pval) results_adj = self.objgoea.get_adj_records(goea_results, min_ratio, self.args.pval) if results_adj: if not self.prepgrp: self.objgoea.print_results_adj(results_adj, indent=self.args.indent) else: grpwr = self.prepgrp.get_objgrpwr(results_adj) grpwr.prt_txt(sys.stdout)
[ "def", "_prt_results", "(", "self", ",", "goea_results", ")", ":", "min_ratio", "=", "self", ".", "args", ".", "ratio", "if", "min_ratio", "is", "not", "None", ":", "assert", "1", "<=", "min_ratio", "<=", "2", "self", ".", "objgoea", ".", "print_date", ...
Print GOEA results to the screen.
[ "Print", "GOEA", "results", "to", "the", "screen", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L241-L253
242,320
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.chk_genes
def chk_genes(self, study, pop, assoc=None): """Check gene sets.""" if len(pop) < len(study): exit("\nERROR: The study file contains more elements than the population file. " "Please check that the study file is a subset of the population file.\n") # check the fraction of genomic ids that overlap between study and population overlap = self.get_overlap(study, pop) if overlap < 0.95: sys.stderr.write("\nWARNING: only {} fraction of genes/proteins in study are found in " "the population background.\n\n".format(overlap)) if overlap <= self.args.min_overlap: exit("\nERROR: only {} of genes/proteins in the study are found in the " "background population. Please check.\n".format(overlap)) # Population and associations if assoc is not None and pop.isdisjoint(assoc.keys()): if self.objanno.name == 'gene2go': err = ('**FATAL: NO POPULATION ITEMS SEEN IN THE NCBI gene2go ANNOTATIONS ' 'FOR taxid({T}). TRY: --taxid=<taxid number>') exit(err.format(T=next(iter(self.objanno.taxid2asscs.keys())))) else: exit('**FATAL: NO POPULATION ITEMS SEEN IN THE ANNOTATIONS')
python
def chk_genes(self, study, pop, assoc=None): if len(pop) < len(study): exit("\nERROR: The study file contains more elements than the population file. " "Please check that the study file is a subset of the population file.\n") # check the fraction of genomic ids that overlap between study and population overlap = self.get_overlap(study, pop) if overlap < 0.95: sys.stderr.write("\nWARNING: only {} fraction of genes/proteins in study are found in " "the population background.\n\n".format(overlap)) if overlap <= self.args.min_overlap: exit("\nERROR: only {} of genes/proteins in the study are found in the " "background population. Please check.\n".format(overlap)) # Population and associations if assoc is not None and pop.isdisjoint(assoc.keys()): if self.objanno.name == 'gene2go': err = ('**FATAL: NO POPULATION ITEMS SEEN IN THE NCBI gene2go ANNOTATIONS ' 'FOR taxid({T}). TRY: --taxid=<taxid number>') exit(err.format(T=next(iter(self.objanno.taxid2asscs.keys())))) else: exit('**FATAL: NO POPULATION ITEMS SEEN IN THE ANNOTATIONS')
[ "def", "chk_genes", "(", "self", ",", "study", ",", "pop", ",", "assoc", "=", "None", ")", ":", "if", "len", "(", "pop", ")", "<", "len", "(", "study", ")", ":", "exit", "(", "\"\\nERROR: The study file contains more elements than the population file. \"", "\"...
Check gene sets.
[ "Check", "gene", "sets", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L269-L289
242,321
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.get_results_sig
def get_results_sig(self): """Get significant results.""" # Only print results when uncorrected p-value < this value. print("{N:7,} of {M:,} results have uncorrected P-values <= {PVAL}=pval\n".format( N=sum(1 for r in self.results_all if r.p_uncorrected < self.args.pval), M=len(self.results_all), PVAL=self.args.pval)) pval_fld = self.get_pval_field() results = [r for r in self.results_all if getattr(r, pval_fld) <= self.args.pval] return results
python
def get_results_sig(self): # Only print results when uncorrected p-value < this value. print("{N:7,} of {M:,} results have uncorrected P-values <= {PVAL}=pval\n".format( N=sum(1 for r in self.results_all if r.p_uncorrected < self.args.pval), M=len(self.results_all), PVAL=self.args.pval)) pval_fld = self.get_pval_field() results = [r for r in self.results_all if getattr(r, pval_fld) <= self.args.pval] return results
[ "def", "get_results_sig", "(", "self", ")", ":", "# Only print results when uncorrected p-value < this value.", "print", "(", "\"{N:7,} of {M:,} results have uncorrected P-values <= {PVAL}=pval\\n\"", ".", "format", "(", "N", "=", "sum", "(", "1", "for", "r", "in", "self", ...
Get significant results.
[ "Get", "significant", "results", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L291-L300
242,322
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.get_pval_field
def get_pval_field(self): """Get 'p_uncorrected' or the user-specified field for determining significant results.""" pval_fld = self.args.pval_field # If --pval_field [VAL] was specified if pval_fld is not None: if pval_fld[:2] != 'p_': pval_fld = 'p_' + pval_fld # If only one method was used, use that instead of the uncorrected pvalue elif len(self.methods) == 1: pval_fld = 'p_' + self.methods[0] # Use 'uncorrected pvalue' if there are many methods & none chosen using --pval_field else: pval_fld = 'p_uncorrected' if self.results_all: assert hasattr(next(iter(self.results_all)), pval_fld), \ 'NO PVAL({P}). EXPECTED ONE OF: {E}'.format( P=self.args.pval_field, E=" ".join([k for k in dir(next(iter(self.results_all))) if k[:2] == 'p_'])) return pval_fld
python
def get_pval_field(self): pval_fld = self.args.pval_field # If --pval_field [VAL] was specified if pval_fld is not None: if pval_fld[:2] != 'p_': pval_fld = 'p_' + pval_fld # If only one method was used, use that instead of the uncorrected pvalue elif len(self.methods) == 1: pval_fld = 'p_' + self.methods[0] # Use 'uncorrected pvalue' if there are many methods & none chosen using --pval_field else: pval_fld = 'p_uncorrected' if self.results_all: assert hasattr(next(iter(self.results_all)), pval_fld), \ 'NO PVAL({P}). EXPECTED ONE OF: {E}'.format( P=self.args.pval_field, E=" ".join([k for k in dir(next(iter(self.results_all))) if k[:2] == 'p_'])) return pval_fld
[ "def", "get_pval_field", "(", "self", ")", ":", "pval_fld", "=", "self", ".", "args", ".", "pval_field", "# If --pval_field [VAL] was specified", "if", "pval_fld", "is", "not", "None", ":", "if", "pval_fld", "[", ":", "2", "]", "!=", "'p_'", ":", "pval_fld",...
Get 'p_uncorrected' or the user-specified field for determining significant results.
[ "Get", "p_uncorrected", "or", "the", "user", "-", "specified", "field", "for", "determining", "significant", "results", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L307-L325
242,323
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.rd_files
def rd_files(self, study_fn, pop_fn): """Read files and return study and population.""" study, pop = self._read_geneset(study_fn, pop_fn) print("Study: {0} vs. Population {1}\n".format(len(study), len(pop))) return study, pop
python
def rd_files(self, study_fn, pop_fn): study, pop = self._read_geneset(study_fn, pop_fn) print("Study: {0} vs. Population {1}\n".format(len(study), len(pop))) return study, pop
[ "def", "rd_files", "(", "self", ",", "study_fn", ",", "pop_fn", ")", ":", "study", ",", "pop", "=", "self", ".", "_read_geneset", "(", "study_fn", ",", "pop_fn", ")", "print", "(", "\"Study: {0} vs. Population {1}\\n\"", ".", "format", "(", "len", "(", "st...
Read files and return study and population.
[ "Read", "files", "and", "return", "study", "and", "population", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L327-L331
242,324
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._read_geneset
def _read_geneset(self, study_fn, pop_fn): """Open files containing genes. Return study genes and population genes.""" pop = set(_.strip() for _ in open(pop_fn) if _.strip()) study = frozenset(_.strip() for _ in open(study_fn) if _.strip()) if next(iter(pop)).isdigit(): pop = set(int(g) for g in pop) study = frozenset(int(g) for g in study) # some times the pop is a second group to compare, rather than the # population in that case, we need to make sure the overlapping terms # are removed first if self.args.compare: common = pop & study pop |= study pop -= common study -= common sys.stderr.write("removed %d overlapping items\n" % (len(common))) sys.stderr.write("Set 1: {0}, Set 2: {1}\n".format( len(study), len(pop))) return study, pop
python
def _read_geneset(self, study_fn, pop_fn): pop = set(_.strip() for _ in open(pop_fn) if _.strip()) study = frozenset(_.strip() for _ in open(study_fn) if _.strip()) if next(iter(pop)).isdigit(): pop = set(int(g) for g in pop) study = frozenset(int(g) for g in study) # some times the pop is a second group to compare, rather than the # population in that case, we need to make sure the overlapping terms # are removed first if self.args.compare: common = pop & study pop |= study pop -= common study -= common sys.stderr.write("removed %d overlapping items\n" % (len(common))) sys.stderr.write("Set 1: {0}, Set 2: {1}\n".format( len(study), len(pop))) return study, pop
[ "def", "_read_geneset", "(", "self", ",", "study_fn", ",", "pop_fn", ")", ":", "pop", "=", "set", "(", "_", ".", "strip", "(", ")", "for", "_", "in", "open", "(", "pop_fn", ")", "if", "_", ".", "strip", "(", ")", ")", "study", "=", "frozenset", ...
Open files containing genes. Return study genes and population genes.
[ "Open", "files", "containing", "genes", ".", "Return", "study", "genes", "and", "population", "genes", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L333-L351
242,325
tanghaibao/goatools
goatools/cli/find_enrichment.py
GroupItems.get_objgrpwr
def get_objgrpwr(self, goea_results): """Get a GrpWr object to write grouped GOEA results.""" sortobj = self.get_sortobj(goea_results) return GrpWr(sortobj, self.pval_fld, ver_list=self.ver_list)
python
def get_objgrpwr(self, goea_results): sortobj = self.get_sortobj(goea_results) return GrpWr(sortobj, self.pval_fld, ver_list=self.ver_list)
[ "def", "get_objgrpwr", "(", "self", ",", "goea_results", ")", ":", "sortobj", "=", "self", ".", "get_sortobj", "(", "goea_results", ")", "return", "GrpWr", "(", "sortobj", ",", "self", ".", "pval_fld", ",", "ver_list", "=", "self", ".", "ver_list", ")" ]
Get a GrpWr object to write grouped GOEA results.
[ "Get", "a", "GrpWr", "object", "to", "write", "grouped", "GOEA", "results", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L370-L373
242,326
tanghaibao/goatools
goatools/cli/find_enrichment.py
GroupItems.get_sortobj
def get_sortobj(self, goea_results, **kws): """Return a Grouper object, given a list of GOEnrichmentRecord.""" nts_goea = MgrNtGOEAs(goea_results).get_goea_nts_prt(**kws) goids = set(nt.GO for nt in nts_goea) go2nt = {nt.GO:nt for nt in nts_goea} grprobj = Grouper("GOEA", goids, self.hdrobj, self.grprdflt.gosubdag, go2nt=go2nt) grprobj.prt_summary(sys.stdout) # hdrgo_prt", "section_prt", "top_n", "use_sections" sortobj = Sorter(grprobj, section_sortby=lambda nt: getattr(nt, self.pval_fld)) return sortobj
python
def get_sortobj(self, goea_results, **kws): nts_goea = MgrNtGOEAs(goea_results).get_goea_nts_prt(**kws) goids = set(nt.GO for nt in nts_goea) go2nt = {nt.GO:nt for nt in nts_goea} grprobj = Grouper("GOEA", goids, self.hdrobj, self.grprdflt.gosubdag, go2nt=go2nt) grprobj.prt_summary(sys.stdout) # hdrgo_prt", "section_prt", "top_n", "use_sections" sortobj = Sorter(grprobj, section_sortby=lambda nt: getattr(nt, self.pval_fld)) return sortobj
[ "def", "get_sortobj", "(", "self", ",", "goea_results", ",", "*", "*", "kws", ")", ":", "nts_goea", "=", "MgrNtGOEAs", "(", "goea_results", ")", ".", "get_goea_nts_prt", "(", "*", "*", "kws", ")", "goids", "=", "set", "(", "nt", ".", "GO", "for", "nt...
Return a Grouper object, given a list of GOEnrichmentRecord.
[ "Return", "a", "Grouper", "object", "given", "a", "list", "of", "GOEnrichmentRecord", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L375-L384
242,327
tanghaibao/goatools
goatools/cli/find_enrichment.py
GroupItems._init_objaartall
def _init_objaartall(self): """Get background database info for making ASCII art.""" kws = { 'sortgo':lambda nt: [nt.NS, nt.dcnt], # fmtgo=('{p_fdr_bh:8.2e} {GO} ' # Formatting for GO terms in grouped GO list 'fmtgo':('{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} {childcnt:3} R{reldepth:02} ' '{D1:5} {GO_name} ({study_count} study genes)\n'), # Formatting for GO terms listed under each gene 'fmtgo2':('{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} R{reldepth:02} ' '{GO_name} ({study_count} study genes)\n'), # itemid2name=ensmusg2symbol} } return AArtGeneProductSetsAll(self.grprdflt, self.hdrobj, **kws)
python
def _init_objaartall(self): kws = { 'sortgo':lambda nt: [nt.NS, nt.dcnt], # fmtgo=('{p_fdr_bh:8.2e} {GO} ' # Formatting for GO terms in grouped GO list 'fmtgo':('{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} {childcnt:3} R{reldepth:02} ' '{D1:5} {GO_name} ({study_count} study genes)\n'), # Formatting for GO terms listed under each gene 'fmtgo2':('{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} R{reldepth:02} ' '{GO_name} ({study_count} study genes)\n'), # itemid2name=ensmusg2symbol} } return AArtGeneProductSetsAll(self.grprdflt, self.hdrobj, **kws)
[ "def", "_init_objaartall", "(", "self", ")", ":", "kws", "=", "{", "'sortgo'", ":", "lambda", "nt", ":", "[", "nt", ".", "NS", ",", "nt", ".", "dcnt", "]", ",", "# fmtgo=('{p_fdr_bh:8.2e} {GO} '", "# Formatting for GO terms in grouped GO list", "'fmtgo'", ":", ...
Get background database info for making ASCII art.
[ "Get", "background", "database", "info", "for", "making", "ASCII", "art", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L392-L407
242,328
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr.wr_xlsx
def wr_xlsx(self, fout_xlsx): """Print grouped GOEA results into an xlsx file.""" objwr = WrXlsxSortedGos("GOEA", self.sortobj) #### fld2fmt['ratio_in_study'] = '{:>8}' #### fld2fmt['ratio_in_pop'] = '{:>12}' #### ntfld2wbfmtdict = { # ntfld_wbfmt = { # 'ratio_in_study': {'align':'right'}, # 'ratio_in_pop':{'align':'right'}} kws_xlsx = { 'title': self.ver_list, 'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'}, #'ntfld_wbfmt': ntfld_wbfmt, #### 'ntval2wbfmtdict': ntval2wbfmtdict, #'hdrs': [], 'prt_flds': self.flds_cur} objwr.wr_xlsx_nts(fout_xlsx, self.desc2nts, **kws_xlsx)
python
def wr_xlsx(self, fout_xlsx): objwr = WrXlsxSortedGos("GOEA", self.sortobj) #### fld2fmt['ratio_in_study'] = '{:>8}' #### fld2fmt['ratio_in_pop'] = '{:>12}' #### ntfld2wbfmtdict = { # ntfld_wbfmt = { # 'ratio_in_study': {'align':'right'}, # 'ratio_in_pop':{'align':'right'}} kws_xlsx = { 'title': self.ver_list, 'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'}, #'ntfld_wbfmt': ntfld_wbfmt, #### 'ntval2wbfmtdict': ntval2wbfmtdict, #'hdrs': [], 'prt_flds': self.flds_cur} objwr.wr_xlsx_nts(fout_xlsx, self.desc2nts, **kws_xlsx)
[ "def", "wr_xlsx", "(", "self", ",", "fout_xlsx", ")", ":", "objwr", "=", "WrXlsxSortedGos", "(", "\"GOEA\"", ",", "self", ".", "sortobj", ")", "#### fld2fmt['ratio_in_study'] = '{:>8}'", "#### fld2fmt['ratio_in_pop'] = '{:>12}'", "#### ntfld2wbfmtdict = {", "# ntfld_wbfmt =...
Print grouped GOEA results into an xlsx file.
[ "Print", "grouped", "GOEA", "results", "into", "an", "xlsx", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L432-L448
242,329
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr.wr_tsv
def wr_tsv(self, fout_tsv): """Print grouped GOEA results into a tab-separated file.""" with open(fout_tsv, 'w') as prt: kws_tsv = { 'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'}, 'prt_flds':self.flds_cur} prt_tsv_sections(prt, self.desc2nts['sections'], **kws_tsv) print(" WROTE: {TSV}".format(TSV=fout_tsv))
python
def wr_tsv(self, fout_tsv): with open(fout_tsv, 'w') as prt: kws_tsv = { 'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'}, 'prt_flds':self.flds_cur} prt_tsv_sections(prt, self.desc2nts['sections'], **kws_tsv) print(" WROTE: {TSV}".format(TSV=fout_tsv))
[ "def", "wr_tsv", "(", "self", ",", "fout_tsv", ")", ":", "with", "open", "(", "fout_tsv", ",", "'w'", ")", "as", "prt", ":", "kws_tsv", "=", "{", "'fld2fmt'", ":", "{", "f", ":", "'{:8.2e}'", "for", "f", "in", "self", ".", "flds_cur", "if", "f", ...
Print grouped GOEA results into a tab-separated file.
[ "Print", "grouped", "GOEA", "results", "into", "a", "tab", "-", "separated", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L450-L457
242,330
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr.wr_txt
def wr_txt(self, fout_txt): """Write to a file GOEA results in an ASCII text format.""" with open(fout_txt, 'w') as prt: for line in self.ver_list: prt.write("{LINE}\n".format(LINE=line)) self.prt_txt(prt) print(" WROTE: {TXT}".format(TXT=fout_txt))
python
def wr_txt(self, fout_txt): with open(fout_txt, 'w') as prt: for line in self.ver_list: prt.write("{LINE}\n".format(LINE=line)) self.prt_txt(prt) print(" WROTE: {TXT}".format(TXT=fout_txt))
[ "def", "wr_txt", "(", "self", ",", "fout_txt", ")", ":", "with", "open", "(", "fout_txt", ",", "'w'", ")", "as", "prt", ":", "for", "line", "in", "self", ".", "ver_list", ":", "prt", ".", "write", "(", "\"{LINE}\\n\"", ".", "format", "(", "LINE", "...
Write to a file GOEA results in an ASCII text format.
[ "Write", "to", "a", "file", "GOEA", "results", "in", "an", "ASCII", "text", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L459-L465
242,331
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr.prt_tsv
def prt_tsv(self, prt=sys.stdout): """Print an ASCII text format.""" prtfmt = self.objprt.get_prtfmt_str(self.flds_cur) prt.write("{FLDS}\n".format(FLDS=" ".join(self.flds_cur))) WrSectionsTxt.prt_sections(prt, self.desc2nts['sections'], prtfmt, secspc=True)
python
def prt_tsv(self, prt=sys.stdout): prtfmt = self.objprt.get_prtfmt_str(self.flds_cur) prt.write("{FLDS}\n".format(FLDS=" ".join(self.flds_cur))) WrSectionsTxt.prt_sections(prt, self.desc2nts['sections'], prtfmt, secspc=True)
[ "def", "prt_tsv", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "prtfmt", "=", "self", ".", "objprt", ".", "get_prtfmt_str", "(", "self", ".", "flds_cur", ")", "prt", ".", "write", "(", "\"{FLDS}\\n\"", ".", "format", "(", "FLDS", "="...
Print an ASCII text format.
[ "Print", "an", "ASCII", "text", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L467-L471
242,332
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr._init_flds_cur
def _init_flds_cur(self): """Choose fields to print from a multitude of available fields.""" flds = [] # ('GO', 'NS', 'enrichment', 'name', 'ratio_in_study', 'ratio_in_pop', 'depth', # 'p_uncorrected', 'p_bonferroni', 'p_sidak', 'p_holm', 'p_fdr_bh', # 'pop_n', 'pop_count', 'pop_items' # 'study_n', 'study_count', 'study_items', # 'is_ratio_different', 'level', 'is_obsolete', # 'namespace', 'reldepth', 'alt_ids', 'format_txt', 'hdr_idx', # 'is_hdrgo', 'is_usrgo', 'num_usrgos', 'hdr1usr01', 'alt', 'GO_name', # 'dcnt', 'D1', 'tcnt', 'tfreq', 'tinfo', 'childcnt', 'REL', # 'REL_short', 'rel', 'id') flds0 = ['GO', 'NS', 'enrichment', self.pval_fld, 'dcnt', 'tinfo', 'depth', 'ratio_in_study', 'ratio_in_pop', 'name'] flds_p = [f for f in self.flds_all if f[:2] == 'p_' and f != self.pval_fld] flds.extend(flds0) if flds_p: flds.extend(flds_p) flds.append('study_count') flds.append('study_items') return flds
python
def _init_flds_cur(self): flds = [] # ('GO', 'NS', 'enrichment', 'name', 'ratio_in_study', 'ratio_in_pop', 'depth', # 'p_uncorrected', 'p_bonferroni', 'p_sidak', 'p_holm', 'p_fdr_bh', # 'pop_n', 'pop_count', 'pop_items' # 'study_n', 'study_count', 'study_items', # 'is_ratio_different', 'level', 'is_obsolete', # 'namespace', 'reldepth', 'alt_ids', 'format_txt', 'hdr_idx', # 'is_hdrgo', 'is_usrgo', 'num_usrgos', 'hdr1usr01', 'alt', 'GO_name', # 'dcnt', 'D1', 'tcnt', 'tfreq', 'tinfo', 'childcnt', 'REL', # 'REL_short', 'rel', 'id') flds0 = ['GO', 'NS', 'enrichment', self.pval_fld, 'dcnt', 'tinfo', 'depth', 'ratio_in_study', 'ratio_in_pop', 'name'] flds_p = [f for f in self.flds_all if f[:2] == 'p_' and f != self.pval_fld] flds.extend(flds0) if flds_p: flds.extend(flds_p) flds.append('study_count') flds.append('study_items') return flds
[ "def", "_init_flds_cur", "(", "self", ")", ":", "flds", "=", "[", "]", "# ('GO', 'NS', 'enrichment', 'name', 'ratio_in_study', 'ratio_in_pop', 'depth',", "# 'p_uncorrected', 'p_bonferroni', 'p_sidak', 'p_holm', 'p_fdr_bh',", "# 'pop_n', 'pop_count', 'pop_items'", "# 'study_n', 'study_count...
Choose fields to print from a multitude of available fields.
[ "Choose", "fields", "to", "print", "from", "a", "multitude", "of", "available", "fields", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L479-L499
242,333
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader.do_hdr
def do_hdr(self, line, hdrs_usr): """Initialize self.h2i.""" # If there is no header hint, consider the first line the header. if self.hdr_ex is None: self._init_hdr(line, hdrs_usr) return True # If there is a header hint, examine each beginning line until header hint is found. elif self.hdr_ex in line: self._init_hdr(line, hdrs_usr) return True return False
python
def do_hdr(self, line, hdrs_usr): # If there is no header hint, consider the first line the header. if self.hdr_ex is None: self._init_hdr(line, hdrs_usr) return True # If there is a header hint, examine each beginning line until header hint is found. elif self.hdr_ex in line: self._init_hdr(line, hdrs_usr) return True return False
[ "def", "do_hdr", "(", "self", ",", "line", ",", "hdrs_usr", ")", ":", "# If there is no header hint, consider the first line the header.", "if", "self", ".", "hdr_ex", "is", "None", ":", "self", ".", "_init_hdr", "(", "line", ",", "hdrs_usr", ")", "return", "Tru...
Initialize self.h2i.
[ "Initialize", "self", ".", "h2i", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L84-L94
242,334
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader.hdr_xform
def hdr_xform(self, hdrs): """Transform NCBI Gene header fields into valid namedtuple fields.""" xform = [] hdrs = self.replace_nulls(hdrs) for hdr in hdrs: hdr = hdr.replace('.', '_') hdr = hdr.replace(' ', '_') hdr = hdr.replace('#', 'N') hdr = hdr.replace('-', '_') hdr = hdr.replace('"', '') xform.append(hdr) return xform
python
def hdr_xform(self, hdrs): xform = [] hdrs = self.replace_nulls(hdrs) for hdr in hdrs: hdr = hdr.replace('.', '_') hdr = hdr.replace(' ', '_') hdr = hdr.replace('#', 'N') hdr = hdr.replace('-', '_') hdr = hdr.replace('"', '') xform.append(hdr) return xform
[ "def", "hdr_xform", "(", "self", ",", "hdrs", ")", ":", "xform", "=", "[", "]", "hdrs", "=", "self", ".", "replace_nulls", "(", "hdrs", ")", "for", "hdr", "in", "hdrs", ":", "hdr", "=", "hdr", ".", "replace", "(", "'.'", ",", "'_'", ")", "hdr", ...
Transform NCBI Gene header fields into valid namedtuple fields.
[ "Transform", "NCBI", "Gene", "header", "fields", "into", "valid", "namedtuple", "fields", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L146-L157
242,335
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_nt_hdr
def _init_nt_hdr(self, line): """Convert headers into valid namedtuple fields.""" line = line.replace('.', '_') line = line.replace(' ', '_') line = line.replace('#', 'N') line = line.replace('-', '_') line = line.replace('"', '') #line = re.sub(r"_$", r"", line) hdrs = re.split(self.sep, line) if '' in hdrs: hdrs = NCBIgeneFileReader.replace_nulls(hdrs) # Init indexes which will be converted to int or float self.idxs_int = [idx for idx, hdr in enumerate(hdrs) if hdr in self.int_hdrs] self.idxs_float = [idx for idx, hdr in enumerate(hdrs) if hdr in self.float_hdrs] assert hdrs[6] == 'Aliases' return namedtuple('ntncbi', ' '.join(hdrs))
python
def _init_nt_hdr(self, line): line = line.replace('.', '_') line = line.replace(' ', '_') line = line.replace('#', 'N') line = line.replace('-', '_') line = line.replace('"', '') #line = re.sub(r"_$", r"", line) hdrs = re.split(self.sep, line) if '' in hdrs: hdrs = NCBIgeneFileReader.replace_nulls(hdrs) # Init indexes which will be converted to int or float self.idxs_int = [idx for idx, hdr in enumerate(hdrs) if hdr in self.int_hdrs] self.idxs_float = [idx for idx, hdr in enumerate(hdrs) if hdr in self.float_hdrs] assert hdrs[6] == 'Aliases' return namedtuple('ntncbi', ' '.join(hdrs))
[ "def", "_init_nt_hdr", "(", "self", ",", "line", ")", ":", "line", "=", "line", ".", "replace", "(", "'.'", ",", "'_'", ")", "line", "=", "line", ".", "replace", "(", "' '", ",", "'_'", ")", "line", "=", "line", ".", "replace", "(", "'#'", ",", ...
Convert headers into valid namedtuple fields.
[ "Convert", "headers", "into", "valid", "namedtuple", "fields", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L159-L174
242,336
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader.replace_nulls
def replace_nulls(hdrs): """Replace '' in hdrs.""" ret = [] idx = 0 for hdr in hdrs: if hdr == '': ret.append("no_hdr{}".format(idx)) else: ret.append(hdr) return ret
python
def replace_nulls(hdrs): ret = [] idx = 0 for hdr in hdrs: if hdr == '': ret.append("no_hdr{}".format(idx)) else: ret.append(hdr) return ret
[ "def", "replace_nulls", "(", "hdrs", ")", ":", "ret", "=", "[", "]", "idx", "=", "0", "for", "hdr", "in", "hdrs", ":", "if", "hdr", "==", "''", ":", "ret", ".", "append", "(", "\"no_hdr{}\"", ".", "format", "(", "idx", ")", ")", "else", ":", "r...
Replace '' in hdrs.
[ "Replace", "in", "hdrs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L187-L196
242,337
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_data_line
def _init_data_line(self, fnc, lnum, line): """Process Data line.""" fld = re.split(self.sep, line) # Lines may contain different numbers of items. # The line should have all columns requested by the user. if self.usr_max_idx < len(fld): self.convert_ints_floats(fld) fnc(fld) else: for fld in enumerate(zip(self.hdr2idx.keys(), fld)): print(fld) for hdr in self.hdrs_usr: print(hdr) print('# ITEMS ON A LINE:', len(fld)) print('MAX USR IDX:', self.usr_max_idx) raise Exception("ERROR ON LINE {} IN {}".format(lnum+1, self.fin))
python
def _init_data_line(self, fnc, lnum, line): fld = re.split(self.sep, line) # Lines may contain different numbers of items. # The line should have all columns requested by the user. if self.usr_max_idx < len(fld): self.convert_ints_floats(fld) fnc(fld) else: for fld in enumerate(zip(self.hdr2idx.keys(), fld)): print(fld) for hdr in self.hdrs_usr: print(hdr) print('# ITEMS ON A LINE:', len(fld)) print('MAX USR IDX:', self.usr_max_idx) raise Exception("ERROR ON LINE {} IN {}".format(lnum+1, self.fin))
[ "def", "_init_data_line", "(", "self", ",", "fnc", ",", "lnum", ",", "line", ")", ":", "fld", "=", "re", ".", "split", "(", "self", ".", "sep", ",", "line", ")", "# Lines may contain different numbers of items.", "# The line should have all columns requested by the ...
Process Data line.
[ "Process", "Data", "line", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L198-L213
242,338
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader.convert_ints_floats
def convert_ints_floats(self, flds): """Convert strings to ints and floats, if so specified.""" for idx in self.idxs_float: flds[idx] = float(flds[idx]) for idx in self.idxs_int: dig = flds[idx] #print 'idx={} ({}) {}'.format(idx, flds[idx], flds) # DVK flds[idx] = int(flds[idx]) if dig.isdigit() else dig for idx in self.idxs_strpat: hdr = self.hdr2idx.items()[idx][0] pat = self.strpat_hdrs[hdr] flds[idx] = pat.format(flds[idx])
python
def convert_ints_floats(self, flds): for idx in self.idxs_float: flds[idx] = float(flds[idx]) for idx in self.idxs_int: dig = flds[idx] #print 'idx={} ({}) {}'.format(idx, flds[idx], flds) # DVK flds[idx] = int(flds[idx]) if dig.isdigit() else dig for idx in self.idxs_strpat: hdr = self.hdr2idx.items()[idx][0] pat = self.strpat_hdrs[hdr] flds[idx] = pat.format(flds[idx])
[ "def", "convert_ints_floats", "(", "self", ",", "flds", ")", ":", "for", "idx", "in", "self", ".", "idxs_float", ":", "flds", "[", "idx", "]", "=", "float", "(", "flds", "[", "idx", "]", ")", "for", "idx", "in", "self", ".", "idxs_int", ":", "dig",...
Convert strings to ints and floats, if so specified.
[ "Convert", "strings", "to", "ints", "and", "floats", "if", "so", "specified", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L215-L226
242,339
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_hdr
def _init_hdr(self, line, hdrs_usr): """Initialize self.hdr2idx, self.len, self.idxs_float, and self.idxs_int""" self.hdr2idx = OrderedDict([(v.strip(), i) for i, v in enumerate(re.split(self.sep, line))]) self.len = len(self.hdr2idx) # If user is requesting specific data fields... if hdrs_usr is not None: # Loop through the user headers for usr_hdr in hdrs_usr: # If the user header is contained in the file.... if usr_hdr in self.hdr2idx: # Add the user header and the field index to a list self.hdrs_usr.append([usr_hdr, self.hdr2idx[usr_hdr]]) else: raise Exception("NO COLUMN({}) FOUND:\n HDR={}\n".format( hdrs_usr, '\n HDR='.join(self.hdr2idx.keys()))) usr_hdrs = [E[0] for E in self.hdrs_usr] if self.hdrs_usr else self.hdr2idx self._init_idxs_float(usr_hdrs) self._init_idxs_int(usr_hdrs) self._init_idxs_strpat(usr_hdrs) self.usr_max_idx = max(E[1] for E in self.hdrs_usr) if self.hdrs_usr else len(self.hdr2idx)-1
python
def _init_hdr(self, line, hdrs_usr): self.hdr2idx = OrderedDict([(v.strip(), i) for i, v in enumerate(re.split(self.sep, line))]) self.len = len(self.hdr2idx) # If user is requesting specific data fields... if hdrs_usr is not None: # Loop through the user headers for usr_hdr in hdrs_usr: # If the user header is contained in the file.... if usr_hdr in self.hdr2idx: # Add the user header and the field index to a list self.hdrs_usr.append([usr_hdr, self.hdr2idx[usr_hdr]]) else: raise Exception("NO COLUMN({}) FOUND:\n HDR={}\n".format( hdrs_usr, '\n HDR='.join(self.hdr2idx.keys()))) usr_hdrs = [E[0] for E in self.hdrs_usr] if self.hdrs_usr else self.hdr2idx self._init_idxs_float(usr_hdrs) self._init_idxs_int(usr_hdrs) self._init_idxs_strpat(usr_hdrs) self.usr_max_idx = max(E[1] for E in self.hdrs_usr) if self.hdrs_usr else len(self.hdr2idx)-1
[ "def", "_init_hdr", "(", "self", ",", "line", ",", "hdrs_usr", ")", ":", "self", ".", "hdr2idx", "=", "OrderedDict", "(", "[", "(", "v", ".", "strip", "(", ")", ",", "i", ")", "for", "i", ",", "v", "in", "enumerate", "(", "re", ".", "split", "(...
Initialize self.hdr2idx, self.len, self.idxs_float, and self.idxs_int
[ "Initialize", "self", ".", "hdr2idx", "self", ".", "len", "self", ".", "idxs_float", "and", "self", ".", "idxs_int" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L228-L247
242,340
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_idxs_float
def _init_idxs_float(self, usr_hdrs): """List of indexes whose values will be floats.""" self.idxs_float = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.float_hdrs]
python
def _init_idxs_float(self, usr_hdrs): self.idxs_float = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.float_hdrs]
[ "def", "_init_idxs_float", "(", "self", ",", "usr_hdrs", ")", ":", "self", ".", "idxs_float", "=", "[", "Idx", "for", "Hdr", ",", "Idx", "in", "self", ".", "hdr2idx", ".", "items", "(", ")", "if", "Hdr", "in", "usr_hdrs", "and", "Hdr", "in", "self", ...
List of indexes whose values will be floats.
[ "List", "of", "indexes", "whose", "values", "will", "be", "floats", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L249-L252
242,341
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_idxs_int
def _init_idxs_int(self, usr_hdrs): """List of indexes whose values will be ints.""" self.idxs_int = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.int_hdrs]
python
def _init_idxs_int(self, usr_hdrs): self.idxs_int = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.int_hdrs]
[ "def", "_init_idxs_int", "(", "self", ",", "usr_hdrs", ")", ":", "self", ".", "idxs_int", "=", "[", "Idx", "for", "Hdr", ",", "Idx", "in", "self", ".", "hdr2idx", ".", "items", "(", ")", "if", "Hdr", "in", "usr_hdrs", "and", "Hdr", "in", "self", "....
List of indexes whose values will be ints.
[ "List", "of", "indexes", "whose", "values", "will", "be", "ints", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L254-L257
242,342
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_idxs_strpat
def _init_idxs_strpat(self, usr_hdrs): """List of indexes whose values will be strings.""" strpat = self.strpat_hdrs.keys() self.idxs_strpat = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in strpat]
python
def _init_idxs_strpat(self, usr_hdrs): strpat = self.strpat_hdrs.keys() self.idxs_strpat = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in strpat]
[ "def", "_init_idxs_strpat", "(", "self", ",", "usr_hdrs", ")", ":", "strpat", "=", "self", ".", "strpat_hdrs", ".", "keys", "(", ")", "self", ".", "idxs_strpat", "=", "[", "Idx", "for", "Hdr", ",", "Idx", "in", "self", ".", "hdr2idx", ".", "items", "...
List of indexes whose values will be strings.
[ "List", "of", "indexes", "whose", "values", "will", "be", "strings", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L259-L263
242,343
tanghaibao/goatools
goatools/cli/ncbi_gene_results_to_python.py
NCBIgeneToPythonCli._get_geneid2nt
def _get_geneid2nt(nts): """Get geneid2nt given a list of namedtuples.""" geneid2nt = {} for ntd in nts: geneid = ntd.GeneID if geneid not in geneid2nt: geneid2nt[geneid] = ntd else: print("DUPLICATE GeneID FOUND {N:9} {SYM}".format(N=geneid, SYM=ntd.Symbol)) return geneid2nt
python
def _get_geneid2nt(nts): geneid2nt = {} for ntd in nts: geneid = ntd.GeneID if geneid not in geneid2nt: geneid2nt[geneid] = ntd else: print("DUPLICATE GeneID FOUND {N:9} {SYM}".format(N=geneid, SYM=ntd.Symbol)) return geneid2nt
[ "def", "_get_geneid2nt", "(", "nts", ")", ":", "geneid2nt", "=", "{", "}", "for", "ntd", "in", "nts", ":", "geneid", "=", "ntd", ".", "GeneID", "if", "geneid", "not", "in", "geneid2nt", ":", "geneid2nt", "[", "geneid", "]", "=", "ntd", "else", ":", ...
Get geneid2nt given a list of namedtuples.
[ "Get", "geneid2nt", "given", "a", "list", "of", "namedtuples", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/ncbi_gene_results_to_python.py#L50-L59
242,344
tanghaibao/goatools
goatools/cli/ncbi_gene_results_to_python.py
NCBIgeneToPythonCli._wrpy_ncbi_gene_nts
def _wrpy_ncbi_gene_nts(fout_py, geneid2nt, log): """Write namedtuples to a dict in a Python module.""" num_genes = len(geneid2nt) with open(fout_py, 'w') as ofstrm: docstr = "Data downloaded from NCBI Gene converted into Python namedtuples." ofstrm.write('"""{PYDOC}"""\n\n'.format(PYDOC=docstr)) ofstrm.write("from collections import namedtuple\n\n") ofstrm.write('WRITTEN = "{DATE}"'.format( DATE=re.sub('-', '_', str(datetime.date.today())))) ofstrm.write(' # {N} items\n\n'.format(N=num_genes)) ntd = next(iter(geneid2nt.values())) # Access one dictionary value in Python 2 ofstrm.write("#pylint: disable=line-too-long,too-many-lines,invalid-name\n") ofstrm.write("{NtName} = namedtuple('{NtName}', '{FLDS}')\n\n".format( NtName=type(ntd).__name__, FLDS=' '.join(ntd._fields))) ofstrm.write("GENEID2NT = {{ # {N:,} items\n".format(N=num_genes)) for geneid, ntd in sorted(geneid2nt.items(), key=lambda t: t[0]): ofstrm.write(" {GeneID} : {NT},\n".format(GeneID=geneid, NT=ntd)) ofstrm.write("}\n") log.write(" {N:9} geneids WROTE: {PY}\n".format(N=num_genes, PY=fout_py))
python
def _wrpy_ncbi_gene_nts(fout_py, geneid2nt, log): num_genes = len(geneid2nt) with open(fout_py, 'w') as ofstrm: docstr = "Data downloaded from NCBI Gene converted into Python namedtuples." ofstrm.write('"""{PYDOC}"""\n\n'.format(PYDOC=docstr)) ofstrm.write("from collections import namedtuple\n\n") ofstrm.write('WRITTEN = "{DATE}"'.format( DATE=re.sub('-', '_', str(datetime.date.today())))) ofstrm.write(' # {N} items\n\n'.format(N=num_genes)) ntd = next(iter(geneid2nt.values())) # Access one dictionary value in Python 2 ofstrm.write("#pylint: disable=line-too-long,too-many-lines,invalid-name\n") ofstrm.write("{NtName} = namedtuple('{NtName}', '{FLDS}')\n\n".format( NtName=type(ntd).__name__, FLDS=' '.join(ntd._fields))) ofstrm.write("GENEID2NT = {{ # {N:,} items\n".format(N=num_genes)) for geneid, ntd in sorted(geneid2nt.items(), key=lambda t: t[0]): ofstrm.write(" {GeneID} : {NT},\n".format(GeneID=geneid, NT=ntd)) ofstrm.write("}\n") log.write(" {N:9} geneids WROTE: {PY}\n".format(N=num_genes, PY=fout_py))
[ "def", "_wrpy_ncbi_gene_nts", "(", "fout_py", ",", "geneid2nt", ",", "log", ")", ":", "num_genes", "=", "len", "(", "geneid2nt", ")", "with", "open", "(", "fout_py", ",", "'w'", ")", "as", "ofstrm", ":", "docstr", "=", "\"Data downloaded from NCBI Gene convert...
Write namedtuples to a dict in a Python module.
[ "Write", "namedtuples", "to", "a", "dict", "in", "a", "Python", "module", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/ncbi_gene_results_to_python.py#L62-L80
242,345
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
get_goobjs_altgo2goobj
def get_goobjs_altgo2goobj(go2obj): """Separate alt GO IDs and key GO IDs.""" goobjs = set() altgo2goobj = {} for goid, goobj in go2obj.items(): goobjs.add(goobj) if goid != goobj.id: altgo2goobj[goid] = goobj return goobjs, altgo2goobj
python
def get_goobjs_altgo2goobj(go2obj): goobjs = set() altgo2goobj = {} for goid, goobj in go2obj.items(): goobjs.add(goobj) if goid != goobj.id: altgo2goobj[goid] = goobj return goobjs, altgo2goobj
[ "def", "get_goobjs_altgo2goobj", "(", "go2obj", ")", ":", "goobjs", "=", "set", "(", ")", "altgo2goobj", "=", "{", "}", "for", "goid", ",", "goobj", "in", "go2obj", ".", "items", "(", ")", ":", "goobjs", ".", "add", "(", "goobj", ")", "if", "goid", ...
Separate alt GO IDs and key GO IDs.
[ "Separate", "alt", "GO", "IDs", "and", "key", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L99-L107
242,346
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
add_alt_goids
def add_alt_goids(go2values, altgo2goobj): """Add alternate source GO IDs.""" for goobj_key in altgo2goobj.values(): values_curr = go2values[goobj_key.id] for goid_alt in goobj_key.alt_ids: go2values[goid_alt] = values_curr return go2values
python
def add_alt_goids(go2values, altgo2goobj): for goobj_key in altgo2goobj.values(): values_curr = go2values[goobj_key.id] for goid_alt in goobj_key.alt_ids: go2values[goid_alt] = values_curr return go2values
[ "def", "add_alt_goids", "(", "go2values", ",", "altgo2goobj", ")", ":", "for", "goobj_key", "in", "altgo2goobj", ".", "values", "(", ")", ":", "values_curr", "=", "go2values", "[", "goobj_key", ".", "id", "]", "for", "goid_alt", "in", "goobj_key", ".", "al...
Add alternate source GO IDs.
[ "Add", "alternate", "source", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L109-L115
242,347
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
fill_main_goids
def fill_main_goids(go2obj, goids): """Ensure main GO IDs are included in go2obj.""" # User GO IDs (goids) may be either main GO IDs or alternate GO IDs. for goid in goids: goobj = go2obj[goid] # If a user specified an ALT GO ID and main GO ID not in go2obj: if goid != goobj.id and goobj.id not in go2obj: # Add main GO ID to go2obj go2obj[goobj.id] = goobj
python
def fill_main_goids(go2obj, goids): # User GO IDs (goids) may be either main GO IDs or alternate GO IDs. for goid in goids: goobj = go2obj[goid] # If a user specified an ALT GO ID and main GO ID not in go2obj: if goid != goobj.id and goobj.id not in go2obj: # Add main GO ID to go2obj go2obj[goobj.id] = goobj
[ "def", "fill_main_goids", "(", "go2obj", ",", "goids", ")", ":", "# User GO IDs (goids) may be either main GO IDs or alternate GO IDs.", "for", "goid", "in", "goids", ":", "goobj", "=", "go2obj", "[", "goid", "]", "# If a user specified an ALT GO ID and main GO ID not in go2o...
Ensure main GO IDs are included in go2obj.
[ "Ensure", "main", "GO", "IDs", "are", "included", "in", "go2obj", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L118-L126
242,348
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
fill_altgoids
def fill_altgoids(go2obj): """Given a go2obj containing key GO IDs, fill with all alternate GO IDs.""" alt2obj = {altgo:goobj for goobj in go2obj.values() for altgo in goobj.alt_ids} for goid, goobj in alt2obj.items(): go2obj[goid] = goobj
python
def fill_altgoids(go2obj): alt2obj = {altgo:goobj for goobj in go2obj.values() for altgo in goobj.alt_ids} for goid, goobj in alt2obj.items(): go2obj[goid] = goobj
[ "def", "fill_altgoids", "(", "go2obj", ")", ":", "alt2obj", "=", "{", "altgo", ":", "goobj", "for", "goobj", "in", "go2obj", ".", "values", "(", ")", "for", "altgo", "in", "goobj", ".", "alt_ids", "}", "for", "goid", ",", "goobj", "in", "alt2obj", "....
Given a go2obj containing key GO IDs, fill with all alternate GO IDs.
[ "Given", "a", "go2obj", "containing", "key", "GO", "IDs", "fill", "with", "all", "alternate", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L128-L132
242,349
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
fill_relationshipobjs
def fill_relationshipobjs(go2obj, relationships): """Add GO IDs to go2obj that are involved in relationships.""" # Get all GO Term record objects that have relationships obj = RelationshipFill(go2obj, relationships) for goobj in go2obj.values(): if goobj.relationship: obj.fill_relationshipgo2obj(goobj) if goobj.relationship_rev: obj.fill_relationshiprevgo2obj(goobj)
python
def fill_relationshipobjs(go2obj, relationships): # Get all GO Term record objects that have relationships obj = RelationshipFill(go2obj, relationships) for goobj in go2obj.values(): if goobj.relationship: obj.fill_relationshipgo2obj(goobj) if goobj.relationship_rev: obj.fill_relationshiprevgo2obj(goobj)
[ "def", "fill_relationshipobjs", "(", "go2obj", ",", "relationships", ")", ":", "# Get all GO Term record objects that have relationships", "obj", "=", "RelationshipFill", "(", "go2obj", ",", "relationships", ")", "for", "goobj", "in", "go2obj", ".", "values", "(", ")"...
Add GO IDs to go2obj that are involved in relationships.
[ "Add", "GO", "IDs", "to", "go2obj", "that", "are", "involved", "in", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L135-L143
242,350
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
fill_childgoid2obj
def fill_childgoid2obj(childgoid2obj, parent_obj): """Fill childgoid2obj with all child key GO IDs and their objects.""" for child_obj in parent_obj.children: if child_obj.id not in childgoid2obj: childgoid2obj[child_obj.id] = child_obj fill_childgoid2obj(childgoid2obj, child_obj)
python
def fill_childgoid2obj(childgoid2obj, parent_obj): for child_obj in parent_obj.children: if child_obj.id not in childgoid2obj: childgoid2obj[child_obj.id] = child_obj fill_childgoid2obj(childgoid2obj, child_obj)
[ "def", "fill_childgoid2obj", "(", "childgoid2obj", ",", "parent_obj", ")", ":", "for", "child_obj", "in", "parent_obj", ".", "children", ":", "if", "child_obj", ".", "id", "not", "in", "childgoid2obj", ":", "childgoid2obj", "[", "child_obj", ".", "id", "]", ...
Fill childgoid2obj with all child key GO IDs and their objects.
[ "Fill", "childgoid2obj", "with", "all", "child", "key", "GO", "IDs", "and", "their", "objects", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L180-L185
242,351
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
get_leaf_children
def get_leaf_children(gos_user, go2obj_arg): """Find all the GO descendants under all user GO IDs. Return leaf-level GO IDs.""" childgoid2obj = {} for goid_usr in gos_user: goobj_usr = go2obj_arg[goid_usr] fill_childgoid2obj(childgoid2obj, goobj_usr) return set(go for go, o in childgoid2obj.items() if not o.children)
python
def get_leaf_children(gos_user, go2obj_arg): childgoid2obj = {} for goid_usr in gos_user: goobj_usr = go2obj_arg[goid_usr] fill_childgoid2obj(childgoid2obj, goobj_usr) return set(go for go, o in childgoid2obj.items() if not o.children)
[ "def", "get_leaf_children", "(", "gos_user", ",", "go2obj_arg", ")", ":", "childgoid2obj", "=", "{", "}", "for", "goid_usr", "in", "gos_user", ":", "goobj_usr", "=", "go2obj_arg", "[", "goid_usr", "]", "fill_childgoid2obj", "(", "childgoid2obj", ",", "goobj_usr"...
Find all the GO descendants under all user GO IDs. Return leaf-level GO IDs.
[ "Find", "all", "the", "GO", "descendants", "under", "all", "user", "GO", "IDs", ".", "Return", "leaf", "-", "level", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L188-L194
242,352
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
chk_goids
def chk_goids(goids, msg=None, raise_except=True): """check that all GO IDs have the proper format.""" for goid in goids: if not goid_is_valid(goid): if raise_except: raise RuntimeError("BAD GO({GO}): {MSG}".format(GO=goid, MSG=msg)) else: return goid
python
def chk_goids(goids, msg=None, raise_except=True): for goid in goids: if not goid_is_valid(goid): if raise_except: raise RuntimeError("BAD GO({GO}): {MSG}".format(GO=goid, MSG=msg)) else: return goid
[ "def", "chk_goids", "(", "goids", ",", "msg", "=", "None", ",", "raise_except", "=", "True", ")", ":", "for", "goid", "in", "goids", ":", "if", "not", "goid_is_valid", "(", "goid", ")", ":", "if", "raise_except", ":", "raise", "RuntimeError", "(", "\"B...
check that all GO IDs have the proper format.
[ "check", "that", "all", "GO", "IDs", "have", "the", "proper", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L208-L215
242,353
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
TopologicalSortRelationships._get_sorted_relationships
def _get_sorted_relationships(self, goterm): """Traverse GO Terms above the current GO Term. Then add current GO Term to sorted.""" if goterm.id in self.goids_seen: return self.goids_seen.add(goterm.id) for goterm_upper in goterm.get_goterms_upper(): self._get_sorted_relationships(goterm_upper) self.goterms_sorted.append(goterm)
python
def _get_sorted_relationships(self, goterm): if goterm.id in self.goids_seen: return self.goids_seen.add(goterm.id) for goterm_upper in goterm.get_goterms_upper(): self._get_sorted_relationships(goterm_upper) self.goterms_sorted.append(goterm)
[ "def", "_get_sorted_relationships", "(", "self", ",", "goterm", ")", ":", "if", "goterm", ".", "id", "in", "self", ".", "goids_seen", ":", "return", "self", ".", "goids_seen", ".", "add", "(", "goterm", ".", "id", ")", "for", "goterm_upper", "in", "goter...
Traverse GO Terms above the current GO Term. Then add current GO Term to sorted.
[ "Traverse", "GO", "Terms", "above", "the", "current", "GO", "Term", ".", "Then", "add", "current", "GO", "Term", "to", "sorted", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L32-L39
242,354
tanghaibao/goatools
goatools/grouper/read_goids.py
read_sections
def read_sections(sections_file, exclude_ungrouped=False, prt=sys.stdout): """Get sections and GO grouping hdrgos from file, if sections exist.""" 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))
python
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))
[ "def", "read_sections", "(", "sections_file", ",", "exclude_ungrouped", "=", "False", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "if", "sections_file", "is", "None", ":", "return", "None", "assert", "isinstance", "(", "sections_file", ",", "str", ")", ...
Get sections and GO grouping hdrgos from file, if sections exist.
[ "Get", "sections", "and", "GO", "grouping", "hdrgos", "from", "file", "if", "sections", "exist", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L19-L40
242,355
tanghaibao/goatools
goatools/grouper/read_goids.py
ReadGoids.read_py
def read_py(self, fin_txt, get_goids_only, exclude_ungrouped, prt=sys.stdout): """Read GO IDs or sections data from a Python file.""" goids_fin = self._read_py(fin_txt, get_goids_only, exclude_ungrouped) sections = self._read_finish(goids_fin, prt) # Print summary of GO IDs read if prt is not None: self._prt_read_msg(prt, fin_txt, exclude_ungrouped) return sections
python
def read_py(self, fin_txt, get_goids_only, exclude_ungrouped, prt=sys.stdout): goids_fin = self._read_py(fin_txt, get_goids_only, exclude_ungrouped) sections = self._read_finish(goids_fin, prt) # Print summary of GO IDs read if prt is not None: self._prt_read_msg(prt, fin_txt, exclude_ungrouped) return sections
[ "def", "read_py", "(", "self", ",", "fin_txt", ",", "get_goids_only", ",", "exclude_ungrouped", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "goids_fin", "=", "self", ".", "_read_py", "(", "fin_txt", ",", "get_goids_only", ",", "exclude_ungrouped", ")", ...
Read GO IDs or sections data from a Python file.
[ "Read", "GO", "IDs", "or", "sections", "data", "from", "a", "Python", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L74-L81
242,356
tanghaibao/goatools
goatools/grouper/read_goids.py
ReadGoids.read_sections
def read_sections(self, sections_file, get_goids_only, exclude_ungrouped): """Read sections variable from a text file of from a Python file.""" 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)
python
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)
[ "def", "read_sections", "(", "self", ",", "sections_file", ",", "get_goids_only", ",", "exclude_ungrouped", ")", ":", "ext", "=", "os", ".", "path", ".", "splitext", "(", "sections_file", ")", "[", "1", "]", "file_contents", "=", "None", "if", "ext", "==",...
Read sections variable from a text file of from a Python file.
[ "Read", "sections", "variable", "from", "a", "text", "file", "of", "from", "a", "Python", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L83-L92
242,357
tanghaibao/goatools
goatools/grouper/read_goids.py
ReadGoids._rpt_unused_sections
def _rpt_unused_sections(self, prt): """Report unused sections.""" sections_unused = set(self.sections_seen).difference(self.section2goids.keys()) for sec in sections_unused: prt.write(" UNUSED SECTION: {SEC}\n".format(SEC=sec))
python
def _rpt_unused_sections(self, prt): sections_unused = set(self.sections_seen).difference(self.section2goids.keys()) for sec in sections_unused: prt.write(" UNUSED SECTION: {SEC}\n".format(SEC=sec))
[ "def", "_rpt_unused_sections", "(", "self", ",", "prt", ")", ":", "sections_unused", "=", "set", "(", "self", ".", "sections_seen", ")", ".", "difference", "(", "self", ".", "section2goids", ".", "keys", "(", ")", ")", "for", "sec", "in", "sections_unused"...
Report unused sections.
[ "Report", "unused", "sections", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L161-L165
242,358
tanghaibao/goatools
goatools/grouper/read_goids.py
ReadGoids._prt_read_msg
def _prt_read_msg(self, prt, fin_txt, exclude_ungrouped): """Print which file was read and the number of GO IDs found.""" 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))
python
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))
[ "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", "=", "Su...
Print which file was read and the number of GO IDs found.
[ "Print", "which", "file", "was", "read", "and", "the", "number", "of", "GO", "IDs", "found", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L182-L191
242,359
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.rm_gos
def rm_gos(self, rm_goids): """Remove any edges that contain user-specified edges.""" self.edges = self._rm_gos_edges(rm_goids, self.edges) self.edges_rel = self._rm_gos_edges_rel(rm_goids, self.edges_rel)
python
def rm_gos(self, rm_goids): self.edges = self._rm_gos_edges(rm_goids, self.edges) self.edges_rel = self._rm_gos_edges_rel(rm_goids, self.edges_rel)
[ "def", "rm_gos", "(", "self", ",", "rm_goids", ")", ":", "self", ".", "edges", "=", "self", ".", "_rm_gos_edges", "(", "rm_goids", ",", "self", ".", "edges", ")", "self", ".", "edges_rel", "=", "self", ".", "_rm_gos_edges_rel", "(", "rm_goids", ",", "s...
Remove any edges that contain user-specified edges.
[ "Remove", "any", "edges", "that", "contain", "user", "-", "specified", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L64-L67
242,360
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase._rm_gos_edges_rel
def _rm_gos_edges_rel(self, rm_goids, edges_rel): """Remove any relationship that contain user-specified edges.""" edges_ret = {} for rname, edges_cur in edges_rel.items(): edges_new = self._rm_gos_edges(rm_goids, edges_cur) if edges_new: edges_ret[rname] = edges_new return edges_ret
python
def _rm_gos_edges_rel(self, rm_goids, edges_rel): edges_ret = {} for rname, edges_cur in edges_rel.items(): edges_new = self._rm_gos_edges(rm_goids, edges_cur) if edges_new: edges_ret[rname] = edges_new return edges_ret
[ "def", "_rm_gos_edges_rel", "(", "self", ",", "rm_goids", ",", "edges_rel", ")", ":", "edges_ret", "=", "{", "}", "for", "rname", ",", "edges_cur", "in", "edges_rel", ".", "items", "(", ")", ":", "edges_new", "=", "self", ".", "_rm_gos_edges", "(", "rm_g...
Remove any relationship that contain user-specified edges.
[ "Remove", "any", "relationship", "that", "contain", "user", "-", "specified", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L69-L76
242,361
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase._rm_gos_edges
def _rm_gos_edges(rm_goids, edges_all): """Remove any is_a edges that contain user-specified edges.""" edges_reduced = [] for goid_child, goid_parent in sorted(edges_all, key=lambda t: t[1]): if goid_child not in rm_goids and goid_parent not in rm_goids: edges_reduced.append((goid_child, goid_parent)) return edges_reduced
python
def _rm_gos_edges(rm_goids, edges_all): edges_reduced = [] for goid_child, goid_parent in sorted(edges_all, key=lambda t: t[1]): if goid_child not in rm_goids and goid_parent not in rm_goids: edges_reduced.append((goid_child, goid_parent)) return edges_reduced
[ "def", "_rm_gos_edges", "(", "rm_goids", ",", "edges_all", ")", ":", "edges_reduced", "=", "[", "]", "for", "goid_child", ",", "goid_parent", "in", "sorted", "(", "edges_all", ",", "key", "=", "lambda", "t", ":", "t", "[", "1", "]", ")", ":", "if", "...
Remove any is_a edges that contain user-specified edges.
[ "Remove", "any", "is_a", "edges", "that", "contain", "user", "-", "specified", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L79-L85
242,362
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.get_all_edge_nodes
def get_all_edge_nodes(self): """Return a list of all GO IDs that are connected to edges.""" edge_nodes = set(e for es in self.edges for e in es) for edges in self.edges_rel.values(): rel_nodes = set(e for es in edges for e in es) edge_nodes.update(rel_nodes) return edge_nodes
python
def get_all_edge_nodes(self): edge_nodes = set(e for es in self.edges for e in es) for edges in self.edges_rel.values(): rel_nodes = set(e for es in edges for e in es) edge_nodes.update(rel_nodes) return edge_nodes
[ "def", "get_all_edge_nodes", "(", "self", ")", ":", "edge_nodes", "=", "set", "(", "e", "for", "es", "in", "self", ".", "edges", "for", "e", "in", "es", ")", "for", "edges", "in", "self", ".", "edges_rel", ".", "values", "(", ")", ":", "rel_nodes", ...
Return a list of all GO IDs that are connected to edges.
[ "Return", "a", "list", "of", "all", "GO", "IDs", "that", "are", "connected", "to", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L87-L93
242,363
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.chk_edges
def chk_edges(self): """Check that all edge nodes exist in local subset.""" goids = set(self.go2obj) self.chk_edges_nodes(self.edges, goids, "is_a") for reltype, edges in self.edges_rel.items(): self.chk_edges_nodes(edges, goids, reltype)
python
def chk_edges(self): goids = set(self.go2obj) self.chk_edges_nodes(self.edges, goids, "is_a") for reltype, edges in self.edges_rel.items(): self.chk_edges_nodes(edges, goids, reltype)
[ "def", "chk_edges", "(", "self", ")", ":", "goids", "=", "set", "(", "self", ".", "go2obj", ")", "self", ".", "chk_edges_nodes", "(", "self", ".", "edges", ",", "goids", ",", "\"is_a\"", ")", "for", "reltype", ",", "edges", "in", "self", ".", "edges_...
Check that all edge nodes exist in local subset.
[ "Check", "that", "all", "edge", "nodes", "exist", "in", "local", "subset", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L95-L100
242,364
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.chk_edges_nodes
def chk_edges_nodes(edges, nodes, name): """Check that user specified edges have a node which exists.""" edge_nodes = set(e for es in edges for e in es) missing_nodes = edge_nodes.difference(nodes) assert not missing_nodes, "MISSING: {GOs}\n{NM} EDGES MISSING {N} NODES (OF {T})".format( NM=name, N=len(missing_nodes), T=len(edge_nodes), GOs=missing_nodes)
python
def chk_edges_nodes(edges, nodes, name): edge_nodes = set(e for es in edges for e in es) missing_nodes = edge_nodes.difference(nodes) assert not missing_nodes, "MISSING: {GOs}\n{NM} EDGES MISSING {N} NODES (OF {T})".format( NM=name, N=len(missing_nodes), T=len(edge_nodes), GOs=missing_nodes)
[ "def", "chk_edges_nodes", "(", "edges", ",", "nodes", ",", "name", ")", ":", "edge_nodes", "=", "set", "(", "e", "for", "es", "in", "edges", "for", "e", "in", "es", ")", "missing_nodes", "=", "edge_nodes", ".", "difference", "(", "nodes", ")", "assert"...
Check that user specified edges have a node which exists.
[ "Check", "that", "user", "specified", "edges", "have", "a", "node", "which", "exists", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L103-L108
242,365
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.get_c2ps
def get_c2ps(self): """Set child2parents dict for all parents used in this set of edges.""" c2ps = defaultdict(set) for goid_child, goid_parent in self.edges: c2ps[goid_child].add(goid_parent) return c2ps
python
def get_c2ps(self): c2ps = defaultdict(set) for goid_child, goid_parent in self.edges: c2ps[goid_child].add(goid_parent) return c2ps
[ "def", "get_c2ps", "(", "self", ")", ":", "c2ps", "=", "defaultdict", "(", "set", ")", "for", "goid_child", ",", "goid_parent", "in", "self", ".", "edges", ":", "c2ps", "[", "goid_child", "]", ".", "add", "(", "goid_parent", ")", "return", "c2ps" ]
Set child2parents dict for all parents used in this set of edges.
[ "Set", "child2parents", "dict", "for", "all", "parents", "used", "in", "this", "set", "of", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L110-L115
242,366
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesRelatives._init_edges_relationships
def _init_edges_relationships(rel2src2dsts, rel2dst2srcs): """Get the directed edges from GO term to GO term using relationships.""" edge_rel2fromto = {} relationships = set(rel2src2dsts).union(rel2dst2srcs) for reltype in relationships: edge_from_to = [] if reltype in rel2src2dsts: for parent, children in rel2src2dsts[reltype].items(): for child in children: edge_from_to.append((child, parent)) if reltype in rel2dst2srcs: for parent, children in rel2dst2srcs[reltype].items(): for child in children: edge_from_to.append((child, parent)) edge_rel2fromto[reltype] = edge_from_to return edge_rel2fromto
python
def _init_edges_relationships(rel2src2dsts, rel2dst2srcs): edge_rel2fromto = {} relationships = set(rel2src2dsts).union(rel2dst2srcs) for reltype in relationships: edge_from_to = [] if reltype in rel2src2dsts: for parent, children in rel2src2dsts[reltype].items(): for child in children: edge_from_to.append((child, parent)) if reltype in rel2dst2srcs: for parent, children in rel2dst2srcs[reltype].items(): for child in children: edge_from_to.append((child, parent)) edge_rel2fromto[reltype] = edge_from_to return edge_rel2fromto
[ "def", "_init_edges_relationships", "(", "rel2src2dsts", ",", "rel2dst2srcs", ")", ":", "edge_rel2fromto", "=", "{", "}", "relationships", "=", "set", "(", "rel2src2dsts", ")", ".", "union", "(", "rel2dst2srcs", ")", "for", "reltype", "in", "relationships", ":",...
Get the directed edges from GO term to GO term using relationships.
[ "Get", "the", "directed", "edges", "from", "GO", "term", "to", "GO", "term", "using", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L169-L184
242,367
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesRelatives._traverse_relationship_objs
def _traverse_relationship_objs(self, rel2src2dsts, goobj_child, goids_seen): """Traverse from source GO up relationships.""" child_id = goobj_child.id goids_seen.add(child_id) ##A self.go2obj[child_id] = goobj_child # Update goids_seen and go2obj with child alt_ids for goid_altid in goobj_child.alt_ids: goids_seen.add(goid_altid) ##A self.go2obj[goid_altid] = goobj_child # Loop through relationships of child object for reltype, recs in goobj_child.relationship.items(): if reltype in self.relationships: for relationship_obj in recs: relationship_id = relationship_obj.id rel2src2dsts[reltype][relationship_id].add(child_id) # If relationship has not been seen, traverse if relationship_id not in goids_seen: self._traverse_relationship_objs(rel2src2dsts, relationship_obj, goids_seen)
python
def _traverse_relationship_objs(self, rel2src2dsts, goobj_child, goids_seen): child_id = goobj_child.id goids_seen.add(child_id) ##A self.go2obj[child_id] = goobj_child # Update goids_seen and go2obj with child alt_ids for goid_altid in goobj_child.alt_ids: goids_seen.add(goid_altid) ##A self.go2obj[goid_altid] = goobj_child # Loop through relationships of child object for reltype, recs in goobj_child.relationship.items(): if reltype in self.relationships: for relationship_obj in recs: relationship_id = relationship_obj.id rel2src2dsts[reltype][relationship_id].add(child_id) # If relationship has not been seen, traverse if relationship_id not in goids_seen: self._traverse_relationship_objs(rel2src2dsts, relationship_obj, goids_seen)
[ "def", "_traverse_relationship_objs", "(", "self", ",", "rel2src2dsts", ",", "goobj_child", ",", "goids_seen", ")", ":", "child_id", "=", "goobj_child", ".", "id", "goids_seen", ".", "add", "(", "child_id", ")", "##A self.go2obj[child_id] = goobj_child", "# Update goi...
Traverse from source GO up relationships.
[ "Traverse", "from", "source", "GO", "up", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L200-L217
242,368
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesRelatives._init_rel2dst2srcs
def _init_rel2dst2srcs(self, go_sources, traverse_child): """Traverse through reverse relationships.""" if not traverse_child or not self.relationships: return {} rel2dst2srcs = {r:defaultdict(set) for r in self.relationships} goids_seen = set() go2obj = self.go2obj for goid_src in go_sources: goobj_src = go2obj[goid_src] if goid_src not in goids_seen: self._traverse_relationship_rev_objs(rel2dst2srcs, goobj_src, goids_seen) return rel2dst2srcs
python
def _init_rel2dst2srcs(self, go_sources, traverse_child): if not traverse_child or not self.relationships: return {} rel2dst2srcs = {r:defaultdict(set) for r in self.relationships} goids_seen = set() go2obj = self.go2obj for goid_src in go_sources: goobj_src = go2obj[goid_src] if goid_src not in goids_seen: self._traverse_relationship_rev_objs(rel2dst2srcs, goobj_src, goids_seen) return rel2dst2srcs
[ "def", "_init_rel2dst2srcs", "(", "self", ",", "go_sources", ",", "traverse_child", ")", ":", "if", "not", "traverse_child", "or", "not", "self", ".", "relationships", ":", "return", "{", "}", "rel2dst2srcs", "=", "{", "r", ":", "defaultdict", "(", "set", ...
Traverse through reverse relationships.
[ "Traverse", "through", "reverse", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L220-L231
242,369
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesRelatives._init_c2ps
def _init_c2ps(self, go_sources, traverse_child): """Traverse up children.""" if not traverse_child: return {} c2ps = defaultdict(set) goids_seen = set() go2obj = self.go2obj for goid_src in go_sources: goobj_src = go2obj[goid_src] if goid_src not in goids_seen: ##F self._traverse_child_objs(c2ps, goobj_src, go2obj, goids_seen) self._traverse_child_objs(c2ps, goobj_src, goids_seen) return c2ps
python
def _init_c2ps(self, go_sources, traverse_child): if not traverse_child: return {} c2ps = defaultdict(set) goids_seen = set() go2obj = self.go2obj for goid_src in go_sources: goobj_src = go2obj[goid_src] if goid_src not in goids_seen: ##F self._traverse_child_objs(c2ps, goobj_src, go2obj, goids_seen) self._traverse_child_objs(c2ps, goobj_src, goids_seen) return c2ps
[ "def", "_init_c2ps", "(", "self", ",", "go_sources", ",", "traverse_child", ")", ":", "if", "not", "traverse_child", ":", "return", "{", "}", "c2ps", "=", "defaultdict", "(", "set", ")", "goids_seen", "=", "set", "(", ")", "go2obj", "=", "self", ".", "...
Traverse up children.
[ "Traverse", "up", "children", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L290-L302
242,370
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData.chk
def chk(self, annotations, fout_err): """Check annotations.""" for idx, ntd in enumerate(annotations): self._chk_fld(ntd, "Qualifier") # optional 0 or greater self._chk_fld(ntd, "DB_Reference", 1) # required 1 or greater self._chk_fld(ntd, "With_From") # optional 0 or greater self._chk_fld(ntd, "DB_Name", 0, 1) # optional 0 or 1 self._chk_fld(ntd, "DB_Synonym") # optional 0 or greater self._chk_fld(ntd, "Taxon", 1, 2) flds = list(ntd) self._chk_qty_eq_1(flds) # self._chk_qualifier(ntd.Qualifier, flds, idx) if not ntd.Taxon or len(ntd.Taxon) not in {1, 2}: self.illegal_lines['BAD TAXON'].append((idx, '**{I}) TAXON: {NT}'.format(I=idx, NT=ntd))) if self.illegal_lines: self.prt_error_summary(fout_err) return not self.illegal_lines
python
def chk(self, annotations, fout_err): for idx, ntd in enumerate(annotations): self._chk_fld(ntd, "Qualifier") # optional 0 or greater self._chk_fld(ntd, "DB_Reference", 1) # required 1 or greater self._chk_fld(ntd, "With_From") # optional 0 or greater self._chk_fld(ntd, "DB_Name", 0, 1) # optional 0 or 1 self._chk_fld(ntd, "DB_Synonym") # optional 0 or greater self._chk_fld(ntd, "Taxon", 1, 2) flds = list(ntd) self._chk_qty_eq_1(flds) # self._chk_qualifier(ntd.Qualifier, flds, idx) if not ntd.Taxon or len(ntd.Taxon) not in {1, 2}: self.illegal_lines['BAD TAXON'].append((idx, '**{I}) TAXON: {NT}'.format(I=idx, NT=ntd))) if self.illegal_lines: self.prt_error_summary(fout_err) return not self.illegal_lines
[ "def", "chk", "(", "self", ",", "annotations", ",", "fout_err", ")", ":", "for", "idx", ",", "ntd", "in", "enumerate", "(", "annotations", ")", ":", "self", ".", "_chk_fld", "(", "ntd", ",", "\"Qualifier\"", ")", "# optional 0 or greater", "self", ".", "...
Check annotations.
[ "Check", "annotations", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L151-L167
242,371
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData.get_gafvals
def get_gafvals(self, line): """Convert fields from string to preferred format for GAF ver 2.1 and 2.0.""" flds = line.split('\t') flds[3] = self._get_qualifier(flds[3]) # 3 Qualifier flds[5] = self._get_set(flds[5]) # 5 DB_Reference flds[7] = self._get_set(flds[7]) # 7 With_From flds[8] = self.aspect2ns[flds[8]] # 8 GAF Aspect field converted to BP, MF, or CC flds[9] = self._get_set(flds[9]) # 9 DB_Name flds[10] = self._get_set(flds[10]) # 10 DB_Synonym flds[12] = self._do_taxons(flds[12]) # 12 Taxon flds[13] = GET_DATE_YYYYMMDD(flds[13]) # self.strptime(flds[13], '%Y%m%d').date(), # 13 Date 20190406 # Version 2.x has these additional fields not found in v1.0 if self.is_long: flds[15] = get_extensions(flds[15]) # Extensions (or Annotation_Extension) flds[16] = self._get_set(flds[16].rstrip()) else: flds[14] = self._get_set(flds[14].rstrip()) return flds
python
def get_gafvals(self, line): flds = line.split('\t') flds[3] = self._get_qualifier(flds[3]) # 3 Qualifier flds[5] = self._get_set(flds[5]) # 5 DB_Reference flds[7] = self._get_set(flds[7]) # 7 With_From flds[8] = self.aspect2ns[flds[8]] # 8 GAF Aspect field converted to BP, MF, or CC flds[9] = self._get_set(flds[9]) # 9 DB_Name flds[10] = self._get_set(flds[10]) # 10 DB_Synonym flds[12] = self._do_taxons(flds[12]) # 12 Taxon flds[13] = GET_DATE_YYYYMMDD(flds[13]) # self.strptime(flds[13], '%Y%m%d').date(), # 13 Date 20190406 # Version 2.x has these additional fields not found in v1.0 if self.is_long: flds[15] = get_extensions(flds[15]) # Extensions (or Annotation_Extension) flds[16] = self._get_set(flds[16].rstrip()) else: flds[14] = self._get_set(flds[14].rstrip()) return flds
[ "def", "get_gafvals", "(", "self", ",", "line", ")", ":", "flds", "=", "line", ".", "split", "(", "'\\t'", ")", "flds", "[", "3", "]", "=", "self", ".", "_get_qualifier", "(", "flds", "[", "3", "]", ")", "# 3 Qualifier", "flds", "[", "5", "]", "...
Convert fields from string to preferred format for GAF ver 2.1 and 2.0.
[ "Convert", "fields", "from", "string", "to", "preferred", "format", "for", "GAF", "ver", "2", ".", "1", "and", "2", ".", "0", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L173-L192
242,372
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData._get_qualifier
def _get_qualifier(val): """Get qualifiers. Correct for inconsistent capitalization in GAF files""" quals = set() if val == '': return quals for val in val.split('|'): val = val.lower() quals.add(val if val != 'not' else 'NOT') return quals
python
def _get_qualifier(val): quals = set() if val == '': return quals for val in val.split('|'): val = val.lower() quals.add(val if val != 'not' else 'NOT') return quals
[ "def", "_get_qualifier", "(", "val", ")", ":", "quals", "=", "set", "(", ")", "if", "val", "==", "''", ":", "return", "quals", "for", "val", "in", "val", ".", "split", "(", "'|'", ")", ":", "val", "=", "val", ".", "lower", "(", ")", "quals", "....
Get qualifiers. Correct for inconsistent capitalization in GAF files
[ "Get", "qualifiers", ".", "Correct", "for", "inconsistent", "capitalization", "in", "GAF", "files" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L195-L203
242,373
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData._chk_fld
def _chk_fld(self, ntd, name, qty_min=0, qty_max=None): """Further split a GAF value within a single field.""" vals = getattr(ntd, name) num_vals = len(vals) if num_vals < qty_min: self.illegal_lines['MIN QTY'].append( (-1, "FIELD({F}): MIN QUANTITY({Q}) WASN'T MET: {V}".format(F=name, Q=qty_min, V=vals))) if qty_max is not None: if num_vals > qty_max: self.illegal_lines['MAX QTY'].append( (-1, "FIELD({F}): MAX QUANTITY({Q}) EXCEEDED: {V}\n{NT}".format( F=name, Q=qty_max, V=vals, NT=ntd)))
python
def _chk_fld(self, ntd, name, qty_min=0, qty_max=None): vals = getattr(ntd, name) num_vals = len(vals) if num_vals < qty_min: self.illegal_lines['MIN QTY'].append( (-1, "FIELD({F}): MIN QUANTITY({Q}) WASN'T MET: {V}".format(F=name, Q=qty_min, V=vals))) if qty_max is not None: if num_vals > qty_max: self.illegal_lines['MAX QTY'].append( (-1, "FIELD({F}): MAX QUANTITY({Q}) EXCEEDED: {V}\n{NT}".format( F=name, Q=qty_max, V=vals, NT=ntd)))
[ "def", "_chk_fld", "(", "self", ",", "ntd", ",", "name", ",", "qty_min", "=", "0", ",", "qty_max", "=", "None", ")", ":", "vals", "=", "getattr", "(", "ntd", ",", "name", ")", "num_vals", "=", "len", "(", "vals", ")", "if", "num_vals", "<", "qty_...
Further split a GAF value within a single field.
[ "Further", "split", "a", "GAF", "value", "within", "a", "single", "field", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L215-L226
242,374
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData.prt_line_detail
def prt_line_detail(self, prt, line): """Print line header and values in a readable format.""" values = line.split('\t') self._prt_line_detail(prt, values)
python
def prt_line_detail(self, prt, line): values = line.split('\t') self._prt_line_detail(prt, values)
[ "def", "prt_line_detail", "(", "self", ",", "prt", ",", "line", ")", ":", "values", "=", "line", ".", "split", "(", "'\\t'", ")", "self", ".", "_prt_line_detail", "(", "prt", ",", "values", ")" ]
Print line header and values in a readable format.
[ "Print", "line", "header", "and", "values", "in", "a", "readable", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L236-L239
242,375
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData._prt_line_detail
def _prt_line_detail(self, prt, values, lnum=""): """Print header and field values in a readable format.""" #### data = zip(self.req_str, self.ntgafobj._fields, values) data = zip(self.req_str, self.flds, values) txt = ["{:2}) {:3} {:20} {}".format(i, req, hdr, val) for i, (req, hdr, val) in enumerate(data)] prt.write("{LNUM}\n{TXT}\n".format(LNUM=lnum, TXT="\n".join(txt)))
python
def _prt_line_detail(self, prt, values, lnum=""): #### data = zip(self.req_str, self.ntgafobj._fields, values) data = zip(self.req_str, self.flds, values) txt = ["{:2}) {:3} {:20} {}".format(i, req, hdr, val) for i, (req, hdr, val) in enumerate(data)] prt.write("{LNUM}\n{TXT}\n".format(LNUM=lnum, TXT="\n".join(txt)))
[ "def", "_prt_line_detail", "(", "self", ",", "prt", ",", "values", ",", "lnum", "=", "\"\"", ")", ":", "#### data = zip(self.req_str, self.ntgafobj._fields, values)", "data", "=", "zip", "(", "self", ".", "req_str", ",", "self", ".", "flds", ",", "values", ")"...
Print header and field values in a readable format.
[ "Print", "header", "and", "field", "values", "in", "a", "readable", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L241-L246
242,376
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData.prt_error_summary
def prt_error_summary(self, fout_err): """Print a summary about the GAF file that was read.""" # Get summary of error types and their counts errcnts = [] if self.ignored: errcnts.append(" {N:9,} IGNORED associations\n".format(N=len(self.ignored))) if self.illegal_lines: for err_name, errors in self.illegal_lines.items(): errcnts.append(" {N:9,} {ERROR}\n".format(N=len(errors), ERROR=err_name)) # Save error details into a log file fout_log = self._wrlog_details_illegal_gaf(fout_err, errcnts) sys.stdout.write(" WROTE GAF ERROR LOG: {LOG}:\n".format(LOG=fout_log)) for err_cnt in errcnts: sys.stdout.write(err_cnt)
python
def prt_error_summary(self, fout_err): # Get summary of error types and their counts errcnts = [] if self.ignored: errcnts.append(" {N:9,} IGNORED associations\n".format(N=len(self.ignored))) if self.illegal_lines: for err_name, errors in self.illegal_lines.items(): errcnts.append(" {N:9,} {ERROR}\n".format(N=len(errors), ERROR=err_name)) # Save error details into a log file fout_log = self._wrlog_details_illegal_gaf(fout_err, errcnts) sys.stdout.write(" WROTE GAF ERROR LOG: {LOG}:\n".format(LOG=fout_log)) for err_cnt in errcnts: sys.stdout.write(err_cnt)
[ "def", "prt_error_summary", "(", "self", ",", "fout_err", ")", ":", "# Get summary of error types and their counts", "errcnts", "=", "[", "]", "if", "self", ".", "ignored", ":", "errcnts", ".", "append", "(", "\" {N:9,} IGNORED associations\\n\"", ".", "format", "(...
Print a summary about the GAF file that was read.
[ "Print", "a", "summary", "about", "the", "GAF", "file", "that", "was", "read", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L265-L278
242,377
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData._wrlog_details_illegal_gaf
def _wrlog_details_illegal_gaf(self, fout_err, err_cnts): """Print details regarding illegal GAF lines seen to a log file.""" # fout_err = "{}.log".format(fin_gaf) gaf_base = os.path.basename(fout_err) with open(fout_err, 'w') as prt: prt.write("ILLEGAL GAF ERROR SUMMARY:\n\n") for err_cnt in err_cnts: prt.write(err_cnt) prt.write("\n\nILLEGAL GAF ERROR DETAILS:\n\n") for lnum, line in self.ignored: prt.write("**WARNING: GAF LINE IGNORED: {FIN}[{LNUM}]:\n{L}\n".format( FIN=gaf_base, L=line, LNUM=lnum)) self.prt_line_detail(prt, line) prt.write("\n\n") for error, lines in self.illegal_lines.items(): for lnum, line in lines: prt.write("**WARNING: GAF LINE ILLEGAL({ERR}): {FIN}[{LNUM}]:\n{L}\n".format( ERR=error, FIN=gaf_base, L=line, LNUM=lnum)) self.prt_line_detail(prt, line) prt.write("\n\n") return fout_err
python
def _wrlog_details_illegal_gaf(self, fout_err, err_cnts): # fout_err = "{}.log".format(fin_gaf) gaf_base = os.path.basename(fout_err) with open(fout_err, 'w') as prt: prt.write("ILLEGAL GAF ERROR SUMMARY:\n\n") for err_cnt in err_cnts: prt.write(err_cnt) prt.write("\n\nILLEGAL GAF ERROR DETAILS:\n\n") for lnum, line in self.ignored: prt.write("**WARNING: GAF LINE IGNORED: {FIN}[{LNUM}]:\n{L}\n".format( FIN=gaf_base, L=line, LNUM=lnum)) self.prt_line_detail(prt, line) prt.write("\n\n") for error, lines in self.illegal_lines.items(): for lnum, line in lines: prt.write("**WARNING: GAF LINE ILLEGAL({ERR}): {FIN}[{LNUM}]:\n{L}\n".format( ERR=error, FIN=gaf_base, L=line, LNUM=lnum)) self.prt_line_detail(prt, line) prt.write("\n\n") return fout_err
[ "def", "_wrlog_details_illegal_gaf", "(", "self", ",", "fout_err", ",", "err_cnts", ")", ":", "# fout_err = \"{}.log\".format(fin_gaf)", "gaf_base", "=", "os", ".", "path", ".", "basename", "(", "fout_err", ")", "with", "open", "(", "fout_err", ",", "'w'", ")", ...
Print details regarding illegal GAF lines seen to a log file.
[ "Print", "details", "regarding", "illegal", "GAF", "lines", "seen", "to", "a", "log", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L280-L300
242,378
tanghaibao/goatools
goatools/gosubdag/godag_rcnt_init.py
CountRelativesInit.get_relationship_dicts
def get_relationship_dicts(self): """Given GO DAG relationships, return summaries per GO ID.""" if not self.relationships: return None for goid, goobj in self.go2obj.items(): for reltyp, relset in goobj.relationship.items(): relfwd_goids = set(o.id for o in relset) # for relfwd_goid in relfwd_goids: # assert relfwd_goid in self.go2obj, "{GO} {REL} NOT FOUND {GO_R}".format( # GO=goid, REL=reltyp, GO_R=relfwd_goid) print("CountRelativesInit RELLLLS", goid, goobj.id, reltyp, relfwd_goids)
python
def get_relationship_dicts(self): if not self.relationships: return None for goid, goobj in self.go2obj.items(): for reltyp, relset in goobj.relationship.items(): relfwd_goids = set(o.id for o in relset) # for relfwd_goid in relfwd_goids: # assert relfwd_goid in self.go2obj, "{GO} {REL} NOT FOUND {GO_R}".format( # GO=goid, REL=reltyp, GO_R=relfwd_goid) print("CountRelativesInit RELLLLS", goid, goobj.id, reltyp, relfwd_goids)
[ "def", "get_relationship_dicts", "(", "self", ")", ":", "if", "not", "self", ".", "relationships", ":", "return", "None", "for", "goid", ",", "goobj", "in", "self", ".", "go2obj", ".", "items", "(", ")", ":", "for", "reltyp", ",", "relset", "in", "goob...
Given GO DAG relationships, return summaries per GO ID.
[ "Given", "GO", "DAG", "relationships", "return", "summaries", "per", "GO", "ID", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/godag_rcnt_init.py#L38-L48
242,379
tanghaibao/goatools
goatools/gosubdag/godag_rcnt_init.py
CountRelativesInit.get_goone2ntletter
def get_goone2ntletter(self, go2dcnt, depth2goobjs): """Assign letters to depth-01 GO terms ordered using descendants cnt.""" # 1. Group level-01/depth-01 GO terms by namespace ns2dcntgoobj = cx.defaultdict(list) for goobj in depth2goobjs[1]: dcnt = go2dcnt[goobj.id] ns2dcntgoobj[goobj.namespace].append((dcnt, goobj)) # 2. Assign letters to level-01/depth-01 GO terms go2nt = {} ntobj = cx.namedtuple("NtGoLetters", "D1 dcnt goobj") _go2abc = self.go2letter letters = list(chain(range(ord('A'), ord('Z') + 1), range(ord('a'), ord('z') + 1))) for list_dcnt_goobj in ns2dcntgoobj.values(): letter_idx = 0 for dcnt, goobj in sorted(list_dcnt_goobj, key=lambda t: t[0], reverse=True): letter = chr(letters[letter_idx]) if _go2abc is None else _go2abc.get(goobj.id, '') go2nt[goobj.id] = ntobj._make([letter, dcnt, goobj]) letter_idx += 1 return go2nt
python
def get_goone2ntletter(self, go2dcnt, depth2goobjs): # 1. Group level-01/depth-01 GO terms by namespace ns2dcntgoobj = cx.defaultdict(list) for goobj in depth2goobjs[1]: dcnt = go2dcnt[goobj.id] ns2dcntgoobj[goobj.namespace].append((dcnt, goobj)) # 2. Assign letters to level-01/depth-01 GO terms go2nt = {} ntobj = cx.namedtuple("NtGoLetters", "D1 dcnt goobj") _go2abc = self.go2letter letters = list(chain(range(ord('A'), ord('Z') + 1), range(ord('a'), ord('z') + 1))) for list_dcnt_goobj in ns2dcntgoobj.values(): letter_idx = 0 for dcnt, goobj in sorted(list_dcnt_goobj, key=lambda t: t[0], reverse=True): letter = chr(letters[letter_idx]) if _go2abc is None else _go2abc.get(goobj.id, '') go2nt[goobj.id] = ntobj._make([letter, dcnt, goobj]) letter_idx += 1 return go2nt
[ "def", "get_goone2ntletter", "(", "self", ",", "go2dcnt", ",", "depth2goobjs", ")", ":", "# 1. Group level-01/depth-01 GO terms by namespace", "ns2dcntgoobj", "=", "cx", ".", "defaultdict", "(", "list", ")", "for", "goobj", "in", "depth2goobjs", "[", "1", "]", ":"...
Assign letters to depth-01 GO terms ordered using descendants cnt.
[ "Assign", "letters", "to", "depth", "-", "01", "GO", "terms", "ordered", "using", "descendants", "cnt", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/godag_rcnt_init.py#L50-L68
242,380
tanghaibao/goatools
goatools/grouper/grprdflts.py
GrouperDflts._init_goslims
def _init_goslims(self, dagslim): """Get GO IDs in GO slims.""" go2obj_main = self.gosubdag.go2obj go2obj_slim = {go for go, o in dagslim.items() if go in go2obj_main} if self.gosubdag.relationships: return self._get_goslimids_norel(go2obj_slim) return set(dagslim.keys())
python
def _init_goslims(self, dagslim): go2obj_main = self.gosubdag.go2obj go2obj_slim = {go for go, o in dagslim.items() if go in go2obj_main} if self.gosubdag.relationships: return self._get_goslimids_norel(go2obj_slim) return set(dagslim.keys())
[ "def", "_init_goslims", "(", "self", ",", "dagslim", ")", ":", "go2obj_main", "=", "self", ".", "gosubdag", ".", "go2obj", "go2obj_slim", "=", "{", "go", "for", "go", ",", "o", "in", "dagslim", ".", "items", "(", ")", "if", "go", "in", "go2obj_main", ...
Get GO IDs in GO slims.
[ "Get", "GO", "IDs", "in", "GO", "slims", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprdflts.py#L48-L54
242,381
tanghaibao/goatools
goatools/grouper/grprdflts.py
GrouperDflts._get_goslimids_norel
def _get_goslimids_norel(self, dagslim): """Get all GO slim GO IDs that do not have a relationship.""" go_slims = set() go2obj = self.gosubdag.go2obj for goid in dagslim: goobj = go2obj[goid] if not goobj.relationship: go_slims.add(goobj.id) return go_slims
python
def _get_goslimids_norel(self, dagslim): go_slims = set() go2obj = self.gosubdag.go2obj for goid in dagslim: goobj = go2obj[goid] if not goobj.relationship: go_slims.add(goobj.id) return go_slims
[ "def", "_get_goslimids_norel", "(", "self", ",", "dagslim", ")", ":", "go_slims", "=", "set", "(", ")", "go2obj", "=", "self", ".", "gosubdag", ".", "go2obj", "for", "goid", "in", "dagslim", ":", "goobj", "=", "go2obj", "[", "goid", "]", "if", "not", ...
Get all GO slim GO IDs that do not have a relationship.
[ "Get", "all", "GO", "slim", "GO", "IDs", "that", "do", "not", "have", "a", "relationship", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprdflts.py#L60-L68
242,382
tanghaibao/goatools
goatools/grouper/grprdflts.py
GrouperDflts.get_gosubdag
def get_gosubdag(gosubdag=None): """Gets a GoSubDag initialized for use by a Grouper object.""" if gosubdag is not None: if gosubdag.rcntobj is not None: return gosubdag else: gosubdag.init_auxobjs() return gosubdag else: go2obj = get_godag() return GoSubDag(None, go2obj, rcntobj=True)
python
def get_gosubdag(gosubdag=None): if gosubdag is not None: if gosubdag.rcntobj is not None: return gosubdag else: gosubdag.init_auxobjs() return gosubdag else: go2obj = get_godag() return GoSubDag(None, go2obj, rcntobj=True)
[ "def", "get_gosubdag", "(", "gosubdag", "=", "None", ")", ":", "if", "gosubdag", "is", "not", "None", ":", "if", "gosubdag", ".", "rcntobj", "is", "not", "None", ":", "return", "gosubdag", "else", ":", "gosubdag", ".", "init_auxobjs", "(", ")", "return",...
Gets a GoSubDag initialized for use by a Grouper object.
[ "Gets", "a", "GoSubDag", "initialized", "for", "use", "by", "a", "Grouper", "object", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprdflts.py#L71-L81
242,383
tanghaibao/goatools
goatools/anno/opts.py
AnnoOptions.getfnc_qual_ev
def getfnc_qual_ev(self): """Keep annotaion if it passes potentially modified selection.""" fnc_key = ( self.nd_not2desc[(self._keep_nd, self._keep_not)], self.incexc2num[( self.include_evcodes is not None, self.exclude_evcodes is not None)], ) return self.param2fnc[fnc_key]
python
def getfnc_qual_ev(self): fnc_key = ( self.nd_not2desc[(self._keep_nd, self._keep_not)], self.incexc2num[( self.include_evcodes is not None, self.exclude_evcodes is not None)], ) return self.param2fnc[fnc_key]
[ "def", "getfnc_qual_ev", "(", "self", ")", ":", "fnc_key", "=", "(", "self", ".", "nd_not2desc", "[", "(", "self", ".", "_keep_nd", ",", "self", ".", "_keep_not", ")", "]", ",", "self", ".", "incexc2num", "[", "(", "self", ".", "include_evcodes", "is",...
Keep annotaion if it passes potentially modified selection.
[ "Keep", "annotaion", "if", "it", "passes", "potentially", "modified", "selection", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/opts.py#L65-L73
242,384
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNodeOpts.get_kws
def get_kws(self): """Only load keywords if they are specified by the user.""" ret = self.kws['dict'].copy() act_set = self.kws['set'] if 'shorten' in act_set and 'goobj2fncname' not in ret: ret['goobj2fncname'] = ShortenText().get_short_plot_name return ret
python
def get_kws(self): ret = self.kws['dict'].copy() act_set = self.kws['set'] if 'shorten' in act_set and 'goobj2fncname' not in ret: ret['goobj2fncname'] = ShortenText().get_short_plot_name return ret
[ "def", "get_kws", "(", "self", ")", ":", "ret", "=", "self", ".", "kws", "[", "'dict'", "]", ".", "copy", "(", ")", "act_set", "=", "self", ".", "kws", "[", "'set'", "]", "if", "'shorten'", "in", "act_set", "and", "'goobj2fncname'", "not", "in", "r...
Only load keywords if they are specified by the user.
[ "Only", "load", "keywords", "if", "they", "are", "specified", "by", "the", "user", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L32-L38
242,385
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode.get_node
def get_node(self, goid, goobj): """Return pydot node.""" # pydot.Node.objdict holds this information. pydot.Node.objdict['name'] return pydot.Node( self.get_node_text(goid, goobj), shape="box", style="rounded, filled", fillcolor=self.go2color.get(goid, "white"), color=self.objcolor.get_bordercolor(goid))
python
def get_node(self, goid, goobj): # pydot.Node.objdict holds this information. pydot.Node.objdict['name'] return pydot.Node( self.get_node_text(goid, goobj), shape="box", style="rounded, filled", fillcolor=self.go2color.get(goid, "white"), color=self.objcolor.get_bordercolor(goid))
[ "def", "get_node", "(", "self", ",", "goid", ",", "goobj", ")", ":", "# pydot.Node.objdict holds this information. pydot.Node.objdict['name']", "return", "pydot", ".", "Node", "(", "self", ".", "get_node_text", "(", "goid", ",", "goobj", ")", ",", "shape", "=", ...
Return pydot node.
[ "Return", "pydot", "node", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L56-L64
242,386
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode.str_fmthdr
def str_fmthdr(self, goid, goobj): """Return hdr line seen inside a GO Term box.""" # Shorten: Ex: GO:0007608 -> G0007608 go_txt = goid.replace("GO:", "G") if 'mark_alt_id' in self.present and goid != goobj.id: go_txt += 'a' return go_txt
python
def str_fmthdr(self, goid, goobj): # Shorten: Ex: GO:0007608 -> G0007608 go_txt = goid.replace("GO:", "G") if 'mark_alt_id' in self.present and goid != goobj.id: go_txt += 'a' return go_txt
[ "def", "str_fmthdr", "(", "self", ",", "goid", ",", "goobj", ")", ":", "# Shorten: Ex: GO:0007608 -> G0007608", "go_txt", "=", "goid", ".", "replace", "(", "\"GO:\"", ",", "\"G\"", ")", "if", "'mark_alt_id'", "in", "self", ".", "present", "and", "goid", "!="...
Return hdr line seen inside a GO Term box.
[ "Return", "hdr", "line", "seen", "inside", "a", "GO", "Term", "box", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L66-L72
242,387
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode._get_prtflds
def _get_prtflds(self): """Get print fields for GO header.""" # User-specified print fields ntflds = self.gosubdag.prt_attr['flds'] prt_flds = self.kws.get('prt_flds') if prt_flds: return prt_flds.intersection(ntflds) exclude = set() # Default print fields if self.gosubdag.relationships: exclude.add('level') return set(f for f in ntflds if f not in exclude)
python
def _get_prtflds(self): # User-specified print fields ntflds = self.gosubdag.prt_attr['flds'] prt_flds = self.kws.get('prt_flds') if prt_flds: return prt_flds.intersection(ntflds) exclude = set() # Default print fields if self.gosubdag.relationships: exclude.add('level') return set(f for f in ntflds if f not in exclude)
[ "def", "_get_prtflds", "(", "self", ")", ":", "# User-specified print fields", "ntflds", "=", "self", ".", "gosubdag", ".", "prt_attr", "[", "'flds'", "]", "prt_flds", "=", "self", ".", "kws", ".", "get", "(", "'prt_flds'", ")", "if", "prt_flds", ":", "ret...
Get print fields for GO header.
[ "Get", "print", "fields", "for", "GO", "header", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L132-L143
242,388
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode._get_hdr_childcnt
def _get_hdr_childcnt(self, goobj, ntgo): """Get string representing count of children for this GO term.""" if 'childcnt' in self.present: return "c{N}".format(N=len(goobj.children)) elif self.gosubdag.relationships and not goobj.children and ntgo.dcnt != 0: return "c0"
python
def _get_hdr_childcnt(self, goobj, ntgo): if 'childcnt' in self.present: return "c{N}".format(N=len(goobj.children)) elif self.gosubdag.relationships and not goobj.children and ntgo.dcnt != 0: return "c0"
[ "def", "_get_hdr_childcnt", "(", "self", ",", "goobj", ",", "ntgo", ")", ":", "if", "'childcnt'", "in", "self", ".", "present", ":", "return", "\"c{N}\"", ".", "format", "(", "N", "=", "len", "(", "goobj", ".", "children", ")", ")", "elif", "self", "...
Get string representing count of children for this GO term.
[ "Get", "string", "representing", "count", "of", "children", "for", "this", "GO", "term", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L145-L150
242,389
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode._add_parent_cnt
def _add_parent_cnt(self, hdr, goobj, c2ps): """Add the parent count to the GO term box for if not all parents are plotted.""" if goobj.id in c2ps: parents = c2ps[goobj.id] if 'prt_pcnt' in self.present or parents and len(goobj.parents) != len(parents): assert len(goobj.parents) == len(set(goobj.parents)) hdr.append("p{N}".format(N=len(set(goobj.parents))))
python
def _add_parent_cnt(self, hdr, goobj, c2ps): if goobj.id in c2ps: parents = c2ps[goobj.id] if 'prt_pcnt' in self.present or parents and len(goobj.parents) != len(parents): assert len(goobj.parents) == len(set(goobj.parents)) hdr.append("p{N}".format(N=len(set(goobj.parents))))
[ "def", "_add_parent_cnt", "(", "self", ",", "hdr", ",", "goobj", ",", "c2ps", ")", ":", "if", "goobj", ".", "id", "in", "c2ps", ":", "parents", "=", "c2ps", "[", "goobj", ".", "id", "]", "if", "'prt_pcnt'", "in", "self", ".", "present", "or", "pare...
Add the parent count to the GO term box for if not all parents are plotted.
[ "Add", "the", "parent", "count", "to", "the", "GO", "term", "box", "for", "if", "not", "all", "parents", "are", "plotted", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L152-L158
242,390
tanghaibao/goatools
goatools/anno/idtogos_reader.py
IdToGosReader.prt_summary_anno2ev
def prt_summary_anno2ev(self, prt=sys.stdout): """Print a summary of all Evidence Codes seen in annotations""" prt.write('**NOTE: No evidence codes in associations: {F}\n'.format(F=self.filename))
python
def prt_summary_anno2ev(self, prt=sys.stdout): prt.write('**NOTE: No evidence codes in associations: {F}\n'.format(F=self.filename))
[ "def", "prt_summary_anno2ev", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "prt", ".", "write", "(", "'**NOTE: No evidence codes in associations: {F}\\n'", ".", "format", "(", "F", "=", "self", ".", "filename", ")", ")" ]
Print a summary of all Evidence Codes seen in annotations
[ "Print", "a", "summary", "of", "all", "Evidence", "Codes", "seen", "in", "annotations" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/idtogos_reader.py#L21-L23
242,391
tanghaibao/goatools
goatools/ratio.py
count_terms
def count_terms(geneset, assoc, obo_dag): """count the number of terms in the study group """ term_cnt = Counter() for gene in (g for g in geneset if g in assoc): for goid in assoc[gene]: if goid in obo_dag: term_cnt[obo_dag[goid].id] += 1 return term_cnt
python
def count_terms(geneset, assoc, obo_dag): term_cnt = Counter() for gene in (g for g in geneset if g in assoc): for goid in assoc[gene]: if goid in obo_dag: term_cnt[obo_dag[goid].id] += 1 return term_cnt
[ "def", "count_terms", "(", "geneset", ",", "assoc", ",", "obo_dag", ")", ":", "term_cnt", "=", "Counter", "(", ")", "for", "gene", "in", "(", "g", "for", "g", "in", "geneset", "if", "g", "in", "assoc", ")", ":", "for", "goid", "in", "assoc", "[", ...
count the number of terms in the study group
[ "count", "the", "number", "of", "terms", "in", "the", "study", "group" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/ratio.py#L10-L19
242,392
tanghaibao/goatools
goatools/ratio.py
get_terms
def get_terms(desc, geneset, assoc, obo_dag, log): """Get the terms in the study group """ _chk_gene2go(assoc) term2itemids = defaultdict(set) genes = [g for g in geneset if g in assoc] for gene in genes: for goid in assoc[gene]: if goid in obo_dag: term2itemids[obo_dag[goid].id].add(gene) if log is not None: num_stu = len(genes) num_pop = len(geneset) perc = 100.0*num_stu/num_pop if num_pop != 0 else 0.0 log.write("{P:3.0f}% {N:>6,} of {M:>6,} {DESC} items found in association\n".format( DESC=desc, N=num_stu, M=num_pop, P=perc)) return term2itemids
python
def get_terms(desc, geneset, assoc, obo_dag, log): _chk_gene2go(assoc) term2itemids = defaultdict(set) genes = [g for g in geneset if g in assoc] for gene in genes: for goid in assoc[gene]: if goid in obo_dag: term2itemids[obo_dag[goid].id].add(gene) if log is not None: num_stu = len(genes) num_pop = len(geneset) perc = 100.0*num_stu/num_pop if num_pop != 0 else 0.0 log.write("{P:3.0f}% {N:>6,} of {M:>6,} {DESC} items found in association\n".format( DESC=desc, N=num_stu, M=num_pop, P=perc)) return term2itemids
[ "def", "get_terms", "(", "desc", ",", "geneset", ",", "assoc", ",", "obo_dag", ",", "log", ")", ":", "_chk_gene2go", "(", "assoc", ")", "term2itemids", "=", "defaultdict", "(", "set", ")", "genes", "=", "[", "g", "for", "g", "in", "geneset", "if", "g...
Get the terms in the study group
[ "Get", "the", "terms", "in", "the", "study", "group" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/ratio.py#L21-L37
242,393
tanghaibao/goatools
goatools/ratio.py
_chk_gene2go
def _chk_gene2go(assoc): """Check that associations is gene2go, not go2gene.""" if not assoc: raise RuntimeError("NO ITEMS FOUND IN ASSOCIATIONS {A}".format(A=assoc)) for key in assoc: if isinstance(key, str) and key[:3] == "GO:": raise Exception("ASSOCIATIONS EXPECTED TO BE gene2go, NOT go2gene: {EX}".format( EX=assoc.items()[:2])) return
python
def _chk_gene2go(assoc): if not assoc: raise RuntimeError("NO ITEMS FOUND IN ASSOCIATIONS {A}".format(A=assoc)) for key in assoc: if isinstance(key, str) and key[:3] == "GO:": raise Exception("ASSOCIATIONS EXPECTED TO BE gene2go, NOT go2gene: {EX}".format( EX=assoc.items()[:2])) return
[ "def", "_chk_gene2go", "(", "assoc", ")", ":", "if", "not", "assoc", ":", "raise", "RuntimeError", "(", "\"NO ITEMS FOUND IN ASSOCIATIONS {A}\"", ".", "format", "(", "A", "=", "assoc", ")", ")", "for", "key", "in", "assoc", ":", "if", "isinstance", "(", "k...
Check that associations is gene2go, not go2gene.
[ "Check", "that", "associations", "is", "gene2go", "not", "go2gene", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/ratio.py#L56-L64
242,394
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit._init_usrgos
def _init_usrgos(self, goids): """Return user GO IDs which have GO Terms.""" usrgos = set() goids_missing = set() _go2obj = self.gosubdag.go2obj for goid in goids: if goid in _go2obj: usrgos.add(goid) else: goids_missing.add(goid) if goids_missing: print("MISSING GO IDs: {GOs}".format(GOs=goids_missing)) print("{N} of {M} GO IDs ARE MISSING".format(N=len(goids_missing), M=len(goids))) return usrgos
python
def _init_usrgos(self, goids): usrgos = set() goids_missing = set() _go2obj = self.gosubdag.go2obj for goid in goids: if goid in _go2obj: usrgos.add(goid) else: goids_missing.add(goid) if goids_missing: print("MISSING GO IDs: {GOs}".format(GOs=goids_missing)) print("{N} of {M} GO IDs ARE MISSING".format(N=len(goids_missing), M=len(goids))) return usrgos
[ "def", "_init_usrgos", "(", "self", ",", "goids", ")", ":", "usrgos", "=", "set", "(", ")", "goids_missing", "=", "set", "(", ")", "_go2obj", "=", "self", ".", "gosubdag", ".", "go2obj", "for", "goid", "in", "goids", ":", "if", "goid", "in", "_go2obj...
Return user GO IDs which have GO Terms.
[ "Return", "user", "GO", "IDs", "which", "have", "GO", "Terms", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L49-L62
242,395
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit.get_gos_all
def get_gos_all(self): """Return a flat list of all GO IDs in grouping object. All GO IDs: * header GO IDs that are not user GO IDs * user GO IDs that are under header GOs * user GO IDs that are header GOs in groups containing no other user GO IDs """ gos_all = set() # Get: # * Header GO IDs that are not user GO IDs # * User GO IDs that are under header GOs for hdrgo, usrgos in self.hdrgo2usrgos.items(): gos_all.add(hdrgo) gos_all |= usrgos # User GO IDs that are header GOs in groups containing no other user GO IDs gos_all |= self.hdrgo_is_usrgo assert gos_all == self.usrgos.union(set(self.hdrgo2usrgos.keys())) assert len(self.usrgos.difference(gos_all)) == 0, \ "GROUPER ERROR: {GOs}".format(GOs=self.usrgos.difference(gos_all)) return gos_all
python
def get_gos_all(self): gos_all = set() # Get: # * Header GO IDs that are not user GO IDs # * User GO IDs that are under header GOs for hdrgo, usrgos in self.hdrgo2usrgos.items(): gos_all.add(hdrgo) gos_all |= usrgos # User GO IDs that are header GOs in groups containing no other user GO IDs gos_all |= self.hdrgo_is_usrgo assert gos_all == self.usrgos.union(set(self.hdrgo2usrgos.keys())) assert len(self.usrgos.difference(gos_all)) == 0, \ "GROUPER ERROR: {GOs}".format(GOs=self.usrgos.difference(gos_all)) return gos_all
[ "def", "get_gos_all", "(", "self", ")", ":", "gos_all", "=", "set", "(", ")", "# Get:", "# * Header GO IDs that are not user GO IDs", "# * User GO IDs that are under header GOs", "for", "hdrgo", ",", "usrgos", "in", "self", ".", "hdrgo2usrgos", ".", "items", "(", ...
Return a flat list of all GO IDs in grouping object. All GO IDs: * header GO IDs that are not user GO IDs * user GO IDs that are under header GOs * user GO IDs that are header GOs in groups containing no other user GO IDs
[ "Return", "a", "flat", "list", "of", "all", "GO", "IDs", "in", "grouping", "object", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L64-L84
242,396
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit._init_h2us
def _init_h2us(self, fnc_most_specific): """Given a set of user GO ids, return GO ids grouped under the "GO high" terms. Example of a grouped go list: gos = ['GO:0044464':[ # grp_term: D1 cell part 'GO:0005737', # child: D3 cytoplasm 'GO:0048471', # child: D4 perinuclear region of cytoplasm 'GO:0016020':[ # grp_term: D1 membrane 'GO:0098589', # child: D2 membrane region 'GO:0005886', # child: D2 plasma membrane ] """ # Header GO IDs are main. User GO IDs are as specified by the user hdrgo2usrgos = cx.defaultdict(set) # Contains user GO IDs which are also header GO IDs, plus user main GO if needed hdrgo_is_usrgo = set() _go2nt = self.gosubdag.go2nt objhi = GrouperInit.GetGoidHigh(self.gosubdag, self.hdrobj.hdrgos, self.most_specific_fncs[fnc_most_specific]) for goid_usr in self.usrgos: goid_main = _go2nt[goid_usr].id # Add current GO ID to parents_all in case curr GO ID is a high GO. goid_high = objhi.get_goid_high(goid_main) # Don't add user GO ID if it is also the GO header if goid_main != goid_high: hdrgo2usrgos[goid_high].add(goid_usr) elif goid_high not in hdrgo2usrgos: hdrgo2usrgos[goid_high] = set() if goid_main == goid_high: hdrgo_is_usrgo.add(goid_main) if goid_main != goid_usr: hdrgo_is_usrgo.add(goid_usr) # Initialize data members self.hdrgo2usrgos = hdrgo2usrgos self.hdrgo_is_usrgo = hdrgo_is_usrgo
python
def _init_h2us(self, fnc_most_specific): # Header GO IDs are main. User GO IDs are as specified by the user hdrgo2usrgos = cx.defaultdict(set) # Contains user GO IDs which are also header GO IDs, plus user main GO if needed hdrgo_is_usrgo = set() _go2nt = self.gosubdag.go2nt objhi = GrouperInit.GetGoidHigh(self.gosubdag, self.hdrobj.hdrgos, self.most_specific_fncs[fnc_most_specific]) for goid_usr in self.usrgos: goid_main = _go2nt[goid_usr].id # Add current GO ID to parents_all in case curr GO ID is a high GO. goid_high = objhi.get_goid_high(goid_main) # Don't add user GO ID if it is also the GO header if goid_main != goid_high: hdrgo2usrgos[goid_high].add(goid_usr) elif goid_high not in hdrgo2usrgos: hdrgo2usrgos[goid_high] = set() if goid_main == goid_high: hdrgo_is_usrgo.add(goid_main) if goid_main != goid_usr: hdrgo_is_usrgo.add(goid_usr) # Initialize data members self.hdrgo2usrgos = hdrgo2usrgos self.hdrgo_is_usrgo = hdrgo_is_usrgo
[ "def", "_init_h2us", "(", "self", ",", "fnc_most_specific", ")", ":", "# Header GO IDs are main. User GO IDs are as specified by the user", "hdrgo2usrgos", "=", "cx", ".", "defaultdict", "(", "set", ")", "# Contains user GO IDs which are also header GO IDs, plus user main GO if nee...
Given a set of user GO ids, return GO ids grouped under the "GO high" terms. Example of a grouped go list: gos = ['GO:0044464':[ # grp_term: D1 cell part 'GO:0005737', # child: D3 cytoplasm 'GO:0048471', # child: D4 perinuclear region of cytoplasm 'GO:0016020':[ # grp_term: D1 membrane 'GO:0098589', # child: D2 membrane region 'GO:0005886', # child: D2 plasma membrane ]
[ "Given", "a", "set", "of", "user", "GO", "ids", "return", "GO", "ids", "grouped", "under", "the", "GO", "high", "terms", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L86-L121
242,397
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit.get_go2nt
def get_go2nt(self, usr_go2nt): """Combine user namedtuple fields, GO object fields, and format_txt.""" gos_all = self.get_gos_all() # Minimum set of namedtuple fields available for use with Sorter on grouped GO IDs prt_flds_all = get_hdridx_flds() + self.gosubdag.prt_attr['flds'] if not usr_go2nt: return self.__init_go2nt_dflt(gos_all, prt_flds_all) usr_nt_flds = next(iter(usr_go2nt.values()))._fields # If user namedtuple already contains all fields available, then return usr_go2nt if len(set(prt_flds_all).difference(usr_nt_flds)) == 0: return self._init_go2nt_aug(usr_go2nt) # Otherwise, combine user fields and default Sorter fields return self.__init_go2nt_w_usr(gos_all, usr_go2nt, prt_flds_all)
python
def get_go2nt(self, usr_go2nt): gos_all = self.get_gos_all() # Minimum set of namedtuple fields available for use with Sorter on grouped GO IDs prt_flds_all = get_hdridx_flds() + self.gosubdag.prt_attr['flds'] if not usr_go2nt: return self.__init_go2nt_dflt(gos_all, prt_flds_all) usr_nt_flds = next(iter(usr_go2nt.values()))._fields # If user namedtuple already contains all fields available, then return usr_go2nt if len(set(prt_flds_all).difference(usr_nt_flds)) == 0: return self._init_go2nt_aug(usr_go2nt) # Otherwise, combine user fields and default Sorter fields return self.__init_go2nt_w_usr(gos_all, usr_go2nt, prt_flds_all)
[ "def", "get_go2nt", "(", "self", ",", "usr_go2nt", ")", ":", "gos_all", "=", "self", ".", "get_gos_all", "(", ")", "# Minimum set of namedtuple fields available for use with Sorter on grouped GO IDs", "prt_flds_all", "=", "get_hdridx_flds", "(", ")", "+", "self", ".", ...
Combine user namedtuple fields, GO object fields, and format_txt.
[ "Combine", "user", "namedtuple", "fields", "GO", "object", "fields", "and", "format_txt", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L143-L155
242,398
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit._init_go2nt_aug
def _init_go2nt_aug(self, go2nt): """Augment go2nt with GO ID key to account for alt GO IDs.""" go2obj = self.gosubdag.go2obj # Get alt GO IDs go2nt_aug = {} # NOW for goid_usr, nt_usr in go2nt.items(): goobj = go2obj[goid_usr] if goobj.alt_ids: alts = set(goobj.alt_ids) alts.add(goobj.id) for goid_alt in alts: if goid_alt not in go2nt: go2nt_aug[goid_alt] = nt_usr # WAS # Add alt GO IDs to go2nt for goid, gont in go2nt_aug.items(): go2nt[goid] = gont return go2nt
python
def _init_go2nt_aug(self, go2nt): go2obj = self.gosubdag.go2obj # Get alt GO IDs go2nt_aug = {} # NOW for goid_usr, nt_usr in go2nt.items(): goobj = go2obj[goid_usr] if goobj.alt_ids: alts = set(goobj.alt_ids) alts.add(goobj.id) for goid_alt in alts: if goid_alt not in go2nt: go2nt_aug[goid_alt] = nt_usr # WAS # Add alt GO IDs to go2nt for goid, gont in go2nt_aug.items(): go2nt[goid] = gont return go2nt
[ "def", "_init_go2nt_aug", "(", "self", ",", "go2nt", ")", ":", "go2obj", "=", "self", ".", "gosubdag", ".", "go2obj", "# Get alt GO IDs", "go2nt_aug", "=", "{", "}", "# NOW", "for", "goid_usr", ",", "nt_usr", "in", "go2nt", ".", "items", "(", ")", ":", ...
Augment go2nt with GO ID key to account for alt GO IDs.
[ "Augment", "go2nt", "with", "GO", "ID", "key", "to", "account", "for", "alt", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L173-L191
242,399
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit._get_go2nthdridx
def _get_go2nthdridx(self, gos_all): """Get GO IDs header index for each user GO ID and corresponding parent GO IDs.""" go2nthdridx = {} # NtHdrIdx Namedtuple fields: # * format_txt: Used to determine the format when writing Excel cells # * hdr_idx: Value printed in an Excel cell # shortcuts obj = GrouperInit.NtMaker(self) # Create go2nthdridx for goid in gos_all: go2nthdridx[goid] = obj.get_nt(goid) return go2nthdridx
python
def _get_go2nthdridx(self, gos_all): go2nthdridx = {} # NtHdrIdx Namedtuple fields: # * format_txt: Used to determine the format when writing Excel cells # * hdr_idx: Value printed in an Excel cell # shortcuts obj = GrouperInit.NtMaker(self) # Create go2nthdridx for goid in gos_all: go2nthdridx[goid] = obj.get_nt(goid) return go2nthdridx
[ "def", "_get_go2nthdridx", "(", "self", ",", "gos_all", ")", ":", "go2nthdridx", "=", "{", "}", "# NtHdrIdx Namedtuple fields:", "# * format_txt: Used to determine the format when writing Excel cells", "# * hdr_idx: Value printed in an Excel cell", "# shortcuts", "obj", "=", ...
Get GO IDs header index for each user GO ID and corresponding parent GO IDs.
[ "Get", "GO", "IDs", "header", "index", "for", "each", "user", "GO", "ID", "and", "corresponding", "parent", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L193-L204