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 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
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):
"""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 | [
"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 | train | 223,400 |
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):
"""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) | [
"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 | train | 223,401 |
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):
"""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) | [
"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 | train | 223,402 |
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):
"""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 | [
"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 | train | 223,403 |
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):
"""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 | [
"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 | train | 223,404 |
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):
"""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) | [
"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 | train | 223,405 |
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):
"""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 | [
"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 | train | 223,406 |
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):
"""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 | [
"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 | train | 223,407 |
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):
"""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 | [
"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 | train | 223,408 |
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):
"""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 | [
"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 | train | 223,409 |
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):
"""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 | [
"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 | train | 223,410 |
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):
"""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))) | [
"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 | train | 223,411 |
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):
"""Print line header and values in a readable format."""
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 | train | 223,412 |
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=""):
"""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))) | [
"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 | train | 223,413 |
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):
"""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) | [
"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 | train | 223,414 |
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):
"""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 | [
"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 | train | 223,415 |
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):
"""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) | [
"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 | train | 223,416 |
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):
"""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 | [
"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 | train | 223,417 |
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):
"""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()) | [
"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 | train | 223,418 |
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):
"""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 | [
"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 | train | 223,419 |
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):
"""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) | [
"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 | train | 223,420 |
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):
"""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] | [
"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 | train | 223,421 |
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):
"""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 | [
"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 | train | 223,422 |
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):
"""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)) | [
"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 | train | 223,423 |
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):
"""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 | [
"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 | train | 223,424 |
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):
"""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) | [
"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 | train | 223,425 |
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):
"""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" | [
"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 | train | 223,426 |
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):
"""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)))) | [
"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 | train | 223,427 |
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):
"""Print a summary of all Evidence Codes seen in annotations"""
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 | train | 223,428 |
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):
"""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 | [
"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 | train | 223,429 |
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):
"""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 | [
"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 | train | 223,430 |
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):
"""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 | [
"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 | train | 223,431 |
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):
"""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 | [
"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 | train | 223,432 |
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):
"""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 | [
"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 | train | 223,433 |
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):
"""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 | [
"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 | train | 223,434 |
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):
"""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) | [
"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 | train | 223,435 |
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):
"""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 | [
"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 | train | 223,436 |
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):
"""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 | [
"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 | train | 223,437 |
tanghaibao/goatools | goatools/godag_obosm.py | OboToGoDagSmall._init_go2obj | def _init_go2obj(self, **kws):
"""Initialize go2obj in small dag for source gos."""
if 'goids' in kws and 'obodag' in kws:
self.godag.go_sources = kws['goids']
obo = kws['obodag']
for goid in self.godag.go_sources:
self.godag.go2obj[goid] = obo[goid]
elif 'goid2goobj' in kws:
goid2goobj = kws['goid2goobj']
self.godag.go_sources = goid2goobj.keys()
for goid, goobj in goid2goobj.items():
self.godag.go2obj[goid] = goobj
elif 'goea_results' in kws:
goea_results = kws['goea_results']
self.godag.go_sources = [rec.GO for rec in goea_results]
self.godag.go2obj = {rec.GO:rec.goterm for rec in goea_results} | python | def _init_go2obj(self, **kws):
"""Initialize go2obj in small dag for source gos."""
if 'goids' in kws and 'obodag' in kws:
self.godag.go_sources = kws['goids']
obo = kws['obodag']
for goid in self.godag.go_sources:
self.godag.go2obj[goid] = obo[goid]
elif 'goid2goobj' in kws:
goid2goobj = kws['goid2goobj']
self.godag.go_sources = goid2goobj.keys()
for goid, goobj in goid2goobj.items():
self.godag.go2obj[goid] = goobj
elif 'goea_results' in kws:
goea_results = kws['goea_results']
self.godag.go_sources = [rec.GO for rec in goea_results]
self.godag.go2obj = {rec.GO:rec.goterm for rec in goea_results} | [
"def",
"_init_go2obj",
"(",
"self",
",",
"*",
"*",
"kws",
")",
":",
"if",
"'goids'",
"in",
"kws",
"and",
"'obodag'",
"in",
"kws",
":",
"self",
".",
"godag",
".",
"go_sources",
"=",
"kws",
"[",
"'goids'",
"]",
"obo",
"=",
"kws",
"[",
"'obodag'",
"]"... | Initialize go2obj in small dag for source gos. | [
"Initialize",
"go2obj",
"in",
"small",
"dag",
"for",
"source",
"gos",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag_obosm.py#L28-L43 | train | 223,438 |
tanghaibao/goatools | goatools/godag_obosm.py | OboToGoDagSmall._init | def _init(self):
"""Given GO ids and GOTerm objects, create mini GO dag."""
for goid in self.godag.go_sources:
goobj = self.godag.go2obj[goid]
self.godag.go2obj[goid] = goobj
# Traverse up parents
if self.traverse_parent and goid not in self.seen_cids:
self._traverse_parent_objs(goobj)
# Traverse down children
if self.traverse_child and goid not in self.seen_pids:
self._traverse_child_objs(goobj) | python | def _init(self):
"""Given GO ids and GOTerm objects, create mini GO dag."""
for goid in self.godag.go_sources:
goobj = self.godag.go2obj[goid]
self.godag.go2obj[goid] = goobj
# Traverse up parents
if self.traverse_parent and goid not in self.seen_cids:
self._traverse_parent_objs(goobj)
# Traverse down children
if self.traverse_child and goid not in self.seen_pids:
self._traverse_child_objs(goobj) | [
"def",
"_init",
"(",
"self",
")",
":",
"for",
"goid",
"in",
"self",
".",
"godag",
".",
"go_sources",
":",
"goobj",
"=",
"self",
".",
"godag",
".",
"go2obj",
"[",
"goid",
"]",
"self",
".",
"godag",
".",
"go2obj",
"[",
"goid",
"]",
"=",
"goobj",
"#... | Given GO ids and GOTerm objects, create mini GO dag. | [
"Given",
"GO",
"ids",
"and",
"GOTerm",
"objects",
"create",
"mini",
"GO",
"dag",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag_obosm.py#L45-L55 | train | 223,439 |
tanghaibao/goatools | goatools/rpt/write_hierarchy_base.py | WrHierPrt.prt_hier_rec | def prt_hier_rec(self, item_id, depth=1):
"""Write hierarchy for a GO Term record and all GO IDs down to the leaf level."""
# Shortens hierarchy report by only printing the hierarchy
# for the sub-set of user-specified GO terms which are connected.
if self.include_only and item_id not in self.include_only:
return
obj = self.id2obj[item_id]
# Optionally space the branches for readability
if self.space_branches:
if depth == 1 and obj.children:
self.prt.write("\n")
# Print marks if provided
if self.item_marks:
self.prt.write('{MARK} '.format(
MARK=self.item_marks.get(item_id, self.mark_dflt)))
no_repeat = self.concise_prt and item_id in self.items_printed
# Print content
dashes = self._str_dash(depth, no_repeat, obj)
if self.do_prtfmt:
self._prtfmt(item_id, dashes)
else:
self._prtstr(obj, dashes)
self.items_printed.add(item_id)
self.items_list.append(item_id)
# Do not print hierarchy below this turn if it has already been printed
if no_repeat:
return
depth += 1
if self.max_indent is not None and depth > self.max_indent:
return
children = obj.children if self.sortby is None else sorted(obj.children, key=self.sortby)
for child in children:
self.prt_hier_rec(child.item_id, depth) | python | def prt_hier_rec(self, item_id, depth=1):
"""Write hierarchy for a GO Term record and all GO IDs down to the leaf level."""
# Shortens hierarchy report by only printing the hierarchy
# for the sub-set of user-specified GO terms which are connected.
if self.include_only and item_id not in self.include_only:
return
obj = self.id2obj[item_id]
# Optionally space the branches for readability
if self.space_branches:
if depth == 1 and obj.children:
self.prt.write("\n")
# Print marks if provided
if self.item_marks:
self.prt.write('{MARK} '.format(
MARK=self.item_marks.get(item_id, self.mark_dflt)))
no_repeat = self.concise_prt and item_id in self.items_printed
# Print content
dashes = self._str_dash(depth, no_repeat, obj)
if self.do_prtfmt:
self._prtfmt(item_id, dashes)
else:
self._prtstr(obj, dashes)
self.items_printed.add(item_id)
self.items_list.append(item_id)
# Do not print hierarchy below this turn if it has already been printed
if no_repeat:
return
depth += 1
if self.max_indent is not None and depth > self.max_indent:
return
children = obj.children if self.sortby is None else sorted(obj.children, key=self.sortby)
for child in children:
self.prt_hier_rec(child.item_id, depth) | [
"def",
"prt_hier_rec",
"(",
"self",
",",
"item_id",
",",
"depth",
"=",
"1",
")",
":",
"# Shortens hierarchy report by only printing the hierarchy",
"# for the sub-set of user-specified GO terms which are connected.",
"if",
"self",
".",
"include_only",
"and",
"item_id",
"not",... | Write hierarchy for a GO Term record and all GO IDs down to the leaf level. | [
"Write",
"hierarchy",
"for",
"a",
"GO",
"Term",
"record",
"and",
"all",
"GO",
"IDs",
"down",
"to",
"the",
"leaf",
"level",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/write_hierarchy_base.py#L34-L68 | train | 223,440 |
tanghaibao/goatools | goatools/rpt/write_hierarchy_base.py | WrHierPrt._init_item_marks | def _init_item_marks(item_marks):
"""Initialize the makred item dict."""
if isinstance(item_marks, dict):
return item_marks
if item_marks:
return {item_id:'>' for item_id in item_marks} | python | def _init_item_marks(item_marks):
"""Initialize the makred item dict."""
if isinstance(item_marks, dict):
return item_marks
if item_marks:
return {item_id:'>' for item_id in item_marks} | [
"def",
"_init_item_marks",
"(",
"item_marks",
")",
":",
"if",
"isinstance",
"(",
"item_marks",
",",
"dict",
")",
":",
"return",
"item_marks",
"if",
"item_marks",
":",
"return",
"{",
"item_id",
":",
"'>'",
"for",
"item_id",
"in",
"item_marks",
"}"
] | Initialize the makred item dict. | [
"Initialize",
"the",
"makred",
"item",
"dict",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/write_hierarchy_base.py#L97-L102 | train | 223,441 |
tanghaibao/goatools | goatools/obo_parser.py | OBOReader._add_to_obj | def _add_to_obj(self, rec_curr, typedef_curr, line):
"""Add information on line to GOTerm or Typedef."""
if rec_curr is not None:
self._add_to_ref(rec_curr, line)
else:
add_to_typedef(typedef_curr, line) | python | def _add_to_obj(self, rec_curr, typedef_curr, line):
"""Add information on line to GOTerm or Typedef."""
if rec_curr is not None:
self._add_to_ref(rec_curr, line)
else:
add_to_typedef(typedef_curr, line) | [
"def",
"_add_to_obj",
"(",
"self",
",",
"rec_curr",
",",
"typedef_curr",
",",
"line",
")",
":",
"if",
"rec_curr",
"is",
"not",
"None",
":",
"self",
".",
"_add_to_ref",
"(",
"rec_curr",
",",
"line",
")",
"else",
":",
"add_to_typedef",
"(",
"typedef_curr",
... | Add information on line to GOTerm or Typedef. | [
"Add",
"information",
"on",
"line",
"to",
"GOTerm",
"or",
"Typedef",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L87-L92 | train | 223,442 |
tanghaibao/goatools | goatools/obo_parser.py | OBOReader._init_obo_version | def _init_obo_version(self, line):
"""Save obo version and release."""
if line[0:14] == "format-version":
self.format_version = line[16:-1]
if line[0:12] == "data-version":
self.data_version = line[14:-1] | python | def _init_obo_version(self, line):
"""Save obo version and release."""
if line[0:14] == "format-version":
self.format_version = line[16:-1]
if line[0:12] == "data-version":
self.data_version = line[14:-1] | [
"def",
"_init_obo_version",
"(",
"self",
",",
"line",
")",
":",
"if",
"line",
"[",
"0",
":",
"14",
"]",
"==",
"\"format-version\"",
":",
"self",
".",
"format_version",
"=",
"line",
"[",
"16",
":",
"-",
"1",
"]",
"if",
"line",
"[",
"0",
":",
"12",
... | Save obo version and release. | [
"Save",
"obo",
"version",
"and",
"release",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L94-L99 | train | 223,443 |
tanghaibao/goatools | goatools/obo_parser.py | OBOReader._init_optional_attrs | def _init_optional_attrs(optional_attrs):
"""Create OboOptionalAttrs or return None."""
if optional_attrs is None:
return None
opts = OboOptionalAttrs.get_optional_attrs(optional_attrs)
if opts:
return OboOptionalAttrs(opts) | python | def _init_optional_attrs(optional_attrs):
"""Create OboOptionalAttrs or return None."""
if optional_attrs is None:
return None
opts = OboOptionalAttrs.get_optional_attrs(optional_attrs)
if opts:
return OboOptionalAttrs(opts) | [
"def",
"_init_optional_attrs",
"(",
"optional_attrs",
")",
":",
"if",
"optional_attrs",
"is",
"None",
":",
"return",
"None",
"opts",
"=",
"OboOptionalAttrs",
".",
"get_optional_attrs",
"(",
"optional_attrs",
")",
"if",
"opts",
":",
"return",
"OboOptionalAttrs",
"(... | Create OboOptionalAttrs or return None. | [
"Create",
"OboOptionalAttrs",
"or",
"return",
"None",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L130-L136 | train | 223,444 |
tanghaibao/goatools | goatools/obo_parser.py | GOTerm.has_parent | def has_parent(self, term):
"""Return True if this GO object has a parent GO ID."""
for parent in self.parents:
if parent.item_id == term or parent.has_parent(term):
return True
return False | python | def has_parent(self, term):
"""Return True if this GO object has a parent GO ID."""
for parent in self.parents:
if parent.item_id == term or parent.has_parent(term):
return True
return False | [
"def",
"has_parent",
"(",
"self",
",",
"term",
")",
":",
"for",
"parent",
"in",
"self",
".",
"parents",
":",
"if",
"parent",
".",
"item_id",
"==",
"term",
"or",
"parent",
".",
"has_parent",
"(",
"term",
")",
":",
"return",
"True",
"return",
"False"
] | Return True if this GO object has a parent GO ID. | [
"Return",
"True",
"if",
"this",
"GO",
"object",
"has",
"a",
"parent",
"GO",
"ID",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L191-L196 | train | 223,445 |
tanghaibao/goatools | goatools/obo_parser.py | GOTerm.has_child | def has_child(self, term):
"""Return True if this GO object has a child GO ID."""
for parent in self.children:
if parent.item_id == term or parent.has_child(term):
return True
return False | python | def has_child(self, term):
"""Return True if this GO object has a child GO ID."""
for parent in self.children:
if parent.item_id == term or parent.has_child(term):
return True
return False | [
"def",
"has_child",
"(",
"self",
",",
"term",
")",
":",
"for",
"parent",
"in",
"self",
".",
"children",
":",
"if",
"parent",
".",
"item_id",
"==",
"term",
"or",
"parent",
".",
"has_child",
"(",
"term",
")",
":",
"return",
"True",
"return",
"False"
] | Return True if this GO object has a child GO ID. | [
"Return",
"True",
"if",
"this",
"GO",
"object",
"has",
"a",
"child",
"GO",
"ID",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L198-L203 | train | 223,446 |
tanghaibao/goatools | goatools/obo_parser.py | GOTerm.get_all_parents | def get_all_parents(self):
"""Return all parent GO IDs."""
all_parents = set()
for parent in self.parents:
all_parents.add(parent.item_id)
all_parents |= parent.get_all_parents()
return all_parents | python | def get_all_parents(self):
"""Return all parent GO IDs."""
all_parents = set()
for parent in self.parents:
all_parents.add(parent.item_id)
all_parents |= parent.get_all_parents()
return all_parents | [
"def",
"get_all_parents",
"(",
"self",
")",
":",
"all_parents",
"=",
"set",
"(",
")",
"for",
"parent",
"in",
"self",
".",
"parents",
":",
"all_parents",
".",
"add",
"(",
"parent",
".",
"item_id",
")",
"all_parents",
"|=",
"parent",
".",
"get_all_parents",
... | Return all parent GO IDs. | [
"Return",
"all",
"parent",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L205-L211 | train | 223,447 |
tanghaibao/goatools | goatools/obo_parser.py | GOTerm.get_all_upper | def get_all_upper(self):
"""Return all parent GO IDs through both 'is_a' and all relationships."""
all_upper = set()
for upper in self.get_goterms_upper():
all_upper.add(upper.item_id)
all_upper |= upper.get_all_upper()
return all_upper | python | def get_all_upper(self):
"""Return all parent GO IDs through both 'is_a' and all relationships."""
all_upper = set()
for upper in self.get_goterms_upper():
all_upper.add(upper.item_id)
all_upper |= upper.get_all_upper()
return all_upper | [
"def",
"get_all_upper",
"(",
"self",
")",
":",
"all_upper",
"=",
"set",
"(",
")",
"for",
"upper",
"in",
"self",
".",
"get_goterms_upper",
"(",
")",
":",
"all_upper",
".",
"add",
"(",
"upper",
".",
"item_id",
")",
"all_upper",
"|=",
"upper",
".",
"get_a... | Return all parent GO IDs through both 'is_a' and all relationships. | [
"Return",
"all",
"parent",
"GO",
"IDs",
"through",
"both",
"is_a",
"and",
"all",
"relationships",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L213-L219 | train | 223,448 |
tanghaibao/goatools | goatools/obo_parser.py | GOTerm.get_all_children | def get_all_children(self):
"""Return all children GO IDs."""
all_children = set()
for parent in self.children:
all_children.add(parent.item_id)
all_children |= parent.get_all_children()
return all_children | python | def get_all_children(self):
"""Return all children GO IDs."""
all_children = set()
for parent in self.children:
all_children.add(parent.item_id)
all_children |= parent.get_all_children()
return all_children | [
"def",
"get_all_children",
"(",
"self",
")",
":",
"all_children",
"=",
"set",
"(",
")",
"for",
"parent",
"in",
"self",
".",
"children",
":",
"all_children",
".",
"add",
"(",
"parent",
".",
"item_id",
")",
"all_children",
"|=",
"parent",
".",
"get_all_child... | Return all children GO IDs. | [
"Return",
"all",
"children",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L221-L227 | train | 223,449 |
tanghaibao/goatools | goatools/obo_parser.py | GOTerm.get_all_lower | def get_all_lower(self):
"""Return all parent GO IDs through both reverse 'is_a' and all relationships."""
all_lower = set()
for lower in self.get_goterms_lower():
all_lower.add(lower.item_id)
all_lower |= lower.get_all_lower()
return all_lower | python | def get_all_lower(self):
"""Return all parent GO IDs through both reverse 'is_a' and all relationships."""
all_lower = set()
for lower in self.get_goterms_lower():
all_lower.add(lower.item_id)
all_lower |= lower.get_all_lower()
return all_lower | [
"def",
"get_all_lower",
"(",
"self",
")",
":",
"all_lower",
"=",
"set",
"(",
")",
"for",
"lower",
"in",
"self",
".",
"get_goterms_lower",
"(",
")",
":",
"all_lower",
".",
"add",
"(",
"lower",
".",
"item_id",
")",
"all_lower",
"|=",
"lower",
".",
"get_a... | Return all parent GO IDs through both reverse 'is_a' and all relationships. | [
"Return",
"all",
"parent",
"GO",
"IDs",
"through",
"both",
"reverse",
"is_a",
"and",
"all",
"relationships",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L229-L235 | train | 223,450 |
tanghaibao/goatools | goatools/obo_parser.py | GOTerm.get_all_parent_edges | def get_all_parent_edges(self):
"""Return tuples for all parent GO IDs, containing current GO ID and parent GO ID."""
all_parent_edges = set()
for parent in self.parents:
all_parent_edges.add((self.item_id, parent.item_id))
all_parent_edges |= parent.get_all_parent_edges()
return all_parent_edges | python | def get_all_parent_edges(self):
"""Return tuples for all parent GO IDs, containing current GO ID and parent GO ID."""
all_parent_edges = set()
for parent in self.parents:
all_parent_edges.add((self.item_id, parent.item_id))
all_parent_edges |= parent.get_all_parent_edges()
return all_parent_edges | [
"def",
"get_all_parent_edges",
"(",
"self",
")",
":",
"all_parent_edges",
"=",
"set",
"(",
")",
"for",
"parent",
"in",
"self",
".",
"parents",
":",
"all_parent_edges",
".",
"add",
"(",
"(",
"self",
".",
"item_id",
",",
"parent",
".",
"item_id",
")",
")",... | Return tuples for all parent GO IDs, containing current GO ID and parent GO ID. | [
"Return",
"tuples",
"for",
"all",
"parent",
"GO",
"IDs",
"containing",
"current",
"GO",
"ID",
"and",
"parent",
"GO",
"ID",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L237-L243 | train | 223,451 |
tanghaibao/goatools | goatools/obo_parser.py | GOTerm.get_all_child_edges | def get_all_child_edges(self):
"""Return tuples for all child GO IDs, containing current GO ID and child GO ID."""
all_child_edges = set()
for parent in self.children:
all_child_edges.add((parent.item_id, self.item_id))
all_child_edges |= parent.get_all_child_edges()
return all_child_edges | python | def get_all_child_edges(self):
"""Return tuples for all child GO IDs, containing current GO ID and child GO ID."""
all_child_edges = set()
for parent in self.children:
all_child_edges.add((parent.item_id, self.item_id))
all_child_edges |= parent.get_all_child_edges()
return all_child_edges | [
"def",
"get_all_child_edges",
"(",
"self",
")",
":",
"all_child_edges",
"=",
"set",
"(",
")",
"for",
"parent",
"in",
"self",
".",
"children",
":",
"all_child_edges",
".",
"add",
"(",
"(",
"parent",
".",
"item_id",
",",
"self",
".",
"item_id",
")",
")",
... | Return tuples for all child GO IDs, containing current GO ID and child GO ID. | [
"Return",
"tuples",
"for",
"all",
"child",
"GO",
"IDs",
"containing",
"current",
"GO",
"ID",
"and",
"child",
"GO",
"ID",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L245-L251 | train | 223,452 |
tanghaibao/goatools | goatools/obo_parser.py | GODag.load_obo_file | def load_obo_file(self, obo_file, optional_attrs, load_obsolete, prt):
"""Read obo file. Store results."""
reader = OBOReader(obo_file, optional_attrs)
# Save alt_ids and their corresponding main GO ID. Add to GODag after populating GO Terms
alt2rec = {}
for rec in reader:
# Save record if:
# 1) Argument load_obsolete is True OR
# 2) Argument load_obsolete is False and the GO term is "live" (not obsolete)
if load_obsolete or not rec.is_obsolete:
self[rec.item_id] = rec
for alt in rec.alt_ids:
alt2rec[alt] = rec
# Save the typedefs and parsed optional_attrs
# self.optobj = reader.optobj
self.typedefs = reader.typedefs
self._populate_terms(reader.optobj)
self._set_level_depth(reader.optobj)
# Add alt_ids to go2obj
for goid_alt, rec in alt2rec.items():
self[goid_alt] = rec
desc = self._str_desc(reader)
if prt is not None:
prt.write("{DESC}\n".format(DESC=desc))
return desc | python | def load_obo_file(self, obo_file, optional_attrs, load_obsolete, prt):
"""Read obo file. Store results."""
reader = OBOReader(obo_file, optional_attrs)
# Save alt_ids and their corresponding main GO ID. Add to GODag after populating GO Terms
alt2rec = {}
for rec in reader:
# Save record if:
# 1) Argument load_obsolete is True OR
# 2) Argument load_obsolete is False and the GO term is "live" (not obsolete)
if load_obsolete or not rec.is_obsolete:
self[rec.item_id] = rec
for alt in rec.alt_ids:
alt2rec[alt] = rec
# Save the typedefs and parsed optional_attrs
# self.optobj = reader.optobj
self.typedefs = reader.typedefs
self._populate_terms(reader.optobj)
self._set_level_depth(reader.optobj)
# Add alt_ids to go2obj
for goid_alt, rec in alt2rec.items():
self[goid_alt] = rec
desc = self._str_desc(reader)
if prt is not None:
prt.write("{DESC}\n".format(DESC=desc))
return desc | [
"def",
"load_obo_file",
"(",
"self",
",",
"obo_file",
",",
"optional_attrs",
",",
"load_obsolete",
",",
"prt",
")",
":",
"reader",
"=",
"OBOReader",
"(",
"obo_file",
",",
"optional_attrs",
")",
"# Save alt_ids and their corresponding main GO ID. Add to GODag after populat... | Read obo file. Store results. | [
"Read",
"obo",
"file",
".",
"Store",
"results",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L312-L340 | train | 223,453 |
tanghaibao/goatools | goatools/obo_parser.py | GODag._str_desc | def _str_desc(self, reader):
"""String containing information about the current GO DAG."""
data_version = reader.data_version
if data_version is not None:
data_version = data_version.replace("releases/", "")
desc = "{OBO}: fmt({FMT}) rel({REL}) {N:,} GO Terms".format(
OBO=reader.obo_file, FMT=reader.format_version,
REL=data_version, N=len(self))
if reader.optobj:
desc = "{D}; optional_attrs({A})".format(D=desc, A=" ".join(sorted(reader.optobj.optional_attrs)))
return desc | python | def _str_desc(self, reader):
"""String containing information about the current GO DAG."""
data_version = reader.data_version
if data_version is not None:
data_version = data_version.replace("releases/", "")
desc = "{OBO}: fmt({FMT}) rel({REL}) {N:,} GO Terms".format(
OBO=reader.obo_file, FMT=reader.format_version,
REL=data_version, N=len(self))
if reader.optobj:
desc = "{D}; optional_attrs({A})".format(D=desc, A=" ".join(sorted(reader.optobj.optional_attrs)))
return desc | [
"def",
"_str_desc",
"(",
"self",
",",
"reader",
")",
":",
"data_version",
"=",
"reader",
".",
"data_version",
"if",
"data_version",
"is",
"not",
"None",
":",
"data_version",
"=",
"data_version",
".",
"replace",
"(",
"\"releases/\"",
",",
"\"\"",
")",
"desc",... | String containing information about the current GO DAG. | [
"String",
"containing",
"information",
"about",
"the",
"current",
"GO",
"DAG",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L342-L352 | train | 223,454 |
tanghaibao/goatools | goatools/obo_parser.py | GODag._populate_terms | def _populate_terms(self, optobj):
"""Convert GO IDs to GO Term record objects. Populate children."""
has_relationship = optobj is not None and 'relationship' in optobj.optional_attrs
# Make parents and relationships references to the actual GO terms.
for rec in self.values():
# Given parent GO IDs, set parent GO Term objects
rec.parents = set([self[goid] for goid in rec._parents])
# For each parent GO Term object, add it's child GO Term to the children data member
for parent_rec in rec.parents:
parent_rec.children.add(rec)
if has_relationship:
self._populate_relationships(rec) | python | def _populate_terms(self, optobj):
"""Convert GO IDs to GO Term record objects. Populate children."""
has_relationship = optobj is not None and 'relationship' in optobj.optional_attrs
# Make parents and relationships references to the actual GO terms.
for rec in self.values():
# Given parent GO IDs, set parent GO Term objects
rec.parents = set([self[goid] for goid in rec._parents])
# For each parent GO Term object, add it's child GO Term to the children data member
for parent_rec in rec.parents:
parent_rec.children.add(rec)
if has_relationship:
self._populate_relationships(rec) | [
"def",
"_populate_terms",
"(",
"self",
",",
"optobj",
")",
":",
"has_relationship",
"=",
"optobj",
"is",
"not",
"None",
"and",
"'relationship'",
"in",
"optobj",
".",
"optional_attrs",
"# Make parents and relationships references to the actual GO terms.",
"for",
"rec",
"... | Convert GO IDs to GO Term record objects. Populate children. | [
"Convert",
"GO",
"IDs",
"to",
"GO",
"Term",
"record",
"objects",
".",
"Populate",
"children",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L355-L368 | train | 223,455 |
tanghaibao/goatools | goatools/obo_parser.py | GODag._populate_relationships | def _populate_relationships(self, rec_curr):
"""Convert GO IDs in relationships to GO Term record objects. Populate children."""
for relationship_type, goids in rec_curr.relationship.items():
parent_recs = set([self[goid] for goid in goids])
rec_curr.relationship[relationship_type] = parent_recs
for parent_rec in parent_recs:
if relationship_type not in parent_rec.relationship_rev:
parent_rec.relationship_rev[relationship_type] = set([rec_curr])
else:
parent_rec.relationship_rev[relationship_type].add(rec_curr) | python | def _populate_relationships(self, rec_curr):
"""Convert GO IDs in relationships to GO Term record objects. Populate children."""
for relationship_type, goids in rec_curr.relationship.items():
parent_recs = set([self[goid] for goid in goids])
rec_curr.relationship[relationship_type] = parent_recs
for parent_rec in parent_recs:
if relationship_type not in parent_rec.relationship_rev:
parent_rec.relationship_rev[relationship_type] = set([rec_curr])
else:
parent_rec.relationship_rev[relationship_type].add(rec_curr) | [
"def",
"_populate_relationships",
"(",
"self",
",",
"rec_curr",
")",
":",
"for",
"relationship_type",
",",
"goids",
"in",
"rec_curr",
".",
"relationship",
".",
"items",
"(",
")",
":",
"parent_recs",
"=",
"set",
"(",
"[",
"self",
"[",
"goid",
"]",
"for",
... | Convert GO IDs in relationships to GO Term record objects. Populate children. | [
"Convert",
"GO",
"IDs",
"in",
"relationships",
"to",
"GO",
"Term",
"record",
"objects",
".",
"Populate",
"children",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L370-L379 | train | 223,456 |
tanghaibao/goatools | goatools/obo_parser.py | GODag._set_level_depth | def _set_level_depth(self, optobj):
"""Set level, depth and add inverted relationships."""
has_relationship = optobj is not None and 'relationship' in optobj.optional_attrs
def _init_level(rec):
if rec.level is None:
if rec.parents:
rec.level = min(_init_level(rec) for rec in rec.parents) + 1
else:
rec.level = 0
return rec.level
def _init_depth(rec):
if rec.depth is None:
if rec.parents:
rec.depth = max(_init_depth(rec) for rec in rec.parents) + 1
else:
rec.depth = 0
return rec.depth
def _init_reldepth(rec):
if not hasattr(rec, 'reldepth'):
up_terms = rec.get_goterms_upper()
if up_terms:
rec.reldepth = max(_init_reldepth(rec) for rec in up_terms) + 1
else:
rec.reldepth = 0
return rec.reldepth
for rec in self.values():
# Add invert relationships
if has_relationship:
if rec.depth is None:
_init_reldepth(rec)
# print("BBBBBBBBBBB1", rec.item_id, rec.relationship)
#for (typedef, terms) in rec.relationship.items():
# invert_typedef = self.typedefs[typedef].inverse_of
# # print("BBBBBBBBBBB2 {} ({}) ({}) ({})".format(
# # rec.item_id, rec.relationship, typedef, invert_typedef))
# if invert_typedef:
# # Add inverted relationship
# for term in terms:
# if not hasattr(term, 'relationship'):
# term.relationship = defaultdict(set)
# term.relationship[invert_typedef].add(rec)
# print("BBBBBBBBBBB3", rec.item_id, rec.relationship)
if rec.level is None:
_init_level(rec)
if rec.depth is None:
_init_depth(rec) | python | def _set_level_depth(self, optobj):
"""Set level, depth and add inverted relationships."""
has_relationship = optobj is not None and 'relationship' in optobj.optional_attrs
def _init_level(rec):
if rec.level is None:
if rec.parents:
rec.level = min(_init_level(rec) for rec in rec.parents) + 1
else:
rec.level = 0
return rec.level
def _init_depth(rec):
if rec.depth is None:
if rec.parents:
rec.depth = max(_init_depth(rec) for rec in rec.parents) + 1
else:
rec.depth = 0
return rec.depth
def _init_reldepth(rec):
if not hasattr(rec, 'reldepth'):
up_terms = rec.get_goterms_upper()
if up_terms:
rec.reldepth = max(_init_reldepth(rec) for rec in up_terms) + 1
else:
rec.reldepth = 0
return rec.reldepth
for rec in self.values():
# Add invert relationships
if has_relationship:
if rec.depth is None:
_init_reldepth(rec)
# print("BBBBBBBBBBB1", rec.item_id, rec.relationship)
#for (typedef, terms) in rec.relationship.items():
# invert_typedef = self.typedefs[typedef].inverse_of
# # print("BBBBBBBBBBB2 {} ({}) ({}) ({})".format(
# # rec.item_id, rec.relationship, typedef, invert_typedef))
# if invert_typedef:
# # Add inverted relationship
# for term in terms:
# if not hasattr(term, 'relationship'):
# term.relationship = defaultdict(set)
# term.relationship[invert_typedef].add(rec)
# print("BBBBBBBBBBB3", rec.item_id, rec.relationship)
if rec.level is None:
_init_level(rec)
if rec.depth is None:
_init_depth(rec) | [
"def",
"_set_level_depth",
"(",
"self",
",",
"optobj",
")",
":",
"has_relationship",
"=",
"optobj",
"is",
"not",
"None",
"and",
"'relationship'",
"in",
"optobj",
".",
"optional_attrs",
"def",
"_init_level",
"(",
"rec",
")",
":",
"if",
"rec",
".",
"level",
... | Set level, depth and add inverted relationships. | [
"Set",
"level",
"depth",
"and",
"add",
"inverted",
"relationships",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L381-L434 | train | 223,457 |
tanghaibao/goatools | goatools/obo_parser.py | GODag.write_dag | def write_dag(self, out=sys.stdout):
"""Write info for all GO Terms in obo file, sorted numerically."""
for rec in sorted(self.values()):
print(rec, file=out) | python | def write_dag(self, out=sys.stdout):
"""Write info for all GO Terms in obo file, sorted numerically."""
for rec in sorted(self.values()):
print(rec, file=out) | [
"def",
"write_dag",
"(",
"self",
",",
"out",
"=",
"sys",
".",
"stdout",
")",
":",
"for",
"rec",
"in",
"sorted",
"(",
"self",
".",
"values",
"(",
")",
")",
":",
"print",
"(",
"rec",
",",
"file",
"=",
"out",
")"
] | Write info for all GO Terms in obo file, sorted numerically. | [
"Write",
"info",
"for",
"all",
"GO",
"Terms",
"in",
"obo",
"file",
"sorted",
"numerically",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L436-L439 | train | 223,458 |
tanghaibao/goatools | goatools/obo_parser.py | GODag.query_term | def query_term(self, term, verbose=False):
"""Given a GO ID, return GO object."""
if term not in self:
sys.stderr.write("Term %s not found!\n" % term)
return
rec = self[term]
if verbose:
print(rec)
sys.stderr.write("all parents: {}\n".format(
repr(rec.get_all_parents())))
sys.stderr.write("all children: {}\n".format(
repr(rec.get_all_children())))
return rec | python | def query_term(self, term, verbose=False):
"""Given a GO ID, return GO object."""
if term not in self:
sys.stderr.write("Term %s not found!\n" % term)
return
rec = self[term]
if verbose:
print(rec)
sys.stderr.write("all parents: {}\n".format(
repr(rec.get_all_parents())))
sys.stderr.write("all children: {}\n".format(
repr(rec.get_all_children())))
return rec | [
"def",
"query_term",
"(",
"self",
",",
"term",
",",
"verbose",
"=",
"False",
")",
":",
"if",
"term",
"not",
"in",
"self",
":",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"Term %s not found!\\n\"",
"%",
"term",
")",
"return",
"rec",
"=",
"self",
"[",
... | Given a GO ID, return GO object. | [
"Given",
"a",
"GO",
"ID",
"return",
"GO",
"object",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L461-L474 | train | 223,459 |
tanghaibao/goatools | goatools/obo_parser.py | GODag.label_wrap | def label_wrap(self, label):
"""Label text for plot."""
wrapped_label = r"%s\n%s" % (label,
self[label].name.replace(",", r"\n"))
return wrapped_label | python | def label_wrap(self, label):
"""Label text for plot."""
wrapped_label = r"%s\n%s" % (label,
self[label].name.replace(",", r"\n"))
return wrapped_label | [
"def",
"label_wrap",
"(",
"self",
",",
"label",
")",
":",
"wrapped_label",
"=",
"r\"%s\\n%s\"",
"%",
"(",
"label",
",",
"self",
"[",
"label",
"]",
".",
"name",
".",
"replace",
"(",
"\",\"",
",",
"r\"\\n\"",
")",
")",
"return",
"wrapped_label"
] | Label text for plot. | [
"Label",
"text",
"for",
"plot",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L512-L516 | train | 223,460 |
tanghaibao/goatools | goatools/obo_parser.py | GODag.make_graph_pygraphviz | def make_graph_pygraphviz(self, recs, nodecolor,
edgecolor, dpi,
draw_parents=True, draw_children=True):
"""Draw AMIGO style network, lineage containing one query record."""
import pygraphviz as pgv
grph = pgv.AGraph(name="GO tree")
edgeset = set()
for rec in recs:
if draw_parents:
edgeset.update(rec.get_all_parent_edges())
if draw_children:
edgeset.update(rec.get_all_child_edges())
edgeset = [(self.label_wrap(a), self.label_wrap(b))
for (a, b) in edgeset]
# add nodes explicitly via add_node
# adding nodes implicitly via add_edge misses nodes
# without at least one edge
for rec in recs:
grph.add_node(self.label_wrap(rec.item_id))
for src, target in edgeset:
# default layout in graphviz is top->bottom, so we invert
# the direction and plot using dir="back"
grph.add_edge(target, src)
grph.graph_attr.update(dpi="%d" % dpi)
grph.node_attr.update(shape="box", style="rounded,filled",
fillcolor="beige", color=nodecolor)
grph.edge_attr.update(shape="normal", color=edgecolor,
dir="back", label="is_a")
# highlight the query terms
for rec in recs:
try:
node = grph.get_node(self.label_wrap(rec.item_id))
node.attr.update(fillcolor="plum")
except:
continue
return grph | python | def make_graph_pygraphviz(self, recs, nodecolor,
edgecolor, dpi,
draw_parents=True, draw_children=True):
"""Draw AMIGO style network, lineage containing one query record."""
import pygraphviz as pgv
grph = pgv.AGraph(name="GO tree")
edgeset = set()
for rec in recs:
if draw_parents:
edgeset.update(rec.get_all_parent_edges())
if draw_children:
edgeset.update(rec.get_all_child_edges())
edgeset = [(self.label_wrap(a), self.label_wrap(b))
for (a, b) in edgeset]
# add nodes explicitly via add_node
# adding nodes implicitly via add_edge misses nodes
# without at least one edge
for rec in recs:
grph.add_node(self.label_wrap(rec.item_id))
for src, target in edgeset:
# default layout in graphviz is top->bottom, so we invert
# the direction and plot using dir="back"
grph.add_edge(target, src)
grph.graph_attr.update(dpi="%d" % dpi)
grph.node_attr.update(shape="box", style="rounded,filled",
fillcolor="beige", color=nodecolor)
grph.edge_attr.update(shape="normal", color=edgecolor,
dir="back", label="is_a")
# highlight the query terms
for rec in recs:
try:
node = grph.get_node(self.label_wrap(rec.item_id))
node.attr.update(fillcolor="plum")
except:
continue
return grph | [
"def",
"make_graph_pygraphviz",
"(",
"self",
",",
"recs",
",",
"nodecolor",
",",
"edgecolor",
",",
"dpi",
",",
"draw_parents",
"=",
"True",
",",
"draw_children",
"=",
"True",
")",
":",
"import",
"pygraphviz",
"as",
"pgv",
"grph",
"=",
"pgv",
".",
"AGraph",... | Draw AMIGO style network, lineage containing one query record. | [
"Draw",
"AMIGO",
"style",
"network",
"lineage",
"containing",
"one",
"query",
"record",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L557-L599 | train | 223,461 |
tanghaibao/goatools | goatools/obo_parser.py | GODag.draw_lineage | def draw_lineage(self, recs, nodecolor="mediumseagreen",
edgecolor="lightslateblue", dpi=96,
lineage_img="GO_lineage.png", engine="pygraphviz",
gml=False, draw_parents=True, draw_children=True):
"""Draw GO DAG subplot."""
assert engine in GraphEngines
grph = None
if engine == "pygraphviz":
grph = self.make_graph_pygraphviz(recs, nodecolor, edgecolor, dpi,
draw_parents=draw_parents,
draw_children=draw_children)
else:
grph = self.make_graph_pydot(recs, nodecolor, edgecolor, dpi,
draw_parents=draw_parents, draw_children=draw_children)
if gml:
import networkx as nx # use networkx to do the conversion
gmlbase = lineage_img.rsplit(".", 1)[0]
obj = nx.from_agraph(grph) if engine == "pygraphviz" else nx.from_pydot(grph)
del obj.graph['node']
del obj.graph['edge']
gmlfile = gmlbase + ".gml"
nx.write_gml(self.label_wrap, gmlfile)
sys.stderr.write("GML graph written to {0}\n".format(gmlfile))
sys.stderr.write(("lineage info for terms %s written to %s\n" %
([rec.item_id for rec in recs], lineage_img)))
if engine == "pygraphviz":
grph.draw(lineage_img, prog="dot")
else:
grph.write_png(lineage_img) | python | def draw_lineage(self, recs, nodecolor="mediumseagreen",
edgecolor="lightslateblue", dpi=96,
lineage_img="GO_lineage.png", engine="pygraphviz",
gml=False, draw_parents=True, draw_children=True):
"""Draw GO DAG subplot."""
assert engine in GraphEngines
grph = None
if engine == "pygraphviz":
grph = self.make_graph_pygraphviz(recs, nodecolor, edgecolor, dpi,
draw_parents=draw_parents,
draw_children=draw_children)
else:
grph = self.make_graph_pydot(recs, nodecolor, edgecolor, dpi,
draw_parents=draw_parents, draw_children=draw_children)
if gml:
import networkx as nx # use networkx to do the conversion
gmlbase = lineage_img.rsplit(".", 1)[0]
obj = nx.from_agraph(grph) if engine == "pygraphviz" else nx.from_pydot(grph)
del obj.graph['node']
del obj.graph['edge']
gmlfile = gmlbase + ".gml"
nx.write_gml(self.label_wrap, gmlfile)
sys.stderr.write("GML graph written to {0}\n".format(gmlfile))
sys.stderr.write(("lineage info for terms %s written to %s\n" %
([rec.item_id for rec in recs], lineage_img)))
if engine == "pygraphviz":
grph.draw(lineage_img, prog="dot")
else:
grph.write_png(lineage_img) | [
"def",
"draw_lineage",
"(",
"self",
",",
"recs",
",",
"nodecolor",
"=",
"\"mediumseagreen\"",
",",
"edgecolor",
"=",
"\"lightslateblue\"",
",",
"dpi",
"=",
"96",
",",
"lineage_img",
"=",
"\"GO_lineage.png\"",
",",
"engine",
"=",
"\"pygraphviz\"",
",",
"gml",
"... | Draw GO DAG subplot. | [
"Draw",
"GO",
"DAG",
"subplot",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L601-L633 | train | 223,462 |
tanghaibao/goatools | goatools/anno/init/reader_gpad.py | InitAssc._get_ntgpadvals | def _get_ntgpadvals(self, flds, add_ns):
"""Convert fields from string to preferred format for GPAD ver 2.1 and 2.0."""
is_set = False
qualifiers = self._get_qualifier(flds[2])
assert flds[3][:3] == 'GO:', 'UNRECOGNIZED GO({GO})'.format(GO=flds[3])
db_reference = self._rd_fld_vals("DB_Reference", flds[4], is_set, 1)
assert flds[5][:4] == 'ECO:', 'UNRECOGNIZED ECO({ECO})'.format(ECO=flds[3])
with_from = self._rd_fld_vals("With_From", flds[6], is_set)
taxons = self._get_taxon(flds[7])
assert flds[8].isdigit(), 'UNRECOGNIZED DATE({D})'.format(D=flds[8])
assert flds[9], '"Assigned By" VALUE WAS NOT FOUND'
props = self._get_properties(flds[11])
self._chk_qty_eq_1(flds, [0, 1, 3, 5, 8, 9])
# Additional Formatting
self._chk_qualifier(qualifiers)
# Create list of values
eco = flds[5]
goid = flds[3]
gpadvals = [
flds[0], # 0 DB
flds[1], # 1 DB_ID
qualifiers, # 3 Qualifier
flds[3], # 4 GO_ID
db_reference, # 5 DB_Reference
eco, # 6 ECO
ECO2GRP[eco],
with_from, # 7 With_From
taxons, # 12 Taxon
GET_DATE_YYYYMMDD(flds[8]), # 13 Date
flds[9], # 14 Assigned_By
get_extensions(flds[10]), # 12 Extension
props] # 12 Annotation_Properties
if add_ns:
goobj = self.godag.get(goid, '')
gpadvals.append(NAMESPACE2NS[goobj.namespace] if goobj else '')
return gpadvals | python | def _get_ntgpadvals(self, flds, add_ns):
"""Convert fields from string to preferred format for GPAD ver 2.1 and 2.0."""
is_set = False
qualifiers = self._get_qualifier(flds[2])
assert flds[3][:3] == 'GO:', 'UNRECOGNIZED GO({GO})'.format(GO=flds[3])
db_reference = self._rd_fld_vals("DB_Reference", flds[4], is_set, 1)
assert flds[5][:4] == 'ECO:', 'UNRECOGNIZED ECO({ECO})'.format(ECO=flds[3])
with_from = self._rd_fld_vals("With_From", flds[6], is_set)
taxons = self._get_taxon(flds[7])
assert flds[8].isdigit(), 'UNRECOGNIZED DATE({D})'.format(D=flds[8])
assert flds[9], '"Assigned By" VALUE WAS NOT FOUND'
props = self._get_properties(flds[11])
self._chk_qty_eq_1(flds, [0, 1, 3, 5, 8, 9])
# Additional Formatting
self._chk_qualifier(qualifiers)
# Create list of values
eco = flds[5]
goid = flds[3]
gpadvals = [
flds[0], # 0 DB
flds[1], # 1 DB_ID
qualifiers, # 3 Qualifier
flds[3], # 4 GO_ID
db_reference, # 5 DB_Reference
eco, # 6 ECO
ECO2GRP[eco],
with_from, # 7 With_From
taxons, # 12 Taxon
GET_DATE_YYYYMMDD(flds[8]), # 13 Date
flds[9], # 14 Assigned_By
get_extensions(flds[10]), # 12 Extension
props] # 12 Annotation_Properties
if add_ns:
goobj = self.godag.get(goid, '')
gpadvals.append(NAMESPACE2NS[goobj.namespace] if goobj else '')
return gpadvals | [
"def",
"_get_ntgpadvals",
"(",
"self",
",",
"flds",
",",
"add_ns",
")",
":",
"is_set",
"=",
"False",
"qualifiers",
"=",
"self",
".",
"_get_qualifier",
"(",
"flds",
"[",
"2",
"]",
")",
"assert",
"flds",
"[",
"3",
"]",
"[",
":",
"3",
"]",
"==",
"'GO:... | Convert fields from string to preferred format for GPAD ver 2.1 and 2.0. | [
"Convert",
"fields",
"from",
"string",
"to",
"preferred",
"format",
"for",
"GPAD",
"ver",
"2",
".",
"1",
"and",
"2",
".",
"0",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gpad.py#L74-L109 | train | 223,463 |
tanghaibao/goatools | goatools/anno/init/reader_gpad.py | InitAssc._rd_fld_vals | def _rd_fld_vals(name, val, set_list_ft=True, qty_min=0, qty_max=None):
"""Further split a GPAD value within a single field."""
if not val and qty_min == 0:
return [] if set_list_ft else set()
vals = val.split('|') # Use a pipe to separate entries
num_vals = len(vals)
assert num_vals >= qty_min, \
"FLD({F}): MIN QUANTITY({Q}) WASN'T MET: {V}".format(
F=name, Q=qty_min, V=vals)
if qty_max is not None:
assert num_vals <= qty_max, \
"FLD({F}): MAX QUANTITY({Q}) EXCEEDED: {V}".format(
F=name, Q=qty_max, V=vals)
return vals if set_list_ft else set(vals) | python | def _rd_fld_vals(name, val, set_list_ft=True, qty_min=0, qty_max=None):
"""Further split a GPAD value within a single field."""
if not val and qty_min == 0:
return [] if set_list_ft else set()
vals = val.split('|') # Use a pipe to separate entries
num_vals = len(vals)
assert num_vals >= qty_min, \
"FLD({F}): MIN QUANTITY({Q}) WASN'T MET: {V}".format(
F=name, Q=qty_min, V=vals)
if qty_max is not None:
assert num_vals <= qty_max, \
"FLD({F}): MAX QUANTITY({Q}) EXCEEDED: {V}".format(
F=name, Q=qty_max, V=vals)
return vals if set_list_ft else set(vals) | [
"def",
"_rd_fld_vals",
"(",
"name",
",",
"val",
",",
"set_list_ft",
"=",
"True",
",",
"qty_min",
"=",
"0",
",",
"qty_max",
"=",
"None",
")",
":",
"if",
"not",
"val",
"and",
"qty_min",
"==",
"0",
":",
"return",
"[",
"]",
"if",
"set_list_ft",
"else",
... | Further split a GPAD value within a single field. | [
"Further",
"split",
"a",
"GPAD",
"value",
"within",
"a",
"single",
"field",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gpad.py#L123-L136 | train | 223,464 |
tanghaibao/goatools | goatools/anno/init/reader_gpad.py | InitAssc._get_taxon | def _get_taxon(taxon):
"""Return Interacting taxon ID | optional | 0 or 1 | gaf column 13."""
if not taxon:
return None
## assert taxon[:6] == 'taxon:', 'UNRECOGNIZED Taxon({Taxon})'.format(Taxon=taxon)
## taxid = taxon[6:]
## assert taxon[:10] == 'NCBITaxon:', 'UNRECOGNIZED Taxon({Taxon})'.format(Taxon=taxon)
## taxid = taxon[10:]
# Get tzxon number: taxon:9606 NCBITaxon:9606
sep = taxon.find(':')
taxid = taxon[sep + 1:]
assert taxid.isdigit(), "UNEXPECTED TAXON({T})".format(T=taxid)
return int(taxid) | python | def _get_taxon(taxon):
"""Return Interacting taxon ID | optional | 0 or 1 | gaf column 13."""
if not taxon:
return None
## assert taxon[:6] == 'taxon:', 'UNRECOGNIZED Taxon({Taxon})'.format(Taxon=taxon)
## taxid = taxon[6:]
## assert taxon[:10] == 'NCBITaxon:', 'UNRECOGNIZED Taxon({Taxon})'.format(Taxon=taxon)
## taxid = taxon[10:]
# Get tzxon number: taxon:9606 NCBITaxon:9606
sep = taxon.find(':')
taxid = taxon[sep + 1:]
assert taxid.isdigit(), "UNEXPECTED TAXON({T})".format(T=taxid)
return int(taxid) | [
"def",
"_get_taxon",
"(",
"taxon",
")",
":",
"if",
"not",
"taxon",
":",
"return",
"None",
"## assert taxon[:6] == 'taxon:', 'UNRECOGNIZED Taxon({Taxon})'.format(Taxon=taxon)",
"## taxid = taxon[6:]",
"## assert taxon[:10] == 'NCBITaxon:', 'UNRECOGNIZED Taxon({Taxon})'.format(Taxon=taxon)... | Return Interacting taxon ID | optional | 0 or 1 | gaf column 13. | [
"Return",
"Interacting",
"taxon",
"ID",
"|",
"optional",
"|",
"0",
"or",
"1",
"|",
"gaf",
"column",
"13",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gpad.py#L139-L151 | train | 223,465 |
tanghaibao/goatools | goatools/anno/init/reader_gpad.py | InitAssc._get_ntgpadnt | def _get_ntgpadnt(self, ver, add_ns):
"""Create a namedtuple object for each annotation"""
hdrs = self.gpad_columns[ver]
if add_ns:
hdrs = hdrs + ['NS']
return cx.namedtuple("ntgpadobj", hdrs) | python | def _get_ntgpadnt(self, ver, add_ns):
"""Create a namedtuple object for each annotation"""
hdrs = self.gpad_columns[ver]
if add_ns:
hdrs = hdrs + ['NS']
return cx.namedtuple("ntgpadobj", hdrs) | [
"def",
"_get_ntgpadnt",
"(",
"self",
",",
"ver",
",",
"add_ns",
")",
":",
"hdrs",
"=",
"self",
".",
"gpad_columns",
"[",
"ver",
"]",
"if",
"add_ns",
":",
"hdrs",
"=",
"hdrs",
"+",
"[",
"'NS'",
"]",
"return",
"cx",
".",
"namedtuple",
"(",
"\"ntgpadobj... | Create a namedtuple object for each annotation | [
"Create",
"a",
"namedtuple",
"object",
"for",
"each",
"annotation"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gpad.py#L226-L231 | train | 223,466 |
tanghaibao/goatools | goatools/anno/init/reader_gpad.py | InitAssc._split_line | def _split_line(self, line):
"""Split line into field values."""
line = line.rstrip('\r\n')
flds = re.split('\t', line)
assert len(flds) == self.exp_numcol, "EXPECTED({E}) COLUMNS, ACTUAL({A}): {L}".format(
E=self.exp_numcol, A=len(flds), L=line)
return flds | python | def _split_line(self, line):
"""Split line into field values."""
line = line.rstrip('\r\n')
flds = re.split('\t', line)
assert len(flds) == self.exp_numcol, "EXPECTED({E}) COLUMNS, ACTUAL({A}): {L}".format(
E=self.exp_numcol, A=len(flds), L=line)
return flds | [
"def",
"_split_line",
"(",
"self",
",",
"line",
")",
":",
"line",
"=",
"line",
".",
"rstrip",
"(",
"'\\r\\n'",
")",
"flds",
"=",
"re",
".",
"split",
"(",
"'\\t'",
",",
"line",
")",
"assert",
"len",
"(",
"flds",
")",
"==",
"self",
".",
"exp_numcol",... | Split line into field values. | [
"Split",
"line",
"into",
"field",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gpad.py#L233-L239 | train | 223,467 |
tanghaibao/goatools | goatools/anno/init/reader_gpad.py | GpadHdr.chkaddhdr | def chkaddhdr(self, line):
"""If this line contains desired header info, save it."""
mtch = self.cmpline.search(line)
if mtch:
self.gpadhdr.append(mtch.group(1)) | python | def chkaddhdr(self, line):
"""If this line contains desired header info, save it."""
mtch = self.cmpline.search(line)
if mtch:
self.gpadhdr.append(mtch.group(1)) | [
"def",
"chkaddhdr",
"(",
"self",
",",
"line",
")",
":",
"mtch",
"=",
"self",
".",
"cmpline",
".",
"search",
"(",
"line",
")",
"if",
"mtch",
":",
"self",
".",
"gpadhdr",
".",
"append",
"(",
"mtch",
".",
"group",
"(",
"1",
")",
")"
] | If this line contains desired header info, save it. | [
"If",
"this",
"line",
"contains",
"desired",
"header",
"info",
"save",
"it",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gpad.py#L268-L272 | train | 223,468 |
tanghaibao/goatools | goatools/nt_utils.py | get_dict_w_id2nts | def get_dict_w_id2nts(ids, id2nts, flds, dflt_null=""):
"""Return a new dict of namedtuples by combining "dicts" of namedtuples or objects."""
assert len(ids) == len(set(ids)), "NOT ALL IDs ARE UNIQUE: {IDs}".format(IDs=ids)
assert len(flds) == len(set(flds)), "DUPLICATE FIELDS: {IDs}".format(
IDs=cx.Counter(flds).most_common())
usr_id_nt = []
# 1. Instantiate namedtuple object
ntobj = cx.namedtuple("Nt", " ".join(flds))
# 2. Fill dict with namedtuple objects for desired ids
for item_id in ids:
# 2a. Combine various namedtuples into a single namedtuple
nts = [id2nt.get(item_id) for id2nt in id2nts]
vals = _combine_nt_vals(nts, flds, dflt_null)
usr_id_nt.append((item_id, ntobj._make(vals)))
return cx.OrderedDict(usr_id_nt) | python | def get_dict_w_id2nts(ids, id2nts, flds, dflt_null=""):
"""Return a new dict of namedtuples by combining "dicts" of namedtuples or objects."""
assert len(ids) == len(set(ids)), "NOT ALL IDs ARE UNIQUE: {IDs}".format(IDs=ids)
assert len(flds) == len(set(flds)), "DUPLICATE FIELDS: {IDs}".format(
IDs=cx.Counter(flds).most_common())
usr_id_nt = []
# 1. Instantiate namedtuple object
ntobj = cx.namedtuple("Nt", " ".join(flds))
# 2. Fill dict with namedtuple objects for desired ids
for item_id in ids:
# 2a. Combine various namedtuples into a single namedtuple
nts = [id2nt.get(item_id) for id2nt in id2nts]
vals = _combine_nt_vals(nts, flds, dflt_null)
usr_id_nt.append((item_id, ntobj._make(vals)))
return cx.OrderedDict(usr_id_nt) | [
"def",
"get_dict_w_id2nts",
"(",
"ids",
",",
"id2nts",
",",
"flds",
",",
"dflt_null",
"=",
"\"\"",
")",
":",
"assert",
"len",
"(",
"ids",
")",
"==",
"len",
"(",
"set",
"(",
"ids",
")",
")",
",",
"\"NOT ALL IDs ARE UNIQUE: {IDs}\"",
".",
"format",
"(",
... | Return a new dict of namedtuples by combining "dicts" of namedtuples or objects. | [
"Return",
"a",
"new",
"dict",
"of",
"namedtuples",
"by",
"combining",
"dicts",
"of",
"namedtuples",
"or",
"objects",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/nt_utils.py#L10-L24 | train | 223,469 |
tanghaibao/goatools | goatools/nt_utils.py | get_list_w_id2nts | def get_list_w_id2nts(ids, id2nts, flds, dflt_null=""):
"""Return a new list of namedtuples by combining "dicts" of namedtuples or objects."""
combined_nt_list = []
# 1. Instantiate namedtuple object
ntobj = cx.namedtuple("Nt", " ".join(flds))
# 2. Fill dict with namedtuple objects for desired ids
for item_id in ids:
# 2a. Combine various namedtuples into a single namedtuple
nts = [id2nt.get(item_id) for id2nt in id2nts]
vals = _combine_nt_vals(nts, flds, dflt_null)
combined_nt_list.append(ntobj._make(vals))
return combined_nt_list | python | def get_list_w_id2nts(ids, id2nts, flds, dflt_null=""):
"""Return a new list of namedtuples by combining "dicts" of namedtuples or objects."""
combined_nt_list = []
# 1. Instantiate namedtuple object
ntobj = cx.namedtuple("Nt", " ".join(flds))
# 2. Fill dict with namedtuple objects for desired ids
for item_id in ids:
# 2a. Combine various namedtuples into a single namedtuple
nts = [id2nt.get(item_id) for id2nt in id2nts]
vals = _combine_nt_vals(nts, flds, dflt_null)
combined_nt_list.append(ntobj._make(vals))
return combined_nt_list | [
"def",
"get_list_w_id2nts",
"(",
"ids",
",",
"id2nts",
",",
"flds",
",",
"dflt_null",
"=",
"\"\"",
")",
":",
"combined_nt_list",
"=",
"[",
"]",
"# 1. Instantiate namedtuple object",
"ntobj",
"=",
"cx",
".",
"namedtuple",
"(",
"\"Nt\"",
",",
"\" \"",
".",
"jo... | Return a new list of namedtuples by combining "dicts" of namedtuples or objects. | [
"Return",
"a",
"new",
"list",
"of",
"namedtuples",
"by",
"combining",
"dicts",
"of",
"namedtuples",
"or",
"objects",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/nt_utils.py#L26-L37 | train | 223,470 |
tanghaibao/goatools | goatools/nt_utils.py | combine_nt_lists | def combine_nt_lists(lists, flds, dflt_null=""):
"""Return a new list of namedtuples by zipping "lists" of namedtuples or objects."""
combined_nt_list = []
# Check that all lists are the same length
lens = [len(lst) for lst in lists]
assert len(set(lens)) == 1, \
"LIST LENGTHS MUST BE EQUAL: {Ls}".format(Ls=" ".join(str(l) for l in lens))
# 1. Instantiate namedtuple object
ntobj = cx.namedtuple("Nt", " ".join(flds))
# 2. Loop through zipped list
for lst0_lstn in zip(*lists):
# 2a. Combine various namedtuples into a single namedtuple
combined_nt_list.append(ntobj._make(_combine_nt_vals(lst0_lstn, flds, dflt_null)))
return combined_nt_list | python | def combine_nt_lists(lists, flds, dflt_null=""):
"""Return a new list of namedtuples by zipping "lists" of namedtuples or objects."""
combined_nt_list = []
# Check that all lists are the same length
lens = [len(lst) for lst in lists]
assert len(set(lens)) == 1, \
"LIST LENGTHS MUST BE EQUAL: {Ls}".format(Ls=" ".join(str(l) for l in lens))
# 1. Instantiate namedtuple object
ntobj = cx.namedtuple("Nt", " ".join(flds))
# 2. Loop through zipped list
for lst0_lstn in zip(*lists):
# 2a. Combine various namedtuples into a single namedtuple
combined_nt_list.append(ntobj._make(_combine_nt_vals(lst0_lstn, flds, dflt_null)))
return combined_nt_list | [
"def",
"combine_nt_lists",
"(",
"lists",
",",
"flds",
",",
"dflt_null",
"=",
"\"\"",
")",
":",
"combined_nt_list",
"=",
"[",
"]",
"# Check that all lists are the same length",
"lens",
"=",
"[",
"len",
"(",
"lst",
")",
"for",
"lst",
"in",
"lists",
"]",
"asser... | Return a new list of namedtuples by zipping "lists" of namedtuples or objects. | [
"Return",
"a",
"new",
"list",
"of",
"namedtuples",
"by",
"zipping",
"lists",
"of",
"namedtuples",
"or",
"objects",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/nt_utils.py#L39-L52 | train | 223,471 |
tanghaibao/goatools | goatools/nt_utils.py | wr_py_nts | def wr_py_nts(fout_py, nts, docstring=None, varname="nts"):
"""Save namedtuples into a Python module."""
if nts:
with open(fout_py, 'w') as prt:
prt.write('"""{DOCSTRING}"""\n\n'.format(DOCSTRING=docstring))
prt.write("# Created: {DATE}\n".format(DATE=str(datetime.date.today())))
prt_nts(prt, nts, varname)
sys.stdout.write(" {N:7,} items WROTE: {PY}\n".format(N=len(nts), PY=fout_py)) | python | def wr_py_nts(fout_py, nts, docstring=None, varname="nts"):
"""Save namedtuples into a Python module."""
if nts:
with open(fout_py, 'w') as prt:
prt.write('"""{DOCSTRING}"""\n\n'.format(DOCSTRING=docstring))
prt.write("# Created: {DATE}\n".format(DATE=str(datetime.date.today())))
prt_nts(prt, nts, varname)
sys.stdout.write(" {N:7,} items WROTE: {PY}\n".format(N=len(nts), PY=fout_py)) | [
"def",
"wr_py_nts",
"(",
"fout_py",
",",
"nts",
",",
"docstring",
"=",
"None",
",",
"varname",
"=",
"\"nts\"",
")",
":",
"if",
"nts",
":",
"with",
"open",
"(",
"fout_py",
",",
"'w'",
")",
"as",
"prt",
":",
"prt",
".",
"write",
"(",
"'\"\"\"{DOCSTRING... | Save namedtuples into a Python module. | [
"Save",
"namedtuples",
"into",
"a",
"Python",
"module",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/nt_utils.py#L54-L61 | train | 223,472 |
tanghaibao/goatools | goatools/nt_utils.py | prt_nts | def prt_nts(prt, nts, varname, spc=' '):
"""Print namedtuples into a Python module."""
first_nt = nts[0]
nt_name = type(first_nt).__name__
prt.write("import collections as cx\n\n")
prt.write("NT_FIELDS = [\n")
for fld in first_nt._fields:
prt.write('{SPC}"{F}",\n'.format(SPC=spc, F=fld))
prt.write("]\n\n")
prt.write('{NtName} = cx.namedtuple("{NtName}", " ".join(NT_FIELDS))\n\n'.format(
NtName=nt_name))
prt.write("# {N:,} items\n".format(N=len(nts)))
prt.write("# pylint: disable=line-too-long\n")
prt.write("{VARNAME} = [\n".format(VARNAME=varname))
for ntup in nts:
prt.write("{SPC}{NT},\n".format(SPC=spc, NT=ntup))
prt.write("]\n") | python | def prt_nts(prt, nts, varname, spc=' '):
"""Print namedtuples into a Python module."""
first_nt = nts[0]
nt_name = type(first_nt).__name__
prt.write("import collections as cx\n\n")
prt.write("NT_FIELDS = [\n")
for fld in first_nt._fields:
prt.write('{SPC}"{F}",\n'.format(SPC=spc, F=fld))
prt.write("]\n\n")
prt.write('{NtName} = cx.namedtuple("{NtName}", " ".join(NT_FIELDS))\n\n'.format(
NtName=nt_name))
prt.write("# {N:,} items\n".format(N=len(nts)))
prt.write("# pylint: disable=line-too-long\n")
prt.write("{VARNAME} = [\n".format(VARNAME=varname))
for ntup in nts:
prt.write("{SPC}{NT},\n".format(SPC=spc, NT=ntup))
prt.write("]\n") | [
"def",
"prt_nts",
"(",
"prt",
",",
"nts",
",",
"varname",
",",
"spc",
"=",
"' '",
")",
":",
"first_nt",
"=",
"nts",
"[",
"0",
"]",
"nt_name",
"=",
"type",
"(",
"first_nt",
")",
".",
"__name__",
"prt",
".",
"write",
"(",
"\"import collections as cx\\... | Print namedtuples into a Python module. | [
"Print",
"namedtuples",
"into",
"a",
"Python",
"module",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/nt_utils.py#L63-L79 | train | 223,473 |
tanghaibao/goatools | goatools/nt_utils.py | get_unique_fields | def get_unique_fields(fld_lists):
"""Get unique namedtuple fields, despite potential duplicates in lists of fields."""
flds = []
fld_set = set([f for flst in fld_lists for f in flst])
fld_seen = set()
# Add unique fields to list of fields in order that they appear
for fld_list in fld_lists:
for fld in fld_list:
# Add fields if the field has not yet been seen
if fld not in fld_seen:
flds.append(fld)
fld_seen.add(fld)
assert len(flds) == len(fld_set)
return flds | python | def get_unique_fields(fld_lists):
"""Get unique namedtuple fields, despite potential duplicates in lists of fields."""
flds = []
fld_set = set([f for flst in fld_lists for f in flst])
fld_seen = set()
# Add unique fields to list of fields in order that they appear
for fld_list in fld_lists:
for fld in fld_list:
# Add fields if the field has not yet been seen
if fld not in fld_seen:
flds.append(fld)
fld_seen.add(fld)
assert len(flds) == len(fld_set)
return flds | [
"def",
"get_unique_fields",
"(",
"fld_lists",
")",
":",
"flds",
"=",
"[",
"]",
"fld_set",
"=",
"set",
"(",
"[",
"f",
"for",
"flst",
"in",
"fld_lists",
"for",
"f",
"in",
"flst",
"]",
")",
"fld_seen",
"=",
"set",
"(",
")",
"# Add unique fields to list of f... | Get unique namedtuple fields, despite potential duplicates in lists of fields. | [
"Get",
"unique",
"namedtuple",
"fields",
"despite",
"potential",
"duplicates",
"in",
"lists",
"of",
"fields",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/nt_utils.py#L81-L94 | train | 223,474 |
tanghaibao/goatools | goatools/nt_utils.py | _combine_nt_vals | def _combine_nt_vals(lst0_lstn, flds, dflt_null):
"""Given a list of lists of nts, return a single namedtuple."""
vals = []
for fld in flds:
fld_seen = False
# Set field value using the **first** value seen in list of nt lists(lst0_lstn)
for nt_curr in lst0_lstn:
if hasattr(nt_curr, fld):
vals.append(getattr(nt_curr, fld))
fld_seen = True
break
# Set default value if GO ID or nt value is not present
if fld_seen is False:
vals.append(dflt_null)
return vals | python | def _combine_nt_vals(lst0_lstn, flds, dflt_null):
"""Given a list of lists of nts, return a single namedtuple."""
vals = []
for fld in flds:
fld_seen = False
# Set field value using the **first** value seen in list of nt lists(lst0_lstn)
for nt_curr in lst0_lstn:
if hasattr(nt_curr, fld):
vals.append(getattr(nt_curr, fld))
fld_seen = True
break
# Set default value if GO ID or nt value is not present
if fld_seen is False:
vals.append(dflt_null)
return vals | [
"def",
"_combine_nt_vals",
"(",
"lst0_lstn",
",",
"flds",
",",
"dflt_null",
")",
":",
"vals",
"=",
"[",
"]",
"for",
"fld",
"in",
"flds",
":",
"fld_seen",
"=",
"False",
"# Set field value using the **first** value seen in list of nt lists(lst0_lstn)",
"for",
"nt_curr",... | Given a list of lists of nts, return a single namedtuple. | [
"Given",
"a",
"list",
"of",
"lists",
"of",
"nts",
"return",
"a",
"single",
"namedtuple",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/nt_utils.py#L97-L111 | train | 223,475 |
tanghaibao/goatools | goatools/cli/gos_get.py | GetGOs.get_go2obj | def get_go2obj(self, goids):
"""Return GO Terms for each user-specified GO ID. Note missing GO IDs."""
goids = goids.intersection(self.go2obj.keys())
if len(goids) != len(goids):
goids_missing = goids.difference(goids)
print(" {N} MISSING GO IDs: {GOs}".format(N=len(goids_missing), GOs=goids_missing))
return {go:self.go2obj[go] for go in goids} | python | def get_go2obj(self, goids):
"""Return GO Terms for each user-specified GO ID. Note missing GO IDs."""
goids = goids.intersection(self.go2obj.keys())
if len(goids) != len(goids):
goids_missing = goids.difference(goids)
print(" {N} MISSING GO IDs: {GOs}".format(N=len(goids_missing), GOs=goids_missing))
return {go:self.go2obj[go] for go in goids} | [
"def",
"get_go2obj",
"(",
"self",
",",
"goids",
")",
":",
"goids",
"=",
"goids",
".",
"intersection",
"(",
"self",
".",
"go2obj",
".",
"keys",
"(",
")",
")",
"if",
"len",
"(",
"goids",
")",
"!=",
"len",
"(",
"goids",
")",
":",
"goids_missing",
"=",... | Return GO Terms for each user-specified GO ID. Note missing GO IDs. | [
"Return",
"GO",
"Terms",
"for",
"each",
"user",
"-",
"specified",
"GO",
"ID",
".",
"Note",
"missing",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/gos_get.py#L46-L52 | train | 223,476 |
tanghaibao/goatools | goatools/grouper/utils.py | no_duplicates_sections2d | def no_duplicates_sections2d(sections2d, prt=None):
"""Check for duplicate header GO IDs in the 2-D sections variable."""
no_dups = True
ctr = cx.Counter()
for _, hdrgos in sections2d:
for goid in hdrgos:
ctr[goid] += 1
for goid, cnt in ctr.most_common():
if cnt == 1:
break
no_dups = False
if prt is not None:
prt.write("**SECTIONS WARNING FOUND: {N:3} {GO}\n".format(N=cnt, GO=goid))
return no_dups | python | def no_duplicates_sections2d(sections2d, prt=None):
"""Check for duplicate header GO IDs in the 2-D sections variable."""
no_dups = True
ctr = cx.Counter()
for _, hdrgos in sections2d:
for goid in hdrgos:
ctr[goid] += 1
for goid, cnt in ctr.most_common():
if cnt == 1:
break
no_dups = False
if prt is not None:
prt.write("**SECTIONS WARNING FOUND: {N:3} {GO}\n".format(N=cnt, GO=goid))
return no_dups | [
"def",
"no_duplicates_sections2d",
"(",
"sections2d",
",",
"prt",
"=",
"None",
")",
":",
"no_dups",
"=",
"True",
"ctr",
"=",
"cx",
".",
"Counter",
"(",
")",
"for",
"_",
",",
"hdrgos",
"in",
"sections2d",
":",
"for",
"goid",
"in",
"hdrgos",
":",
"ctr",
... | Check for duplicate header GO IDs in the 2-D sections variable. | [
"Check",
"for",
"duplicate",
"header",
"GO",
"IDs",
"in",
"the",
"2",
"-",
"D",
"sections",
"variable",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/utils.py#L13-L26 | train | 223,477 |
tanghaibao/goatools | goatools/evidence_codes.py | EvidenceCodes.get_evcodes | def get_evcodes(self, inc_set=None, exc_set=None):
"""Get evidence code for all but NOT 'No biological data'"""
codes = self.get_evcodes_all(inc_set, exc_set)
codes.discard('ND')
return codes | python | def get_evcodes(self, inc_set=None, exc_set=None):
"""Get evidence code for all but NOT 'No biological data'"""
codes = self.get_evcodes_all(inc_set, exc_set)
codes.discard('ND')
return codes | [
"def",
"get_evcodes",
"(",
"self",
",",
"inc_set",
"=",
"None",
",",
"exc_set",
"=",
"None",
")",
":",
"codes",
"=",
"self",
".",
"get_evcodes_all",
"(",
"inc_set",
",",
"exc_set",
")",
"codes",
".",
"discard",
"(",
"'ND'",
")",
"return",
"codes"
] | Get evidence code for all but NOT 'No biological data | [
"Get",
"evidence",
"code",
"for",
"all",
"but",
"NOT",
"No",
"biological",
"data"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L90-L94 | train | 223,478 |
tanghaibao/goatools | goatools/evidence_codes.py | EvidenceCodes.get_evcodes_all | def get_evcodes_all(self, inc_set=None, exc_set=None):
"""Get set of evidence codes given include set and exclude set"""
codes = self._get_grps_n_codes(inc_set) if inc_set else set(self.code2nt)
if exc_set:
codes.difference_update(self._get_grps_n_codes(exc_set))
return codes | python | def get_evcodes_all(self, inc_set=None, exc_set=None):
"""Get set of evidence codes given include set and exclude set"""
codes = self._get_grps_n_codes(inc_set) if inc_set else set(self.code2nt)
if exc_set:
codes.difference_update(self._get_grps_n_codes(exc_set))
return codes | [
"def",
"get_evcodes_all",
"(",
"self",
",",
"inc_set",
"=",
"None",
",",
"exc_set",
"=",
"None",
")",
":",
"codes",
"=",
"self",
".",
"_get_grps_n_codes",
"(",
"inc_set",
")",
"if",
"inc_set",
"else",
"set",
"(",
"self",
".",
"code2nt",
")",
"if",
"exc... | Get set of evidence codes given include set and exclude set | [
"Get",
"set",
"of",
"evidence",
"codes",
"given",
"include",
"set",
"and",
"exclude",
"set"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L96-L101 | train | 223,479 |
tanghaibao/goatools | goatools/evidence_codes.py | EvidenceCodes._get_grps_n_codes | def _get_grps_n_codes(self, usr_set):
"""Get codes, given codes or groups."""
codes = usr_set.intersection(self.code2nt)
for grp in usr_set.intersection(self.grp2codes):
codes.update(self.grp2codes[grp])
return codes | python | def _get_grps_n_codes(self, usr_set):
"""Get codes, given codes or groups."""
codes = usr_set.intersection(self.code2nt)
for grp in usr_set.intersection(self.grp2codes):
codes.update(self.grp2codes[grp])
return codes | [
"def",
"_get_grps_n_codes",
"(",
"self",
",",
"usr_set",
")",
":",
"codes",
"=",
"usr_set",
".",
"intersection",
"(",
"self",
".",
"code2nt",
")",
"for",
"grp",
"in",
"usr_set",
".",
"intersection",
"(",
"self",
".",
"grp2codes",
")",
":",
"codes",
".",
... | Get codes, given codes or groups. | [
"Get",
"codes",
"given",
"codes",
"or",
"groups",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L103-L108 | train | 223,480 |
tanghaibao/goatools | goatools/evidence_codes.py | EvidenceCodes.sort_nts | def sort_nts(self, nt_list, codekey):
"""Sort list of namedtuples such so evidence codes in same order as code2nt."""
# Problem is that some members in the nt_list do NOT have
# codekey=EvidenceCode, then it returns None, which breaks py34 and 35
# The fix here is that for these members, default to -1 (is this valid?)
sortby = lambda nt: self.ev2idx.get(getattr(nt, codekey), -1)
return sorted(nt_list, key=sortby) | python | def sort_nts(self, nt_list, codekey):
"""Sort list of namedtuples such so evidence codes in same order as code2nt."""
# Problem is that some members in the nt_list do NOT have
# codekey=EvidenceCode, then it returns None, which breaks py34 and 35
# The fix here is that for these members, default to -1 (is this valid?)
sortby = lambda nt: self.ev2idx.get(getattr(nt, codekey), -1)
return sorted(nt_list, key=sortby) | [
"def",
"sort_nts",
"(",
"self",
",",
"nt_list",
",",
"codekey",
")",
":",
"# Problem is that some members in the nt_list do NOT have",
"# codekey=EvidenceCode, then it returns None, which breaks py34 and 35",
"# The fix here is that for these members, default to -1 (is this valid?)",
"sort... | Sort list of namedtuples such so evidence codes in same order as code2nt. | [
"Sort",
"list",
"of",
"namedtuples",
"such",
"so",
"evidence",
"codes",
"in",
"same",
"order",
"as",
"code2nt",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L110-L116 | train | 223,481 |
tanghaibao/goatools | goatools/evidence_codes.py | EvidenceCodes.get_grp_name | def get_grp_name(self, code):
"""Return group and name for an evidence code."""
nt_code = self.code2nt.get(code.strip(), None)
if nt_code is not None:
return nt_code.group, nt_code.name
return "", "" | python | def get_grp_name(self, code):
"""Return group and name for an evidence code."""
nt_code = self.code2nt.get(code.strip(), None)
if nt_code is not None:
return nt_code.group, nt_code.name
return "", "" | [
"def",
"get_grp_name",
"(",
"self",
",",
"code",
")",
":",
"nt_code",
"=",
"self",
".",
"code2nt",
".",
"get",
"(",
"code",
".",
"strip",
"(",
")",
",",
"None",
")",
"if",
"nt_code",
"is",
"not",
"None",
":",
"return",
"nt_code",
".",
"group",
",",... | Return group and name for an evidence code. | [
"Return",
"group",
"and",
"name",
"for",
"an",
"evidence",
"code",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L118-L123 | train | 223,482 |
tanghaibao/goatools | goatools/evidence_codes.py | EvidenceCodes.prt_ev_cnts | def prt_ev_cnts(self, ctr, prt=sys.stdout):
"""Prints evidence code counts stored in a collections Counter."""
for key, cnt in ctr.most_common():
grp, name = self.get_grp_name(key.replace("NOT ", ""))
prt.write("{CNT:7,} {EV:>7} {GROUP:<15} {NAME}\n".format(
CNT=cnt, EV=key, GROUP=grp, NAME=name)) | python | def prt_ev_cnts(self, ctr, prt=sys.stdout):
"""Prints evidence code counts stored in a collections Counter."""
for key, cnt in ctr.most_common():
grp, name = self.get_grp_name(key.replace("NOT ", ""))
prt.write("{CNT:7,} {EV:>7} {GROUP:<15} {NAME}\n".format(
CNT=cnt, EV=key, GROUP=grp, NAME=name)) | [
"def",
"prt_ev_cnts",
"(",
"self",
",",
"ctr",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"for",
"key",
",",
"cnt",
"in",
"ctr",
".",
"most_common",
"(",
")",
":",
"grp",
",",
"name",
"=",
"self",
".",
"get_grp_name",
"(",
"key",
".",
"repl... | Prints evidence code counts stored in a collections Counter. | [
"Prints",
"evidence",
"code",
"counts",
"stored",
"in",
"a",
"collections",
"Counter",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L125-L130 | train | 223,483 |
tanghaibao/goatools | goatools/evidence_codes.py | EvidenceCodes.get_order | def get_order(self, codes):
"""Return evidence codes in order shown in code2name."""
return sorted(codes, key=lambda e: [self.ev2idx.get(e)]) | python | def get_order(self, codes):
"""Return evidence codes in order shown in code2name."""
return sorted(codes, key=lambda e: [self.ev2idx.get(e)]) | [
"def",
"get_order",
"(",
"self",
",",
"codes",
")",
":",
"return",
"sorted",
"(",
"codes",
",",
"key",
"=",
"lambda",
"e",
":",
"[",
"self",
".",
"ev2idx",
".",
"get",
"(",
"e",
")",
"]",
")"
] | Return evidence codes in order shown in code2name. | [
"Return",
"evidence",
"codes",
"in",
"order",
"shown",
"in",
"code2name",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L132-L134 | train | 223,484 |
tanghaibao/goatools | goatools/evidence_codes.py | _Init.get_grp2code2nt | def get_grp2code2nt(self):
"""Return ordered dict for group to namedtuple"""
grp2code2nt = cx.OrderedDict([(g, []) for g in self.grps])
for code, ntd in self.code2nt.items():
grp2code2nt[ntd.group].append((code, ntd))
for grp, nts in grp2code2nt.items():
grp2code2nt[grp] = cx.OrderedDict(nts)
return grp2code2nt | python | def get_grp2code2nt(self):
"""Return ordered dict for group to namedtuple"""
grp2code2nt = cx.OrderedDict([(g, []) for g in self.grps])
for code, ntd in self.code2nt.items():
grp2code2nt[ntd.group].append((code, ntd))
for grp, nts in grp2code2nt.items():
grp2code2nt[grp] = cx.OrderedDict(nts)
return grp2code2nt | [
"def",
"get_grp2code2nt",
"(",
"self",
")",
":",
"grp2code2nt",
"=",
"cx",
".",
"OrderedDict",
"(",
"[",
"(",
"g",
",",
"[",
"]",
")",
"for",
"g",
"in",
"self",
".",
"grps",
"]",
")",
"for",
"code",
",",
"ntd",
"in",
"self",
".",
"code2nt",
".",
... | Return ordered dict for group to namedtuple | [
"Return",
"ordered",
"dict",
"for",
"group",
"to",
"namedtuple"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L156-L163 | train | 223,485 |
tanghaibao/goatools | goatools/evidence_codes.py | _Init._init_grps | def _init_grps(code2nt):
"""Return list of groups in same order as in code2nt"""
seen = set()
seen_add = seen.add
groups = [nt.group for nt in code2nt.values()]
return [g for g in groups if not (g in seen or seen_add(g))] | python | def _init_grps(code2nt):
"""Return list of groups in same order as in code2nt"""
seen = set()
seen_add = seen.add
groups = [nt.group for nt in code2nt.values()]
return [g for g in groups if not (g in seen or seen_add(g))] | [
"def",
"_init_grps",
"(",
"code2nt",
")",
":",
"seen",
"=",
"set",
"(",
")",
"seen_add",
"=",
"seen",
".",
"add",
"groups",
"=",
"[",
"nt",
".",
"group",
"for",
"nt",
"in",
"code2nt",
".",
"values",
"(",
")",
"]",
"return",
"[",
"g",
"for",
"g",
... | Return list of groups in same order as in code2nt | [
"Return",
"list",
"of",
"groups",
"in",
"same",
"order",
"as",
"in",
"code2nt"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L166-L171 | train | 223,486 |
tanghaibao/goatools | goatools/evidence_codes.py | _Init.get_grp2codes | def get_grp2codes(self):
"""Get dict of group name to namedtuples."""
grp2codes = cx.defaultdict(set)
for code, ntd in self.code2nt.items():
grp2codes[ntd.group].add(code)
return dict(grp2codes) | python | def get_grp2codes(self):
"""Get dict of group name to namedtuples."""
grp2codes = cx.defaultdict(set)
for code, ntd in self.code2nt.items():
grp2codes[ntd.group].add(code)
return dict(grp2codes) | [
"def",
"get_grp2codes",
"(",
"self",
")",
":",
"grp2codes",
"=",
"cx",
".",
"defaultdict",
"(",
"set",
")",
"for",
"code",
",",
"ntd",
"in",
"self",
".",
"code2nt",
".",
"items",
"(",
")",
":",
"grp2codes",
"[",
"ntd",
".",
"group",
"]",
".",
"add"... | Get dict of group name to namedtuples. | [
"Get",
"dict",
"of",
"group",
"name",
"to",
"namedtuples",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/evidence_codes.py#L173-L178 | train | 223,487 |
tanghaibao/goatools | goatools/grouper/grprplt.py | GrouperPlot.plot_sections | def plot_sections(self, fout_dir=".", **kws_usr):
"""Plot groups of GOs which have been placed in sections."""
kws_plt, _ = self._get_kws_plt(None, **kws_usr)
PltGroupedGos(self).plot_sections(fout_dir, **kws_plt) | python | def plot_sections(self, fout_dir=".", **kws_usr):
"""Plot groups of GOs which have been placed in sections."""
kws_plt, _ = self._get_kws_plt(None, **kws_usr)
PltGroupedGos(self).plot_sections(fout_dir, **kws_plt) | [
"def",
"plot_sections",
"(",
"self",
",",
"fout_dir",
"=",
"\".\"",
",",
"*",
"*",
"kws_usr",
")",
":",
"kws_plt",
",",
"_",
"=",
"self",
".",
"_get_kws_plt",
"(",
"None",
",",
"*",
"*",
"kws_usr",
")",
"PltGroupedGos",
"(",
"self",
")",
".",
"plot_s... | Plot groups of GOs which have been placed in sections. | [
"Plot",
"groups",
"of",
"GOs",
"which",
"have",
"been",
"placed",
"in",
"sections",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprplt.py#L31-L34 | train | 223,488 |
tanghaibao/goatools | goatools/grouper/grprplt.py | GrouperPlot.get_pltdotstr | def get_pltdotstr(self, **kws_usr):
"""Plot one GO header group in Grouper."""
dotstrs = self.get_pltdotstrs(**kws_usr)
assert len(dotstrs) == 1
return dotstrs[0] | python | def get_pltdotstr(self, **kws_usr):
"""Plot one GO header group in Grouper."""
dotstrs = self.get_pltdotstrs(**kws_usr)
assert len(dotstrs) == 1
return dotstrs[0] | [
"def",
"get_pltdotstr",
"(",
"self",
",",
"*",
"*",
"kws_usr",
")",
":",
"dotstrs",
"=",
"self",
".",
"get_pltdotstrs",
"(",
"*",
"*",
"kws_usr",
")",
"assert",
"len",
"(",
"dotstrs",
")",
"==",
"1",
"return",
"dotstrs",
"[",
"0",
"]"
] | Plot one GO header group in Grouper. | [
"Plot",
"one",
"GO",
"header",
"group",
"in",
"Grouper",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprplt.py#L46-L50 | train | 223,489 |
tanghaibao/goatools | goatools/grouper/grprplt.py | GrouperPlot.plot_groups_unplaced | def plot_groups_unplaced(self, fout_dir=".", **kws_usr):
"""Plot each GO group."""
# kws: go2color max_gos upper_trigger max_upper
plotobj = PltGroupedGos(self)
return plotobj.plot_groups_unplaced(fout_dir, **kws_usr) | python | def plot_groups_unplaced(self, fout_dir=".", **kws_usr):
"""Plot each GO group."""
# kws: go2color max_gos upper_trigger max_upper
plotobj = PltGroupedGos(self)
return plotobj.plot_groups_unplaced(fout_dir, **kws_usr) | [
"def",
"plot_groups_unplaced",
"(",
"self",
",",
"fout_dir",
"=",
"\".\"",
",",
"*",
"*",
"kws_usr",
")",
":",
"# kws: go2color max_gos upper_trigger max_upper",
"plotobj",
"=",
"PltGroupedGos",
"(",
"self",
")",
"return",
"plotobj",
".",
"plot_groups_unplaced",
"("... | Plot each GO group. | [
"Plot",
"each",
"GO",
"group",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprplt.py#L52-L56 | train | 223,490 |
tanghaibao/goatools | goatools/grouper/grprplt.py | GrouperPlot._get_kws_plt | def _get_kws_plt(self, usrgos, **kws_usr):
"""Add go2color and go2bordercolor relevant to this grouping into plot."""
kws_plt = kws_usr.copy()
kws_dag = {}
hdrgo = kws_plt.get('hdrgo', None)
objcolor = GrouperColors(self.grprobj)
# GO term colors
if 'go2color' not in kws_usr:
kws_plt['go2color'] = objcolor.get_go2color_users()
elif hdrgo is not None:
go2color = kws_plt.get('go2color').copy()
go2color[hdrgo] = PltGroupedGosArgs.hdrgo_dflt_color
kws_plt['go2color'] = go2color
# GO term border colors
if 'go2bordercolor' not in kws_usr:
kws_plt['go2bordercolor'] = objcolor.get_bordercolor()
prune = kws_usr.get('prune', None)
if prune is True and hdrgo is not None:
kws_dag['dst_srcs_list'] = [(hdrgo, usrgos), (None, set([hdrgo]))]
kws_plt['parentcnt'] = True
elif prune:
kws_dag['dst_srcs_list'] = prune
kws_plt['parentcnt'] = True
# Group text
kws_plt['go2txt'] = self.get_go2txt(self.grprobj,
kws_plt.get('go2color'), kws_plt.get('go2bordercolor'))
return kws_plt, kws_dag | python | def _get_kws_plt(self, usrgos, **kws_usr):
"""Add go2color and go2bordercolor relevant to this grouping into plot."""
kws_plt = kws_usr.copy()
kws_dag = {}
hdrgo = kws_plt.get('hdrgo', None)
objcolor = GrouperColors(self.grprobj)
# GO term colors
if 'go2color' not in kws_usr:
kws_plt['go2color'] = objcolor.get_go2color_users()
elif hdrgo is not None:
go2color = kws_plt.get('go2color').copy()
go2color[hdrgo] = PltGroupedGosArgs.hdrgo_dflt_color
kws_plt['go2color'] = go2color
# GO term border colors
if 'go2bordercolor' not in kws_usr:
kws_plt['go2bordercolor'] = objcolor.get_bordercolor()
prune = kws_usr.get('prune', None)
if prune is True and hdrgo is not None:
kws_dag['dst_srcs_list'] = [(hdrgo, usrgos), (None, set([hdrgo]))]
kws_plt['parentcnt'] = True
elif prune:
kws_dag['dst_srcs_list'] = prune
kws_plt['parentcnt'] = True
# Group text
kws_plt['go2txt'] = self.get_go2txt(self.grprobj,
kws_plt.get('go2color'), kws_plt.get('go2bordercolor'))
return kws_plt, kws_dag | [
"def",
"_get_kws_plt",
"(",
"self",
",",
"usrgos",
",",
"*",
"*",
"kws_usr",
")",
":",
"kws_plt",
"=",
"kws_usr",
".",
"copy",
"(",
")",
"kws_dag",
"=",
"{",
"}",
"hdrgo",
"=",
"kws_plt",
".",
"get",
"(",
"'hdrgo'",
",",
"None",
")",
"objcolor",
"=... | Add go2color and go2bordercolor relevant to this grouping into plot. | [
"Add",
"go2color",
"and",
"go2bordercolor",
"relevant",
"to",
"this",
"grouping",
"into",
"plot",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprplt.py#L77-L103 | train | 223,491 |
tanghaibao/goatools | goatools/grouper/grprplt.py | GrouperPlot.get_go2txt | def get_go2txt(grprobj_cur, grp_go2color, grp_go2bordercolor):
"""Adds section text in all GO terms if not Misc. Adds Misc in terms of interest."""
goids_main = set(o.id for o in grprobj_cur.gosubdag.go2obj.values())
hdrobj = grprobj_cur.hdrobj
grprobj_all = Grouper("all",
grprobj_cur.usrgos.union(goids_main), hdrobj, grprobj_cur.gosubdag)
# Adds section text to all GO terms in plot (misses middle GO terms)
_secdflt = hdrobj.secdflt
_hilight = set(grp_go2color.keys()).union(grp_go2bordercolor)
ret_go2txt = {}
# Keep sections text only if GO header, GO user, or not Misc.
if hdrobj.sections:
for goid, txt in grprobj_all.get_go2sectiontxt().items():
if txt == 'broad':
continue
if txt != _secdflt or goid in _hilight:
ret_go2txt[goid] = txt
return ret_go2txt | python | def get_go2txt(grprobj_cur, grp_go2color, grp_go2bordercolor):
"""Adds section text in all GO terms if not Misc. Adds Misc in terms of interest."""
goids_main = set(o.id for o in grprobj_cur.gosubdag.go2obj.values())
hdrobj = grprobj_cur.hdrobj
grprobj_all = Grouper("all",
grprobj_cur.usrgos.union(goids_main), hdrobj, grprobj_cur.gosubdag)
# Adds section text to all GO terms in plot (misses middle GO terms)
_secdflt = hdrobj.secdflt
_hilight = set(grp_go2color.keys()).union(grp_go2bordercolor)
ret_go2txt = {}
# Keep sections text only if GO header, GO user, or not Misc.
if hdrobj.sections:
for goid, txt in grprobj_all.get_go2sectiontxt().items():
if txt == 'broad':
continue
if txt != _secdflt or goid in _hilight:
ret_go2txt[goid] = txt
return ret_go2txt | [
"def",
"get_go2txt",
"(",
"grprobj_cur",
",",
"grp_go2color",
",",
"grp_go2bordercolor",
")",
":",
"goids_main",
"=",
"set",
"(",
"o",
".",
"id",
"for",
"o",
"in",
"grprobj_cur",
".",
"gosubdag",
".",
"go2obj",
".",
"values",
"(",
")",
")",
"hdrobj",
"="... | Adds section text in all GO terms if not Misc. Adds Misc in terms of interest. | [
"Adds",
"section",
"text",
"in",
"all",
"GO",
"terms",
"if",
"not",
"Misc",
".",
"Adds",
"Misc",
"in",
"terms",
"of",
"interest",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprplt.py#L106-L123 | train | 223,492 |
tanghaibao/goatools | goatools/base.py | download_go_basic_obo | def download_go_basic_obo(obo="go-basic.obo", prt=sys.stdout, loading_bar=True):
"""Download Ontologies, if necessary."""
if not os.path.isfile(obo):
http = "http://purl.obolibrary.org/obo/go"
if "slim" in obo:
http = "http://www.geneontology.org/ontology/subsets"
# http = 'http://current.geneontology.org/ontology/subsets'
obo_remote = "{HTTP}/{OBO}".format(HTTP=http, OBO=os.path.basename(obo))
dnld_file(obo_remote, obo, prt, loading_bar)
else:
if prt is not None:
prt.write(" EXISTS: {FILE}\n".format(FILE=obo))
return obo | python | def download_go_basic_obo(obo="go-basic.obo", prt=sys.stdout, loading_bar=True):
"""Download Ontologies, if necessary."""
if not os.path.isfile(obo):
http = "http://purl.obolibrary.org/obo/go"
if "slim" in obo:
http = "http://www.geneontology.org/ontology/subsets"
# http = 'http://current.geneontology.org/ontology/subsets'
obo_remote = "{HTTP}/{OBO}".format(HTTP=http, OBO=os.path.basename(obo))
dnld_file(obo_remote, obo, prt, loading_bar)
else:
if prt is not None:
prt.write(" EXISTS: {FILE}\n".format(FILE=obo))
return obo | [
"def",
"download_go_basic_obo",
"(",
"obo",
"=",
"\"go-basic.obo\"",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"loading_bar",
"=",
"True",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"obo",
")",
":",
"http",
"=",
"\"http://purl.obolib... | Download Ontologies, if necessary. | [
"Download",
"Ontologies",
"if",
"necessary",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L113-L125 | train | 223,493 |
tanghaibao/goatools | goatools/base.py | download_ncbi_associations | def download_ncbi_associations(gene2go="gene2go", prt=sys.stdout, loading_bar=True):
"""Download associations from NCBI, if necessary"""
# Download: ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/gene2go.gz
gzip_file = "{GENE2GO}.gz".format(GENE2GO=gene2go)
if not os.path.isfile(gene2go):
file_remote = "ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/{GZ}".format(
GZ=os.path.basename(gzip_file))
dnld_file(file_remote, gene2go, prt, loading_bar)
else:
if prt is not None:
prt.write(" EXISTS: {FILE}\n".format(FILE=gene2go))
return gene2go | python | def download_ncbi_associations(gene2go="gene2go", prt=sys.stdout, loading_bar=True):
"""Download associations from NCBI, if necessary"""
# Download: ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/gene2go.gz
gzip_file = "{GENE2GO}.gz".format(GENE2GO=gene2go)
if not os.path.isfile(gene2go):
file_remote = "ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/{GZ}".format(
GZ=os.path.basename(gzip_file))
dnld_file(file_remote, gene2go, prt, loading_bar)
else:
if prt is not None:
prt.write(" EXISTS: {FILE}\n".format(FILE=gene2go))
return gene2go | [
"def",
"download_ncbi_associations",
"(",
"gene2go",
"=",
"\"gene2go\"",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"loading_bar",
"=",
"True",
")",
":",
"# Download: ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/gene2go.gz",
"gzip_file",
"=",
"\"{GENE2GO}.gz\"",
".",
"format",... | Download associations from NCBI, if necessary | [
"Download",
"associations",
"from",
"NCBI",
"if",
"necessary"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L127-L138 | train | 223,494 |
tanghaibao/goatools | goatools/base.py | gunzip | def gunzip(gzip_file, file_gunzip=None):
"""Unzip .gz file. Return filename of unzipped file."""
if file_gunzip is None:
file_gunzip = os.path.splitext(gzip_file)[0]
gzip_open_to(gzip_file, file_gunzip)
return file_gunzip | python | def gunzip(gzip_file, file_gunzip=None):
"""Unzip .gz file. Return filename of unzipped file."""
if file_gunzip is None:
file_gunzip = os.path.splitext(gzip_file)[0]
gzip_open_to(gzip_file, file_gunzip)
return file_gunzip | [
"def",
"gunzip",
"(",
"gzip_file",
",",
"file_gunzip",
"=",
"None",
")",
":",
"if",
"file_gunzip",
"is",
"None",
":",
"file_gunzip",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"gzip_file",
")",
"[",
"0",
"]",
"gzip_open_to",
"(",
"gzip_file",
",",
"... | Unzip .gz file. Return filename of unzipped file. | [
"Unzip",
".",
"gz",
"file",
".",
"Return",
"filename",
"of",
"unzipped",
"file",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L140-L145 | train | 223,495 |
tanghaibao/goatools | goatools/base.py | get_godag | def get_godag(fin_obo="go-basic.obo", prt=sys.stdout, loading_bar=True, optional_attrs=None):
"""Return GODag object. Initialize, if necessary."""
from goatools.obo_parser import GODag
download_go_basic_obo(fin_obo, prt, loading_bar)
return GODag(fin_obo, optional_attrs, load_obsolete=False, prt=prt) | python | def get_godag(fin_obo="go-basic.obo", prt=sys.stdout, loading_bar=True, optional_attrs=None):
"""Return GODag object. Initialize, if necessary."""
from goatools.obo_parser import GODag
download_go_basic_obo(fin_obo, prt, loading_bar)
return GODag(fin_obo, optional_attrs, load_obsolete=False, prt=prt) | [
"def",
"get_godag",
"(",
"fin_obo",
"=",
"\"go-basic.obo\"",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"loading_bar",
"=",
"True",
",",
"optional_attrs",
"=",
"None",
")",
":",
"from",
"goatools",
".",
"obo_parser",
"import",
"GODag",
"download_go_basic_obo"... | Return GODag object. Initialize, if necessary. | [
"Return",
"GODag",
"object",
".",
"Initialize",
"if",
"necessary",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L147-L151 | train | 223,496 |
tanghaibao/goatools | goatools/base.py | dnld_gaf | def dnld_gaf(species_txt, prt=sys.stdout, loading_bar=True):
"""Download GAF file if necessary."""
return dnld_gafs([species_txt], prt, loading_bar)[0] | python | def dnld_gaf(species_txt, prt=sys.stdout, loading_bar=True):
"""Download GAF file if necessary."""
return dnld_gafs([species_txt], prt, loading_bar)[0] | [
"def",
"dnld_gaf",
"(",
"species_txt",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"loading_bar",
"=",
"True",
")",
":",
"return",
"dnld_gafs",
"(",
"[",
"species_txt",
"]",
",",
"prt",
",",
"loading_bar",
")",
"[",
"0",
"]"
] | Download GAF file if necessary. | [
"Download",
"GAF",
"file",
"if",
"necessary",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L153-L155 | train | 223,497 |
tanghaibao/goatools | goatools/base.py | dnld_gafs | def dnld_gafs(species_list, prt=sys.stdout, loading_bar=True):
"""Download GAF files if necessary."""
# Example GAF files in http://current.geneontology.org/annotations/:
# http://current.geneontology.org/annotations/mgi.gaf.gz
# http://current.geneontology.org/annotations/fb.gaf.gz
# http://current.geneontology.org/annotations/goa_human.gaf.gz
http = "http://current.geneontology.org/annotations"
# There are two filename patterns for gene associations on geneontology.org
fin_gafs = []
cwd = os.getcwd()
for species_txt in species_list: # e.g., goa_human mgi fb
gaf_base = '{ABC}.gaf'.format(ABC=species_txt) # goa_human.gaf
gaf_cwd = os.path.join(cwd, gaf_base) # {CWD}/goa_human.gaf
wget_cmd = "{HTTP}/{GAF}.gz".format(HTTP=http, GAF=gaf_base)
dnld_file(wget_cmd, gaf_cwd, prt, loading_bar)
fin_gafs.append(gaf_cwd)
return fin_gafs | python | def dnld_gafs(species_list, prt=sys.stdout, loading_bar=True):
"""Download GAF files if necessary."""
# Example GAF files in http://current.geneontology.org/annotations/:
# http://current.geneontology.org/annotations/mgi.gaf.gz
# http://current.geneontology.org/annotations/fb.gaf.gz
# http://current.geneontology.org/annotations/goa_human.gaf.gz
http = "http://current.geneontology.org/annotations"
# There are two filename patterns for gene associations on geneontology.org
fin_gafs = []
cwd = os.getcwd()
for species_txt in species_list: # e.g., goa_human mgi fb
gaf_base = '{ABC}.gaf'.format(ABC=species_txt) # goa_human.gaf
gaf_cwd = os.path.join(cwd, gaf_base) # {CWD}/goa_human.gaf
wget_cmd = "{HTTP}/{GAF}.gz".format(HTTP=http, GAF=gaf_base)
dnld_file(wget_cmd, gaf_cwd, prt, loading_bar)
fin_gafs.append(gaf_cwd)
return fin_gafs | [
"def",
"dnld_gafs",
"(",
"species_list",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"loading_bar",
"=",
"True",
")",
":",
"# Example GAF files in http://current.geneontology.org/annotations/:",
"# http://current.geneontology.org/annotations/mgi.gaf.gz",
"# http://current.ge... | Download GAF files if necessary. | [
"Download",
"GAF",
"files",
"if",
"necessary",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L157-L173 | train | 223,498 |
tanghaibao/goatools | goatools/base.py | http_get | def http_get(url, fout=None):
"""Download a file from http. Save it in a file named by fout"""
print('requests.get({URL}, stream=True)'.format(URL=url))
rsp = requests.get(url, stream=True)
if rsp.status_code == 200 and fout is not None:
with open(fout, 'wb') as prt:
for chunk in rsp: # .iter_content(chunk_size=128):
prt.write(chunk)
print(' WROTE: {F}\n'.format(F=fout))
else:
print(rsp.status_code, rsp.reason, url)
print(rsp.content)
return rsp | python | def http_get(url, fout=None):
"""Download a file from http. Save it in a file named by fout"""
print('requests.get({URL}, stream=True)'.format(URL=url))
rsp = requests.get(url, stream=True)
if rsp.status_code == 200 and fout is not None:
with open(fout, 'wb') as prt:
for chunk in rsp: # .iter_content(chunk_size=128):
prt.write(chunk)
print(' WROTE: {F}\n'.format(F=fout))
else:
print(rsp.status_code, rsp.reason, url)
print(rsp.content)
return rsp | [
"def",
"http_get",
"(",
"url",
",",
"fout",
"=",
"None",
")",
":",
"print",
"(",
"'requests.get({URL}, stream=True)'",
".",
"format",
"(",
"URL",
"=",
"url",
")",
")",
"rsp",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"stream",
"=",
"True",
")",
"... | Download a file from http. Save it in a file named by fout | [
"Download",
"a",
"file",
"from",
"http",
".",
"Save",
"it",
"in",
"a",
"file",
"named",
"by",
"fout"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L175-L187 | train | 223,499 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.