repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1 value | code stringlengths 75 19.8k | code_tokens listlengths 20 707 | docstring stringlengths 3 17.3k | docstring_tokens listlengths 3 222 | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1 value | idx int64 0 252k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
tanghaibao/goatools | goatools/base.py | ftp_get | def ftp_get(fin_src, fout):
"""Download a file from an ftp server"""
assert fin_src[:6] == 'ftp://', fin_src
dir_full, fin_ftp = os.path.split(fin_src[6:])
pt0 = dir_full.find('/')
assert pt0 != -1, pt0
ftphost = dir_full[:pt0]
chg_dir = dir_full[pt0+1:]
print('FTP RETR {HOST} {DIR} {SRC} -> {DST}'.format(
HOST=ftphost, DIR=chg_dir, SRC=fin_ftp, DST=fout))
ftp = FTP(ftphost) # connect to host, default port ftp.ncbi.nlm.nih.gov
ftp.login() # user anonymous, passwd anonymous@
ftp.cwd(chg_dir) # change into "debian" directory gene/DATA
cmd = 'RETR {F}'.format(F=fin_ftp) # gene2go.gz
ftp.retrbinary(cmd, open(fout, 'wb').write) # /usr/home/gene2go.gz
ftp.quit() | python | def ftp_get(fin_src, fout):
"""Download a file from an ftp server"""
assert fin_src[:6] == 'ftp://', fin_src
dir_full, fin_ftp = os.path.split(fin_src[6:])
pt0 = dir_full.find('/')
assert pt0 != -1, pt0
ftphost = dir_full[:pt0]
chg_dir = dir_full[pt0+1:]
print('FTP RETR {HOST} {DIR} {SRC} -> {DST}'.format(
HOST=ftphost, DIR=chg_dir, SRC=fin_ftp, DST=fout))
ftp = FTP(ftphost) # connect to host, default port ftp.ncbi.nlm.nih.gov
ftp.login() # user anonymous, passwd anonymous@
ftp.cwd(chg_dir) # change into "debian" directory gene/DATA
cmd = 'RETR {F}'.format(F=fin_ftp) # gene2go.gz
ftp.retrbinary(cmd, open(fout, 'wb').write) # /usr/home/gene2go.gz
ftp.quit() | [
"def",
"ftp_get",
"(",
"fin_src",
",",
"fout",
")",
":",
"assert",
"fin_src",
"[",
":",
"6",
"]",
"==",
"'ftp://'",
",",
"fin_src",
"dir_full",
",",
"fin_ftp",
"=",
"os",
".",
"path",
".",
"split",
"(",
"fin_src",
"[",
"6",
":",
"]",
")",
"pt0",
... | Download a file from an ftp server | [
"Download",
"a",
"file",
"from",
"an",
"ftp",
"server"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L189-L204 | train | 223,500 |
tanghaibao/goatools | goatools/base.py | dnld_file | def dnld_file(src_ftp, dst_file, prt=sys.stdout, loading_bar=True):
"""Download specified file if necessary."""
if os.path.isfile(dst_file):
return
do_gunzip = src_ftp[-3:] == '.gz' and dst_file[-3:] != '.gz'
dst_wget = "{DST}.gz".format(DST=dst_file) if do_gunzip else dst_file
# Write to stderr, not stdout so this message will be seen when running nosetests
wget_msg = "wget({SRC} out={DST})\n".format(SRC=src_ftp, DST=dst_wget)
#### sys.stderr.write(" {WGET}".format(WGET=wget_msg))
#### if loading_bar:
#### loading_bar = wget.bar_adaptive
try:
#### wget.download(src_ftp, out=dst_wget, bar=loading_bar)
rsp = http_get(src_ftp, dst_wget) if src_ftp[:4] == 'http' else ftp_get(src_ftp, dst_wget)
if do_gunzip:
if prt is not None:
prt.write(" gunzip {FILE}\n".format(FILE=dst_wget))
gzip_open_to(dst_wget, dst_file)
except IOError as errmsg:
import traceback
traceback.print_exc()
sys.stderr.write("**FATAL cmd: {WGET}".format(WGET=wget_msg))
sys.stderr.write("**FATAL msg: {ERR}".format(ERR=str(errmsg)))
sys.exit(1) | python | def dnld_file(src_ftp, dst_file, prt=sys.stdout, loading_bar=True):
"""Download specified file if necessary."""
if os.path.isfile(dst_file):
return
do_gunzip = src_ftp[-3:] == '.gz' and dst_file[-3:] != '.gz'
dst_wget = "{DST}.gz".format(DST=dst_file) if do_gunzip else dst_file
# Write to stderr, not stdout so this message will be seen when running nosetests
wget_msg = "wget({SRC} out={DST})\n".format(SRC=src_ftp, DST=dst_wget)
#### sys.stderr.write(" {WGET}".format(WGET=wget_msg))
#### if loading_bar:
#### loading_bar = wget.bar_adaptive
try:
#### wget.download(src_ftp, out=dst_wget, bar=loading_bar)
rsp = http_get(src_ftp, dst_wget) if src_ftp[:4] == 'http' else ftp_get(src_ftp, dst_wget)
if do_gunzip:
if prt is not None:
prt.write(" gunzip {FILE}\n".format(FILE=dst_wget))
gzip_open_to(dst_wget, dst_file)
except IOError as errmsg:
import traceback
traceback.print_exc()
sys.stderr.write("**FATAL cmd: {WGET}".format(WGET=wget_msg))
sys.stderr.write("**FATAL msg: {ERR}".format(ERR=str(errmsg)))
sys.exit(1) | [
"def",
"dnld_file",
"(",
"src_ftp",
",",
"dst_file",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"loading_bar",
"=",
"True",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"dst_file",
")",
":",
"return",
"do_gunzip",
"=",
"src_ftp",
"[",
"-",... | Download specified file if necessary. | [
"Download",
"specified",
"file",
"if",
"necessary",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/base.py#L207-L230 | train | 223,501 |
tanghaibao/goatools | goatools/godag/obo_optional_attributes.py | OboOptionalAttrs.init_datamembers | def init_datamembers(self, rec):
"""Initialize current GOTerm with data members for storing optional attributes."""
# pylint: disable=multiple-statements
if 'synonym' in self.optional_attrs: rec.synonym = []
if 'xref' in self.optional_attrs: rec.xref = set()
if 'subset' in self.optional_attrs: rec.subset = set()
if 'comment' in self.optional_attrs: rec.comment = ""
if 'relationship' in self.optional_attrs:
rec.relationship = {}
rec.relationship_rev = {} | python | def init_datamembers(self, rec):
"""Initialize current GOTerm with data members for storing optional attributes."""
# pylint: disable=multiple-statements
if 'synonym' in self.optional_attrs: rec.synonym = []
if 'xref' in self.optional_attrs: rec.xref = set()
if 'subset' in self.optional_attrs: rec.subset = set()
if 'comment' in self.optional_attrs: rec.comment = ""
if 'relationship' in self.optional_attrs:
rec.relationship = {}
rec.relationship_rev = {} | [
"def",
"init_datamembers",
"(",
"self",
",",
"rec",
")",
":",
"# pylint: disable=multiple-statements",
"if",
"'synonym'",
"in",
"self",
".",
"optional_attrs",
":",
"rec",
".",
"synonym",
"=",
"[",
"]",
"if",
"'xref'",
"in",
"self",
".",
"optional_attrs",
":",
... | Initialize current GOTerm with data members for storing optional attributes. | [
"Initialize",
"current",
"GOTerm",
"with",
"data",
"members",
"for",
"storing",
"optional",
"attributes",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/obo_optional_attributes.py#L51-L60 | train | 223,502 |
tanghaibao/goatools | goatools/godag/obo_optional_attributes.py | OboOptionalAttrs._get_synonym | def _get_synonym(self, line):
"""Given line, return optional attribute synonym value in a namedtuple.
Example synonym and its storage in a namedtuple:
synonym: "The other white meat" EXACT MARKETING_SLOGAN [MEAT:00324, BACONBASE:03021]
text: "The other white meat"
scope: EXACT
typename: MARKETING_SLOGAN
dbxrefs: set(["MEAT:00324", "BACONBASE:03021"])
Example synonyms:
"peptidase inhibitor complex" EXACT [GOC:bf, GOC:pr]
"regulation of postsynaptic cytosolic calcium levels" EXACT syngo_official_label []
"tocopherol 13-hydroxylase activity" EXACT systematic_synonym []
"""
mtch = self.attr2cmp['synonym'].match(line)
text, scope, typename, dbxrefs, _ = mtch.groups()
typename = typename.strip()
dbxrefs = set(dbxrefs.split(', ')) if dbxrefs else set()
return self.attr2cmp['synonym nt']._make([text, scope, typename, dbxrefs]) | python | def _get_synonym(self, line):
"""Given line, return optional attribute synonym value in a namedtuple.
Example synonym and its storage in a namedtuple:
synonym: "The other white meat" EXACT MARKETING_SLOGAN [MEAT:00324, BACONBASE:03021]
text: "The other white meat"
scope: EXACT
typename: MARKETING_SLOGAN
dbxrefs: set(["MEAT:00324", "BACONBASE:03021"])
Example synonyms:
"peptidase inhibitor complex" EXACT [GOC:bf, GOC:pr]
"regulation of postsynaptic cytosolic calcium levels" EXACT syngo_official_label []
"tocopherol 13-hydroxylase activity" EXACT systematic_synonym []
"""
mtch = self.attr2cmp['synonym'].match(line)
text, scope, typename, dbxrefs, _ = mtch.groups()
typename = typename.strip()
dbxrefs = set(dbxrefs.split(', ')) if dbxrefs else set()
return self.attr2cmp['synonym nt']._make([text, scope, typename, dbxrefs]) | [
"def",
"_get_synonym",
"(",
"self",
",",
"line",
")",
":",
"mtch",
"=",
"self",
".",
"attr2cmp",
"[",
"'synonym'",
"]",
".",
"match",
"(",
"line",
")",
"text",
",",
"scope",
",",
"typename",
",",
"dbxrefs",
",",
"_",
"=",
"mtch",
".",
"groups",
"("... | Given line, return optional attribute synonym value in a namedtuple.
Example synonym and its storage in a namedtuple:
synonym: "The other white meat" EXACT MARKETING_SLOGAN [MEAT:00324, BACONBASE:03021]
text: "The other white meat"
scope: EXACT
typename: MARKETING_SLOGAN
dbxrefs: set(["MEAT:00324", "BACONBASE:03021"])
Example synonyms:
"peptidase inhibitor complex" EXACT [GOC:bf, GOC:pr]
"regulation of postsynaptic cytosolic calcium levels" EXACT syngo_official_label []
"tocopherol 13-hydroxylase activity" EXACT systematic_synonym [] | [
"Given",
"line",
"return",
"optional",
"attribute",
"synonym",
"value",
"in",
"a",
"namedtuple",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/obo_optional_attributes.py#L62-L81 | train | 223,503 |
tanghaibao/goatools | goatools/godag/obo_optional_attributes.py | OboOptionalAttrs._get_xref | def _get_xref(self, line):
"""Given line, return optional attribute xref value in a dict of sets."""
# Ex: Wikipedia:Zygotene
# Ex: Reactome:REACT_22295 "Addition of a third mannose to ..."
mtch = self.attr2cmp['xref'].match(line)
return mtch.group(1).replace(' ', '') | python | def _get_xref(self, line):
"""Given line, return optional attribute xref value in a dict of sets."""
# Ex: Wikipedia:Zygotene
# Ex: Reactome:REACT_22295 "Addition of a third mannose to ..."
mtch = self.attr2cmp['xref'].match(line)
return mtch.group(1).replace(' ', '') | [
"def",
"_get_xref",
"(",
"self",
",",
"line",
")",
":",
"# Ex: Wikipedia:Zygotene",
"# Ex: Reactome:REACT_22295 \"Addition of a third mannose to ...\"",
"mtch",
"=",
"self",
".",
"attr2cmp",
"[",
"'xref'",
"]",
".",
"match",
"(",
"line",
")",
"return",
"mtch",
".",
... | Given line, return optional attribute xref value in a dict of sets. | [
"Given",
"line",
"return",
"optional",
"attribute",
"xref",
"value",
"in",
"a",
"dict",
"of",
"sets",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/obo_optional_attributes.py#L83-L88 | train | 223,504 |
tanghaibao/goatools | goatools/godag/obo_optional_attributes.py | OboOptionalAttrs._init_compile_patterns | def _init_compile_patterns(optional_attrs):
"""Compile search patterns for optional attributes if needed."""
attr2cmp = {}
if optional_attrs is None:
return attr2cmp
# "peptidase inhibitor complex" EXACT [GOC:bf, GOC:pr]
# "blood vessel formation from pre-existing blood vessels" EXACT systematic_synonym []
# "mitochondrial inheritance" EXACT []
# "tricarboxylate transport protein" RELATED [] {comment="WIkipedia:Mitochondrial_carrier"}
if 'synonym' in optional_attrs:
attr2cmp['synonym'] = re.compile(r'"(\S.*\S)" ([A-Z]+) (.*)\[(.*)\](.*)$')
attr2cmp['synonym nt'] = cx.namedtuple("synonym", "text scope typename dbxrefs")
# Wikipedia:Zygotene
# Reactome:REACT_27267 "DHAP from Ery4P and PEP, Mycobacterium tuberculosis"
if 'xref' in optional_attrs:
attr2cmp['xref'] = re.compile(r'^(\S+:\s*\S+)\b(.*)$')
return attr2cmp | python | def _init_compile_patterns(optional_attrs):
"""Compile search patterns for optional attributes if needed."""
attr2cmp = {}
if optional_attrs is None:
return attr2cmp
# "peptidase inhibitor complex" EXACT [GOC:bf, GOC:pr]
# "blood vessel formation from pre-existing blood vessels" EXACT systematic_synonym []
# "mitochondrial inheritance" EXACT []
# "tricarboxylate transport protein" RELATED [] {comment="WIkipedia:Mitochondrial_carrier"}
if 'synonym' in optional_attrs:
attr2cmp['synonym'] = re.compile(r'"(\S.*\S)" ([A-Z]+) (.*)\[(.*)\](.*)$')
attr2cmp['synonym nt'] = cx.namedtuple("synonym", "text scope typename dbxrefs")
# Wikipedia:Zygotene
# Reactome:REACT_27267 "DHAP from Ery4P and PEP, Mycobacterium tuberculosis"
if 'xref' in optional_attrs:
attr2cmp['xref'] = re.compile(r'^(\S+:\s*\S+)\b(.*)$')
return attr2cmp | [
"def",
"_init_compile_patterns",
"(",
"optional_attrs",
")",
":",
"attr2cmp",
"=",
"{",
"}",
"if",
"optional_attrs",
"is",
"None",
":",
"return",
"attr2cmp",
"# \"peptidase inhibitor complex\" EXACT [GOC:bf, GOC:pr]",
"# \"blood vessel formation from pre-existing blood vessels\" ... | Compile search patterns for optional attributes if needed. | [
"Compile",
"search",
"patterns",
"for",
"optional",
"attributes",
"if",
"needed",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/obo_optional_attributes.py#L91-L107 | train | 223,505 |
tanghaibao/goatools | goatools/cli/wr_hierarchy.py | cli | def cli():
"""Command-line script to print a GO term's lower-level hierarchy."""
objcli = WrHierCli(sys.argv[1:])
fouts_txt = objcli.get_fouts()
if fouts_txt:
for fout_txt in fouts_txt:
objcli.wrtxt_hier(fout_txt)
else:
objcli.prt_hier(sys.stdout) | python | def cli():
"""Command-line script to print a GO term's lower-level hierarchy."""
objcli = WrHierCli(sys.argv[1:])
fouts_txt = objcli.get_fouts()
if fouts_txt:
for fout_txt in fouts_txt:
objcli.wrtxt_hier(fout_txt)
else:
objcli.prt_hier(sys.stdout) | [
"def",
"cli",
"(",
")",
":",
"objcli",
"=",
"WrHierCli",
"(",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
")",
"fouts_txt",
"=",
"objcli",
".",
"get_fouts",
"(",
")",
"if",
"fouts_txt",
":",
"for",
"fout_txt",
"in",
"fouts_txt",
":",
"objcli",
".",
"wr... | Command-line script to print a GO term's lower-level hierarchy. | [
"Command",
"-",
"line",
"script",
"to",
"print",
"a",
"GO",
"term",
"s",
"lower",
"-",
"level",
"hierarchy",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/wr_hierarchy.py#L50-L58 | train | 223,506 |
tanghaibao/goatools | goatools/cli/wr_hierarchy.py | WrHierCli.get_fouts | def get_fouts(self):
"""Get output filename."""
fouts_txt = []
if 'o' in self.kws:
fouts_txt.append(self.kws['o'])
if 'f' in self.kws:
fouts_txt.append(self._get_fout_go())
return fouts_txt | python | def get_fouts(self):
"""Get output filename."""
fouts_txt = []
if 'o' in self.kws:
fouts_txt.append(self.kws['o'])
if 'f' in self.kws:
fouts_txt.append(self._get_fout_go())
return fouts_txt | [
"def",
"get_fouts",
"(",
"self",
")",
":",
"fouts_txt",
"=",
"[",
"]",
"if",
"'o'",
"in",
"self",
".",
"kws",
":",
"fouts_txt",
".",
"append",
"(",
"self",
".",
"kws",
"[",
"'o'",
"]",
")",
"if",
"'f'",
"in",
"self",
".",
"kws",
":",
"fouts_txt",... | Get output filename. | [
"Get",
"output",
"filename",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/wr_hierarchy.py#L107-L114 | train | 223,507 |
tanghaibao/goatools | goatools/cli/wr_hierarchy.py | WrHierCli._get_fout_go | def _get_fout_go(self):
"""Get the name of an output file based on the top GO term."""
assert self.goids, "NO VALID GO IDs WERE PROVIDED AS STARTING POINTS FOR HIERARCHY REPORT"
base = next(iter(self.goids)).replace(':', '')
upstr = '_up' if 'up' in self.kws else ''
return "hier_{BASE}{UP}.{EXT}".format(BASE=base, UP=upstr, EXT='txt') | python | def _get_fout_go(self):
"""Get the name of an output file based on the top GO term."""
assert self.goids, "NO VALID GO IDs WERE PROVIDED AS STARTING POINTS FOR HIERARCHY REPORT"
base = next(iter(self.goids)).replace(':', '')
upstr = '_up' if 'up' in self.kws else ''
return "hier_{BASE}{UP}.{EXT}".format(BASE=base, UP=upstr, EXT='txt') | [
"def",
"_get_fout_go",
"(",
"self",
")",
":",
"assert",
"self",
".",
"goids",
",",
"\"NO VALID GO IDs WERE PROVIDED AS STARTING POINTS FOR HIERARCHY REPORT\"",
"base",
"=",
"next",
"(",
"iter",
"(",
"self",
".",
"goids",
")",
")",
".",
"replace",
"(",
"':'",
","... | Get the name of an output file based on the top GO term. | [
"Get",
"the",
"name",
"of",
"an",
"output",
"file",
"based",
"on",
"the",
"top",
"GO",
"term",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/wr_hierarchy.py#L116-L121 | train | 223,508 |
tanghaibao/goatools | goatools/cli/wr_hierarchy.py | WrHierCli.wrtxt_hier | def wrtxt_hier(self, fout_txt):
"""Write hierarchy below specfied GO IDs to an ASCII file."""
with open(fout_txt, 'wb') as prt:
self.prt_hier(prt)
print(" WROTE: {TXT}".format(TXT=fout_txt)) | python | def wrtxt_hier(self, fout_txt):
"""Write hierarchy below specfied GO IDs to an ASCII file."""
with open(fout_txt, 'wb') as prt:
self.prt_hier(prt)
print(" WROTE: {TXT}".format(TXT=fout_txt)) | [
"def",
"wrtxt_hier",
"(",
"self",
",",
"fout_txt",
")",
":",
"with",
"open",
"(",
"fout_txt",
",",
"'wb'",
")",
"as",
"prt",
":",
"self",
".",
"prt_hier",
"(",
"prt",
")",
"print",
"(",
"\" WROTE: {TXT}\"",
".",
"format",
"(",
"TXT",
"=",
"fout_txt",
... | Write hierarchy below specfied GO IDs to an ASCII file. | [
"Write",
"hierarchy",
"below",
"specfied",
"GO",
"IDs",
"to",
"an",
"ASCII",
"file",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/wr_hierarchy.py#L123-L127 | train | 223,509 |
tanghaibao/goatools | goatools/cli/wr_hierarchy.py | WrHierCli.prt_hier | def prt_hier(self, prt=sys.stdout):
"""Write hierarchy below specfied GO IDs."""
objwr = WrHierGO(self.gosubdag, **self.kws)
assert self.goids, "NO VALID GO IDs WERE PROVIDED"
if 'up' not in objwr.usrset:
for goid in self.goids:
objwr.prt_hier_down(goid, prt)
else:
objwr.prt_hier_up(self.goids, prt) | python | def prt_hier(self, prt=sys.stdout):
"""Write hierarchy below specfied GO IDs."""
objwr = WrHierGO(self.gosubdag, **self.kws)
assert self.goids, "NO VALID GO IDs WERE PROVIDED"
if 'up' not in objwr.usrset:
for goid in self.goids:
objwr.prt_hier_down(goid, prt)
else:
objwr.prt_hier_up(self.goids, prt) | [
"def",
"prt_hier",
"(",
"self",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"objwr",
"=",
"WrHierGO",
"(",
"self",
".",
"gosubdag",
",",
"*",
"*",
"self",
".",
"kws",
")",
"assert",
"self",
".",
"goids",
",",
"\"NO VALID GO IDs WERE PROVIDED\"",
"... | Write hierarchy below specfied GO IDs. | [
"Write",
"hierarchy",
"below",
"specfied",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/wr_hierarchy.py#L129-L137 | train | 223,510 |
tanghaibao/goatools | goatools/cli/wr_hierarchy.py | WrHierCli._adj_for_assc | def _adj_for_assc(self):
"""Print only GO IDs from associations and their ancestors."""
if self.gene2gos:
gos_assoc = set(get_b2aset(self.gene2gos).keys())
if 'item_marks' not in self.kws:
self.kws['item_marks'] = {go:'>' for go in gos_assoc}
if 'include_only' not in self.kws:
gosubdag = GoSubDag(gos_assoc, self.gosubdag.go2obj,
self.gosubdag.relationships)
self.kws['include_only'] = gosubdag.go2obj | python | def _adj_for_assc(self):
"""Print only GO IDs from associations and their ancestors."""
if self.gene2gos:
gos_assoc = set(get_b2aset(self.gene2gos).keys())
if 'item_marks' not in self.kws:
self.kws['item_marks'] = {go:'>' for go in gos_assoc}
if 'include_only' not in self.kws:
gosubdag = GoSubDag(gos_assoc, self.gosubdag.go2obj,
self.gosubdag.relationships)
self.kws['include_only'] = gosubdag.go2obj | [
"def",
"_adj_for_assc",
"(",
"self",
")",
":",
"if",
"self",
".",
"gene2gos",
":",
"gos_assoc",
"=",
"set",
"(",
"get_b2aset",
"(",
"self",
".",
"gene2gos",
")",
".",
"keys",
"(",
")",
")",
"if",
"'item_marks'",
"not",
"in",
"self",
".",
"kws",
":",
... | Print only GO IDs from associations and their ancestors. | [
"Print",
"only",
"GO",
"IDs",
"from",
"associations",
"and",
"their",
"ancestors",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/wr_hierarchy.py#L165-L174 | train | 223,511 |
tanghaibao/goatools | goatools/pvalcalc.py | PvalCalcBase.calc_pvalue | def calc_pvalue(self, study_count, study_n, pop_count, pop_n):
"""pvalues are calculated in derived classes."""
fnc_call = "calc_pvalue({SCNT}, {STOT}, {PCNT} {PTOT})".format(
SCNT=study_count, STOT=study_n, PCNT=pop_count, PTOT=pop_n)
raise Exception("NOT IMPLEMENTED: {FNC_CALL} using {FNC}.".format(
FNC_CALL=fnc_call, FNC=self.pval_fnc)) | python | def calc_pvalue(self, study_count, study_n, pop_count, pop_n):
"""pvalues are calculated in derived classes."""
fnc_call = "calc_pvalue({SCNT}, {STOT}, {PCNT} {PTOT})".format(
SCNT=study_count, STOT=study_n, PCNT=pop_count, PTOT=pop_n)
raise Exception("NOT IMPLEMENTED: {FNC_CALL} using {FNC}.".format(
FNC_CALL=fnc_call, FNC=self.pval_fnc)) | [
"def",
"calc_pvalue",
"(",
"self",
",",
"study_count",
",",
"study_n",
",",
"pop_count",
",",
"pop_n",
")",
":",
"fnc_call",
"=",
"\"calc_pvalue({SCNT}, {STOT}, {PCNT} {PTOT})\"",
".",
"format",
"(",
"SCNT",
"=",
"study_count",
",",
"STOT",
"=",
"study_n",
",",
... | pvalues are calculated in derived classes. | [
"pvalues",
"are",
"calculated",
"in",
"derived",
"classes",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/pvalcalc.py#L19-L24 | train | 223,512 |
tanghaibao/goatools | goatools/pvalcalc.py | FisherFactory._init_pval_obj | def _init_pval_obj(self):
"""Returns a Fisher object based on user-input."""
if self.pval_fnc_name in self.options.keys():
try:
fisher_obj = self.options[self.pval_fnc_name](self.pval_fnc_name, self.log)
except ImportError:
print("fisher module not installed. Falling back on scipy.stats.fisher_exact")
fisher_obj = self.options['fisher_scipy_stats']('fisher_scipy_stats', self.log)
return fisher_obj
raise Exception("PVALUE FUNCTION({FNC}) NOT FOUND".format(FNC=self.pval_fnc_name)) | python | def _init_pval_obj(self):
"""Returns a Fisher object based on user-input."""
if self.pval_fnc_name in self.options.keys():
try:
fisher_obj = self.options[self.pval_fnc_name](self.pval_fnc_name, self.log)
except ImportError:
print("fisher module not installed. Falling back on scipy.stats.fisher_exact")
fisher_obj = self.options['fisher_scipy_stats']('fisher_scipy_stats', self.log)
return fisher_obj
raise Exception("PVALUE FUNCTION({FNC}) NOT FOUND".format(FNC=self.pval_fnc_name)) | [
"def",
"_init_pval_obj",
"(",
"self",
")",
":",
"if",
"self",
".",
"pval_fnc_name",
"in",
"self",
".",
"options",
".",
"keys",
"(",
")",
":",
"try",
":",
"fisher_obj",
"=",
"self",
".",
"options",
"[",
"self",
".",
"pval_fnc_name",
"]",
"(",
"self",
... | Returns a Fisher object based on user-input. | [
"Returns",
"a",
"Fisher",
"object",
"based",
"on",
"user",
"-",
"input",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/pvalcalc.py#L90-L101 | train | 223,513 |
tanghaibao/goatools | setup_helper.py | SetupHelper.check_version | def check_version(self, name, majorv=2, minorv=7):
""" Make sure the package runs on the supported Python version
"""
if sys.version_info.major == majorv and sys.version_info.minor != minorv:
sys.stderr.write("ERROR: %s is only for >= Python %d.%d but you are running %d.%d\n" %\
(name, majorv, minorv, sys.version_info.major, sys.version_info.minor))
sys.exit(1) | python | def check_version(self, name, majorv=2, minorv=7):
""" Make sure the package runs on the supported Python version
"""
if sys.version_info.major == majorv and sys.version_info.minor != minorv:
sys.stderr.write("ERROR: %s is only for >= Python %d.%d but you are running %d.%d\n" %\
(name, majorv, minorv, sys.version_info.major, sys.version_info.minor))
sys.exit(1) | [
"def",
"check_version",
"(",
"self",
",",
"name",
",",
"majorv",
"=",
"2",
",",
"minorv",
"=",
"7",
")",
":",
"if",
"sys",
".",
"version_info",
".",
"major",
"==",
"majorv",
"and",
"sys",
".",
"version_info",
".",
"minor",
"!=",
"minorv",
":",
"sys",... | Make sure the package runs on the supported Python version | [
"Make",
"sure",
"the",
"package",
"runs",
"on",
"the",
"supported",
"Python",
"version"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/setup_helper.py#L21-L27 | train | 223,514 |
tanghaibao/goatools | setup_helper.py | SetupHelper.get_init | def get_init(self, filename="__init__.py"):
""" Get various info from the package without importing them
"""
import ast
with open(filename) as init_file:
module = ast.parse(init_file.read())
itr = lambda x: (ast.literal_eval(node.value) for node in ast.walk(module) \
if isinstance(node, ast.Assign) and node.targets[0].id == x)
try:
return next(itr("__author__")), \
next(itr("__email__")), \
next(itr("__license__")), \
next(itr("__version__"))
except StopIteration:
raise ValueError("One of author, email, license, or version"
" cannot be found in {}".format(filename)) | python | def get_init(self, filename="__init__.py"):
""" Get various info from the package without importing them
"""
import ast
with open(filename) as init_file:
module = ast.parse(init_file.read())
itr = lambda x: (ast.literal_eval(node.value) for node in ast.walk(module) \
if isinstance(node, ast.Assign) and node.targets[0].id == x)
try:
return next(itr("__author__")), \
next(itr("__email__")), \
next(itr("__license__")), \
next(itr("__version__"))
except StopIteration:
raise ValueError("One of author, email, license, or version"
" cannot be found in {}".format(filename)) | [
"def",
"get_init",
"(",
"self",
",",
"filename",
"=",
"\"__init__.py\"",
")",
":",
"import",
"ast",
"with",
"open",
"(",
"filename",
")",
"as",
"init_file",
":",
"module",
"=",
"ast",
".",
"parse",
"(",
"init_file",
".",
"read",
"(",
")",
")",
"itr",
... | Get various info from the package without importing them | [
"Get",
"various",
"info",
"from",
"the",
"package",
"without",
"importing",
"them"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/setup_helper.py#L29-L47 | train | 223,515 |
tanghaibao/goatools | setup_helper.py | SetupHelper.missing_requirements | def missing_requirements(self, specifiers):
""" Find what's missing
"""
for specifier in specifiers:
try:
pkg_resources.require(specifier)
except pkg_resources.DistributionNotFound:
yield specifier | python | def missing_requirements(self, specifiers):
""" Find what's missing
"""
for specifier in specifiers:
try:
pkg_resources.require(specifier)
except pkg_resources.DistributionNotFound:
yield specifier | [
"def",
"missing_requirements",
"(",
"self",
",",
"specifiers",
")",
":",
"for",
"specifier",
"in",
"specifiers",
":",
"try",
":",
"pkg_resources",
".",
"require",
"(",
"specifier",
")",
"except",
"pkg_resources",
".",
"DistributionNotFound",
":",
"yield",
"speci... | Find what's missing | [
"Find",
"what",
"s",
"missing"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/setup_helper.py#L49-L56 | train | 223,516 |
tanghaibao/goatools | setup_helper.py | SetupHelper.install_requirements | def install_requirements(self, requires):
""" Install the listed requirements
"""
# Temporarily install dependencies required by setup.py before trying to import them.
sys.path[0:0] = ['setup-requires']
pkg_resources.working_set.add_entry('setup-requires')
to_install = list(self.missing_requirements(requires))
if to_install:
cmd = [sys.executable, "-m", "pip", "install",
"-t", "setup-requires"] + to_install
subprocess.call(cmd) | python | def install_requirements(self, requires):
""" Install the listed requirements
"""
# Temporarily install dependencies required by setup.py before trying to import them.
sys.path[0:0] = ['setup-requires']
pkg_resources.working_set.add_entry('setup-requires')
to_install = list(self.missing_requirements(requires))
if to_install:
cmd = [sys.executable, "-m", "pip", "install",
"-t", "setup-requires"] + to_install
subprocess.call(cmd) | [
"def",
"install_requirements",
"(",
"self",
",",
"requires",
")",
":",
"# Temporarily install dependencies required by setup.py before trying to import them.",
"sys",
".",
"path",
"[",
"0",
":",
"0",
"]",
"=",
"[",
"'setup-requires'",
"]",
"pkg_resources",
".",
"working... | Install the listed requirements | [
"Install",
"the",
"listed",
"requirements"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/setup_helper.py#L58-L69 | train | 223,517 |
tanghaibao/goatools | setup_helper.py | SetupHelper.get_long_description | def get_long_description(self, filename='README.md'):
""" I really prefer Markdown to reStructuredText. PyPi does not.
"""
try:
import pypandoc
description = pypandoc.convert_file('README.md', 'rst', 'md')
except (IOError, ImportError):
description = open("README.md").read()
return description | python | def get_long_description(self, filename='README.md'):
""" I really prefer Markdown to reStructuredText. PyPi does not.
"""
try:
import pypandoc
description = pypandoc.convert_file('README.md', 'rst', 'md')
except (IOError, ImportError):
description = open("README.md").read()
return description | [
"def",
"get_long_description",
"(",
"self",
",",
"filename",
"=",
"'README.md'",
")",
":",
"try",
":",
"import",
"pypandoc",
"description",
"=",
"pypandoc",
".",
"convert_file",
"(",
"'README.md'",
",",
"'rst'",
",",
"'md'",
")",
"except",
"(",
"IOError",
",... | I really prefer Markdown to reStructuredText. PyPi does not. | [
"I",
"really",
"prefer",
"Markdown",
"to",
"reStructuredText",
".",
"PyPi",
"does",
"not",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/setup_helper.py#L71-L79 | train | 223,518 |
tanghaibao/goatools | goatools/grouper/sorter.py | Sorter.prt_gos | def prt_gos(self, prt=sys.stdout, **kws_usr):
"""Sort user GO ids, grouped under broader GO terms or sections. Print to screen."""
# deprecated
# Keyword arguments (control content): hdrgo_prt section_prt use_sections
# desc2nts contains: (sections hdrgo_prt sortobj) or (flat hdrgo_prt sortobj)
desc2nts = self.get_desc2nts(**kws_usr)
# Keyword arguments (control print format): prt prtfmt
self.prt_nts(desc2nts, prt, kws_usr.get('prtfmt'))
return desc2nts | python | def prt_gos(self, prt=sys.stdout, **kws_usr):
"""Sort user GO ids, grouped under broader GO terms or sections. Print to screen."""
# deprecated
# Keyword arguments (control content): hdrgo_prt section_prt use_sections
# desc2nts contains: (sections hdrgo_prt sortobj) or (flat hdrgo_prt sortobj)
desc2nts = self.get_desc2nts(**kws_usr)
# Keyword arguments (control print format): prt prtfmt
self.prt_nts(desc2nts, prt, kws_usr.get('prtfmt'))
return desc2nts | [
"def",
"prt_gos",
"(",
"self",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"*",
"*",
"kws_usr",
")",
":",
"# deprecated",
"# Keyword arguments (control content): hdrgo_prt section_prt use_sections",
"# desc2nts contains: (sections hdrgo_prt sortobj) or (flat hdrgo_prt sortobj)",
... | Sort user GO ids, grouped under broader GO terms or sections. Print to screen. | [
"Sort",
"user",
"GO",
"ids",
"grouped",
"under",
"broader",
"GO",
"terms",
"or",
"sections",
".",
"Print",
"to",
"screen",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/sorter.py#L64-L72 | train | 223,519 |
tanghaibao/goatools | goatools/grouper/sorter.py | Sorter.get_nts_flat | def get_nts_flat(self, hdrgo_prt=True, use_sections=True):
"""Return a flat list of sorted nts."""
# Either there are no sections OR we are not using them
if self.sectobj is None or not use_sections:
return self.sortgos.get_nts_sorted(
hdrgo_prt,
hdrgos=self.grprobj.get_hdrgos(),
hdrgo_sort=True)
if not use_sections:
return self.sectobj.get_sorted_nts_omit_section(hdrgo_prt, hdrgo_sort=True)
return None | python | def get_nts_flat(self, hdrgo_prt=True, use_sections=True):
"""Return a flat list of sorted nts."""
# Either there are no sections OR we are not using them
if self.sectobj is None or not use_sections:
return self.sortgos.get_nts_sorted(
hdrgo_prt,
hdrgos=self.grprobj.get_hdrgos(),
hdrgo_sort=True)
if not use_sections:
return self.sectobj.get_sorted_nts_omit_section(hdrgo_prt, hdrgo_sort=True)
return None | [
"def",
"get_nts_flat",
"(",
"self",
",",
"hdrgo_prt",
"=",
"True",
",",
"use_sections",
"=",
"True",
")",
":",
"# Either there are no sections OR we are not using them",
"if",
"self",
".",
"sectobj",
"is",
"None",
"or",
"not",
"use_sections",
":",
"return",
"self"... | Return a flat list of sorted nts. | [
"Return",
"a",
"flat",
"list",
"of",
"sorted",
"nts",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/sorter.py#L165-L175 | train | 223,520 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_sections_2d | def get_sections_2d(self):
"""Get 2-D list of sections and hdrgos sets actually used in grouping."""
sections_hdrgos_act = []
hdrgos_act_all = self.get_hdrgos() # Header GOs actually used to group
hdrgos_act_secs = set()
if self.hdrobj.sections:
for section_name, hdrgos_all_lst in self.hdrobj.sections:
# print("GGGGGGGGGGGGGGGGG {N:3} {NAME}".format(N=len(hdrgos_all_lst), NAME=section_name))
hdrgos_all_set = set(hdrgos_all_lst)
hdrgos_act_set = hdrgos_all_set.intersection(hdrgos_act_all)
if hdrgos_act_set:
hdrgos_act_secs |= hdrgos_act_set
# Use original order of header GOs found in sections
hdrgos_act_lst = []
hdrgos_act_ctr = cx.Counter()
for hdrgo_p in hdrgos_all_lst: # Header GO that may or may not be used.
if hdrgo_p in hdrgos_act_set and hdrgos_act_ctr[hdrgo_p] == 0:
hdrgos_act_lst.append(hdrgo_p)
hdrgos_act_ctr[hdrgo_p] += 1
sections_hdrgos_act.append((section_name, hdrgos_act_lst))
# print(">>>>>>>>>>>>>>> hdrgos_act_all {N:3}".format(N=len(hdrgos_act_all)))
# print(">>>>>>>>>>>>>>> hdrgos_act_secs {N:3}".format(N=len(hdrgos_act_secs)))
hdrgos_act_rem = hdrgos_act_all.difference(hdrgos_act_secs)
if hdrgos_act_rem:
# print("RRRRRRRRRRR {N:3}".format(N=len(hdrgos_act_rem)))
sections_hdrgos_act.append((self.hdrobj.secdflt, hdrgos_act_rem))
else:
sections_hdrgos_act.append((self.hdrobj.secdflt, hdrgos_act_all))
return sections_hdrgos_act | python | def get_sections_2d(self):
"""Get 2-D list of sections and hdrgos sets actually used in grouping."""
sections_hdrgos_act = []
hdrgos_act_all = self.get_hdrgos() # Header GOs actually used to group
hdrgos_act_secs = set()
if self.hdrobj.sections:
for section_name, hdrgos_all_lst in self.hdrobj.sections:
# print("GGGGGGGGGGGGGGGGG {N:3} {NAME}".format(N=len(hdrgos_all_lst), NAME=section_name))
hdrgos_all_set = set(hdrgos_all_lst)
hdrgos_act_set = hdrgos_all_set.intersection(hdrgos_act_all)
if hdrgos_act_set:
hdrgos_act_secs |= hdrgos_act_set
# Use original order of header GOs found in sections
hdrgos_act_lst = []
hdrgos_act_ctr = cx.Counter()
for hdrgo_p in hdrgos_all_lst: # Header GO that may or may not be used.
if hdrgo_p in hdrgos_act_set and hdrgos_act_ctr[hdrgo_p] == 0:
hdrgos_act_lst.append(hdrgo_p)
hdrgos_act_ctr[hdrgo_p] += 1
sections_hdrgos_act.append((section_name, hdrgos_act_lst))
# print(">>>>>>>>>>>>>>> hdrgos_act_all {N:3}".format(N=len(hdrgos_act_all)))
# print(">>>>>>>>>>>>>>> hdrgos_act_secs {N:3}".format(N=len(hdrgos_act_secs)))
hdrgos_act_rem = hdrgos_act_all.difference(hdrgos_act_secs)
if hdrgos_act_rem:
# print("RRRRRRRRRRR {N:3}".format(N=len(hdrgos_act_rem)))
sections_hdrgos_act.append((self.hdrobj.secdflt, hdrgos_act_rem))
else:
sections_hdrgos_act.append((self.hdrobj.secdflt, hdrgos_act_all))
return sections_hdrgos_act | [
"def",
"get_sections_2d",
"(",
"self",
")",
":",
"sections_hdrgos_act",
"=",
"[",
"]",
"hdrgos_act_all",
"=",
"self",
".",
"get_hdrgos",
"(",
")",
"# Header GOs actually used to group",
"hdrgos_act_secs",
"=",
"set",
"(",
")",
"if",
"self",
".",
"hdrobj",
".",
... | Get 2-D list of sections and hdrgos sets actually used in grouping. | [
"Get",
"2",
"-",
"D",
"list",
"of",
"sections",
"and",
"hdrgos",
"sets",
"actually",
"used",
"in",
"grouping",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L60-L88 | train | 223,521 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_usrgos_g_section | def get_usrgos_g_section(self, section=None):
"""Get usrgos in a requested section."""
if section is None:
section = self.hdrobj.secdflt
if section is True:
return self.usrgos
# Get dict of sections and hdrgos actually used in grouping
section2hdrgos = cx.OrderedDict(self.get_sections_2d())
hdrgos_lst = section2hdrgos.get(section, None)
if hdrgos_lst is not None:
hdrgos_set = set(hdrgos_lst)
hdrgos_u = hdrgos_set.intersection(self.hdrgo_is_usrgo)
hdrgos_h = hdrgos_set.intersection(self.hdrgo2usrgos.keys())
usrgos = set([u for h in hdrgos_h for u in self.hdrgo2usrgos.get(h)])
usrgos |= hdrgos_u
return usrgos
return set() | python | def get_usrgos_g_section(self, section=None):
"""Get usrgos in a requested section."""
if section is None:
section = self.hdrobj.secdflt
if section is True:
return self.usrgos
# Get dict of sections and hdrgos actually used in grouping
section2hdrgos = cx.OrderedDict(self.get_sections_2d())
hdrgos_lst = section2hdrgos.get(section, None)
if hdrgos_lst is not None:
hdrgos_set = set(hdrgos_lst)
hdrgos_u = hdrgos_set.intersection(self.hdrgo_is_usrgo)
hdrgos_h = hdrgos_set.intersection(self.hdrgo2usrgos.keys())
usrgos = set([u for h in hdrgos_h for u in self.hdrgo2usrgos.get(h)])
usrgos |= hdrgos_u
return usrgos
return set() | [
"def",
"get_usrgos_g_section",
"(",
"self",
",",
"section",
"=",
"None",
")",
":",
"if",
"section",
"is",
"None",
":",
"section",
"=",
"self",
".",
"hdrobj",
".",
"secdflt",
"if",
"section",
"is",
"True",
":",
"return",
"self",
".",
"usrgos",
"# Get dict... | Get usrgos in a requested section. | [
"Get",
"usrgos",
"in",
"a",
"requested",
"section",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L90-L106 | train | 223,522 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_section2usrnts | def get_section2usrnts(self):
"""Get dict section2usrnts."""
sec_nts = []
for section_name, _ in self.get_sections_2d():
usrgos = self.get_usrgos_g_section(section_name)
sec_nts.append((section_name, [self.go2nt.get(u) for u in usrgos]))
return cx.OrderedDict(sec_nts) | python | def get_section2usrnts(self):
"""Get dict section2usrnts."""
sec_nts = []
for section_name, _ in self.get_sections_2d():
usrgos = self.get_usrgos_g_section(section_name)
sec_nts.append((section_name, [self.go2nt.get(u) for u in usrgos]))
return cx.OrderedDict(sec_nts) | [
"def",
"get_section2usrnts",
"(",
"self",
")",
":",
"sec_nts",
"=",
"[",
"]",
"for",
"section_name",
",",
"_",
"in",
"self",
".",
"get_sections_2d",
"(",
")",
":",
"usrgos",
"=",
"self",
".",
"get_usrgos_g_section",
"(",
"section_name",
")",
"sec_nts",
"."... | Get dict section2usrnts. | [
"Get",
"dict",
"section2usrnts",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L108-L114 | train | 223,523 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_section2items | def get_section2items(self, itemkey):
"""Collect all items into a single set per section."""
sec_items = []
section2usrnts = self.get_section2usrnts()
for section, usrnts in section2usrnts.items():
items = set([e for nt in usrnts for e in getattr(nt, itemkey, set())])
sec_items.append((section, items))
return cx.OrderedDict(sec_items) | python | def get_section2items(self, itemkey):
"""Collect all items into a single set per section."""
sec_items = []
section2usrnts = self.get_section2usrnts()
for section, usrnts in section2usrnts.items():
items = set([e for nt in usrnts for e in getattr(nt, itemkey, set())])
sec_items.append((section, items))
return cx.OrderedDict(sec_items) | [
"def",
"get_section2items",
"(",
"self",
",",
"itemkey",
")",
":",
"sec_items",
"=",
"[",
"]",
"section2usrnts",
"=",
"self",
".",
"get_section2usrnts",
"(",
")",
"for",
"section",
",",
"usrnts",
"in",
"section2usrnts",
".",
"items",
"(",
")",
":",
"items"... | Collect all items into a single set per section. | [
"Collect",
"all",
"items",
"into",
"a",
"single",
"set",
"per",
"section",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L116-L123 | train | 223,524 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_hdrgos_g_usrgos | def get_hdrgos_g_usrgos(self, usrgos):
"""Return hdrgos which contain the usrgos."""
hdrgos_for_usrgos = set()
hdrgos_all = self.get_hdrgos()
usrgo2hdrgo = self.get_usrgo2hdrgo()
for usrgo in usrgos:
if usrgo in hdrgos_all:
hdrgos_for_usrgos.add(usrgo)
continue
hdrgo_cur = usrgo2hdrgo.get(usrgo, None)
if hdrgo_cur is not None:
hdrgos_for_usrgos.add(hdrgo_cur)
return hdrgos_for_usrgos | python | def get_hdrgos_g_usrgos(self, usrgos):
"""Return hdrgos which contain the usrgos."""
hdrgos_for_usrgos = set()
hdrgos_all = self.get_hdrgos()
usrgo2hdrgo = self.get_usrgo2hdrgo()
for usrgo in usrgos:
if usrgo in hdrgos_all:
hdrgos_for_usrgos.add(usrgo)
continue
hdrgo_cur = usrgo2hdrgo.get(usrgo, None)
if hdrgo_cur is not None:
hdrgos_for_usrgos.add(hdrgo_cur)
return hdrgos_for_usrgos | [
"def",
"get_hdrgos_g_usrgos",
"(",
"self",
",",
"usrgos",
")",
":",
"hdrgos_for_usrgos",
"=",
"set",
"(",
")",
"hdrgos_all",
"=",
"self",
".",
"get_hdrgos",
"(",
")",
"usrgo2hdrgo",
"=",
"self",
".",
"get_usrgo2hdrgo",
"(",
")",
"for",
"usrgo",
"in",
"usrg... | Return hdrgos which contain the usrgos. | [
"Return",
"hdrgos",
"which",
"contain",
"the",
"usrgos",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L125-L137 | train | 223,525 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_section_hdrgos_nts | def get_section_hdrgos_nts(self, sortby=None):
"""Get a flat list of sections and hdrgos actually used in grouping."""
nts_all = []
section_hdrgos_actual = self.get_sections_2d()
flds_all = ['Section'] + self.gosubdag.prt_attr['flds']
ntobj = cx.namedtuple("NtGoSec", " ".join(flds_all))
flds_go = None
if sortby is None:
sortby = lambda nt: -1*nt.dcnt
for section_name, hdrgos_actual in section_hdrgos_actual:
nts_sec = []
for hdrgo_nt in self.gosubdag.get_go2nt(hdrgos_actual).values():
if flds_go is None:
flds_go = hdrgo_nt._fields
key2val = {key:val for key, val in zip(flds_go, list(hdrgo_nt))}
key2val['Section'] = section_name
nts_sec.append(ntobj(**key2val))
nts_all.extend(sorted(nts_sec, key=sortby))
return nts_all | python | def get_section_hdrgos_nts(self, sortby=None):
"""Get a flat list of sections and hdrgos actually used in grouping."""
nts_all = []
section_hdrgos_actual = self.get_sections_2d()
flds_all = ['Section'] + self.gosubdag.prt_attr['flds']
ntobj = cx.namedtuple("NtGoSec", " ".join(flds_all))
flds_go = None
if sortby is None:
sortby = lambda nt: -1*nt.dcnt
for section_name, hdrgos_actual in section_hdrgos_actual:
nts_sec = []
for hdrgo_nt in self.gosubdag.get_go2nt(hdrgos_actual).values():
if flds_go is None:
flds_go = hdrgo_nt._fields
key2val = {key:val for key, val in zip(flds_go, list(hdrgo_nt))}
key2val['Section'] = section_name
nts_sec.append(ntobj(**key2val))
nts_all.extend(sorted(nts_sec, key=sortby))
return nts_all | [
"def",
"get_section_hdrgos_nts",
"(",
"self",
",",
"sortby",
"=",
"None",
")",
":",
"nts_all",
"=",
"[",
"]",
"section_hdrgos_actual",
"=",
"self",
".",
"get_sections_2d",
"(",
")",
"flds_all",
"=",
"[",
"'Section'",
"]",
"+",
"self",
".",
"gosubdag",
".",... | Get a flat list of sections and hdrgos actually used in grouping. | [
"Get",
"a",
"flat",
"list",
"of",
"sections",
"and",
"hdrgos",
"actually",
"used",
"in",
"grouping",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L139-L157 | train | 223,526 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_sections_2d_nts | def get_sections_2d_nts(self, sortby=None):
"""Get high GO IDs that are actually used to group current set of GO IDs."""
sections_2d_nts = []
for section_name, hdrgos_actual in self.get_sections_2d():
hdrgo_nts = self.gosubdag.get_nts(hdrgos_actual, sortby=sortby)
sections_2d_nts.append((section_name, hdrgo_nts))
return sections_2d_nts | python | def get_sections_2d_nts(self, sortby=None):
"""Get high GO IDs that are actually used to group current set of GO IDs."""
sections_2d_nts = []
for section_name, hdrgos_actual in self.get_sections_2d():
hdrgo_nts = self.gosubdag.get_nts(hdrgos_actual, sortby=sortby)
sections_2d_nts.append((section_name, hdrgo_nts))
return sections_2d_nts | [
"def",
"get_sections_2d_nts",
"(",
"self",
",",
"sortby",
"=",
"None",
")",
":",
"sections_2d_nts",
"=",
"[",
"]",
"for",
"section_name",
",",
"hdrgos_actual",
"in",
"self",
".",
"get_sections_2d",
"(",
")",
":",
"hdrgo_nts",
"=",
"self",
".",
"gosubdag",
... | Get high GO IDs that are actually used to group current set of GO IDs. | [
"Get",
"high",
"GO",
"IDs",
"that",
"are",
"actually",
"used",
"to",
"group",
"current",
"set",
"of",
"GO",
"IDs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L159-L165 | train | 223,527 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_usrgos_g_hdrgos | def get_usrgos_g_hdrgos(self, hdrgos):
"""Return usrgos under provided hdrgos."""
usrgos_all = set()
if isinstance(hdrgos, str):
hdrgos = [hdrgos]
for hdrgo in hdrgos:
usrgos_cur = self.hdrgo2usrgos.get(hdrgo, None)
if usrgos_cur is not None:
usrgos_all |= usrgos_cur
if hdrgo in self.hdrgo_is_usrgo:
usrgos_all.add(hdrgo)
return usrgos_all | python | def get_usrgos_g_hdrgos(self, hdrgos):
"""Return usrgos under provided hdrgos."""
usrgos_all = set()
if isinstance(hdrgos, str):
hdrgos = [hdrgos]
for hdrgo in hdrgos:
usrgos_cur = self.hdrgo2usrgos.get(hdrgo, None)
if usrgos_cur is not None:
usrgos_all |= usrgos_cur
if hdrgo in self.hdrgo_is_usrgo:
usrgos_all.add(hdrgo)
return usrgos_all | [
"def",
"get_usrgos_g_hdrgos",
"(",
"self",
",",
"hdrgos",
")",
":",
"usrgos_all",
"=",
"set",
"(",
")",
"if",
"isinstance",
"(",
"hdrgos",
",",
"str",
")",
":",
"hdrgos",
"=",
"[",
"hdrgos",
"]",
"for",
"hdrgo",
"in",
"hdrgos",
":",
"usrgos_cur",
"=",
... | Return usrgos under provided hdrgos. | [
"Return",
"usrgos",
"under",
"provided",
"hdrgos",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L171-L182 | train | 223,528 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_hdrgo2usrgos | def get_hdrgo2usrgos(self, hdrgos):
"""Return a subset of hdrgo2usrgos."""
get_usrgos = self.hdrgo2usrgos.get
hdrgos_actual = self.get_hdrgos().intersection(hdrgos)
return {h:get_usrgos(h) for h in hdrgos_actual} | python | def get_hdrgo2usrgos(self, hdrgos):
"""Return a subset of hdrgo2usrgos."""
get_usrgos = self.hdrgo2usrgos.get
hdrgos_actual = self.get_hdrgos().intersection(hdrgos)
return {h:get_usrgos(h) for h in hdrgos_actual} | [
"def",
"get_hdrgo2usrgos",
"(",
"self",
",",
"hdrgos",
")",
":",
"get_usrgos",
"=",
"self",
".",
"hdrgo2usrgos",
".",
"get",
"hdrgos_actual",
"=",
"self",
".",
"get_hdrgos",
"(",
")",
".",
"intersection",
"(",
"hdrgos",
")",
"return",
"{",
"h",
":",
"get... | Return a subset of hdrgo2usrgos. | [
"Return",
"a",
"subset",
"of",
"hdrgo2usrgos",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L196-L200 | train | 223,529 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_usrgo2hdrgo | def get_usrgo2hdrgo(self):
"""Return a dict with all user GO IDs as keys and their respective header GOs as values."""
usrgo2hdrgo = {}
for hdrgo, usrgos in self.hdrgo2usrgos.items():
for usrgo in usrgos:
assert usrgo not in usrgo2hdrgo
usrgo2hdrgo[usrgo] = hdrgo
# Add usrgos which are also a hdrgo and the GO group contains no other GO IDs
for goid in self.hdrgo_is_usrgo:
usrgo2hdrgo[goid] = goid
assert len(self.usrgos) <= len(usrgo2hdrgo), \
"USRGOS({U}) != USRGO2HDRGO({H}): {GOs}".format(
U=len(self.usrgos),
H=len(usrgo2hdrgo),
GOs=self.usrgos.symmetric_difference(set(usrgo2hdrgo.keys())))
return usrgo2hdrgo | python | def get_usrgo2hdrgo(self):
"""Return a dict with all user GO IDs as keys and their respective header GOs as values."""
usrgo2hdrgo = {}
for hdrgo, usrgos in self.hdrgo2usrgos.items():
for usrgo in usrgos:
assert usrgo not in usrgo2hdrgo
usrgo2hdrgo[usrgo] = hdrgo
# Add usrgos which are also a hdrgo and the GO group contains no other GO IDs
for goid in self.hdrgo_is_usrgo:
usrgo2hdrgo[goid] = goid
assert len(self.usrgos) <= len(usrgo2hdrgo), \
"USRGOS({U}) != USRGO2HDRGO({H}): {GOs}".format(
U=len(self.usrgos),
H=len(usrgo2hdrgo),
GOs=self.usrgos.symmetric_difference(set(usrgo2hdrgo.keys())))
return usrgo2hdrgo | [
"def",
"get_usrgo2hdrgo",
"(",
"self",
")",
":",
"usrgo2hdrgo",
"=",
"{",
"}",
"for",
"hdrgo",
",",
"usrgos",
"in",
"self",
".",
"hdrgo2usrgos",
".",
"items",
"(",
")",
":",
"for",
"usrgo",
"in",
"usrgos",
":",
"assert",
"usrgo",
"not",
"in",
"usrgo2hd... | Return a dict with all user GO IDs as keys and their respective header GOs as values. | [
"Return",
"a",
"dict",
"with",
"all",
"user",
"GO",
"IDs",
"as",
"keys",
"and",
"their",
"respective",
"header",
"GOs",
"as",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L202-L217 | train | 223,530 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_go2sectiontxt | def get_go2sectiontxt(self):
"""Return a dict with actual header and user GO IDs as keys and their sections as values."""
go2txt = {}
_get_secs = self.hdrobj.get_sections
hdrgo2sectxt = {h:" ".join(_get_secs(h)) for h in self.get_hdrgos()}
usrgo2hdrgo = self.get_usrgo2hdrgo()
for goid, ntgo in self.go2nt.items():
hdrgo = ntgo.GO if ntgo.is_hdrgo else usrgo2hdrgo[ntgo.GO]
go2txt[goid] = hdrgo2sectxt[hdrgo]
return go2txt | python | def get_go2sectiontxt(self):
"""Return a dict with actual header and user GO IDs as keys and their sections as values."""
go2txt = {}
_get_secs = self.hdrobj.get_sections
hdrgo2sectxt = {h:" ".join(_get_secs(h)) for h in self.get_hdrgos()}
usrgo2hdrgo = self.get_usrgo2hdrgo()
for goid, ntgo in self.go2nt.items():
hdrgo = ntgo.GO if ntgo.is_hdrgo else usrgo2hdrgo[ntgo.GO]
go2txt[goid] = hdrgo2sectxt[hdrgo]
return go2txt | [
"def",
"get_go2sectiontxt",
"(",
"self",
")",
":",
"go2txt",
"=",
"{",
"}",
"_get_secs",
"=",
"self",
".",
"hdrobj",
".",
"get_sections",
"hdrgo2sectxt",
"=",
"{",
"h",
":",
"\" \"",
".",
"join",
"(",
"_get_secs",
"(",
"h",
")",
")",
"for",
"h",
"in"... | Return a dict with actual header and user GO IDs as keys and their sections as values. | [
"Return",
"a",
"dict",
"with",
"actual",
"header",
"and",
"user",
"GO",
"IDs",
"as",
"keys",
"and",
"their",
"sections",
"as",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L219-L228 | train | 223,531 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_usrgo2sections | def get_usrgo2sections(self):
"""Return a dict with all user GO IDs as keys and their sections as values."""
usrgo2sections = cx.defaultdict(set)
usrgo2hdrgo = self.get_usrgo2hdrgo()
get_sections = self.hdrobj.get_sections
for usrgo, hdrgo in usrgo2hdrgo.items():
sections = set(get_sections(hdrgo))
usrgo2sections[usrgo] |= sections
assert len(usrgo2sections) >= len(self.usrgos), \
"uGOS({U}) != uGO2sections({H}): {GOs}".format(
U=len(self.usrgos),
H=len(usrgo2sections),
GOs=self.usrgos.symmetric_difference(set(usrgo2sections.keys())))
return usrgo2sections | python | def get_usrgo2sections(self):
"""Return a dict with all user GO IDs as keys and their sections as values."""
usrgo2sections = cx.defaultdict(set)
usrgo2hdrgo = self.get_usrgo2hdrgo()
get_sections = self.hdrobj.get_sections
for usrgo, hdrgo in usrgo2hdrgo.items():
sections = set(get_sections(hdrgo))
usrgo2sections[usrgo] |= sections
assert len(usrgo2sections) >= len(self.usrgos), \
"uGOS({U}) != uGO2sections({H}): {GOs}".format(
U=len(self.usrgos),
H=len(usrgo2sections),
GOs=self.usrgos.symmetric_difference(set(usrgo2sections.keys())))
return usrgo2sections | [
"def",
"get_usrgo2sections",
"(",
"self",
")",
":",
"usrgo2sections",
"=",
"cx",
".",
"defaultdict",
"(",
"set",
")",
"usrgo2hdrgo",
"=",
"self",
".",
"get_usrgo2hdrgo",
"(",
")",
"get_sections",
"=",
"self",
".",
"hdrobj",
".",
"get_sections",
"for",
"usrgo... | Return a dict with all user GO IDs as keys and their sections as values. | [
"Return",
"a",
"dict",
"with",
"all",
"user",
"GO",
"IDs",
"as",
"keys",
"and",
"their",
"sections",
"as",
"values",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L230-L243 | train | 223,532 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper.get_fout_base | def get_fout_base(self, goid, name=None, pre="gogrp"):
"""Get filename for a group of GO IDs under a single header GO ID."""
goobj = self.gosubdag.go2obj[goid]
if name is None:
name = self.grpname.replace(" ", "_")
sections = "_".join(self.hdrobj.get_sections(goid))
return "{PRE}_{BP}_{NAME}_{SEC}_{DSTR}_{D1s}_{GO}".format(
PRE=pre,
BP=Consts.NAMESPACE2NS[goobj.namespace],
NAME=self._str_replace(name),
SEC=self._str_replace(self._str_replace(sections)),
GO=goid.replace(":", ""),
DSTR=self._get_depthsr(goobj),
D1s=self.gosubdag.go2nt[goobj.id].D1) | python | def get_fout_base(self, goid, name=None, pre="gogrp"):
"""Get filename for a group of GO IDs under a single header GO ID."""
goobj = self.gosubdag.go2obj[goid]
if name is None:
name = self.grpname.replace(" ", "_")
sections = "_".join(self.hdrobj.get_sections(goid))
return "{PRE}_{BP}_{NAME}_{SEC}_{DSTR}_{D1s}_{GO}".format(
PRE=pre,
BP=Consts.NAMESPACE2NS[goobj.namespace],
NAME=self._str_replace(name),
SEC=self._str_replace(self._str_replace(sections)),
GO=goid.replace(":", ""),
DSTR=self._get_depthsr(goobj),
D1s=self.gosubdag.go2nt[goobj.id].D1) | [
"def",
"get_fout_base",
"(",
"self",
",",
"goid",
",",
"name",
"=",
"None",
",",
"pre",
"=",
"\"gogrp\"",
")",
":",
"goobj",
"=",
"self",
".",
"gosubdag",
".",
"go2obj",
"[",
"goid",
"]",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"self",
".",
... | Get filename for a group of GO IDs under a single header GO ID. | [
"Get",
"filename",
"for",
"a",
"group",
"of",
"GO",
"IDs",
"under",
"a",
"single",
"header",
"GO",
"ID",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L245-L258 | train | 223,533 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper._get_depthsr | def _get_depthsr(self, goobj):
"""Return DNN or RNN depending on if relationships are loaded."""
if 'reldepth' in self.gosubdag.prt_attr['flds']:
return "R{R:02}".format(R=goobj.reldepth)
return "D{D:02}".format(D=goobj.depth) | python | def _get_depthsr(self, goobj):
"""Return DNN or RNN depending on if relationships are loaded."""
if 'reldepth' in self.gosubdag.prt_attr['flds']:
return "R{R:02}".format(R=goobj.reldepth)
return "D{D:02}".format(D=goobj.depth) | [
"def",
"_get_depthsr",
"(",
"self",
",",
"goobj",
")",
":",
"if",
"'reldepth'",
"in",
"self",
".",
"gosubdag",
".",
"prt_attr",
"[",
"'flds'",
"]",
":",
"return",
"\"R{R:02}\"",
".",
"format",
"(",
"R",
"=",
"goobj",
".",
"reldepth",
")",
"return",
"\"... | Return DNN or RNN depending on if relationships are loaded. | [
"Return",
"DNN",
"or",
"RNN",
"depending",
"on",
"if",
"relationships",
"are",
"loaded",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L260-L264 | train | 223,534 |
tanghaibao/goatools | goatools/grouper/grprobj.py | Grouper._str_replace | def _str_replace(txt):
"""Makes a small text amenable to being used in a filename."""
txt = txt.replace(",", "")
txt = txt.replace(" ", "_")
txt = txt.replace(":", "")
txt = txt.replace(".", "")
txt = txt.replace("/", "")
txt = txt.replace("", "")
return txt | python | def _str_replace(txt):
"""Makes a small text amenable to being used in a filename."""
txt = txt.replace(",", "")
txt = txt.replace(" ", "_")
txt = txt.replace(":", "")
txt = txt.replace(".", "")
txt = txt.replace("/", "")
txt = txt.replace("", "")
return txt | [
"def",
"_str_replace",
"(",
"txt",
")",
":",
"txt",
"=",
"txt",
".",
"replace",
"(",
"\",\"",
",",
"\"\"",
")",
"txt",
"=",
"txt",
".",
"replace",
"(",
"\" \"",
",",
"\"_\"",
")",
"txt",
"=",
"txt",
".",
"replace",
"(",
"\":\"",
",",
"\"\"",
")",... | Makes a small text amenable to being used in a filename. | [
"Makes",
"a",
"small",
"text",
"amenable",
"to",
"being",
"used",
"in",
"a",
"filename",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj.py#L267-L275 | train | 223,535 |
tanghaibao/goatools | goatools/rpt/prtfmt.py | PrtFmt.get_prtfmt_list | def get_prtfmt_list(self, flds, add_nl=True):
"""Get print format, given fields."""
fmts = []
for fld in flds:
if fld[:2] == 'p_':
fmts.append('{{{FLD}:8.2e}}'.format(FLD=fld))
elif fld in self.default_fld2fmt:
fmts.append(self.default_fld2fmt[fld])
else:
raise Exception("UNKNOWN FORMAT: {FLD}".format(FLD=fld))
if add_nl:
fmts.append("\n")
return fmts | python | def get_prtfmt_list(self, flds, add_nl=True):
"""Get print format, given fields."""
fmts = []
for fld in flds:
if fld[:2] == 'p_':
fmts.append('{{{FLD}:8.2e}}'.format(FLD=fld))
elif fld in self.default_fld2fmt:
fmts.append(self.default_fld2fmt[fld])
else:
raise Exception("UNKNOWN FORMAT: {FLD}".format(FLD=fld))
if add_nl:
fmts.append("\n")
return fmts | [
"def",
"get_prtfmt_list",
"(",
"self",
",",
"flds",
",",
"add_nl",
"=",
"True",
")",
":",
"fmts",
"=",
"[",
"]",
"for",
"fld",
"in",
"flds",
":",
"if",
"fld",
"[",
":",
"2",
"]",
"==",
"'p_'",
":",
"fmts",
".",
"append",
"(",
"'{{{FLD}:8.2e}}'",
... | Get print format, given fields. | [
"Get",
"print",
"format",
"given",
"fields",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/prtfmt.py#L55-L67 | train | 223,536 |
tanghaibao/goatools | scripts/fetch_associations.py | main | def main():
"""Fetch simple gene-term assocaitions from Golr using bioentity document type, one line per gene."""
import argparse
prs = argparse.ArgumentParser(__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
prs.add_argument('--taxon_id', type=str,
help='NCBI taxon ID, must match exact species/strain used by GO Central, e.g. 4896 for S Pombe')
prs.add_argument('--golr_url', default='http://golr.geneontology.org/solr/', type=str,
help='NCBI taxon ID, must match exact species/strain used by GO Central, e.g. 4896 for S Pombe')
prs.add_argument('-o', default=None, type=str,
help="Specifies the name of the output file")
prs.add_argument('--max_rows', default=100000, type=int,
help="maximum rows to be fetched")
args = prs.parse_args()
solr = pysolr.Solr(args.golr_url, timeout=30)
sys.stderr.write("TAX:"+args.taxon_id+"\n")
results = solr.search(q='document_category:"bioentity" AND taxon:"NCBITaxon:'+args.taxon_id+'"',
fl='bioentity_label,annotation_class_list', rows=args.max_rows)
sys.stderr.write("NUM GENES:"+str(len(results))+"\n")
if (len(results) ==0):
sys.stderr.write("NO RESULTS")
exit(1)
if (len(results) == args.max_rows):
sys.stderr.write("max_rows set too low")
exit(1)
file_out = sys.stdout if args.o is None else open(args.o, 'w')
for r in results:
gene_symbol = r['bioentity_label']
sys.stderr.write(gene_symbol+"\n")
if 'annotation_class_list' in r:
file_out.write(r['bioentity_label']+"\t" + ';'.join(r['annotation_class_list'])+"\n")
else:
sys.stderr.write("no annotations for "+gene_symbol+"\n")
if args.o is not None:
file_out.close()
sys.stdout.write(" WROTE: {}\n".format(args.o)) | python | def main():
"""Fetch simple gene-term assocaitions from Golr using bioentity document type, one line per gene."""
import argparse
prs = argparse.ArgumentParser(__doc__,
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
prs.add_argument('--taxon_id', type=str,
help='NCBI taxon ID, must match exact species/strain used by GO Central, e.g. 4896 for S Pombe')
prs.add_argument('--golr_url', default='http://golr.geneontology.org/solr/', type=str,
help='NCBI taxon ID, must match exact species/strain used by GO Central, e.g. 4896 for S Pombe')
prs.add_argument('-o', default=None, type=str,
help="Specifies the name of the output file")
prs.add_argument('--max_rows', default=100000, type=int,
help="maximum rows to be fetched")
args = prs.parse_args()
solr = pysolr.Solr(args.golr_url, timeout=30)
sys.stderr.write("TAX:"+args.taxon_id+"\n")
results = solr.search(q='document_category:"bioentity" AND taxon:"NCBITaxon:'+args.taxon_id+'"',
fl='bioentity_label,annotation_class_list', rows=args.max_rows)
sys.stderr.write("NUM GENES:"+str(len(results))+"\n")
if (len(results) ==0):
sys.stderr.write("NO RESULTS")
exit(1)
if (len(results) == args.max_rows):
sys.stderr.write("max_rows set too low")
exit(1)
file_out = sys.stdout if args.o is None else open(args.o, 'w')
for r in results:
gene_symbol = r['bioentity_label']
sys.stderr.write(gene_symbol+"\n")
if 'annotation_class_list' in r:
file_out.write(r['bioentity_label']+"\t" + ';'.join(r['annotation_class_list'])+"\n")
else:
sys.stderr.write("no annotations for "+gene_symbol+"\n")
if args.o is not None:
file_out.close()
sys.stdout.write(" WROTE: {}\n".format(args.o)) | [
"def",
"main",
"(",
")",
":",
"import",
"argparse",
"prs",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"__doc__",
",",
"formatter_class",
"=",
"argparse",
".",
"ArgumentDefaultsHelpFormatter",
")",
"prs",
".",
"add_argument",
"(",
"'--taxon_id'",
",",
"type",
... | Fetch simple gene-term assocaitions from Golr using bioentity document type, one line per gene. | [
"Fetch",
"simple",
"gene",
"-",
"term",
"assocaitions",
"from",
"Golr",
"using",
"bioentity",
"document",
"type",
"one",
"line",
"per",
"gene",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/scripts/fetch_associations.py#L34-L76 | train | 223,537 |
tanghaibao/goatools | goatools/gosubdag/plot/go_name_shorten.py | ShortenText.get_short_plot_name | def get_short_plot_name(self, goobj):
"""Shorten some GO names so plots are smaller."""
name = goobj.name
if self._keep_this(name):
return self.replace_greek(name)
name = name.replace("cellular response to chemical stimulus",
"cellular rsp. to chemical stim.")
depth = goobj.depth
if depth > 1:
name = name.replace("regulation of ", "reg. of ")
name = name.replace("positive reg", "+reg")
name = name.replace("negative reg", "-reg")
name = name.replace("involved in", "in")
if depth > 2:
name = name.replace("antigen processing and presentation", "a.p.p")
name = name.replace("MHC class I", "MHC-I")
if depth == 4:
if goobj.id == "GO:0002460":
before = " ".join([
"adaptive immune response based on somatic recombination of",
"immune receptors built from immunoglobulin superfamily domains"])
name = name.replace(
before,
"rsp. based on somatic recombination of Ig immune receptors")
if depth > 3:
name = name.replace("signaling pathway", "sig. pw.")
name = name.replace("response", "rsp.")
name = name.replace("immunoglobulin superfamily domains", "Ig domains")
name = name.replace("immunoglobulin", "Ig")
if depth > 4:
name = name.replace("production", "prod.")
if depth == 6 or depth == 5:
name = name.replace("tumor necrosis factor", "TNF")
name = self.replace_greek(name)
return name | python | def get_short_plot_name(self, goobj):
"""Shorten some GO names so plots are smaller."""
name = goobj.name
if self._keep_this(name):
return self.replace_greek(name)
name = name.replace("cellular response to chemical stimulus",
"cellular rsp. to chemical stim.")
depth = goobj.depth
if depth > 1:
name = name.replace("regulation of ", "reg. of ")
name = name.replace("positive reg", "+reg")
name = name.replace("negative reg", "-reg")
name = name.replace("involved in", "in")
if depth > 2:
name = name.replace("antigen processing and presentation", "a.p.p")
name = name.replace("MHC class I", "MHC-I")
if depth == 4:
if goobj.id == "GO:0002460":
before = " ".join([
"adaptive immune response based on somatic recombination of",
"immune receptors built from immunoglobulin superfamily domains"])
name = name.replace(
before,
"rsp. based on somatic recombination of Ig immune receptors")
if depth > 3:
name = name.replace("signaling pathway", "sig. pw.")
name = name.replace("response", "rsp.")
name = name.replace("immunoglobulin superfamily domains", "Ig domains")
name = name.replace("immunoglobulin", "Ig")
if depth > 4:
name = name.replace("production", "prod.")
if depth == 6 or depth == 5:
name = name.replace("tumor necrosis factor", "TNF")
name = self.replace_greek(name)
return name | [
"def",
"get_short_plot_name",
"(",
"self",
",",
"goobj",
")",
":",
"name",
"=",
"goobj",
".",
"name",
"if",
"self",
".",
"_keep_this",
"(",
"name",
")",
":",
"return",
"self",
".",
"replace_greek",
"(",
"name",
")",
"name",
"=",
"name",
".",
"replace",... | Shorten some GO names so plots are smaller. | [
"Shorten",
"some",
"GO",
"names",
"so",
"plots",
"are",
"smaller",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_name_shorten.py#L26-L60 | train | 223,538 |
tanghaibao/goatools | goatools/gosubdag/plot/go_name_shorten.py | ShortenText.shorten_go_name_ptbl1 | def shorten_go_name_ptbl1(self, name):
"""Shorten GO name for tables in paper."""
if self._keep_this(name):
return name
name = name.replace("negative", "neg.")
name = name.replace("positive", "pos.")
name = name.replace("response", "rsp.")
name = name.replace("regulation", "reg.")
name = name.replace("antigen processing and presentation", "app.")
return name | python | def shorten_go_name_ptbl1(self, name):
"""Shorten GO name for tables in paper."""
if self._keep_this(name):
return name
name = name.replace("negative", "neg.")
name = name.replace("positive", "pos.")
name = name.replace("response", "rsp.")
name = name.replace("regulation", "reg.")
name = name.replace("antigen processing and presentation", "app.")
return name | [
"def",
"shorten_go_name_ptbl1",
"(",
"self",
",",
"name",
")",
":",
"if",
"self",
".",
"_keep_this",
"(",
"name",
")",
":",
"return",
"name",
"name",
"=",
"name",
".",
"replace",
"(",
"\"negative\"",
",",
"\"neg.\"",
")",
"name",
"=",
"name",
".",
"rep... | Shorten GO name for tables in paper. | [
"Shorten",
"GO",
"name",
"for",
"tables",
"in",
"paper",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_name_shorten.py#L62-L71 | train | 223,539 |
tanghaibao/goatools | goatools/gosubdag/plot/go_name_shorten.py | ShortenText.shorten_go_name_ptbl3 | def shorten_go_name_ptbl3(self, name, dcnt):
"""Shorten GO description for Table 3 in manuscript."""
if self._keep_this(name):
return name
name = name.replace("positive regulation of immune system process",
"+ reg. of immune sys. process")
name = name.replace("positive regulation of immune response",
"+ reg. of immune response")
name = name.replace("positive regulation of cytokine production",
"+ reg. of cytokine production")
if dcnt < 40:
name = name.replace("antigen processing and presentation", "a.p.p.")
if dcnt < 10:
name = name.replace("negative", "-")
name = name.replace("positive", "+")
#name = name.replace("tumor necrosis factor production", "tumor necrosis factor prod.")
name = name.replace("tumor necrosis factor production", "TNF production")
if dcnt < 4:
name = name.replace("regulation", "reg.")
name = name.replace("exogenous ", "")
name = name.replace(" via ", " w/")
name = name.replace("T cell mediated cytotoxicity", "cytotoxicity via T cell")
name = name.replace('involved in', 'in')
name = name.replace('-positive', '+')
return name | python | def shorten_go_name_ptbl3(self, name, dcnt):
"""Shorten GO description for Table 3 in manuscript."""
if self._keep_this(name):
return name
name = name.replace("positive regulation of immune system process",
"+ reg. of immune sys. process")
name = name.replace("positive regulation of immune response",
"+ reg. of immune response")
name = name.replace("positive regulation of cytokine production",
"+ reg. of cytokine production")
if dcnt < 40:
name = name.replace("antigen processing and presentation", "a.p.p.")
if dcnt < 10:
name = name.replace("negative", "-")
name = name.replace("positive", "+")
#name = name.replace("tumor necrosis factor production", "tumor necrosis factor prod.")
name = name.replace("tumor necrosis factor production", "TNF production")
if dcnt < 4:
name = name.replace("regulation", "reg.")
name = name.replace("exogenous ", "")
name = name.replace(" via ", " w/")
name = name.replace("T cell mediated cytotoxicity", "cytotoxicity via T cell")
name = name.replace('involved in', 'in')
name = name.replace('-positive', '+')
return name | [
"def",
"shorten_go_name_ptbl3",
"(",
"self",
",",
"name",
",",
"dcnt",
")",
":",
"if",
"self",
".",
"_keep_this",
"(",
"name",
")",
":",
"return",
"name",
"name",
"=",
"name",
".",
"replace",
"(",
"\"positive regulation of immune system process\"",
",",
"\"+ r... | Shorten GO description for Table 3 in manuscript. | [
"Shorten",
"GO",
"description",
"for",
"Table",
"3",
"in",
"manuscript",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_name_shorten.py#L73-L97 | train | 223,540 |
tanghaibao/goatools | goatools/gosubdag/plot/go_name_shorten.py | ShortenText.shorten_go_name_all | def shorten_go_name_all(self, name):
"""Shorten GO name for tables in paper, supplemental materials, and plots."""
name = self.replace_greek(name)
name = name.replace("MHC class I", "MHC-I")
return name | python | def shorten_go_name_all(self, name):
"""Shorten GO name for tables in paper, supplemental materials, and plots."""
name = self.replace_greek(name)
name = name.replace("MHC class I", "MHC-I")
return name | [
"def",
"shorten_go_name_all",
"(",
"self",
",",
"name",
")",
":",
"name",
"=",
"self",
".",
"replace_greek",
"(",
"name",
")",
"name",
"=",
"name",
".",
"replace",
"(",
"\"MHC class I\"",
",",
"\"MHC-I\"",
")",
"return",
"name"
] | Shorten GO name for tables in paper, supplemental materials, and plots. | [
"Shorten",
"GO",
"name",
"for",
"tables",
"in",
"paper",
"supplemental",
"materials",
"and",
"plots",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_name_shorten.py#L125-L129 | train | 223,541 |
tanghaibao/goatools | goatools/gosubdag/plot/go_name_shorten.py | ShortenText._keep_this | def _keep_this(self, name):
"""Return True if there are to be no modifications to name."""
for keep_name in self.keep:
if name == keep_name:
return True
return False | python | def _keep_this(self, name):
"""Return True if there are to be no modifications to name."""
for keep_name in self.keep:
if name == keep_name:
return True
return False | [
"def",
"_keep_this",
"(",
"self",
",",
"name",
")",
":",
"for",
"keep_name",
"in",
"self",
".",
"keep",
":",
"if",
"name",
"==",
"keep_name",
":",
"return",
"True",
"return",
"False"
] | Return True if there are to be no modifications to name. | [
"Return",
"True",
"if",
"there",
"are",
"to",
"be",
"no",
"modifications",
"to",
"name",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_name_shorten.py#L131-L136 | train | 223,542 |
tanghaibao/goatools | goatools/gosubdag/rpt/wr_xlsx.py | read_d1_letter | def read_d1_letter(fin_txt):
"""Reads letter aliases from a text file created by GoDepth1LettersWr."""
go2letter = {}
re_goid = re.compile(r"(GO:\d{7})")
with open(fin_txt) as ifstrm:
for line in ifstrm:
mtch = re_goid.search(line)
if mtch and line[:1] != ' ':
# Alias is expected to be the first character
go2letter[mtch.group(1)] = line[:1]
return go2letter | python | def read_d1_letter(fin_txt):
"""Reads letter aliases from a text file created by GoDepth1LettersWr."""
go2letter = {}
re_goid = re.compile(r"(GO:\d{7})")
with open(fin_txt) as ifstrm:
for line in ifstrm:
mtch = re_goid.search(line)
if mtch and line[:1] != ' ':
# Alias is expected to be the first character
go2letter[mtch.group(1)] = line[:1]
return go2letter | [
"def",
"read_d1_letter",
"(",
"fin_txt",
")",
":",
"go2letter",
"=",
"{",
"}",
"re_goid",
"=",
"re",
".",
"compile",
"(",
"r\"(GO:\\d{7})\"",
")",
"with",
"open",
"(",
"fin_txt",
")",
"as",
"ifstrm",
":",
"for",
"line",
"in",
"ifstrm",
":",
"mtch",
"="... | Reads letter aliases from a text file created by GoDepth1LettersWr. | [
"Reads",
"letter",
"aliases",
"from",
"a",
"text",
"file",
"created",
"by",
"GoDepth1LettersWr",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/wr_xlsx.py#L66-L76 | train | 223,543 |
tanghaibao/goatools | goatools/gosubdag/rpt/wr_xlsx.py | GoSubDagWr.get_goids_sections | def get_goids_sections(sections):
"""Return all the GO IDs in a 2-D sections list."""
goids_all = set()
for _, goids_sec in sections:
goids_all |= set(goids_sec)
return goids_all | python | def get_goids_sections(sections):
"""Return all the GO IDs in a 2-D sections list."""
goids_all = set()
for _, goids_sec in sections:
goids_all |= set(goids_sec)
return goids_all | [
"def",
"get_goids_sections",
"(",
"sections",
")",
":",
"goids_all",
"=",
"set",
"(",
")",
"for",
"_",
",",
"goids_sec",
"in",
"sections",
":",
"goids_all",
"|=",
"set",
"(",
"goids_sec",
")",
"return",
"goids_all"
] | Return all the GO IDs in a 2-D sections list. | [
"Return",
"all",
"the",
"GO",
"IDs",
"in",
"a",
"2",
"-",
"D",
"sections",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/wr_xlsx.py#L58-L63 | train | 223,544 |
tanghaibao/goatools | goatools/gosubdag/rpt/wr_xlsx.py | GoDepth1LettersWr.prt_txt | def prt_txt(self, prt=sys.stdout, pre=''):
"""Print letters, descendant count, and GO information."""
data_nts = self.get_d1nts()
for ntdata in data_nts:
prt.write("{PRE}{L:1} {NS} {d:6,} D{D:02} {GO} {NAME}\n".format(
PRE=pre,
L=ntdata.D1,
d=ntdata.dcnt,
NS=ntdata.NS,
D=ntdata.depth,
GO=ntdata.GO,
NAME=ntdata.name))
return data_nts | python | def prt_txt(self, prt=sys.stdout, pre=''):
"""Print letters, descendant count, and GO information."""
data_nts = self.get_d1nts()
for ntdata in data_nts:
prt.write("{PRE}{L:1} {NS} {d:6,} D{D:02} {GO} {NAME}\n".format(
PRE=pre,
L=ntdata.D1,
d=ntdata.dcnt,
NS=ntdata.NS,
D=ntdata.depth,
GO=ntdata.GO,
NAME=ntdata.name))
return data_nts | [
"def",
"prt_txt",
"(",
"self",
",",
"prt",
"=",
"sys",
".",
"stdout",
",",
"pre",
"=",
"''",
")",
":",
"data_nts",
"=",
"self",
".",
"get_d1nts",
"(",
")",
"for",
"ntdata",
"in",
"data_nts",
":",
"prt",
".",
"write",
"(",
"\"{PRE}{L:1} {NS} {d:6,} D{D:... | Print letters, descendant count, and GO information. | [
"Print",
"letters",
"descendant",
"count",
"and",
"GO",
"information",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/wr_xlsx.py#L88-L100 | train | 223,545 |
tanghaibao/goatools | goatools/gosubdag/rpt/wr_xlsx.py | GoDepth1LettersWr.wr_xlsx | def wr_xlsx(self, fout_xlsx="gos_depth01.xlsx", **kws):
"""Write xlsx table of depth-01 GO terms and their letter representation."""
data_nts = self.get_d1nts()
if 'fld2col_widths' not in kws:
kws['fld2col_widths'] = {'D1': 6, 'NS':3, 'depth': 5, 'GO': 12, 'name': 40}
if 'hdrs' not in kws:
kws['hdrs'] = self.hdrs
wr_xlsx_tbl(fout_xlsx, data_nts, **kws) | python | def wr_xlsx(self, fout_xlsx="gos_depth01.xlsx", **kws):
"""Write xlsx table of depth-01 GO terms and their letter representation."""
data_nts = self.get_d1nts()
if 'fld2col_widths' not in kws:
kws['fld2col_widths'] = {'D1': 6, 'NS':3, 'depth': 5, 'GO': 12, 'name': 40}
if 'hdrs' not in kws:
kws['hdrs'] = self.hdrs
wr_xlsx_tbl(fout_xlsx, data_nts, **kws) | [
"def",
"wr_xlsx",
"(",
"self",
",",
"fout_xlsx",
"=",
"\"gos_depth01.xlsx\"",
",",
"*",
"*",
"kws",
")",
":",
"data_nts",
"=",
"self",
".",
"get_d1nts",
"(",
")",
"if",
"'fld2col_widths'",
"not",
"in",
"kws",
":",
"kws",
"[",
"'fld2col_widths'",
"]",
"="... | Write xlsx table of depth-01 GO terms and their letter representation. | [
"Write",
"xlsx",
"table",
"of",
"depth",
"-",
"01",
"GO",
"terms",
"and",
"their",
"letter",
"representation",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/wr_xlsx.py#L102-L109 | train | 223,546 |
tanghaibao/goatools | goatools/gosubdag/rpt/wr_xlsx.py | GoDepth1LettersWr.get_d1nts | def get_d1nts(self):
"""Get letters for depth-01 GO terms, descendants count, and GO information."""
data = []
ntdata = cx.namedtuple("NtPrt", "D1 NS dcnt depth GO name")
namespace = None
for ntlet in sorted(self.goone2ntletter.values(),
key=lambda nt: [nt.goobj.namespace, -1 * nt.dcnt, nt.D1]):
goobj = ntlet.goobj
goid = goobj.id
assert len(goobj.parents) == 1
if namespace != goobj.namespace:
namespace = goobj.namespace
ntns = self.ns2nt[namespace]
pobj = ntns.goobj
ns2 = self.str2ns[goobj.namespace]
data.append(ntdata._make([" ", ns2, ntns.dcnt, pobj.depth, pobj.id, pobj.name]))
data.append(ntdata._make(
[ntlet.D1, self.str2ns[namespace], ntlet.dcnt, goobj.depth, goid, goobj.name]))
return data | python | def get_d1nts(self):
"""Get letters for depth-01 GO terms, descendants count, and GO information."""
data = []
ntdata = cx.namedtuple("NtPrt", "D1 NS dcnt depth GO name")
namespace = None
for ntlet in sorted(self.goone2ntletter.values(),
key=lambda nt: [nt.goobj.namespace, -1 * nt.dcnt, nt.D1]):
goobj = ntlet.goobj
goid = goobj.id
assert len(goobj.parents) == 1
if namespace != goobj.namespace:
namespace = goobj.namespace
ntns = self.ns2nt[namespace]
pobj = ntns.goobj
ns2 = self.str2ns[goobj.namespace]
data.append(ntdata._make([" ", ns2, ntns.dcnt, pobj.depth, pobj.id, pobj.name]))
data.append(ntdata._make(
[ntlet.D1, self.str2ns[namespace], ntlet.dcnt, goobj.depth, goid, goobj.name]))
return data | [
"def",
"get_d1nts",
"(",
"self",
")",
":",
"data",
"=",
"[",
"]",
"ntdata",
"=",
"cx",
".",
"namedtuple",
"(",
"\"NtPrt\"",
",",
"\"D1 NS dcnt depth GO name\"",
")",
"namespace",
"=",
"None",
"for",
"ntlet",
"in",
"sorted",
"(",
"self",
".",
"goone2ntlette... | Get letters for depth-01 GO terms, descendants count, and GO information. | [
"Get",
"letters",
"for",
"depth",
"-",
"01",
"GO",
"terms",
"descendants",
"count",
"and",
"GO",
"information",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/wr_xlsx.py#L172-L190 | train | 223,547 |
tanghaibao/goatools | goatools/gosubdag/rpt/wr_xlsx.py | GoDepth1LettersWr._init_ns2nt | def _init_ns2nt(rcntobj):
"""Save depth-00 GO terms ordered using descendants cnt."""
go2dcnt = rcntobj.go2dcnt
ntobj = cx.namedtuple("NtD1", "D1 dcnt goobj")
d0s = rcntobj.depth2goobjs[0]
ns_nt = [(o.namespace, ntobj(D1="", dcnt=go2dcnt[o.id], goobj=o)) for o in d0s]
return cx.OrderedDict(ns_nt) | python | def _init_ns2nt(rcntobj):
"""Save depth-00 GO terms ordered using descendants cnt."""
go2dcnt = rcntobj.go2dcnt
ntobj = cx.namedtuple("NtD1", "D1 dcnt goobj")
d0s = rcntobj.depth2goobjs[0]
ns_nt = [(o.namespace, ntobj(D1="", dcnt=go2dcnt[o.id], goobj=o)) for o in d0s]
return cx.OrderedDict(ns_nt) | [
"def",
"_init_ns2nt",
"(",
"rcntobj",
")",
":",
"go2dcnt",
"=",
"rcntobj",
".",
"go2dcnt",
"ntobj",
"=",
"cx",
".",
"namedtuple",
"(",
"\"NtD1\"",
",",
"\"D1 dcnt goobj\"",
")",
"d0s",
"=",
"rcntobj",
".",
"depth2goobjs",
"[",
"0",
"]",
"ns_nt",
"=",
"["... | Save depth-00 GO terms ordered using descendants cnt. | [
"Save",
"depth",
"-",
"00",
"GO",
"terms",
"ordered",
"using",
"descendants",
"cnt",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/wr_xlsx.py#L193-L199 | train | 223,548 |
tanghaibao/goatools | goatools/grouper/wrxlsx.py | WrXlsxSortedGos._get_xlsx_kws | def _get_xlsx_kws(self, **kws_usr):
"""Return keyword arguments relevant to writing an xlsx."""
kws_xlsx = {'fld2col_widths':self._get_fld2col_widths(**kws_usr), 'items':'GO IDs'}
remaining_keys = set(['title', 'hdrs', 'prt_flds', 'fld2fmt',
'ntval2wbfmtdict', 'ntfld_wbfmt'])
for usr_key, usr_val in kws_usr.items():
if usr_key in remaining_keys:
kws_xlsx[usr_key] = usr_val
return kws_xlsx | python | def _get_xlsx_kws(self, **kws_usr):
"""Return keyword arguments relevant to writing an xlsx."""
kws_xlsx = {'fld2col_widths':self._get_fld2col_widths(**kws_usr), 'items':'GO IDs'}
remaining_keys = set(['title', 'hdrs', 'prt_flds', 'fld2fmt',
'ntval2wbfmtdict', 'ntfld_wbfmt'])
for usr_key, usr_val in kws_usr.items():
if usr_key in remaining_keys:
kws_xlsx[usr_key] = usr_val
return kws_xlsx | [
"def",
"_get_xlsx_kws",
"(",
"self",
",",
"*",
"*",
"kws_usr",
")",
":",
"kws_xlsx",
"=",
"{",
"'fld2col_widths'",
":",
"self",
".",
"_get_fld2col_widths",
"(",
"*",
"*",
"kws_usr",
")",
",",
"'items'",
":",
"'GO IDs'",
"}",
"remaining_keys",
"=",
"set",
... | Return keyword arguments relevant to writing an xlsx. | [
"Return",
"keyword",
"arguments",
"relevant",
"to",
"writing",
"an",
"xlsx",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wrxlsx.py#L113-L121 | train | 223,549 |
tanghaibao/goatools | goatools/grouper/wrxlsx.py | WrXlsxSortedGos._adjust_prt_flds | def _adjust_prt_flds(self, kws_xlsx, desc2nts, shade_hdrgos):
"""Print user-requested fields or provided fields minus info fields."""
# Use xlsx prt_flds from the user, if provided
if "prt_flds" in kws_xlsx:
return kws_xlsx["prt_flds"]
# If the user did not provide specific fields to print in an xlsx file:
dont_print = set(['hdr_idx', 'is_hdrgo', 'is_usrgo'])
# Are we printing GO group headers?
# Build new list of xlsx print fields, excluding those which add no new information
prt_flds_adjusted = []
# Get all namedtuple fields
nt_flds = self.sortobj.get_fields(desc2nts)
# Keep fields intended for print and optionally gray-shade field (format_txt)
# print('FFFFFFFFFFFFFFF WrXlsxSortedGos::_adjust_prt_flds:', nt_flds)
for nt_fld in nt_flds:
if nt_fld not in dont_print:
# Only add grey-shade to hdrgo and section name rows if hdrgo_prt=True
if nt_fld == "format_txt":
if shade_hdrgos is True:
prt_flds_adjusted.append(nt_fld)
else:
prt_flds_adjusted.append(nt_fld)
kws_xlsx['prt_flds'] = prt_flds_adjusted | python | def _adjust_prt_flds(self, kws_xlsx, desc2nts, shade_hdrgos):
"""Print user-requested fields or provided fields minus info fields."""
# Use xlsx prt_flds from the user, if provided
if "prt_flds" in kws_xlsx:
return kws_xlsx["prt_flds"]
# If the user did not provide specific fields to print in an xlsx file:
dont_print = set(['hdr_idx', 'is_hdrgo', 'is_usrgo'])
# Are we printing GO group headers?
# Build new list of xlsx print fields, excluding those which add no new information
prt_flds_adjusted = []
# Get all namedtuple fields
nt_flds = self.sortobj.get_fields(desc2nts)
# Keep fields intended for print and optionally gray-shade field (format_txt)
# print('FFFFFFFFFFFFFFF WrXlsxSortedGos::_adjust_prt_flds:', nt_flds)
for nt_fld in nt_flds:
if nt_fld not in dont_print:
# Only add grey-shade to hdrgo and section name rows if hdrgo_prt=True
if nt_fld == "format_txt":
if shade_hdrgos is True:
prt_flds_adjusted.append(nt_fld)
else:
prt_flds_adjusted.append(nt_fld)
kws_xlsx['prt_flds'] = prt_flds_adjusted | [
"def",
"_adjust_prt_flds",
"(",
"self",
",",
"kws_xlsx",
",",
"desc2nts",
",",
"shade_hdrgos",
")",
":",
"# Use xlsx prt_flds from the user, if provided",
"if",
"\"prt_flds\"",
"in",
"kws_xlsx",
":",
"return",
"kws_xlsx",
"[",
"\"prt_flds\"",
"]",
"# If the user did not... | Print user-requested fields or provided fields minus info fields. | [
"Print",
"user",
"-",
"requested",
"fields",
"or",
"provided",
"fields",
"minus",
"info",
"fields",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wrxlsx.py#L123-L145 | train | 223,550 |
tanghaibao/goatools | goatools/grouper/wrxlsx.py | WrXlsxSortedGos._get_fld2col_widths | def _get_fld2col_widths(self, **kws):
"""Return xlsx column widths based on default and user-specified field-value pairs."""
fld2col_widths = self._init_fld2col_widths()
if 'fld2col_widths' not in kws:
return fld2col_widths
for fld, val in kws['fld2col_widths'].items():
fld2col_widths[fld] = val
return fld2col_widths | python | def _get_fld2col_widths(self, **kws):
"""Return xlsx column widths based on default and user-specified field-value pairs."""
fld2col_widths = self._init_fld2col_widths()
if 'fld2col_widths' not in kws:
return fld2col_widths
for fld, val in kws['fld2col_widths'].items():
fld2col_widths[fld] = val
return fld2col_widths | [
"def",
"_get_fld2col_widths",
"(",
"self",
",",
"*",
"*",
"kws",
")",
":",
"fld2col_widths",
"=",
"self",
".",
"_init_fld2col_widths",
"(",
")",
"if",
"'fld2col_widths'",
"not",
"in",
"kws",
":",
"return",
"fld2col_widths",
"for",
"fld",
",",
"val",
"in",
... | Return xlsx column widths based on default and user-specified field-value pairs. | [
"Return",
"xlsx",
"column",
"widths",
"based",
"on",
"default",
"and",
"user",
"-",
"specified",
"field",
"-",
"value",
"pairs",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wrxlsx.py#L147-L154 | train | 223,551 |
tanghaibao/goatools | goatools/grouper/wrxlsx.py | WrXlsxSortedGos._init_fld2col_widths | def _init_fld2col_widths(self):
"""Return default column widths for writing an Excel Spreadsheet."""
# GO info namedtuple fields: NS dcnt level depth GO D1 name
# GO header namedtuple fields: format_txt hdr_idx
fld2col_widths = GoSubDagWr.fld2col_widths.copy()
for fld, wid in self.oprtfmt.default_fld2col_widths.items():
fld2col_widths[fld] = wid
for fld in get_hdridx_flds():
fld2col_widths[fld] = 2
return fld2col_widths | python | def _init_fld2col_widths(self):
"""Return default column widths for writing an Excel Spreadsheet."""
# GO info namedtuple fields: NS dcnt level depth GO D1 name
# GO header namedtuple fields: format_txt hdr_idx
fld2col_widths = GoSubDagWr.fld2col_widths.copy()
for fld, wid in self.oprtfmt.default_fld2col_widths.items():
fld2col_widths[fld] = wid
for fld in get_hdridx_flds():
fld2col_widths[fld] = 2
return fld2col_widths | [
"def",
"_init_fld2col_widths",
"(",
"self",
")",
":",
"# GO info namedtuple fields: NS dcnt level depth GO D1 name",
"# GO header namedtuple fields: format_txt hdr_idx",
"fld2col_widths",
"=",
"GoSubDagWr",
".",
"fld2col_widths",
".",
"copy",
"(",
")",
"for",
"fld",
",",
"wid... | Return default column widths for writing an Excel Spreadsheet. | [
"Return",
"default",
"column",
"widths",
"for",
"writing",
"an",
"Excel",
"Spreadsheet",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wrxlsx.py#L156-L165 | train | 223,552 |
tanghaibao/goatools | goatools/grouper/wrxlsx.py | WrXlsxSortedGos._get_shade_hdrgos | def _get_shade_hdrgos(**kws):
"""If no hdrgo_prt specified, and these conditions are present -> hdrgo_prt=F."""
# KWS: shade_hdrgos hdrgo_prt section_sortby top_n
if 'shade_hdrgos' in kws:
return kws['shade_hdrgos']
# Return user-sepcified hdrgo_prt, if provided
if 'hdrgo_prt' in kws:
return kws['hdrgo_prt']
# If no hdrgo_prt provided, set hdrgo_prt to False if:
# * section_sortby == True
# * section_sortby = user_sort
# * top_n == N
if 'section_sortby' in kws and kws['section_sortby']:
return False
if 'top_n' in kws and isinstance(kws['top_n'], int):
return False
return True | python | def _get_shade_hdrgos(**kws):
"""If no hdrgo_prt specified, and these conditions are present -> hdrgo_prt=F."""
# KWS: shade_hdrgos hdrgo_prt section_sortby top_n
if 'shade_hdrgos' in kws:
return kws['shade_hdrgos']
# Return user-sepcified hdrgo_prt, if provided
if 'hdrgo_prt' in kws:
return kws['hdrgo_prt']
# If no hdrgo_prt provided, set hdrgo_prt to False if:
# * section_sortby == True
# * section_sortby = user_sort
# * top_n == N
if 'section_sortby' in kws and kws['section_sortby']:
return False
if 'top_n' in kws and isinstance(kws['top_n'], int):
return False
return True | [
"def",
"_get_shade_hdrgos",
"(",
"*",
"*",
"kws",
")",
":",
"# KWS: shade_hdrgos hdrgo_prt section_sortby top_n",
"if",
"'shade_hdrgos'",
"in",
"kws",
":",
"return",
"kws",
"[",
"'shade_hdrgos'",
"]",
"# Return user-sepcified hdrgo_prt, if provided",
"if",
"'hdrgo_prt'",
... | If no hdrgo_prt specified, and these conditions are present -> hdrgo_prt=F. | [
"If",
"no",
"hdrgo_prt",
"specified",
"and",
"these",
"conditions",
"are",
"present",
"-",
">",
"hdrgo_prt",
"=",
"F",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wrxlsx.py#L174-L190 | train | 223,553 |
tanghaibao/goatools | goatools/rpt/goea_nt_xfrm.py | MgrNtGOEAs.dflt_sortby_objgoea | def dflt_sortby_objgoea(goea_res):
"""Default sorting of GOEA results."""
return [getattr(goea_res, 'enrichment'),
getattr(goea_res, 'namespace'),
getattr(goea_res, 'p_uncorrected'),
getattr(goea_res, 'depth'),
getattr(goea_res, 'GO')] | python | def dflt_sortby_objgoea(goea_res):
"""Default sorting of GOEA results."""
return [getattr(goea_res, 'enrichment'),
getattr(goea_res, 'namespace'),
getattr(goea_res, 'p_uncorrected'),
getattr(goea_res, 'depth'),
getattr(goea_res, 'GO')] | [
"def",
"dflt_sortby_objgoea",
"(",
"goea_res",
")",
":",
"return",
"[",
"getattr",
"(",
"goea_res",
",",
"'enrichment'",
")",
",",
"getattr",
"(",
"goea_res",
",",
"'namespace'",
")",
",",
"getattr",
"(",
"goea_res",
",",
"'p_uncorrected'",
")",
",",
"getatt... | Default sorting of GOEA results. | [
"Default",
"sorting",
"of",
"GOEA",
"results",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/goea_nt_xfrm.py#L44-L50 | train | 223,554 |
tanghaibao/goatools | goatools/rpt/goea_nt_xfrm.py | MgrNtGOEAs.dflt_sortby_ntgoea | def dflt_sortby_ntgoea(ntgoea):
"""Default sorting of GOEA results stored in namedtuples."""
return [ntgoea.enrichment,
ntgoea.namespace,
ntgoea.p_uncorrected,
ntgoea.depth,
ntgoea.GO] | python | def dflt_sortby_ntgoea(ntgoea):
"""Default sorting of GOEA results stored in namedtuples."""
return [ntgoea.enrichment,
ntgoea.namespace,
ntgoea.p_uncorrected,
ntgoea.depth,
ntgoea.GO] | [
"def",
"dflt_sortby_ntgoea",
"(",
"ntgoea",
")",
":",
"return",
"[",
"ntgoea",
".",
"enrichment",
",",
"ntgoea",
".",
"namespace",
",",
"ntgoea",
".",
"p_uncorrected",
",",
"ntgoea",
".",
"depth",
",",
"ntgoea",
".",
"GO",
"]"
] | Default sorting of GOEA results stored in namedtuples. | [
"Default",
"sorting",
"of",
"GOEA",
"results",
"stored",
"in",
"namedtuples",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/goea_nt_xfrm.py#L53-L59 | train | 223,555 |
tanghaibao/goatools | goatools/rpt/goea_nt_xfrm.py | MgrNtGOEAs.get_goea_nts_prt | def get_goea_nts_prt(self, fldnames=None, **usr_kws):
"""Return list of namedtuples removing fields which are redundant or verbose."""
kws = usr_kws.copy()
if 'not_fldnames' not in kws:
kws['not_fldnames'] = ['goterm', 'parents', 'children', 'id']
if 'rpt_fmt' not in kws:
kws['rpt_fmt'] = True
return self.get_goea_nts_all(fldnames, **kws) | python | def get_goea_nts_prt(self, fldnames=None, **usr_kws):
"""Return list of namedtuples removing fields which are redundant or verbose."""
kws = usr_kws.copy()
if 'not_fldnames' not in kws:
kws['not_fldnames'] = ['goterm', 'parents', 'children', 'id']
if 'rpt_fmt' not in kws:
kws['rpt_fmt'] = True
return self.get_goea_nts_all(fldnames, **kws) | [
"def",
"get_goea_nts_prt",
"(",
"self",
",",
"fldnames",
"=",
"None",
",",
"*",
"*",
"usr_kws",
")",
":",
"kws",
"=",
"usr_kws",
".",
"copy",
"(",
")",
"if",
"'not_fldnames'",
"not",
"in",
"kws",
":",
"kws",
"[",
"'not_fldnames'",
"]",
"=",
"[",
"'go... | Return list of namedtuples removing fields which are redundant or verbose. | [
"Return",
"list",
"of",
"namedtuples",
"removing",
"fields",
"which",
"are",
"redundant",
"or",
"verbose",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/goea_nt_xfrm.py#L61-L68 | train | 223,556 |
tanghaibao/goatools | goatools/rpt/goea_nt_xfrm.py | MgrNtGOEAs._get_field_values | def _get_field_values(item, fldnames, rpt_fmt=None, itemid2name=None):
"""Return fieldnames and values of either a namedtuple or GOEnrichmentRecord."""
if hasattr(item, "_fldsdefprt"): # Is a GOEnrichmentRecord
return item.get_field_values(fldnames, rpt_fmt, itemid2name)
if hasattr(item, "_fields"): # Is a namedtuple
return [getattr(item, f) for f in fldnames] | python | def _get_field_values(item, fldnames, rpt_fmt=None, itemid2name=None):
"""Return fieldnames and values of either a namedtuple or GOEnrichmentRecord."""
if hasattr(item, "_fldsdefprt"): # Is a GOEnrichmentRecord
return item.get_field_values(fldnames, rpt_fmt, itemid2name)
if hasattr(item, "_fields"): # Is a namedtuple
return [getattr(item, f) for f in fldnames] | [
"def",
"_get_field_values",
"(",
"item",
",",
"fldnames",
",",
"rpt_fmt",
"=",
"None",
",",
"itemid2name",
"=",
"None",
")",
":",
"if",
"hasattr",
"(",
"item",
",",
"\"_fldsdefprt\"",
")",
":",
"# Is a GOEnrichmentRecord",
"return",
"item",
".",
"get_field_val... | Return fieldnames and values of either a namedtuple or GOEnrichmentRecord. | [
"Return",
"fieldnames",
"and",
"values",
"of",
"either",
"a",
"namedtuple",
"or",
"GOEnrichmentRecord",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/goea_nt_xfrm.py#L103-L108 | train | 223,557 |
tanghaibao/goatools | goatools/rpt/goea_nt_xfrm.py | MgrNtGOEAs._get_fieldnames | def _get_fieldnames(item):
"""Return fieldnames of either a namedtuple or GOEnrichmentRecord."""
if hasattr(item, "_fldsdefprt"): # Is a GOEnrichmentRecord
return item.get_prtflds_all()
if hasattr(item, "_fields"): # Is a namedtuple
return item._fields | python | def _get_fieldnames(item):
"""Return fieldnames of either a namedtuple or GOEnrichmentRecord."""
if hasattr(item, "_fldsdefprt"): # Is a GOEnrichmentRecord
return item.get_prtflds_all()
if hasattr(item, "_fields"): # Is a namedtuple
return item._fields | [
"def",
"_get_fieldnames",
"(",
"item",
")",
":",
"if",
"hasattr",
"(",
"item",
",",
"\"_fldsdefprt\"",
")",
":",
"# Is a GOEnrichmentRecord",
"return",
"item",
".",
"get_prtflds_all",
"(",
")",
"if",
"hasattr",
"(",
"item",
",",
"\"_fields\"",
")",
":",
"# I... | Return fieldnames of either a namedtuple or GOEnrichmentRecord. | [
"Return",
"fieldnames",
"of",
"either",
"a",
"namedtuple",
"or",
"GOEnrichmentRecord",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/goea_nt_xfrm.py#L111-L116 | train | 223,558 |
tanghaibao/goatools | goatools/grouper/colors.py | GrouperColors.get_bordercolor | def get_bordercolor(self):
"""Get bordercolor based on hdrgos and usergos."""
hdrgos_all = self.grprobj.hdrobj.get_hdrgos()
hdrgos_unused = hdrgos_all.difference(self.hdrgos_actual)
go2bordercolor = {}
# hdrgos that went unused
for hdrgo in hdrgos_unused:
go2bordercolor[hdrgo] = self.hdrcol_all
# hdrgos used in this grouping that are NOT usrgos
for hdrgo in self.grprobj.hdrgo2usrgos.keys():
go2bordercolor[hdrgo] = self.hdrcol_all
# hdrgos used in this grouping that ARE usrgos
for hdrgo in self.grprobj.hdrgo_is_usrgo:
go2bordercolor[hdrgo] = 'blue'
# usrgos which are NOT hdrgos
usrgos_rem = self.grprobj.usrgos.difference(self.grprobj.hdrgo_is_usrgo)
for usrgo in usrgos_rem:
go2bordercolor[usrgo] = '#029386' # teal
# print("{N:5} hdrgos actual".format(N=len(self.hdrgos_actual)))
# print("{N:5} hdrgos unused".format(N=len(hdrgos_unused)))
# print("{N:5} hdrgos only BLACK".format(N=len(self.grprobj.hdrgo2usrgos.keys())))
# print("{N:5} usrgos".format(N=len(self.grprobj.usrgos)))
# print("{N:5} usrgos AND hdrgos BLUE".format(N=len(self.grprobj.hdrgo_is_usrgo)))
# print("{N:5} usrgos Only".format(N=len(usrgos_rem)))
return go2bordercolor | python | def get_bordercolor(self):
"""Get bordercolor based on hdrgos and usergos."""
hdrgos_all = self.grprobj.hdrobj.get_hdrgos()
hdrgos_unused = hdrgos_all.difference(self.hdrgos_actual)
go2bordercolor = {}
# hdrgos that went unused
for hdrgo in hdrgos_unused:
go2bordercolor[hdrgo] = self.hdrcol_all
# hdrgos used in this grouping that are NOT usrgos
for hdrgo in self.grprobj.hdrgo2usrgos.keys():
go2bordercolor[hdrgo] = self.hdrcol_all
# hdrgos used in this grouping that ARE usrgos
for hdrgo in self.grprobj.hdrgo_is_usrgo:
go2bordercolor[hdrgo] = 'blue'
# usrgos which are NOT hdrgos
usrgos_rem = self.grprobj.usrgos.difference(self.grprobj.hdrgo_is_usrgo)
for usrgo in usrgos_rem:
go2bordercolor[usrgo] = '#029386' # teal
# print("{N:5} hdrgos actual".format(N=len(self.hdrgos_actual)))
# print("{N:5} hdrgos unused".format(N=len(hdrgos_unused)))
# print("{N:5} hdrgos only BLACK".format(N=len(self.grprobj.hdrgo2usrgos.keys())))
# print("{N:5} usrgos".format(N=len(self.grprobj.usrgos)))
# print("{N:5} usrgos AND hdrgos BLUE".format(N=len(self.grprobj.hdrgo_is_usrgo)))
# print("{N:5} usrgos Only".format(N=len(usrgos_rem)))
return go2bordercolor | [
"def",
"get_bordercolor",
"(",
"self",
")",
":",
"hdrgos_all",
"=",
"self",
".",
"grprobj",
".",
"hdrobj",
".",
"get_hdrgos",
"(",
")",
"hdrgos_unused",
"=",
"hdrgos_all",
".",
"difference",
"(",
"self",
".",
"hdrgos_actual",
")",
"go2bordercolor",
"=",
"{",... | Get bordercolor based on hdrgos and usergos. | [
"Get",
"bordercolor",
"based",
"on",
"hdrgos",
"and",
"usergos",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/colors.py#L18-L42 | train | 223,559 |
tanghaibao/goatools | goatools/grouper/colors.py | GrouperColors.get_go2color_users | def get_go2color_users(self,
usrgo_color='#feffa3', # yellow
hdrusrgo_color='#d4ffea', # green
hdrgo_color='#eee6f6'): # purple
"""Get go2color for GO DAG plots."""
go2color = {}
# Color user GO IDs
for goid in self.usrgos:
go2color[goid] = usrgo_color
# Color header GO IDs. Headers which are also GO IDs get their own color.
for goid_hdr in self.hdrgos_actual:
go2color[goid_hdr] = hdrusrgo_color if goid_hdr in self.usrgos else hdrgo_color
return go2color | python | def get_go2color_users(self,
usrgo_color='#feffa3', # yellow
hdrusrgo_color='#d4ffea', # green
hdrgo_color='#eee6f6'): # purple
"""Get go2color for GO DAG plots."""
go2color = {}
# Color user GO IDs
for goid in self.usrgos:
go2color[goid] = usrgo_color
# Color header GO IDs. Headers which are also GO IDs get their own color.
for goid_hdr in self.hdrgos_actual:
go2color[goid_hdr] = hdrusrgo_color if goid_hdr in self.usrgos else hdrgo_color
return go2color | [
"def",
"get_go2color_users",
"(",
"self",
",",
"usrgo_color",
"=",
"'#feffa3'",
",",
"# yellow",
"hdrusrgo_color",
"=",
"'#d4ffea'",
",",
"# green",
"hdrgo_color",
"=",
"'#eee6f6'",
")",
":",
"# purple",
"go2color",
"=",
"{",
"}",
"# Color user GO IDs",
"for",
"... | Get go2color for GO DAG plots. | [
"Get",
"go2color",
"for",
"GO",
"DAG",
"plots",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/colors.py#L44-L56 | train | 223,560 |
tanghaibao/goatools | goatools/grouper/aart_geneproducts_all.py | AArtGeneProductSetsAll.run | def run(self, name, goea_nts, log):
"""Run gene product ASCII art."""
objaart = AArtGeneProductSetsOne(name, goea_nts, self)
if self.hdrobj.sections:
return objaart.prt_report_grp1(log)
else:
return objaart.prt_report_grp0(log) | python | def run(self, name, goea_nts, log):
"""Run gene product ASCII art."""
objaart = AArtGeneProductSetsOne(name, goea_nts, self)
if self.hdrobj.sections:
return objaart.prt_report_grp1(log)
else:
return objaart.prt_report_grp0(log) | [
"def",
"run",
"(",
"self",
",",
"name",
",",
"goea_nts",
",",
"log",
")",
":",
"objaart",
"=",
"AArtGeneProductSetsOne",
"(",
"name",
",",
"goea_nts",
",",
"self",
")",
"if",
"self",
".",
"hdrobj",
".",
"sections",
":",
"return",
"objaart",
".",
"prt_r... | Run gene product ASCII art. | [
"Run",
"gene",
"product",
"ASCII",
"art",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_all.py#L40-L46 | train | 223,561 |
tanghaibao/goatools | goatools/grouper/aart_geneproducts_all.py | AArtGeneProductSetsAll.get_chr2idx | def get_chr2idx(self):
"""Return a dict with the ASCII art character as key and its index as value."""
return {chr(ascii_int):idx for idx, ascii_int in enumerate(self.all_chrints)} | python | def get_chr2idx(self):
"""Return a dict with the ASCII art character as key and its index as value."""
return {chr(ascii_int):idx for idx, ascii_int in enumerate(self.all_chrints)} | [
"def",
"get_chr2idx",
"(",
"self",
")",
":",
"return",
"{",
"chr",
"(",
"ascii_int",
")",
":",
"idx",
"for",
"idx",
",",
"ascii_int",
"in",
"enumerate",
"(",
"self",
".",
"all_chrints",
")",
"}"
] | Return a dict with the ASCII art character as key and its index as value. | [
"Return",
"a",
"dict",
"with",
"the",
"ASCII",
"art",
"character",
"as",
"key",
"and",
"its",
"index",
"as",
"value",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_all.py#L99-L101 | train | 223,562 |
tanghaibao/goatools | goatools/grouper/aart_geneproducts_all.py | AArtGeneProductSetsAll._init_kws | def _init_kws(self):
"""Fill default values for keyword args, if necessary."""
# Return user-specified GO formatting, if specfied:
if 'fmtgo' not in self.kws:
self.kws['fmtgo'] = self.grprdflt.gosubdag.prt_attr['fmt'] + "\n"
if 'fmtgo2' not in self.kws:
self.kws['fmtgo2'] = self.grprdflt.gosubdag.prt_attr['fmt'] + "\n"
if 'fmtgene' not in self.kws:
if 'itemid2name' not in self.kws:
self.kws['fmtgene'] = "{AART} {ID}\n"
else:
self.kws['fmtgene'] = "{AART} {ID} {NAME}\n"
if 'fmtgene2' not in self.kws:
self.kws['fmtgene2'] = self.kws['fmtgene'] | python | def _init_kws(self):
"""Fill default values for keyword args, if necessary."""
# Return user-specified GO formatting, if specfied:
if 'fmtgo' not in self.kws:
self.kws['fmtgo'] = self.grprdflt.gosubdag.prt_attr['fmt'] + "\n"
if 'fmtgo2' not in self.kws:
self.kws['fmtgo2'] = self.grprdflt.gosubdag.prt_attr['fmt'] + "\n"
if 'fmtgene' not in self.kws:
if 'itemid2name' not in self.kws:
self.kws['fmtgene'] = "{AART} {ID}\n"
else:
self.kws['fmtgene'] = "{AART} {ID} {NAME}\n"
if 'fmtgene2' not in self.kws:
self.kws['fmtgene2'] = self.kws['fmtgene'] | [
"def",
"_init_kws",
"(",
"self",
")",
":",
"# Return user-specified GO formatting, if specfied:",
"if",
"'fmtgo'",
"not",
"in",
"self",
".",
"kws",
":",
"self",
".",
"kws",
"[",
"'fmtgo'",
"]",
"=",
"self",
".",
"grprdflt",
".",
"gosubdag",
".",
"prt_attr",
... | Fill default values for keyword args, if necessary. | [
"Fill",
"default",
"values",
"for",
"keyword",
"args",
"if",
"necessary",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/aart_geneproducts_all.py#L103-L116 | train | 223,563 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitGOs._init_relationships | def _init_relationships(self, relationships_arg):
"""Return a set of relationships found in all subset GO Terms."""
if relationships_arg:
relationships_all = self._get_all_relationships()
if relationships_arg is True:
return relationships_all
else:
return relationships_all.intersection(relationships_arg)
return set() | python | def _init_relationships(self, relationships_arg):
"""Return a set of relationships found in all subset GO Terms."""
if relationships_arg:
relationships_all = self._get_all_relationships()
if relationships_arg is True:
return relationships_all
else:
return relationships_all.intersection(relationships_arg)
return set() | [
"def",
"_init_relationships",
"(",
"self",
",",
"relationships_arg",
")",
":",
"if",
"relationships_arg",
":",
"relationships_all",
"=",
"self",
".",
"_get_all_relationships",
"(",
")",
"if",
"relationships_arg",
"is",
"True",
":",
"return",
"relationships_all",
"el... | Return a set of relationships found in all subset GO Terms. | [
"Return",
"a",
"set",
"of",
"relationships",
"found",
"in",
"all",
"subset",
"GO",
"Terms",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L39-L47 | train | 223,564 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitGOs._get_all_relationships | def _get_all_relationships(self):
"""Return all relationships seen in GO Dag subset."""
relationships_all = set()
for goterm in self.go2obj.values():
if goterm.relationship:
relationships_all.update(goterm.relationship)
if goterm.relationship_rev:
relationships_all.update(goterm.relationship_rev)
return relationships_all | python | def _get_all_relationships(self):
"""Return all relationships seen in GO Dag subset."""
relationships_all = set()
for goterm in self.go2obj.values():
if goterm.relationship:
relationships_all.update(goterm.relationship)
if goterm.relationship_rev:
relationships_all.update(goterm.relationship_rev)
return relationships_all | [
"def",
"_get_all_relationships",
"(",
"self",
")",
":",
"relationships_all",
"=",
"set",
"(",
")",
"for",
"goterm",
"in",
"self",
".",
"go2obj",
".",
"values",
"(",
")",
":",
"if",
"goterm",
".",
"relationship",
":",
"relationships_all",
".",
"update",
"("... | Return all relationships seen in GO Dag subset. | [
"Return",
"all",
"relationships",
"seen",
"in",
"GO",
"Dag",
"subset",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L49-L57 | train | 223,565 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitGOs._init_gos | def _init_gos(self, go_sources_arg, relationships_arg):
"""Initialize GO sources."""
# No GO sources provided
if not go_sources_arg:
assert self.go2obj_orig, "go2obj MUST BE PRESENT IF go_sources IS NOT"
self.go_sources = set(self.go2obj_orig)
self.go2obj = self.go2obj_orig
sys.stdout.write("**NOTE: {N:,} SOURCE GO IDS\n".format(N=len(self.go_sources)))
return
# GO sources provided
go_sources = self._init_go_sources(go_sources_arg, self.go2obj_orig)
# Create new go2obj_user subset matching GO sources
# Fill with source and parent GO IDs and alternate GO IDs
go2obj_user = {}
objrel = CurNHigher(relationships_arg, self.go2obj_orig)
objrel.get_id2obj_cur_n_high(go2obj_user, go_sources)
# Add additional GOTerm information, if needed for user task
kws_gos = {k:v for k, v in self.kws.items() if k in self.kws_aux_gos}
if kws_gos:
self._add_goterms_kws(go2obj_user, kws_gos)
self.go_sources = go_sources
self.go2obj = go2obj_user | python | def _init_gos(self, go_sources_arg, relationships_arg):
"""Initialize GO sources."""
# No GO sources provided
if not go_sources_arg:
assert self.go2obj_orig, "go2obj MUST BE PRESENT IF go_sources IS NOT"
self.go_sources = set(self.go2obj_orig)
self.go2obj = self.go2obj_orig
sys.stdout.write("**NOTE: {N:,} SOURCE GO IDS\n".format(N=len(self.go_sources)))
return
# GO sources provided
go_sources = self._init_go_sources(go_sources_arg, self.go2obj_orig)
# Create new go2obj_user subset matching GO sources
# Fill with source and parent GO IDs and alternate GO IDs
go2obj_user = {}
objrel = CurNHigher(relationships_arg, self.go2obj_orig)
objrel.get_id2obj_cur_n_high(go2obj_user, go_sources)
# Add additional GOTerm information, if needed for user task
kws_gos = {k:v for k, v in self.kws.items() if k in self.kws_aux_gos}
if kws_gos:
self._add_goterms_kws(go2obj_user, kws_gos)
self.go_sources = go_sources
self.go2obj = go2obj_user | [
"def",
"_init_gos",
"(",
"self",
",",
"go_sources_arg",
",",
"relationships_arg",
")",
":",
"# No GO sources provided",
"if",
"not",
"go_sources_arg",
":",
"assert",
"self",
".",
"go2obj_orig",
",",
"\"go2obj MUST BE PRESENT IF go_sources IS NOT\"",
"self",
".",
"go_sou... | Initialize GO sources. | [
"Initialize",
"GO",
"sources",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L59-L80 | train | 223,566 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitGOs._add_goterms_kws | def _add_goterms_kws(self, go2obj_user, kws_gos):
"""Add more GOTerms to go2obj_user, if requested and relevant."""
if 'go2color' in kws_gos:
for goid in kws_gos['go2color'].keys():
self._add_goterms(go2obj_user, goid) | python | def _add_goterms_kws(self, go2obj_user, kws_gos):
"""Add more GOTerms to go2obj_user, if requested and relevant."""
if 'go2color' in kws_gos:
for goid in kws_gos['go2color'].keys():
self._add_goterms(go2obj_user, goid) | [
"def",
"_add_goterms_kws",
"(",
"self",
",",
"go2obj_user",
",",
"kws_gos",
")",
":",
"if",
"'go2color'",
"in",
"kws_gos",
":",
"for",
"goid",
"in",
"kws_gos",
"[",
"'go2color'",
"]",
".",
"keys",
"(",
")",
":",
"self",
".",
"_add_goterms",
"(",
"go2obj_... | Add more GOTerms to go2obj_user, if requested and relevant. | [
"Add",
"more",
"GOTerms",
"to",
"go2obj_user",
"if",
"requested",
"and",
"relevant",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L82-L86 | train | 223,567 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitGOs._add_goterms | def _add_goterms(self, go2obj_user, goid):
"""Add alt GO IDs to go2obj subset, if requested and relevant."""
goterm = self.go2obj_orig[goid]
if goid != goterm.id and goterm.id in go2obj_user and goid not in go2obj_user:
go2obj_user[goid] = goterm | python | def _add_goterms(self, go2obj_user, goid):
"""Add alt GO IDs to go2obj subset, if requested and relevant."""
goterm = self.go2obj_orig[goid]
if goid != goterm.id and goterm.id in go2obj_user and goid not in go2obj_user:
go2obj_user[goid] = goterm | [
"def",
"_add_goterms",
"(",
"self",
",",
"go2obj_user",
",",
"goid",
")",
":",
"goterm",
"=",
"self",
".",
"go2obj_orig",
"[",
"goid",
"]",
"if",
"goid",
"!=",
"goterm",
".",
"id",
"and",
"goterm",
".",
"id",
"in",
"go2obj_user",
"and",
"goid",
"not",
... | Add alt GO IDs to go2obj subset, if requested and relevant. | [
"Add",
"alt",
"GO",
"IDs",
"to",
"go2obj",
"subset",
"if",
"requested",
"and",
"relevant",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L88-L92 | train | 223,568 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitGOs._init_go_sources | def _init_go_sources(self, go_sources_arg, go2obj_arg):
"""Return GO sources which are present in GODag."""
gos_user = set(go_sources_arg)
if 'children' in self.kws and self.kws['children']:
gos_user |= get_leaf_children(gos_user, go2obj_arg)
gos_godag = set(go2obj_arg)
gos_source = gos_user.intersection(gos_godag)
gos_missing = gos_user.difference(gos_godag)
if not gos_missing:
return gos_source
sys.stdout.write("{N} GO IDs NOT FOUND IN GO DAG: {GOs}\n".format(
N=len(gos_missing), GOs=" ".join([str(e) for e in gos_missing])))
return gos_source | python | def _init_go_sources(self, go_sources_arg, go2obj_arg):
"""Return GO sources which are present in GODag."""
gos_user = set(go_sources_arg)
if 'children' in self.kws and self.kws['children']:
gos_user |= get_leaf_children(gos_user, go2obj_arg)
gos_godag = set(go2obj_arg)
gos_source = gos_user.intersection(gos_godag)
gos_missing = gos_user.difference(gos_godag)
if not gos_missing:
return gos_source
sys.stdout.write("{N} GO IDs NOT FOUND IN GO DAG: {GOs}\n".format(
N=len(gos_missing), GOs=" ".join([str(e) for e in gos_missing])))
return gos_source | [
"def",
"_init_go_sources",
"(",
"self",
",",
"go_sources_arg",
",",
"go2obj_arg",
")",
":",
"gos_user",
"=",
"set",
"(",
"go_sources_arg",
")",
"if",
"'children'",
"in",
"self",
".",
"kws",
"and",
"self",
".",
"kws",
"[",
"'children'",
"]",
":",
"gos_user"... | Return GO sources which are present in GODag. | [
"Return",
"GO",
"sources",
"which",
"are",
"present",
"in",
"GODag",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L94-L106 | train | 223,569 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitFields.get_rcntobj | def get_rcntobj(self):
"""Return None or user-provided CountRelatives object."""
# rcntobj value in kws can be: None, False, True, CountRelatives object
if 'rcntobj' in self.kws:
rcntobj = self.kws['rcntobj']
if isinstance(rcntobj, CountRelatives):
return rcntobj
return CountRelatives(
self.go2obj, # Subset go2obj contains only items needed by go_sources
self.relationships,
dcnt='dcnt' in self.kw_elems,
go2letter=self.kws.get('go2letter')) | python | def get_rcntobj(self):
"""Return None or user-provided CountRelatives object."""
# rcntobj value in kws can be: None, False, True, CountRelatives object
if 'rcntobj' in self.kws:
rcntobj = self.kws['rcntobj']
if isinstance(rcntobj, CountRelatives):
return rcntobj
return CountRelatives(
self.go2obj, # Subset go2obj contains only items needed by go_sources
self.relationships,
dcnt='dcnt' in self.kw_elems,
go2letter=self.kws.get('go2letter')) | [
"def",
"get_rcntobj",
"(",
"self",
")",
":",
"# rcntobj value in kws can be: None, False, True, CountRelatives object",
"if",
"'rcntobj'",
"in",
"self",
".",
"kws",
":",
"rcntobj",
"=",
"self",
".",
"kws",
"[",
"'rcntobj'",
"]",
"if",
"isinstance",
"(",
"rcntobj",
... | Return None or user-provided CountRelatives object. | [
"Return",
"None",
"or",
"user",
"-",
"provided",
"CountRelatives",
"object",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L123-L134 | train | 223,570 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitFields.get_prt_fmt | def get_prt_fmt(self, alt=False):
"""Return the format for printing GO named tuples and their related information."""
# prt_fmt = [ # rcnt
# '{GO} # {NS} L{level:02} D{depth:02} {GO_name}',
# '{GO} # {NS} {dcnt:6,} L{level:02} D{depth:02} {D1:5} {GO_name}']
prt_fmt = []
if alt:
prt_fmt.append('{GO}{alt:1}')
else:
prt_fmt.append('{GO}')
prt_fmt.append('# {NS}')
if 'dcnt' in self.prt_flds:
prt_fmt.append('{dcnt:5}')
if 'childcnt' in self.prt_flds:
prt_fmt.append('{childcnt:3}')
if 'tcnt' in self.prt_flds:
prt_fmt.append("{tcnt:7,}")
if 'tfreq' in self.prt_flds:
prt_fmt.append("{tfreq:8.6f}")
if 'tinfo' in self.prt_flds:
prt_fmt.append("{tinfo:5.2f}")
prt_fmt.append('L{level:02} D{depth:02}')
if self.relationships:
prt_fmt.append('R{reldepth:02}')
if 'D1' in self.prt_flds:
prt_fmt.append('{D1:5}')
if 'REL' in self.prt_flds:
prt_fmt.append('{REL}')
prt_fmt.append('{rel}')
prt_fmt.append('{GO_name}')
return " ".join(prt_fmt) | python | def get_prt_fmt(self, alt=False):
"""Return the format for printing GO named tuples and their related information."""
# prt_fmt = [ # rcnt
# '{GO} # {NS} L{level:02} D{depth:02} {GO_name}',
# '{GO} # {NS} {dcnt:6,} L{level:02} D{depth:02} {D1:5} {GO_name}']
prt_fmt = []
if alt:
prt_fmt.append('{GO}{alt:1}')
else:
prt_fmt.append('{GO}')
prt_fmt.append('# {NS}')
if 'dcnt' in self.prt_flds:
prt_fmt.append('{dcnt:5}')
if 'childcnt' in self.prt_flds:
prt_fmt.append('{childcnt:3}')
if 'tcnt' in self.prt_flds:
prt_fmt.append("{tcnt:7,}")
if 'tfreq' in self.prt_flds:
prt_fmt.append("{tfreq:8.6f}")
if 'tinfo' in self.prt_flds:
prt_fmt.append("{tinfo:5.2f}")
prt_fmt.append('L{level:02} D{depth:02}')
if self.relationships:
prt_fmt.append('R{reldepth:02}')
if 'D1' in self.prt_flds:
prt_fmt.append('{D1:5}')
if 'REL' in self.prt_flds:
prt_fmt.append('{REL}')
prt_fmt.append('{rel}')
prt_fmt.append('{GO_name}')
return " ".join(prt_fmt) | [
"def",
"get_prt_fmt",
"(",
"self",
",",
"alt",
"=",
"False",
")",
":",
"# prt_fmt = [ # rcnt",
"# '{GO} # {NS} L{level:02} D{depth:02} {GO_name}',",
"# '{GO} # {NS} {dcnt:6,} L{level:02} D{depth:02} {D1:5} {GO_name}']",
"prt_f... | Return the format for printing GO named tuples and their related information. | [
"Return",
"the",
"format",
"for",
"printing",
"GO",
"named",
"tuples",
"and",
"their",
"related",
"information",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L174-L204 | train | 223,571 |
tanghaibao/goatools | goatools/gosubdag/gosubdag_init.py | InitFields._init_kwelems | def _init_kwelems(self):
"""Init set elements."""
ret = set()
if 'rcntobj' in self.kws:
ret.add('dcnt')
ret.add('D1')
if 'tcntobj' in self.kws:
ret.add('tcnt')
ret.add('tfreq')
ret.add('tinfo')
return ret | python | def _init_kwelems(self):
"""Init set elements."""
ret = set()
if 'rcntobj' in self.kws:
ret.add('dcnt')
ret.add('D1')
if 'tcntobj' in self.kws:
ret.add('tcnt')
ret.add('tfreq')
ret.add('tinfo')
return ret | [
"def",
"_init_kwelems",
"(",
"self",
")",
":",
"ret",
"=",
"set",
"(",
")",
"if",
"'rcntobj'",
"in",
"self",
".",
"kws",
":",
"ret",
".",
"add",
"(",
"'dcnt'",
")",
"ret",
".",
"add",
"(",
"'D1'",
")",
"if",
"'tcntobj'",
"in",
"self",
".",
"kws",... | Init set elements. | [
"Init",
"set",
"elements",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/gosubdag_init.py#L248-L258 | train | 223,572 |
tanghaibao/goatools | goatools/anno/extensions/extensions.py | AnnotationExtensions.get_relations_cnt | def get_relations_cnt(self):
"""Get the set of all relations."""
return cx.Counter([e.relation for es in self.exts for e in es]) | python | def get_relations_cnt(self):
"""Get the set of all relations."""
return cx.Counter([e.relation for es in self.exts for e in es]) | [
"def",
"get_relations_cnt",
"(",
"self",
")",
":",
"return",
"cx",
".",
"Counter",
"(",
"[",
"e",
".",
"relation",
"for",
"es",
"in",
"self",
".",
"exts",
"for",
"e",
"in",
"es",
"]",
")"
] | Get the set of all relations. | [
"Get",
"the",
"set",
"of",
"all",
"relations",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/extensions/extensions.py#L40-L42 | train | 223,573 |
tanghaibao/goatools | goatools/gosubdag/plot/go2color.py | Go2Color._init_equiv | def _init_equiv(self):
"""Add equivalent GO IDs to go2color, if necessary."""
gocolored_all = set(self.go2color)
go2obj_usr = self.gosubdag.go2obj
go2color_add = {}
for gocolored_cur, color in self.go2color.items():
# Ignore GOs in go2color that are not in the user set
if gocolored_cur in go2obj_usr:
goobj = go2obj_usr[gocolored_cur]
goids_equiv = goobj.alt_ids.union([goobj.id])
# mrk_alt = "*" if gocolored_cur != goobj.id else ""
# print("COLORED({}) KEY({}){:1} ALL({})".format(
# gocolored_cur, goobj.id, mrk_alt, goids_equiv))
# Loop through GO IDs which are not colored, but are equivalent to colored GO IDs.
for goid_add in goids_equiv.difference(gocolored_all):
if goid_add in go2color_add:
print('**TBD: TWO DIFFERENT COLORS FOR EQUIV GO ID') # pylint: disable=superfluous-parens
go2color_add[goid_add] = color
# print("ADDING {N} GO IDs TO go2color".format(N=len(go2color_add)))
for goid, color in go2color_add.items():
self.go2color[goid] = color | python | def _init_equiv(self):
"""Add equivalent GO IDs to go2color, if necessary."""
gocolored_all = set(self.go2color)
go2obj_usr = self.gosubdag.go2obj
go2color_add = {}
for gocolored_cur, color in self.go2color.items():
# Ignore GOs in go2color that are not in the user set
if gocolored_cur in go2obj_usr:
goobj = go2obj_usr[gocolored_cur]
goids_equiv = goobj.alt_ids.union([goobj.id])
# mrk_alt = "*" if gocolored_cur != goobj.id else ""
# print("COLORED({}) KEY({}){:1} ALL({})".format(
# gocolored_cur, goobj.id, mrk_alt, goids_equiv))
# Loop through GO IDs which are not colored, but are equivalent to colored GO IDs.
for goid_add in goids_equiv.difference(gocolored_all):
if goid_add in go2color_add:
print('**TBD: TWO DIFFERENT COLORS FOR EQUIV GO ID') # pylint: disable=superfluous-parens
go2color_add[goid_add] = color
# print("ADDING {N} GO IDs TO go2color".format(N=len(go2color_add)))
for goid, color in go2color_add.items():
self.go2color[goid] = color | [
"def",
"_init_equiv",
"(",
"self",
")",
":",
"gocolored_all",
"=",
"set",
"(",
"self",
".",
"go2color",
")",
"go2obj_usr",
"=",
"self",
".",
"gosubdag",
".",
"go2obj",
"go2color_add",
"=",
"{",
"}",
"for",
"gocolored_cur",
",",
"color",
"in",
"self",
"."... | Add equivalent GO IDs to go2color, if necessary. | [
"Add",
"equivalent",
"GO",
"IDs",
"to",
"go2color",
"if",
"necessary",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go2color.py#L78-L98 | train | 223,574 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord.get_pvalue | def get_pvalue(self):
"""Returns pval for 1st method, if it exists. Else returns uncorrected pval."""
if self.method_flds:
return getattr(self, "p_{m}".format(m=self.get_method_name()))
return getattr(self, "p_uncorrected") | python | def get_pvalue(self):
"""Returns pval for 1st method, if it exists. Else returns uncorrected pval."""
if self.method_flds:
return getattr(self, "p_{m}".format(m=self.get_method_name()))
return getattr(self, "p_uncorrected") | [
"def",
"get_pvalue",
"(",
"self",
")",
":",
"if",
"self",
".",
"method_flds",
":",
"return",
"getattr",
"(",
"self",
",",
"\"p_{m}\"",
".",
"format",
"(",
"m",
"=",
"self",
".",
"get_method_name",
"(",
")",
")",
")",
"return",
"getattr",
"(",
"self",
... | Returns pval for 1st method, if it exists. Else returns uncorrected pval. | [
"Returns",
"pval",
"for",
"1st",
"method",
"if",
"it",
"exists",
".",
"Else",
"returns",
"uncorrected",
"pval",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L86-L90 | train | 223,575 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord.set_corrected_pval | def set_corrected_pval(self, nt_method, pvalue):
"""Add object attribute based on method name."""
self.method_flds.append(nt_method)
fieldname = "".join(["p_", nt_method.fieldname])
setattr(self, fieldname, pvalue) | python | def set_corrected_pval(self, nt_method, pvalue):
"""Add object attribute based on method name."""
self.method_flds.append(nt_method)
fieldname = "".join(["p_", nt_method.fieldname])
setattr(self, fieldname, pvalue) | [
"def",
"set_corrected_pval",
"(",
"self",
",",
"nt_method",
",",
"pvalue",
")",
":",
"self",
".",
"method_flds",
".",
"append",
"(",
"nt_method",
")",
"fieldname",
"=",
"\"\"",
".",
"join",
"(",
"[",
"\"p_\"",
",",
"nt_method",
".",
"fieldname",
"]",
")"... | Add object attribute based on method name. | [
"Add",
"object",
"attribute",
"based",
"on",
"method",
"name",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L92-L96 | train | 223,576 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord._chk_fields | def _chk_fields(field_data, field_formatter):
"""Check that expected fields are present."""
if len(field_data) == len(field_formatter):
return
len_dat = len(field_data)
len_fmt = len(field_formatter)
msg = [
"FIELD DATA({d}) != FORMATTER({f})".format(d=len_dat, f=len_fmt),
"DAT({N}): {D}".format(N=len_dat, D=field_data),
"FMT({N}): {F}".format(N=len_fmt, F=field_formatter)]
raise Exception("\n".join(msg)) | python | def _chk_fields(field_data, field_formatter):
"""Check that expected fields are present."""
if len(field_data) == len(field_formatter):
return
len_dat = len(field_data)
len_fmt = len(field_formatter)
msg = [
"FIELD DATA({d}) != FORMATTER({f})".format(d=len_dat, f=len_fmt),
"DAT({N}): {D}".format(N=len_dat, D=field_data),
"FMT({N}): {F}".format(N=len_fmt, F=field_formatter)]
raise Exception("\n".join(msg)) | [
"def",
"_chk_fields",
"(",
"field_data",
",",
"field_formatter",
")",
":",
"if",
"len",
"(",
"field_data",
")",
"==",
"len",
"(",
"field_formatter",
")",
":",
"return",
"len_dat",
"=",
"len",
"(",
"field_data",
")",
"len_fmt",
"=",
"len",
"(",
"field_forma... | Check that expected fields are present. | [
"Check",
"that",
"expected",
"fields",
"are",
"present",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L121-L131 | train | 223,577 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord.set_goterm | def set_goterm(self, go2obj):
"""Set goterm and copy GOTerm's name and namespace."""
if self.GO in go2obj:
goterm = go2obj[self.GO]
self.goterm = goterm
self.name = goterm.name
self.depth = goterm.depth
self.NS = self.namespace2NS[self.goterm.namespace] | python | def set_goterm(self, go2obj):
"""Set goterm and copy GOTerm's name and namespace."""
if self.GO in go2obj:
goterm = go2obj[self.GO]
self.goterm = goterm
self.name = goterm.name
self.depth = goterm.depth
self.NS = self.namespace2NS[self.goterm.namespace] | [
"def",
"set_goterm",
"(",
"self",
",",
"go2obj",
")",
":",
"if",
"self",
".",
"GO",
"in",
"go2obj",
":",
"goterm",
"=",
"go2obj",
"[",
"self",
".",
"GO",
"]",
"self",
".",
"goterm",
"=",
"goterm",
"self",
".",
"name",
"=",
"goterm",
".",
"name",
... | Set goterm and copy GOTerm's name and namespace. | [
"Set",
"goterm",
"and",
"copy",
"GOTerm",
"s",
"name",
"and",
"namespace",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L136-L143 | train | 223,578 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord._init_enrichment | def _init_enrichment(self):
"""Mark as 'enriched' or 'purified'."""
if self.study_n:
return 'e' if ((1.0 * self.study_count / self.study_n) >
(1.0 * self.pop_count / self.pop_n)) else 'p'
return 'p' | python | def _init_enrichment(self):
"""Mark as 'enriched' or 'purified'."""
if self.study_n:
return 'e' if ((1.0 * self.study_count / self.study_n) >
(1.0 * self.pop_count / self.pop_n)) else 'p'
return 'p' | [
"def",
"_init_enrichment",
"(",
"self",
")",
":",
"if",
"self",
".",
"study_n",
":",
"return",
"'e'",
"if",
"(",
"(",
"1.0",
"*",
"self",
".",
"study_count",
"/",
"self",
".",
"study_n",
")",
">",
"(",
"1.0",
"*",
"self",
".",
"pop_count",
"/",
"se... | Mark as 'enriched' or 'purified'. | [
"Mark",
"as",
"enriched",
"or",
"purified",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L145-L150 | train | 223,579 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord.get_prtflds_default | def get_prtflds_default(self):
"""Get default fields."""
return self._fldsdefprt[:-1] + \
["p_{M}".format(M=m.fieldname) for m in self.method_flds] + \
[self._fldsdefprt[-1]] | python | def get_prtflds_default(self):
"""Get default fields."""
return self._fldsdefprt[:-1] + \
["p_{M}".format(M=m.fieldname) for m in self.method_flds] + \
[self._fldsdefprt[-1]] | [
"def",
"get_prtflds_default",
"(",
"self",
")",
":",
"return",
"self",
".",
"_fldsdefprt",
"[",
":",
"-",
"1",
"]",
"+",
"[",
"\"p_{M}\"",
".",
"format",
"(",
"M",
"=",
"m",
".",
"fieldname",
")",
"for",
"m",
"in",
"self",
".",
"method_flds",
"]",
... | Get default fields. | [
"Get",
"default",
"fields",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L160-L164 | train | 223,580 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord.get_prtflds_all | def get_prtflds_all(self):
"""When converting to a namedtuple, get all possible fields in their original order."""
flds = []
dont_add = set(['_parents', 'method_flds', 'relationship_rev', 'relationship'])
# Fields: GO NS enrichment name ratio_in_study ratio_in_pop p_uncorrected
# depth study_count p_sm_bonferroni p_fdr_bh study_items
self._flds_append(flds, self.get_prtflds_default(), dont_add)
# Fields: GO NS goterm
# ratio_in_pop pop_n pop_count pop_items name
# ratio_in_study study_n study_count study_items
# method_flds enrichment p_uncorrected p_sm_bonferroni p_fdr_bh
self._flds_append(flds, vars(self).keys(), dont_add)
# Fields: name level is_obsolete namespace id depth parents children _parents alt_ids
self._flds_append(flds, vars(self.goterm).keys(), dont_add)
return flds | python | def get_prtflds_all(self):
"""When converting to a namedtuple, get all possible fields in their original order."""
flds = []
dont_add = set(['_parents', 'method_flds', 'relationship_rev', 'relationship'])
# Fields: GO NS enrichment name ratio_in_study ratio_in_pop p_uncorrected
# depth study_count p_sm_bonferroni p_fdr_bh study_items
self._flds_append(flds, self.get_prtflds_default(), dont_add)
# Fields: GO NS goterm
# ratio_in_pop pop_n pop_count pop_items name
# ratio_in_study study_n study_count study_items
# method_flds enrichment p_uncorrected p_sm_bonferroni p_fdr_bh
self._flds_append(flds, vars(self).keys(), dont_add)
# Fields: name level is_obsolete namespace id depth parents children _parents alt_ids
self._flds_append(flds, vars(self.goterm).keys(), dont_add)
return flds | [
"def",
"get_prtflds_all",
"(",
"self",
")",
":",
"flds",
"=",
"[",
"]",
"dont_add",
"=",
"set",
"(",
"[",
"'_parents'",
",",
"'method_flds'",
",",
"'relationship_rev'",
",",
"'relationship'",
"]",
")",
"# Fields: GO NS enrichment name ratio_in_study ratio_in_pop p_unc... | When converting to a namedtuple, get all possible fields in their original order. | [
"When",
"converting",
"to",
"a",
"namedtuple",
"get",
"all",
"possible",
"fields",
"in",
"their",
"original",
"order",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L166-L180 | train | 223,581 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord._flds_append | def _flds_append(flds, addthese, dont_add):
"""Retain order of fields as we add them once to the list."""
for fld in addthese:
if fld not in flds and fld not in dont_add:
flds.append(fld) | python | def _flds_append(flds, addthese, dont_add):
"""Retain order of fields as we add them once to the list."""
for fld in addthese:
if fld not in flds and fld not in dont_add:
flds.append(fld) | [
"def",
"_flds_append",
"(",
"flds",
",",
"addthese",
",",
"dont_add",
")",
":",
"for",
"fld",
"in",
"addthese",
":",
"if",
"fld",
"not",
"in",
"flds",
"and",
"fld",
"not",
"in",
"dont_add",
":",
"flds",
".",
"append",
"(",
"fld",
")"
] | Retain order of fields as we add them once to the list. | [
"Retain",
"order",
"of",
"fields",
"as",
"we",
"add",
"them",
"once",
"to",
"the",
"list",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L183-L187 | train | 223,582 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord.get_field_values | def get_field_values(self, fldnames, rpt_fmt=True, itemid2name=None):
"""Get flat namedtuple fields for one GOEnrichmentRecord."""
row = []
# Loop through each user field desired
for fld in fldnames:
# 1. Check the GOEnrichmentRecord's attributes
val = getattr(self, fld, None)
if val is not None:
if rpt_fmt:
val = self._get_rpt_fmt(fld, val, itemid2name)
row.append(val)
else:
# 2. Check the GO object for the field
val = getattr(self.goterm, fld, None)
if rpt_fmt:
val = self._get_rpt_fmt(fld, val, itemid2name)
if val is not None:
row.append(val)
else:
# 3. Field not found, raise Exception
self._err_fld(fld, fldnames)
if rpt_fmt:
assert not isinstance(val, list), \
"UNEXPECTED LIST: FIELD({F}) VALUE({V}) FMT({P})".format(
P=rpt_fmt, F=fld, V=val)
return row | python | def get_field_values(self, fldnames, rpt_fmt=True, itemid2name=None):
"""Get flat namedtuple fields for one GOEnrichmentRecord."""
row = []
# Loop through each user field desired
for fld in fldnames:
# 1. Check the GOEnrichmentRecord's attributes
val = getattr(self, fld, None)
if val is not None:
if rpt_fmt:
val = self._get_rpt_fmt(fld, val, itemid2name)
row.append(val)
else:
# 2. Check the GO object for the field
val = getattr(self.goterm, fld, None)
if rpt_fmt:
val = self._get_rpt_fmt(fld, val, itemid2name)
if val is not None:
row.append(val)
else:
# 3. Field not found, raise Exception
self._err_fld(fld, fldnames)
if rpt_fmt:
assert not isinstance(val, list), \
"UNEXPECTED LIST: FIELD({F}) VALUE({V}) FMT({P})".format(
P=rpt_fmt, F=fld, V=val)
return row | [
"def",
"get_field_values",
"(",
"self",
",",
"fldnames",
",",
"rpt_fmt",
"=",
"True",
",",
"itemid2name",
"=",
"None",
")",
":",
"row",
"=",
"[",
"]",
"# Loop through each user field desired",
"for",
"fld",
"in",
"fldnames",
":",
"# 1. Check the GOEnrichmentRecord... | Get flat namedtuple fields for one GOEnrichmentRecord. | [
"Get",
"flat",
"namedtuple",
"fields",
"for",
"one",
"GOEnrichmentRecord",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L189-L214 | train | 223,583 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord._get_rpt_fmt | def _get_rpt_fmt(fld, val, itemid2name=None):
"""Return values in a format amenable to printing in a table."""
if fld.startswith("ratio_"):
return "{N}/{TOT}".format(N=val[0], TOT=val[1])
elif fld in set(['study_items', 'pop_items', 'alt_ids']):
if itemid2name is not None:
val = [itemid2name.get(v, v) for v in val]
return ", ".join([str(v) for v in sorted(val)])
return val | python | def _get_rpt_fmt(fld, val, itemid2name=None):
"""Return values in a format amenable to printing in a table."""
if fld.startswith("ratio_"):
return "{N}/{TOT}".format(N=val[0], TOT=val[1])
elif fld in set(['study_items', 'pop_items', 'alt_ids']):
if itemid2name is not None:
val = [itemid2name.get(v, v) for v in val]
return ", ".join([str(v) for v in sorted(val)])
return val | [
"def",
"_get_rpt_fmt",
"(",
"fld",
",",
"val",
",",
"itemid2name",
"=",
"None",
")",
":",
"if",
"fld",
".",
"startswith",
"(",
"\"ratio_\"",
")",
":",
"return",
"\"{N}/{TOT}\"",
".",
"format",
"(",
"N",
"=",
"val",
"[",
"0",
"]",
",",
"TOT",
"=",
"... | Return values in a format amenable to printing in a table. | [
"Return",
"values",
"in",
"a",
"format",
"amenable",
"to",
"printing",
"in",
"a",
"table",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L217-L225 | train | 223,584 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentRecord._err_fld | def _err_fld(self, fld, fldnames):
"""Unrecognized field. Print detailed Failure message."""
msg = ['ERROR. UNRECOGNIZED FIELD({F})'.format(F=fld)]
actual_flds = set(self.get_prtflds_default() + self.goterm.__dict__.keys())
bad_flds = set(fldnames).difference(set(actual_flds))
if bad_flds:
msg.append("\nGOEA RESULT FIELDS: {}".format(" ".join(self._fldsdefprt)))
msg.append("GO FIELDS: {}".format(" ".join(self.goterm.__dict__.keys())))
msg.append("\nFATAL: {N} UNEXPECTED FIELDS({F})\n".format(
N=len(bad_flds), F=" ".join(bad_flds)))
msg.append(" {N} User-provided fields:".format(N=len(fldnames)))
for idx, fld in enumerate(fldnames, 1):
mrk = "ERROR -->" if fld in bad_flds else ""
msg.append(" {M:>9} {I:>2}) {F}".format(M=mrk, I=idx, F=fld))
raise Exception("\n".join(msg)) | python | def _err_fld(self, fld, fldnames):
"""Unrecognized field. Print detailed Failure message."""
msg = ['ERROR. UNRECOGNIZED FIELD({F})'.format(F=fld)]
actual_flds = set(self.get_prtflds_default() + self.goterm.__dict__.keys())
bad_flds = set(fldnames).difference(set(actual_flds))
if bad_flds:
msg.append("\nGOEA RESULT FIELDS: {}".format(" ".join(self._fldsdefprt)))
msg.append("GO FIELDS: {}".format(" ".join(self.goterm.__dict__.keys())))
msg.append("\nFATAL: {N} UNEXPECTED FIELDS({F})\n".format(
N=len(bad_flds), F=" ".join(bad_flds)))
msg.append(" {N} User-provided fields:".format(N=len(fldnames)))
for idx, fld in enumerate(fldnames, 1):
mrk = "ERROR -->" if fld in bad_flds else ""
msg.append(" {M:>9} {I:>2}) {F}".format(M=mrk, I=idx, F=fld))
raise Exception("\n".join(msg)) | [
"def",
"_err_fld",
"(",
"self",
",",
"fld",
",",
"fldnames",
")",
":",
"msg",
"=",
"[",
"'ERROR. UNRECOGNIZED FIELD({F})'",
".",
"format",
"(",
"F",
"=",
"fld",
")",
"]",
"actual_flds",
"=",
"set",
"(",
"self",
".",
"get_prtflds_default",
"(",
")",
"+",
... | Unrecognized field. Print detailed Failure message. | [
"Unrecognized",
"field",
".",
"Print",
"detailed",
"Failure",
"message",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L227-L241 | train | 223,585 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.run_study_nts | def run_study_nts(self, study, **kws):
"""Run GOEA on study ids. Return results as a list of namedtuples."""
goea_results = self.run_study(study, **kws)
return MgrNtGOEAs(goea_results).get_goea_nts_all() | python | def run_study_nts(self, study, **kws):
"""Run GOEA on study ids. Return results as a list of namedtuples."""
goea_results = self.run_study(study, **kws)
return MgrNtGOEAs(goea_results).get_goea_nts_all() | [
"def",
"run_study_nts",
"(",
"self",
",",
"study",
",",
"*",
"*",
"kws",
")",
":",
"goea_results",
"=",
"self",
".",
"run_study",
"(",
"study",
",",
"*",
"*",
"kws",
")",
"return",
"MgrNtGOEAs",
"(",
"goea_results",
")",
".",
"get_goea_nts_all",
"(",
"... | Run GOEA on study ids. Return results as a list of namedtuples. | [
"Run",
"GOEA",
"on",
"study",
"ids",
".",
"Return",
"results",
"as",
"a",
"list",
"of",
"namedtuples",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L302-L305 | train | 223,586 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.get_results_msg | def get_results_msg(self, results, study):
"""Return summary for GOEA results."""
# To convert msg list to string: "\n".join(msg)
msg = []
if results:
fmt = "{M:6,} GO terms are associated with {N:6,} of {NT:6,}"
stu_items, num_gos_stu = self.get_item_cnt(results, "study_items")
pop_items, num_gos_pop = self.get_item_cnt(results, "pop_items")
stu_txt = fmt.format(N=len(stu_items), M=num_gos_stu, NT=len(set(study)))
pop_txt = fmt.format(N=len(pop_items), M=num_gos_pop, NT=self.pop_n)
msg.append("{POP} population items".format(POP=pop_txt))
msg.append("{STU} study items".format(STU=stu_txt))
return msg | python | def get_results_msg(self, results, study):
"""Return summary for GOEA results."""
# To convert msg list to string: "\n".join(msg)
msg = []
if results:
fmt = "{M:6,} GO terms are associated with {N:6,} of {NT:6,}"
stu_items, num_gos_stu = self.get_item_cnt(results, "study_items")
pop_items, num_gos_pop = self.get_item_cnt(results, "pop_items")
stu_txt = fmt.format(N=len(stu_items), M=num_gos_stu, NT=len(set(study)))
pop_txt = fmt.format(N=len(pop_items), M=num_gos_pop, NT=self.pop_n)
msg.append("{POP} population items".format(POP=pop_txt))
msg.append("{STU} study items".format(STU=stu_txt))
return msg | [
"def",
"get_results_msg",
"(",
"self",
",",
"results",
",",
"study",
")",
":",
"# To convert msg list to string: \"\\n\".join(msg)",
"msg",
"=",
"[",
"]",
"if",
"results",
":",
"fmt",
"=",
"\"{M:6,} GO terms are associated with {N:6,} of {NT:6,}\"",
"stu_items",
",",
"n... | Return summary for GOEA results. | [
"Return",
"summary",
"for",
"GOEA",
"results",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L307-L319 | train | 223,587 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.get_pval_uncorr | def get_pval_uncorr(self, study, log=sys.stdout):
"""Calculate the uncorrected pvalues for study items."""
results = []
study_in_pop = self.pop.intersection(study)
# " 99% 378 of 382 study items found in population"
go2studyitems = get_terms("study", study_in_pop, self.assoc, self.obo_dag, log)
pop_n, study_n = self.pop_n, len(study_in_pop)
allterms = set(go2studyitems).union(set(self.go2popitems))
if log is not None:
# Some study genes may not have been found in the population. Report from orig
study_n_orig = len(study)
perc = 100.0*study_n/study_n_orig if study_n_orig != 0 else 0.0
log.write("{R:3.0f}% {N:>6,} of {M:>6,} study items found in population({P})\n".format(
N=study_n, M=study_n_orig, P=pop_n, R=perc))
if study_n:
log.write("Calculating {N:,} uncorrected p-values using {PFNC}\n".format(
N=len(allterms), PFNC=self.pval_obj.name))
# If no study genes were found in the population, return empty GOEA results
if not study_n:
return []
calc_pvalue = self.pval_obj.calc_pvalue
for goid in allterms:
study_items = go2studyitems.get(goid, set())
study_count = len(study_items)
pop_items = self.go2popitems.get(goid, set())
pop_count = len(pop_items)
one_record = GOEnrichmentRecord(
goid,
p_uncorrected=calc_pvalue(study_count, study_n, pop_count, pop_n),
study_items=study_items,
pop_items=pop_items,
ratio_in_study=(study_count, study_n),
ratio_in_pop=(pop_count, pop_n))
results.append(one_record)
return results | python | def get_pval_uncorr(self, study, log=sys.stdout):
"""Calculate the uncorrected pvalues for study items."""
results = []
study_in_pop = self.pop.intersection(study)
# " 99% 378 of 382 study items found in population"
go2studyitems = get_terms("study", study_in_pop, self.assoc, self.obo_dag, log)
pop_n, study_n = self.pop_n, len(study_in_pop)
allterms = set(go2studyitems).union(set(self.go2popitems))
if log is not None:
# Some study genes may not have been found in the population. Report from orig
study_n_orig = len(study)
perc = 100.0*study_n/study_n_orig if study_n_orig != 0 else 0.0
log.write("{R:3.0f}% {N:>6,} of {M:>6,} study items found in population({P})\n".format(
N=study_n, M=study_n_orig, P=pop_n, R=perc))
if study_n:
log.write("Calculating {N:,} uncorrected p-values using {PFNC}\n".format(
N=len(allterms), PFNC=self.pval_obj.name))
# If no study genes were found in the population, return empty GOEA results
if not study_n:
return []
calc_pvalue = self.pval_obj.calc_pvalue
for goid in allterms:
study_items = go2studyitems.get(goid, set())
study_count = len(study_items)
pop_items = self.go2popitems.get(goid, set())
pop_count = len(pop_items)
one_record = GOEnrichmentRecord(
goid,
p_uncorrected=calc_pvalue(study_count, study_n, pop_count, pop_n),
study_items=study_items,
pop_items=pop_items,
ratio_in_study=(study_count, study_n),
ratio_in_pop=(pop_count, pop_n))
results.append(one_record)
return results | [
"def",
"get_pval_uncorr",
"(",
"self",
",",
"study",
",",
"log",
"=",
"sys",
".",
"stdout",
")",
":",
"results",
"=",
"[",
"]",
"study_in_pop",
"=",
"self",
".",
"pop",
".",
"intersection",
"(",
"study",
")",
"# \" 99% 378 of 382 study items found in pop... | Calculate the uncorrected pvalues for study items. | [
"Calculate",
"the",
"uncorrected",
"pvalues",
"for",
"study",
"items",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L321-L359 | train | 223,588 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.get_study_items | def get_study_items(results):
"""Return a list of study items associated with the given results."""
study_items = set()
for obj in results:
study_items.update(obj.study_items)
return study_items | python | def get_study_items(results):
"""Return a list of study items associated with the given results."""
study_items = set()
for obj in results:
study_items.update(obj.study_items)
return study_items | [
"def",
"get_study_items",
"(",
"results",
")",
":",
"study_items",
"=",
"set",
"(",
")",
"for",
"obj",
"in",
"results",
":",
"study_items",
".",
"update",
"(",
"obj",
".",
"study_items",
")",
"return",
"study_items"
] | Return a list of study items associated with the given results. | [
"Return",
"a",
"list",
"of",
"study",
"items",
"associated",
"with",
"the",
"given",
"results",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L389-L394 | train | 223,589 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy._update_pvalcorr | def _update_pvalcorr(ntmt, corrected_pvals):
"""Add data members to store multiple test corrections."""
if corrected_pvals is None:
return
for rec, val in zip(ntmt.results, corrected_pvals):
rec.set_corrected_pval(ntmt.nt_method, val) | python | def _update_pvalcorr(ntmt, corrected_pvals):
"""Add data members to store multiple test corrections."""
if corrected_pvals is None:
return
for rec, val in zip(ntmt.results, corrected_pvals):
rec.set_corrected_pval(ntmt.nt_method, val) | [
"def",
"_update_pvalcorr",
"(",
"ntmt",
",",
"corrected_pvals",
")",
":",
"if",
"corrected_pvals",
"is",
"None",
":",
"return",
"for",
"rec",
",",
"val",
"in",
"zip",
"(",
"ntmt",
".",
"results",
",",
"corrected_pvals",
")",
":",
"rec",
".",
"set_corrected... | Add data members to store multiple test corrections. | [
"Add",
"data",
"members",
"to",
"store",
"multiple",
"test",
"corrections",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L429-L434 | train | 223,590 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.wr_txt | def wr_txt(self, fout_txt, goea_results, prtfmt=None, **kws):
"""Print GOEA results to text file."""
if not goea_results:
sys.stdout.write(" 0 GOEA results. NOT WRITING {FOUT}\n".format(FOUT=fout_txt))
return
with open(fout_txt, 'w') as prt:
if 'title' in kws:
prt.write("{TITLE}\n".format(TITLE=kws['title']))
data_nts = self.prt_txt(prt, goea_results, prtfmt, **kws)
log = self.log if self.log is not None else sys.stdout
log.write(" {N:>5} GOEA results for {CUR:5} study items. WROTE: {F}\n".format(
N=len(data_nts),
CUR=len(MgrNtGOEAs(goea_results).get_study_items()),
F=fout_txt)) | python | def wr_txt(self, fout_txt, goea_results, prtfmt=None, **kws):
"""Print GOEA results to text file."""
if not goea_results:
sys.stdout.write(" 0 GOEA results. NOT WRITING {FOUT}\n".format(FOUT=fout_txt))
return
with open(fout_txt, 'w') as prt:
if 'title' in kws:
prt.write("{TITLE}\n".format(TITLE=kws['title']))
data_nts = self.prt_txt(prt, goea_results, prtfmt, **kws)
log = self.log if self.log is not None else sys.stdout
log.write(" {N:>5} GOEA results for {CUR:5} study items. WROTE: {F}\n".format(
N=len(data_nts),
CUR=len(MgrNtGOEAs(goea_results).get_study_items()),
F=fout_txt)) | [
"def",
"wr_txt",
"(",
"self",
",",
"fout_txt",
",",
"goea_results",
",",
"prtfmt",
"=",
"None",
",",
"*",
"*",
"kws",
")",
":",
"if",
"not",
"goea_results",
":",
"sys",
".",
"stdout",
".",
"write",
"(",
"\" 0 GOEA results. NOT WRITING {FOUT}\\n\"",
".",... | Print GOEA results to text file. | [
"Print",
"GOEA",
"results",
"to",
"text",
"file",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L437-L450 | train | 223,591 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.prt_txt | def prt_txt(prt, goea_results, prtfmt=None, **kws):
"""Print GOEA results in text format."""
objprt = PrtFmt()
if prtfmt is None:
flds = ['GO', 'NS', 'p_uncorrected',
'ratio_in_study', 'ratio_in_pop', 'depth', 'name', 'study_items']
prtfmt = objprt.get_prtfmt_str(flds)
prtfmt = objprt.adjust_prtfmt(prtfmt)
prt_flds = RPT.get_fmtflds(prtfmt)
data_nts = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
RPT.prt_txt(prt, data_nts, prtfmt, prt_flds, **kws)
return data_nts | python | def prt_txt(prt, goea_results, prtfmt=None, **kws):
"""Print GOEA results in text format."""
objprt = PrtFmt()
if prtfmt is None:
flds = ['GO', 'NS', 'p_uncorrected',
'ratio_in_study', 'ratio_in_pop', 'depth', 'name', 'study_items']
prtfmt = objprt.get_prtfmt_str(flds)
prtfmt = objprt.adjust_prtfmt(prtfmt)
prt_flds = RPT.get_fmtflds(prtfmt)
data_nts = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
RPT.prt_txt(prt, data_nts, prtfmt, prt_flds, **kws)
return data_nts | [
"def",
"prt_txt",
"(",
"prt",
",",
"goea_results",
",",
"prtfmt",
"=",
"None",
",",
"*",
"*",
"kws",
")",
":",
"objprt",
"=",
"PrtFmt",
"(",
")",
"if",
"prtfmt",
"is",
"None",
":",
"flds",
"=",
"[",
"'GO'",
",",
"'NS'",
",",
"'p_uncorrected'",
",",... | Print GOEA results in text format. | [
"Print",
"GOEA",
"results",
"in",
"text",
"format",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L453-L464 | train | 223,592 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.wr_xlsx | def wr_xlsx(self, fout_xlsx, goea_results, **kws):
"""Write a xlsx file."""
# kws: prt_if indent itemid2name(study_items)
objprt = PrtFmt()
prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results))
xlsx_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
if 'fld2col_widths' not in kws:
kws['fld2col_widths'] = {f:objprt.default_fld2col_widths.get(f, 8) for f in prt_flds}
RPT.wr_xlsx(fout_xlsx, xlsx_data, **kws) | python | def wr_xlsx(self, fout_xlsx, goea_results, **kws):
"""Write a xlsx file."""
# kws: prt_if indent itemid2name(study_items)
objprt = PrtFmt()
prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results))
xlsx_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
if 'fld2col_widths' not in kws:
kws['fld2col_widths'] = {f:objprt.default_fld2col_widths.get(f, 8) for f in prt_flds}
RPT.wr_xlsx(fout_xlsx, xlsx_data, **kws) | [
"def",
"wr_xlsx",
"(",
"self",
",",
"fout_xlsx",
",",
"goea_results",
",",
"*",
"*",
"kws",
")",
":",
"# kws: prt_if indent itemid2name(study_items)",
"objprt",
"=",
"PrtFmt",
"(",
")",
"prt_flds",
"=",
"kws",
".",
"get",
"(",
"'prt_flds'",
",",
"self",
".",... | Write a xlsx file. | [
"Write",
"a",
"xlsx",
"file",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L466-L474 | train | 223,593 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.wr_tsv | def wr_tsv(self, fout_tsv, goea_results, **kws):
"""Write tab-separated table data to file"""
prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results))
tsv_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
RPT.wr_tsv(fout_tsv, tsv_data, **kws) | python | def wr_tsv(self, fout_tsv, goea_results, **kws):
"""Write tab-separated table data to file"""
prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results))
tsv_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
RPT.wr_tsv(fout_tsv, tsv_data, **kws) | [
"def",
"wr_tsv",
"(",
"self",
",",
"fout_tsv",
",",
"goea_results",
",",
"*",
"*",
"kws",
")",
":",
"prt_flds",
"=",
"kws",
".",
"get",
"(",
"'prt_flds'",
",",
"self",
".",
"get_prtflds_default",
"(",
"goea_results",
")",
")",
"tsv_data",
"=",
"MgrNtGOEA... | Write tab-separated table data to file | [
"Write",
"tab",
"-",
"separated",
"table",
"data",
"to",
"file"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L476-L480 | train | 223,594 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.prt_tsv | def prt_tsv(self, prt, goea_results, **kws):
"""Write tab-separated table data"""
prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results))
tsv_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
RPT.prt_tsv(prt, tsv_data, **kws) | python | def prt_tsv(self, prt, goea_results, **kws):
"""Write tab-separated table data"""
prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results))
tsv_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws)
RPT.prt_tsv(prt, tsv_data, **kws) | [
"def",
"prt_tsv",
"(",
"self",
",",
"prt",
",",
"goea_results",
",",
"*",
"*",
"kws",
")",
":",
"prt_flds",
"=",
"kws",
".",
"get",
"(",
"'prt_flds'",
",",
"self",
".",
"get_prtflds_default",
"(",
"goea_results",
")",
")",
"tsv_data",
"=",
"MgrNtGOEAs",
... | Write tab-separated table data | [
"Write",
"tab",
"-",
"separated",
"table",
"data"
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L482-L486 | train | 223,595 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.get_ns2nts | def get_ns2nts(results, fldnames=None, **kws):
"""Get namedtuples of GOEA results, split into BP, MF, CC."""
ns2nts = cx.defaultdict(list)
nts = MgrNtGOEAs(results).get_goea_nts_all(fldnames, **kws)
for ntgoea in nts:
ns2nts[ntgoea.NS].append(ntgoea)
return ns2nts | python | def get_ns2nts(results, fldnames=None, **kws):
"""Get namedtuples of GOEA results, split into BP, MF, CC."""
ns2nts = cx.defaultdict(list)
nts = MgrNtGOEAs(results).get_goea_nts_all(fldnames, **kws)
for ntgoea in nts:
ns2nts[ntgoea.NS].append(ntgoea)
return ns2nts | [
"def",
"get_ns2nts",
"(",
"results",
",",
"fldnames",
"=",
"None",
",",
"*",
"*",
"kws",
")",
":",
"ns2nts",
"=",
"cx",
".",
"defaultdict",
"(",
"list",
")",
"nts",
"=",
"MgrNtGOEAs",
"(",
"results",
")",
".",
"get_goea_nts_all",
"(",
"fldnames",
",",
... | Get namedtuples of GOEA results, split into BP, MF, CC. | [
"Get",
"namedtuples",
"of",
"GOEA",
"results",
"split",
"into",
"BP",
"MF",
"CC",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L489-L495 | train | 223,596 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.print_date | def print_date(min_ratio=None, pval=0.05):
"""Print GOATOOLS version and the date the GOEA was run."""
import goatools
# Header contains provenance and parameters
date = datetime.date.today()
print("# Generated by GOATOOLS v{0} ({1})".format(goatools.__version__, date))
print("# min_ratio={0} pval={1}".format(min_ratio, pval)) | python | def print_date(min_ratio=None, pval=0.05):
"""Print GOATOOLS version and the date the GOEA was run."""
import goatools
# Header contains provenance and parameters
date = datetime.date.today()
print("# Generated by GOATOOLS v{0} ({1})".format(goatools.__version__, date))
print("# min_ratio={0} pval={1}".format(min_ratio, pval)) | [
"def",
"print_date",
"(",
"min_ratio",
"=",
"None",
",",
"pval",
"=",
"0.05",
")",
":",
"import",
"goatools",
"# Header contains provenance and parameters",
"date",
"=",
"datetime",
".",
"date",
".",
"today",
"(",
")",
"print",
"(",
"\"# Generated by GOATOOLS v{0}... | Print GOATOOLS version and the date the GOEA was run. | [
"Print",
"GOATOOLS",
"version",
"and",
"the",
"date",
"the",
"GOEA",
"was",
"run",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L523-L530 | train | 223,597 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.print_results | def print_results(self, results, min_ratio=None, indent=False, pval=0.05, prt=sys.stdout):
"""Print GOEA results with some additional statistics calculated."""
results_adj = self.get_adj_records(results, min_ratio, pval)
self.print_results_adj(results_adj, indent, prt) | python | def print_results(self, results, min_ratio=None, indent=False, pval=0.05, prt=sys.stdout):
"""Print GOEA results with some additional statistics calculated."""
results_adj = self.get_adj_records(results, min_ratio, pval)
self.print_results_adj(results_adj, indent, prt) | [
"def",
"print_results",
"(",
"self",
",",
"results",
",",
"min_ratio",
"=",
"None",
",",
"indent",
"=",
"False",
",",
"pval",
"=",
"0.05",
",",
"prt",
"=",
"sys",
".",
"stdout",
")",
":",
"results_adj",
"=",
"self",
".",
"get_adj_records",
"(",
"result... | Print GOEA results with some additional statistics calculated. | [
"Print",
"GOEA",
"results",
"with",
"some",
"additional",
"statistics",
"calculated",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L532-L535 | train | 223,598 |
tanghaibao/goatools | goatools/go_enrichment.py | GOEnrichmentStudy.get_adj_records | def get_adj_records(results, min_ratio=None, pval=0.05):
"""Return GOEA results with some additional statistics calculated."""
records = []
for rec in results:
# calculate some additional statistics
# (over_under, is_ratio_different)
rec.update_remaining_fldsdefprt(min_ratio=min_ratio)
if pval is not None and rec.p_uncorrected >= pval:
continue
if rec.is_ratio_different:
records.append(rec)
return records | python | def get_adj_records(results, min_ratio=None, pval=0.05):
"""Return GOEA results with some additional statistics calculated."""
records = []
for rec in results:
# calculate some additional statistics
# (over_under, is_ratio_different)
rec.update_remaining_fldsdefprt(min_ratio=min_ratio)
if pval is not None and rec.p_uncorrected >= pval:
continue
if rec.is_ratio_different:
records.append(rec)
return records | [
"def",
"get_adj_records",
"(",
"results",
",",
"min_ratio",
"=",
"None",
",",
"pval",
"=",
"0.05",
")",
":",
"records",
"=",
"[",
"]",
"for",
"rec",
"in",
"results",
":",
"# calculate some additional statistics",
"# (over_under, is_ratio_different)",
"rec",
".",
... | Return GOEA results with some additional statistics calculated. | [
"Return",
"GOEA",
"results",
"with",
"some",
"additional",
"statistics",
"calculated",
"."
] | 407682e573a108864a79031f8ca19ee3bf377626 | https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_enrichment.py#L538-L551 | train | 223,599 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.