id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
228,400 | tanghaibao/goatools | goatools/parsers/david_chart.py | DavidChartReader.get_num_sig | def get_num_sig(self, alpha=0.05):
"""Print the number of significant results using various metrics."""
# Get the number of significant GO terms
ctr = cx.Counter()
flds = set(['FDR', 'Bonferroni', 'Benjamini', 'PValue'])
for ntd in self.nts:
for fld in flds:
if getattr(ntd, fld) < alpha:
ctr[fld] += 1
return ctr | python | def get_num_sig(self, alpha=0.05):
"""Print the number of significant results using various metrics."""
# Get the number of significant GO terms
ctr = cx.Counter()
flds = set(['FDR', 'Bonferroni', 'Benjamini', 'PValue'])
for ntd in self.nts:
for fld in flds:
if getattr(ntd, fld) < alpha:
ctr[fld] += 1
return ctr | [
"def",
"get_num_sig",
"(",
"self",
",",
"alpha",
"=",
"0.05",
")",
":",
"# Get the number of significant GO terms",
"ctr",
"=",
"cx",
".",
"Counter",
"(",
")",
"flds",
"=",
"set",
"(",
"[",
"'FDR'",
",",
"'Bonferroni'",
",",
"'Benjamini'",
",",
"'PValue'",
"]",
")",
"for",
"ntd",
"in",
"self",
".",
"nts",
":",
"for",
"fld",
"in",
"flds",
":",
"if",
"getattr",
"(",
"ntd",
",",
"fld",
")",
"<",
"alpha",
":",
"ctr",
"[",
"fld",
"]",
"+=",
"1",
"return",
"ctr"
] | Print the number of significant results using various metrics. | [
"Print",
"the",
"number",
"of",
"significant",
"results",
"using",
"various",
"metrics",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L91-L100 |
228,401 | tanghaibao/goatools | goatools/parsers/david_chart.py | _Init.get_nts | def get_nts(self, fin_davidchart):
"""Read DAVID Chart file. Store each line in a namedtuple."""
nts = []
with open(fin_davidchart) as ifstrm:
hdr_seen = False
for line in ifstrm:
line = line.rstrip()
flds = line.split('\t')
if hdr_seen:
ntd = self._init_nt(flds)
nts.append(ntd)
else:
if line[:8] == 'Category':
assert len(flds) == 13, len(flds)
hdr_seen = True
sys.stdout.write(" READ {N:5} GO IDs from DAVID Chart: {TSV}\n".format(
N=len(nts), TSV=fin_davidchart))
return nts | python | def get_nts(self, fin_davidchart):
"""Read DAVID Chart file. Store each line in a namedtuple."""
nts = []
with open(fin_davidchart) as ifstrm:
hdr_seen = False
for line in ifstrm:
line = line.rstrip()
flds = line.split('\t')
if hdr_seen:
ntd = self._init_nt(flds)
nts.append(ntd)
else:
if line[:8] == 'Category':
assert len(flds) == 13, len(flds)
hdr_seen = True
sys.stdout.write(" READ {N:5} GO IDs from DAVID Chart: {TSV}\n".format(
N=len(nts), TSV=fin_davidchart))
return nts | [
"def",
"get_nts",
"(",
"self",
",",
"fin_davidchart",
")",
":",
"nts",
"=",
"[",
"]",
"with",
"open",
"(",
"fin_davidchart",
")",
"as",
"ifstrm",
":",
"hdr_seen",
"=",
"False",
"for",
"line",
"in",
"ifstrm",
":",
"line",
"=",
"line",
".",
"rstrip",
"(",
")",
"flds",
"=",
"line",
".",
"split",
"(",
"'\\t'",
")",
"if",
"hdr_seen",
":",
"ntd",
"=",
"self",
".",
"_init_nt",
"(",
"flds",
")",
"nts",
".",
"append",
"(",
"ntd",
")",
"else",
":",
"if",
"line",
"[",
":",
"8",
"]",
"==",
"'Category'",
":",
"assert",
"len",
"(",
"flds",
")",
"==",
"13",
",",
"len",
"(",
"flds",
")",
"hdr_seen",
"=",
"True",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" READ {N:5} GO IDs from DAVID Chart: {TSV}\\n\"",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"nts",
")",
",",
"TSV",
"=",
"fin_davidchart",
")",
")",
"return",
"nts"
] | Read DAVID Chart file. Store each line in a namedtuple. | [
"Read",
"DAVID",
"Chart",
"file",
".",
"Store",
"each",
"line",
"in",
"a",
"namedtuple",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L127-L145 |
228,402 | tanghaibao/goatools | goatools/parsers/david_chart.py | _Init._init_nt | def _init_nt(self, flds):
"""Given string fields from a DAVID chart file, return namedtuple."""
term = flds[1]
genes_str = flds[5]
# pylint: disable=bad-whitespace
return self.ntobj(
Category = flds[0],
GO = term[:10], # 1 GO:0045202~synapse
name = term[10:], # 1 GO:0045202~synapse
Count = int(flds[2]), # 2 94
Perc = float(flds[3]), # 3 9.456740442655935
PValue = float(flds[4]), # 4 6.102654380458156E-20
Genes = genes_str, # 5 ['ENSMUSG00000052613', ...]
Genes_set = self.get_genes(genes_str), # 5 ['ENSMUSG00000052613', ...]
List_Total = int(flds[6]), # 6 920
Pop_Hits = int(flds[7]), # 7 444
Pop_Total = int(flds[8]), # 8 12002
Fold_Enrichment = float(flds[9]), # 9 2.7619173521347435
Bonferroni = float(flds[10]), # 10 3.3930758355347344E-17
Benjamini = float(flds[11]), # 11 3.3930758355347344E-17
FDR = float(flds[12])) | python | def _init_nt(self, flds):
"""Given string fields from a DAVID chart file, return namedtuple."""
term = flds[1]
genes_str = flds[5]
# pylint: disable=bad-whitespace
return self.ntobj(
Category = flds[0],
GO = term[:10], # 1 GO:0045202~synapse
name = term[10:], # 1 GO:0045202~synapse
Count = int(flds[2]), # 2 94
Perc = float(flds[3]), # 3 9.456740442655935
PValue = float(flds[4]), # 4 6.102654380458156E-20
Genes = genes_str, # 5 ['ENSMUSG00000052613', ...]
Genes_set = self.get_genes(genes_str), # 5 ['ENSMUSG00000052613', ...]
List_Total = int(flds[6]), # 6 920
Pop_Hits = int(flds[7]), # 7 444
Pop_Total = int(flds[8]), # 8 12002
Fold_Enrichment = float(flds[9]), # 9 2.7619173521347435
Bonferroni = float(flds[10]), # 10 3.3930758355347344E-17
Benjamini = float(flds[11]), # 11 3.3930758355347344E-17
FDR = float(flds[12])) | [
"def",
"_init_nt",
"(",
"self",
",",
"flds",
")",
":",
"term",
"=",
"flds",
"[",
"1",
"]",
"genes_str",
"=",
"flds",
"[",
"5",
"]",
"# pylint: disable=bad-whitespace",
"return",
"self",
".",
"ntobj",
"(",
"Category",
"=",
"flds",
"[",
"0",
"]",
",",
"GO",
"=",
"term",
"[",
":",
"10",
"]",
",",
"# 1 GO:0045202~synapse",
"name",
"=",
"term",
"[",
"10",
":",
"]",
",",
"# 1 GO:0045202~synapse",
"Count",
"=",
"int",
"(",
"flds",
"[",
"2",
"]",
")",
",",
"# 2 94",
"Perc",
"=",
"float",
"(",
"flds",
"[",
"3",
"]",
")",
",",
"# 3 9.456740442655935",
"PValue",
"=",
"float",
"(",
"flds",
"[",
"4",
"]",
")",
",",
"# 4 6.102654380458156E-20",
"Genes",
"=",
"genes_str",
",",
"# 5 ['ENSMUSG00000052613', ...]",
"Genes_set",
"=",
"self",
".",
"get_genes",
"(",
"genes_str",
")",
",",
"# 5 ['ENSMUSG00000052613', ...]",
"List_Total",
"=",
"int",
"(",
"flds",
"[",
"6",
"]",
")",
",",
"# 6 920",
"Pop_Hits",
"=",
"int",
"(",
"flds",
"[",
"7",
"]",
")",
",",
"# 7 444",
"Pop_Total",
"=",
"int",
"(",
"flds",
"[",
"8",
"]",
")",
",",
"# 8 12002",
"Fold_Enrichment",
"=",
"float",
"(",
"flds",
"[",
"9",
"]",
")",
",",
"# 9 2.7619173521347435",
"Bonferroni",
"=",
"float",
"(",
"flds",
"[",
"10",
"]",
")",
",",
"# 10 3.3930758355347344E-17",
"Benjamini",
"=",
"float",
"(",
"flds",
"[",
"11",
"]",
")",
",",
"# 11 3.3930758355347344E-17",
"FDR",
"=",
"float",
"(",
"flds",
"[",
"12",
"]",
")",
")"
] | Given string fields from a DAVID chart file, return namedtuple. | [
"Given",
"string",
"fields",
"from",
"a",
"DAVID",
"chart",
"file",
"return",
"namedtuple",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L147-L167 |
228,403 | tanghaibao/goatools | goatools/parsers/david_chart.py | _Init.get_genes | def get_genes(genes_str):
"""Given a string containng genes, return a list."""
gene_set = genes_str.split(', ')
if gene_set and gene_set[0].isdigit():
gene_set = set(int(g) for g in gene_set)
return gene_set | python | def get_genes(genes_str):
"""Given a string containng genes, return a list."""
gene_set = genes_str.split(', ')
if gene_set and gene_set[0].isdigit():
gene_set = set(int(g) for g in gene_set)
return gene_set | [
"def",
"get_genes",
"(",
"genes_str",
")",
":",
"gene_set",
"=",
"genes_str",
".",
"split",
"(",
"', '",
")",
"if",
"gene_set",
"and",
"gene_set",
"[",
"0",
"]",
".",
"isdigit",
"(",
")",
":",
"gene_set",
"=",
"set",
"(",
"int",
"(",
"g",
")",
"for",
"g",
"in",
"gene_set",
")",
"return",
"gene_set"
] | Given a string containng genes, return a list. | [
"Given",
"a",
"string",
"containng",
"genes",
"return",
"a",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L170-L175 |
228,404 | tanghaibao/goatools | goatools/anno/extensions/factory.py | get_extensions | def get_extensions(extstr):
"""Return zero or greater Annotation Extensions, given a line of text."""
# Extension examples:
# has_direct_input(UniProtKB:P37840),occurs_in(GO:0005576)
# part_of(UBERON:0006618),part_of(UBERON:0002302)
# occurs_in(CL:0000988)|occurs_in(CL:0001021)
if not extstr:
return None
exts = []
for ext_lst in extstr.split('|'):
grp = []
for ext in ext_lst.split(','):
idx = ext.find('(')
if idx != -1 and ext[-1] == ')':
grp.append(AnnotationExtension(ext[:idx], ext[idx+1:-1]))
else:
# Ignore improperly formatted Extensions
sys.stdout.write('BAD Extension({E})\n'.format(E=ext))
exts.append(grp)
return AnnotationExtensions(exts) | python | def get_extensions(extstr):
"""Return zero or greater Annotation Extensions, given a line of text."""
# Extension examples:
# has_direct_input(UniProtKB:P37840),occurs_in(GO:0005576)
# part_of(UBERON:0006618),part_of(UBERON:0002302)
# occurs_in(CL:0000988)|occurs_in(CL:0001021)
if not extstr:
return None
exts = []
for ext_lst in extstr.split('|'):
grp = []
for ext in ext_lst.split(','):
idx = ext.find('(')
if idx != -1 and ext[-1] == ')':
grp.append(AnnotationExtension(ext[:idx], ext[idx+1:-1]))
else:
# Ignore improperly formatted Extensions
sys.stdout.write('BAD Extension({E})\n'.format(E=ext))
exts.append(grp)
return AnnotationExtensions(exts) | [
"def",
"get_extensions",
"(",
"extstr",
")",
":",
"# Extension examples:",
"# has_direct_input(UniProtKB:P37840),occurs_in(GO:0005576)",
"# part_of(UBERON:0006618),part_of(UBERON:0002302)",
"# occurs_in(CL:0000988)|occurs_in(CL:0001021)",
"if",
"not",
"extstr",
":",
"return",
"None",
"exts",
"=",
"[",
"]",
"for",
"ext_lst",
"in",
"extstr",
".",
"split",
"(",
"'|'",
")",
":",
"grp",
"=",
"[",
"]",
"for",
"ext",
"in",
"ext_lst",
".",
"split",
"(",
"','",
")",
":",
"idx",
"=",
"ext",
".",
"find",
"(",
"'('",
")",
"if",
"idx",
"!=",
"-",
"1",
"and",
"ext",
"[",
"-",
"1",
"]",
"==",
"')'",
":",
"grp",
".",
"append",
"(",
"AnnotationExtension",
"(",
"ext",
"[",
":",
"idx",
"]",
",",
"ext",
"[",
"idx",
"+",
"1",
":",
"-",
"1",
"]",
")",
")",
"else",
":",
"# Ignore improperly formatted Extensions",
"sys",
".",
"stdout",
".",
"write",
"(",
"'BAD Extension({E})\\n'",
".",
"format",
"(",
"E",
"=",
"ext",
")",
")",
"exts",
".",
"append",
"(",
"grp",
")",
"return",
"AnnotationExtensions",
"(",
"exts",
")"
] | Return zero or greater Annotation Extensions, given a line of text. | [
"Return",
"zero",
"or",
"greater",
"Annotation",
"Extensions",
"given",
"a",
"line",
"of",
"text",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/extensions/factory.py#L25-L44 |
228,405 | tanghaibao/goatools | goatools/cli/docopt_parse.py | DocOptParse._set_intvals | def _set_intvals(kws, keys):
"""Convert keyword values to int."""
for key in keys:
if key in kws:
kws[key] = int(kws[key]) | python | def _set_intvals(kws, keys):
"""Convert keyword values to int."""
for key in keys:
if key in kws:
kws[key] = int(kws[key]) | [
"def",
"_set_intvals",
"(",
"kws",
",",
"keys",
")",
":",
"for",
"key",
"in",
"keys",
":",
"if",
"key",
"in",
"kws",
":",
"kws",
"[",
"key",
"]",
"=",
"int",
"(",
"kws",
"[",
"key",
"]",
")"
] | Convert keyword values to int. | [
"Convert",
"keyword",
"values",
"to",
"int",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/docopt_parse.py#L51-L55 |
228,406 | tanghaibao/goatools | goatools/cli/docopt_parse.py | DocOptParse._chk_docopt_exit | def _chk_docopt_exit(self, args, exp_letters):
"""Check if docopt exit was for an unknown argument."""
if args is None:
args = sys.argv[1:]
keys_all = self.exp_keys.union(self.exp_elems)
if exp_letters:
keys_all |= exp_letters
unknown_args = self._chk_docunknown(args, keys_all)
if unknown_args:
raise RuntimeError("{USAGE}\n **FATAL: UNKNOWN ARGS: {UNK}".format(
USAGE=self.doc, UNK=" ".join(unknown_args))) | python | def _chk_docopt_exit(self, args, exp_letters):
"""Check if docopt exit was for an unknown argument."""
if args is None:
args = sys.argv[1:]
keys_all = self.exp_keys.union(self.exp_elems)
if exp_letters:
keys_all |= exp_letters
unknown_args = self._chk_docunknown(args, keys_all)
if unknown_args:
raise RuntimeError("{USAGE}\n **FATAL: UNKNOWN ARGS: {UNK}".format(
USAGE=self.doc, UNK=" ".join(unknown_args))) | [
"def",
"_chk_docopt_exit",
"(",
"self",
",",
"args",
",",
"exp_letters",
")",
":",
"if",
"args",
"is",
"None",
":",
"args",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
"keys_all",
"=",
"self",
".",
"exp_keys",
".",
"union",
"(",
"self",
".",
"exp_elems",
")",
"if",
"exp_letters",
":",
"keys_all",
"|=",
"exp_letters",
"unknown_args",
"=",
"self",
".",
"_chk_docunknown",
"(",
"args",
",",
"keys_all",
")",
"if",
"unknown_args",
":",
"raise",
"RuntimeError",
"(",
"\"{USAGE}\\n **FATAL: UNKNOWN ARGS: {UNK}\"",
".",
"format",
"(",
"USAGE",
"=",
"self",
".",
"doc",
",",
"UNK",
"=",
"\" \"",
".",
"join",
"(",
"unknown_args",
")",
")",
")"
] | Check if docopt exit was for an unknown argument. | [
"Check",
"if",
"docopt",
"exit",
"was",
"for",
"an",
"unknown",
"argument",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/docopt_parse.py#L57-L67 |
228,407 | tanghaibao/goatools | goatools/cli/docopt_parse.py | DocOptParse._chk_docopt_kws | def _chk_docopt_kws(self, docdict, exp):
"""Check for common user errors when running from the command-line."""
for key, val in docdict.items():
if isinstance(val, str):
assert '=' not in val, self._err("'=' FOUND IN VALUE", key, val, exp)
elif key != 'help' and key not in self.exp_keys and key not in self.exp_elems:
raise RuntimeError(self._err("UNKNOWN KEY", key, val, exp)) | python | def _chk_docopt_kws(self, docdict, exp):
"""Check for common user errors when running from the command-line."""
for key, val in docdict.items():
if isinstance(val, str):
assert '=' not in val, self._err("'=' FOUND IN VALUE", key, val, exp)
elif key != 'help' and key not in self.exp_keys and key not in self.exp_elems:
raise RuntimeError(self._err("UNKNOWN KEY", key, val, exp)) | [
"def",
"_chk_docopt_kws",
"(",
"self",
",",
"docdict",
",",
"exp",
")",
":",
"for",
"key",
",",
"val",
"in",
"docdict",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"val",
",",
"str",
")",
":",
"assert",
"'='",
"not",
"in",
"val",
",",
"self",
".",
"_err",
"(",
"\"'=' FOUND IN VALUE\"",
",",
"key",
",",
"val",
",",
"exp",
")",
"elif",
"key",
"!=",
"'help'",
"and",
"key",
"not",
"in",
"self",
".",
"exp_keys",
"and",
"key",
"not",
"in",
"self",
".",
"exp_elems",
":",
"raise",
"RuntimeError",
"(",
"self",
".",
"_err",
"(",
"\"UNKNOWN KEY\"",
",",
"key",
",",
"val",
",",
"exp",
")",
")"
] | Check for common user errors when running from the command-line. | [
"Check",
"for",
"common",
"user",
"errors",
"when",
"running",
"from",
"the",
"command",
"-",
"line",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/docopt_parse.py#L69-L75 |
228,408 | tanghaibao/goatools | goatools/cli/docopt_parse.py | DocOptParse._chk_docunknown | def _chk_docunknown(args, exp):
"""Return any unknown args."""
unknown = []
for arg in args:
if arg[:2] == '--':
val = arg[2:]
if val not in exp:
unknown.append(arg)
elif arg[:1] == '-':
val = arg[1:]
if val not in exp:
unknown.append(arg)
if '-h' in unknown or '--help' in unknown:
return []
return unknown | python | def _chk_docunknown(args, exp):
"""Return any unknown args."""
unknown = []
for arg in args:
if arg[:2] == '--':
val = arg[2:]
if val not in exp:
unknown.append(arg)
elif arg[:1] == '-':
val = arg[1:]
if val not in exp:
unknown.append(arg)
if '-h' in unknown or '--help' in unknown:
return []
return unknown | [
"def",
"_chk_docunknown",
"(",
"args",
",",
"exp",
")",
":",
"unknown",
"=",
"[",
"]",
"for",
"arg",
"in",
"args",
":",
"if",
"arg",
"[",
":",
"2",
"]",
"==",
"'--'",
":",
"val",
"=",
"arg",
"[",
"2",
":",
"]",
"if",
"val",
"not",
"in",
"exp",
":",
"unknown",
".",
"append",
"(",
"arg",
")",
"elif",
"arg",
"[",
":",
"1",
"]",
"==",
"'-'",
":",
"val",
"=",
"arg",
"[",
"1",
":",
"]",
"if",
"val",
"not",
"in",
"exp",
":",
"unknown",
".",
"append",
"(",
"arg",
")",
"if",
"'-h'",
"in",
"unknown",
"or",
"'--help'",
"in",
"unknown",
":",
"return",
"[",
"]",
"return",
"unknown"
] | Return any unknown args. | [
"Return",
"any",
"unknown",
"args",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/docopt_parse.py#L82-L96 |
228,409 | tanghaibao/goatools | goatools/anno/dnld_ebi_goa.py | DnldGoa.dnld_goa | def dnld_goa(self, species, ext='gaf', item=None, fileout=None):
"""Download GOA source file name on EMBL-EBI ftp server."""
basename = self.get_basename(species, ext, item)
src = os.path.join(self.ftp_src_goa, species.upper(), "{F}.gz".format(F=basename))
dst = os.path.join(os.getcwd(), basename) if fileout is None else fileout
dnld_file(src, dst, prt=sys.stdout, loading_bar=None)
return dst | python | def dnld_goa(self, species, ext='gaf', item=None, fileout=None):
"""Download GOA source file name on EMBL-EBI ftp server."""
basename = self.get_basename(species, ext, item)
src = os.path.join(self.ftp_src_goa, species.upper(), "{F}.gz".format(F=basename))
dst = os.path.join(os.getcwd(), basename) if fileout is None else fileout
dnld_file(src, dst, prt=sys.stdout, loading_bar=None)
return dst | [
"def",
"dnld_goa",
"(",
"self",
",",
"species",
",",
"ext",
"=",
"'gaf'",
",",
"item",
"=",
"None",
",",
"fileout",
"=",
"None",
")",
":",
"basename",
"=",
"self",
".",
"get_basename",
"(",
"species",
",",
"ext",
",",
"item",
")",
"src",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"ftp_src_goa",
",",
"species",
".",
"upper",
"(",
")",
",",
"\"{F}.gz\"",
".",
"format",
"(",
"F",
"=",
"basename",
")",
")",
"dst",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"getcwd",
"(",
")",
",",
"basename",
")",
"if",
"fileout",
"is",
"None",
"else",
"fileout",
"dnld_file",
"(",
"src",
",",
"dst",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"loading_bar",
"=",
"None",
")",
"return",
"dst"
] | Download GOA source file name on EMBL-EBI ftp server. | [
"Download",
"GOA",
"source",
"file",
"name",
"on",
"EMBL",
"-",
"EBI",
"ftp",
"server",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/dnld_ebi_goa.py#L41-L47 |
228,410 | tanghaibao/goatools | goatools/associations.py | read_associations | def read_associations(assoc_fn, anno_type='id2gos', **kws):
"""Return associatinos in id2gos format"""
# kws get_objanno: taxids hdr_only prt allow_missing_symbol
obj = get_objanno(assoc_fn, anno_type, **kws)
# kws get_id2gos: ev_include ev_exclude keep_ND keep_NOT b_geneid2gos go2geneids
return obj.get_id2gos(**kws) | python | def read_associations(assoc_fn, anno_type='id2gos', **kws):
"""Return associatinos in id2gos format"""
# kws get_objanno: taxids hdr_only prt allow_missing_symbol
obj = get_objanno(assoc_fn, anno_type, **kws)
# kws get_id2gos: ev_include ev_exclude keep_ND keep_NOT b_geneid2gos go2geneids
return obj.get_id2gos(**kws) | [
"def",
"read_associations",
"(",
"assoc_fn",
",",
"anno_type",
"=",
"'id2gos'",
",",
"*",
"*",
"kws",
")",
":",
"# kws get_objanno: taxids hdr_only prt allow_missing_symbol",
"obj",
"=",
"get_objanno",
"(",
"assoc_fn",
",",
"anno_type",
",",
"*",
"*",
"kws",
")",
"# kws get_id2gos: ev_include ev_exclude keep_ND keep_NOT b_geneid2gos go2geneids",
"return",
"obj",
".",
"get_id2gos",
"(",
"*",
"*",
"kws",
")"
] | Return associatinos in id2gos format | [
"Return",
"associatinos",
"in",
"id2gos",
"format"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L49-L54 |
228,411 | tanghaibao/goatools | goatools/associations.py | dnld_ncbi_gene_file | def dnld_ncbi_gene_file(fin, force_dnld=False, log=sys.stdout, loading_bar=True):
"""Download a file from NCBI Gene's ftp server."""
if not os.path.exists(fin) or force_dnld:
import gzip
fin_dir, fin_base = os.path.split(fin)
fin_gz = "{F}.gz".format(F=fin_base)
fin_gz = os.path.join(fin_dir, fin_gz)
if os.path.exists(fin_gz):
os.remove(fin_gz)
fin_ftp = "ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/{F}.gz".format(F=fin_base)
## if log is not None:
## log.write(" DOWNLOADING GZIP: {GZ}\n".format(GZ=fin_ftp))
## if loading_bar:
## loading_bar = wget.bar_adaptive
## wget.download(fin_ftp, bar=loading_bar)
## rsp = wget(fin_ftp)
ftp_get(fin_ftp, fin_gz)
with gzip.open(fin_gz, 'rb') as zstrm:
if log is not None:
log.write("\n READ GZIP: {F}\n".format(F=fin_gz))
with open(fin, 'wb') as ostrm:
ostrm.write(zstrm.read())
if log is not None:
log.write(" WROTE UNZIPPED: {F}\n".format(F=fin)) | python | def dnld_ncbi_gene_file(fin, force_dnld=False, log=sys.stdout, loading_bar=True):
"""Download a file from NCBI Gene's ftp server."""
if not os.path.exists(fin) or force_dnld:
import gzip
fin_dir, fin_base = os.path.split(fin)
fin_gz = "{F}.gz".format(F=fin_base)
fin_gz = os.path.join(fin_dir, fin_gz)
if os.path.exists(fin_gz):
os.remove(fin_gz)
fin_ftp = "ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/{F}.gz".format(F=fin_base)
## if log is not None:
## log.write(" DOWNLOADING GZIP: {GZ}\n".format(GZ=fin_ftp))
## if loading_bar:
## loading_bar = wget.bar_adaptive
## wget.download(fin_ftp, bar=loading_bar)
## rsp = wget(fin_ftp)
ftp_get(fin_ftp, fin_gz)
with gzip.open(fin_gz, 'rb') as zstrm:
if log is not None:
log.write("\n READ GZIP: {F}\n".format(F=fin_gz))
with open(fin, 'wb') as ostrm:
ostrm.write(zstrm.read())
if log is not None:
log.write(" WROTE UNZIPPED: {F}\n".format(F=fin)) | [
"def",
"dnld_ncbi_gene_file",
"(",
"fin",
",",
"force_dnld",
"=",
"False",
",",
"log",
"=",
"sys",
".",
"stdout",
",",
"loading_bar",
"=",
"True",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"fin",
")",
"or",
"force_dnld",
":",
"import",
"gzip",
"fin_dir",
",",
"fin_base",
"=",
"os",
".",
"path",
".",
"split",
"(",
"fin",
")",
"fin_gz",
"=",
"\"{F}.gz\"",
".",
"format",
"(",
"F",
"=",
"fin_base",
")",
"fin_gz",
"=",
"os",
".",
"path",
".",
"join",
"(",
"fin_dir",
",",
"fin_gz",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"fin_gz",
")",
":",
"os",
".",
"remove",
"(",
"fin_gz",
")",
"fin_ftp",
"=",
"\"ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/{F}.gz\"",
".",
"format",
"(",
"F",
"=",
"fin_base",
")",
"## if log is not None:",
"## log.write(\" DOWNLOADING GZIP: {GZ}\\n\".format(GZ=fin_ftp))",
"## if loading_bar:",
"## loading_bar = wget.bar_adaptive",
"## wget.download(fin_ftp, bar=loading_bar)",
"## rsp = wget(fin_ftp)",
"ftp_get",
"(",
"fin_ftp",
",",
"fin_gz",
")",
"with",
"gzip",
".",
"open",
"(",
"fin_gz",
",",
"'rb'",
")",
"as",
"zstrm",
":",
"if",
"log",
"is",
"not",
"None",
":",
"log",
".",
"write",
"(",
"\"\\n READ GZIP: {F}\\n\"",
".",
"format",
"(",
"F",
"=",
"fin_gz",
")",
")",
"with",
"open",
"(",
"fin",
",",
"'wb'",
")",
"as",
"ostrm",
":",
"ostrm",
".",
"write",
"(",
"zstrm",
".",
"read",
"(",
")",
")",
"if",
"log",
"is",
"not",
"None",
":",
"log",
".",
"write",
"(",
"\" WROTE UNZIPPED: {F}\\n\"",
".",
"format",
"(",
"F",
"=",
"fin",
")",
")"
] | Download a file from NCBI Gene's ftp server. | [
"Download",
"a",
"file",
"from",
"NCBI",
"Gene",
"s",
"ftp",
"server",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L62-L85 |
228,412 | tanghaibao/goatools | goatools/associations.py | dnld_annofile | def dnld_annofile(fin_anno, anno_type):
"""Download annotation file, if needed"""
if os.path.exists(fin_anno):
return
anno_type = get_anno_desc(fin_anno, anno_type)
if anno_type == 'gene2go':
dnld_ncbi_gene_file(fin_anno)
if anno_type in {'gaf', 'gpad'}:
dnld_annotation(fin_anno) | python | def dnld_annofile(fin_anno, anno_type):
"""Download annotation file, if needed"""
if os.path.exists(fin_anno):
return
anno_type = get_anno_desc(fin_anno, anno_type)
if anno_type == 'gene2go':
dnld_ncbi_gene_file(fin_anno)
if anno_type in {'gaf', 'gpad'}:
dnld_annotation(fin_anno) | [
"def",
"dnld_annofile",
"(",
"fin_anno",
",",
"anno_type",
")",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"fin_anno",
")",
":",
"return",
"anno_type",
"=",
"get_anno_desc",
"(",
"fin_anno",
",",
"anno_type",
")",
"if",
"anno_type",
"==",
"'gene2go'",
":",
"dnld_ncbi_gene_file",
"(",
"fin_anno",
")",
"if",
"anno_type",
"in",
"{",
"'gaf'",
",",
"'gpad'",
"}",
":",
"dnld_annotation",
"(",
"fin_anno",
")"
] | Download annotation file, if needed | [
"Download",
"annotation",
"file",
"if",
"needed"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L87-L95 |
228,413 | tanghaibao/goatools | goatools/associations.py | read_ncbi_gene2go | def read_ncbi_gene2go(fin_gene2go, taxids=None, **kws):
"""Read NCBI's gene2go. Return gene2go data for user-specified taxids."""
obj = Gene2GoReader(fin_gene2go, taxids=taxids)
# By default, return id2gos. User can cause go2geneids to be returned by:
# >>> read_ncbi_gene2go(..., go2geneids=True
if 'taxid2asscs' not in kws:
if len(obj.taxid2asscs) == 1:
taxid = next(iter(obj.taxid2asscs))
kws_ncbi = {k:v for k, v in kws.items() if k in AnnoOptions.keys_exp}
kws_ncbi['taxid'] = taxid
return obj.get_id2gos(**kws_ncbi)
# Optional detailed associations split by taxid and having both ID2GOs & GO2IDs
# e.g., taxid2asscs = defaultdict(lambda: defaultdict(lambda: defaultdict(set))
t2asscs_ret = obj.get_taxid2asscs(taxids, **kws)
t2asscs_usr = kws.get('taxid2asscs', defaultdict(lambda: defaultdict(lambda: defaultdict(set))))
if 'taxid2asscs' in kws:
obj.fill_taxid2asscs(t2asscs_usr, t2asscs_ret)
return obj.get_id2gos_all(t2asscs_ret) | python | def read_ncbi_gene2go(fin_gene2go, taxids=None, **kws):
"""Read NCBI's gene2go. Return gene2go data for user-specified taxids."""
obj = Gene2GoReader(fin_gene2go, taxids=taxids)
# By default, return id2gos. User can cause go2geneids to be returned by:
# >>> read_ncbi_gene2go(..., go2geneids=True
if 'taxid2asscs' not in kws:
if len(obj.taxid2asscs) == 1:
taxid = next(iter(obj.taxid2asscs))
kws_ncbi = {k:v for k, v in kws.items() if k in AnnoOptions.keys_exp}
kws_ncbi['taxid'] = taxid
return obj.get_id2gos(**kws_ncbi)
# Optional detailed associations split by taxid and having both ID2GOs & GO2IDs
# e.g., taxid2asscs = defaultdict(lambda: defaultdict(lambda: defaultdict(set))
t2asscs_ret = obj.get_taxid2asscs(taxids, **kws)
t2asscs_usr = kws.get('taxid2asscs', defaultdict(lambda: defaultdict(lambda: defaultdict(set))))
if 'taxid2asscs' in kws:
obj.fill_taxid2asscs(t2asscs_usr, t2asscs_ret)
return obj.get_id2gos_all(t2asscs_ret) | [
"def",
"read_ncbi_gene2go",
"(",
"fin_gene2go",
",",
"taxids",
"=",
"None",
",",
"*",
"*",
"kws",
")",
":",
"obj",
"=",
"Gene2GoReader",
"(",
"fin_gene2go",
",",
"taxids",
"=",
"taxids",
")",
"# By default, return id2gos. User can cause go2geneids to be returned by:",
"# >>> read_ncbi_gene2go(..., go2geneids=True",
"if",
"'taxid2asscs'",
"not",
"in",
"kws",
":",
"if",
"len",
"(",
"obj",
".",
"taxid2asscs",
")",
"==",
"1",
":",
"taxid",
"=",
"next",
"(",
"iter",
"(",
"obj",
".",
"taxid2asscs",
")",
")",
"kws_ncbi",
"=",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"kws",
".",
"items",
"(",
")",
"if",
"k",
"in",
"AnnoOptions",
".",
"keys_exp",
"}",
"kws_ncbi",
"[",
"'taxid'",
"]",
"=",
"taxid",
"return",
"obj",
".",
"get_id2gos",
"(",
"*",
"*",
"kws_ncbi",
")",
"# Optional detailed associations split by taxid and having both ID2GOs & GO2IDs",
"# e.g., taxid2asscs = defaultdict(lambda: defaultdict(lambda: defaultdict(set))",
"t2asscs_ret",
"=",
"obj",
".",
"get_taxid2asscs",
"(",
"taxids",
",",
"*",
"*",
"kws",
")",
"t2asscs_usr",
"=",
"kws",
".",
"get",
"(",
"'taxid2asscs'",
",",
"defaultdict",
"(",
"lambda",
":",
"defaultdict",
"(",
"lambda",
":",
"defaultdict",
"(",
"set",
")",
")",
")",
")",
"if",
"'taxid2asscs'",
"in",
"kws",
":",
"obj",
".",
"fill_taxid2asscs",
"(",
"t2asscs_usr",
",",
"t2asscs_ret",
")",
"return",
"obj",
".",
"get_id2gos_all",
"(",
"t2asscs_ret",
")"
] | Read NCBI's gene2go. Return gene2go data for user-specified taxids. | [
"Read",
"NCBI",
"s",
"gene2go",
".",
"Return",
"gene2go",
"data",
"for",
"user",
"-",
"specified",
"taxids",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L97-L114 |
228,414 | tanghaibao/goatools | goatools/associations.py | get_b2aset | def get_b2aset(a2bset):
"""Given gene2gos, return go2genes. Given go2genes, return gene2gos."""
b2aset = {}
for a_item, bset in a2bset.items():
for b_item in bset:
if b_item in b2aset:
b2aset[b_item].add(a_item)
else:
b2aset[b_item] = set([a_item])
return b2aset | python | def get_b2aset(a2bset):
"""Given gene2gos, return go2genes. Given go2genes, return gene2gos."""
b2aset = {}
for a_item, bset in a2bset.items():
for b_item in bset:
if b_item in b2aset:
b2aset[b_item].add(a_item)
else:
b2aset[b_item] = set([a_item])
return b2aset | [
"def",
"get_b2aset",
"(",
"a2bset",
")",
":",
"b2aset",
"=",
"{",
"}",
"for",
"a_item",
",",
"bset",
"in",
"a2bset",
".",
"items",
"(",
")",
":",
"for",
"b_item",
"in",
"bset",
":",
"if",
"b_item",
"in",
"b2aset",
":",
"b2aset",
"[",
"b_item",
"]",
".",
"add",
"(",
"a_item",
")",
"else",
":",
"b2aset",
"[",
"b_item",
"]",
"=",
"set",
"(",
"[",
"a_item",
"]",
")",
"return",
"b2aset"
] | Given gene2gos, return go2genes. Given go2genes, return gene2gos. | [
"Given",
"gene2gos",
"return",
"go2genes",
".",
"Given",
"go2genes",
"return",
"gene2gos",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L125-L134 |
228,415 | tanghaibao/goatools | goatools/associations.py | get_assc_pruned | def get_assc_pruned(assc_geneid2gos, min_genecnt=None, max_genecnt=None, prt=sys.stdout):
"""Remove GO IDs associated with large numbers of genes. Used in stochastic simulations."""
# DEFN WAS: get_assc_pruned(assc_geneid2gos, max_genecnt=None, prt=sys.stdout):
# ADDED min_genecnt argument and functionality
if max_genecnt is None and min_genecnt is None:
return assc_geneid2gos, set()
go2genes_orig = get_b2aset(assc_geneid2gos)
# go2genes_prun = {go:gs for go, gs in go2genes_orig.items() if len(gs) <= max_genecnt}
go2genes_prun = {}
for goid, genes in go2genes_orig.items():
num_genes = len(genes)
if (min_genecnt is None or num_genes >= min_genecnt) and \
(max_genecnt is None or num_genes <= max_genecnt):
go2genes_prun[goid] = genes
num_was = len(go2genes_orig)
num_now = len(go2genes_prun)
gos_rm = set(go2genes_orig.keys()).difference(set(go2genes_prun.keys()))
assert num_was-num_now == len(gos_rm)
if prt is not None:
if min_genecnt is None:
min_genecnt = 1
if max_genecnt is None:
max_genecnt = "Max"
prt.write("{N:4} GO IDs pruned. Kept {NOW} GOs assc w/({m} to {M} genes)\n".format(
m=min_genecnt, M=max_genecnt, N=num_was-num_now, NOW=num_now))
return get_b2aset(go2genes_prun), gos_rm | python | def get_assc_pruned(assc_geneid2gos, min_genecnt=None, max_genecnt=None, prt=sys.stdout):
"""Remove GO IDs associated with large numbers of genes. Used in stochastic simulations."""
# DEFN WAS: get_assc_pruned(assc_geneid2gos, max_genecnt=None, prt=sys.stdout):
# ADDED min_genecnt argument and functionality
if max_genecnt is None and min_genecnt is None:
return assc_geneid2gos, set()
go2genes_orig = get_b2aset(assc_geneid2gos)
# go2genes_prun = {go:gs for go, gs in go2genes_orig.items() if len(gs) <= max_genecnt}
go2genes_prun = {}
for goid, genes in go2genes_orig.items():
num_genes = len(genes)
if (min_genecnt is None or num_genes >= min_genecnt) and \
(max_genecnt is None or num_genes <= max_genecnt):
go2genes_prun[goid] = genes
num_was = len(go2genes_orig)
num_now = len(go2genes_prun)
gos_rm = set(go2genes_orig.keys()).difference(set(go2genes_prun.keys()))
assert num_was-num_now == len(gos_rm)
if prt is not None:
if min_genecnt is None:
min_genecnt = 1
if max_genecnt is None:
max_genecnt = "Max"
prt.write("{N:4} GO IDs pruned. Kept {NOW} GOs assc w/({m} to {M} genes)\n".format(
m=min_genecnt, M=max_genecnt, N=num_was-num_now, NOW=num_now))
return get_b2aset(go2genes_prun), gos_rm | [
"def",
"get_assc_pruned",
"(",
"assc_geneid2gos",
",",
"min_genecnt",
"=",
"None",
",",
"max_genecnt",
"=",
"None",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"# DEFN WAS: get_assc_pruned(assc_geneid2gos, max_genecnt=None, prt=sys.stdout):",
"# ADDED min_genecnt argument and functionality",
"if",
"max_genecnt",
"is",
"None",
"and",
"min_genecnt",
"is",
"None",
":",
"return",
"assc_geneid2gos",
",",
"set",
"(",
")",
"go2genes_orig",
"=",
"get_b2aset",
"(",
"assc_geneid2gos",
")",
"# go2genes_prun = {go:gs for go, gs in go2genes_orig.items() if len(gs) <= max_genecnt}",
"go2genes_prun",
"=",
"{",
"}",
"for",
"goid",
",",
"genes",
"in",
"go2genes_orig",
".",
"items",
"(",
")",
":",
"num_genes",
"=",
"len",
"(",
"genes",
")",
"if",
"(",
"min_genecnt",
"is",
"None",
"or",
"num_genes",
">=",
"min_genecnt",
")",
"and",
"(",
"max_genecnt",
"is",
"None",
"or",
"num_genes",
"<=",
"max_genecnt",
")",
":",
"go2genes_prun",
"[",
"goid",
"]",
"=",
"genes",
"num_was",
"=",
"len",
"(",
"go2genes_orig",
")",
"num_now",
"=",
"len",
"(",
"go2genes_prun",
")",
"gos_rm",
"=",
"set",
"(",
"go2genes_orig",
".",
"keys",
"(",
")",
")",
".",
"difference",
"(",
"set",
"(",
"go2genes_prun",
".",
"keys",
"(",
")",
")",
")",
"assert",
"num_was",
"-",
"num_now",
"==",
"len",
"(",
"gos_rm",
")",
"if",
"prt",
"is",
"not",
"None",
":",
"if",
"min_genecnt",
"is",
"None",
":",
"min_genecnt",
"=",
"1",
"if",
"max_genecnt",
"is",
"None",
":",
"max_genecnt",
"=",
"\"Max\"",
"prt",
".",
"write",
"(",
"\"{N:4} GO IDs pruned. Kept {NOW} GOs assc w/({m} to {M} genes)\\n\"",
".",
"format",
"(",
"m",
"=",
"min_genecnt",
",",
"M",
"=",
"max_genecnt",
",",
"N",
"=",
"num_was",
"-",
"num_now",
",",
"NOW",
"=",
"num_now",
")",
")",
"return",
"get_b2aset",
"(",
"go2genes_prun",
")",
",",
"gos_rm"
] | Remove GO IDs associated with large numbers of genes. Used in stochastic simulations. | [
"Remove",
"GO",
"IDs",
"associated",
"with",
"large",
"numbers",
"of",
"genes",
".",
"Used",
"in",
"stochastic",
"simulations",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L136-L161 |
228,416 | tanghaibao/goatools | goatools/associations.py | read_annotations | def read_annotations(**kws):
"""Read annotations from either a GAF file or NCBI's gene2go file."""
if 'gaf' not in kws and 'gene2go' not in kws:
return
gene2gos = None
if 'gaf' in kws:
gene2gos = read_gaf(kws['gaf'], prt=sys.stdout)
if not gene2gos:
raise RuntimeError("NO ASSOCIATIONS LOADED FROM {F}".format(F=kws['gaf']))
elif 'gene2go' in kws:
assert 'taxid' in kws, 'taxid IS REQUIRED WHEN READING gene2go'
gene2gos = read_ncbi_gene2go(kws['gene2go'], taxids=[kws['taxid']])
if not gene2gos:
raise RuntimeError("NO ASSOCIATIONS LOADED FROM {F} FOR TAXID({T})".format(
F=kws['gene2go'], T=kws['taxid']))
return gene2gos | python | def read_annotations(**kws):
"""Read annotations from either a GAF file or NCBI's gene2go file."""
if 'gaf' not in kws and 'gene2go' not in kws:
return
gene2gos = None
if 'gaf' in kws:
gene2gos = read_gaf(kws['gaf'], prt=sys.stdout)
if not gene2gos:
raise RuntimeError("NO ASSOCIATIONS LOADED FROM {F}".format(F=kws['gaf']))
elif 'gene2go' in kws:
assert 'taxid' in kws, 'taxid IS REQUIRED WHEN READING gene2go'
gene2gos = read_ncbi_gene2go(kws['gene2go'], taxids=[kws['taxid']])
if not gene2gos:
raise RuntimeError("NO ASSOCIATIONS LOADED FROM {F} FOR TAXID({T})".format(
F=kws['gene2go'], T=kws['taxid']))
return gene2gos | [
"def",
"read_annotations",
"(",
"*",
"*",
"kws",
")",
":",
"if",
"'gaf'",
"not",
"in",
"kws",
"and",
"'gene2go'",
"not",
"in",
"kws",
":",
"return",
"gene2gos",
"=",
"None",
"if",
"'gaf'",
"in",
"kws",
":",
"gene2gos",
"=",
"read_gaf",
"(",
"kws",
"[",
"'gaf'",
"]",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
"if",
"not",
"gene2gos",
":",
"raise",
"RuntimeError",
"(",
"\"NO ASSOCIATIONS LOADED FROM {F}\"",
".",
"format",
"(",
"F",
"=",
"kws",
"[",
"'gaf'",
"]",
")",
")",
"elif",
"'gene2go'",
"in",
"kws",
":",
"assert",
"'taxid'",
"in",
"kws",
",",
"'taxid IS REQUIRED WHEN READING gene2go'",
"gene2gos",
"=",
"read_ncbi_gene2go",
"(",
"kws",
"[",
"'gene2go'",
"]",
",",
"taxids",
"=",
"[",
"kws",
"[",
"'taxid'",
"]",
"]",
")",
"if",
"not",
"gene2gos",
":",
"raise",
"RuntimeError",
"(",
"\"NO ASSOCIATIONS LOADED FROM {F} FOR TAXID({T})\"",
".",
"format",
"(",
"F",
"=",
"kws",
"[",
"'gene2go'",
"]",
",",
"T",
"=",
"kws",
"[",
"'taxid'",
"]",
")",
")",
"return",
"gene2gos"
] | Read annotations from either a GAF file or NCBI's gene2go file. | [
"Read",
"annotations",
"from",
"either",
"a",
"GAF",
"file",
"or",
"NCBI",
"s",
"gene2go",
"file",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L163-L178 |
228,417 | tanghaibao/goatools | goatools/associations.py | get_tcntobj | def get_tcntobj(go2obj, **kws):
"""Return a TermCounts object if the user provides an annotation file, otherwise None."""
# kws: gaf gene2go
annots = read_annotations(**kws)
if annots:
return TermCounts(go2obj, annots) | python | def get_tcntobj(go2obj, **kws):
"""Return a TermCounts object if the user provides an annotation file, otherwise None."""
# kws: gaf gene2go
annots = read_annotations(**kws)
if annots:
return TermCounts(go2obj, annots) | [
"def",
"get_tcntobj",
"(",
"go2obj",
",",
"*",
"*",
"kws",
")",
":",
"# kws: gaf gene2go",
"annots",
"=",
"read_annotations",
"(",
"*",
"*",
"kws",
")",
"if",
"annots",
":",
"return",
"TermCounts",
"(",
"go2obj",
",",
"annots",
")"
] | Return a TermCounts object if the user provides an annotation file, otherwise None. | [
"Return",
"a",
"TermCounts",
"object",
"if",
"the",
"user",
"provides",
"an",
"annotation",
"file",
"otherwise",
"None",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L180-L185 |
228,418 | tanghaibao/goatools | goatools/wr_tbl_class.py | get_hdrs | def get_hdrs(flds_all, **kws):
"""Return headers, given user-specified key-word args."""
# Return Headers if the user explicitly lists them.
hdrs = kws.get('hdrs', None)
if hdrs is not None:
return hdrs
# User may specify a subset of fields or a column order using prt_flds
if 'prt_flds' in kws:
return kws['prt_flds']
# All fields in the namedtuple will be in the headers
return flds_all | python | def get_hdrs(flds_all, **kws):
"""Return headers, given user-specified key-word args."""
# Return Headers if the user explicitly lists them.
hdrs = kws.get('hdrs', None)
if hdrs is not None:
return hdrs
# User may specify a subset of fields or a column order using prt_flds
if 'prt_flds' in kws:
return kws['prt_flds']
# All fields in the namedtuple will be in the headers
return flds_all | [
"def",
"get_hdrs",
"(",
"flds_all",
",",
"*",
"*",
"kws",
")",
":",
"# Return Headers if the user explicitly lists them.",
"hdrs",
"=",
"kws",
".",
"get",
"(",
"'hdrs'",
",",
"None",
")",
"if",
"hdrs",
"is",
"not",
"None",
":",
"return",
"hdrs",
"# User may specify a subset of fields or a column order using prt_flds",
"if",
"'prt_flds'",
"in",
"kws",
":",
"return",
"kws",
"[",
"'prt_flds'",
"]",
"# All fields in the namedtuple will be in the headers",
"return",
"flds_all"
] | Return headers, given user-specified key-word args. | [
"Return",
"headers",
"given",
"user",
"-",
"specified",
"key",
"-",
"word",
"args",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L218-L228 |
228,419 | tanghaibao/goatools | goatools/wr_tbl_class.py | WrXlsx.wr_row_mergeall | def wr_row_mergeall(self, worksheet, txtstr, fmt, row_idx):
"""Merge all columns and place text string in widened cell."""
hdridxval = len(self.hdrs) - 1
worksheet.merge_range(row_idx, 0, row_idx, hdridxval, txtstr, fmt)
return row_idx + 1 | python | def wr_row_mergeall(self, worksheet, txtstr, fmt, row_idx):
"""Merge all columns and place text string in widened cell."""
hdridxval = len(self.hdrs) - 1
worksheet.merge_range(row_idx, 0, row_idx, hdridxval, txtstr, fmt)
return row_idx + 1 | [
"def",
"wr_row_mergeall",
"(",
"self",
",",
"worksheet",
",",
"txtstr",
",",
"fmt",
",",
"row_idx",
")",
":",
"hdridxval",
"=",
"len",
"(",
"self",
".",
"hdrs",
")",
"-",
"1",
"worksheet",
".",
"merge_range",
"(",
"row_idx",
",",
"0",
",",
"row_idx",
",",
"hdridxval",
",",
"txtstr",
",",
"fmt",
")",
"return",
"row_idx",
"+",
"1"
] | Merge all columns and place text string in widened cell. | [
"Merge",
"all",
"columns",
"and",
"place",
"text",
"string",
"in",
"widened",
"cell",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L49-L53 |
228,420 | tanghaibao/goatools | goatools/wr_tbl_class.py | WrXlsx.wr_hdrs | def wr_hdrs(self, worksheet, row_idx):
"""Print row of column headers"""
for col_idx, hdr in enumerate(self.hdrs):
# print("ROW({R}) COL({C}) HDR({H}) FMT({F})\n".format(
# R=row_idx, C=col_idx, H=hdr, F=self.fmt_hdr))
worksheet.write(row_idx, col_idx, hdr, self.fmt_hdr)
row_idx += 1
return row_idx | python | def wr_hdrs(self, worksheet, row_idx):
"""Print row of column headers"""
for col_idx, hdr in enumerate(self.hdrs):
# print("ROW({R}) COL({C}) HDR({H}) FMT({F})\n".format(
# R=row_idx, C=col_idx, H=hdr, F=self.fmt_hdr))
worksheet.write(row_idx, col_idx, hdr, self.fmt_hdr)
row_idx += 1
return row_idx | [
"def",
"wr_hdrs",
"(",
"self",
",",
"worksheet",
",",
"row_idx",
")",
":",
"for",
"col_idx",
",",
"hdr",
"in",
"enumerate",
"(",
"self",
".",
"hdrs",
")",
":",
"# print(\"ROW({R}) COL({C}) HDR({H}) FMT({F})\\n\".format(",
"# R=row_idx, C=col_idx, H=hdr, F=self.fmt_hdr))",
"worksheet",
".",
"write",
"(",
"row_idx",
",",
"col_idx",
",",
"hdr",
",",
"self",
".",
"fmt_hdr",
")",
"row_idx",
"+=",
"1",
"return",
"row_idx"
] | Print row of column headers | [
"Print",
"row",
"of",
"column",
"headers"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L55-L62 |
228,421 | tanghaibao/goatools | goatools/wr_tbl_class.py | WrXlsx.wr_data | def wr_data(self, xlsx_data, row_i, worksheet):
"""Write data into xlsx worksheet."""
fld2fmt = self.vars.fld2fmt
# User may specify to skip rows based on values in row
prt_if = self.vars.prt_if
# User may specify a subset of columns to print or
# a column ordering different from the _fields seen in the namedtuple
prt_flds = self.wbfmtobj.get_prt_flds()
get_wbfmt = self.wbfmtobj.get_wbfmt
if self.vars.sort_by is not None:
xlsx_data = sorted(xlsx_data, key=self.vars.sort_by)
try:
for data_nt in xlsx_data:
if prt_if is None or prt_if(data_nt):
wbfmt = get_wbfmt(data_nt) # xlsxwriter.format.Format created w/add_format
# Print an xlsx row by printing each column in order.
for col_i, fld in enumerate(prt_flds):
try:
# If fld "format_txt" present, use val for formatting, but don't print.
val = getattr(data_nt, fld, "")
# Optional user-formatting of specific fields, eg, pval: "{:8.2e}"
# If field value is empty (""), don't use fld2fmt
if fld2fmt is not None and fld in fld2fmt and val != "" and val != "*":
val = fld2fmt[fld].format(val)
worksheet.write(row_i, col_i, val, wbfmt)
except:
raise RuntimeError(self._get_err_msg(row_i, col_i, fld, val, prt_flds))
row_i += 1
except RuntimeError as inst:
import traceback
traceback.print_exc()
sys.stderr.write("\n **FATAL in wr_data: {MSG}\n\n".format(MSG=str(inst)))
sys.exit(1)
return row_i | python | def wr_data(self, xlsx_data, row_i, worksheet):
"""Write data into xlsx worksheet."""
fld2fmt = self.vars.fld2fmt
# User may specify to skip rows based on values in row
prt_if = self.vars.prt_if
# User may specify a subset of columns to print or
# a column ordering different from the _fields seen in the namedtuple
prt_flds = self.wbfmtobj.get_prt_flds()
get_wbfmt = self.wbfmtobj.get_wbfmt
if self.vars.sort_by is not None:
xlsx_data = sorted(xlsx_data, key=self.vars.sort_by)
try:
for data_nt in xlsx_data:
if prt_if is None or prt_if(data_nt):
wbfmt = get_wbfmt(data_nt) # xlsxwriter.format.Format created w/add_format
# Print an xlsx row by printing each column in order.
for col_i, fld in enumerate(prt_flds):
try:
# If fld "format_txt" present, use val for formatting, but don't print.
val = getattr(data_nt, fld, "")
# Optional user-formatting of specific fields, eg, pval: "{:8.2e}"
# If field value is empty (""), don't use fld2fmt
if fld2fmt is not None and fld in fld2fmt and val != "" and val != "*":
val = fld2fmt[fld].format(val)
worksheet.write(row_i, col_i, val, wbfmt)
except:
raise RuntimeError(self._get_err_msg(row_i, col_i, fld, val, prt_flds))
row_i += 1
except RuntimeError as inst:
import traceback
traceback.print_exc()
sys.stderr.write("\n **FATAL in wr_data: {MSG}\n\n".format(MSG=str(inst)))
sys.exit(1)
return row_i | [
"def",
"wr_data",
"(",
"self",
",",
"xlsx_data",
",",
"row_i",
",",
"worksheet",
")",
":",
"fld2fmt",
"=",
"self",
".",
"vars",
".",
"fld2fmt",
"# User may specify to skip rows based on values in row",
"prt_if",
"=",
"self",
".",
"vars",
".",
"prt_if",
"# User may specify a subset of columns to print or",
"# a column ordering different from the _fields seen in the namedtuple",
"prt_flds",
"=",
"self",
".",
"wbfmtobj",
".",
"get_prt_flds",
"(",
")",
"get_wbfmt",
"=",
"self",
".",
"wbfmtobj",
".",
"get_wbfmt",
"if",
"self",
".",
"vars",
".",
"sort_by",
"is",
"not",
"None",
":",
"xlsx_data",
"=",
"sorted",
"(",
"xlsx_data",
",",
"key",
"=",
"self",
".",
"vars",
".",
"sort_by",
")",
"try",
":",
"for",
"data_nt",
"in",
"xlsx_data",
":",
"if",
"prt_if",
"is",
"None",
"or",
"prt_if",
"(",
"data_nt",
")",
":",
"wbfmt",
"=",
"get_wbfmt",
"(",
"data_nt",
")",
"# xlsxwriter.format.Format created w/add_format",
"# Print an xlsx row by printing each column in order.",
"for",
"col_i",
",",
"fld",
"in",
"enumerate",
"(",
"prt_flds",
")",
":",
"try",
":",
"# If fld \"format_txt\" present, use val for formatting, but don't print.",
"val",
"=",
"getattr",
"(",
"data_nt",
",",
"fld",
",",
"\"\"",
")",
"# Optional user-formatting of specific fields, eg, pval: \"{:8.2e}\"",
"# If field value is empty (\"\"), don't use fld2fmt",
"if",
"fld2fmt",
"is",
"not",
"None",
"and",
"fld",
"in",
"fld2fmt",
"and",
"val",
"!=",
"\"\"",
"and",
"val",
"!=",
"\"*\"",
":",
"val",
"=",
"fld2fmt",
"[",
"fld",
"]",
".",
"format",
"(",
"val",
")",
"worksheet",
".",
"write",
"(",
"row_i",
",",
"col_i",
",",
"val",
",",
"wbfmt",
")",
"except",
":",
"raise",
"RuntimeError",
"(",
"self",
".",
"_get_err_msg",
"(",
"row_i",
",",
"col_i",
",",
"fld",
",",
"val",
",",
"prt_flds",
")",
")",
"row_i",
"+=",
"1",
"except",
"RuntimeError",
"as",
"inst",
":",
"import",
"traceback",
"traceback",
".",
"print_exc",
"(",
")",
"sys",
".",
"stderr",
".",
"write",
"(",
"\"\\n **FATAL in wr_data: {MSG}\\n\\n\"",
".",
"format",
"(",
"MSG",
"=",
"str",
"(",
"inst",
")",
")",
")",
"sys",
".",
"exit",
"(",
"1",
")",
"return",
"row_i"
] | Write data into xlsx worksheet. | [
"Write",
"data",
"into",
"xlsx",
"worksheet",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L64-L97 |
228,422 | tanghaibao/goatools | goatools/wr_tbl_class.py | WrXlsx._get_err_msg | def _get_err_msg(row, col, fld, val, prt_flds):
"""Return an informative message with details of xlsx write attempt."""
import traceback
traceback.print_exc()
err_msg = (
"ROW({R}) COL({C}) FIELD({F}) VAL({V})\n".format(R=row, C=col, F=fld, V=val),
"PRINT FIELDS({N}): {F}".format(N=len(prt_flds), F=" ".join(prt_flds)))
return "\n".join(err_msg) | python | def _get_err_msg(row, col, fld, val, prt_flds):
"""Return an informative message with details of xlsx write attempt."""
import traceback
traceback.print_exc()
err_msg = (
"ROW({R}) COL({C}) FIELD({F}) VAL({V})\n".format(R=row, C=col, F=fld, V=val),
"PRINT FIELDS({N}): {F}".format(N=len(prt_flds), F=" ".join(prt_flds)))
return "\n".join(err_msg) | [
"def",
"_get_err_msg",
"(",
"row",
",",
"col",
",",
"fld",
",",
"val",
",",
"prt_flds",
")",
":",
"import",
"traceback",
"traceback",
".",
"print_exc",
"(",
")",
"err_msg",
"=",
"(",
"\"ROW({R}) COL({C}) FIELD({F}) VAL({V})\\n\"",
".",
"format",
"(",
"R",
"=",
"row",
",",
"C",
"=",
"col",
",",
"F",
"=",
"fld",
",",
"V",
"=",
"val",
")",
",",
"\"PRINT FIELDS({N}): {F}\"",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"prt_flds",
")",
",",
"F",
"=",
"\" \"",
".",
"join",
"(",
"prt_flds",
")",
")",
")",
"return",
"\"\\n\"",
".",
"join",
"(",
"err_msg",
")"
] | Return an informative message with details of xlsx write attempt. | [
"Return",
"an",
"informative",
"message",
"with",
"details",
"of",
"xlsx",
"write",
"attempt",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L100-L107 |
228,423 | tanghaibao/goatools | goatools/wr_tbl_class.py | WrXlsx.add_worksheet | def add_worksheet(self):
"""Add a worksheet to the workbook."""
wsh = self.workbook.add_worksheet()
if self.vars.fld2col_widths is not None:
self.set_xlsx_colwidths(wsh, self.vars.fld2col_widths, self.wbfmtobj.get_prt_flds())
return wsh | python | def add_worksheet(self):
"""Add a worksheet to the workbook."""
wsh = self.workbook.add_worksheet()
if self.vars.fld2col_widths is not None:
self.set_xlsx_colwidths(wsh, self.vars.fld2col_widths, self.wbfmtobj.get_prt_flds())
return wsh | [
"def",
"add_worksheet",
"(",
"self",
")",
":",
"wsh",
"=",
"self",
".",
"workbook",
".",
"add_worksheet",
"(",
")",
"if",
"self",
".",
"vars",
".",
"fld2col_widths",
"is",
"not",
"None",
":",
"self",
".",
"set_xlsx_colwidths",
"(",
"wsh",
",",
"self",
".",
"vars",
".",
"fld2col_widths",
",",
"self",
".",
"wbfmtobj",
".",
"get_prt_flds",
"(",
")",
")",
"return",
"wsh"
] | Add a worksheet to the workbook. | [
"Add",
"a",
"worksheet",
"to",
"the",
"workbook",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L109-L114 |
228,424 | tanghaibao/goatools | goatools/wr_tbl_class.py | WrXlsx.set_xlsx_colwidths | def set_xlsx_colwidths(worksheet, fld2col_widths, fldnames):
"""Set xlsx column widths using fld2col_widths."""
for col_idx, fld in enumerate(fldnames):
col_width = fld2col_widths.get(fld, None)
if col_width is not None:
worksheet.set_column(col_idx, col_idx, col_width) | python | def set_xlsx_colwidths(worksheet, fld2col_widths, fldnames):
"""Set xlsx column widths using fld2col_widths."""
for col_idx, fld in enumerate(fldnames):
col_width = fld2col_widths.get(fld, None)
if col_width is not None:
worksheet.set_column(col_idx, col_idx, col_width) | [
"def",
"set_xlsx_colwidths",
"(",
"worksheet",
",",
"fld2col_widths",
",",
"fldnames",
")",
":",
"for",
"col_idx",
",",
"fld",
"in",
"enumerate",
"(",
"fldnames",
")",
":",
"col_width",
"=",
"fld2col_widths",
".",
"get",
"(",
"fld",
",",
"None",
")",
"if",
"col_width",
"is",
"not",
"None",
":",
"worksheet",
".",
"set_column",
"(",
"col_idx",
",",
"col_idx",
",",
"col_width",
")"
] | Set xlsx column widths using fld2col_widths. | [
"Set",
"xlsx",
"column",
"widths",
"using",
"fld2col_widths",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L117-L122 |
228,425 | tanghaibao/goatools | goatools/wr_tbl_class.py | WbFmt.get_hdrs | def get_hdrs(self, **kws):
"""Initialize column headers."""
hdrs = get_hdrs(self.prt_flds, **kws)
# Values in a "format_txt" "column" are used for formatting, not printing
return [h for h in hdrs if h != "format_txt"] | python | def get_hdrs(self, **kws):
"""Initialize column headers."""
hdrs = get_hdrs(self.prt_flds, **kws)
# Values in a "format_txt" "column" are used for formatting, not printing
return [h for h in hdrs if h != "format_txt"] | [
"def",
"get_hdrs",
"(",
"self",
",",
"*",
"*",
"kws",
")",
":",
"hdrs",
"=",
"get_hdrs",
"(",
"self",
".",
"prt_flds",
",",
"*",
"*",
"kws",
")",
"# Values in a \"format_txt\" \"column\" are used for formatting, not printing",
"return",
"[",
"h",
"for",
"h",
"in",
"hdrs",
"if",
"h",
"!=",
"\"format_txt\"",
"]"
] | Initialize column headers. | [
"Initialize",
"column",
"headers",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L149-L153 |
228,426 | tanghaibao/goatools | goatools/wr_tbl_class.py | WbFmt._init_fmtname2wbfmtobj | def _init_fmtname2wbfmtobj(self, workbook, **kws):
"""Initialize fmtname2wbfmtobj."""
wbfmtdict = [
kws.get('format_txt0', self.dflt_wbfmtdict[0]),
kws.get('format_txt1', self.dflt_wbfmtdict[1]),
kws.get('format_txt2', self.dflt_wbfmtdict[2]),
kws.get('format_txt3', self.dflt_wbfmtdict[3])]
fmtname2wbfmtobj = {
'plain': workbook.add_format(wbfmtdict[0]),
'plain bold': workbook.add_format(wbfmtdict[3]),
'very light grey' : workbook.add_format(wbfmtdict[1]),
'light grey' :workbook.add_format(wbfmtdict[2])}
# Use a xlsx namedtuple field value to set row color
ntval2wbfmtdict = kws.get('ntval2wbfmtdict', None)
if ntval2wbfmtdict is not None:
for ntval, wbfmtdict in ntval2wbfmtdict.items():
fmtname2wbfmtobj[ntval] = workbook.add_format(wbfmtdict)
if 'ntfld_wbfmt' not in kws:
sys.stdout.write("**WARNING: 'ntfld_wbfmt' NOT PRESENT\n")
return fmtname2wbfmtobj | python | def _init_fmtname2wbfmtobj(self, workbook, **kws):
"""Initialize fmtname2wbfmtobj."""
wbfmtdict = [
kws.get('format_txt0', self.dflt_wbfmtdict[0]),
kws.get('format_txt1', self.dflt_wbfmtdict[1]),
kws.get('format_txt2', self.dflt_wbfmtdict[2]),
kws.get('format_txt3', self.dflt_wbfmtdict[3])]
fmtname2wbfmtobj = {
'plain': workbook.add_format(wbfmtdict[0]),
'plain bold': workbook.add_format(wbfmtdict[3]),
'very light grey' : workbook.add_format(wbfmtdict[1]),
'light grey' :workbook.add_format(wbfmtdict[2])}
# Use a xlsx namedtuple field value to set row color
ntval2wbfmtdict = kws.get('ntval2wbfmtdict', None)
if ntval2wbfmtdict is not None:
for ntval, wbfmtdict in ntval2wbfmtdict.items():
fmtname2wbfmtobj[ntval] = workbook.add_format(wbfmtdict)
if 'ntfld_wbfmt' not in kws:
sys.stdout.write("**WARNING: 'ntfld_wbfmt' NOT PRESENT\n")
return fmtname2wbfmtobj | [
"def",
"_init_fmtname2wbfmtobj",
"(",
"self",
",",
"workbook",
",",
"*",
"*",
"kws",
")",
":",
"wbfmtdict",
"=",
"[",
"kws",
".",
"get",
"(",
"'format_txt0'",
",",
"self",
".",
"dflt_wbfmtdict",
"[",
"0",
"]",
")",
",",
"kws",
".",
"get",
"(",
"'format_txt1'",
",",
"self",
".",
"dflt_wbfmtdict",
"[",
"1",
"]",
")",
",",
"kws",
".",
"get",
"(",
"'format_txt2'",
",",
"self",
".",
"dflt_wbfmtdict",
"[",
"2",
"]",
")",
",",
"kws",
".",
"get",
"(",
"'format_txt3'",
",",
"self",
".",
"dflt_wbfmtdict",
"[",
"3",
"]",
")",
"]",
"fmtname2wbfmtobj",
"=",
"{",
"'plain'",
":",
"workbook",
".",
"add_format",
"(",
"wbfmtdict",
"[",
"0",
"]",
")",
",",
"'plain bold'",
":",
"workbook",
".",
"add_format",
"(",
"wbfmtdict",
"[",
"3",
"]",
")",
",",
"'very light grey'",
":",
"workbook",
".",
"add_format",
"(",
"wbfmtdict",
"[",
"1",
"]",
")",
",",
"'light grey'",
":",
"workbook",
".",
"add_format",
"(",
"wbfmtdict",
"[",
"2",
"]",
")",
"}",
"# Use a xlsx namedtuple field value to set row color",
"ntval2wbfmtdict",
"=",
"kws",
".",
"get",
"(",
"'ntval2wbfmtdict'",
",",
"None",
")",
"if",
"ntval2wbfmtdict",
"is",
"not",
"None",
":",
"for",
"ntval",
",",
"wbfmtdict",
"in",
"ntval2wbfmtdict",
".",
"items",
"(",
")",
":",
"fmtname2wbfmtobj",
"[",
"ntval",
"]",
"=",
"workbook",
".",
"add_format",
"(",
"wbfmtdict",
")",
"if",
"'ntfld_wbfmt'",
"not",
"in",
"kws",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\"**WARNING: 'ntfld_wbfmt' NOT PRESENT\\n\"",
")",
"return",
"fmtname2wbfmtobj"
] | Initialize fmtname2wbfmtobj. | [
"Initialize",
"fmtname2wbfmtobj",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L155-L174 |
228,427 | tanghaibao/goatools | goatools/wr_tbl_class.py | WbFmt.get_wbfmt | def get_wbfmt(self, data_nt=None):
"""Return format for text cell."""
if data_nt is None or self.b_plain:
return self.fmtname2wbfmtobj.get('plain')
# User namedtuple field/value for color
if self.ntfld_wbfmt is not None:
return self.__get_wbfmt_usrfld(data_nt)
# namedtuple format_txt for color/bold/border
if self.b_format_txt:
wbfmt = self.__get_wbfmt_format_txt(data_nt)
if wbfmt is not None:
return wbfmt
# 'ntfld_wbfmt': namedtuple field which contains a value used as a key for a xlsx format
# 'ntval2wbfmtdict': namedtuple value and corresponding xlsx format dict.
return self.fmtname2wbfmtobj.get('plain') | python | def get_wbfmt(self, data_nt=None):
"""Return format for text cell."""
if data_nt is None or self.b_plain:
return self.fmtname2wbfmtobj.get('plain')
# User namedtuple field/value for color
if self.ntfld_wbfmt is not None:
return self.__get_wbfmt_usrfld(data_nt)
# namedtuple format_txt for color/bold/border
if self.b_format_txt:
wbfmt = self.__get_wbfmt_format_txt(data_nt)
if wbfmt is not None:
return wbfmt
# 'ntfld_wbfmt': namedtuple field which contains a value used as a key for a xlsx format
# 'ntval2wbfmtdict': namedtuple value and corresponding xlsx format dict.
return self.fmtname2wbfmtobj.get('plain') | [
"def",
"get_wbfmt",
"(",
"self",
",",
"data_nt",
"=",
"None",
")",
":",
"if",
"data_nt",
"is",
"None",
"or",
"self",
".",
"b_plain",
":",
"return",
"self",
".",
"fmtname2wbfmtobj",
".",
"get",
"(",
"'plain'",
")",
"# User namedtuple field/value for color",
"if",
"self",
".",
"ntfld_wbfmt",
"is",
"not",
"None",
":",
"return",
"self",
".",
"__get_wbfmt_usrfld",
"(",
"data_nt",
")",
"# namedtuple format_txt for color/bold/border",
"if",
"self",
".",
"b_format_txt",
":",
"wbfmt",
"=",
"self",
".",
"__get_wbfmt_format_txt",
"(",
"data_nt",
")",
"if",
"wbfmt",
"is",
"not",
"None",
":",
"return",
"wbfmt",
"# 'ntfld_wbfmt': namedtuple field which contains a value used as a key for a xlsx format",
"# 'ntval2wbfmtdict': namedtuple value and corresponding xlsx format dict.",
"return",
"self",
".",
"fmtname2wbfmtobj",
".",
"get",
"(",
"'plain'",
")"
] | Return format for text cell. | [
"Return",
"format",
"for",
"text",
"cell",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L176-L190 |
228,428 | tanghaibao/goatools | goatools/wr_tbl_class.py | WbFmt.__get_wbfmt_usrfld | def __get_wbfmt_usrfld(self, data_nt):
"""Return format for text cell from namedtuple field specified by 'ntfld_wbfmt'"""
if self.ntfld_wbfmt is not None:
if isinstance(self.ntfld_wbfmt, str):
ntval = getattr(data_nt, self.ntfld_wbfmt, None) # Ex: 'section'
if ntval is not None:
return self.fmtname2wbfmtobj.get(ntval, None) | python | def __get_wbfmt_usrfld(self, data_nt):
"""Return format for text cell from namedtuple field specified by 'ntfld_wbfmt'"""
if self.ntfld_wbfmt is not None:
if isinstance(self.ntfld_wbfmt, str):
ntval = getattr(data_nt, self.ntfld_wbfmt, None) # Ex: 'section'
if ntval is not None:
return self.fmtname2wbfmtobj.get(ntval, None) | [
"def",
"__get_wbfmt_usrfld",
"(",
"self",
",",
"data_nt",
")",
":",
"if",
"self",
".",
"ntfld_wbfmt",
"is",
"not",
"None",
":",
"if",
"isinstance",
"(",
"self",
".",
"ntfld_wbfmt",
",",
"str",
")",
":",
"ntval",
"=",
"getattr",
"(",
"data_nt",
",",
"self",
".",
"ntfld_wbfmt",
",",
"None",
")",
"# Ex: 'section'",
"if",
"ntval",
"is",
"not",
"None",
":",
"return",
"self",
".",
"fmtname2wbfmtobj",
".",
"get",
"(",
"ntval",
",",
"None",
")"
] | Return format for text cell from namedtuple field specified by 'ntfld_wbfmt | [
"Return",
"format",
"for",
"text",
"cell",
"from",
"namedtuple",
"field",
"specified",
"by",
"ntfld_wbfmt"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L192-L198 |
228,429 | tanghaibao/goatools | goatools/wr_tbl_class.py | WbFmt.__get_wbfmt_format_txt | def __get_wbfmt_format_txt(self, data_nt):
"""Return format for text cell from namedtuple field, 'format_txt'."""
format_txt_val = getattr(data_nt, "format_txt")
if format_txt_val == 1:
return self.fmtname2wbfmtobj.get("very light grey")
if format_txt_val == 2:
return self.fmtname2wbfmtobj.get("light grey")
return self.fmtname2wbfmtobj.get(format_txt_val) | python | def __get_wbfmt_format_txt(self, data_nt):
"""Return format for text cell from namedtuple field, 'format_txt'."""
format_txt_val = getattr(data_nt, "format_txt")
if format_txt_val == 1:
return self.fmtname2wbfmtobj.get("very light grey")
if format_txt_val == 2:
return self.fmtname2wbfmtobj.get("light grey")
return self.fmtname2wbfmtobj.get(format_txt_val) | [
"def",
"__get_wbfmt_format_txt",
"(",
"self",
",",
"data_nt",
")",
":",
"format_txt_val",
"=",
"getattr",
"(",
"data_nt",
",",
"\"format_txt\"",
")",
"if",
"format_txt_val",
"==",
"1",
":",
"return",
"self",
".",
"fmtname2wbfmtobj",
".",
"get",
"(",
"\"very light grey\"",
")",
"if",
"format_txt_val",
"==",
"2",
":",
"return",
"self",
".",
"fmtname2wbfmtobj",
".",
"get",
"(",
"\"light grey\"",
")",
"return",
"self",
".",
"fmtname2wbfmtobj",
".",
"get",
"(",
"format_txt_val",
")"
] | Return format for text cell from namedtuple field, 'format_txt'. | [
"Return",
"format",
"for",
"text",
"cell",
"from",
"namedtuple",
"field",
"format_txt",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L202-L209 |
228,430 | tanghaibao/goatools | goatools/wr_tbl_class.py | WbFmt.get_fmt_section | def get_fmt_section(self):
"""Grey if printing header GOs and plain if not printing header GOs."""
if self.b_format_txt:
return self.fmtname2wbfmtobj.get("light grey")
return self.fmtname2wbfmtobj.get("plain bold") | python | def get_fmt_section(self):
"""Grey if printing header GOs and plain if not printing header GOs."""
if self.b_format_txt:
return self.fmtname2wbfmtobj.get("light grey")
return self.fmtname2wbfmtobj.get("plain bold") | [
"def",
"get_fmt_section",
"(",
"self",
")",
":",
"if",
"self",
".",
"b_format_txt",
":",
"return",
"self",
".",
"fmtname2wbfmtobj",
".",
"get",
"(",
"\"light grey\"",
")",
"return",
"self",
".",
"fmtname2wbfmtobj",
".",
"get",
"(",
"\"plain bold\"",
")"
] | Grey if printing header GOs and plain if not printing header GOs. | [
"Grey",
"if",
"printing",
"header",
"GOs",
"and",
"plain",
"if",
"not",
"printing",
"header",
"GOs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L211-L215 |
228,431 | tanghaibao/goatools | goatools/anno/genetogo_reader.py | Gene2GoReader.get_id2gos | def get_id2gos(self, **kws):
#### def get_annotations_dct(self, taxid, options):
"""Return geneid2gos, or optionally go2geneids."""
if len(self.taxid2asscs) == 1:
taxid = next(iter(self.taxid2asscs.keys()))
return self._get_id2gos(self.taxid2asscs[taxid], **kws)
assert 'taxid' in kws, "**FATAL: 'taxid' NOT FOUND IN Gene2GoReader::get_id2gos({KW})".format(KW=kws)
taxid = kws['taxid']
assert taxid in self.taxid2asscs, '**FATAL: TAXID({T}) DATA MISSING'.format(T=taxid)
return self._get_id2gos(self.taxid2asscs[taxid], **kws) | python | def get_id2gos(self, **kws):
#### def get_annotations_dct(self, taxid, options):
"""Return geneid2gos, or optionally go2geneids."""
if len(self.taxid2asscs) == 1:
taxid = next(iter(self.taxid2asscs.keys()))
return self._get_id2gos(self.taxid2asscs[taxid], **kws)
assert 'taxid' in kws, "**FATAL: 'taxid' NOT FOUND IN Gene2GoReader::get_id2gos({KW})".format(KW=kws)
taxid = kws['taxid']
assert taxid in self.taxid2asscs, '**FATAL: TAXID({T}) DATA MISSING'.format(T=taxid)
return self._get_id2gos(self.taxid2asscs[taxid], **kws) | [
"def",
"get_id2gos",
"(",
"self",
",",
"*",
"*",
"kws",
")",
":",
"#### def get_annotations_dct(self, taxid, options):",
"if",
"len",
"(",
"self",
".",
"taxid2asscs",
")",
"==",
"1",
":",
"taxid",
"=",
"next",
"(",
"iter",
"(",
"self",
".",
"taxid2asscs",
".",
"keys",
"(",
")",
")",
")",
"return",
"self",
".",
"_get_id2gos",
"(",
"self",
".",
"taxid2asscs",
"[",
"taxid",
"]",
",",
"*",
"*",
"kws",
")",
"assert",
"'taxid'",
"in",
"kws",
",",
"\"**FATAL: 'taxid' NOT FOUND IN Gene2GoReader::get_id2gos({KW})\"",
".",
"format",
"(",
"KW",
"=",
"kws",
")",
"taxid",
"=",
"kws",
"[",
"'taxid'",
"]",
"assert",
"taxid",
"in",
"self",
".",
"taxid2asscs",
",",
"'**FATAL: TAXID({T}) DATA MISSING'",
".",
"format",
"(",
"T",
"=",
"taxid",
")",
"return",
"self",
".",
"_get_id2gos",
"(",
"self",
".",
"taxid2asscs",
"[",
"taxid",
"]",
",",
"*",
"*",
"kws",
")"
] | Return geneid2gos, or optionally go2geneids. | [
"Return",
"geneid2gos",
"or",
"optionally",
"go2geneids",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L28-L37 |
228,432 | tanghaibao/goatools | goatools/anno/genetogo_reader.py | Gene2GoReader.get_name | def get_name(self):
"""Get name using taxid"""
if len(self.taxid2asscs) == 1:
return '{BASE}_{TAXID}'.format(
BASE=self.name, TAXID=next(iter(self.taxid2asscs.keys())))
return '{BASE}_various'.format(BASE=self.name) | python | def get_name(self):
"""Get name using taxid"""
if len(self.taxid2asscs) == 1:
return '{BASE}_{TAXID}'.format(
BASE=self.name, TAXID=next(iter(self.taxid2asscs.keys())))
return '{BASE}_various'.format(BASE=self.name) | [
"def",
"get_name",
"(",
"self",
")",
":",
"if",
"len",
"(",
"self",
".",
"taxid2asscs",
")",
"==",
"1",
":",
"return",
"'{BASE}_{TAXID}'",
".",
"format",
"(",
"BASE",
"=",
"self",
".",
"name",
",",
"TAXID",
"=",
"next",
"(",
"iter",
"(",
"self",
".",
"taxid2asscs",
".",
"keys",
"(",
")",
")",
")",
")",
"return",
"'{BASE}_various'",
".",
"format",
"(",
"BASE",
"=",
"self",
".",
"name",
")"
] | Get name using taxid | [
"Get",
"name",
"using",
"taxid"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L39-L44 |
228,433 | tanghaibao/goatools | goatools/anno/genetogo_reader.py | Gene2GoReader.get_taxid | def get_taxid(self):
"""Return taxid, if one was provided. Other wise return True representing all taxids"""
return next(iter(self.taxid2asscs.keys())) if len(self.taxid2asscs) == 1 else True | python | def get_taxid(self):
"""Return taxid, if one was provided. Other wise return True representing all taxids"""
return next(iter(self.taxid2asscs.keys())) if len(self.taxid2asscs) == 1 else True | [
"def",
"get_taxid",
"(",
"self",
")",
":",
"return",
"next",
"(",
"iter",
"(",
"self",
".",
"taxid2asscs",
".",
"keys",
"(",
")",
")",
")",
"if",
"len",
"(",
"self",
".",
"taxid2asscs",
")",
"==",
"1",
"else",
"True"
] | Return taxid, if one was provided. Other wise return True representing all taxids | [
"Return",
"taxid",
"if",
"one",
"was",
"provided",
".",
"Other",
"wise",
"return",
"True",
"representing",
"all",
"taxids"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L46-L48 |
228,434 | tanghaibao/goatools | goatools/anno/genetogo_reader.py | Gene2GoReader.fill_taxid2asscs | def fill_taxid2asscs(taxid2asscs_usr, taxid2asscs_ret):
"""Fill user taxid2asscs for backward compatibility."""
for taxid, ab_ret in taxid2asscs_ret.items():
taxid2asscs_usr[taxid]['ID2GOs'] = ab_ret['ID2GOs']
taxid2asscs_usr[taxid]['GO2IDs'] = ab_ret['GO2IDs'] | python | def fill_taxid2asscs(taxid2asscs_usr, taxid2asscs_ret):
"""Fill user taxid2asscs for backward compatibility."""
for taxid, ab_ret in taxid2asscs_ret.items():
taxid2asscs_usr[taxid]['ID2GOs'] = ab_ret['ID2GOs']
taxid2asscs_usr[taxid]['GO2IDs'] = ab_ret['GO2IDs'] | [
"def",
"fill_taxid2asscs",
"(",
"taxid2asscs_usr",
",",
"taxid2asscs_ret",
")",
":",
"for",
"taxid",
",",
"ab_ret",
"in",
"taxid2asscs_ret",
".",
"items",
"(",
")",
":",
"taxid2asscs_usr",
"[",
"taxid",
"]",
"[",
"'ID2GOs'",
"]",
"=",
"ab_ret",
"[",
"'ID2GOs'",
"]",
"taxid2asscs_usr",
"[",
"taxid",
"]",
"[",
"'GO2IDs'",
"]",
"=",
"ab_ret",
"[",
"'GO2IDs'",
"]"
] | Fill user taxid2asscs for backward compatibility. | [
"Fill",
"user",
"taxid2asscs",
"for",
"backward",
"compatibility",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L64-L68 |
228,435 | tanghaibao/goatools | goatools/anno/genetogo_reader.py | Gene2GoReader._get_taxids | def _get_taxids(self, taxids=None):
"""Return user-specified taxids or taxids in self.taxid2asscs"""
taxid_keys = set(self.taxid2asscs.keys())
return taxid_keys if taxids is None else set(taxids).intersection(taxid_keys) | python | def _get_taxids(self, taxids=None):
"""Return user-specified taxids or taxids in self.taxid2asscs"""
taxid_keys = set(self.taxid2asscs.keys())
return taxid_keys if taxids is None else set(taxids).intersection(taxid_keys) | [
"def",
"_get_taxids",
"(",
"self",
",",
"taxids",
"=",
"None",
")",
":",
"taxid_keys",
"=",
"set",
"(",
"self",
".",
"taxid2asscs",
".",
"keys",
"(",
")",
")",
"return",
"taxid_keys",
"if",
"taxids",
"is",
"None",
"else",
"set",
"(",
"taxids",
")",
".",
"intersection",
"(",
"taxid_keys",
")"
] | Return user-specified taxids or taxids in self.taxid2asscs | [
"Return",
"user",
"-",
"specified",
"taxids",
"or",
"taxids",
"in",
"self",
".",
"taxid2asscs"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L79-L82 |
228,436 | tanghaibao/goatools | goatools/anno/genetogo_reader.py | Gene2GoReader._init_taxid2asscs | def _init_taxid2asscs(self):
"""Create dict with taxid keys and annotation namedtuple list."""
taxid2asscs = cx.defaultdict(list)
for ntanno in self.associations:
taxid2asscs[ntanno.tax_id].append(ntanno)
assert len(taxid2asscs) != 0, "**FATAL: NO TAXIDS: {F}".format(F=self.filename)
# """Print the number of taxids stored."""
prt = sys.stdout
num_taxids = len(taxid2asscs)
prt.write('{N} taxids stored'.format(N=num_taxids))
if num_taxids < 5:
prt.write(': {Ts}'.format(Ts=' '.join(sorted(str(t) for t in taxid2asscs))))
prt.write('\n')
return dict(taxid2asscs) | python | def _init_taxid2asscs(self):
"""Create dict with taxid keys and annotation namedtuple list."""
taxid2asscs = cx.defaultdict(list)
for ntanno in self.associations:
taxid2asscs[ntanno.tax_id].append(ntanno)
assert len(taxid2asscs) != 0, "**FATAL: NO TAXIDS: {F}".format(F=self.filename)
# """Print the number of taxids stored."""
prt = sys.stdout
num_taxids = len(taxid2asscs)
prt.write('{N} taxids stored'.format(N=num_taxids))
if num_taxids < 5:
prt.write(': {Ts}'.format(Ts=' '.join(sorted(str(t) for t in taxid2asscs))))
prt.write('\n')
return dict(taxid2asscs) | [
"def",
"_init_taxid2asscs",
"(",
"self",
")",
":",
"taxid2asscs",
"=",
"cx",
".",
"defaultdict",
"(",
"list",
")",
"for",
"ntanno",
"in",
"self",
".",
"associations",
":",
"taxid2asscs",
"[",
"ntanno",
".",
"tax_id",
"]",
".",
"append",
"(",
"ntanno",
")",
"assert",
"len",
"(",
"taxid2asscs",
")",
"!=",
"0",
",",
"\"**FATAL: NO TAXIDS: {F}\"",
".",
"format",
"(",
"F",
"=",
"self",
".",
"filename",
")",
"# \"\"\"Print the number of taxids stored.\"\"\"",
"prt",
"=",
"sys",
".",
"stdout",
"num_taxids",
"=",
"len",
"(",
"taxid2asscs",
")",
"prt",
".",
"write",
"(",
"'{N} taxids stored'",
".",
"format",
"(",
"N",
"=",
"num_taxids",
")",
")",
"if",
"num_taxids",
"<",
"5",
":",
"prt",
".",
"write",
"(",
"': {Ts}'",
".",
"format",
"(",
"Ts",
"=",
"' '",
".",
"join",
"(",
"sorted",
"(",
"str",
"(",
"t",
")",
"for",
"t",
"in",
"taxid2asscs",
")",
")",
")",
")",
"prt",
".",
"write",
"(",
"'\\n'",
")",
"return",
"dict",
"(",
"taxid2asscs",
")"
] | Create dict with taxid keys and annotation namedtuple list. | [
"Create",
"dict",
"with",
"taxid",
"keys",
"and",
"annotation",
"namedtuple",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L90-L103 |
228,437 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGosArgs.get_go2color_inst | def get_go2color_inst(self, hdrgo):
"""Get a copy of go2color with GO group header colored."""
go2color = self.go2color.copy()
go2color[hdrgo] = self.hdrgo_dflt_color
return go2color | python | def get_go2color_inst(self, hdrgo):
"""Get a copy of go2color with GO group header colored."""
go2color = self.go2color.copy()
go2color[hdrgo] = self.hdrgo_dflt_color
return go2color | [
"def",
"get_go2color_inst",
"(",
"self",
",",
"hdrgo",
")",
":",
"go2color",
"=",
"self",
".",
"go2color",
".",
"copy",
"(",
")",
"go2color",
"[",
"hdrgo",
"]",
"=",
"self",
".",
"hdrgo_dflt_color",
"return",
"go2color"
] | Get a copy of go2color with GO group header colored. | [
"Get",
"a",
"copy",
"of",
"go2color",
"with",
"GO",
"group",
"header",
"colored",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L38-L42 |
228,438 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGosArgs.get_kws_plt | def get_kws_plt(self):
"""Get keyword args for GoSubDagPlot from self unless they are None."""
kws_plt = {}
for key_plt in self.keys_plt:
key_val = getattr(self, key_plt, None)
if key_val is not None:
kws_plt[key_plt] = key_val
elif key_plt in self.kws:
kws_plt[key_plt] = self.kws[key_plt]
return kws_plt | python | def get_kws_plt(self):
"""Get keyword args for GoSubDagPlot from self unless they are None."""
kws_plt = {}
for key_plt in self.keys_plt:
key_val = getattr(self, key_plt, None)
if key_val is not None:
kws_plt[key_plt] = key_val
elif key_plt in self.kws:
kws_plt[key_plt] = self.kws[key_plt]
return kws_plt | [
"def",
"get_kws_plt",
"(",
"self",
")",
":",
"kws_plt",
"=",
"{",
"}",
"for",
"key_plt",
"in",
"self",
".",
"keys_plt",
":",
"key_val",
"=",
"getattr",
"(",
"self",
",",
"key_plt",
",",
"None",
")",
"if",
"key_val",
"is",
"not",
"None",
":",
"kws_plt",
"[",
"key_plt",
"]",
"=",
"key_val",
"elif",
"key_plt",
"in",
"self",
".",
"kws",
":",
"kws_plt",
"[",
"key_plt",
"]",
"=",
"self",
".",
"kws",
"[",
"key_plt",
"]",
"return",
"kws_plt"
] | Get keyword args for GoSubDagPlot from self unless they are None. | [
"Get",
"keyword",
"args",
"for",
"GoSubDagPlot",
"from",
"self",
"unless",
"they",
"are",
"None",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L44-L53 |
228,439 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGosArgs._init_go2bordercolor | def _init_go2bordercolor(objcolors, **kws):
"""Initialize go2bordercolor with default to make hdrgos bright blue."""
go2bordercolor_ret = objcolors.get_bordercolor()
if 'go2bordercolor' not in kws:
return go2bordercolor_ret
go2bordercolor_usr = kws['go2bordercolor']
goids = set(go2bordercolor_ret).intersection(go2bordercolor_usr)
for goid in goids:
go2bordercolor_usr[goid] = go2bordercolor_ret[goid]
return go2bordercolor_usr | python | def _init_go2bordercolor(objcolors, **kws):
"""Initialize go2bordercolor with default to make hdrgos bright blue."""
go2bordercolor_ret = objcolors.get_bordercolor()
if 'go2bordercolor' not in kws:
return go2bordercolor_ret
go2bordercolor_usr = kws['go2bordercolor']
goids = set(go2bordercolor_ret).intersection(go2bordercolor_usr)
for goid in goids:
go2bordercolor_usr[goid] = go2bordercolor_ret[goid]
return go2bordercolor_usr | [
"def",
"_init_go2bordercolor",
"(",
"objcolors",
",",
"*",
"*",
"kws",
")",
":",
"go2bordercolor_ret",
"=",
"objcolors",
".",
"get_bordercolor",
"(",
")",
"if",
"'go2bordercolor'",
"not",
"in",
"kws",
":",
"return",
"go2bordercolor_ret",
"go2bordercolor_usr",
"=",
"kws",
"[",
"'go2bordercolor'",
"]",
"goids",
"=",
"set",
"(",
"go2bordercolor_ret",
")",
".",
"intersection",
"(",
"go2bordercolor_usr",
")",
"for",
"goid",
"in",
"goids",
":",
"go2bordercolor_usr",
"[",
"goid",
"]",
"=",
"go2bordercolor_ret",
"[",
"goid",
"]",
"return",
"go2bordercolor_usr"
] | Initialize go2bordercolor with default to make hdrgos bright blue. | [
"Initialize",
"go2bordercolor",
"with",
"default",
"to",
"make",
"hdrgos",
"bright",
"blue",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L56-L65 |
228,440 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos.plot_groups_unplaced | def plot_groups_unplaced(self, fout_dir=".", **kws_pltargs):
"""Plot GO DAGs for groups of user GOs which are not in a section."""
hdrgos = self.grprobj.get_hdrgos_unplaced()
pltargs = PltGroupedGosArgs(self.grprobj, fout_dir=fout_dir, **kws_pltargs)
return self._plot_groups_hdrgos(hdrgos, pltargs) | python | def plot_groups_unplaced(self, fout_dir=".", **kws_pltargs):
"""Plot GO DAGs for groups of user GOs which are not in a section."""
hdrgos = self.grprobj.get_hdrgos_unplaced()
pltargs = PltGroupedGosArgs(self.grprobj, fout_dir=fout_dir, **kws_pltargs)
return self._plot_groups_hdrgos(hdrgos, pltargs) | [
"def",
"plot_groups_unplaced",
"(",
"self",
",",
"fout_dir",
"=",
"\".\"",
",",
"*",
"*",
"kws_pltargs",
")",
":",
"hdrgos",
"=",
"self",
".",
"grprobj",
".",
"get_hdrgos_unplaced",
"(",
")",
"pltargs",
"=",
"PltGroupedGosArgs",
"(",
"self",
".",
"grprobj",
",",
"fout_dir",
"=",
"fout_dir",
",",
"*",
"*",
"kws_pltargs",
")",
"return",
"self",
".",
"_plot_groups_hdrgos",
"(",
"hdrgos",
",",
"pltargs",
")"
] | Plot GO DAGs for groups of user GOs which are not in a section. | [
"Plot",
"GO",
"DAGs",
"for",
"groups",
"of",
"user",
"GOs",
"which",
"are",
"not",
"in",
"a",
"section",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L92-L96 |
228,441 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._get_plt_data | def _get_plt_data(self, hdrgos_usr):
"""Given User GO IDs, return their GO headers and other GO info."""
hdrgo2usrgos = self.grprobj.get_hdrgo2usrgos(hdrgos_usr)
usrgos_actual = set([u for us in hdrgo2usrgos.values() for u in us])
go2obj = self.gosubdag.get_go2obj(usrgos_actual.union(hdrgo2usrgos.keys()))
return hdrgo2usrgos, go2obj | python | def _get_plt_data(self, hdrgos_usr):
"""Given User GO IDs, return their GO headers and other GO info."""
hdrgo2usrgos = self.grprobj.get_hdrgo2usrgos(hdrgos_usr)
usrgos_actual = set([u for us in hdrgo2usrgos.values() for u in us])
go2obj = self.gosubdag.get_go2obj(usrgos_actual.union(hdrgo2usrgos.keys()))
return hdrgo2usrgos, go2obj | [
"def",
"_get_plt_data",
"(",
"self",
",",
"hdrgos_usr",
")",
":",
"hdrgo2usrgos",
"=",
"self",
".",
"grprobj",
".",
"get_hdrgo2usrgos",
"(",
"hdrgos_usr",
")",
"usrgos_actual",
"=",
"set",
"(",
"[",
"u",
"for",
"us",
"in",
"hdrgo2usrgos",
".",
"values",
"(",
")",
"for",
"u",
"in",
"us",
"]",
")",
"go2obj",
"=",
"self",
".",
"gosubdag",
".",
"get_go2obj",
"(",
"usrgos_actual",
".",
"union",
"(",
"hdrgo2usrgos",
".",
"keys",
"(",
")",
")",
")",
"return",
"hdrgo2usrgos",
",",
"go2obj"
] | Given User GO IDs, return their GO headers and other GO info. | [
"Given",
"User",
"GO",
"IDs",
"return",
"their",
"GO",
"headers",
"and",
"other",
"GO",
"info",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L103-L108 |
228,442 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._plot_go_group | def _plot_go_group(self, hdrgo, usrgos, pltargs, go2parentids):
"""Plot an exploratory GO DAG for a single Group of user GOs."""
gosubdagplotnts = self._get_gosubdagplotnts(hdrgo, usrgos, pltargs, go2parentids)
# Create pngs and return png names
pngs = [obj.wrplt(pltargs.fout_dir, pltargs.plt_ext) for obj in gosubdagplotnts]
return pngs | python | def _plot_go_group(self, hdrgo, usrgos, pltargs, go2parentids):
"""Plot an exploratory GO DAG for a single Group of user GOs."""
gosubdagplotnts = self._get_gosubdagplotnts(hdrgo, usrgos, pltargs, go2parentids)
# Create pngs and return png names
pngs = [obj.wrplt(pltargs.fout_dir, pltargs.plt_ext) for obj in gosubdagplotnts]
return pngs | [
"def",
"_plot_go_group",
"(",
"self",
",",
"hdrgo",
",",
"usrgos",
",",
"pltargs",
",",
"go2parentids",
")",
":",
"gosubdagplotnts",
"=",
"self",
".",
"_get_gosubdagplotnts",
"(",
"hdrgo",
",",
"usrgos",
",",
"pltargs",
",",
"go2parentids",
")",
"# Create pngs and return png names",
"pngs",
"=",
"[",
"obj",
".",
"wrplt",
"(",
"pltargs",
".",
"fout_dir",
",",
"pltargs",
".",
"plt_ext",
")",
"for",
"obj",
"in",
"gosubdagplotnts",
"]",
"return",
"pngs"
] | Plot an exploratory GO DAG for a single Group of user GOs. | [
"Plot",
"an",
"exploratory",
"GO",
"DAG",
"for",
"a",
"single",
"Group",
"of",
"user",
"GOs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L150-L155 |
228,443 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._get_dotgraphs | def _get_dotgraphs(self, hdrgo, usrgos, pltargs, go2parentids):
"""Get a GO DAG in a dot-language string for a single Group of user GOs."""
gosubdagplotnts = self._get_gosubdagplotnts(hdrgo, usrgos, pltargs, go2parentids)
# Create DAG graphs as dot language strings. Loop through GoSubDagPlotNt list
dotstrs = [obj.get_dotstr() for obj in gosubdagplotnts]
return dotstrs | python | def _get_dotgraphs(self, hdrgo, usrgos, pltargs, go2parentids):
"""Get a GO DAG in a dot-language string for a single Group of user GOs."""
gosubdagplotnts = self._get_gosubdagplotnts(hdrgo, usrgos, pltargs, go2parentids)
# Create DAG graphs as dot language strings. Loop through GoSubDagPlotNt list
dotstrs = [obj.get_dotstr() for obj in gosubdagplotnts]
return dotstrs | [
"def",
"_get_dotgraphs",
"(",
"self",
",",
"hdrgo",
",",
"usrgos",
",",
"pltargs",
",",
"go2parentids",
")",
":",
"gosubdagplotnts",
"=",
"self",
".",
"_get_gosubdagplotnts",
"(",
"hdrgo",
",",
"usrgos",
",",
"pltargs",
",",
"go2parentids",
")",
"# Create DAG graphs as dot language strings. Loop through GoSubDagPlotNt list",
"dotstrs",
"=",
"[",
"obj",
".",
"get_dotstr",
"(",
")",
"for",
"obj",
"in",
"gosubdagplotnts",
"]",
"return",
"dotstrs"
] | Get a GO DAG in a dot-language string for a single Group of user GOs. | [
"Get",
"a",
"GO",
"DAG",
"in",
"a",
"dot",
"-",
"language",
"string",
"for",
"a",
"single",
"Group",
"of",
"user",
"GOs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L157-L162 |
228,444 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._get_gosubdagplotnts | def _get_gosubdagplotnts(self, hdrgo, usrgos, pltargs, go2parentids):
"""Get list of GoSubDagPlotNt for plotting an exploratory GODAG for 1 Group of user GOs."""
dotgraphs = []
go2color = pltargs.get_go2color_inst(hdrgo)
# namedtuple fields: hdrgo gosubdag tot_usrgos parentcnt desc
ntpltgo0 = self._get_pltdag_ancesters(hdrgo, usrgos, desc="")
ntpltgo1 = self._get_pltdag_path_hdr(hdrgo, usrgos, desc="pruned")
num_go0 = len(ntpltgo0.gosubdag.go2obj)
num_go1 = len(ntpltgo1.gosubdag.go2obj)
title = "{GO} {NAME}; {N} GO sources".format(
GO=hdrgo,
NAME=self.gosubdag.go2obj[hdrgo].name,
N=len(ntpltgo0.gosubdag.go_sources))
# print("PltGroupedGos::_get_gosubdagplotnts TITLE", title)
if num_go0 < pltargs.max_gos:
# print("PltGroupedGos::_get_gosubdagplotnts ntpltgo0 ALWAYS IF NOT TOO BIG")
dotgraphs.append(self._get_gosubdagplotnt(ntpltgo0, title, go2color, pltargs))
# PLOT A: Plot the entire GO ID group under GO header, hdrgo, if not too big
if num_go0 < pltargs.max_gos and \
ntpltgo0.tot_usrgos == ntpltgo1.tot_usrgos:
# print("PltGroupedGos::_get_gosubdagplotnts ntpltgo0 AAAAAAAAAAAAAAAAA")
dotgraphs.append(self._get_gosubdagplotnt(ntpltgo0, title, go2color, pltargs))
# PLOT B: Plot only the GO ID group passing thru the GO header, hdrgo, if not too big
elif num_go1 < pltargs.max_gos and ntpltgo0.tot_usrgos != ntpltgo1.tot_usrgos:
# print("PltGroupedGos::_get_gosubdagplotnts ntpltgo1(pruned) BBBBBBBBBBBBBBBBB")
dotgraphs.append(self._get_gosubdagplotnt(ntpltgo1, title, go2color, pltargs))
# PLOT C: If DAG is large, just print upper portion
# PLOT D: If DAG is large, just print upper portion passing through the GO header
elif num_go1 >= pltargs.upper_trigger:
# print("PltGroupedGos::_get_gosubdagplotnts upper_pruned CCCCCCCCCCCCCCCCC")
gos_upper = self._get_gos_upper(ntpltgo1, pltargs.max_upper, go2parentids)
#ntpltgo2 = self._get_pltdag_ancesters(hdrgo, gos_upper, "{BASE}_upper.png")
ntpltgo3 = self._get_pltdag_path_hdr(hdrgo, gos_upper, "upper_pruned")
# Middle GO terms chosen to be start points will be green unless reset back
for goid in gos_upper:
if goid not in go2color:
go2color[goid] = 'white'
dotgraphs.append(self._get_gosubdagplotnt(ntpltgo3, title, go2color, pltargs))
else:
# print("PltGroupedGos::_get_gosubdagplotnts EEEEEEEEEEEEEEEEE")
self._no_ntplt(ntpltgo0)
return dotgraphs | python | def _get_gosubdagplotnts(self, hdrgo, usrgos, pltargs, go2parentids):
"""Get list of GoSubDagPlotNt for plotting an exploratory GODAG for 1 Group of user GOs."""
dotgraphs = []
go2color = pltargs.get_go2color_inst(hdrgo)
# namedtuple fields: hdrgo gosubdag tot_usrgos parentcnt desc
ntpltgo0 = self._get_pltdag_ancesters(hdrgo, usrgos, desc="")
ntpltgo1 = self._get_pltdag_path_hdr(hdrgo, usrgos, desc="pruned")
num_go0 = len(ntpltgo0.gosubdag.go2obj)
num_go1 = len(ntpltgo1.gosubdag.go2obj)
title = "{GO} {NAME}; {N} GO sources".format(
GO=hdrgo,
NAME=self.gosubdag.go2obj[hdrgo].name,
N=len(ntpltgo0.gosubdag.go_sources))
# print("PltGroupedGos::_get_gosubdagplotnts TITLE", title)
if num_go0 < pltargs.max_gos:
# print("PltGroupedGos::_get_gosubdagplotnts ntpltgo0 ALWAYS IF NOT TOO BIG")
dotgraphs.append(self._get_gosubdagplotnt(ntpltgo0, title, go2color, pltargs))
# PLOT A: Plot the entire GO ID group under GO header, hdrgo, if not too big
if num_go0 < pltargs.max_gos and \
ntpltgo0.tot_usrgos == ntpltgo1.tot_usrgos:
# print("PltGroupedGos::_get_gosubdagplotnts ntpltgo0 AAAAAAAAAAAAAAAAA")
dotgraphs.append(self._get_gosubdagplotnt(ntpltgo0, title, go2color, pltargs))
# PLOT B: Plot only the GO ID group passing thru the GO header, hdrgo, if not too big
elif num_go1 < pltargs.max_gos and ntpltgo0.tot_usrgos != ntpltgo1.tot_usrgos:
# print("PltGroupedGos::_get_gosubdagplotnts ntpltgo1(pruned) BBBBBBBBBBBBBBBBB")
dotgraphs.append(self._get_gosubdagplotnt(ntpltgo1, title, go2color, pltargs))
# PLOT C: If DAG is large, just print upper portion
# PLOT D: If DAG is large, just print upper portion passing through the GO header
elif num_go1 >= pltargs.upper_trigger:
# print("PltGroupedGos::_get_gosubdagplotnts upper_pruned CCCCCCCCCCCCCCCCC")
gos_upper = self._get_gos_upper(ntpltgo1, pltargs.max_upper, go2parentids)
#ntpltgo2 = self._get_pltdag_ancesters(hdrgo, gos_upper, "{BASE}_upper.png")
ntpltgo3 = self._get_pltdag_path_hdr(hdrgo, gos_upper, "upper_pruned")
# Middle GO terms chosen to be start points will be green unless reset back
for goid in gos_upper:
if goid not in go2color:
go2color[goid] = 'white'
dotgraphs.append(self._get_gosubdagplotnt(ntpltgo3, title, go2color, pltargs))
else:
# print("PltGroupedGos::_get_gosubdagplotnts EEEEEEEEEEEEEEEEE")
self._no_ntplt(ntpltgo0)
return dotgraphs | [
"def",
"_get_gosubdagplotnts",
"(",
"self",
",",
"hdrgo",
",",
"usrgos",
",",
"pltargs",
",",
"go2parentids",
")",
":",
"dotgraphs",
"=",
"[",
"]",
"go2color",
"=",
"pltargs",
".",
"get_go2color_inst",
"(",
"hdrgo",
")",
"# namedtuple fields: hdrgo gosubdag tot_usrgos parentcnt desc",
"ntpltgo0",
"=",
"self",
".",
"_get_pltdag_ancesters",
"(",
"hdrgo",
",",
"usrgos",
",",
"desc",
"=",
"\"\"",
")",
"ntpltgo1",
"=",
"self",
".",
"_get_pltdag_path_hdr",
"(",
"hdrgo",
",",
"usrgos",
",",
"desc",
"=",
"\"pruned\"",
")",
"num_go0",
"=",
"len",
"(",
"ntpltgo0",
".",
"gosubdag",
".",
"go2obj",
")",
"num_go1",
"=",
"len",
"(",
"ntpltgo1",
".",
"gosubdag",
".",
"go2obj",
")",
"title",
"=",
"\"{GO} {NAME}; {N} GO sources\"",
".",
"format",
"(",
"GO",
"=",
"hdrgo",
",",
"NAME",
"=",
"self",
".",
"gosubdag",
".",
"go2obj",
"[",
"hdrgo",
"]",
".",
"name",
",",
"N",
"=",
"len",
"(",
"ntpltgo0",
".",
"gosubdag",
".",
"go_sources",
")",
")",
"# print(\"PltGroupedGos::_get_gosubdagplotnts TITLE\", title)",
"if",
"num_go0",
"<",
"pltargs",
".",
"max_gos",
":",
"# print(\"PltGroupedGos::_get_gosubdagplotnts ntpltgo0 ALWAYS IF NOT TOO BIG\")",
"dotgraphs",
".",
"append",
"(",
"self",
".",
"_get_gosubdagplotnt",
"(",
"ntpltgo0",
",",
"title",
",",
"go2color",
",",
"pltargs",
")",
")",
"# PLOT A: Plot the entire GO ID group under GO header, hdrgo, if not too big",
"if",
"num_go0",
"<",
"pltargs",
".",
"max_gos",
"and",
"ntpltgo0",
".",
"tot_usrgos",
"==",
"ntpltgo1",
".",
"tot_usrgos",
":",
"# print(\"PltGroupedGos::_get_gosubdagplotnts ntpltgo0 AAAAAAAAAAAAAAAAA\")",
"dotgraphs",
".",
"append",
"(",
"self",
".",
"_get_gosubdagplotnt",
"(",
"ntpltgo0",
",",
"title",
",",
"go2color",
",",
"pltargs",
")",
")",
"# PLOT B: Plot only the GO ID group passing thru the GO header, hdrgo, if not too big",
"elif",
"num_go1",
"<",
"pltargs",
".",
"max_gos",
"and",
"ntpltgo0",
".",
"tot_usrgos",
"!=",
"ntpltgo1",
".",
"tot_usrgos",
":",
"# print(\"PltGroupedGos::_get_gosubdagplotnts ntpltgo1(pruned) BBBBBBBBBBBBBBBBB\")",
"dotgraphs",
".",
"append",
"(",
"self",
".",
"_get_gosubdagplotnt",
"(",
"ntpltgo1",
",",
"title",
",",
"go2color",
",",
"pltargs",
")",
")",
"# PLOT C: If DAG is large, just print upper portion",
"# PLOT D: If DAG is large, just print upper portion passing through the GO header",
"elif",
"num_go1",
">=",
"pltargs",
".",
"upper_trigger",
":",
"# print(\"PltGroupedGos::_get_gosubdagplotnts upper_pruned CCCCCCCCCCCCCCCCC\")",
"gos_upper",
"=",
"self",
".",
"_get_gos_upper",
"(",
"ntpltgo1",
",",
"pltargs",
".",
"max_upper",
",",
"go2parentids",
")",
"#ntpltgo2 = self._get_pltdag_ancesters(hdrgo, gos_upper, \"{BASE}_upper.png\")",
"ntpltgo3",
"=",
"self",
".",
"_get_pltdag_path_hdr",
"(",
"hdrgo",
",",
"gos_upper",
",",
"\"upper_pruned\"",
")",
"# Middle GO terms chosen to be start points will be green unless reset back",
"for",
"goid",
"in",
"gos_upper",
":",
"if",
"goid",
"not",
"in",
"go2color",
":",
"go2color",
"[",
"goid",
"]",
"=",
"'white'",
"dotgraphs",
".",
"append",
"(",
"self",
".",
"_get_gosubdagplotnt",
"(",
"ntpltgo3",
",",
"title",
",",
"go2color",
",",
"pltargs",
")",
")",
"else",
":",
"# print(\"PltGroupedGos::_get_gosubdagplotnts EEEEEEEEEEEEEEEEE\")",
"self",
".",
"_no_ntplt",
"(",
"ntpltgo0",
")",
"return",
"dotgraphs"
] | Get list of GoSubDagPlotNt for plotting an exploratory GODAG for 1 Group of user GOs. | [
"Get",
"list",
"of",
"GoSubDagPlotNt",
"for",
"plotting",
"an",
"exploratory",
"GODAG",
"for",
"1",
"Group",
"of",
"user",
"GOs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L164-L205 |
228,445 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._get_gos_upper | def _get_gos_upper(self, ntpltgo1, max_upper, go2parentids):
"""Plot a GO DAG for the upper portion of a single Group of user GOs."""
# Get GO IDs which are in the hdrgo path
goids_possible = ntpltgo1.gosubdag.go2obj.keys()
# Get upper GO IDs which have the most descendants
return self._get_gosrcs_upper(goids_possible, max_upper, go2parentids) | python | def _get_gos_upper(self, ntpltgo1, max_upper, go2parentids):
"""Plot a GO DAG for the upper portion of a single Group of user GOs."""
# Get GO IDs which are in the hdrgo path
goids_possible = ntpltgo1.gosubdag.go2obj.keys()
# Get upper GO IDs which have the most descendants
return self._get_gosrcs_upper(goids_possible, max_upper, go2parentids) | [
"def",
"_get_gos_upper",
"(",
"self",
",",
"ntpltgo1",
",",
"max_upper",
",",
"go2parentids",
")",
":",
"# Get GO IDs which are in the hdrgo path",
"goids_possible",
"=",
"ntpltgo1",
".",
"gosubdag",
".",
"go2obj",
".",
"keys",
"(",
")",
"# Get upper GO IDs which have the most descendants",
"return",
"self",
".",
"_get_gosrcs_upper",
"(",
"goids_possible",
",",
"max_upper",
",",
"go2parentids",
")"
] | Plot a GO DAG for the upper portion of a single Group of user GOs. | [
"Plot",
"a",
"GO",
"DAG",
"for",
"the",
"upper",
"portion",
"of",
"a",
"single",
"Group",
"of",
"user",
"GOs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L207-L212 |
228,446 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._get_gosrcs_upper | def _get_gosrcs_upper(self, goids, max_upper, go2parentids):
"""Get GO IDs for the upper portion of the GO DAG."""
gosrcs_upper = set()
get_nt = self.gosubdag.go2nt.get
go2nt = {g:get_nt(g) for g in goids}
# Sort by descending order of descendant counts to find potential new hdrgos
go_nt = sorted(go2nt.items(), key=lambda t: -1*t[1].dcnt)
goids_upper = set()
for goid, _ in go_nt: # Loop through GO ID, GO nt
goids_upper.add(goid)
if goid in go2parentids:
goids_upper |= go2parentids[goid]
#print "{} {:3} {}".format(goid, len(goids_upper), gont.GO_name)
if len(goids_upper) < max_upper:
gosrcs_upper.add(goid)
else:
break
return gosrcs_upper | python | def _get_gosrcs_upper(self, goids, max_upper, go2parentids):
"""Get GO IDs for the upper portion of the GO DAG."""
gosrcs_upper = set()
get_nt = self.gosubdag.go2nt.get
go2nt = {g:get_nt(g) for g in goids}
# Sort by descending order of descendant counts to find potential new hdrgos
go_nt = sorted(go2nt.items(), key=lambda t: -1*t[1].dcnt)
goids_upper = set()
for goid, _ in go_nt: # Loop through GO ID, GO nt
goids_upper.add(goid)
if goid in go2parentids:
goids_upper |= go2parentids[goid]
#print "{} {:3} {}".format(goid, len(goids_upper), gont.GO_name)
if len(goids_upper) < max_upper:
gosrcs_upper.add(goid)
else:
break
return gosrcs_upper | [
"def",
"_get_gosrcs_upper",
"(",
"self",
",",
"goids",
",",
"max_upper",
",",
"go2parentids",
")",
":",
"gosrcs_upper",
"=",
"set",
"(",
")",
"get_nt",
"=",
"self",
".",
"gosubdag",
".",
"go2nt",
".",
"get",
"go2nt",
"=",
"{",
"g",
":",
"get_nt",
"(",
"g",
")",
"for",
"g",
"in",
"goids",
"}",
"# Sort by descending order of descendant counts to find potential new hdrgos",
"go_nt",
"=",
"sorted",
"(",
"go2nt",
".",
"items",
"(",
")",
",",
"key",
"=",
"lambda",
"t",
":",
"-",
"1",
"*",
"t",
"[",
"1",
"]",
".",
"dcnt",
")",
"goids_upper",
"=",
"set",
"(",
")",
"for",
"goid",
",",
"_",
"in",
"go_nt",
":",
"# Loop through GO ID, GO nt",
"goids_upper",
".",
"add",
"(",
"goid",
")",
"if",
"goid",
"in",
"go2parentids",
":",
"goids_upper",
"|=",
"go2parentids",
"[",
"goid",
"]",
"#print \"{} {:3} {}\".format(goid, len(goids_upper), gont.GO_name)",
"if",
"len",
"(",
"goids_upper",
")",
"<",
"max_upper",
":",
"gosrcs_upper",
".",
"add",
"(",
"goid",
")",
"else",
":",
"break",
"return",
"gosrcs_upper"
] | Get GO IDs for the upper portion of the GO DAG. | [
"Get",
"GO",
"IDs",
"for",
"the",
"upper",
"portion",
"of",
"the",
"GO",
"DAG",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L214-L231 |
228,447 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._get_gosubdagplotnt | def _get_gosubdagplotnt(self, ntplt, title, go2color, pltargs):
"""Return GoSubDagPlotNt, which contains both a GoSubDagPlot object and ntobj."""
kws_plt = pltargs.get_kws_plt()
kws_plt['id'] = '"{ID}"'.format(ID=ntplt.hdrgo)
kws_plt['title'] = "{TITLE} of {M} user GOs".format(TITLE=title, M=ntplt.tot_usrgos)
kws_plt['go2color'] = go2color
kws_plt['go2bordercolor'] = pltargs.go2bordercolor
if ntplt.parentcnt:
kws_plt["parentcnt"] = True
gosubdagplot = GoSubDagPlot(ntplt.gosubdag, **kws_plt)
return GoSubDagPlotNt(self.grprobj, gosubdagplot, ntplt) | python | def _get_gosubdagplotnt(self, ntplt, title, go2color, pltargs):
"""Return GoSubDagPlotNt, which contains both a GoSubDagPlot object and ntobj."""
kws_plt = pltargs.get_kws_plt()
kws_plt['id'] = '"{ID}"'.format(ID=ntplt.hdrgo)
kws_plt['title'] = "{TITLE} of {M} user GOs".format(TITLE=title, M=ntplt.tot_usrgos)
kws_plt['go2color'] = go2color
kws_plt['go2bordercolor'] = pltargs.go2bordercolor
if ntplt.parentcnt:
kws_plt["parentcnt"] = True
gosubdagplot = GoSubDagPlot(ntplt.gosubdag, **kws_plt)
return GoSubDagPlotNt(self.grprobj, gosubdagplot, ntplt) | [
"def",
"_get_gosubdagplotnt",
"(",
"self",
",",
"ntplt",
",",
"title",
",",
"go2color",
",",
"pltargs",
")",
":",
"kws_plt",
"=",
"pltargs",
".",
"get_kws_plt",
"(",
")",
"kws_plt",
"[",
"'id'",
"]",
"=",
"'\"{ID}\"'",
".",
"format",
"(",
"ID",
"=",
"ntplt",
".",
"hdrgo",
")",
"kws_plt",
"[",
"'title'",
"]",
"=",
"\"{TITLE} of {M} user GOs\"",
".",
"format",
"(",
"TITLE",
"=",
"title",
",",
"M",
"=",
"ntplt",
".",
"tot_usrgos",
")",
"kws_plt",
"[",
"'go2color'",
"]",
"=",
"go2color",
"kws_plt",
"[",
"'go2bordercolor'",
"]",
"=",
"pltargs",
".",
"go2bordercolor",
"if",
"ntplt",
".",
"parentcnt",
":",
"kws_plt",
"[",
"\"parentcnt\"",
"]",
"=",
"True",
"gosubdagplot",
"=",
"GoSubDagPlot",
"(",
"ntplt",
".",
"gosubdag",
",",
"*",
"*",
"kws_plt",
")",
"return",
"GoSubDagPlotNt",
"(",
"self",
".",
"grprobj",
",",
"gosubdagplot",
",",
"ntplt",
")"
] | Return GoSubDagPlotNt, which contains both a GoSubDagPlot object and ntobj. | [
"Return",
"GoSubDagPlotNt",
"which",
"contains",
"both",
"a",
"GoSubDagPlot",
"object",
"and",
"ntobj",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L233-L243 |
228,448 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._no_ntplt | def _no_ntplt(self, ntplt):
"""Print a message about the GO DAG Plot we are NOT plotting."""
sys.stdout.write(" {GO_USR:>6,} usr {GO_ALL:>6,} GOs DID NOT WRITE: {B} {D}\n".format(
B=self.grprobj.get_fout_base(ntplt.hdrgo),
D=ntplt.desc,
GO_USR=len(ntplt.gosubdag.go_sources),
GO_ALL=len(ntplt.gosubdag.go2obj))) | python | def _no_ntplt(self, ntplt):
"""Print a message about the GO DAG Plot we are NOT plotting."""
sys.stdout.write(" {GO_USR:>6,} usr {GO_ALL:>6,} GOs DID NOT WRITE: {B} {D}\n".format(
B=self.grprobj.get_fout_base(ntplt.hdrgo),
D=ntplt.desc,
GO_USR=len(ntplt.gosubdag.go_sources),
GO_ALL=len(ntplt.gosubdag.go2obj))) | [
"def",
"_no_ntplt",
"(",
"self",
",",
"ntplt",
")",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" {GO_USR:>6,} usr {GO_ALL:>6,} GOs DID NOT WRITE: {B} {D}\\n\"",
".",
"format",
"(",
"B",
"=",
"self",
".",
"grprobj",
".",
"get_fout_base",
"(",
"ntplt",
".",
"hdrgo",
")",
",",
"D",
"=",
"ntplt",
".",
"desc",
",",
"GO_USR",
"=",
"len",
"(",
"ntplt",
".",
"gosubdag",
".",
"go_sources",
")",
",",
"GO_ALL",
"=",
"len",
"(",
"ntplt",
".",
"gosubdag",
".",
"go2obj",
")",
")",
")"
] | Print a message about the GO DAG Plot we are NOT plotting. | [
"Print",
"a",
"message",
"about",
"the",
"GO",
"DAG",
"Plot",
"we",
"are",
"NOT",
"plotting",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L245-L251 |
228,449 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._get_pltdag_ancesters | def _get_pltdag_ancesters(self, hdrgo, usrgos, desc=""):
"""Get GoSubDag containing hdrgo and all usrgos and their ancesters."""
go_srcs = usrgos.union([hdrgo])
gosubdag = GoSubDag(go_srcs,
self.gosubdag.get_go2obj(go_srcs),
relationships=self.gosubdag.relationships,
rcntobj=self.gosubdag.rcntobj,
go2nt=self.gosubdag.go2nt)
tot_usrgos = len(set(gosubdag.go2obj.keys()).intersection(self.usrgos))
return self.ntpltgo(
hdrgo=hdrgo,
gosubdag=gosubdag,
tot_usrgos=tot_usrgos,
parentcnt=False,
desc=desc) | python | def _get_pltdag_ancesters(self, hdrgo, usrgos, desc=""):
"""Get GoSubDag containing hdrgo and all usrgos and their ancesters."""
go_srcs = usrgos.union([hdrgo])
gosubdag = GoSubDag(go_srcs,
self.gosubdag.get_go2obj(go_srcs),
relationships=self.gosubdag.relationships,
rcntobj=self.gosubdag.rcntobj,
go2nt=self.gosubdag.go2nt)
tot_usrgos = len(set(gosubdag.go2obj.keys()).intersection(self.usrgos))
return self.ntpltgo(
hdrgo=hdrgo,
gosubdag=gosubdag,
tot_usrgos=tot_usrgos,
parentcnt=False,
desc=desc) | [
"def",
"_get_pltdag_ancesters",
"(",
"self",
",",
"hdrgo",
",",
"usrgos",
",",
"desc",
"=",
"\"\"",
")",
":",
"go_srcs",
"=",
"usrgos",
".",
"union",
"(",
"[",
"hdrgo",
"]",
")",
"gosubdag",
"=",
"GoSubDag",
"(",
"go_srcs",
",",
"self",
".",
"gosubdag",
".",
"get_go2obj",
"(",
"go_srcs",
")",
",",
"relationships",
"=",
"self",
".",
"gosubdag",
".",
"relationships",
",",
"rcntobj",
"=",
"self",
".",
"gosubdag",
".",
"rcntobj",
",",
"go2nt",
"=",
"self",
".",
"gosubdag",
".",
"go2nt",
")",
"tot_usrgos",
"=",
"len",
"(",
"set",
"(",
"gosubdag",
".",
"go2obj",
".",
"keys",
"(",
")",
")",
".",
"intersection",
"(",
"self",
".",
"usrgos",
")",
")",
"return",
"self",
".",
"ntpltgo",
"(",
"hdrgo",
"=",
"hdrgo",
",",
"gosubdag",
"=",
"gosubdag",
",",
"tot_usrgos",
"=",
"tot_usrgos",
",",
"parentcnt",
"=",
"False",
",",
"desc",
"=",
"desc",
")"
] | Get GoSubDag containing hdrgo and all usrgos and their ancesters. | [
"Get",
"GoSubDag",
"containing",
"hdrgo",
"and",
"all",
"usrgos",
"and",
"their",
"ancesters",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L253-L267 |
228,450 | tanghaibao/goatools | goatools/grouper/plotobj.py | PltGroupedGos._get_pltdag_path_hdr | def _get_pltdag_path_hdr(self, hdrgo, usrgos, desc="pruned"):
"""Get GoSubDag with paths from usrgos through hdrgo."""
go_sources = usrgos.union([hdrgo])
gosubdag = GoSubDag(go_sources,
self.gosubdag.get_go2obj(go_sources),
relationships=self.gosubdag.relationships,
rcntobj=self.gosubdag.rcntobj,
go2nt=self.gosubdag.go2nt,
dst_srcs_list=[(hdrgo, usrgos), (None, set([hdrgo]))])
tot_usrgos = len(set(gosubdag.go2obj.keys()).intersection(self.usrgos))
return self.ntpltgo(
hdrgo=hdrgo,
gosubdag=gosubdag,
tot_usrgos=tot_usrgos,
parentcnt=True,
desc=desc) | python | def _get_pltdag_path_hdr(self, hdrgo, usrgos, desc="pruned"):
"""Get GoSubDag with paths from usrgos through hdrgo."""
go_sources = usrgos.union([hdrgo])
gosubdag = GoSubDag(go_sources,
self.gosubdag.get_go2obj(go_sources),
relationships=self.gosubdag.relationships,
rcntobj=self.gosubdag.rcntobj,
go2nt=self.gosubdag.go2nt,
dst_srcs_list=[(hdrgo, usrgos), (None, set([hdrgo]))])
tot_usrgos = len(set(gosubdag.go2obj.keys()).intersection(self.usrgos))
return self.ntpltgo(
hdrgo=hdrgo,
gosubdag=gosubdag,
tot_usrgos=tot_usrgos,
parentcnt=True,
desc=desc) | [
"def",
"_get_pltdag_path_hdr",
"(",
"self",
",",
"hdrgo",
",",
"usrgos",
",",
"desc",
"=",
"\"pruned\"",
")",
":",
"go_sources",
"=",
"usrgos",
".",
"union",
"(",
"[",
"hdrgo",
"]",
")",
"gosubdag",
"=",
"GoSubDag",
"(",
"go_sources",
",",
"self",
".",
"gosubdag",
".",
"get_go2obj",
"(",
"go_sources",
")",
",",
"relationships",
"=",
"self",
".",
"gosubdag",
".",
"relationships",
",",
"rcntobj",
"=",
"self",
".",
"gosubdag",
".",
"rcntobj",
",",
"go2nt",
"=",
"self",
".",
"gosubdag",
".",
"go2nt",
",",
"dst_srcs_list",
"=",
"[",
"(",
"hdrgo",
",",
"usrgos",
")",
",",
"(",
"None",
",",
"set",
"(",
"[",
"hdrgo",
"]",
")",
")",
"]",
")",
"tot_usrgos",
"=",
"len",
"(",
"set",
"(",
"gosubdag",
".",
"go2obj",
".",
"keys",
"(",
")",
")",
".",
"intersection",
"(",
"self",
".",
"usrgos",
")",
")",
"return",
"self",
".",
"ntpltgo",
"(",
"hdrgo",
"=",
"hdrgo",
",",
"gosubdag",
"=",
"gosubdag",
",",
"tot_usrgos",
"=",
"tot_usrgos",
",",
"parentcnt",
"=",
"True",
",",
"desc",
"=",
"desc",
")"
] | Get GoSubDag with paths from usrgos through hdrgo. | [
"Get",
"GoSubDag",
"with",
"paths",
"from",
"usrgos",
"through",
"hdrgo",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L269-L284 |
228,451 | tanghaibao/goatools | goatools/grouper/plotobj.py | GoSubDagPlotNt.wrplt | def wrplt(self, fout_dir, plt_ext="png"):
"""Write png containing plot of GoSubDag."""
# Ex basename
basename = self.grprobj.get_fout_base(self.ntplt.hdrgo)
plt_pat = self.get_pltpat(plt_ext)
fout_basename = plt_pat.format(BASE=basename)
fout_plt = os.path.join(fout_dir, fout_basename)
self.gosubdagplot.plt_dag(fout_plt) # Create Plot
return fout_plt | python | def wrplt(self, fout_dir, plt_ext="png"):
"""Write png containing plot of GoSubDag."""
# Ex basename
basename = self.grprobj.get_fout_base(self.ntplt.hdrgo)
plt_pat = self.get_pltpat(plt_ext)
fout_basename = plt_pat.format(BASE=basename)
fout_plt = os.path.join(fout_dir, fout_basename)
self.gosubdagplot.plt_dag(fout_plt) # Create Plot
return fout_plt | [
"def",
"wrplt",
"(",
"self",
",",
"fout_dir",
",",
"plt_ext",
"=",
"\"png\"",
")",
":",
"# Ex basename",
"basename",
"=",
"self",
".",
"grprobj",
".",
"get_fout_base",
"(",
"self",
".",
"ntplt",
".",
"hdrgo",
")",
"plt_pat",
"=",
"self",
".",
"get_pltpat",
"(",
"plt_ext",
")",
"fout_basename",
"=",
"plt_pat",
".",
"format",
"(",
"BASE",
"=",
"basename",
")",
"fout_plt",
"=",
"os",
".",
"path",
".",
"join",
"(",
"fout_dir",
",",
"fout_basename",
")",
"self",
".",
"gosubdagplot",
".",
"plt_dag",
"(",
"fout_plt",
")",
"# Create Plot",
"return",
"fout_plt"
] | Write png containing plot of GoSubDag. | [
"Write",
"png",
"containing",
"plot",
"of",
"GoSubDag",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L296-L304 |
228,452 | tanghaibao/goatools | goatools/grouper/plotobj.py | GoSubDagPlotNt.get_dotstr | def get_dotstr(self):
"""Return a string containing DAG graph in Grpahviz's dot language."""
dotobj = self.gosubdagplot.get_pydot_graph() # pydot.Dot
dotstr = dotobj.create_dot()
return dotstr | python | def get_dotstr(self):
"""Return a string containing DAG graph in Grpahviz's dot language."""
dotobj = self.gosubdagplot.get_pydot_graph() # pydot.Dot
dotstr = dotobj.create_dot()
return dotstr | [
"def",
"get_dotstr",
"(",
"self",
")",
":",
"dotobj",
"=",
"self",
".",
"gosubdagplot",
".",
"get_pydot_graph",
"(",
")",
"# pydot.Dot",
"dotstr",
"=",
"dotobj",
".",
"create_dot",
"(",
")",
"return",
"dotstr"
] | Return a string containing DAG graph in Grpahviz's dot language. | [
"Return",
"a",
"string",
"containing",
"DAG",
"graph",
"in",
"Grpahviz",
"s",
"dot",
"language",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L306-L310 |
228,453 | tanghaibao/goatools | goatools/gosubdag/rpt/write_hierarchy.py | WrHierGO._get_wrhiercfg | def _get_wrhiercfg(self):
"""Initialize print format."""
prtfmt = self.gosubdag.prt_attr['fmt']
prtfmt = prtfmt.replace('{GO} # ', '')
prtfmt = prtfmt.replace('{D1:5} ', '')
return {'name2prtfmt':{'ITEM':prtfmt, 'ID':'{GO}{alt:1}'},
'max_indent': self.usrdct.get('max_indent'),
'include_only': self.usrdct.get('include_only'),
'item_marks': self.usrdct.get('item_marks', {}),
'concise_prt': 'concise' in self.usrset,
'indent': 'no_indent' not in self.usrset,
'dash_len': self.usrdct.get('dash_len', 6),
'sortby': self.usrdct.get('sortby')
} | python | def _get_wrhiercfg(self):
"""Initialize print format."""
prtfmt = self.gosubdag.prt_attr['fmt']
prtfmt = prtfmt.replace('{GO} # ', '')
prtfmt = prtfmt.replace('{D1:5} ', '')
return {'name2prtfmt':{'ITEM':prtfmt, 'ID':'{GO}{alt:1}'},
'max_indent': self.usrdct.get('max_indent'),
'include_only': self.usrdct.get('include_only'),
'item_marks': self.usrdct.get('item_marks', {}),
'concise_prt': 'concise' in self.usrset,
'indent': 'no_indent' not in self.usrset,
'dash_len': self.usrdct.get('dash_len', 6),
'sortby': self.usrdct.get('sortby')
} | [
"def",
"_get_wrhiercfg",
"(",
"self",
")",
":",
"prtfmt",
"=",
"self",
".",
"gosubdag",
".",
"prt_attr",
"[",
"'fmt'",
"]",
"prtfmt",
"=",
"prtfmt",
".",
"replace",
"(",
"'{GO} # '",
",",
"''",
")",
"prtfmt",
"=",
"prtfmt",
".",
"replace",
"(",
"'{D1:5} '",
",",
"''",
")",
"return",
"{",
"'name2prtfmt'",
":",
"{",
"'ITEM'",
":",
"prtfmt",
",",
"'ID'",
":",
"'{GO}{alt:1}'",
"}",
",",
"'max_indent'",
":",
"self",
".",
"usrdct",
".",
"get",
"(",
"'max_indent'",
")",
",",
"'include_only'",
":",
"self",
".",
"usrdct",
".",
"get",
"(",
"'include_only'",
")",
",",
"'item_marks'",
":",
"self",
".",
"usrdct",
".",
"get",
"(",
"'item_marks'",
",",
"{",
"}",
")",
",",
"'concise_prt'",
":",
"'concise'",
"in",
"self",
".",
"usrset",
",",
"'indent'",
":",
"'no_indent'",
"not",
"in",
"self",
".",
"usrset",
",",
"'dash_len'",
":",
"self",
".",
"usrdct",
".",
"get",
"(",
"'dash_len'",
",",
"6",
")",
",",
"'sortby'",
":",
"self",
".",
"usrdct",
".",
"get",
"(",
"'sortby'",
")",
"}"
] | Initialize print format. | [
"Initialize",
"print",
"format",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/write_hierarchy.py#L78-L91 |
228,454 | tanghaibao/goatools | goatools/gosubdag/rpt/write_hierarchy.py | WrHierGO._get_goroot | def _get_goroot(self, goids_all, namespace):
"""Get the top GO for the set of goids_all."""
root_goid = self.consts.NAMESPACE2GO[namespace]
if root_goid in goids_all:
return root_goid
root_goids = set()
for goid in goids_all:
goterm = self.gosubdag.go2obj[goid]
if goterm.depth == 0:
root_goids.add(goterm.id)
if len(root_goids) == 1:
return next(iter(root_goids))
raise RuntimeError("UNEXPECTED NUMBER OF ROOTS: {R}".format(R=root_goids)) | python | def _get_goroot(self, goids_all, namespace):
"""Get the top GO for the set of goids_all."""
root_goid = self.consts.NAMESPACE2GO[namespace]
if root_goid in goids_all:
return root_goid
root_goids = set()
for goid in goids_all:
goterm = self.gosubdag.go2obj[goid]
if goterm.depth == 0:
root_goids.add(goterm.id)
if len(root_goids) == 1:
return next(iter(root_goids))
raise RuntimeError("UNEXPECTED NUMBER OF ROOTS: {R}".format(R=root_goids)) | [
"def",
"_get_goroot",
"(",
"self",
",",
"goids_all",
",",
"namespace",
")",
":",
"root_goid",
"=",
"self",
".",
"consts",
".",
"NAMESPACE2GO",
"[",
"namespace",
"]",
"if",
"root_goid",
"in",
"goids_all",
":",
"return",
"root_goid",
"root_goids",
"=",
"set",
"(",
")",
"for",
"goid",
"in",
"goids_all",
":",
"goterm",
"=",
"self",
".",
"gosubdag",
".",
"go2obj",
"[",
"goid",
"]",
"if",
"goterm",
".",
"depth",
"==",
"0",
":",
"root_goids",
".",
"add",
"(",
"goterm",
".",
"id",
")",
"if",
"len",
"(",
"root_goids",
")",
"==",
"1",
":",
"return",
"next",
"(",
"iter",
"(",
"root_goids",
")",
")",
"raise",
"RuntimeError",
"(",
"\"UNEXPECTED NUMBER OF ROOTS: {R}\"",
".",
"format",
"(",
"R",
"=",
"root_goids",
")",
")"
] | Get the top GO for the set of goids_all. | [
"Get",
"the",
"top",
"GO",
"for",
"the",
"set",
"of",
"goids_all",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/write_hierarchy.py#L93-L105 |
228,455 | tanghaibao/goatools | goatools/rpt/nts_xfrm.py | MgrNts.mknts | def mknts(self, add_dct):
"""Add information from add_dct to a new copy of namedtuples stored in nts."""
nts = []
assert len(add_dct) == len(self.nts)
flds = list(next(iter(self.nts))._fields) + list(next(iter(add_dct)).keys())
ntobj = cx.namedtuple("ntgoea", " ".join(flds))
for dct_new, ntgoea in zip(add_dct, self.nts):
dct_curr = ntgoea._asdict()
for key, val in dct_new.items():
dct_curr[key] = val
nts.append(ntobj(**dct_curr))
return nts | python | def mknts(self, add_dct):
"""Add information from add_dct to a new copy of namedtuples stored in nts."""
nts = []
assert len(add_dct) == len(self.nts)
flds = list(next(iter(self.nts))._fields) + list(next(iter(add_dct)).keys())
ntobj = cx.namedtuple("ntgoea", " ".join(flds))
for dct_new, ntgoea in zip(add_dct, self.nts):
dct_curr = ntgoea._asdict()
for key, val in dct_new.items():
dct_curr[key] = val
nts.append(ntobj(**dct_curr))
return nts | [
"def",
"mknts",
"(",
"self",
",",
"add_dct",
")",
":",
"nts",
"=",
"[",
"]",
"assert",
"len",
"(",
"add_dct",
")",
"==",
"len",
"(",
"self",
".",
"nts",
")",
"flds",
"=",
"list",
"(",
"next",
"(",
"iter",
"(",
"self",
".",
"nts",
")",
")",
".",
"_fields",
")",
"+",
"list",
"(",
"next",
"(",
"iter",
"(",
"add_dct",
")",
")",
".",
"keys",
"(",
")",
")",
"ntobj",
"=",
"cx",
".",
"namedtuple",
"(",
"\"ntgoea\"",
",",
"\" \"",
".",
"join",
"(",
"flds",
")",
")",
"for",
"dct_new",
",",
"ntgoea",
"in",
"zip",
"(",
"add_dct",
",",
"self",
".",
"nts",
")",
":",
"dct_curr",
"=",
"ntgoea",
".",
"_asdict",
"(",
")",
"for",
"key",
",",
"val",
"in",
"dct_new",
".",
"items",
"(",
")",
":",
"dct_curr",
"[",
"key",
"]",
"=",
"val",
"nts",
".",
"append",
"(",
"ntobj",
"(",
"*",
"*",
"dct_curr",
")",
")",
"return",
"nts"
] | Add information from add_dct to a new copy of namedtuples stored in nts. | [
"Add",
"information",
"from",
"add_dct",
"to",
"a",
"new",
"copy",
"of",
"namedtuples",
"stored",
"in",
"nts",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/nts_xfrm.py#L22-L33 |
228,456 | tanghaibao/goatools | goatools/rpt/nts_xfrm.py | MgrNts.add_f2str | def add_f2str(self, dcts, srcfld, dstfld, dstfmt):
"""Add a namedtuple field of type string generated from an existing namedtuple field."""
# Example: f2str = objntmgr.add_f2str(dcts, "p_fdr_bh", "s_fdr_bh", "{:8.2e}")
# ntobj = self.get_ntobj()
# print(ntobj)
assert len(dcts) == len(self.nts)
for dct, ntgoea in zip(dcts, self.nts):
valorig = getattr(ntgoea, srcfld)
valstr = dstfmt.format(valorig)
dct[dstfld] = valstr | python | def add_f2str(self, dcts, srcfld, dstfld, dstfmt):
"""Add a namedtuple field of type string generated from an existing namedtuple field."""
# Example: f2str = objntmgr.add_f2str(dcts, "p_fdr_bh", "s_fdr_bh", "{:8.2e}")
# ntobj = self.get_ntobj()
# print(ntobj)
assert len(dcts) == len(self.nts)
for dct, ntgoea in zip(dcts, self.nts):
valorig = getattr(ntgoea, srcfld)
valstr = dstfmt.format(valorig)
dct[dstfld] = valstr | [
"def",
"add_f2str",
"(",
"self",
",",
"dcts",
",",
"srcfld",
",",
"dstfld",
",",
"dstfmt",
")",
":",
"# Example: f2str = objntmgr.add_f2str(dcts, \"p_fdr_bh\", \"s_fdr_bh\", \"{:8.2e}\")",
"# ntobj = self.get_ntobj()",
"# print(ntobj)",
"assert",
"len",
"(",
"dcts",
")",
"==",
"len",
"(",
"self",
".",
"nts",
")",
"for",
"dct",
",",
"ntgoea",
"in",
"zip",
"(",
"dcts",
",",
"self",
".",
"nts",
")",
":",
"valorig",
"=",
"getattr",
"(",
"ntgoea",
",",
"srcfld",
")",
"valstr",
"=",
"dstfmt",
".",
"format",
"(",
"valorig",
")",
"dct",
"[",
"dstfld",
"]",
"=",
"valstr"
] | Add a namedtuple field of type string generated from an existing namedtuple field. | [
"Add",
"a",
"namedtuple",
"field",
"of",
"type",
"string",
"generated",
"from",
"an",
"existing",
"namedtuple",
"field",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/nts_xfrm.py#L35-L44 |
228,457 | tanghaibao/goatools | goatools/rpt/nts_xfrm.py | MgrNts.get_ntobj | def get_ntobj(self):
"""Create namedtuple object with GOEA fields."""
if self.nts:
return cx.namedtuple("ntgoea", " ".join(vars(next(iter(self.nts))).keys())) | python | def get_ntobj(self):
"""Create namedtuple object with GOEA fields."""
if self.nts:
return cx.namedtuple("ntgoea", " ".join(vars(next(iter(self.nts))).keys())) | [
"def",
"get_ntobj",
"(",
"self",
")",
":",
"if",
"self",
".",
"nts",
":",
"return",
"cx",
".",
"namedtuple",
"(",
"\"ntgoea\"",
",",
"\" \"",
".",
"join",
"(",
"vars",
"(",
"next",
"(",
"iter",
"(",
"self",
".",
"nts",
")",
")",
")",
".",
"keys",
"(",
")",
")",
")"
] | Create namedtuple object with GOEA fields. | [
"Create",
"namedtuple",
"object",
"with",
"GOEA",
"fields",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/nts_xfrm.py#L46-L49 |
228,458 | tanghaibao/goatools | goatools/semantic.py | get_info_content | def get_info_content(go_id, termcounts):
'''
Calculates the information content of a GO term.
'''
# Get the observed frequency of the GO term
freq = termcounts.get_term_freq(go_id)
# Calculate the information content (i.e., -log("freq of GO term")
return -1.0 * math.log(freq) if freq else 0 | python | def get_info_content(go_id, termcounts):
'''
Calculates the information content of a GO term.
'''
# Get the observed frequency of the GO term
freq = termcounts.get_term_freq(go_id)
# Calculate the information content (i.e., -log("freq of GO term")
return -1.0 * math.log(freq) if freq else 0 | [
"def",
"get_info_content",
"(",
"go_id",
",",
"termcounts",
")",
":",
"# Get the observed frequency of the GO term",
"freq",
"=",
"termcounts",
".",
"get_term_freq",
"(",
"go_id",
")",
"# Calculate the information content (i.e., -log(\"freq of GO term\")",
"return",
"-",
"1.0",
"*",
"math",
".",
"log",
"(",
"freq",
")",
"if",
"freq",
"else",
"0"
] | Calculates the information content of a GO term. | [
"Calculates",
"the",
"information",
"content",
"of",
"a",
"GO",
"term",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L120-L128 |
228,459 | tanghaibao/goatools | goatools/semantic.py | resnik_sim | def resnik_sim(go_id1, go_id2, godag, termcounts):
'''
Computes Resnik's similarity measure.
'''
goterm1 = godag[go_id1]
goterm2 = godag[go_id2]
if goterm1.namespace == goterm2.namespace:
msca_goid = deepest_common_ancestor([go_id1, go_id2], godag)
return get_info_content(msca_goid, termcounts) | python | def resnik_sim(go_id1, go_id2, godag, termcounts):
'''
Computes Resnik's similarity measure.
'''
goterm1 = godag[go_id1]
goterm2 = godag[go_id2]
if goterm1.namespace == goterm2.namespace:
msca_goid = deepest_common_ancestor([go_id1, go_id2], godag)
return get_info_content(msca_goid, termcounts) | [
"def",
"resnik_sim",
"(",
"go_id1",
",",
"go_id2",
",",
"godag",
",",
"termcounts",
")",
":",
"goterm1",
"=",
"godag",
"[",
"go_id1",
"]",
"goterm2",
"=",
"godag",
"[",
"go_id2",
"]",
"if",
"goterm1",
".",
"namespace",
"==",
"goterm2",
".",
"namespace",
":",
"msca_goid",
"=",
"deepest_common_ancestor",
"(",
"[",
"go_id1",
",",
"go_id2",
"]",
",",
"godag",
")",
"return",
"get_info_content",
"(",
"msca_goid",
",",
"termcounts",
")"
] | Computes Resnik's similarity measure. | [
"Computes",
"Resnik",
"s",
"similarity",
"measure",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L131-L139 |
228,460 | tanghaibao/goatools | goatools/semantic.py | lin_sim | def lin_sim(goid1, goid2, godag, termcnts):
'''
Computes Lin's similarity measure.
'''
sim_r = resnik_sim(goid1, goid2, godag, termcnts)
return lin_sim_calc(goid1, goid2, sim_r, termcnts) | python | def lin_sim(goid1, goid2, godag, termcnts):
'''
Computes Lin's similarity measure.
'''
sim_r = resnik_sim(goid1, goid2, godag, termcnts)
return lin_sim_calc(goid1, goid2, sim_r, termcnts) | [
"def",
"lin_sim",
"(",
"goid1",
",",
"goid2",
",",
"godag",
",",
"termcnts",
")",
":",
"sim_r",
"=",
"resnik_sim",
"(",
"goid1",
",",
"goid2",
",",
"godag",
",",
"termcnts",
")",
"return",
"lin_sim_calc",
"(",
"goid1",
",",
"goid2",
",",
"sim_r",
",",
"termcnts",
")"
] | Computes Lin's similarity measure. | [
"Computes",
"Lin",
"s",
"similarity",
"measure",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L142-L147 |
228,461 | tanghaibao/goatools | goatools/semantic.py | lin_sim_calc | def lin_sim_calc(goid1, goid2, sim_r, termcnts):
'''
Computes Lin's similarity measure using pre-calculated Resnik's similarities.
'''
if sim_r is not None:
info = get_info_content(goid1, termcnts) + get_info_content(goid2, termcnts)
if info != 0:
return (2*sim_r)/info | python | def lin_sim_calc(goid1, goid2, sim_r, termcnts):
'''
Computes Lin's similarity measure using pre-calculated Resnik's similarities.
'''
if sim_r is not None:
info = get_info_content(goid1, termcnts) + get_info_content(goid2, termcnts)
if info != 0:
return (2*sim_r)/info | [
"def",
"lin_sim_calc",
"(",
"goid1",
",",
"goid2",
",",
"sim_r",
",",
"termcnts",
")",
":",
"if",
"sim_r",
"is",
"not",
"None",
":",
"info",
"=",
"get_info_content",
"(",
"goid1",
",",
"termcnts",
")",
"+",
"get_info_content",
"(",
"goid2",
",",
"termcnts",
")",
"if",
"info",
"!=",
"0",
":",
"return",
"(",
"2",
"*",
"sim_r",
")",
"/",
"info"
] | Computes Lin's similarity measure using pre-calculated Resnik's similarities. | [
"Computes",
"Lin",
"s",
"similarity",
"measure",
"using",
"pre",
"-",
"calculated",
"Resnik",
"s",
"similarities",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L150-L157 |
228,462 | tanghaibao/goatools | goatools/semantic.py | common_parent_go_ids | def common_parent_go_ids(goids, godag):
'''
This function finds the common ancestors in the GO
tree of the list of goids in the input.
'''
# Find candidates from first
rec = godag[goids[0]]
candidates = rec.get_all_parents()
candidates.update({goids[0]})
# Find intersection with second to nth goid
for goid in goids[1:]:
rec = godag[goid]
parents = rec.get_all_parents()
parents.update({goid})
# Find the intersection with the candidates, and update.
candidates.intersection_update(parents)
return candidates | python | def common_parent_go_ids(goids, godag):
'''
This function finds the common ancestors in the GO
tree of the list of goids in the input.
'''
# Find candidates from first
rec = godag[goids[0]]
candidates = rec.get_all_parents()
candidates.update({goids[0]})
# Find intersection with second to nth goid
for goid in goids[1:]:
rec = godag[goid]
parents = rec.get_all_parents()
parents.update({goid})
# Find the intersection with the candidates, and update.
candidates.intersection_update(parents)
return candidates | [
"def",
"common_parent_go_ids",
"(",
"goids",
",",
"godag",
")",
":",
"# Find candidates from first",
"rec",
"=",
"godag",
"[",
"goids",
"[",
"0",
"]",
"]",
"candidates",
"=",
"rec",
".",
"get_all_parents",
"(",
")",
"candidates",
".",
"update",
"(",
"{",
"goids",
"[",
"0",
"]",
"}",
")",
"# Find intersection with second to nth goid",
"for",
"goid",
"in",
"goids",
"[",
"1",
":",
"]",
":",
"rec",
"=",
"godag",
"[",
"goid",
"]",
"parents",
"=",
"rec",
".",
"get_all_parents",
"(",
")",
"parents",
".",
"update",
"(",
"{",
"goid",
"}",
")",
"# Find the intersection with the candidates, and update.",
"candidates",
".",
"intersection_update",
"(",
"parents",
")",
"return",
"candidates"
] | This function finds the common ancestors in the GO
tree of the list of goids in the input. | [
"This",
"function",
"finds",
"the",
"common",
"ancestors",
"in",
"the",
"GO",
"tree",
"of",
"the",
"list",
"of",
"goids",
"in",
"the",
"input",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L160-L178 |
228,463 | tanghaibao/goatools | goatools/semantic.py | deepest_common_ancestor | def deepest_common_ancestor(goterms, godag):
'''
This function gets the nearest common ancestor
using the above function.
Only returns single most specific - assumes unique exists.
'''
# Take the element at maximum depth.
return max(common_parent_go_ids(goterms, godag), key=lambda t: godag[t].depth) | python | def deepest_common_ancestor(goterms, godag):
'''
This function gets the nearest common ancestor
using the above function.
Only returns single most specific - assumes unique exists.
'''
# Take the element at maximum depth.
return max(common_parent_go_ids(goterms, godag), key=lambda t: godag[t].depth) | [
"def",
"deepest_common_ancestor",
"(",
"goterms",
",",
"godag",
")",
":",
"# Take the element at maximum depth.",
"return",
"max",
"(",
"common_parent_go_ids",
"(",
"goterms",
",",
"godag",
")",
",",
"key",
"=",
"lambda",
"t",
":",
"godag",
"[",
"t",
"]",
".",
"depth",
")"
] | This function gets the nearest common ancestor
using the above function.
Only returns single most specific - assumes unique exists. | [
"This",
"function",
"gets",
"the",
"nearest",
"common",
"ancestor",
"using",
"the",
"above",
"function",
".",
"Only",
"returns",
"single",
"most",
"specific",
"-",
"assumes",
"unique",
"exists",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L181-L188 |
228,464 | tanghaibao/goatools | goatools/semantic.py | min_branch_length | def min_branch_length(go_id1, go_id2, godag, branch_dist):
'''
Finds the minimum branch length between two terms in the GO DAG.
'''
# First get the deepest common ancestor
goterm1 = godag[go_id1]
goterm2 = godag[go_id2]
if goterm1.namespace == goterm2.namespace:
dca = deepest_common_ancestor([go_id1, go_id2], godag)
# Then get the distance from the DCA to each term
dca_depth = godag[dca].depth
depth1 = goterm1.depth - dca_depth
depth2 = goterm2.depth - dca_depth
# Return the total distance - i.e., to the deepest common ancestor and back.
return depth1 + depth2
elif branch_dist is not None:
return goterm1.depth + goterm2.depth + branch_dist | python | def min_branch_length(go_id1, go_id2, godag, branch_dist):
'''
Finds the minimum branch length between two terms in the GO DAG.
'''
# First get the deepest common ancestor
goterm1 = godag[go_id1]
goterm2 = godag[go_id2]
if goterm1.namespace == goterm2.namespace:
dca = deepest_common_ancestor([go_id1, go_id2], godag)
# Then get the distance from the DCA to each term
dca_depth = godag[dca].depth
depth1 = goterm1.depth - dca_depth
depth2 = goterm2.depth - dca_depth
# Return the total distance - i.e., to the deepest common ancestor and back.
return depth1 + depth2
elif branch_dist is not None:
return goterm1.depth + goterm2.depth + branch_dist | [
"def",
"min_branch_length",
"(",
"go_id1",
",",
"go_id2",
",",
"godag",
",",
"branch_dist",
")",
":",
"# First get the deepest common ancestor",
"goterm1",
"=",
"godag",
"[",
"go_id1",
"]",
"goterm2",
"=",
"godag",
"[",
"go_id2",
"]",
"if",
"goterm1",
".",
"namespace",
"==",
"goterm2",
".",
"namespace",
":",
"dca",
"=",
"deepest_common_ancestor",
"(",
"[",
"go_id1",
",",
"go_id2",
"]",
",",
"godag",
")",
"# Then get the distance from the DCA to each term",
"dca_depth",
"=",
"godag",
"[",
"dca",
"]",
".",
"depth",
"depth1",
"=",
"goterm1",
".",
"depth",
"-",
"dca_depth",
"depth2",
"=",
"goterm2",
".",
"depth",
"-",
"dca_depth",
"# Return the total distance - i.e., to the deepest common ancestor and back.",
"return",
"depth1",
"+",
"depth2",
"elif",
"branch_dist",
"is",
"not",
"None",
":",
"return",
"goterm1",
".",
"depth",
"+",
"goterm2",
".",
"depth",
"+",
"branch_dist"
] | Finds the minimum branch length between two terms in the GO DAG. | [
"Finds",
"the",
"minimum",
"branch",
"length",
"between",
"two",
"terms",
"in",
"the",
"GO",
"DAG",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L191-L210 |
228,465 | tanghaibao/goatools | goatools/semantic.py | TermCounts._init_count_terms | def _init_count_terms(self, annots):
'''
Fills in the counts and overall aspect counts.
'''
gonotindag = set()
gocnts = self.gocnts
go2obj = self.go2obj
# Fill gocnts with GO IDs in annotations and their corresponding counts
for terms in annots.values(): # key is 'gene'
# Make a union of all the terms for a gene, if term parents are
# propagated but they won't get double-counted for the gene
allterms = set()
for go_id in terms:
goobj = go2obj.get(go_id, None)
if goobj is not None:
allterms.add(go_id)
allterms |= goobj.get_all_parents()
else:
gonotindag.add(go_id)
for parent in allterms:
gocnts[parent] += 1
if gonotindag:
print("{N} Assc. GO IDs not found in the GODag\n".format(N=len(gonotindag))) | python | def _init_count_terms(self, annots):
'''
Fills in the counts and overall aspect counts.
'''
gonotindag = set()
gocnts = self.gocnts
go2obj = self.go2obj
# Fill gocnts with GO IDs in annotations and their corresponding counts
for terms in annots.values(): # key is 'gene'
# Make a union of all the terms for a gene, if term parents are
# propagated but they won't get double-counted for the gene
allterms = set()
for go_id in terms:
goobj = go2obj.get(go_id, None)
if goobj is not None:
allterms.add(go_id)
allterms |= goobj.get_all_parents()
else:
gonotindag.add(go_id)
for parent in allterms:
gocnts[parent] += 1
if gonotindag:
print("{N} Assc. GO IDs not found in the GODag\n".format(N=len(gonotindag))) | [
"def",
"_init_count_terms",
"(",
"self",
",",
"annots",
")",
":",
"gonotindag",
"=",
"set",
"(",
")",
"gocnts",
"=",
"self",
".",
"gocnts",
"go2obj",
"=",
"self",
".",
"go2obj",
"# Fill gocnts with GO IDs in annotations and their corresponding counts",
"for",
"terms",
"in",
"annots",
".",
"values",
"(",
")",
":",
"# key is 'gene'",
"# Make a union of all the terms for a gene, if term parents are",
"# propagated but they won't get double-counted for the gene",
"allterms",
"=",
"set",
"(",
")",
"for",
"go_id",
"in",
"terms",
":",
"goobj",
"=",
"go2obj",
".",
"get",
"(",
"go_id",
",",
"None",
")",
"if",
"goobj",
"is",
"not",
"None",
":",
"allterms",
".",
"add",
"(",
"go_id",
")",
"allterms",
"|=",
"goobj",
".",
"get_all_parents",
"(",
")",
"else",
":",
"gonotindag",
".",
"add",
"(",
"go_id",
")",
"for",
"parent",
"in",
"allterms",
":",
"gocnts",
"[",
"parent",
"]",
"+=",
"1",
"if",
"gonotindag",
":",
"print",
"(",
"\"{N} Assc. GO IDs not found in the GODag\\n\"",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"gonotindag",
")",
")",
")"
] | Fills in the counts and overall aspect counts. | [
"Fills",
"in",
"the",
"counts",
"and",
"overall",
"aspect",
"counts",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L43-L65 |
228,466 | tanghaibao/goatools | goatools/semantic.py | TermCounts._init_add_goid_alt | def _init_add_goid_alt(self):
'''
Add alternate GO IDs to term counts.
'''
# Fill aspect_counts. Find alternate GO IDs that may not be on gocnts
goid_alts = set()
go2cnt_add = {}
aspect_counts = self.aspect_counts
gocnts = self.gocnts
go2obj = self.go2obj
for go_id, cnt in gocnts.items():
goobj = go2obj[go_id]
assert cnt, "NO TERM COUNTS FOR {GO}".format(GO=goobj.item_id)
# Was the count set using an alternate GO?
if go_id != goobj.item_id:
go2cnt_add[goobj.item_id] = cnt
goid_alts |= goobj.alt_ids
# Group by namespace
aspect_counts[goobj.namespace] += cnt
# If alternate GO used to set count, add main GO ID
for goid, cnt in go2cnt_add.items():
gocnts[goid] = cnt
# Add missing alt GO IDs to gocnts
for alt_goid in goid_alts.difference(gocnts):
goobj = go2obj[alt_goid]
cnt = gocnts[goobj.item_id]
assert cnt, "NO TERM COUNTS FOR ALT_ID({GOa}) ID({GO}): {NAME}".format(
GOa=alt_goid, GO=goobj.item_id, NAME=goobj.name)
gocnts[alt_goid] = cnt | python | def _init_add_goid_alt(self):
'''
Add alternate GO IDs to term counts.
'''
# Fill aspect_counts. Find alternate GO IDs that may not be on gocnts
goid_alts = set()
go2cnt_add = {}
aspect_counts = self.aspect_counts
gocnts = self.gocnts
go2obj = self.go2obj
for go_id, cnt in gocnts.items():
goobj = go2obj[go_id]
assert cnt, "NO TERM COUNTS FOR {GO}".format(GO=goobj.item_id)
# Was the count set using an alternate GO?
if go_id != goobj.item_id:
go2cnt_add[goobj.item_id] = cnt
goid_alts |= goobj.alt_ids
# Group by namespace
aspect_counts[goobj.namespace] += cnt
# If alternate GO used to set count, add main GO ID
for goid, cnt in go2cnt_add.items():
gocnts[goid] = cnt
# Add missing alt GO IDs to gocnts
for alt_goid in goid_alts.difference(gocnts):
goobj = go2obj[alt_goid]
cnt = gocnts[goobj.item_id]
assert cnt, "NO TERM COUNTS FOR ALT_ID({GOa}) ID({GO}): {NAME}".format(
GOa=alt_goid, GO=goobj.item_id, NAME=goobj.name)
gocnts[alt_goid] = cnt | [
"def",
"_init_add_goid_alt",
"(",
"self",
")",
":",
"# Fill aspect_counts. Find alternate GO IDs that may not be on gocnts",
"goid_alts",
"=",
"set",
"(",
")",
"go2cnt_add",
"=",
"{",
"}",
"aspect_counts",
"=",
"self",
".",
"aspect_counts",
"gocnts",
"=",
"self",
".",
"gocnts",
"go2obj",
"=",
"self",
".",
"go2obj",
"for",
"go_id",
",",
"cnt",
"in",
"gocnts",
".",
"items",
"(",
")",
":",
"goobj",
"=",
"go2obj",
"[",
"go_id",
"]",
"assert",
"cnt",
",",
"\"NO TERM COUNTS FOR {GO}\"",
".",
"format",
"(",
"GO",
"=",
"goobj",
".",
"item_id",
")",
"# Was the count set using an alternate GO?",
"if",
"go_id",
"!=",
"goobj",
".",
"item_id",
":",
"go2cnt_add",
"[",
"goobj",
".",
"item_id",
"]",
"=",
"cnt",
"goid_alts",
"|=",
"goobj",
".",
"alt_ids",
"# Group by namespace",
"aspect_counts",
"[",
"goobj",
".",
"namespace",
"]",
"+=",
"cnt",
"# If alternate GO used to set count, add main GO ID",
"for",
"goid",
",",
"cnt",
"in",
"go2cnt_add",
".",
"items",
"(",
")",
":",
"gocnts",
"[",
"goid",
"]",
"=",
"cnt",
"# Add missing alt GO IDs to gocnts",
"for",
"alt_goid",
"in",
"goid_alts",
".",
"difference",
"(",
"gocnts",
")",
":",
"goobj",
"=",
"go2obj",
"[",
"alt_goid",
"]",
"cnt",
"=",
"gocnts",
"[",
"goobj",
".",
"item_id",
"]",
"assert",
"cnt",
",",
"\"NO TERM COUNTS FOR ALT_ID({GOa}) ID({GO}): {NAME}\"",
".",
"format",
"(",
"GOa",
"=",
"alt_goid",
",",
"GO",
"=",
"goobj",
".",
"item_id",
",",
"NAME",
"=",
"goobj",
".",
"name",
")",
"gocnts",
"[",
"alt_goid",
"]",
"=",
"cnt"
] | Add alternate GO IDs to term counts. | [
"Add",
"alternate",
"GO",
"IDs",
"to",
"term",
"counts",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L68-L96 |
228,467 | tanghaibao/goatools | goatools/semantic.py | TermCounts.get_term_freq | def get_term_freq(self, go_id):
'''
Returns the frequency at which a particular GO term has
been observed in the annotations.
'''
num_ns = float(self.get_total_count(self.go2obj[go_id].namespace))
return float(self.get_count(go_id))/num_ns if num_ns != 0 else 0 | python | def get_term_freq(self, go_id):
'''
Returns the frequency at which a particular GO term has
been observed in the annotations.
'''
num_ns = float(self.get_total_count(self.go2obj[go_id].namespace))
return float(self.get_count(go_id))/num_ns if num_ns != 0 else 0 | [
"def",
"get_term_freq",
"(",
"self",
",",
"go_id",
")",
":",
"num_ns",
"=",
"float",
"(",
"self",
".",
"get_total_count",
"(",
"self",
".",
"go2obj",
"[",
"go_id",
"]",
".",
"namespace",
")",
")",
"return",
"float",
"(",
"self",
".",
"get_count",
"(",
"go_id",
")",
")",
"/",
"num_ns",
"if",
"num_ns",
"!=",
"0",
"else",
"0"
] | Returns the frequency at which a particular GO term has
been observed in the annotations. | [
"Returns",
"the",
"frequency",
"at",
"which",
"a",
"particular",
"GO",
"term",
"has",
"been",
"observed",
"in",
"the",
"annotations",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L111-L117 |
228,468 | tanghaibao/goatools | goatools/grouper/hdrgos.py | HdrgosSections.get_sections | def get_sections(self, hdrgo, dflt_section=True):
"""Given a header GO, return the sections that contain it."""
dflt_list = []
# If the hdrgo is not in a section, return the default name for a section
if dflt_section:
dflt_list = [self.secdflt]
return self.hdrgo2sections.get(hdrgo, dflt_list) | python | def get_sections(self, hdrgo, dflt_section=True):
"""Given a header GO, return the sections that contain it."""
dflt_list = []
# If the hdrgo is not in a section, return the default name for a section
if dflt_section:
dflt_list = [self.secdflt]
return self.hdrgo2sections.get(hdrgo, dflt_list) | [
"def",
"get_sections",
"(",
"self",
",",
"hdrgo",
",",
"dflt_section",
"=",
"True",
")",
":",
"dflt_list",
"=",
"[",
"]",
"# If the hdrgo is not in a section, return the default name for a section",
"if",
"dflt_section",
":",
"dflt_list",
"=",
"[",
"self",
".",
"secdflt",
"]",
"return",
"self",
".",
"hdrgo2sections",
".",
"get",
"(",
"hdrgo",
",",
"dflt_list",
")"
] | Given a header GO, return the sections that contain it. | [
"Given",
"a",
"header",
"GO",
"return",
"the",
"sections",
"that",
"contain",
"it",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/hdrgos.py#L25-L31 |
228,469 | tanghaibao/goatools | goatools/grouper/hdrgos.py | HdrgosSections.get_section_hdrgos | def get_section_hdrgos(self):
"""Get the GO group headers explicitly listed in sections."""
return set([h for _, hs in self.sections for h in hs]) if self.sections else set() | python | def get_section_hdrgos(self):
"""Get the GO group headers explicitly listed in sections."""
return set([h for _, hs in self.sections for h in hs]) if self.sections else set() | [
"def",
"get_section_hdrgos",
"(",
"self",
")",
":",
"return",
"set",
"(",
"[",
"h",
"for",
"_",
",",
"hs",
"in",
"self",
".",
"sections",
"for",
"h",
"in",
"hs",
"]",
")",
"if",
"self",
".",
"sections",
"else",
"set",
"(",
")"
] | Get the GO group headers explicitly listed in sections. | [
"Get",
"the",
"GO",
"group",
"headers",
"explicitly",
"listed",
"in",
"sections",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/hdrgos.py#L41-L43 |
228,470 | tanghaibao/goatools | goatools/grouper/hdrgos.py | HdrgosSections._chk_sections | def _chk_sections(sections):
"""Check format of user-provided 'sections' variable"""
if sections:
assert len(sections[0]) == 2, \
"SECTIONS DATA MUST BE A 2-D LIST. FOUND: {S}".format(S=sections)
for _, hdrgos in sections:
chk_goids(hdrgos, "HdrgosSections::_chk_sections()") | python | def _chk_sections(sections):
"""Check format of user-provided 'sections' variable"""
if sections:
assert len(sections[0]) == 2, \
"SECTIONS DATA MUST BE A 2-D LIST. FOUND: {S}".format(S=sections)
for _, hdrgos in sections:
chk_goids(hdrgos, "HdrgosSections::_chk_sections()") | [
"def",
"_chk_sections",
"(",
"sections",
")",
":",
"if",
"sections",
":",
"assert",
"len",
"(",
"sections",
"[",
"0",
"]",
")",
"==",
"2",
",",
"\"SECTIONS DATA MUST BE A 2-D LIST. FOUND: {S}\"",
".",
"format",
"(",
"S",
"=",
"sections",
")",
"for",
"_",
",",
"hdrgos",
"in",
"sections",
":",
"chk_goids",
"(",
"hdrgos",
",",
"\"HdrgosSections::_chk_sections()\"",
")"
] | Check format of user-provided 'sections' variable | [
"Check",
"format",
"of",
"user",
"-",
"provided",
"sections",
"variable"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/hdrgos.py#L46-L52 |
228,471 | tanghaibao/goatools | goatools/grouper/hdrgos.py | HdrgosSections._init_hdrgos | def _init_hdrgos(self, hdrgos_dflt, hdrgos_usr=None, add_dflt=True):
"""Initialize GO high"""
# Use default GO group header values
if (hdrgos_usr is None or hdrgos_usr is False) and not self.sections:
return set(hdrgos_dflt)
# Get GO group headers provided by user
hdrgos_init = set()
if hdrgos_usr:
chk_goids(hdrgos_usr, "User-provided GO group headers")
hdrgos_init |= set(hdrgos_usr)
if self.sections:
self._chk_sections(self.sections)
hdrgos_sec = set([hg for _, hdrgos in self.sections for hg in hdrgos])
chk_goids(hdrgos_sec, "User-provided GO group headers in sections")
hdrgos_init |= hdrgos_sec
# Add default depth-01 GOs to headers, if desired
if add_dflt:
return set(hdrgos_init).union(hdrgos_dflt)
# Return user-provided GO grouping headers
return hdrgos_init | python | def _init_hdrgos(self, hdrgos_dflt, hdrgos_usr=None, add_dflt=True):
"""Initialize GO high"""
# Use default GO group header values
if (hdrgos_usr is None or hdrgos_usr is False) and not self.sections:
return set(hdrgos_dflt)
# Get GO group headers provided by user
hdrgos_init = set()
if hdrgos_usr:
chk_goids(hdrgos_usr, "User-provided GO group headers")
hdrgos_init |= set(hdrgos_usr)
if self.sections:
self._chk_sections(self.sections)
hdrgos_sec = set([hg for _, hdrgos in self.sections for hg in hdrgos])
chk_goids(hdrgos_sec, "User-provided GO group headers in sections")
hdrgos_init |= hdrgos_sec
# Add default depth-01 GOs to headers, if desired
if add_dflt:
return set(hdrgos_init).union(hdrgos_dflt)
# Return user-provided GO grouping headers
return hdrgos_init | [
"def",
"_init_hdrgos",
"(",
"self",
",",
"hdrgos_dflt",
",",
"hdrgos_usr",
"=",
"None",
",",
"add_dflt",
"=",
"True",
")",
":",
"# Use default GO group header values",
"if",
"(",
"hdrgos_usr",
"is",
"None",
"or",
"hdrgos_usr",
"is",
"False",
")",
"and",
"not",
"self",
".",
"sections",
":",
"return",
"set",
"(",
"hdrgos_dflt",
")",
"# Get GO group headers provided by user",
"hdrgos_init",
"=",
"set",
"(",
")",
"if",
"hdrgos_usr",
":",
"chk_goids",
"(",
"hdrgos_usr",
",",
"\"User-provided GO group headers\"",
")",
"hdrgos_init",
"|=",
"set",
"(",
"hdrgos_usr",
")",
"if",
"self",
".",
"sections",
":",
"self",
".",
"_chk_sections",
"(",
"self",
".",
"sections",
")",
"hdrgos_sec",
"=",
"set",
"(",
"[",
"hg",
"for",
"_",
",",
"hdrgos",
"in",
"self",
".",
"sections",
"for",
"hg",
"in",
"hdrgos",
"]",
")",
"chk_goids",
"(",
"hdrgos_sec",
",",
"\"User-provided GO group headers in sections\"",
")",
"hdrgos_init",
"|=",
"hdrgos_sec",
"# Add default depth-01 GOs to headers, if desired",
"if",
"add_dflt",
":",
"return",
"set",
"(",
"hdrgos_init",
")",
".",
"union",
"(",
"hdrgos_dflt",
")",
"# Return user-provided GO grouping headers",
"return",
"hdrgos_init"
] | Initialize GO high | [
"Initialize",
"GO",
"high"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/hdrgos.py#L69-L88 |
228,472 | tanghaibao/goatools | goatools/obo_tasks.py | get_all_parents | def get_all_parents(go_objs):
"""Return a set containing all GO Term parents of multiple GOTerm objects."""
go_parents = set()
for go_obj in go_objs:
go_parents |= go_obj.get_all_parents()
return go_parents | python | def get_all_parents(go_objs):
"""Return a set containing all GO Term parents of multiple GOTerm objects."""
go_parents = set()
for go_obj in go_objs:
go_parents |= go_obj.get_all_parents()
return go_parents | [
"def",
"get_all_parents",
"(",
"go_objs",
")",
":",
"go_parents",
"=",
"set",
"(",
")",
"for",
"go_obj",
"in",
"go_objs",
":",
"go_parents",
"|=",
"go_obj",
".",
"get_all_parents",
"(",
")",
"return",
"go_parents"
] | Return a set containing all GO Term parents of multiple GOTerm objects. | [
"Return",
"a",
"set",
"containing",
"all",
"GO",
"Term",
"parents",
"of",
"multiple",
"GOTerm",
"objects",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_tasks.py#L3-L8 |
228,473 | tanghaibao/goatools | goatools/statsdescribe.py | StatsDescribe.prt_hdr | def prt_hdr(self, prt=sys.stdout, name="name "):
"""Print stats header in markdown style."""
hdr = "{NAME} | # {ITEMS:11} | range | 25th percentile | " \
" median | 75th percentile | mean | stddev\n".format(NAME=name, ITEMS=self.desc)
div = "{DASHES}|---------------|----------------------|" \
"-----------------|----------|-----------------|----------|-------\n".format(
DASHES='-'*(len(name)))
prt.write(hdr)
prt.write(div) | python | def prt_hdr(self, prt=sys.stdout, name="name "):
"""Print stats header in markdown style."""
hdr = "{NAME} | # {ITEMS:11} | range | 25th percentile | " \
" median | 75th percentile | mean | stddev\n".format(NAME=name, ITEMS=self.desc)
div = "{DASHES}|---------------|----------------------|" \
"-----------------|----------|-----------------|----------|-------\n".format(
DASHES='-'*(len(name)))
prt.write(hdr)
prt.write(div) | [
"def",
"prt_hdr",
"(",
"self",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"name",
"=",
"\"name \"",
")",
":",
"hdr",
"=",
"\"{NAME} | # {ITEMS:11} | range | 25th percentile | \"",
"\" median | 75th percentile | mean | stddev\\n\"",
".",
"format",
"(",
"NAME",
"=",
"name",
",",
"ITEMS",
"=",
"self",
".",
"desc",
")",
"div",
"=",
"\"{DASHES}|---------------|----------------------|\"",
"\"-----------------|----------|-----------------|----------|-------\\n\"",
".",
"format",
"(",
"DASHES",
"=",
"'-'",
"*",
"(",
"len",
"(",
"name",
")",
")",
")",
"prt",
".",
"write",
"(",
"hdr",
")",
"prt",
".",
"write",
"(",
"div",
")"
] | Print stats header in markdown style. | [
"Print",
"stats",
"header",
"in",
"markdown",
"style",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L21-L29 |
228,474 | tanghaibao/goatools | goatools/statsdescribe.py | StatsDescribe.prt_data | def prt_data(self, name, vals, prt=sys.stdout):
"""Print stats data in markdown style."""
fld2val = self.get_fld2val(name, vals)
prt.write(self.fmt.format(**fld2val))
return fld2val | python | def prt_data(self, name, vals, prt=sys.stdout):
"""Print stats data in markdown style."""
fld2val = self.get_fld2val(name, vals)
prt.write(self.fmt.format(**fld2val))
return fld2val | [
"def",
"prt_data",
"(",
"self",
",",
"name",
",",
"vals",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"fld2val",
"=",
"self",
".",
"get_fld2val",
"(",
"name",
",",
"vals",
")",
"prt",
".",
"write",
"(",
"self",
".",
"fmt",
".",
"format",
"(",
"*",
"*",
"fld2val",
")",
")",
"return",
"fld2val"
] | Print stats data in markdown style. | [
"Print",
"stats",
"data",
"in",
"markdown",
"style",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L31-L35 |
228,475 | tanghaibao/goatools | goatools/statsdescribe.py | StatsDescribe.getstr_data | def getstr_data(self, name, vals):
"""Return stats data string in markdown style."""
fld2val = self.get_fld2val(name, vals)
return self.fmt.format(**fld2val) | python | def getstr_data(self, name, vals):
"""Return stats data string in markdown style."""
fld2val = self.get_fld2val(name, vals)
return self.fmt.format(**fld2val) | [
"def",
"getstr_data",
"(",
"self",
",",
"name",
",",
"vals",
")",
":",
"fld2val",
"=",
"self",
".",
"get_fld2val",
"(",
"name",
",",
"vals",
")",
"return",
"self",
".",
"fmt",
".",
"format",
"(",
"*",
"*",
"fld2val",
")"
] | Return stats data string in markdown style. | [
"Return",
"stats",
"data",
"string",
"in",
"markdown",
"style",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L37-L40 |
228,476 | tanghaibao/goatools | goatools/statsdescribe.py | StatsDescribe.get_fld2val | def get_fld2val(self, name, vals):
"""Describe summary statistics for a list of numbers."""
if vals:
return self._init_fld2val_stats(name, vals)
return self._init_fld2val_null(name) | python | def get_fld2val(self, name, vals):
"""Describe summary statistics for a list of numbers."""
if vals:
return self._init_fld2val_stats(name, vals)
return self._init_fld2val_null(name) | [
"def",
"get_fld2val",
"(",
"self",
",",
"name",
",",
"vals",
")",
":",
"if",
"vals",
":",
"return",
"self",
".",
"_init_fld2val_stats",
"(",
"name",
",",
"vals",
")",
"return",
"self",
".",
"_init_fld2val_null",
"(",
"name",
")"
] | Describe summary statistics for a list of numbers. | [
"Describe",
"summary",
"statistics",
"for",
"a",
"list",
"of",
"numbers",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L42-L46 |
228,477 | tanghaibao/goatools | goatools/statsdescribe.py | StatsDescribe._init_fld2val_stats | def _init_fld2val_stats(self, name, vals):
"""Return statistics on values."""
vals_stats = stats.describe(vals)
stddev = math.sqrt(vals_stats[3]) # stats variance
p25 = np.percentile(vals, 25)
p50 = np.percentile(vals, 50) # median
p75 = np.percentile(vals, 75)
fld2val = {
'name':name,
'qty'.format(ITEMS=self.desc):vals_stats[0], # stats nobs
'range':self._get_str_range(vals_stats),
'25th percentile':p25,
'median':p50,
'75th percentile':p75,
'mean':vals_stats[2], # stats mean
'stddev':stddev}
fmtflds = set(['25th percentile', 'median', '75th percentile', 'mean', 'stddev'])
mkint = "," in self.fmtstr
for key, val in fld2val.items():
if key in fmtflds:
if mkint:
val = int(round(val))
fld2val[key] = self.fmtstr.format(val)
return fld2val | python | def _init_fld2val_stats(self, name, vals):
"""Return statistics on values."""
vals_stats = stats.describe(vals)
stddev = math.sqrt(vals_stats[3]) # stats variance
p25 = np.percentile(vals, 25)
p50 = np.percentile(vals, 50) # median
p75 = np.percentile(vals, 75)
fld2val = {
'name':name,
'qty'.format(ITEMS=self.desc):vals_stats[0], # stats nobs
'range':self._get_str_range(vals_stats),
'25th percentile':p25,
'median':p50,
'75th percentile':p75,
'mean':vals_stats[2], # stats mean
'stddev':stddev}
fmtflds = set(['25th percentile', 'median', '75th percentile', 'mean', 'stddev'])
mkint = "," in self.fmtstr
for key, val in fld2val.items():
if key in fmtflds:
if mkint:
val = int(round(val))
fld2val[key] = self.fmtstr.format(val)
return fld2val | [
"def",
"_init_fld2val_stats",
"(",
"self",
",",
"name",
",",
"vals",
")",
":",
"vals_stats",
"=",
"stats",
".",
"describe",
"(",
"vals",
")",
"stddev",
"=",
"math",
".",
"sqrt",
"(",
"vals_stats",
"[",
"3",
"]",
")",
"# stats variance",
"p25",
"=",
"np",
".",
"percentile",
"(",
"vals",
",",
"25",
")",
"p50",
"=",
"np",
".",
"percentile",
"(",
"vals",
",",
"50",
")",
"# median",
"p75",
"=",
"np",
".",
"percentile",
"(",
"vals",
",",
"75",
")",
"fld2val",
"=",
"{",
"'name'",
":",
"name",
",",
"'qty'",
".",
"format",
"(",
"ITEMS",
"=",
"self",
".",
"desc",
")",
":",
"vals_stats",
"[",
"0",
"]",
",",
"# stats nobs",
"'range'",
":",
"self",
".",
"_get_str_range",
"(",
"vals_stats",
")",
",",
"'25th percentile'",
":",
"p25",
",",
"'median'",
":",
"p50",
",",
"'75th percentile'",
":",
"p75",
",",
"'mean'",
":",
"vals_stats",
"[",
"2",
"]",
",",
"# stats mean",
"'stddev'",
":",
"stddev",
"}",
"fmtflds",
"=",
"set",
"(",
"[",
"'25th percentile'",
",",
"'median'",
",",
"'75th percentile'",
",",
"'mean'",
",",
"'stddev'",
"]",
")",
"mkint",
"=",
"\",\"",
"in",
"self",
".",
"fmtstr",
"for",
"key",
",",
"val",
"in",
"fld2val",
".",
"items",
"(",
")",
":",
"if",
"key",
"in",
"fmtflds",
":",
"if",
"mkint",
":",
"val",
"=",
"int",
"(",
"round",
"(",
"val",
")",
")",
"fld2val",
"[",
"key",
"]",
"=",
"self",
".",
"fmtstr",
".",
"format",
"(",
"val",
")",
"return",
"fld2val"
] | Return statistics on values. | [
"Return",
"statistics",
"on",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L48-L71 |
228,478 | tanghaibao/goatools | goatools/statsdescribe.py | StatsDescribe._get_str_range | def _get_str_range(self, vals_stats):
"""Return a string containing the range of values."""
minmax = vals_stats[1] # stats minmax
minval = self.fmtstr.format(minmax[0])
maxval = self.fmtstr.format(minmax[1])
return '{A} to {B:6>}'.format(A=minval, B=maxval) | python | def _get_str_range(self, vals_stats):
"""Return a string containing the range of values."""
minmax = vals_stats[1] # stats minmax
minval = self.fmtstr.format(minmax[0])
maxval = self.fmtstr.format(minmax[1])
return '{A} to {B:6>}'.format(A=minval, B=maxval) | [
"def",
"_get_str_range",
"(",
"self",
",",
"vals_stats",
")",
":",
"minmax",
"=",
"vals_stats",
"[",
"1",
"]",
"# stats minmax",
"minval",
"=",
"self",
".",
"fmtstr",
".",
"format",
"(",
"minmax",
"[",
"0",
"]",
")",
"maxval",
"=",
"self",
".",
"fmtstr",
".",
"format",
"(",
"minmax",
"[",
"1",
"]",
")",
"return",
"'{A} to {B:6>}'",
".",
"format",
"(",
"A",
"=",
"minval",
",",
"B",
"=",
"maxval",
")"
] | Return a string containing the range of values. | [
"Return",
"a",
"string",
"containing",
"the",
"range",
"of",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L85-L90 |
228,479 | tanghaibao/goatools | goatools/grouper/tasks.py | SummarySec2dHdrGos.summarize_sec2hdrgos | def summarize_sec2hdrgos(self, sec2d_hdrgos):
"""Get counts of header GO IDs and sections."""
hdrgos_all = set([])
hdrgos_grouped = set()
hdrgos_ungrouped = set()
sections_grouped = set()
for sectionname, hdrgos in sec2d_hdrgos:
self._chk_hdrgoids(hdrgos)
hdrgos_all.update(hdrgos)
if sectionname != HdrgosSections.secdflt:
hdrgos_grouped.update(hdrgos)
sections_grouped.add(sectionname)
else:
hdrgos_ungrouped.update(hdrgos)
return {'G': hdrgos_grouped,
'S': sections_grouped,
'U': hdrgos_all.difference(hdrgos_grouped)} | python | def summarize_sec2hdrgos(self, sec2d_hdrgos):
"""Get counts of header GO IDs and sections."""
hdrgos_all = set([])
hdrgos_grouped = set()
hdrgos_ungrouped = set()
sections_grouped = set()
for sectionname, hdrgos in sec2d_hdrgos:
self._chk_hdrgoids(hdrgos)
hdrgos_all.update(hdrgos)
if sectionname != HdrgosSections.secdflt:
hdrgos_grouped.update(hdrgos)
sections_grouped.add(sectionname)
else:
hdrgos_ungrouped.update(hdrgos)
return {'G': hdrgos_grouped,
'S': sections_grouped,
'U': hdrgos_all.difference(hdrgos_grouped)} | [
"def",
"summarize_sec2hdrgos",
"(",
"self",
",",
"sec2d_hdrgos",
")",
":",
"hdrgos_all",
"=",
"set",
"(",
"[",
"]",
")",
"hdrgos_grouped",
"=",
"set",
"(",
")",
"hdrgos_ungrouped",
"=",
"set",
"(",
")",
"sections_grouped",
"=",
"set",
"(",
")",
"for",
"sectionname",
",",
"hdrgos",
"in",
"sec2d_hdrgos",
":",
"self",
".",
"_chk_hdrgoids",
"(",
"hdrgos",
")",
"hdrgos_all",
".",
"update",
"(",
"hdrgos",
")",
"if",
"sectionname",
"!=",
"HdrgosSections",
".",
"secdflt",
":",
"hdrgos_grouped",
".",
"update",
"(",
"hdrgos",
")",
"sections_grouped",
".",
"add",
"(",
"sectionname",
")",
"else",
":",
"hdrgos_ungrouped",
".",
"update",
"(",
"hdrgos",
")",
"return",
"{",
"'G'",
":",
"hdrgos_grouped",
",",
"'S'",
":",
"sections_grouped",
",",
"'U'",
":",
"hdrgos_all",
".",
"difference",
"(",
"hdrgos_grouped",
")",
"}"
] | Get counts of header GO IDs and sections. | [
"Get",
"counts",
"of",
"header",
"GO",
"IDs",
"and",
"sections",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/tasks.py#L12-L28 |
228,480 | tanghaibao/goatools | goatools/grouper/tasks.py | SummarySec2dHdrGos.summarize_sec2hdrnts | def summarize_sec2hdrnts(self, sec2d_hdrnts):
"""Given namedtuples in each sectin, get counts of header GO IDs and sections."""
sec2d_hdrgos = [(s, set(nt.GO for nt in nts)) for s, nts in sec2d_hdrnts]
return self.summarize_sec2hdrgos(sec2d_hdrgos) | python | def summarize_sec2hdrnts(self, sec2d_hdrnts):
"""Given namedtuples in each sectin, get counts of header GO IDs and sections."""
sec2d_hdrgos = [(s, set(nt.GO for nt in nts)) for s, nts in sec2d_hdrnts]
return self.summarize_sec2hdrgos(sec2d_hdrgos) | [
"def",
"summarize_sec2hdrnts",
"(",
"self",
",",
"sec2d_hdrnts",
")",
":",
"sec2d_hdrgos",
"=",
"[",
"(",
"s",
",",
"set",
"(",
"nt",
".",
"GO",
"for",
"nt",
"in",
"nts",
")",
")",
"for",
"s",
",",
"nts",
"in",
"sec2d_hdrnts",
"]",
"return",
"self",
".",
"summarize_sec2hdrgos",
"(",
"sec2d_hdrgos",
")"
] | Given namedtuples in each sectin, get counts of header GO IDs and sections. | [
"Given",
"namedtuples",
"in",
"each",
"sectin",
"get",
"counts",
"of",
"header",
"GO",
"IDs",
"and",
"sections",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/tasks.py#L30-L33 |
228,481 | tanghaibao/goatools | goatools/grouper/tasks.py | SummarySec2dHdrGos._chk_hdrgoids | def _chk_hdrgoids(hdrgos):
"""Check that hdrgo set is a set of GO IDs."""
goid = next(iter(hdrgos))
if isinstance(goid, str) and goid[:3] == "GO:":
return
assert False, "HDRGOS DO NOT CONTAIN GO IDs: {E}".format(E=goid) | python | def _chk_hdrgoids(hdrgos):
"""Check that hdrgo set is a set of GO IDs."""
goid = next(iter(hdrgos))
if isinstance(goid, str) and goid[:3] == "GO:":
return
assert False, "HDRGOS DO NOT CONTAIN GO IDs: {E}".format(E=goid) | [
"def",
"_chk_hdrgoids",
"(",
"hdrgos",
")",
":",
"goid",
"=",
"next",
"(",
"iter",
"(",
"hdrgos",
")",
")",
"if",
"isinstance",
"(",
"goid",
",",
"str",
")",
"and",
"goid",
"[",
":",
"3",
"]",
"==",
"\"GO:\"",
":",
"return",
"assert",
"False",
",",
"\"HDRGOS DO NOT CONTAIN GO IDs: {E}\"",
".",
"format",
"(",
"E",
"=",
"goid",
")"
] | Check that hdrgo set is a set of GO IDs. | [
"Check",
"that",
"hdrgo",
"set",
"is",
"a",
"set",
"of",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/tasks.py#L36-L41 |
228,482 | tanghaibao/goatools | goatools/go_search.py | GoSearch.get_matching_gos | def get_matching_gos(self, compiled_pattern, **kws):
"""Return all GOs which match the user regex pattern."""
# kws: prt gos
matching_gos = []
obo_dag = self.obo_dag
prt = kws['prt'] if 'prt' in kws else self.log
prt.write('\nPATTERN SEARCH: "{P}"\n'.format(P=compiled_pattern.pattern))
# Only look through GOs in annotation or user-specified GOs
srchgos = kws['gos'] if 'gos' in kws else self.go2items.keys()
for go_id in srchgos:
go_obj = obo_dag.get(go_id, None)
if go_obj is not None:
for hdr in self.goa_srch_hdrs:
if hdr in go_obj.__dict__:
fld_val = getattr(go_obj, hdr)
matches = self._search_vals(compiled_pattern, fld_val)
for mtch in matches:
prt.write("MATCH {go_id}({NAME}) {FLD}: {M}\n".format(
FLD=hdr, go_id=go_obj.id, NAME=go_obj.name, M=mtch))
if matches:
matching_gos.append(go_id)
else:
prt.write("**WARNING: {GO} found in annotation is not found in obo\n".format(
GO=go_id))
matching_gos = set(matching_gos)
# Print summary message
self._summary_matching_gos(prt, compiled_pattern.pattern, matching_gos, srchgos)
return matching_gos | python | def get_matching_gos(self, compiled_pattern, **kws):
"""Return all GOs which match the user regex pattern."""
# kws: prt gos
matching_gos = []
obo_dag = self.obo_dag
prt = kws['prt'] if 'prt' in kws else self.log
prt.write('\nPATTERN SEARCH: "{P}"\n'.format(P=compiled_pattern.pattern))
# Only look through GOs in annotation or user-specified GOs
srchgos = kws['gos'] if 'gos' in kws else self.go2items.keys()
for go_id in srchgos:
go_obj = obo_dag.get(go_id, None)
if go_obj is not None:
for hdr in self.goa_srch_hdrs:
if hdr in go_obj.__dict__:
fld_val = getattr(go_obj, hdr)
matches = self._search_vals(compiled_pattern, fld_val)
for mtch in matches:
prt.write("MATCH {go_id}({NAME}) {FLD}: {M}\n".format(
FLD=hdr, go_id=go_obj.id, NAME=go_obj.name, M=mtch))
if matches:
matching_gos.append(go_id)
else:
prt.write("**WARNING: {GO} found in annotation is not found in obo\n".format(
GO=go_id))
matching_gos = set(matching_gos)
# Print summary message
self._summary_matching_gos(prt, compiled_pattern.pattern, matching_gos, srchgos)
return matching_gos | [
"def",
"get_matching_gos",
"(",
"self",
",",
"compiled_pattern",
",",
"*",
"*",
"kws",
")",
":",
"# kws: prt gos",
"matching_gos",
"=",
"[",
"]",
"obo_dag",
"=",
"self",
".",
"obo_dag",
"prt",
"=",
"kws",
"[",
"'prt'",
"]",
"if",
"'prt'",
"in",
"kws",
"else",
"self",
".",
"log",
"prt",
".",
"write",
"(",
"'\\nPATTERN SEARCH: \"{P}\"\\n'",
".",
"format",
"(",
"P",
"=",
"compiled_pattern",
".",
"pattern",
")",
")",
"# Only look through GOs in annotation or user-specified GOs",
"srchgos",
"=",
"kws",
"[",
"'gos'",
"]",
"if",
"'gos'",
"in",
"kws",
"else",
"self",
".",
"go2items",
".",
"keys",
"(",
")",
"for",
"go_id",
"in",
"srchgos",
":",
"go_obj",
"=",
"obo_dag",
".",
"get",
"(",
"go_id",
",",
"None",
")",
"if",
"go_obj",
"is",
"not",
"None",
":",
"for",
"hdr",
"in",
"self",
".",
"goa_srch_hdrs",
":",
"if",
"hdr",
"in",
"go_obj",
".",
"__dict__",
":",
"fld_val",
"=",
"getattr",
"(",
"go_obj",
",",
"hdr",
")",
"matches",
"=",
"self",
".",
"_search_vals",
"(",
"compiled_pattern",
",",
"fld_val",
")",
"for",
"mtch",
"in",
"matches",
":",
"prt",
".",
"write",
"(",
"\"MATCH {go_id}({NAME}) {FLD}: {M}\\n\"",
".",
"format",
"(",
"FLD",
"=",
"hdr",
",",
"go_id",
"=",
"go_obj",
".",
"id",
",",
"NAME",
"=",
"go_obj",
".",
"name",
",",
"M",
"=",
"mtch",
")",
")",
"if",
"matches",
":",
"matching_gos",
".",
"append",
"(",
"go_id",
")",
"else",
":",
"prt",
".",
"write",
"(",
"\"**WARNING: {GO} found in annotation is not found in obo\\n\"",
".",
"format",
"(",
"GO",
"=",
"go_id",
")",
")",
"matching_gos",
"=",
"set",
"(",
"matching_gos",
")",
"# Print summary message",
"self",
".",
"_summary_matching_gos",
"(",
"prt",
",",
"compiled_pattern",
".",
"pattern",
",",
"matching_gos",
",",
"srchgos",
")",
"return",
"matching_gos"
] | Return all GOs which match the user regex pattern. | [
"Return",
"all",
"GOs",
"which",
"match",
"the",
"user",
"regex",
"pattern",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L20-L47 |
228,483 | tanghaibao/goatools | goatools/go_search.py | GoSearch._summary_matching_gos | def _summary_matching_gos(prt, pattern, matching_gos, all_gos):
"""Print summary for get_matching_gos."""
msg = 'Found {N} GO(s) out of {M} matching pattern("{P}")\n'
num_gos = len(matching_gos)
num_all = len(all_gos)
prt.write(msg.format(N=num_gos, M=num_all, P=pattern)) | python | def _summary_matching_gos(prt, pattern, matching_gos, all_gos):
"""Print summary for get_matching_gos."""
msg = 'Found {N} GO(s) out of {M} matching pattern("{P}")\n'
num_gos = len(matching_gos)
num_all = len(all_gos)
prt.write(msg.format(N=num_gos, M=num_all, P=pattern)) | [
"def",
"_summary_matching_gos",
"(",
"prt",
",",
"pattern",
",",
"matching_gos",
",",
"all_gos",
")",
":",
"msg",
"=",
"'Found {N} GO(s) out of {M} matching pattern(\"{P}\")\\n'",
"num_gos",
"=",
"len",
"(",
"matching_gos",
")",
"num_all",
"=",
"len",
"(",
"all_gos",
")",
"prt",
".",
"write",
"(",
"msg",
".",
"format",
"(",
"N",
"=",
"num_gos",
",",
"M",
"=",
"num_all",
",",
"P",
"=",
"pattern",
")",
")"
] | Print summary for get_matching_gos. | [
"Print",
"summary",
"for",
"get_matching_gos",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L50-L55 |
228,484 | tanghaibao/goatools | goatools/go_search.py | GoSearch._search_vals | def _search_vals(self, compiled_pattern, fld_val):
"""Search for user-regex in scalar or iterable data values."""
matches = []
if isinstance(fld_val, set):
for val in fld_val:
self._search_val(matches, compiled_pattern, val)
elif isinstance(fld_val, str):
self._search_val(matches, compiled_pattern, fld_val)
return matches | python | def _search_vals(self, compiled_pattern, fld_val):
"""Search for user-regex in scalar or iterable data values."""
matches = []
if isinstance(fld_val, set):
for val in fld_val:
self._search_val(matches, compiled_pattern, val)
elif isinstance(fld_val, str):
self._search_val(matches, compiled_pattern, fld_val)
return matches | [
"def",
"_search_vals",
"(",
"self",
",",
"compiled_pattern",
",",
"fld_val",
")",
":",
"matches",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"fld_val",
",",
"set",
")",
":",
"for",
"val",
"in",
"fld_val",
":",
"self",
".",
"_search_val",
"(",
"matches",
",",
"compiled_pattern",
",",
"val",
")",
"elif",
"isinstance",
"(",
"fld_val",
",",
"str",
")",
":",
"self",
".",
"_search_val",
"(",
"matches",
",",
"compiled_pattern",
",",
"fld_val",
")",
"return",
"matches"
] | Search for user-regex in scalar or iterable data values. | [
"Search",
"for",
"user",
"-",
"regex",
"in",
"scalar",
"or",
"iterable",
"data",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L57-L65 |
228,485 | tanghaibao/goatools | goatools/go_search.py | GoSearch._search_val | def _search_val(matches, compiled_pattern, fld_val):
"""Search for user-regex in scalar data values."""
mtch = compiled_pattern.search(fld_val)
if mtch:
matches.append(fld_val) | python | def _search_val(matches, compiled_pattern, fld_val):
"""Search for user-regex in scalar data values."""
mtch = compiled_pattern.search(fld_val)
if mtch:
matches.append(fld_val) | [
"def",
"_search_val",
"(",
"matches",
",",
"compiled_pattern",
",",
"fld_val",
")",
":",
"mtch",
"=",
"compiled_pattern",
".",
"search",
"(",
"fld_val",
")",
"if",
"mtch",
":",
"matches",
".",
"append",
"(",
"fld_val",
")"
] | Search for user-regex in scalar data values. | [
"Search",
"for",
"user",
"-",
"regex",
"in",
"scalar",
"data",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L68-L72 |
228,486 | tanghaibao/goatools | goatools/go_search.py | GoSearch.add_children_gos | def add_children_gos(self, gos):
"""Return children of input gos plus input gos."""
lst = []
obo_dag = self.obo_dag
get_children = lambda go_obj: list(go_obj.get_all_children()) + [go_obj.id]
for go_id in gos:
go_obj = obo_dag[go_id]
lst.extend(get_children(go_obj))
return set(lst) | python | def add_children_gos(self, gos):
"""Return children of input gos plus input gos."""
lst = []
obo_dag = self.obo_dag
get_children = lambda go_obj: list(go_obj.get_all_children()) + [go_obj.id]
for go_id in gos:
go_obj = obo_dag[go_id]
lst.extend(get_children(go_obj))
return set(lst) | [
"def",
"add_children_gos",
"(",
"self",
",",
"gos",
")",
":",
"lst",
"=",
"[",
"]",
"obo_dag",
"=",
"self",
".",
"obo_dag",
"get_children",
"=",
"lambda",
"go_obj",
":",
"list",
"(",
"go_obj",
".",
"get_all_children",
"(",
")",
")",
"+",
"[",
"go_obj",
".",
"id",
"]",
"for",
"go_id",
"in",
"gos",
":",
"go_obj",
"=",
"obo_dag",
"[",
"go_id",
"]",
"lst",
".",
"extend",
"(",
"get_children",
"(",
"go_obj",
")",
")",
"return",
"set",
"(",
"lst",
")"
] | Return children of input gos plus input gos. | [
"Return",
"children",
"of",
"input",
"gos",
"plus",
"input",
"gos",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L74-L82 |
228,487 | tanghaibao/goatools | goatools/go_search.py | GoSearch.get_items | def get_items(self, gos):
"""Given GO terms, return genes or gene products for the GOs."""
items = []
for go_id in gos:
items.extend(self.go2items.get(go_id, []))
return set(items) | python | def get_items(self, gos):
"""Given GO terms, return genes or gene products for the GOs."""
items = []
for go_id in gos:
items.extend(self.go2items.get(go_id, []))
return set(items) | [
"def",
"get_items",
"(",
"self",
",",
"gos",
")",
":",
"items",
"=",
"[",
"]",
"for",
"go_id",
"in",
"gos",
":",
"items",
".",
"extend",
"(",
"self",
".",
"go2items",
".",
"get",
"(",
"go_id",
",",
"[",
"]",
")",
")",
"return",
"set",
"(",
"items",
")"
] | Given GO terms, return genes or gene products for the GOs. | [
"Given",
"GO",
"terms",
"return",
"genes",
"or",
"gene",
"products",
"for",
"the",
"GOs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L84-L89 |
228,488 | tanghaibao/goatools | goatools/gosubdag/plot/goea_results.py | GoeaResults.prt_summary | def prt_summary(self, prt=sys.stdout):
"""Print summary of GOEA plotting object."""
desc = "NtGoeaResults" if self.is_goterm else "namedtuple"
prt.write("{N} GOEA results from {O}. P-values stored in {P}.\n".format(
N=len(self.go2res), O=desc, P=self.pval_name)) | python | def prt_summary(self, prt=sys.stdout):
"""Print summary of GOEA plotting object."""
desc = "NtGoeaResults" if self.is_goterm else "namedtuple"
prt.write("{N} GOEA results from {O}. P-values stored in {P}.\n".format(
N=len(self.go2res), O=desc, P=self.pval_name)) | [
"def",
"prt_summary",
"(",
"self",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"desc",
"=",
"\"NtGoeaResults\"",
"if",
"self",
".",
"is_goterm",
"else",
"\"namedtuple\"",
"prt",
".",
"write",
"(",
"\"{N} GOEA results from {O}. P-values stored in {P}.\\n\"",
".",
"format",
"(",
"N",
"=",
"len",
"(",
"self",
".",
"go2res",
")",
",",
"O",
"=",
"desc",
",",
"P",
"=",
"self",
".",
"pval_name",
")",
")"
] | Print summary of GOEA plotting object. | [
"Print",
"summary",
"of",
"GOEA",
"plotting",
"object",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/goea_results.py#L40-L44 |
228,489 | tanghaibao/goatools | goatools/gosubdag/plot/goea_results.py | GoeaResults.set_goid2color_pval | def set_goid2color_pval(self, goid2color):
"""Fill missing colors based on p-value of an enriched GO term."""
alpha2col = self.alpha2col
if self.pval_name is not None:
pval_name = self.pval_name
for goid, res in self.go2res.items():
pval = getattr(res, pval_name, None)
if pval is not None:
for alpha, color in alpha2col.items():
if pval <= alpha and res.study_count != 0:
if goid not in goid2color:
goid2color[goid] = color | python | def set_goid2color_pval(self, goid2color):
"""Fill missing colors based on p-value of an enriched GO term."""
alpha2col = self.alpha2col
if self.pval_name is not None:
pval_name = self.pval_name
for goid, res in self.go2res.items():
pval = getattr(res, pval_name, None)
if pval is not None:
for alpha, color in alpha2col.items():
if pval <= alpha and res.study_count != 0:
if goid not in goid2color:
goid2color[goid] = color | [
"def",
"set_goid2color_pval",
"(",
"self",
",",
"goid2color",
")",
":",
"alpha2col",
"=",
"self",
".",
"alpha2col",
"if",
"self",
".",
"pval_name",
"is",
"not",
"None",
":",
"pval_name",
"=",
"self",
".",
"pval_name",
"for",
"goid",
",",
"res",
"in",
"self",
".",
"go2res",
".",
"items",
"(",
")",
":",
"pval",
"=",
"getattr",
"(",
"res",
",",
"pval_name",
",",
"None",
")",
"if",
"pval",
"is",
"not",
"None",
":",
"for",
"alpha",
",",
"color",
"in",
"alpha2col",
".",
"items",
"(",
")",
":",
"if",
"pval",
"<=",
"alpha",
"and",
"res",
".",
"study_count",
"!=",
"0",
":",
"if",
"goid",
"not",
"in",
"goid2color",
":",
"goid2color",
"[",
"goid",
"]",
"=",
"color"
] | Fill missing colors based on p-value of an enriched GO term. | [
"Fill",
"missing",
"colors",
"based",
"on",
"p",
"-",
"value",
"of",
"an",
"enriched",
"GO",
"term",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/goea_results.py#L55-L66 |
228,490 | tanghaibao/goatools | goatools/gosubdag/plot/goea_results.py | GoeaResults.get_goid2color_pval | def get_goid2color_pval(self):
"""Return a go2color dict containing GO colors determined by P-value."""
go2color = {}
self.set_goid2color_pval(go2color)
color_dflt = self.alpha2col[1.000]
for goid in self.go2res:
if goid not in go2color:
go2color[goid] = color_dflt
return go2color | python | def get_goid2color_pval(self):
"""Return a go2color dict containing GO colors determined by P-value."""
go2color = {}
self.set_goid2color_pval(go2color)
color_dflt = self.alpha2col[1.000]
for goid in self.go2res:
if goid not in go2color:
go2color[goid] = color_dflt
return go2color | [
"def",
"get_goid2color_pval",
"(",
"self",
")",
":",
"go2color",
"=",
"{",
"}",
"self",
".",
"set_goid2color_pval",
"(",
"go2color",
")",
"color_dflt",
"=",
"self",
".",
"alpha2col",
"[",
"1.000",
"]",
"for",
"goid",
"in",
"self",
".",
"go2res",
":",
"if",
"goid",
"not",
"in",
"go2color",
":",
"go2color",
"[",
"goid",
"]",
"=",
"color_dflt",
"return",
"go2color"
] | Return a go2color dict containing GO colors determined by P-value. | [
"Return",
"a",
"go2color",
"dict",
"containing",
"GO",
"colors",
"determined",
"by",
"P",
"-",
"value",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/goea_results.py#L68-L76 |
228,491 | tanghaibao/goatools | goatools/rpt/rpt_lev_depth.py | RptLevDepth.prttex_summary_cnts_all | def prttex_summary_cnts_all(self, prt=sys.stdout):
"""Print LaTeX format summary of level and depth counts for all active GO Terms."""
cnts = self.get_cnts_levels_depths_recs(set(self.obo.values()))
self._prttex_summary_cnts(prt, cnts) | python | def prttex_summary_cnts_all(self, prt=sys.stdout):
"""Print LaTeX format summary of level and depth counts for all active GO Terms."""
cnts = self.get_cnts_levels_depths_recs(set(self.obo.values()))
self._prttex_summary_cnts(prt, cnts) | [
"def",
"prttex_summary_cnts_all",
"(",
"self",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"cnts",
"=",
"self",
".",
"get_cnts_levels_depths_recs",
"(",
"set",
"(",
"self",
".",
"obo",
".",
"values",
"(",
")",
")",
")",
"self",
".",
"_prttex_summary_cnts",
"(",
"prt",
",",
"cnts",
")"
] | Print LaTeX format summary of level and depth counts for all active GO Terms. | [
"Print",
"LaTeX",
"format",
"summary",
"of",
"level",
"and",
"depth",
"counts",
"for",
"all",
"active",
"GO",
"Terms",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L82-L85 |
228,492 | tanghaibao/goatools | goatools/rpt/rpt_lev_depth.py | RptLevDepth.write_summary_cnts_all | def write_summary_cnts_all(self):
"""Write summary of level and depth counts for all active GO Terms."""
cnts = self.get_cnts_levels_depths_recs(set(self.obo.values()))
self._write_summary_cnts(cnts) | python | def write_summary_cnts_all(self):
"""Write summary of level and depth counts for all active GO Terms."""
cnts = self.get_cnts_levels_depths_recs(set(self.obo.values()))
self._write_summary_cnts(cnts) | [
"def",
"write_summary_cnts_all",
"(",
"self",
")",
":",
"cnts",
"=",
"self",
".",
"get_cnts_levels_depths_recs",
"(",
"set",
"(",
"self",
".",
"obo",
".",
"values",
"(",
")",
")",
")",
"self",
".",
"_write_summary_cnts",
"(",
"cnts",
")"
] | Write summary of level and depth counts for all active GO Terms. | [
"Write",
"summary",
"of",
"level",
"and",
"depth",
"counts",
"for",
"all",
"active",
"GO",
"Terms",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L87-L90 |
228,493 | tanghaibao/goatools | goatools/rpt/rpt_lev_depth.py | RptLevDepth.write_summary_cnts | def write_summary_cnts(self, go_ids):
"""Write summary of level and depth counts for specific GO ids."""
obo = self.obo
cnts = self.get_cnts_levels_depths_recs([obo.get(GO) for GO in go_ids])
self._write_summary_cnts(cnts) | python | def write_summary_cnts(self, go_ids):
"""Write summary of level and depth counts for specific GO ids."""
obo = self.obo
cnts = self.get_cnts_levels_depths_recs([obo.get(GO) for GO in go_ids])
self._write_summary_cnts(cnts) | [
"def",
"write_summary_cnts",
"(",
"self",
",",
"go_ids",
")",
":",
"obo",
"=",
"self",
".",
"obo",
"cnts",
"=",
"self",
".",
"get_cnts_levels_depths_recs",
"(",
"[",
"obo",
".",
"get",
"(",
"GO",
")",
"for",
"GO",
"in",
"go_ids",
"]",
")",
"self",
".",
"_write_summary_cnts",
"(",
"cnts",
")"
] | Write summary of level and depth counts for specific GO ids. | [
"Write",
"summary",
"of",
"level",
"and",
"depth",
"counts",
"for",
"specific",
"GO",
"ids",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L92-L96 |
228,494 | tanghaibao/goatools | goatools/rpt/rpt_lev_depth.py | RptLevDepth.get_cnts_levels_depths_recs | def get_cnts_levels_depths_recs(recs):
"""Collect counts of levels and depths in a Group of GO Terms."""
cnts = cx.defaultdict(lambda: cx.defaultdict(cx.Counter))
for rec in recs:
if rec is not None and not rec.is_obsolete:
cnts['level'][rec.level][rec.namespace] += 1
cnts['depth'][rec.depth][rec.namespace] += 1
return cnts | python | def get_cnts_levels_depths_recs(recs):
"""Collect counts of levels and depths in a Group of GO Terms."""
cnts = cx.defaultdict(lambda: cx.defaultdict(cx.Counter))
for rec in recs:
if rec is not None and not rec.is_obsolete:
cnts['level'][rec.level][rec.namespace] += 1
cnts['depth'][rec.depth][rec.namespace] += 1
return cnts | [
"def",
"get_cnts_levels_depths_recs",
"(",
"recs",
")",
":",
"cnts",
"=",
"cx",
".",
"defaultdict",
"(",
"lambda",
":",
"cx",
".",
"defaultdict",
"(",
"cx",
".",
"Counter",
")",
")",
"for",
"rec",
"in",
"recs",
":",
"if",
"rec",
"is",
"not",
"None",
"and",
"not",
"rec",
".",
"is_obsolete",
":",
"cnts",
"[",
"'level'",
"]",
"[",
"rec",
".",
"level",
"]",
"[",
"rec",
".",
"namespace",
"]",
"+=",
"1",
"cnts",
"[",
"'depth'",
"]",
"[",
"rec",
".",
"depth",
"]",
"[",
"rec",
".",
"namespace",
"]",
"+=",
"1",
"return",
"cnts"
] | Collect counts of levels and depths in a Group of GO Terms. | [
"Collect",
"counts",
"of",
"levels",
"and",
"depths",
"in",
"a",
"Group",
"of",
"GO",
"Terms",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L149-L156 |
228,495 | tanghaibao/goatools | goatools/rpt/rpt_lev_depth.py | RptLevDepth.get_data | def get_data(self):
"""Collect counts of GO terms at all levels and depths."""
# Count level(shortest path to root) and depth(longest path to root)
# values for all unique GO Terms.
data = []
ntobj = cx.namedtuple("NtGoCnt", "Depth_Level BP_D MF_D CC_D BP_L MF_L CC_L")
cnts = self.get_cnts_levels_depths_recs(set(self.obo.values()))
max_val = max(max(dep for dep in cnts['depth']), max(lev for lev in cnts['level']))
for i in range(max_val+1):
vals = [i] + [cnts[desc][i][ns] for desc in cnts for ns in self.nss]
data.append(ntobj._make(vals))
return data | python | def get_data(self):
"""Collect counts of GO terms at all levels and depths."""
# Count level(shortest path to root) and depth(longest path to root)
# values for all unique GO Terms.
data = []
ntobj = cx.namedtuple("NtGoCnt", "Depth_Level BP_D MF_D CC_D BP_L MF_L CC_L")
cnts = self.get_cnts_levels_depths_recs(set(self.obo.values()))
max_val = max(max(dep for dep in cnts['depth']), max(lev for lev in cnts['level']))
for i in range(max_val+1):
vals = [i] + [cnts[desc][i][ns] for desc in cnts for ns in self.nss]
data.append(ntobj._make(vals))
return data | [
"def",
"get_data",
"(",
"self",
")",
":",
"# Count level(shortest path to root) and depth(longest path to root)",
"# values for all unique GO Terms.",
"data",
"=",
"[",
"]",
"ntobj",
"=",
"cx",
".",
"namedtuple",
"(",
"\"NtGoCnt\"",
",",
"\"Depth_Level BP_D MF_D CC_D BP_L MF_L CC_L\"",
")",
"cnts",
"=",
"self",
".",
"get_cnts_levels_depths_recs",
"(",
"set",
"(",
"self",
".",
"obo",
".",
"values",
"(",
")",
")",
")",
"max_val",
"=",
"max",
"(",
"max",
"(",
"dep",
"for",
"dep",
"in",
"cnts",
"[",
"'depth'",
"]",
")",
",",
"max",
"(",
"lev",
"for",
"lev",
"in",
"cnts",
"[",
"'level'",
"]",
")",
")",
"for",
"i",
"in",
"range",
"(",
"max_val",
"+",
"1",
")",
":",
"vals",
"=",
"[",
"i",
"]",
"+",
"[",
"cnts",
"[",
"desc",
"]",
"[",
"i",
"]",
"[",
"ns",
"]",
"for",
"desc",
"in",
"cnts",
"for",
"ns",
"in",
"self",
".",
"nss",
"]",
"data",
".",
"append",
"(",
"ntobj",
".",
"_make",
"(",
"vals",
")",
")",
"return",
"data"
] | Collect counts of GO terms at all levels and depths. | [
"Collect",
"counts",
"of",
"GO",
"terms",
"at",
"all",
"levels",
"and",
"depths",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/rpt_lev_depth.py#L158-L169 |
228,496 | tanghaibao/goatools | scripts/find_enrichment.py | main | def main():
"""Run gene enrichment analysis."""
# Load study, population, associations, and GoDag. Run GOEA.
obj = GoeaCliFnc(GoeaCliArgs().args)
# Reduce results to significant results (pval<value)
results_specified = obj.get_results()
# Print results in a flat list
obj.prt_results(results_specified) | python | def main():
"""Run gene enrichment analysis."""
# Load study, population, associations, and GoDag. Run GOEA.
obj = GoeaCliFnc(GoeaCliArgs().args)
# Reduce results to significant results (pval<value)
results_specified = obj.get_results()
# Print results in a flat list
obj.prt_results(results_specified) | [
"def",
"main",
"(",
")",
":",
"# Load study, population, associations, and GoDag. Run GOEA.",
"obj",
"=",
"GoeaCliFnc",
"(",
"GoeaCliArgs",
"(",
")",
".",
"args",
")",
"# Reduce results to significant results (pval<value)",
"results_specified",
"=",
"obj",
".",
"get_results",
"(",
")",
"# Print results in a flat list",
"obj",
".",
"prt_results",
"(",
"results_specified",
")"
] | Run gene enrichment analysis. | [
"Run",
"gene",
"enrichment",
"analysis",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/scripts/find_enrichment.py#L28-L35 |
228,497 | tanghaibao/goatools | goatools/anno/factory.py | get_objanno | def get_objanno(fin_anno, anno_type=None, **kws):
"""Read annotations in GAF, GPAD, Entrez gene2go, or text format."""
# kws get_objanno: taxids hdr_only prt allow_missing_symbol
anno_type = get_anno_desc(fin_anno, anno_type)
if anno_type is not None:
if anno_type == 'gene2go':
# kws: taxid taxids
return Gene2GoReader(fin_anno, **kws)
if anno_type == 'gaf':
return GafReader(fin_anno,
hdr_only=kws.get('hdr_only', False),
prt=kws.get('prt', sys.stdout),
allow_missing_symbol=kws.get('allow_missing_symbol', False))
if anno_type == 'gpad':
hdr_only = kws.get('hdr_only', False)
return GpadReader(fin_anno, hdr_only)
if anno_type == 'id2gos':
return IdToGosReader(fin_anno)
raise RuntimeError('UNEXPECTED ANNOTATION FILE FORMAT: {F} {D}'.format(
F=fin_anno, D=anno_type)) | python | def get_objanno(fin_anno, anno_type=None, **kws):
"""Read annotations in GAF, GPAD, Entrez gene2go, or text format."""
# kws get_objanno: taxids hdr_only prt allow_missing_symbol
anno_type = get_anno_desc(fin_anno, anno_type)
if anno_type is not None:
if anno_type == 'gene2go':
# kws: taxid taxids
return Gene2GoReader(fin_anno, **kws)
if anno_type == 'gaf':
return GafReader(fin_anno,
hdr_only=kws.get('hdr_only', False),
prt=kws.get('prt', sys.stdout),
allow_missing_symbol=kws.get('allow_missing_symbol', False))
if anno_type == 'gpad':
hdr_only = kws.get('hdr_only', False)
return GpadReader(fin_anno, hdr_only)
if anno_type == 'id2gos':
return IdToGosReader(fin_anno)
raise RuntimeError('UNEXPECTED ANNOTATION FILE FORMAT: {F} {D}'.format(
F=fin_anno, D=anno_type)) | [
"def",
"get_objanno",
"(",
"fin_anno",
",",
"anno_type",
"=",
"None",
",",
"*",
"*",
"kws",
")",
":",
"# kws get_objanno: taxids hdr_only prt allow_missing_symbol",
"anno_type",
"=",
"get_anno_desc",
"(",
"fin_anno",
",",
"anno_type",
")",
"if",
"anno_type",
"is",
"not",
"None",
":",
"if",
"anno_type",
"==",
"'gene2go'",
":",
"# kws: taxid taxids",
"return",
"Gene2GoReader",
"(",
"fin_anno",
",",
"*",
"*",
"kws",
")",
"if",
"anno_type",
"==",
"'gaf'",
":",
"return",
"GafReader",
"(",
"fin_anno",
",",
"hdr_only",
"=",
"kws",
".",
"get",
"(",
"'hdr_only'",
",",
"False",
")",
",",
"prt",
"=",
"kws",
".",
"get",
"(",
"'prt'",
",",
"sys",
".",
"stdout",
")",
",",
"allow_missing_symbol",
"=",
"kws",
".",
"get",
"(",
"'allow_missing_symbol'",
",",
"False",
")",
")",
"if",
"anno_type",
"==",
"'gpad'",
":",
"hdr_only",
"=",
"kws",
".",
"get",
"(",
"'hdr_only'",
",",
"False",
")",
"return",
"GpadReader",
"(",
"fin_anno",
",",
"hdr_only",
")",
"if",
"anno_type",
"==",
"'id2gos'",
":",
"return",
"IdToGosReader",
"(",
"fin_anno",
")",
"raise",
"RuntimeError",
"(",
"'UNEXPECTED ANNOTATION FILE FORMAT: {F} {D}'",
".",
"format",
"(",
"F",
"=",
"fin_anno",
",",
"D",
"=",
"anno_type",
")",
")"
] | Read annotations in GAF, GPAD, Entrez gene2go, or text format. | [
"Read",
"annotations",
"in",
"GAF",
"GPAD",
"Entrez",
"gene2go",
"or",
"text",
"format",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/factory.py#L13-L32 |
228,498 | tanghaibao/goatools | goatools/anno/gpad_reader.py | GpadReader.get_relation_cnt | def get_relation_cnt(self):
"""Return a Counter containing all relations contained in the Annotation Extensions."""
ctr = cx.Counter()
for ntgpad in self.associations:
if ntgpad.Extension is not None:
ctr += ntgpad.Extension.get_relations_cnt()
return ctr | python | def get_relation_cnt(self):
"""Return a Counter containing all relations contained in the Annotation Extensions."""
ctr = cx.Counter()
for ntgpad in self.associations:
if ntgpad.Extension is not None:
ctr += ntgpad.Extension.get_relations_cnt()
return ctr | [
"def",
"get_relation_cnt",
"(",
"self",
")",
":",
"ctr",
"=",
"cx",
".",
"Counter",
"(",
")",
"for",
"ntgpad",
"in",
"self",
".",
"associations",
":",
"if",
"ntgpad",
".",
"Extension",
"is",
"not",
"None",
":",
"ctr",
"+=",
"ntgpad",
".",
"Extension",
".",
"get_relations_cnt",
"(",
")",
"return",
"ctr"
] | Return a Counter containing all relations contained in the Annotation Extensions. | [
"Return",
"a",
"Counter",
"containing",
"all",
"relations",
"contained",
"in",
"the",
"Annotation",
"Extensions",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/gpad_reader.py#L24-L30 |
228,499 | tanghaibao/goatools | goatools/cli/find_enrichment.py | GoeaCliFnc._get_id2gos | def _get_id2gos(self):
"""Return annotations as id2gos"""
kws = {}
if self.args.ev_inc is not None:
kws['ev_include'] = set(self.args.ev_inc.split(','))
if self.args.ev_exc is not None:
kws['ev_exclude'] = set(self.args.ev_exc.split(','))
return self.objanno.get_id2gos(**kws) | python | def _get_id2gos(self):
"""Return annotations as id2gos"""
kws = {}
if self.args.ev_inc is not None:
kws['ev_include'] = set(self.args.ev_inc.split(','))
if self.args.ev_exc is not None:
kws['ev_exclude'] = set(self.args.ev_exc.split(','))
return self.objanno.get_id2gos(**kws) | [
"def",
"_get_id2gos",
"(",
"self",
")",
":",
"kws",
"=",
"{",
"}",
"if",
"self",
".",
"args",
".",
"ev_inc",
"is",
"not",
"None",
":",
"kws",
"[",
"'ev_include'",
"]",
"=",
"set",
"(",
"self",
".",
"args",
".",
"ev_inc",
".",
"split",
"(",
"','",
")",
")",
"if",
"self",
".",
"args",
".",
"ev_exc",
"is",
"not",
"None",
":",
"kws",
"[",
"'ev_exclude'",
"]",
"=",
"set",
"(",
"self",
".",
"args",
".",
"ev_exc",
".",
"split",
"(",
"','",
")",
")",
"return",
"self",
".",
"objanno",
".",
"get_id2gos",
"(",
"*",
"*",
"kws",
")"
] | Return annotations as id2gos | [
"Return",
"annotations",
"as",
"id2gos"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L182-L189 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.