id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
242,200
tanghaibao/goatools
goatools/godag/go_tasks.py
_get_id2children
def _get_id2children(id2children, item_id, item_obj): """Add the child item IDs for one item object and their children.""" if item_id in id2children: return id2children[item_id] child_ids = set() for child_obj in item_obj.children: child_id = child_obj.item_id child_ids.add(child_id) child_ids |= _get_id2children(id2children, child_id, child_obj) id2children[item_id] = child_ids return child_ids
python
def _get_id2children(id2children, item_id, item_obj): if item_id in id2children: return id2children[item_id] child_ids = set() for child_obj in item_obj.children: child_id = child_obj.item_id child_ids.add(child_id) child_ids |= _get_id2children(id2children, child_id, child_obj) id2children[item_id] = child_ids return child_ids
[ "def", "_get_id2children", "(", "id2children", ",", "item_id", ",", "item_obj", ")", ":", "if", "item_id", "in", "id2children", ":", "return", "id2children", "[", "item_id", "]", "child_ids", "=", "set", "(", ")", "for", "child_obj", "in", "item_obj", ".", ...
Add the child item IDs for one item object and their children.
[ "Add", "the", "child", "item", "IDs", "for", "one", "item", "object", "and", "their", "children", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L62-L72
242,201
tanghaibao/goatools
goatools/godag/go_tasks.py
_get_id2upper
def _get_id2upper(id2upper, item_id, item_obj): """Add the parent item IDs for one item object and their upper.""" if item_id in id2upper: return id2upper[item_id] upper_ids = set() for upper_obj in item_obj.get_goterms_upper(): upper_id = upper_obj.item_id upper_ids.add(upper_id) upper_ids |= _get_id2upper(id2upper, upper_id, upper_obj) id2upper[item_id] = upper_ids return upper_ids
python
def _get_id2upper(id2upper, item_id, item_obj): if item_id in id2upper: return id2upper[item_id] upper_ids = set() for upper_obj in item_obj.get_goterms_upper(): upper_id = upper_obj.item_id upper_ids.add(upper_id) upper_ids |= _get_id2upper(id2upper, upper_id, upper_obj) id2upper[item_id] = upper_ids return upper_ids
[ "def", "_get_id2upper", "(", "id2upper", ",", "item_id", ",", "item_obj", ")", ":", "if", "item_id", "in", "id2upper", ":", "return", "id2upper", "[", "item_id", "]", "upper_ids", "=", "set", "(", ")", "for", "upper_obj", "in", "item_obj", ".", "get_goterm...
Add the parent item IDs for one item object and their upper.
[ "Add", "the", "parent", "item", "IDs", "for", "one", "item", "object", "and", "their", "upper", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L74-L84
242,202
tanghaibao/goatools
goatools/godag/go_tasks.py
_get_id2lower
def _get_id2lower(id2lower, item_id, item_obj): """Add the lower item IDs for one item object and the objects below them.""" if item_id in id2lower: return id2lower[item_id] lower_ids = set() for lower_obj in item_obj.get_goterms_lower(): lower_id = lower_obj.item_id lower_ids.add(lower_id) lower_ids |= _get_id2lower(id2lower, lower_id, lower_obj) id2lower[item_id] = lower_ids return lower_ids
python
def _get_id2lower(id2lower, item_id, item_obj): if item_id in id2lower: return id2lower[item_id] lower_ids = set() for lower_obj in item_obj.get_goterms_lower(): lower_id = lower_obj.item_id lower_ids.add(lower_id) lower_ids |= _get_id2lower(id2lower, lower_id, lower_obj) id2lower[item_id] = lower_ids return lower_ids
[ "def", "_get_id2lower", "(", "id2lower", ",", "item_id", ",", "item_obj", ")", ":", "if", "item_id", "in", "id2lower", ":", "return", "id2lower", "[", "item_id", "]", "lower_ids", "=", "set", "(", ")", "for", "lower_obj", "in", "item_obj", ".", "get_goterm...
Add the lower item IDs for one item object and the objects below them.
[ "Add", "the", "lower", "item", "IDs", "for", "one", "item", "object", "and", "the", "objects", "below", "them", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L86-L96
242,203
tanghaibao/goatools
goatools/godag/go_tasks.py
CurNHigher.fill_parentidid2obj_r0
def fill_parentidid2obj_r0(self, id2obj, child_obj): """Fill id2obj with all parent key item IDs and their objects.""" for parent_obj in child_obj.parents: if parent_obj.item_id not in id2obj: id2obj[parent_obj.item_id] = parent_obj self.fill_parentidid2obj_r0(id2obj, parent_obj)
python
def fill_parentidid2obj_r0(self, id2obj, child_obj): for parent_obj in child_obj.parents: if parent_obj.item_id not in id2obj: id2obj[parent_obj.item_id] = parent_obj self.fill_parentidid2obj_r0(id2obj, parent_obj)
[ "def", "fill_parentidid2obj_r0", "(", "self", ",", "id2obj", ",", "child_obj", ")", ":", "for", "parent_obj", "in", "child_obj", ".", "parents", ":", "if", "parent_obj", ".", "item_id", "not", "in", "id2obj", ":", "id2obj", "[", "parent_obj", ".", "item_id",...
Fill id2obj with all parent key item IDs and their objects.
[ "Fill", "id2obj", "with", "all", "parent", "key", "item", "IDs", "and", "their", "objects", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag/go_tasks.py#L123-L128
242,204
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsBase.prt_ver
def prt_ver(self, prt): """Print version of GO-DAG for the GO and for GO slims.""" if self.ver_list is not None: prt.write("# Versions:\n# {VER}\n\n".format(VER="\n# ".join(self.ver_list)))
python
def prt_ver(self, prt): if self.ver_list is not None: prt.write("# Versions:\n# {VER}\n\n".format(VER="\n# ".join(self.ver_list)))
[ "def", "prt_ver", "(", "self", ",", "prt", ")", ":", "if", "self", ".", "ver_list", "is", "not", "None", ":", "prt", ".", "write", "(", "\"# Versions:\\n# {VER}\\n\\n\"", ".", "format", "(", "VER", "=", "\"\\n# \"", ".", "join", "(", "self", ".", ...
Print version of GO-DAG for the GO and for GO slims.
[ "Print", "version", "of", "GO", "-", "DAG", "for", "the", "GO", "and", "for", "GO", "slims", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L22-L25
242,205
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsBase.get_sections_2dnt
def get_sections_2dnt(self, sec2d_go): """Return a sections list containing sorted lists of namedtuples.""" return [(nm, self.get_ntgos_sorted(gos)) for nm, gos in sec2d_go]
python
def get_sections_2dnt(self, sec2d_go): return [(nm, self.get_ntgos_sorted(gos)) for nm, gos in sec2d_go]
[ "def", "get_sections_2dnt", "(", "self", ",", "sec2d_go", ")", ":", "return", "[", "(", "nm", ",", "self", ".", "get_ntgos_sorted", "(", "gos", ")", ")", "for", "nm", ",", "gos", "in", "sec2d_go", "]" ]
Return a sections list containing sorted lists of namedtuples.
[ "Return", "a", "sections", "list", "containing", "sorted", "lists", "of", "namedtuples", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L27-L29
242,206
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsBase.get_ntgos_sorted
def get_ntgos_sorted(self, hdrgos): """Return sorted Grouper namedtuples if there are user GO IDs underneath.""" go2nt = self.grprobj.go2nt return sorted([go2nt[go] for go in hdrgos if go in go2nt], key=self.fncsortnt)
python
def get_ntgos_sorted(self, hdrgos): go2nt = self.grprobj.go2nt return sorted([go2nt[go] for go in hdrgos if go in go2nt], key=self.fncsortnt)
[ "def", "get_ntgos_sorted", "(", "self", ",", "hdrgos", ")", ":", "go2nt", "=", "self", ".", "grprobj", ".", "go2nt", "return", "sorted", "(", "[", "go2nt", "[", "go", "]", "for", "go", "in", "hdrgos", "if", "go", "in", "go2nt", "]", ",", "key", "="...
Return sorted Grouper namedtuples if there are user GO IDs underneath.
[ "Return", "sorted", "Grouper", "namedtuples", "if", "there", "are", "user", "GO", "IDs", "underneath", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L31-L34
242,207
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsBase.prt_ntgos
def prt_ntgos(self, prt, ntgos): """Print the Grouper namedtuples.""" for ntgo in ntgos: key2val = ntgo._asdict() prt.write("{GO_LINE}\n".format(GO_LINE=self.prtfmt.format(**key2val)))
python
def prt_ntgos(self, prt, ntgos): for ntgo in ntgos: key2val = ntgo._asdict() prt.write("{GO_LINE}\n".format(GO_LINE=self.prtfmt.format(**key2val)))
[ "def", "prt_ntgos", "(", "self", ",", "prt", ",", "ntgos", ")", ":", "for", "ntgo", "in", "ntgos", ":", "key2val", "=", "ntgo", ".", "_asdict", "(", ")", "prt", ".", "write", "(", "\"{GO_LINE}\\n\"", ".", "format", "(", "GO_LINE", "=", "self", ".", ...
Print the Grouper namedtuples.
[ "Print", "the", "Grouper", "namedtuples", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L36-L40
242,208
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsPy.wr_py_sections_new
def wr_py_sections_new(self, fout_py, doc=None): """Write the first sections file.""" sections = self.grprobj.get_sections_2d() return self.wr_py_sections(fout_py, sections, doc)
python
def wr_py_sections_new(self, fout_py, doc=None): sections = self.grprobj.get_sections_2d() return self.wr_py_sections(fout_py, sections, doc)
[ "def", "wr_py_sections_new", "(", "self", ",", "fout_py", ",", "doc", "=", "None", ")", ":", "sections", "=", "self", ".", "grprobj", ".", "get_sections_2d", "(", ")", "return", "self", ".", "wr_py_sections", "(", "fout_py", ",", "sections", ",", "doc", ...
Write the first sections file.
[ "Write", "the", "first", "sections", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L92-L95
242,209
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsPy.wr_py_sections
def wr_py_sections(self, fout_py, sections, doc=None): """Write sections 2-D list into a Python format list.""" if sections is None: sections = self.grprobj.get_sections_2d() sec2d_nt = self.get_sections_2dnt(sections) # lists of GO Grouper namedtuples with open(fout_py, 'w') as prt: self._prt_py_sections(sec2d_nt, prt, doc) dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sections) sys.stdout.write(self.grprobj.fmtsum.format( GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']), UNGRP=len(dat['U']), undesc="unused", ACTION="WROTE:", FILE=fout_py))
python
def wr_py_sections(self, fout_py, sections, doc=None): if sections is None: sections = self.grprobj.get_sections_2d() sec2d_nt = self.get_sections_2dnt(sections) # lists of GO Grouper namedtuples with open(fout_py, 'w') as prt: self._prt_py_sections(sec2d_nt, prt, doc) dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sections) sys.stdout.write(self.grprobj.fmtsum.format( GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']), UNGRP=len(dat['U']), undesc="unused", ACTION="WROTE:", FILE=fout_py))
[ "def", "wr_py_sections", "(", "self", ",", "fout_py", ",", "sections", ",", "doc", "=", "None", ")", ":", "if", "sections", "is", "None", ":", "sections", "=", "self", ".", "grprobj", ".", "get_sections_2d", "(", ")", "sec2d_nt", "=", "self", ".", "get...
Write sections 2-D list into a Python format list.
[ "Write", "sections", "2", "-", "D", "list", "into", "a", "Python", "format", "list", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L97-L108
242,210
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsPy._prt_py_sections
def _prt_py_sections(self, sec2d_nt, prt=sys.stdout, doc=None): """Print sections 2-D list into a Python format list.""" if doc is None: doc = 'Sections variable' prt.write('"""{DOC}"""\n\n'.format(DOC=doc)) self.prt_ver(prt) prt.write("# pylint: disable=line-too-long\n") strcnt = self.get_summary_str(sec2d_nt) prt.write("SECTIONS = [ # {CNTS}\n".format(CNTS=strcnt)) prt.write(' # ("New Section", [\n') prt.write(' # ]),\n') for section_name, nthdrgos in sec2d_nt: self._prt_py_section(prt, section_name, nthdrgos) prt.write("]\n")
python
def _prt_py_sections(self, sec2d_nt, prt=sys.stdout, doc=None): if doc is None: doc = 'Sections variable' prt.write('"""{DOC}"""\n\n'.format(DOC=doc)) self.prt_ver(prt) prt.write("# pylint: disable=line-too-long\n") strcnt = self.get_summary_str(sec2d_nt) prt.write("SECTIONS = [ # {CNTS}\n".format(CNTS=strcnt)) prt.write(' # ("New Section", [\n') prt.write(' # ]),\n') for section_name, nthdrgos in sec2d_nt: self._prt_py_section(prt, section_name, nthdrgos) prt.write("]\n")
[ "def", "_prt_py_sections", "(", "self", ",", "sec2d_nt", ",", "prt", "=", "sys", ".", "stdout", ",", "doc", "=", "None", ")", ":", "if", "doc", "is", "None", ":", "doc", "=", "'Sections variable'", "prt", ".", "write", "(", "'\"\"\"{DOC}\"\"\"\\n\\n'", "...
Print sections 2-D list into a Python format list.
[ "Print", "sections", "2", "-", "D", "list", "into", "a", "Python", "format", "list", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L110-L123
242,211
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsPy._prt_py_section
def _prt_py_section(self, prt, section_name, ntgos): """Print one section and its GO headers.""" prt.write(' ("{SEC}", [ # {N} GO-headers\n'.format(SEC=section_name, N=len(ntgos))) self.prt_ntgos(prt, ntgos) prt.write(" ]),\n")
python
def _prt_py_section(self, prt, section_name, ntgos): prt.write(' ("{SEC}", [ # {N} GO-headers\n'.format(SEC=section_name, N=len(ntgos))) self.prt_ntgos(prt, ntgos) prt.write(" ]),\n")
[ "def", "_prt_py_section", "(", "self", ",", "prt", ",", "section_name", ",", "ntgos", ")", ":", "prt", ".", "write", "(", "' (\"{SEC}\", [ # {N} GO-headers\\n'", ".", "format", "(", "SEC", "=", "section_name", ",", "N", "=", "len", "(", "ntgos", ")", ")...
Print one section and its GO headers.
[ "Print", "one", "section", "and", "its", "GO", "headers", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L125-L129
242,212
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsTxt.prt_goid_cnt
def prt_goid_cnt(self, prt=sys.stdout): """Get number of hdrgos and usrgos in each section.""" for section_name, hdrgos_sec in self.grprobj.get_sections_2d(): prt.write("{NAME} {Us:5,} {Hs:5,} {SEC}\n".format( NAME=self.grprobj.grpname, Us=len(self.grprobj.get_usrgos_g_hdrgos(hdrgos_sec)), Hs=len(hdrgos_sec), SEC=section_name))
python
def prt_goid_cnt(self, prt=sys.stdout): for section_name, hdrgos_sec in self.grprobj.get_sections_2d(): prt.write("{NAME} {Us:5,} {Hs:5,} {SEC}\n".format( NAME=self.grprobj.grpname, Us=len(self.grprobj.get_usrgos_g_hdrgos(hdrgos_sec)), Hs=len(hdrgos_sec), SEC=section_name))
[ "def", "prt_goid_cnt", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "for", "section_name", ",", "hdrgos_sec", "in", "self", ".", "grprobj", ".", "get_sections_2d", "(", ")", ":", "prt", ".", "write", "(", "\"{NAME} {Us:5,} {Hs:5,} {SEC}\\n\"...
Get number of hdrgos and usrgos in each section.
[ "Get", "number", "of", "hdrgos", "and", "usrgos", "in", "each", "section", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L162-L169
242,213
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsTxt.wr_txt_grouping_gos
def wr_txt_grouping_gos(self): """Write one file per GO group.""" prt_goids = self.grprobj.gosubdag.prt_goids for hdrgo, usrgos in self.grprobj.hdrgo2usrgos.items(): keygos = usrgos.union([hdrgo]) fout_txt = "{BASE}.txt".format(BASE=self.grprobj.get_fout_base(hdrgo)) with open(fout_txt, 'w') as prt: prt_goids(keygos, prt=prt) sys.stdout.write(" {N:5,} GO IDs WROTE: {TXT}\n".format( N=len(keygos), TXT=fout_txt))
python
def wr_txt_grouping_gos(self): prt_goids = self.grprobj.gosubdag.prt_goids for hdrgo, usrgos in self.grprobj.hdrgo2usrgos.items(): keygos = usrgos.union([hdrgo]) fout_txt = "{BASE}.txt".format(BASE=self.grprobj.get_fout_base(hdrgo)) with open(fout_txt, 'w') as prt: prt_goids(keygos, prt=prt) sys.stdout.write(" {N:5,} GO IDs WROTE: {TXT}\n".format( N=len(keygos), TXT=fout_txt))
[ "def", "wr_txt_grouping_gos", "(", "self", ")", ":", "prt_goids", "=", "self", ".", "grprobj", ".", "gosubdag", ".", "prt_goids", "for", "hdrgo", ",", "usrgos", "in", "self", ".", "grprobj", ".", "hdrgo2usrgos", ".", "items", "(", ")", ":", "keygos", "="...
Write one file per GO group.
[ "Write", "one", "file", "per", "GO", "group", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L171-L180
242,214
tanghaibao/goatools
goatools/grouper/wr_sections.py
WrSectionsTxt.wr_txt_section_hdrgos
def wr_txt_section_hdrgos(self, fout_txt, sortby=None, prt_section=True): """Write high GO IDs that are actually used to group current set of GO IDs.""" sec2d_go = self.grprobj.get_sections_2d() # lists of GO IDs sec2d_nt = self.get_sections_2dnt(sec2d_go) # lists of GO Grouper namedtuples if sortby is None: sortby = self.fncsortnt with open(fout_txt, 'w') as prt: self.prt_ver(prt) prt.write("# GROUP NAME: {NAME}\n".format(NAME=self.grprobj.grpname)) for section_name, nthdrgos_actual in sec2d_nt: if prt_section: prt.write("# SECTION: {SECTION}\n".format(SECTION=section_name)) self.prt_ntgos(prt, nthdrgos_actual) if prt_section: prt.write("\n") dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sec2d_go) sys.stdout.write(self.grprobj.fmtsum.format( GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']), UNGRP=len(dat['U']), undesc="unused", ACTION="WROTE:", FILE=fout_txt)) return sec2d_nt
python
def wr_txt_section_hdrgos(self, fout_txt, sortby=None, prt_section=True): sec2d_go = self.grprobj.get_sections_2d() # lists of GO IDs sec2d_nt = self.get_sections_2dnt(sec2d_go) # lists of GO Grouper namedtuples if sortby is None: sortby = self.fncsortnt with open(fout_txt, 'w') as prt: self.prt_ver(prt) prt.write("# GROUP NAME: {NAME}\n".format(NAME=self.grprobj.grpname)) for section_name, nthdrgos_actual in sec2d_nt: if prt_section: prt.write("# SECTION: {SECTION}\n".format(SECTION=section_name)) self.prt_ntgos(prt, nthdrgos_actual) if prt_section: prt.write("\n") dat = SummarySec2dHdrGos().summarize_sec2hdrgos(sec2d_go) sys.stdout.write(self.grprobj.fmtsum.format( GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']), UNGRP=len(dat['U']), undesc="unused", ACTION="WROTE:", FILE=fout_txt)) return sec2d_nt
[ "def", "wr_txt_section_hdrgos", "(", "self", ",", "fout_txt", ",", "sortby", "=", "None", ",", "prt_section", "=", "True", ")", ":", "sec2d_go", "=", "self", ".", "grprobj", ".", "get_sections_2d", "(", ")", "# lists of GO IDs", "sec2d_nt", "=", "self", ".",...
Write high GO IDs that are actually used to group current set of GO IDs.
[ "Write", "high", "GO", "IDs", "that", "are", "actually", "used", "to", "group", "current", "set", "of", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/wr_sections.py#L182-L202
242,215
tanghaibao/goatools
goatools/parsers/david_chart.py
DavidChartReader.prt_num_sig
def prt_num_sig(self, prt=sys.stdout, alpha=0.05): """Print the number of significant GO terms.""" ctr = self.get_num_sig(alpha) prt.write("{N:6,} TOTAL: {TXT}\n".format(N=len(self.nts), TXT=" ".join([ "FDR({FDR:4})".format(FDR=ctr['FDR']), "Bonferroni({B:4})".format(B=ctr['Bonferroni']), "Benjamini({B:4})".format(B=ctr['Benjamini']), "PValue({P:4})".format(P=ctr['PValue']), os.path.basename(self.fin_davidchart)])))
python
def prt_num_sig(self, prt=sys.stdout, alpha=0.05): ctr = self.get_num_sig(alpha) prt.write("{N:6,} TOTAL: {TXT}\n".format(N=len(self.nts), TXT=" ".join([ "FDR({FDR:4})".format(FDR=ctr['FDR']), "Bonferroni({B:4})".format(B=ctr['Bonferroni']), "Benjamini({B:4})".format(B=ctr['Benjamini']), "PValue({P:4})".format(P=ctr['PValue']), os.path.basename(self.fin_davidchart)])))
[ "def", "prt_num_sig", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ",", "alpha", "=", "0.05", ")", ":", "ctr", "=", "self", ".", "get_num_sig", "(", "alpha", ")", "prt", ".", "write", "(", "\"{N:6,} TOTAL: {TXT}\\n\"", ".", "format", "(", "N", ...
Print the number of significant GO terms.
[ "Print", "the", "number", "of", "significant", "GO", "terms", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L81-L89
242,216
tanghaibao/goatools
goatools/parsers/david_chart.py
DavidChartReader.get_num_sig
def get_num_sig(self, alpha=0.05): """Print the number of significant results using various metrics.""" # Get the number of significant GO terms ctr = cx.Counter() flds = set(['FDR', 'Bonferroni', 'Benjamini', 'PValue']) for ntd in self.nts: for fld in flds: if getattr(ntd, fld) < alpha: ctr[fld] += 1 return ctr
python
def get_num_sig(self, alpha=0.05): # Get the number of significant GO terms ctr = cx.Counter() flds = set(['FDR', 'Bonferroni', 'Benjamini', 'PValue']) for ntd in self.nts: for fld in flds: if getattr(ntd, fld) < alpha: ctr[fld] += 1 return ctr
[ "def", "get_num_sig", "(", "self", ",", "alpha", "=", "0.05", ")", ":", "# Get the number of significant GO terms", "ctr", "=", "cx", ".", "Counter", "(", ")", "flds", "=", "set", "(", "[", "'FDR'", ",", "'Bonferroni'", ",", "'Benjamini'", ",", "'PValue'", ...
Print the number of significant results using various metrics.
[ "Print", "the", "number", "of", "significant", "results", "using", "various", "metrics", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L91-L100
242,217
tanghaibao/goatools
goatools/parsers/david_chart.py
_Init.get_nts
def get_nts(self, fin_davidchart): """Read DAVID Chart file. Store each line in a namedtuple.""" nts = [] with open(fin_davidchart) as ifstrm: hdr_seen = False for line in ifstrm: line = line.rstrip() flds = line.split('\t') if hdr_seen: ntd = self._init_nt(flds) nts.append(ntd) else: if line[:8] == 'Category': assert len(flds) == 13, len(flds) hdr_seen = True sys.stdout.write(" READ {N:5} GO IDs from DAVID Chart: {TSV}\n".format( N=len(nts), TSV=fin_davidchart)) return nts
python
def get_nts(self, fin_davidchart): nts = [] with open(fin_davidchart) as ifstrm: hdr_seen = False for line in ifstrm: line = line.rstrip() flds = line.split('\t') if hdr_seen: ntd = self._init_nt(flds) nts.append(ntd) else: if line[:8] == 'Category': assert len(flds) == 13, len(flds) hdr_seen = True sys.stdout.write(" READ {N:5} GO IDs from DAVID Chart: {TSV}\n".format( N=len(nts), TSV=fin_davidchart)) return nts
[ "def", "get_nts", "(", "self", ",", "fin_davidchart", ")", ":", "nts", "=", "[", "]", "with", "open", "(", "fin_davidchart", ")", "as", "ifstrm", ":", "hdr_seen", "=", "False", "for", "line", "in", "ifstrm", ":", "line", "=", "line", ".", "rstrip", "...
Read DAVID Chart file. Store each line in a namedtuple.
[ "Read", "DAVID", "Chart", "file", ".", "Store", "each", "line", "in", "a", "namedtuple", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L127-L145
242,218
tanghaibao/goatools
goatools/parsers/david_chart.py
_Init._init_nt
def _init_nt(self, flds): """Given string fields from a DAVID chart file, return namedtuple.""" term = flds[1] genes_str = flds[5] # pylint: disable=bad-whitespace return self.ntobj( Category = flds[0], GO = term[:10], # 1 GO:0045202~synapse name = term[10:], # 1 GO:0045202~synapse Count = int(flds[2]), # 2 94 Perc = float(flds[3]), # 3 9.456740442655935 PValue = float(flds[4]), # 4 6.102654380458156E-20 Genes = genes_str, # 5 ['ENSMUSG00000052613', ...] Genes_set = self.get_genes(genes_str), # 5 ['ENSMUSG00000052613', ...] List_Total = int(flds[6]), # 6 920 Pop_Hits = int(flds[7]), # 7 444 Pop_Total = int(flds[8]), # 8 12002 Fold_Enrichment = float(flds[9]), # 9 2.7619173521347435 Bonferroni = float(flds[10]), # 10 3.3930758355347344E-17 Benjamini = float(flds[11]), # 11 3.3930758355347344E-17 FDR = float(flds[12]))
python
def _init_nt(self, flds): term = flds[1] genes_str = flds[5] # pylint: disable=bad-whitespace return self.ntobj( Category = flds[0], GO = term[:10], # 1 GO:0045202~synapse name = term[10:], # 1 GO:0045202~synapse Count = int(flds[2]), # 2 94 Perc = float(flds[3]), # 3 9.456740442655935 PValue = float(flds[4]), # 4 6.102654380458156E-20 Genes = genes_str, # 5 ['ENSMUSG00000052613', ...] Genes_set = self.get_genes(genes_str), # 5 ['ENSMUSG00000052613', ...] List_Total = int(flds[6]), # 6 920 Pop_Hits = int(flds[7]), # 7 444 Pop_Total = int(flds[8]), # 8 12002 Fold_Enrichment = float(flds[9]), # 9 2.7619173521347435 Bonferroni = float(flds[10]), # 10 3.3930758355347344E-17 Benjamini = float(flds[11]), # 11 3.3930758355347344E-17 FDR = float(flds[12]))
[ "def", "_init_nt", "(", "self", ",", "flds", ")", ":", "term", "=", "flds", "[", "1", "]", "genes_str", "=", "flds", "[", "5", "]", "# pylint: disable=bad-whitespace", "return", "self", ".", "ntobj", "(", "Category", "=", "flds", "[", "0", "]", ",", ...
Given string fields from a DAVID chart file, return namedtuple.
[ "Given", "string", "fields", "from", "a", "DAVID", "chart", "file", "return", "namedtuple", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L147-L167
242,219
tanghaibao/goatools
goatools/parsers/david_chart.py
_Init.get_genes
def get_genes(genes_str): """Given a string containng genes, return a list.""" gene_set = genes_str.split(', ') if gene_set and gene_set[0].isdigit(): gene_set = set(int(g) for g in gene_set) return gene_set
python
def get_genes(genes_str): gene_set = genes_str.split(', ') if gene_set and gene_set[0].isdigit(): gene_set = set(int(g) for g in gene_set) return gene_set
[ "def", "get_genes", "(", "genes_str", ")", ":", "gene_set", "=", "genes_str", ".", "split", "(", "', '", ")", "if", "gene_set", "and", "gene_set", "[", "0", "]", ".", "isdigit", "(", ")", ":", "gene_set", "=", "set", "(", "int", "(", "g", ")", "for...
Given a string containng genes, return a list.
[ "Given", "a", "string", "containng", "genes", "return", "a", "list", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/david_chart.py#L170-L175
242,220
tanghaibao/goatools
goatools/anno/extensions/factory.py
get_extensions
def get_extensions(extstr): """Return zero or greater Annotation Extensions, given a line of text.""" # Extension examples: # has_direct_input(UniProtKB:P37840),occurs_in(GO:0005576) # part_of(UBERON:0006618),part_of(UBERON:0002302) # occurs_in(CL:0000988)|occurs_in(CL:0001021) if not extstr: return None exts = [] for ext_lst in extstr.split('|'): grp = [] for ext in ext_lst.split(','): idx = ext.find('(') if idx != -1 and ext[-1] == ')': grp.append(AnnotationExtension(ext[:idx], ext[idx+1:-1])) else: # Ignore improperly formatted Extensions sys.stdout.write('BAD Extension({E})\n'.format(E=ext)) exts.append(grp) return AnnotationExtensions(exts)
python
def get_extensions(extstr): # Extension examples: # has_direct_input(UniProtKB:P37840),occurs_in(GO:0005576) # part_of(UBERON:0006618),part_of(UBERON:0002302) # occurs_in(CL:0000988)|occurs_in(CL:0001021) if not extstr: return None exts = [] for ext_lst in extstr.split('|'): grp = [] for ext in ext_lst.split(','): idx = ext.find('(') if idx != -1 and ext[-1] == ')': grp.append(AnnotationExtension(ext[:idx], ext[idx+1:-1])) else: # Ignore improperly formatted Extensions sys.stdout.write('BAD Extension({E})\n'.format(E=ext)) exts.append(grp) return AnnotationExtensions(exts)
[ "def", "get_extensions", "(", "extstr", ")", ":", "# Extension examples:", "# has_direct_input(UniProtKB:P37840),occurs_in(GO:0005576)", "# part_of(UBERON:0006618),part_of(UBERON:0002302)", "# occurs_in(CL:0000988)|occurs_in(CL:0001021)", "if", "not", "extstr", ":", "return", "No...
Return zero or greater Annotation Extensions, given a line of text.
[ "Return", "zero", "or", "greater", "Annotation", "Extensions", "given", "a", "line", "of", "text", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/extensions/factory.py#L25-L44
242,221
tanghaibao/goatools
goatools/cli/docopt_parse.py
DocOptParse._set_intvals
def _set_intvals(kws, keys): """Convert keyword values to int.""" for key in keys: if key in kws: kws[key] = int(kws[key])
python
def _set_intvals(kws, keys): for key in keys: if key in kws: kws[key] = int(kws[key])
[ "def", "_set_intvals", "(", "kws", ",", "keys", ")", ":", "for", "key", "in", "keys", ":", "if", "key", "in", "kws", ":", "kws", "[", "key", "]", "=", "int", "(", "kws", "[", "key", "]", ")" ]
Convert keyword values to int.
[ "Convert", "keyword", "values", "to", "int", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/docopt_parse.py#L51-L55
242,222
tanghaibao/goatools
goatools/cli/docopt_parse.py
DocOptParse._chk_docopt_exit
def _chk_docopt_exit(self, args, exp_letters): """Check if docopt exit was for an unknown argument.""" if args is None: args = sys.argv[1:] keys_all = self.exp_keys.union(self.exp_elems) if exp_letters: keys_all |= exp_letters unknown_args = self._chk_docunknown(args, keys_all) if unknown_args: raise RuntimeError("{USAGE}\n **FATAL: UNKNOWN ARGS: {UNK}".format( USAGE=self.doc, UNK=" ".join(unknown_args)))
python
def _chk_docopt_exit(self, args, exp_letters): if args is None: args = sys.argv[1:] keys_all = self.exp_keys.union(self.exp_elems) if exp_letters: keys_all |= exp_letters unknown_args = self._chk_docunknown(args, keys_all) if unknown_args: raise RuntimeError("{USAGE}\n **FATAL: UNKNOWN ARGS: {UNK}".format( USAGE=self.doc, UNK=" ".join(unknown_args)))
[ "def", "_chk_docopt_exit", "(", "self", ",", "args", ",", "exp_letters", ")", ":", "if", "args", "is", "None", ":", "args", "=", "sys", ".", "argv", "[", "1", ":", "]", "keys_all", "=", "self", ".", "exp_keys", ".", "union", "(", "self", ".", "exp_...
Check if docopt exit was for an unknown argument.
[ "Check", "if", "docopt", "exit", "was", "for", "an", "unknown", "argument", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/docopt_parse.py#L57-L67
242,223
tanghaibao/goatools
goatools/cli/docopt_parse.py
DocOptParse._chk_docopt_kws
def _chk_docopt_kws(self, docdict, exp): """Check for common user errors when running from the command-line.""" for key, val in docdict.items(): if isinstance(val, str): assert '=' not in val, self._err("'=' FOUND IN VALUE", key, val, exp) elif key != 'help' and key not in self.exp_keys and key not in self.exp_elems: raise RuntimeError(self._err("UNKNOWN KEY", key, val, exp))
python
def _chk_docopt_kws(self, docdict, exp): for key, val in docdict.items(): if isinstance(val, str): assert '=' not in val, self._err("'=' FOUND IN VALUE", key, val, exp) elif key != 'help' and key not in self.exp_keys and key not in self.exp_elems: raise RuntimeError(self._err("UNKNOWN KEY", key, val, exp))
[ "def", "_chk_docopt_kws", "(", "self", ",", "docdict", ",", "exp", ")", ":", "for", "key", ",", "val", "in", "docdict", ".", "items", "(", ")", ":", "if", "isinstance", "(", "val", ",", "str", ")", ":", "assert", "'='", "not", "in", "val", ",", "...
Check for common user errors when running from the command-line.
[ "Check", "for", "common", "user", "errors", "when", "running", "from", "the", "command", "-", "line", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/docopt_parse.py#L69-L75
242,224
tanghaibao/goatools
goatools/cli/docopt_parse.py
DocOptParse._chk_docunknown
def _chk_docunknown(args, exp): """Return any unknown args.""" unknown = [] for arg in args: if arg[:2] == '--': val = arg[2:] if val not in exp: unknown.append(arg) elif arg[:1] == '-': val = arg[1:] if val not in exp: unknown.append(arg) if '-h' in unknown or '--help' in unknown: return [] return unknown
python
def _chk_docunknown(args, exp): unknown = [] for arg in args: if arg[:2] == '--': val = arg[2:] if val not in exp: unknown.append(arg) elif arg[:1] == '-': val = arg[1:] if val not in exp: unknown.append(arg) if '-h' in unknown or '--help' in unknown: return [] return unknown
[ "def", "_chk_docunknown", "(", "args", ",", "exp", ")", ":", "unknown", "=", "[", "]", "for", "arg", "in", "args", ":", "if", "arg", "[", ":", "2", "]", "==", "'--'", ":", "val", "=", "arg", "[", "2", ":", "]", "if", "val", "not", "in", "exp"...
Return any unknown args.
[ "Return", "any", "unknown", "args", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/docopt_parse.py#L82-L96
242,225
tanghaibao/goatools
goatools/anno/dnld_ebi_goa.py
DnldGoa.dnld_goa
def dnld_goa(self, species, ext='gaf', item=None, fileout=None): """Download GOA source file name on EMBL-EBI ftp server.""" basename = self.get_basename(species, ext, item) src = os.path.join(self.ftp_src_goa, species.upper(), "{F}.gz".format(F=basename)) dst = os.path.join(os.getcwd(), basename) if fileout is None else fileout dnld_file(src, dst, prt=sys.stdout, loading_bar=None) return dst
python
def dnld_goa(self, species, ext='gaf', item=None, fileout=None): basename = self.get_basename(species, ext, item) src = os.path.join(self.ftp_src_goa, species.upper(), "{F}.gz".format(F=basename)) dst = os.path.join(os.getcwd(), basename) if fileout is None else fileout dnld_file(src, dst, prt=sys.stdout, loading_bar=None) return dst
[ "def", "dnld_goa", "(", "self", ",", "species", ",", "ext", "=", "'gaf'", ",", "item", "=", "None", ",", "fileout", "=", "None", ")", ":", "basename", "=", "self", ".", "get_basename", "(", "species", ",", "ext", ",", "item", ")", "src", "=", "os",...
Download GOA source file name on EMBL-EBI ftp server.
[ "Download", "GOA", "source", "file", "name", "on", "EMBL", "-", "EBI", "ftp", "server", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/dnld_ebi_goa.py#L41-L47
242,226
tanghaibao/goatools
goatools/associations.py
read_associations
def read_associations(assoc_fn, anno_type='id2gos', **kws): """Return associatinos in id2gos format""" # kws get_objanno: taxids hdr_only prt allow_missing_symbol obj = get_objanno(assoc_fn, anno_type, **kws) # kws get_id2gos: ev_include ev_exclude keep_ND keep_NOT b_geneid2gos go2geneids return obj.get_id2gos(**kws)
python
def read_associations(assoc_fn, anno_type='id2gos', **kws): # kws get_objanno: taxids hdr_only prt allow_missing_symbol obj = get_objanno(assoc_fn, anno_type, **kws) # kws get_id2gos: ev_include ev_exclude keep_ND keep_NOT b_geneid2gos go2geneids return obj.get_id2gos(**kws)
[ "def", "read_associations", "(", "assoc_fn", ",", "anno_type", "=", "'id2gos'", ",", "*", "*", "kws", ")", ":", "# kws get_objanno: taxids hdr_only prt allow_missing_symbol", "obj", "=", "get_objanno", "(", "assoc_fn", ",", "anno_type", ",", "*", "*", "kws", ")", ...
Return associatinos in id2gos format
[ "Return", "associatinos", "in", "id2gos", "format" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L49-L54
242,227
tanghaibao/goatools
goatools/associations.py
dnld_ncbi_gene_file
def dnld_ncbi_gene_file(fin, force_dnld=False, log=sys.stdout, loading_bar=True): """Download a file from NCBI Gene's ftp server.""" if not os.path.exists(fin) or force_dnld: import gzip fin_dir, fin_base = os.path.split(fin) fin_gz = "{F}.gz".format(F=fin_base) fin_gz = os.path.join(fin_dir, fin_gz) if os.path.exists(fin_gz): os.remove(fin_gz) fin_ftp = "ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/{F}.gz".format(F=fin_base) ## if log is not None: ## log.write(" DOWNLOADING GZIP: {GZ}\n".format(GZ=fin_ftp)) ## if loading_bar: ## loading_bar = wget.bar_adaptive ## wget.download(fin_ftp, bar=loading_bar) ## rsp = wget(fin_ftp) ftp_get(fin_ftp, fin_gz) with gzip.open(fin_gz, 'rb') as zstrm: if log is not None: log.write("\n READ GZIP: {F}\n".format(F=fin_gz)) with open(fin, 'wb') as ostrm: ostrm.write(zstrm.read()) if log is not None: log.write(" WROTE UNZIPPED: {F}\n".format(F=fin))
python
def dnld_ncbi_gene_file(fin, force_dnld=False, log=sys.stdout, loading_bar=True): if not os.path.exists(fin) or force_dnld: import gzip fin_dir, fin_base = os.path.split(fin) fin_gz = "{F}.gz".format(F=fin_base) fin_gz = os.path.join(fin_dir, fin_gz) if os.path.exists(fin_gz): os.remove(fin_gz) fin_ftp = "ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/{F}.gz".format(F=fin_base) ## if log is not None: ## log.write(" DOWNLOADING GZIP: {GZ}\n".format(GZ=fin_ftp)) ## if loading_bar: ## loading_bar = wget.bar_adaptive ## wget.download(fin_ftp, bar=loading_bar) ## rsp = wget(fin_ftp) ftp_get(fin_ftp, fin_gz) with gzip.open(fin_gz, 'rb') as zstrm: if log is not None: log.write("\n READ GZIP: {F}\n".format(F=fin_gz)) with open(fin, 'wb') as ostrm: ostrm.write(zstrm.read()) if log is not None: log.write(" WROTE UNZIPPED: {F}\n".format(F=fin))
[ "def", "dnld_ncbi_gene_file", "(", "fin", ",", "force_dnld", "=", "False", ",", "log", "=", "sys", ".", "stdout", ",", "loading_bar", "=", "True", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "fin", ")", "or", "force_dnld", ":", "imp...
Download a file from NCBI Gene's ftp server.
[ "Download", "a", "file", "from", "NCBI", "Gene", "s", "ftp", "server", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L62-L85
242,228
tanghaibao/goatools
goatools/associations.py
dnld_annofile
def dnld_annofile(fin_anno, anno_type): """Download annotation file, if needed""" if os.path.exists(fin_anno): return anno_type = get_anno_desc(fin_anno, anno_type) if anno_type == 'gene2go': dnld_ncbi_gene_file(fin_anno) if anno_type in {'gaf', 'gpad'}: dnld_annotation(fin_anno)
python
def dnld_annofile(fin_anno, anno_type): if os.path.exists(fin_anno): return anno_type = get_anno_desc(fin_anno, anno_type) if anno_type == 'gene2go': dnld_ncbi_gene_file(fin_anno) if anno_type in {'gaf', 'gpad'}: dnld_annotation(fin_anno)
[ "def", "dnld_annofile", "(", "fin_anno", ",", "anno_type", ")", ":", "if", "os", ".", "path", ".", "exists", "(", "fin_anno", ")", ":", "return", "anno_type", "=", "get_anno_desc", "(", "fin_anno", ",", "anno_type", ")", "if", "anno_type", "==", "'gene2go'...
Download annotation file, if needed
[ "Download", "annotation", "file", "if", "needed" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L87-L95
242,229
tanghaibao/goatools
goatools/associations.py
read_ncbi_gene2go
def read_ncbi_gene2go(fin_gene2go, taxids=None, **kws): """Read NCBI's gene2go. Return gene2go data for user-specified taxids.""" obj = Gene2GoReader(fin_gene2go, taxids=taxids) # By default, return id2gos. User can cause go2geneids to be returned by: # >>> read_ncbi_gene2go(..., go2geneids=True if 'taxid2asscs' not in kws: if len(obj.taxid2asscs) == 1: taxid = next(iter(obj.taxid2asscs)) kws_ncbi = {k:v for k, v in kws.items() if k in AnnoOptions.keys_exp} kws_ncbi['taxid'] = taxid return obj.get_id2gos(**kws_ncbi) # Optional detailed associations split by taxid and having both ID2GOs & GO2IDs # e.g., taxid2asscs = defaultdict(lambda: defaultdict(lambda: defaultdict(set)) t2asscs_ret = obj.get_taxid2asscs(taxids, **kws) t2asscs_usr = kws.get('taxid2asscs', defaultdict(lambda: defaultdict(lambda: defaultdict(set)))) if 'taxid2asscs' in kws: obj.fill_taxid2asscs(t2asscs_usr, t2asscs_ret) return obj.get_id2gos_all(t2asscs_ret)
python
def read_ncbi_gene2go(fin_gene2go, taxids=None, **kws): obj = Gene2GoReader(fin_gene2go, taxids=taxids) # By default, return id2gos. User can cause go2geneids to be returned by: # >>> read_ncbi_gene2go(..., go2geneids=True if 'taxid2asscs' not in kws: if len(obj.taxid2asscs) == 1: taxid = next(iter(obj.taxid2asscs)) kws_ncbi = {k:v for k, v in kws.items() if k in AnnoOptions.keys_exp} kws_ncbi['taxid'] = taxid return obj.get_id2gos(**kws_ncbi) # Optional detailed associations split by taxid and having both ID2GOs & GO2IDs # e.g., taxid2asscs = defaultdict(lambda: defaultdict(lambda: defaultdict(set)) t2asscs_ret = obj.get_taxid2asscs(taxids, **kws) t2asscs_usr = kws.get('taxid2asscs', defaultdict(lambda: defaultdict(lambda: defaultdict(set)))) if 'taxid2asscs' in kws: obj.fill_taxid2asscs(t2asscs_usr, t2asscs_ret) return obj.get_id2gos_all(t2asscs_ret)
[ "def", "read_ncbi_gene2go", "(", "fin_gene2go", ",", "taxids", "=", "None", ",", "*", "*", "kws", ")", ":", "obj", "=", "Gene2GoReader", "(", "fin_gene2go", ",", "taxids", "=", "taxids", ")", "# By default, return id2gos. User can cause go2geneids to be returned by:",...
Read NCBI's gene2go. Return gene2go data for user-specified taxids.
[ "Read", "NCBI", "s", "gene2go", ".", "Return", "gene2go", "data", "for", "user", "-", "specified", "taxids", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L97-L114
242,230
tanghaibao/goatools
goatools/associations.py
get_b2aset
def get_b2aset(a2bset): """Given gene2gos, return go2genes. Given go2genes, return gene2gos.""" b2aset = {} for a_item, bset in a2bset.items(): for b_item in bset: if b_item in b2aset: b2aset[b_item].add(a_item) else: b2aset[b_item] = set([a_item]) return b2aset
python
def get_b2aset(a2bset): b2aset = {} for a_item, bset in a2bset.items(): for b_item in bset: if b_item in b2aset: b2aset[b_item].add(a_item) else: b2aset[b_item] = set([a_item]) return b2aset
[ "def", "get_b2aset", "(", "a2bset", ")", ":", "b2aset", "=", "{", "}", "for", "a_item", ",", "bset", "in", "a2bset", ".", "items", "(", ")", ":", "for", "b_item", "in", "bset", ":", "if", "b_item", "in", "b2aset", ":", "b2aset", "[", "b_item", "]",...
Given gene2gos, return go2genes. Given go2genes, return gene2gos.
[ "Given", "gene2gos", "return", "go2genes", ".", "Given", "go2genes", "return", "gene2gos", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L125-L134
242,231
tanghaibao/goatools
goatools/associations.py
get_assc_pruned
def get_assc_pruned(assc_geneid2gos, min_genecnt=None, max_genecnt=None, prt=sys.stdout): """Remove GO IDs associated with large numbers of genes. Used in stochastic simulations.""" # DEFN WAS: get_assc_pruned(assc_geneid2gos, max_genecnt=None, prt=sys.stdout): # ADDED min_genecnt argument and functionality if max_genecnt is None and min_genecnt is None: return assc_geneid2gos, set() go2genes_orig = get_b2aset(assc_geneid2gos) # go2genes_prun = {go:gs for go, gs in go2genes_orig.items() if len(gs) <= max_genecnt} go2genes_prun = {} for goid, genes in go2genes_orig.items(): num_genes = len(genes) if (min_genecnt is None or num_genes >= min_genecnt) and \ (max_genecnt is None or num_genes <= max_genecnt): go2genes_prun[goid] = genes num_was = len(go2genes_orig) num_now = len(go2genes_prun) gos_rm = set(go2genes_orig.keys()).difference(set(go2genes_prun.keys())) assert num_was-num_now == len(gos_rm) if prt is not None: if min_genecnt is None: min_genecnt = 1 if max_genecnt is None: max_genecnt = "Max" prt.write("{N:4} GO IDs pruned. Kept {NOW} GOs assc w/({m} to {M} genes)\n".format( m=min_genecnt, M=max_genecnt, N=num_was-num_now, NOW=num_now)) return get_b2aset(go2genes_prun), gos_rm
python
def get_assc_pruned(assc_geneid2gos, min_genecnt=None, max_genecnt=None, prt=sys.stdout): # DEFN WAS: get_assc_pruned(assc_geneid2gos, max_genecnt=None, prt=sys.stdout): # ADDED min_genecnt argument and functionality if max_genecnt is None and min_genecnt is None: return assc_geneid2gos, set() go2genes_orig = get_b2aset(assc_geneid2gos) # go2genes_prun = {go:gs for go, gs in go2genes_orig.items() if len(gs) <= max_genecnt} go2genes_prun = {} for goid, genes in go2genes_orig.items(): num_genes = len(genes) if (min_genecnt is None or num_genes >= min_genecnt) and \ (max_genecnt is None or num_genes <= max_genecnt): go2genes_prun[goid] = genes num_was = len(go2genes_orig) num_now = len(go2genes_prun) gos_rm = set(go2genes_orig.keys()).difference(set(go2genes_prun.keys())) assert num_was-num_now == len(gos_rm) if prt is not None: if min_genecnt is None: min_genecnt = 1 if max_genecnt is None: max_genecnt = "Max" prt.write("{N:4} GO IDs pruned. Kept {NOW} GOs assc w/({m} to {M} genes)\n".format( m=min_genecnt, M=max_genecnt, N=num_was-num_now, NOW=num_now)) return get_b2aset(go2genes_prun), gos_rm
[ "def", "get_assc_pruned", "(", "assc_geneid2gos", ",", "min_genecnt", "=", "None", ",", "max_genecnt", "=", "None", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "# DEFN WAS: get_assc_pruned(assc_geneid2gos, max_genecnt=None, prt=sys.stdout):", "# ADDED min_genecnt ...
Remove GO IDs associated with large numbers of genes. Used in stochastic simulations.
[ "Remove", "GO", "IDs", "associated", "with", "large", "numbers", "of", "genes", ".", "Used", "in", "stochastic", "simulations", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L136-L161
242,232
tanghaibao/goatools
goatools/associations.py
read_annotations
def read_annotations(**kws): """Read annotations from either a GAF file or NCBI's gene2go file.""" if 'gaf' not in kws and 'gene2go' not in kws: return gene2gos = None if 'gaf' in kws: gene2gos = read_gaf(kws['gaf'], prt=sys.stdout) if not gene2gos: raise RuntimeError("NO ASSOCIATIONS LOADED FROM {F}".format(F=kws['gaf'])) elif 'gene2go' in kws: assert 'taxid' in kws, 'taxid IS REQUIRED WHEN READING gene2go' gene2gos = read_ncbi_gene2go(kws['gene2go'], taxids=[kws['taxid']]) if not gene2gos: raise RuntimeError("NO ASSOCIATIONS LOADED FROM {F} FOR TAXID({T})".format( F=kws['gene2go'], T=kws['taxid'])) return gene2gos
python
def read_annotations(**kws): if 'gaf' not in kws and 'gene2go' not in kws: return gene2gos = None if 'gaf' in kws: gene2gos = read_gaf(kws['gaf'], prt=sys.stdout) if not gene2gos: raise RuntimeError("NO ASSOCIATIONS LOADED FROM {F}".format(F=kws['gaf'])) elif 'gene2go' in kws: assert 'taxid' in kws, 'taxid IS REQUIRED WHEN READING gene2go' gene2gos = read_ncbi_gene2go(kws['gene2go'], taxids=[kws['taxid']]) if not gene2gos: raise RuntimeError("NO ASSOCIATIONS LOADED FROM {F} FOR TAXID({T})".format( F=kws['gene2go'], T=kws['taxid'])) return gene2gos
[ "def", "read_annotations", "(", "*", "*", "kws", ")", ":", "if", "'gaf'", "not", "in", "kws", "and", "'gene2go'", "not", "in", "kws", ":", "return", "gene2gos", "=", "None", "if", "'gaf'", "in", "kws", ":", "gene2gos", "=", "read_gaf", "(", "kws", "[...
Read annotations from either a GAF file or NCBI's gene2go file.
[ "Read", "annotations", "from", "either", "a", "GAF", "file", "or", "NCBI", "s", "gene2go", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L163-L178
242,233
tanghaibao/goatools
goatools/associations.py
get_tcntobj
def get_tcntobj(go2obj, **kws): """Return a TermCounts object if the user provides an annotation file, otherwise None.""" # kws: gaf gene2go annots = read_annotations(**kws) if annots: return TermCounts(go2obj, annots)
python
def get_tcntobj(go2obj, **kws): # kws: gaf gene2go annots = read_annotations(**kws) if annots: return TermCounts(go2obj, annots)
[ "def", "get_tcntobj", "(", "go2obj", ",", "*", "*", "kws", ")", ":", "# kws: gaf gene2go", "annots", "=", "read_annotations", "(", "*", "*", "kws", ")", "if", "annots", ":", "return", "TermCounts", "(", "go2obj", ",", "annots", ")" ]
Return a TermCounts object if the user provides an annotation file, otherwise None.
[ "Return", "a", "TermCounts", "object", "if", "the", "user", "provides", "an", "annotation", "file", "otherwise", "None", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/associations.py#L180-L185
242,234
tanghaibao/goatools
goatools/wr_tbl_class.py
get_hdrs
def get_hdrs(flds_all, **kws): """Return headers, given user-specified key-word args.""" # Return Headers if the user explicitly lists them. hdrs = kws.get('hdrs', None) if hdrs is not None: return hdrs # User may specify a subset of fields or a column order using prt_flds if 'prt_flds' in kws: return kws['prt_flds'] # All fields in the namedtuple will be in the headers return flds_all
python
def get_hdrs(flds_all, **kws): # Return Headers if the user explicitly lists them. hdrs = kws.get('hdrs', None) if hdrs is not None: return hdrs # User may specify a subset of fields or a column order using prt_flds if 'prt_flds' in kws: return kws['prt_flds'] # All fields in the namedtuple will be in the headers return flds_all
[ "def", "get_hdrs", "(", "flds_all", ",", "*", "*", "kws", ")", ":", "# Return Headers if the user explicitly lists them.", "hdrs", "=", "kws", ".", "get", "(", "'hdrs'", ",", "None", ")", "if", "hdrs", "is", "not", "None", ":", "return", "hdrs", "# User may ...
Return headers, given user-specified key-word args.
[ "Return", "headers", "given", "user", "-", "specified", "key", "-", "word", "args", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L218-L228
242,235
tanghaibao/goatools
goatools/wr_tbl_class.py
WrXlsx.wr_row_mergeall
def wr_row_mergeall(self, worksheet, txtstr, fmt, row_idx): """Merge all columns and place text string in widened cell.""" hdridxval = len(self.hdrs) - 1 worksheet.merge_range(row_idx, 0, row_idx, hdridxval, txtstr, fmt) return row_idx + 1
python
def wr_row_mergeall(self, worksheet, txtstr, fmt, row_idx): hdridxval = len(self.hdrs) - 1 worksheet.merge_range(row_idx, 0, row_idx, hdridxval, txtstr, fmt) return row_idx + 1
[ "def", "wr_row_mergeall", "(", "self", ",", "worksheet", ",", "txtstr", ",", "fmt", ",", "row_idx", ")", ":", "hdridxval", "=", "len", "(", "self", ".", "hdrs", ")", "-", "1", "worksheet", ".", "merge_range", "(", "row_idx", ",", "0", ",", "row_idx", ...
Merge all columns and place text string in widened cell.
[ "Merge", "all", "columns", "and", "place", "text", "string", "in", "widened", "cell", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L49-L53
242,236
tanghaibao/goatools
goatools/wr_tbl_class.py
WrXlsx.wr_hdrs
def wr_hdrs(self, worksheet, row_idx): """Print row of column headers""" for col_idx, hdr in enumerate(self.hdrs): # print("ROW({R}) COL({C}) HDR({H}) FMT({F})\n".format( # R=row_idx, C=col_idx, H=hdr, F=self.fmt_hdr)) worksheet.write(row_idx, col_idx, hdr, self.fmt_hdr) row_idx += 1 return row_idx
python
def wr_hdrs(self, worksheet, row_idx): for col_idx, hdr in enumerate(self.hdrs): # print("ROW({R}) COL({C}) HDR({H}) FMT({F})\n".format( # R=row_idx, C=col_idx, H=hdr, F=self.fmt_hdr)) worksheet.write(row_idx, col_idx, hdr, self.fmt_hdr) row_idx += 1 return row_idx
[ "def", "wr_hdrs", "(", "self", ",", "worksheet", ",", "row_idx", ")", ":", "for", "col_idx", ",", "hdr", "in", "enumerate", "(", "self", ".", "hdrs", ")", ":", "# print(\"ROW({R}) COL({C}) HDR({H}) FMT({F})\\n\".format(", "# R=row_idx, C=col_idx, H=hdr, F=self.fmt_h...
Print row of column headers
[ "Print", "row", "of", "column", "headers" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L55-L62
242,237
tanghaibao/goatools
goatools/wr_tbl_class.py
WrXlsx.wr_data
def wr_data(self, xlsx_data, row_i, worksheet): """Write data into xlsx worksheet.""" fld2fmt = self.vars.fld2fmt # User may specify to skip rows based on values in row prt_if = self.vars.prt_if # User may specify a subset of columns to print or # a column ordering different from the _fields seen in the namedtuple prt_flds = self.wbfmtobj.get_prt_flds() get_wbfmt = self.wbfmtobj.get_wbfmt if self.vars.sort_by is not None: xlsx_data = sorted(xlsx_data, key=self.vars.sort_by) try: for data_nt in xlsx_data: if prt_if is None or prt_if(data_nt): wbfmt = get_wbfmt(data_nt) # xlsxwriter.format.Format created w/add_format # Print an xlsx row by printing each column in order. for col_i, fld in enumerate(prt_flds): try: # If fld "format_txt" present, use val for formatting, but don't print. val = getattr(data_nt, fld, "") # Optional user-formatting of specific fields, eg, pval: "{:8.2e}" # If field value is empty (""), don't use fld2fmt if fld2fmt is not None and fld in fld2fmt and val != "" and val != "*": val = fld2fmt[fld].format(val) worksheet.write(row_i, col_i, val, wbfmt) except: raise RuntimeError(self._get_err_msg(row_i, col_i, fld, val, prt_flds)) row_i += 1 except RuntimeError as inst: import traceback traceback.print_exc() sys.stderr.write("\n **FATAL in wr_data: {MSG}\n\n".format(MSG=str(inst))) sys.exit(1) return row_i
python
def wr_data(self, xlsx_data, row_i, worksheet): fld2fmt = self.vars.fld2fmt # User may specify to skip rows based on values in row prt_if = self.vars.prt_if # User may specify a subset of columns to print or # a column ordering different from the _fields seen in the namedtuple prt_flds = self.wbfmtobj.get_prt_flds() get_wbfmt = self.wbfmtobj.get_wbfmt if self.vars.sort_by is not None: xlsx_data = sorted(xlsx_data, key=self.vars.sort_by) try: for data_nt in xlsx_data: if prt_if is None or prt_if(data_nt): wbfmt = get_wbfmt(data_nt) # xlsxwriter.format.Format created w/add_format # Print an xlsx row by printing each column in order. for col_i, fld in enumerate(prt_flds): try: # If fld "format_txt" present, use val for formatting, but don't print. val = getattr(data_nt, fld, "") # Optional user-formatting of specific fields, eg, pval: "{:8.2e}" # If field value is empty (""), don't use fld2fmt if fld2fmt is not None and fld in fld2fmt and val != "" and val != "*": val = fld2fmt[fld].format(val) worksheet.write(row_i, col_i, val, wbfmt) except: raise RuntimeError(self._get_err_msg(row_i, col_i, fld, val, prt_flds)) row_i += 1 except RuntimeError as inst: import traceback traceback.print_exc() sys.stderr.write("\n **FATAL in wr_data: {MSG}\n\n".format(MSG=str(inst))) sys.exit(1) return row_i
[ "def", "wr_data", "(", "self", ",", "xlsx_data", ",", "row_i", ",", "worksheet", ")", ":", "fld2fmt", "=", "self", ".", "vars", ".", "fld2fmt", "# User may specify to skip rows based on values in row", "prt_if", "=", "self", ".", "vars", ".", "prt_if", "# User m...
Write data into xlsx worksheet.
[ "Write", "data", "into", "xlsx", "worksheet", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L64-L97
242,238
tanghaibao/goatools
goatools/wr_tbl_class.py
WrXlsx._get_err_msg
def _get_err_msg(row, col, fld, val, prt_flds): """Return an informative message with details of xlsx write attempt.""" import traceback traceback.print_exc() err_msg = ( "ROW({R}) COL({C}) FIELD({F}) VAL({V})\n".format(R=row, C=col, F=fld, V=val), "PRINT FIELDS({N}): {F}".format(N=len(prt_flds), F=" ".join(prt_flds))) return "\n".join(err_msg)
python
def _get_err_msg(row, col, fld, val, prt_flds): import traceback traceback.print_exc() err_msg = ( "ROW({R}) COL({C}) FIELD({F}) VAL({V})\n".format(R=row, C=col, F=fld, V=val), "PRINT FIELDS({N}): {F}".format(N=len(prt_flds), F=" ".join(prt_flds))) return "\n".join(err_msg)
[ "def", "_get_err_msg", "(", "row", ",", "col", ",", "fld", ",", "val", ",", "prt_flds", ")", ":", "import", "traceback", "traceback", ".", "print_exc", "(", ")", "err_msg", "=", "(", "\"ROW({R}) COL({C}) FIELD({F}) VAL({V})\\n\"", ".", "format", "(", "R", "=...
Return an informative message with details of xlsx write attempt.
[ "Return", "an", "informative", "message", "with", "details", "of", "xlsx", "write", "attempt", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L100-L107
242,239
tanghaibao/goatools
goatools/wr_tbl_class.py
WrXlsx.add_worksheet
def add_worksheet(self): """Add a worksheet to the workbook.""" wsh = self.workbook.add_worksheet() if self.vars.fld2col_widths is not None: self.set_xlsx_colwidths(wsh, self.vars.fld2col_widths, self.wbfmtobj.get_prt_flds()) return wsh
python
def add_worksheet(self): wsh = self.workbook.add_worksheet() if self.vars.fld2col_widths is not None: self.set_xlsx_colwidths(wsh, self.vars.fld2col_widths, self.wbfmtobj.get_prt_flds()) return wsh
[ "def", "add_worksheet", "(", "self", ")", ":", "wsh", "=", "self", ".", "workbook", ".", "add_worksheet", "(", ")", "if", "self", ".", "vars", ".", "fld2col_widths", "is", "not", "None", ":", "self", ".", "set_xlsx_colwidths", "(", "wsh", ",", "self", ...
Add a worksheet to the workbook.
[ "Add", "a", "worksheet", "to", "the", "workbook", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L109-L114
242,240
tanghaibao/goatools
goatools/wr_tbl_class.py
WrXlsx.set_xlsx_colwidths
def set_xlsx_colwidths(worksheet, fld2col_widths, fldnames): """Set xlsx column widths using fld2col_widths.""" for col_idx, fld in enumerate(fldnames): col_width = fld2col_widths.get(fld, None) if col_width is not None: worksheet.set_column(col_idx, col_idx, col_width)
python
def set_xlsx_colwidths(worksheet, fld2col_widths, fldnames): for col_idx, fld in enumerate(fldnames): col_width = fld2col_widths.get(fld, None) if col_width is not None: worksheet.set_column(col_idx, col_idx, col_width)
[ "def", "set_xlsx_colwidths", "(", "worksheet", ",", "fld2col_widths", ",", "fldnames", ")", ":", "for", "col_idx", ",", "fld", "in", "enumerate", "(", "fldnames", ")", ":", "col_width", "=", "fld2col_widths", ".", "get", "(", "fld", ",", "None", ")", "if",...
Set xlsx column widths using fld2col_widths.
[ "Set", "xlsx", "column", "widths", "using", "fld2col_widths", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L117-L122
242,241
tanghaibao/goatools
goatools/wr_tbl_class.py
WbFmt.get_hdrs
def get_hdrs(self, **kws): """Initialize column headers.""" hdrs = get_hdrs(self.prt_flds, **kws) # Values in a "format_txt" "column" are used for formatting, not printing return [h for h in hdrs if h != "format_txt"]
python
def get_hdrs(self, **kws): hdrs = get_hdrs(self.prt_flds, **kws) # Values in a "format_txt" "column" are used for formatting, not printing return [h for h in hdrs if h != "format_txt"]
[ "def", "get_hdrs", "(", "self", ",", "*", "*", "kws", ")", ":", "hdrs", "=", "get_hdrs", "(", "self", ".", "prt_flds", ",", "*", "*", "kws", ")", "# Values in a \"format_txt\" \"column\" are used for formatting, not printing", "return", "[", "h", "for", "h", "...
Initialize column headers.
[ "Initialize", "column", "headers", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L149-L153
242,242
tanghaibao/goatools
goatools/wr_tbl_class.py
WbFmt._init_fmtname2wbfmtobj
def _init_fmtname2wbfmtobj(self, workbook, **kws): """Initialize fmtname2wbfmtobj.""" wbfmtdict = [ kws.get('format_txt0', self.dflt_wbfmtdict[0]), kws.get('format_txt1', self.dflt_wbfmtdict[1]), kws.get('format_txt2', self.dflt_wbfmtdict[2]), kws.get('format_txt3', self.dflt_wbfmtdict[3])] fmtname2wbfmtobj = { 'plain': workbook.add_format(wbfmtdict[0]), 'plain bold': workbook.add_format(wbfmtdict[3]), 'very light grey' : workbook.add_format(wbfmtdict[1]), 'light grey' :workbook.add_format(wbfmtdict[2])} # Use a xlsx namedtuple field value to set row color ntval2wbfmtdict = kws.get('ntval2wbfmtdict', None) if ntval2wbfmtdict is not None: for ntval, wbfmtdict in ntval2wbfmtdict.items(): fmtname2wbfmtobj[ntval] = workbook.add_format(wbfmtdict) if 'ntfld_wbfmt' not in kws: sys.stdout.write("**WARNING: 'ntfld_wbfmt' NOT PRESENT\n") return fmtname2wbfmtobj
python
def _init_fmtname2wbfmtobj(self, workbook, **kws): wbfmtdict = [ kws.get('format_txt0', self.dflt_wbfmtdict[0]), kws.get('format_txt1', self.dflt_wbfmtdict[1]), kws.get('format_txt2', self.dflt_wbfmtdict[2]), kws.get('format_txt3', self.dflt_wbfmtdict[3])] fmtname2wbfmtobj = { 'plain': workbook.add_format(wbfmtdict[0]), 'plain bold': workbook.add_format(wbfmtdict[3]), 'very light grey' : workbook.add_format(wbfmtdict[1]), 'light grey' :workbook.add_format(wbfmtdict[2])} # Use a xlsx namedtuple field value to set row color ntval2wbfmtdict = kws.get('ntval2wbfmtdict', None) if ntval2wbfmtdict is not None: for ntval, wbfmtdict in ntval2wbfmtdict.items(): fmtname2wbfmtobj[ntval] = workbook.add_format(wbfmtdict) if 'ntfld_wbfmt' not in kws: sys.stdout.write("**WARNING: 'ntfld_wbfmt' NOT PRESENT\n") return fmtname2wbfmtobj
[ "def", "_init_fmtname2wbfmtobj", "(", "self", ",", "workbook", ",", "*", "*", "kws", ")", ":", "wbfmtdict", "=", "[", "kws", ".", "get", "(", "'format_txt0'", ",", "self", ".", "dflt_wbfmtdict", "[", "0", "]", ")", ",", "kws", ".", "get", "(", "'form...
Initialize fmtname2wbfmtobj.
[ "Initialize", "fmtname2wbfmtobj", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L155-L174
242,243
tanghaibao/goatools
goatools/wr_tbl_class.py
WbFmt.get_wbfmt
def get_wbfmt(self, data_nt=None): """Return format for text cell.""" if data_nt is None or self.b_plain: return self.fmtname2wbfmtobj.get('plain') # User namedtuple field/value for color if self.ntfld_wbfmt is not None: return self.__get_wbfmt_usrfld(data_nt) # namedtuple format_txt for color/bold/border if self.b_format_txt: wbfmt = self.__get_wbfmt_format_txt(data_nt) if wbfmt is not None: return wbfmt # 'ntfld_wbfmt': namedtuple field which contains a value used as a key for a xlsx format # 'ntval2wbfmtdict': namedtuple value and corresponding xlsx format dict. return self.fmtname2wbfmtobj.get('plain')
python
def get_wbfmt(self, data_nt=None): if data_nt is None or self.b_plain: return self.fmtname2wbfmtobj.get('plain') # User namedtuple field/value for color if self.ntfld_wbfmt is not None: return self.__get_wbfmt_usrfld(data_nt) # namedtuple format_txt for color/bold/border if self.b_format_txt: wbfmt = self.__get_wbfmt_format_txt(data_nt) if wbfmt is not None: return wbfmt # 'ntfld_wbfmt': namedtuple field which contains a value used as a key for a xlsx format # 'ntval2wbfmtdict': namedtuple value and corresponding xlsx format dict. return self.fmtname2wbfmtobj.get('plain')
[ "def", "get_wbfmt", "(", "self", ",", "data_nt", "=", "None", ")", ":", "if", "data_nt", "is", "None", "or", "self", ".", "b_plain", ":", "return", "self", ".", "fmtname2wbfmtobj", ".", "get", "(", "'plain'", ")", "# User namedtuple field/value for color", "...
Return format for text cell.
[ "Return", "format", "for", "text", "cell", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L176-L190
242,244
tanghaibao/goatools
goatools/wr_tbl_class.py
WbFmt.__get_wbfmt_usrfld
def __get_wbfmt_usrfld(self, data_nt): """Return format for text cell from namedtuple field specified by 'ntfld_wbfmt'""" if self.ntfld_wbfmt is not None: if isinstance(self.ntfld_wbfmt, str): ntval = getattr(data_nt, self.ntfld_wbfmt, None) # Ex: 'section' if ntval is not None: return self.fmtname2wbfmtobj.get(ntval, None)
python
def __get_wbfmt_usrfld(self, data_nt): """Return format for text cell from namedtuple field specified by 'ntfld_wbfmt'""" if self.ntfld_wbfmt is not None: if isinstance(self.ntfld_wbfmt, str): ntval = getattr(data_nt, self.ntfld_wbfmt, None) # Ex: 'section' if ntval is not None: return self.fmtname2wbfmtobj.get(ntval, None)
[ "def", "__get_wbfmt_usrfld", "(", "self", ",", "data_nt", ")", ":", "if", "self", ".", "ntfld_wbfmt", "is", "not", "None", ":", "if", "isinstance", "(", "self", ".", "ntfld_wbfmt", ",", "str", ")", ":", "ntval", "=", "getattr", "(", "data_nt", ",", "se...
Return format for text cell from namedtuple field specified by 'ntfld_wbfmt
[ "Return", "format", "for", "text", "cell", "from", "namedtuple", "field", "specified", "by", "ntfld_wbfmt" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L192-L198
242,245
tanghaibao/goatools
goatools/wr_tbl_class.py
WbFmt.__get_wbfmt_format_txt
def __get_wbfmt_format_txt(self, data_nt): """Return format for text cell from namedtuple field, 'format_txt'.""" format_txt_val = getattr(data_nt, "format_txt") if format_txt_val == 1: return self.fmtname2wbfmtobj.get("very light grey") if format_txt_val == 2: return self.fmtname2wbfmtobj.get("light grey") return self.fmtname2wbfmtobj.get(format_txt_val)
python
def __get_wbfmt_format_txt(self, data_nt): format_txt_val = getattr(data_nt, "format_txt") if format_txt_val == 1: return self.fmtname2wbfmtobj.get("very light grey") if format_txt_val == 2: return self.fmtname2wbfmtobj.get("light grey") return self.fmtname2wbfmtobj.get(format_txt_val)
[ "def", "__get_wbfmt_format_txt", "(", "self", ",", "data_nt", ")", ":", "format_txt_val", "=", "getattr", "(", "data_nt", ",", "\"format_txt\"", ")", "if", "format_txt_val", "==", "1", ":", "return", "self", ".", "fmtname2wbfmtobj", ".", "get", "(", "\"very li...
Return format for text cell from namedtuple field, 'format_txt'.
[ "Return", "format", "for", "text", "cell", "from", "namedtuple", "field", "format_txt", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L202-L209
242,246
tanghaibao/goatools
goatools/wr_tbl_class.py
WbFmt.get_fmt_section
def get_fmt_section(self): """Grey if printing header GOs and plain if not printing header GOs.""" if self.b_format_txt: return self.fmtname2wbfmtobj.get("light grey") return self.fmtname2wbfmtobj.get("plain bold")
python
def get_fmt_section(self): if self.b_format_txt: return self.fmtname2wbfmtobj.get("light grey") return self.fmtname2wbfmtobj.get("plain bold")
[ "def", "get_fmt_section", "(", "self", ")", ":", "if", "self", ".", "b_format_txt", ":", "return", "self", ".", "fmtname2wbfmtobj", ".", "get", "(", "\"light grey\"", ")", "return", "self", ".", "fmtname2wbfmtobj", ".", "get", "(", "\"plain bold\"", ")" ]
Grey if printing header GOs and plain if not printing header GOs.
[ "Grey", "if", "printing", "header", "GOs", "and", "plain", "if", "not", "printing", "header", "GOs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/wr_tbl_class.py#L211-L215
242,247
tanghaibao/goatools
goatools/anno/genetogo_reader.py
Gene2GoReader.get_id2gos
def get_id2gos(self, **kws): #### def get_annotations_dct(self, taxid, options): """Return geneid2gos, or optionally go2geneids.""" if len(self.taxid2asscs) == 1: taxid = next(iter(self.taxid2asscs.keys())) return self._get_id2gos(self.taxid2asscs[taxid], **kws) assert 'taxid' in kws, "**FATAL: 'taxid' NOT FOUND IN Gene2GoReader::get_id2gos({KW})".format(KW=kws) taxid = kws['taxid'] assert taxid in self.taxid2asscs, '**FATAL: TAXID({T}) DATA MISSING'.format(T=taxid) return self._get_id2gos(self.taxid2asscs[taxid], **kws)
python
def get_id2gos(self, **kws): #### def get_annotations_dct(self, taxid, options): if len(self.taxid2asscs) == 1: taxid = next(iter(self.taxid2asscs.keys())) return self._get_id2gos(self.taxid2asscs[taxid], **kws) assert 'taxid' in kws, "**FATAL: 'taxid' NOT FOUND IN Gene2GoReader::get_id2gos({KW})".format(KW=kws) taxid = kws['taxid'] assert taxid in self.taxid2asscs, '**FATAL: TAXID({T}) DATA MISSING'.format(T=taxid) return self._get_id2gos(self.taxid2asscs[taxid], **kws)
[ "def", "get_id2gos", "(", "self", ",", "*", "*", "kws", ")", ":", "#### def get_annotations_dct(self, taxid, options):", "if", "len", "(", "self", ".", "taxid2asscs", ")", "==", "1", ":", "taxid", "=", "next", "(", "iter", "(", "self", ".", "taxid2asscs", ...
Return geneid2gos, or optionally go2geneids.
[ "Return", "geneid2gos", "or", "optionally", "go2geneids", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L28-L37
242,248
tanghaibao/goatools
goatools/anno/genetogo_reader.py
Gene2GoReader.get_name
def get_name(self): """Get name using taxid""" if len(self.taxid2asscs) == 1: return '{BASE}_{TAXID}'.format( BASE=self.name, TAXID=next(iter(self.taxid2asscs.keys()))) return '{BASE}_various'.format(BASE=self.name)
python
def get_name(self): if len(self.taxid2asscs) == 1: return '{BASE}_{TAXID}'.format( BASE=self.name, TAXID=next(iter(self.taxid2asscs.keys()))) return '{BASE}_various'.format(BASE=self.name)
[ "def", "get_name", "(", "self", ")", ":", "if", "len", "(", "self", ".", "taxid2asscs", ")", "==", "1", ":", "return", "'{BASE}_{TAXID}'", ".", "format", "(", "BASE", "=", "self", ".", "name", ",", "TAXID", "=", "next", "(", "iter", "(", "self", "....
Get name using taxid
[ "Get", "name", "using", "taxid" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L39-L44
242,249
tanghaibao/goatools
goatools/anno/genetogo_reader.py
Gene2GoReader.get_taxid
def get_taxid(self): """Return taxid, if one was provided. Other wise return True representing all taxids""" return next(iter(self.taxid2asscs.keys())) if len(self.taxid2asscs) == 1 else True
python
def get_taxid(self): return next(iter(self.taxid2asscs.keys())) if len(self.taxid2asscs) == 1 else True
[ "def", "get_taxid", "(", "self", ")", ":", "return", "next", "(", "iter", "(", "self", ".", "taxid2asscs", ".", "keys", "(", ")", ")", ")", "if", "len", "(", "self", ".", "taxid2asscs", ")", "==", "1", "else", "True" ]
Return taxid, if one was provided. Other wise return True representing all taxids
[ "Return", "taxid", "if", "one", "was", "provided", ".", "Other", "wise", "return", "True", "representing", "all", "taxids" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L46-L48
242,250
tanghaibao/goatools
goatools/anno/genetogo_reader.py
Gene2GoReader.fill_taxid2asscs
def fill_taxid2asscs(taxid2asscs_usr, taxid2asscs_ret): """Fill user taxid2asscs for backward compatibility.""" for taxid, ab_ret in taxid2asscs_ret.items(): taxid2asscs_usr[taxid]['ID2GOs'] = ab_ret['ID2GOs'] taxid2asscs_usr[taxid]['GO2IDs'] = ab_ret['GO2IDs']
python
def fill_taxid2asscs(taxid2asscs_usr, taxid2asscs_ret): for taxid, ab_ret in taxid2asscs_ret.items(): taxid2asscs_usr[taxid]['ID2GOs'] = ab_ret['ID2GOs'] taxid2asscs_usr[taxid]['GO2IDs'] = ab_ret['GO2IDs']
[ "def", "fill_taxid2asscs", "(", "taxid2asscs_usr", ",", "taxid2asscs_ret", ")", ":", "for", "taxid", ",", "ab_ret", "in", "taxid2asscs_ret", ".", "items", "(", ")", ":", "taxid2asscs_usr", "[", "taxid", "]", "[", "'ID2GOs'", "]", "=", "ab_ret", "[", "'ID2GOs...
Fill user taxid2asscs for backward compatibility.
[ "Fill", "user", "taxid2asscs", "for", "backward", "compatibility", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L64-L68
242,251
tanghaibao/goatools
goatools/anno/genetogo_reader.py
Gene2GoReader._get_taxids
def _get_taxids(self, taxids=None): """Return user-specified taxids or taxids in self.taxid2asscs""" taxid_keys = set(self.taxid2asscs.keys()) return taxid_keys if taxids is None else set(taxids).intersection(taxid_keys)
python
def _get_taxids(self, taxids=None): taxid_keys = set(self.taxid2asscs.keys()) return taxid_keys if taxids is None else set(taxids).intersection(taxid_keys)
[ "def", "_get_taxids", "(", "self", ",", "taxids", "=", "None", ")", ":", "taxid_keys", "=", "set", "(", "self", ".", "taxid2asscs", ".", "keys", "(", ")", ")", "return", "taxid_keys", "if", "taxids", "is", "None", "else", "set", "(", "taxids", ")", "...
Return user-specified taxids or taxids in self.taxid2asscs
[ "Return", "user", "-", "specified", "taxids", "or", "taxids", "in", "self", ".", "taxid2asscs" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L79-L82
242,252
tanghaibao/goatools
goatools/anno/genetogo_reader.py
Gene2GoReader._init_taxid2asscs
def _init_taxid2asscs(self): """Create dict with taxid keys and annotation namedtuple list.""" taxid2asscs = cx.defaultdict(list) for ntanno in self.associations: taxid2asscs[ntanno.tax_id].append(ntanno) assert len(taxid2asscs) != 0, "**FATAL: NO TAXIDS: {F}".format(F=self.filename) # """Print the number of taxids stored.""" prt = sys.stdout num_taxids = len(taxid2asscs) prt.write('{N} taxids stored'.format(N=num_taxids)) if num_taxids < 5: prt.write(': {Ts}'.format(Ts=' '.join(sorted(str(t) for t in taxid2asscs)))) prt.write('\n') return dict(taxid2asscs)
python
def _init_taxid2asscs(self): taxid2asscs = cx.defaultdict(list) for ntanno in self.associations: taxid2asscs[ntanno.tax_id].append(ntanno) assert len(taxid2asscs) != 0, "**FATAL: NO TAXIDS: {F}".format(F=self.filename) # """Print the number of taxids stored.""" prt = sys.stdout num_taxids = len(taxid2asscs) prt.write('{N} taxids stored'.format(N=num_taxids)) if num_taxids < 5: prt.write(': {Ts}'.format(Ts=' '.join(sorted(str(t) for t in taxid2asscs)))) prt.write('\n') return dict(taxid2asscs)
[ "def", "_init_taxid2asscs", "(", "self", ")", ":", "taxid2asscs", "=", "cx", ".", "defaultdict", "(", "list", ")", "for", "ntanno", "in", "self", ".", "associations", ":", "taxid2asscs", "[", "ntanno", ".", "tax_id", "]", ".", "append", "(", "ntanno", ")...
Create dict with taxid keys and annotation namedtuple list.
[ "Create", "dict", "with", "taxid", "keys", "and", "annotation", "namedtuple", "list", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/genetogo_reader.py#L90-L103
242,253
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGosArgs.get_go2color_inst
def get_go2color_inst(self, hdrgo): """Get a copy of go2color with GO group header colored.""" go2color = self.go2color.copy() go2color[hdrgo] = self.hdrgo_dflt_color return go2color
python
def get_go2color_inst(self, hdrgo): go2color = self.go2color.copy() go2color[hdrgo] = self.hdrgo_dflt_color return go2color
[ "def", "get_go2color_inst", "(", "self", ",", "hdrgo", ")", ":", "go2color", "=", "self", ".", "go2color", ".", "copy", "(", ")", "go2color", "[", "hdrgo", "]", "=", "self", ".", "hdrgo_dflt_color", "return", "go2color" ]
Get a copy of go2color with GO group header colored.
[ "Get", "a", "copy", "of", "go2color", "with", "GO", "group", "header", "colored", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L38-L42
242,254
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGosArgs.get_kws_plt
def get_kws_plt(self): """Get keyword args for GoSubDagPlot from self unless they are None.""" kws_plt = {} for key_plt in self.keys_plt: key_val = getattr(self, key_plt, None) if key_val is not None: kws_plt[key_plt] = key_val elif key_plt in self.kws: kws_plt[key_plt] = self.kws[key_plt] return kws_plt
python
def get_kws_plt(self): kws_plt = {} for key_plt in self.keys_plt: key_val = getattr(self, key_plt, None) if key_val is not None: kws_plt[key_plt] = key_val elif key_plt in self.kws: kws_plt[key_plt] = self.kws[key_plt] return kws_plt
[ "def", "get_kws_plt", "(", "self", ")", ":", "kws_plt", "=", "{", "}", "for", "key_plt", "in", "self", ".", "keys_plt", ":", "key_val", "=", "getattr", "(", "self", ",", "key_plt", ",", "None", ")", "if", "key_val", "is", "not", "None", ":", "kws_plt...
Get keyword args for GoSubDagPlot from self unless they are None.
[ "Get", "keyword", "args", "for", "GoSubDagPlot", "from", "self", "unless", "they", "are", "None", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L44-L53
242,255
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGosArgs._init_go2bordercolor
def _init_go2bordercolor(objcolors, **kws): """Initialize go2bordercolor with default to make hdrgos bright blue.""" go2bordercolor_ret = objcolors.get_bordercolor() if 'go2bordercolor' not in kws: return go2bordercolor_ret go2bordercolor_usr = kws['go2bordercolor'] goids = set(go2bordercolor_ret).intersection(go2bordercolor_usr) for goid in goids: go2bordercolor_usr[goid] = go2bordercolor_ret[goid] return go2bordercolor_usr
python
def _init_go2bordercolor(objcolors, **kws): go2bordercolor_ret = objcolors.get_bordercolor() if 'go2bordercolor' not in kws: return go2bordercolor_ret go2bordercolor_usr = kws['go2bordercolor'] goids = set(go2bordercolor_ret).intersection(go2bordercolor_usr) for goid in goids: go2bordercolor_usr[goid] = go2bordercolor_ret[goid] return go2bordercolor_usr
[ "def", "_init_go2bordercolor", "(", "objcolors", ",", "*", "*", "kws", ")", ":", "go2bordercolor_ret", "=", "objcolors", ".", "get_bordercolor", "(", ")", "if", "'go2bordercolor'", "not", "in", "kws", ":", "return", "go2bordercolor_ret", "go2bordercolor_usr", "=",...
Initialize go2bordercolor with default to make hdrgos bright blue.
[ "Initialize", "go2bordercolor", "with", "default", "to", "make", "hdrgos", "bright", "blue", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L56-L65
242,256
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos.plot_groups_unplaced
def plot_groups_unplaced(self, fout_dir=".", **kws_pltargs): """Plot GO DAGs for groups of user GOs which are not in a section.""" hdrgos = self.grprobj.get_hdrgos_unplaced() pltargs = PltGroupedGosArgs(self.grprobj, fout_dir=fout_dir, **kws_pltargs) return self._plot_groups_hdrgos(hdrgos, pltargs)
python
def plot_groups_unplaced(self, fout_dir=".", **kws_pltargs): hdrgos = self.grprobj.get_hdrgos_unplaced() pltargs = PltGroupedGosArgs(self.grprobj, fout_dir=fout_dir, **kws_pltargs) return self._plot_groups_hdrgos(hdrgos, pltargs)
[ "def", "plot_groups_unplaced", "(", "self", ",", "fout_dir", "=", "\".\"", ",", "*", "*", "kws_pltargs", ")", ":", "hdrgos", "=", "self", ".", "grprobj", ".", "get_hdrgos_unplaced", "(", ")", "pltargs", "=", "PltGroupedGosArgs", "(", "self", ".", "grprobj", ...
Plot GO DAGs for groups of user GOs which are not in a section.
[ "Plot", "GO", "DAGs", "for", "groups", "of", "user", "GOs", "which", "are", "not", "in", "a", "section", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L92-L96
242,257
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._get_plt_data
def _get_plt_data(self, hdrgos_usr): """Given User GO IDs, return their GO headers and other GO info.""" hdrgo2usrgos = self.grprobj.get_hdrgo2usrgos(hdrgos_usr) usrgos_actual = set([u for us in hdrgo2usrgos.values() for u in us]) go2obj = self.gosubdag.get_go2obj(usrgos_actual.union(hdrgo2usrgos.keys())) return hdrgo2usrgos, go2obj
python
def _get_plt_data(self, hdrgos_usr): hdrgo2usrgos = self.grprobj.get_hdrgo2usrgos(hdrgos_usr) usrgos_actual = set([u for us in hdrgo2usrgos.values() for u in us]) go2obj = self.gosubdag.get_go2obj(usrgos_actual.union(hdrgo2usrgos.keys())) return hdrgo2usrgos, go2obj
[ "def", "_get_plt_data", "(", "self", ",", "hdrgos_usr", ")", ":", "hdrgo2usrgos", "=", "self", ".", "grprobj", ".", "get_hdrgo2usrgos", "(", "hdrgos_usr", ")", "usrgos_actual", "=", "set", "(", "[", "u", "for", "us", "in", "hdrgo2usrgos", ".", "values", "(...
Given User GO IDs, return their GO headers and other GO info.
[ "Given", "User", "GO", "IDs", "return", "their", "GO", "headers", "and", "other", "GO", "info", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L103-L108
242,258
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._plot_go_group
def _plot_go_group(self, hdrgo, usrgos, pltargs, go2parentids): """Plot an exploratory GO DAG for a single Group of user GOs.""" gosubdagplotnts = self._get_gosubdagplotnts(hdrgo, usrgos, pltargs, go2parentids) # Create pngs and return png names pngs = [obj.wrplt(pltargs.fout_dir, pltargs.plt_ext) for obj in gosubdagplotnts] return pngs
python
def _plot_go_group(self, hdrgo, usrgos, pltargs, go2parentids): gosubdagplotnts = self._get_gosubdagplotnts(hdrgo, usrgos, pltargs, go2parentids) # Create pngs and return png names pngs = [obj.wrplt(pltargs.fout_dir, pltargs.plt_ext) for obj in gosubdagplotnts] return pngs
[ "def", "_plot_go_group", "(", "self", ",", "hdrgo", ",", "usrgos", ",", "pltargs", ",", "go2parentids", ")", ":", "gosubdagplotnts", "=", "self", ".", "_get_gosubdagplotnts", "(", "hdrgo", ",", "usrgos", ",", "pltargs", ",", "go2parentids", ")", "# Create pngs...
Plot an exploratory GO DAG for a single Group of user GOs.
[ "Plot", "an", "exploratory", "GO", "DAG", "for", "a", "single", "Group", "of", "user", "GOs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L150-L155
242,259
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._get_dotgraphs
def _get_dotgraphs(self, hdrgo, usrgos, pltargs, go2parentids): """Get a GO DAG in a dot-language string for a single Group of user GOs.""" gosubdagplotnts = self._get_gosubdagplotnts(hdrgo, usrgos, pltargs, go2parentids) # Create DAG graphs as dot language strings. Loop through GoSubDagPlotNt list dotstrs = [obj.get_dotstr() for obj in gosubdagplotnts] return dotstrs
python
def _get_dotgraphs(self, hdrgo, usrgos, pltargs, go2parentids): gosubdagplotnts = self._get_gosubdagplotnts(hdrgo, usrgos, pltargs, go2parentids) # Create DAG graphs as dot language strings. Loop through GoSubDagPlotNt list dotstrs = [obj.get_dotstr() for obj in gosubdagplotnts] return dotstrs
[ "def", "_get_dotgraphs", "(", "self", ",", "hdrgo", ",", "usrgos", ",", "pltargs", ",", "go2parentids", ")", ":", "gosubdagplotnts", "=", "self", ".", "_get_gosubdagplotnts", "(", "hdrgo", ",", "usrgos", ",", "pltargs", ",", "go2parentids", ")", "# Create DAG ...
Get a GO DAG in a dot-language string for a single Group of user GOs.
[ "Get", "a", "GO", "DAG", "in", "a", "dot", "-", "language", "string", "for", "a", "single", "Group", "of", "user", "GOs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L157-L162
242,260
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._get_gosubdagplotnts
def _get_gosubdagplotnts(self, hdrgo, usrgos, pltargs, go2parentids): """Get list of GoSubDagPlotNt for plotting an exploratory GODAG for 1 Group of user GOs.""" dotgraphs = [] go2color = pltargs.get_go2color_inst(hdrgo) # namedtuple fields: hdrgo gosubdag tot_usrgos parentcnt desc ntpltgo0 = self._get_pltdag_ancesters(hdrgo, usrgos, desc="") ntpltgo1 = self._get_pltdag_path_hdr(hdrgo, usrgos, desc="pruned") num_go0 = len(ntpltgo0.gosubdag.go2obj) num_go1 = len(ntpltgo1.gosubdag.go2obj) title = "{GO} {NAME}; {N} GO sources".format( GO=hdrgo, NAME=self.gosubdag.go2obj[hdrgo].name, N=len(ntpltgo0.gosubdag.go_sources)) # print("PltGroupedGos::_get_gosubdagplotnts TITLE", title) if num_go0 < pltargs.max_gos: # print("PltGroupedGos::_get_gosubdagplotnts ntpltgo0 ALWAYS IF NOT TOO BIG") dotgraphs.append(self._get_gosubdagplotnt(ntpltgo0, title, go2color, pltargs)) # PLOT A: Plot the entire GO ID group under GO header, hdrgo, if not too big if num_go0 < pltargs.max_gos and \ ntpltgo0.tot_usrgos == ntpltgo1.tot_usrgos: # print("PltGroupedGos::_get_gosubdagplotnts ntpltgo0 AAAAAAAAAAAAAAAAA") dotgraphs.append(self._get_gosubdagplotnt(ntpltgo0, title, go2color, pltargs)) # PLOT B: Plot only the GO ID group passing thru the GO header, hdrgo, if not too big elif num_go1 < pltargs.max_gos and ntpltgo0.tot_usrgos != ntpltgo1.tot_usrgos: # print("PltGroupedGos::_get_gosubdagplotnts ntpltgo1(pruned) BBBBBBBBBBBBBBBBB") dotgraphs.append(self._get_gosubdagplotnt(ntpltgo1, title, go2color, pltargs)) # PLOT C: If DAG is large, just print upper portion # PLOT D: If DAG is large, just print upper portion passing through the GO header elif num_go1 >= pltargs.upper_trigger: # print("PltGroupedGos::_get_gosubdagplotnts upper_pruned CCCCCCCCCCCCCCCCC") gos_upper = self._get_gos_upper(ntpltgo1, pltargs.max_upper, go2parentids) #ntpltgo2 = self._get_pltdag_ancesters(hdrgo, gos_upper, "{BASE}_upper.png") ntpltgo3 = self._get_pltdag_path_hdr(hdrgo, gos_upper, "upper_pruned") # Middle GO terms chosen to be start points will be green unless reset back for goid in gos_upper: if goid not in go2color: go2color[goid] = 'white' dotgraphs.append(self._get_gosubdagplotnt(ntpltgo3, title, go2color, pltargs)) else: # print("PltGroupedGos::_get_gosubdagplotnts EEEEEEEEEEEEEEEEE") self._no_ntplt(ntpltgo0) return dotgraphs
python
def _get_gosubdagplotnts(self, hdrgo, usrgos, pltargs, go2parentids): dotgraphs = [] go2color = pltargs.get_go2color_inst(hdrgo) # namedtuple fields: hdrgo gosubdag tot_usrgos parentcnt desc ntpltgo0 = self._get_pltdag_ancesters(hdrgo, usrgos, desc="") ntpltgo1 = self._get_pltdag_path_hdr(hdrgo, usrgos, desc="pruned") num_go0 = len(ntpltgo0.gosubdag.go2obj) num_go1 = len(ntpltgo1.gosubdag.go2obj) title = "{GO} {NAME}; {N} GO sources".format( GO=hdrgo, NAME=self.gosubdag.go2obj[hdrgo].name, N=len(ntpltgo0.gosubdag.go_sources)) # print("PltGroupedGos::_get_gosubdagplotnts TITLE", title) if num_go0 < pltargs.max_gos: # print("PltGroupedGos::_get_gosubdagplotnts ntpltgo0 ALWAYS IF NOT TOO BIG") dotgraphs.append(self._get_gosubdagplotnt(ntpltgo0, title, go2color, pltargs)) # PLOT A: Plot the entire GO ID group under GO header, hdrgo, if not too big if num_go0 < pltargs.max_gos and \ ntpltgo0.tot_usrgos == ntpltgo1.tot_usrgos: # print("PltGroupedGos::_get_gosubdagplotnts ntpltgo0 AAAAAAAAAAAAAAAAA") dotgraphs.append(self._get_gosubdagplotnt(ntpltgo0, title, go2color, pltargs)) # PLOT B: Plot only the GO ID group passing thru the GO header, hdrgo, if not too big elif num_go1 < pltargs.max_gos and ntpltgo0.tot_usrgos != ntpltgo1.tot_usrgos: # print("PltGroupedGos::_get_gosubdagplotnts ntpltgo1(pruned) BBBBBBBBBBBBBBBBB") dotgraphs.append(self._get_gosubdagplotnt(ntpltgo1, title, go2color, pltargs)) # PLOT C: If DAG is large, just print upper portion # PLOT D: If DAG is large, just print upper portion passing through the GO header elif num_go1 >= pltargs.upper_trigger: # print("PltGroupedGos::_get_gosubdagplotnts upper_pruned CCCCCCCCCCCCCCCCC") gos_upper = self._get_gos_upper(ntpltgo1, pltargs.max_upper, go2parentids) #ntpltgo2 = self._get_pltdag_ancesters(hdrgo, gos_upper, "{BASE}_upper.png") ntpltgo3 = self._get_pltdag_path_hdr(hdrgo, gos_upper, "upper_pruned") # Middle GO terms chosen to be start points will be green unless reset back for goid in gos_upper: if goid not in go2color: go2color[goid] = 'white' dotgraphs.append(self._get_gosubdagplotnt(ntpltgo3, title, go2color, pltargs)) else: # print("PltGroupedGos::_get_gosubdagplotnts EEEEEEEEEEEEEEEEE") self._no_ntplt(ntpltgo0) return dotgraphs
[ "def", "_get_gosubdagplotnts", "(", "self", ",", "hdrgo", ",", "usrgos", ",", "pltargs", ",", "go2parentids", ")", ":", "dotgraphs", "=", "[", "]", "go2color", "=", "pltargs", ".", "get_go2color_inst", "(", "hdrgo", ")", "# namedtuple fields: hdrgo gosubdag tot_us...
Get list of GoSubDagPlotNt for plotting an exploratory GODAG for 1 Group of user GOs.
[ "Get", "list", "of", "GoSubDagPlotNt", "for", "plotting", "an", "exploratory", "GODAG", "for", "1", "Group", "of", "user", "GOs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L164-L205
242,261
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._get_gos_upper
def _get_gos_upper(self, ntpltgo1, max_upper, go2parentids): """Plot a GO DAG for the upper portion of a single Group of user GOs.""" # Get GO IDs which are in the hdrgo path goids_possible = ntpltgo1.gosubdag.go2obj.keys() # Get upper GO IDs which have the most descendants return self._get_gosrcs_upper(goids_possible, max_upper, go2parentids)
python
def _get_gos_upper(self, ntpltgo1, max_upper, go2parentids): # Get GO IDs which are in the hdrgo path goids_possible = ntpltgo1.gosubdag.go2obj.keys() # Get upper GO IDs which have the most descendants return self._get_gosrcs_upper(goids_possible, max_upper, go2parentids)
[ "def", "_get_gos_upper", "(", "self", ",", "ntpltgo1", ",", "max_upper", ",", "go2parentids", ")", ":", "# Get GO IDs which are in the hdrgo path", "goids_possible", "=", "ntpltgo1", ".", "gosubdag", ".", "go2obj", ".", "keys", "(", ")", "# Get upper GO IDs which have...
Plot a GO DAG for the upper portion of a single Group of user GOs.
[ "Plot", "a", "GO", "DAG", "for", "the", "upper", "portion", "of", "a", "single", "Group", "of", "user", "GOs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L207-L212
242,262
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._get_gosrcs_upper
def _get_gosrcs_upper(self, goids, max_upper, go2parentids): """Get GO IDs for the upper portion of the GO DAG.""" gosrcs_upper = set() get_nt = self.gosubdag.go2nt.get go2nt = {g:get_nt(g) for g in goids} # Sort by descending order of descendant counts to find potential new hdrgos go_nt = sorted(go2nt.items(), key=lambda t: -1*t[1].dcnt) goids_upper = set() for goid, _ in go_nt: # Loop through GO ID, GO nt goids_upper.add(goid) if goid in go2parentids: goids_upper |= go2parentids[goid] #print "{} {:3} {}".format(goid, len(goids_upper), gont.GO_name) if len(goids_upper) < max_upper: gosrcs_upper.add(goid) else: break return gosrcs_upper
python
def _get_gosrcs_upper(self, goids, max_upper, go2parentids): gosrcs_upper = set() get_nt = self.gosubdag.go2nt.get go2nt = {g:get_nt(g) for g in goids} # Sort by descending order of descendant counts to find potential new hdrgos go_nt = sorted(go2nt.items(), key=lambda t: -1*t[1].dcnt) goids_upper = set() for goid, _ in go_nt: # Loop through GO ID, GO nt goids_upper.add(goid) if goid in go2parentids: goids_upper |= go2parentids[goid] #print "{} {:3} {}".format(goid, len(goids_upper), gont.GO_name) if len(goids_upper) < max_upper: gosrcs_upper.add(goid) else: break return gosrcs_upper
[ "def", "_get_gosrcs_upper", "(", "self", ",", "goids", ",", "max_upper", ",", "go2parentids", ")", ":", "gosrcs_upper", "=", "set", "(", ")", "get_nt", "=", "self", ".", "gosubdag", ".", "go2nt", ".", "get", "go2nt", "=", "{", "g", ":", "get_nt", "(", ...
Get GO IDs for the upper portion of the GO DAG.
[ "Get", "GO", "IDs", "for", "the", "upper", "portion", "of", "the", "GO", "DAG", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L214-L231
242,263
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._get_gosubdagplotnt
def _get_gosubdagplotnt(self, ntplt, title, go2color, pltargs): """Return GoSubDagPlotNt, which contains both a GoSubDagPlot object and ntobj.""" kws_plt = pltargs.get_kws_plt() kws_plt['id'] = '"{ID}"'.format(ID=ntplt.hdrgo) kws_plt['title'] = "{TITLE} of {M} user GOs".format(TITLE=title, M=ntplt.tot_usrgos) kws_plt['go2color'] = go2color kws_plt['go2bordercolor'] = pltargs.go2bordercolor if ntplt.parentcnt: kws_plt["parentcnt"] = True gosubdagplot = GoSubDagPlot(ntplt.gosubdag, **kws_plt) return GoSubDagPlotNt(self.grprobj, gosubdagplot, ntplt)
python
def _get_gosubdagplotnt(self, ntplt, title, go2color, pltargs): kws_plt = pltargs.get_kws_plt() kws_plt['id'] = '"{ID}"'.format(ID=ntplt.hdrgo) kws_plt['title'] = "{TITLE} of {M} user GOs".format(TITLE=title, M=ntplt.tot_usrgos) kws_plt['go2color'] = go2color kws_plt['go2bordercolor'] = pltargs.go2bordercolor if ntplt.parentcnt: kws_plt["parentcnt"] = True gosubdagplot = GoSubDagPlot(ntplt.gosubdag, **kws_plt) return GoSubDagPlotNt(self.grprobj, gosubdagplot, ntplt)
[ "def", "_get_gosubdagplotnt", "(", "self", ",", "ntplt", ",", "title", ",", "go2color", ",", "pltargs", ")", ":", "kws_plt", "=", "pltargs", ".", "get_kws_plt", "(", ")", "kws_plt", "[", "'id'", "]", "=", "'\"{ID}\"'", ".", "format", "(", "ID", "=", "n...
Return GoSubDagPlotNt, which contains both a GoSubDagPlot object and ntobj.
[ "Return", "GoSubDagPlotNt", "which", "contains", "both", "a", "GoSubDagPlot", "object", "and", "ntobj", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L233-L243
242,264
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._no_ntplt
def _no_ntplt(self, ntplt): """Print a message about the GO DAG Plot we are NOT plotting.""" sys.stdout.write(" {GO_USR:>6,} usr {GO_ALL:>6,} GOs DID NOT WRITE: {B} {D}\n".format( B=self.grprobj.get_fout_base(ntplt.hdrgo), D=ntplt.desc, GO_USR=len(ntplt.gosubdag.go_sources), GO_ALL=len(ntplt.gosubdag.go2obj)))
python
def _no_ntplt(self, ntplt): sys.stdout.write(" {GO_USR:>6,} usr {GO_ALL:>6,} GOs DID NOT WRITE: {B} {D}\n".format( B=self.grprobj.get_fout_base(ntplt.hdrgo), D=ntplt.desc, GO_USR=len(ntplt.gosubdag.go_sources), GO_ALL=len(ntplt.gosubdag.go2obj)))
[ "def", "_no_ntplt", "(", "self", ",", "ntplt", ")", ":", "sys", ".", "stdout", ".", "write", "(", "\" {GO_USR:>6,} usr {GO_ALL:>6,} GOs DID NOT WRITE: {B} {D}\\n\"", ".", "format", "(", "B", "=", "self", ".", "grprobj", ".", "get_fout_base", "(", "ntplt", ".",...
Print a message about the GO DAG Plot we are NOT plotting.
[ "Print", "a", "message", "about", "the", "GO", "DAG", "Plot", "we", "are", "NOT", "plotting", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L245-L251
242,265
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._get_pltdag_ancesters
def _get_pltdag_ancesters(self, hdrgo, usrgos, desc=""): """Get GoSubDag containing hdrgo and all usrgos and their ancesters.""" go_srcs = usrgos.union([hdrgo]) gosubdag = GoSubDag(go_srcs, self.gosubdag.get_go2obj(go_srcs), relationships=self.gosubdag.relationships, rcntobj=self.gosubdag.rcntobj, go2nt=self.gosubdag.go2nt) tot_usrgos = len(set(gosubdag.go2obj.keys()).intersection(self.usrgos)) return self.ntpltgo( hdrgo=hdrgo, gosubdag=gosubdag, tot_usrgos=tot_usrgos, parentcnt=False, desc=desc)
python
def _get_pltdag_ancesters(self, hdrgo, usrgos, desc=""): go_srcs = usrgos.union([hdrgo]) gosubdag = GoSubDag(go_srcs, self.gosubdag.get_go2obj(go_srcs), relationships=self.gosubdag.relationships, rcntobj=self.gosubdag.rcntobj, go2nt=self.gosubdag.go2nt) tot_usrgos = len(set(gosubdag.go2obj.keys()).intersection(self.usrgos)) return self.ntpltgo( hdrgo=hdrgo, gosubdag=gosubdag, tot_usrgos=tot_usrgos, parentcnt=False, desc=desc)
[ "def", "_get_pltdag_ancesters", "(", "self", ",", "hdrgo", ",", "usrgos", ",", "desc", "=", "\"\"", ")", ":", "go_srcs", "=", "usrgos", ".", "union", "(", "[", "hdrgo", "]", ")", "gosubdag", "=", "GoSubDag", "(", "go_srcs", ",", "self", ".", "gosubdag"...
Get GoSubDag containing hdrgo and all usrgos and their ancesters.
[ "Get", "GoSubDag", "containing", "hdrgo", "and", "all", "usrgos", "and", "their", "ancesters", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L253-L267
242,266
tanghaibao/goatools
goatools/grouper/plotobj.py
PltGroupedGos._get_pltdag_path_hdr
def _get_pltdag_path_hdr(self, hdrgo, usrgos, desc="pruned"): """Get GoSubDag with paths from usrgos through hdrgo.""" go_sources = usrgos.union([hdrgo]) gosubdag = GoSubDag(go_sources, self.gosubdag.get_go2obj(go_sources), relationships=self.gosubdag.relationships, rcntobj=self.gosubdag.rcntobj, go2nt=self.gosubdag.go2nt, dst_srcs_list=[(hdrgo, usrgos), (None, set([hdrgo]))]) tot_usrgos = len(set(gosubdag.go2obj.keys()).intersection(self.usrgos)) return self.ntpltgo( hdrgo=hdrgo, gosubdag=gosubdag, tot_usrgos=tot_usrgos, parentcnt=True, desc=desc)
python
def _get_pltdag_path_hdr(self, hdrgo, usrgos, desc="pruned"): go_sources = usrgos.union([hdrgo]) gosubdag = GoSubDag(go_sources, self.gosubdag.get_go2obj(go_sources), relationships=self.gosubdag.relationships, rcntobj=self.gosubdag.rcntobj, go2nt=self.gosubdag.go2nt, dst_srcs_list=[(hdrgo, usrgos), (None, set([hdrgo]))]) tot_usrgos = len(set(gosubdag.go2obj.keys()).intersection(self.usrgos)) return self.ntpltgo( hdrgo=hdrgo, gosubdag=gosubdag, tot_usrgos=tot_usrgos, parentcnt=True, desc=desc)
[ "def", "_get_pltdag_path_hdr", "(", "self", ",", "hdrgo", ",", "usrgos", ",", "desc", "=", "\"pruned\"", ")", ":", "go_sources", "=", "usrgos", ".", "union", "(", "[", "hdrgo", "]", ")", "gosubdag", "=", "GoSubDag", "(", "go_sources", ",", "self", ".", ...
Get GoSubDag with paths from usrgos through hdrgo.
[ "Get", "GoSubDag", "with", "paths", "from", "usrgos", "through", "hdrgo", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L269-L284
242,267
tanghaibao/goatools
goatools/grouper/plotobj.py
GoSubDagPlotNt.wrplt
def wrplt(self, fout_dir, plt_ext="png"): """Write png containing plot of GoSubDag.""" # Ex basename basename = self.grprobj.get_fout_base(self.ntplt.hdrgo) plt_pat = self.get_pltpat(plt_ext) fout_basename = plt_pat.format(BASE=basename) fout_plt = os.path.join(fout_dir, fout_basename) self.gosubdagplot.plt_dag(fout_plt) # Create Plot return fout_plt
python
def wrplt(self, fout_dir, plt_ext="png"): # Ex basename basename = self.grprobj.get_fout_base(self.ntplt.hdrgo) plt_pat = self.get_pltpat(plt_ext) fout_basename = plt_pat.format(BASE=basename) fout_plt = os.path.join(fout_dir, fout_basename) self.gosubdagplot.plt_dag(fout_plt) # Create Plot return fout_plt
[ "def", "wrplt", "(", "self", ",", "fout_dir", ",", "plt_ext", "=", "\"png\"", ")", ":", "# Ex basename", "basename", "=", "self", ".", "grprobj", ".", "get_fout_base", "(", "self", ".", "ntplt", ".", "hdrgo", ")", "plt_pat", "=", "self", ".", "get_pltpat...
Write png containing plot of GoSubDag.
[ "Write", "png", "containing", "plot", "of", "GoSubDag", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L296-L304
242,268
tanghaibao/goatools
goatools/grouper/plotobj.py
GoSubDagPlotNt.get_dotstr
def get_dotstr(self): """Return a string containing DAG graph in Grpahviz's dot language.""" dotobj = self.gosubdagplot.get_pydot_graph() # pydot.Dot dotstr = dotobj.create_dot() return dotstr
python
def get_dotstr(self): dotobj = self.gosubdagplot.get_pydot_graph() # pydot.Dot dotstr = dotobj.create_dot() return dotstr
[ "def", "get_dotstr", "(", "self", ")", ":", "dotobj", "=", "self", ".", "gosubdagplot", ".", "get_pydot_graph", "(", ")", "# pydot.Dot", "dotstr", "=", "dotobj", ".", "create_dot", "(", ")", "return", "dotstr" ]
Return a string containing DAG graph in Grpahviz's dot language.
[ "Return", "a", "string", "containing", "DAG", "graph", "in", "Grpahviz", "s", "dot", "language", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/plotobj.py#L306-L310
242,269
tanghaibao/goatools
goatools/gosubdag/rpt/write_hierarchy.py
WrHierGO._get_wrhiercfg
def _get_wrhiercfg(self): """Initialize print format.""" prtfmt = self.gosubdag.prt_attr['fmt'] prtfmt = prtfmt.replace('{GO} # ', '') prtfmt = prtfmt.replace('{D1:5} ', '') return {'name2prtfmt':{'ITEM':prtfmt, 'ID':'{GO}{alt:1}'}, 'max_indent': self.usrdct.get('max_indent'), 'include_only': self.usrdct.get('include_only'), 'item_marks': self.usrdct.get('item_marks', {}), 'concise_prt': 'concise' in self.usrset, 'indent': 'no_indent' not in self.usrset, 'dash_len': self.usrdct.get('dash_len', 6), 'sortby': self.usrdct.get('sortby') }
python
def _get_wrhiercfg(self): prtfmt = self.gosubdag.prt_attr['fmt'] prtfmt = prtfmt.replace('{GO} # ', '') prtfmt = prtfmt.replace('{D1:5} ', '') return {'name2prtfmt':{'ITEM':prtfmt, 'ID':'{GO}{alt:1}'}, 'max_indent': self.usrdct.get('max_indent'), 'include_only': self.usrdct.get('include_only'), 'item_marks': self.usrdct.get('item_marks', {}), 'concise_prt': 'concise' in self.usrset, 'indent': 'no_indent' not in self.usrset, 'dash_len': self.usrdct.get('dash_len', 6), 'sortby': self.usrdct.get('sortby') }
[ "def", "_get_wrhiercfg", "(", "self", ")", ":", "prtfmt", "=", "self", ".", "gosubdag", ".", "prt_attr", "[", "'fmt'", "]", "prtfmt", "=", "prtfmt", ".", "replace", "(", "'{GO} # '", ",", "''", ")", "prtfmt", "=", "prtfmt", ".", "replace", "(", "'{D1:5...
Initialize print format.
[ "Initialize", "print", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/write_hierarchy.py#L78-L91
242,270
tanghaibao/goatools
goatools/gosubdag/rpt/write_hierarchy.py
WrHierGO._get_goroot
def _get_goroot(self, goids_all, namespace): """Get the top GO for the set of goids_all.""" root_goid = self.consts.NAMESPACE2GO[namespace] if root_goid in goids_all: return root_goid root_goids = set() for goid in goids_all: goterm = self.gosubdag.go2obj[goid] if goterm.depth == 0: root_goids.add(goterm.id) if len(root_goids) == 1: return next(iter(root_goids)) raise RuntimeError("UNEXPECTED NUMBER OF ROOTS: {R}".format(R=root_goids))
python
def _get_goroot(self, goids_all, namespace): root_goid = self.consts.NAMESPACE2GO[namespace] if root_goid in goids_all: return root_goid root_goids = set() for goid in goids_all: goterm = self.gosubdag.go2obj[goid] if goterm.depth == 0: root_goids.add(goterm.id) if len(root_goids) == 1: return next(iter(root_goids)) raise RuntimeError("UNEXPECTED NUMBER OF ROOTS: {R}".format(R=root_goids))
[ "def", "_get_goroot", "(", "self", ",", "goids_all", ",", "namespace", ")", ":", "root_goid", "=", "self", ".", "consts", ".", "NAMESPACE2GO", "[", "namespace", "]", "if", "root_goid", "in", "goids_all", ":", "return", "root_goid", "root_goids", "=", "set", ...
Get the top GO for the set of goids_all.
[ "Get", "the", "top", "GO", "for", "the", "set", "of", "goids_all", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/rpt/write_hierarchy.py#L93-L105
242,271
tanghaibao/goatools
goatools/rpt/nts_xfrm.py
MgrNts.mknts
def mknts(self, add_dct): """Add information from add_dct to a new copy of namedtuples stored in nts.""" nts = [] assert len(add_dct) == len(self.nts) flds = list(next(iter(self.nts))._fields) + list(next(iter(add_dct)).keys()) ntobj = cx.namedtuple("ntgoea", " ".join(flds)) for dct_new, ntgoea in zip(add_dct, self.nts): dct_curr = ntgoea._asdict() for key, val in dct_new.items(): dct_curr[key] = val nts.append(ntobj(**dct_curr)) return nts
python
def mknts(self, add_dct): nts = [] assert len(add_dct) == len(self.nts) flds = list(next(iter(self.nts))._fields) + list(next(iter(add_dct)).keys()) ntobj = cx.namedtuple("ntgoea", " ".join(flds)) for dct_new, ntgoea in zip(add_dct, self.nts): dct_curr = ntgoea._asdict() for key, val in dct_new.items(): dct_curr[key] = val nts.append(ntobj(**dct_curr)) return nts
[ "def", "mknts", "(", "self", ",", "add_dct", ")", ":", "nts", "=", "[", "]", "assert", "len", "(", "add_dct", ")", "==", "len", "(", "self", ".", "nts", ")", "flds", "=", "list", "(", "next", "(", "iter", "(", "self", ".", "nts", ")", ")", "....
Add information from add_dct to a new copy of namedtuples stored in nts.
[ "Add", "information", "from", "add_dct", "to", "a", "new", "copy", "of", "namedtuples", "stored", "in", "nts", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/nts_xfrm.py#L22-L33
242,272
tanghaibao/goatools
goatools/rpt/nts_xfrm.py
MgrNts.add_f2str
def add_f2str(self, dcts, srcfld, dstfld, dstfmt): """Add a namedtuple field of type string generated from an existing namedtuple field.""" # Example: f2str = objntmgr.add_f2str(dcts, "p_fdr_bh", "s_fdr_bh", "{:8.2e}") # ntobj = self.get_ntobj() # print(ntobj) assert len(dcts) == len(self.nts) for dct, ntgoea in zip(dcts, self.nts): valorig = getattr(ntgoea, srcfld) valstr = dstfmt.format(valorig) dct[dstfld] = valstr
python
def add_f2str(self, dcts, srcfld, dstfld, dstfmt): # Example: f2str = objntmgr.add_f2str(dcts, "p_fdr_bh", "s_fdr_bh", "{:8.2e}") # ntobj = self.get_ntobj() # print(ntobj) assert len(dcts) == len(self.nts) for dct, ntgoea in zip(dcts, self.nts): valorig = getattr(ntgoea, srcfld) valstr = dstfmt.format(valorig) dct[dstfld] = valstr
[ "def", "add_f2str", "(", "self", ",", "dcts", ",", "srcfld", ",", "dstfld", ",", "dstfmt", ")", ":", "# Example: f2str = objntmgr.add_f2str(dcts, \"p_fdr_bh\", \"s_fdr_bh\", \"{:8.2e}\")", "# ntobj = self.get_ntobj()", "# print(ntobj)", "assert", "len", "(", "dcts", ")", ...
Add a namedtuple field of type string generated from an existing namedtuple field.
[ "Add", "a", "namedtuple", "field", "of", "type", "string", "generated", "from", "an", "existing", "namedtuple", "field", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/nts_xfrm.py#L35-L44
242,273
tanghaibao/goatools
goatools/rpt/nts_xfrm.py
MgrNts.get_ntobj
def get_ntobj(self): """Create namedtuple object with GOEA fields.""" if self.nts: return cx.namedtuple("ntgoea", " ".join(vars(next(iter(self.nts))).keys()))
python
def get_ntobj(self): if self.nts: return cx.namedtuple("ntgoea", " ".join(vars(next(iter(self.nts))).keys()))
[ "def", "get_ntobj", "(", "self", ")", ":", "if", "self", ".", "nts", ":", "return", "cx", ".", "namedtuple", "(", "\"ntgoea\"", ",", "\" \"", ".", "join", "(", "vars", "(", "next", "(", "iter", "(", "self", ".", "nts", ")", ")", ")", ".", "keys",...
Create namedtuple object with GOEA fields.
[ "Create", "namedtuple", "object", "with", "GOEA", "fields", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/nts_xfrm.py#L46-L49
242,274
tanghaibao/goatools
goatools/semantic.py
get_info_content
def get_info_content(go_id, termcounts): ''' Calculates the information content of a GO term. ''' # Get the observed frequency of the GO term freq = termcounts.get_term_freq(go_id) # Calculate the information content (i.e., -log("freq of GO term") return -1.0 * math.log(freq) if freq else 0
python
def get_info_content(go_id, termcounts): ''' Calculates the information content of a GO term. ''' # Get the observed frequency of the GO term freq = termcounts.get_term_freq(go_id) # Calculate the information content (i.e., -log("freq of GO term") return -1.0 * math.log(freq) if freq else 0
[ "def", "get_info_content", "(", "go_id", ",", "termcounts", ")", ":", "# Get the observed frequency of the GO term", "freq", "=", "termcounts", ".", "get_term_freq", "(", "go_id", ")", "# Calculate the information content (i.e., -log(\"freq of GO term\")", "return", "-", "1.0...
Calculates the information content of a GO term.
[ "Calculates", "the", "information", "content", "of", "a", "GO", "term", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L120-L128
242,275
tanghaibao/goatools
goatools/semantic.py
resnik_sim
def resnik_sim(go_id1, go_id2, godag, termcounts): ''' Computes Resnik's similarity measure. ''' goterm1 = godag[go_id1] goterm2 = godag[go_id2] if goterm1.namespace == goterm2.namespace: msca_goid = deepest_common_ancestor([go_id1, go_id2], godag) return get_info_content(msca_goid, termcounts)
python
def resnik_sim(go_id1, go_id2, godag, termcounts): ''' Computes Resnik's similarity measure. ''' goterm1 = godag[go_id1] goterm2 = godag[go_id2] if goterm1.namespace == goterm2.namespace: msca_goid = deepest_common_ancestor([go_id1, go_id2], godag) return get_info_content(msca_goid, termcounts)
[ "def", "resnik_sim", "(", "go_id1", ",", "go_id2", ",", "godag", ",", "termcounts", ")", ":", "goterm1", "=", "godag", "[", "go_id1", "]", "goterm2", "=", "godag", "[", "go_id2", "]", "if", "goterm1", ".", "namespace", "==", "goterm2", ".", "namespace", ...
Computes Resnik's similarity measure.
[ "Computes", "Resnik", "s", "similarity", "measure", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L131-L139
242,276
tanghaibao/goatools
goatools/semantic.py
lin_sim
def lin_sim(goid1, goid2, godag, termcnts): ''' Computes Lin's similarity measure. ''' sim_r = resnik_sim(goid1, goid2, godag, termcnts) return lin_sim_calc(goid1, goid2, sim_r, termcnts)
python
def lin_sim(goid1, goid2, godag, termcnts): ''' Computes Lin's similarity measure. ''' sim_r = resnik_sim(goid1, goid2, godag, termcnts) return lin_sim_calc(goid1, goid2, sim_r, termcnts)
[ "def", "lin_sim", "(", "goid1", ",", "goid2", ",", "godag", ",", "termcnts", ")", ":", "sim_r", "=", "resnik_sim", "(", "goid1", ",", "goid2", ",", "godag", ",", "termcnts", ")", "return", "lin_sim_calc", "(", "goid1", ",", "goid2", ",", "sim_r", ",", ...
Computes Lin's similarity measure.
[ "Computes", "Lin", "s", "similarity", "measure", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L142-L147
242,277
tanghaibao/goatools
goatools/semantic.py
lin_sim_calc
def lin_sim_calc(goid1, goid2, sim_r, termcnts): ''' Computes Lin's similarity measure using pre-calculated Resnik's similarities. ''' if sim_r is not None: info = get_info_content(goid1, termcnts) + get_info_content(goid2, termcnts) if info != 0: return (2*sim_r)/info
python
def lin_sim_calc(goid1, goid2, sim_r, termcnts): ''' Computes Lin's similarity measure using pre-calculated Resnik's similarities. ''' if sim_r is not None: info = get_info_content(goid1, termcnts) + get_info_content(goid2, termcnts) if info != 0: return (2*sim_r)/info
[ "def", "lin_sim_calc", "(", "goid1", ",", "goid2", ",", "sim_r", ",", "termcnts", ")", ":", "if", "sim_r", "is", "not", "None", ":", "info", "=", "get_info_content", "(", "goid1", ",", "termcnts", ")", "+", "get_info_content", "(", "goid2", ",", "termcnt...
Computes Lin's similarity measure using pre-calculated Resnik's similarities.
[ "Computes", "Lin", "s", "similarity", "measure", "using", "pre", "-", "calculated", "Resnik", "s", "similarities", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L150-L157
242,278
tanghaibao/goatools
goatools/semantic.py
common_parent_go_ids
def common_parent_go_ids(goids, godag): ''' This function finds the common ancestors in the GO tree of the list of goids in the input. ''' # Find candidates from first rec = godag[goids[0]] candidates = rec.get_all_parents() candidates.update({goids[0]}) # Find intersection with second to nth goid for goid in goids[1:]: rec = godag[goid] parents = rec.get_all_parents() parents.update({goid}) # Find the intersection with the candidates, and update. candidates.intersection_update(parents) return candidates
python
def common_parent_go_ids(goids, godag): ''' This function finds the common ancestors in the GO tree of the list of goids in the input. ''' # Find candidates from first rec = godag[goids[0]] candidates = rec.get_all_parents() candidates.update({goids[0]}) # Find intersection with second to nth goid for goid in goids[1:]: rec = godag[goid] parents = rec.get_all_parents() parents.update({goid}) # Find the intersection with the candidates, and update. candidates.intersection_update(parents) return candidates
[ "def", "common_parent_go_ids", "(", "goids", ",", "godag", ")", ":", "# Find candidates from first", "rec", "=", "godag", "[", "goids", "[", "0", "]", "]", "candidates", "=", "rec", ".", "get_all_parents", "(", ")", "candidates", ".", "update", "(", "{", "...
This function finds the common ancestors in the GO tree of the list of goids in the input.
[ "This", "function", "finds", "the", "common", "ancestors", "in", "the", "GO", "tree", "of", "the", "list", "of", "goids", "in", "the", "input", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L160-L178
242,279
tanghaibao/goatools
goatools/semantic.py
deepest_common_ancestor
def deepest_common_ancestor(goterms, godag): ''' This function gets the nearest common ancestor using the above function. Only returns single most specific - assumes unique exists. ''' # Take the element at maximum depth. return max(common_parent_go_ids(goterms, godag), key=lambda t: godag[t].depth)
python
def deepest_common_ancestor(goterms, godag): ''' This function gets the nearest common ancestor using the above function. Only returns single most specific - assumes unique exists. ''' # Take the element at maximum depth. return max(common_parent_go_ids(goterms, godag), key=lambda t: godag[t].depth)
[ "def", "deepest_common_ancestor", "(", "goterms", ",", "godag", ")", ":", "# Take the element at maximum depth.", "return", "max", "(", "common_parent_go_ids", "(", "goterms", ",", "godag", ")", ",", "key", "=", "lambda", "t", ":", "godag", "[", "t", "]", ".",...
This function gets the nearest common ancestor using the above function. Only returns single most specific - assumes unique exists.
[ "This", "function", "gets", "the", "nearest", "common", "ancestor", "using", "the", "above", "function", ".", "Only", "returns", "single", "most", "specific", "-", "assumes", "unique", "exists", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L181-L188
242,280
tanghaibao/goatools
goatools/semantic.py
min_branch_length
def min_branch_length(go_id1, go_id2, godag, branch_dist): ''' Finds the minimum branch length between two terms in the GO DAG. ''' # First get the deepest common ancestor goterm1 = godag[go_id1] goterm2 = godag[go_id2] if goterm1.namespace == goterm2.namespace: dca = deepest_common_ancestor([go_id1, go_id2], godag) # Then get the distance from the DCA to each term dca_depth = godag[dca].depth depth1 = goterm1.depth - dca_depth depth2 = goterm2.depth - dca_depth # Return the total distance - i.e., to the deepest common ancestor and back. return depth1 + depth2 elif branch_dist is not None: return goterm1.depth + goterm2.depth + branch_dist
python
def min_branch_length(go_id1, go_id2, godag, branch_dist): ''' Finds the minimum branch length between two terms in the GO DAG. ''' # First get the deepest common ancestor goterm1 = godag[go_id1] goterm2 = godag[go_id2] if goterm1.namespace == goterm2.namespace: dca = deepest_common_ancestor([go_id1, go_id2], godag) # Then get the distance from the DCA to each term dca_depth = godag[dca].depth depth1 = goterm1.depth - dca_depth depth2 = goterm2.depth - dca_depth # Return the total distance - i.e., to the deepest common ancestor and back. return depth1 + depth2 elif branch_dist is not None: return goterm1.depth + goterm2.depth + branch_dist
[ "def", "min_branch_length", "(", "go_id1", ",", "go_id2", ",", "godag", ",", "branch_dist", ")", ":", "# First get the deepest common ancestor", "goterm1", "=", "godag", "[", "go_id1", "]", "goterm2", "=", "godag", "[", "go_id2", "]", "if", "goterm1", ".", "na...
Finds the minimum branch length between two terms in the GO DAG.
[ "Finds", "the", "minimum", "branch", "length", "between", "two", "terms", "in", "the", "GO", "DAG", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L191-L210
242,281
tanghaibao/goatools
goatools/semantic.py
TermCounts._init_count_terms
def _init_count_terms(self, annots): ''' Fills in the counts and overall aspect counts. ''' gonotindag = set() gocnts = self.gocnts go2obj = self.go2obj # Fill gocnts with GO IDs in annotations and their corresponding counts for terms in annots.values(): # key is 'gene' # Make a union of all the terms for a gene, if term parents are # propagated but they won't get double-counted for the gene allterms = set() for go_id in terms: goobj = go2obj.get(go_id, None) if goobj is not None: allterms.add(go_id) allterms |= goobj.get_all_parents() else: gonotindag.add(go_id) for parent in allterms: gocnts[parent] += 1 if gonotindag: print("{N} Assc. GO IDs not found in the GODag\n".format(N=len(gonotindag)))
python
def _init_count_terms(self, annots): ''' Fills in the counts and overall aspect counts. ''' gonotindag = set() gocnts = self.gocnts go2obj = self.go2obj # Fill gocnts with GO IDs in annotations and their corresponding counts for terms in annots.values(): # key is 'gene' # Make a union of all the terms for a gene, if term parents are # propagated but they won't get double-counted for the gene allterms = set() for go_id in terms: goobj = go2obj.get(go_id, None) if goobj is not None: allterms.add(go_id) allterms |= goobj.get_all_parents() else: gonotindag.add(go_id) for parent in allterms: gocnts[parent] += 1 if gonotindag: print("{N} Assc. GO IDs not found in the GODag\n".format(N=len(gonotindag)))
[ "def", "_init_count_terms", "(", "self", ",", "annots", ")", ":", "gonotindag", "=", "set", "(", ")", "gocnts", "=", "self", ".", "gocnts", "go2obj", "=", "self", ".", "go2obj", "# Fill gocnts with GO IDs in annotations and their corresponding counts", "for", "terms...
Fills in the counts and overall aspect counts.
[ "Fills", "in", "the", "counts", "and", "overall", "aspect", "counts", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L43-L65
242,282
tanghaibao/goatools
goatools/semantic.py
TermCounts._init_add_goid_alt
def _init_add_goid_alt(self): ''' Add alternate GO IDs to term counts. ''' # Fill aspect_counts. Find alternate GO IDs that may not be on gocnts goid_alts = set() go2cnt_add = {} aspect_counts = self.aspect_counts gocnts = self.gocnts go2obj = self.go2obj for go_id, cnt in gocnts.items(): goobj = go2obj[go_id] assert cnt, "NO TERM COUNTS FOR {GO}".format(GO=goobj.item_id) # Was the count set using an alternate GO? if go_id != goobj.item_id: go2cnt_add[goobj.item_id] = cnt goid_alts |= goobj.alt_ids # Group by namespace aspect_counts[goobj.namespace] += cnt # If alternate GO used to set count, add main GO ID for goid, cnt in go2cnt_add.items(): gocnts[goid] = cnt # Add missing alt GO IDs to gocnts for alt_goid in goid_alts.difference(gocnts): goobj = go2obj[alt_goid] cnt = gocnts[goobj.item_id] assert cnt, "NO TERM COUNTS FOR ALT_ID({GOa}) ID({GO}): {NAME}".format( GOa=alt_goid, GO=goobj.item_id, NAME=goobj.name) gocnts[alt_goid] = cnt
python
def _init_add_goid_alt(self): ''' Add alternate GO IDs to term counts. ''' # Fill aspect_counts. Find alternate GO IDs that may not be on gocnts goid_alts = set() go2cnt_add = {} aspect_counts = self.aspect_counts gocnts = self.gocnts go2obj = self.go2obj for go_id, cnt in gocnts.items(): goobj = go2obj[go_id] assert cnt, "NO TERM COUNTS FOR {GO}".format(GO=goobj.item_id) # Was the count set using an alternate GO? if go_id != goobj.item_id: go2cnt_add[goobj.item_id] = cnt goid_alts |= goobj.alt_ids # Group by namespace aspect_counts[goobj.namespace] += cnt # If alternate GO used to set count, add main GO ID for goid, cnt in go2cnt_add.items(): gocnts[goid] = cnt # Add missing alt GO IDs to gocnts for alt_goid in goid_alts.difference(gocnts): goobj = go2obj[alt_goid] cnt = gocnts[goobj.item_id] assert cnt, "NO TERM COUNTS FOR ALT_ID({GOa}) ID({GO}): {NAME}".format( GOa=alt_goid, GO=goobj.item_id, NAME=goobj.name) gocnts[alt_goid] = cnt
[ "def", "_init_add_goid_alt", "(", "self", ")", ":", "# Fill aspect_counts. Find alternate GO IDs that may not be on gocnts", "goid_alts", "=", "set", "(", ")", "go2cnt_add", "=", "{", "}", "aspect_counts", "=", "self", ".", "aspect_counts", "gocnts", "=", "self", ".",...
Add alternate GO IDs to term counts.
[ "Add", "alternate", "GO", "IDs", "to", "term", "counts", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L68-L96
242,283
tanghaibao/goatools
goatools/semantic.py
TermCounts.get_term_freq
def get_term_freq(self, go_id): ''' Returns the frequency at which a particular GO term has been observed in the annotations. ''' num_ns = float(self.get_total_count(self.go2obj[go_id].namespace)) return float(self.get_count(go_id))/num_ns if num_ns != 0 else 0
python
def get_term_freq(self, go_id): ''' Returns the frequency at which a particular GO term has been observed in the annotations. ''' num_ns = float(self.get_total_count(self.go2obj[go_id].namespace)) return float(self.get_count(go_id))/num_ns if num_ns != 0 else 0
[ "def", "get_term_freq", "(", "self", ",", "go_id", ")", ":", "num_ns", "=", "float", "(", "self", ".", "get_total_count", "(", "self", ".", "go2obj", "[", "go_id", "]", ".", "namespace", ")", ")", "return", "float", "(", "self", ".", "get_count", "(", ...
Returns the frequency at which a particular GO term has been observed in the annotations.
[ "Returns", "the", "frequency", "at", "which", "a", "particular", "GO", "term", "has", "been", "observed", "in", "the", "annotations", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/semantic.py#L111-L117
242,284
tanghaibao/goatools
goatools/grouper/hdrgos.py
HdrgosSections.get_sections
def get_sections(self, hdrgo, dflt_section=True): """Given a header GO, return the sections that contain it.""" dflt_list = [] # If the hdrgo is not in a section, return the default name for a section if dflt_section: dflt_list = [self.secdflt] return self.hdrgo2sections.get(hdrgo, dflt_list)
python
def get_sections(self, hdrgo, dflt_section=True): dflt_list = [] # If the hdrgo is not in a section, return the default name for a section if dflt_section: dflt_list = [self.secdflt] return self.hdrgo2sections.get(hdrgo, dflt_list)
[ "def", "get_sections", "(", "self", ",", "hdrgo", ",", "dflt_section", "=", "True", ")", ":", "dflt_list", "=", "[", "]", "# If the hdrgo is not in a section, return the default name for a section", "if", "dflt_section", ":", "dflt_list", "=", "[", "self", ".", "sec...
Given a header GO, return the sections that contain it.
[ "Given", "a", "header", "GO", "return", "the", "sections", "that", "contain", "it", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/hdrgos.py#L25-L31
242,285
tanghaibao/goatools
goatools/grouper/hdrgos.py
HdrgosSections.get_section_hdrgos
def get_section_hdrgos(self): """Get the GO group headers explicitly listed in sections.""" return set([h for _, hs in self.sections for h in hs]) if self.sections else set()
python
def get_section_hdrgos(self): return set([h for _, hs in self.sections for h in hs]) if self.sections else set()
[ "def", "get_section_hdrgos", "(", "self", ")", ":", "return", "set", "(", "[", "h", "for", "_", ",", "hs", "in", "self", ".", "sections", "for", "h", "in", "hs", "]", ")", "if", "self", ".", "sections", "else", "set", "(", ")" ]
Get the GO group headers explicitly listed in sections.
[ "Get", "the", "GO", "group", "headers", "explicitly", "listed", "in", "sections", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/hdrgos.py#L41-L43
242,286
tanghaibao/goatools
goatools/grouper/hdrgos.py
HdrgosSections._chk_sections
def _chk_sections(sections): """Check format of user-provided 'sections' variable""" if sections: assert len(sections[0]) == 2, \ "SECTIONS DATA MUST BE A 2-D LIST. FOUND: {S}".format(S=sections) for _, hdrgos in sections: chk_goids(hdrgos, "HdrgosSections::_chk_sections()")
python
def _chk_sections(sections): if sections: assert len(sections[0]) == 2, \ "SECTIONS DATA MUST BE A 2-D LIST. FOUND: {S}".format(S=sections) for _, hdrgos in sections: chk_goids(hdrgos, "HdrgosSections::_chk_sections()")
[ "def", "_chk_sections", "(", "sections", ")", ":", "if", "sections", ":", "assert", "len", "(", "sections", "[", "0", "]", ")", "==", "2", ",", "\"SECTIONS DATA MUST BE A 2-D LIST. FOUND: {S}\"", ".", "format", "(", "S", "=", "sections", ")", "for", "_", "...
Check format of user-provided 'sections' variable
[ "Check", "format", "of", "user", "-", "provided", "sections", "variable" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/hdrgos.py#L46-L52
242,287
tanghaibao/goatools
goatools/grouper/hdrgos.py
HdrgosSections._init_hdrgos
def _init_hdrgos(self, hdrgos_dflt, hdrgos_usr=None, add_dflt=True): """Initialize GO high""" # Use default GO group header values if (hdrgos_usr is None or hdrgos_usr is False) and not self.sections: return set(hdrgos_dflt) # Get GO group headers provided by user hdrgos_init = set() if hdrgos_usr: chk_goids(hdrgos_usr, "User-provided GO group headers") hdrgos_init |= set(hdrgos_usr) if self.sections: self._chk_sections(self.sections) hdrgos_sec = set([hg for _, hdrgos in self.sections for hg in hdrgos]) chk_goids(hdrgos_sec, "User-provided GO group headers in sections") hdrgos_init |= hdrgos_sec # Add default depth-01 GOs to headers, if desired if add_dflt: return set(hdrgos_init).union(hdrgos_dflt) # Return user-provided GO grouping headers return hdrgos_init
python
def _init_hdrgos(self, hdrgos_dflt, hdrgos_usr=None, add_dflt=True): # Use default GO group header values if (hdrgos_usr is None or hdrgos_usr is False) and not self.sections: return set(hdrgos_dflt) # Get GO group headers provided by user hdrgos_init = set() if hdrgos_usr: chk_goids(hdrgos_usr, "User-provided GO group headers") hdrgos_init |= set(hdrgos_usr) if self.sections: self._chk_sections(self.sections) hdrgos_sec = set([hg for _, hdrgos in self.sections for hg in hdrgos]) chk_goids(hdrgos_sec, "User-provided GO group headers in sections") hdrgos_init |= hdrgos_sec # Add default depth-01 GOs to headers, if desired if add_dflt: return set(hdrgos_init).union(hdrgos_dflt) # Return user-provided GO grouping headers return hdrgos_init
[ "def", "_init_hdrgos", "(", "self", ",", "hdrgos_dflt", ",", "hdrgos_usr", "=", "None", ",", "add_dflt", "=", "True", ")", ":", "# Use default GO group header values", "if", "(", "hdrgos_usr", "is", "None", "or", "hdrgos_usr", "is", "False", ")", "and", "not",...
Initialize GO high
[ "Initialize", "GO", "high" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/hdrgos.py#L69-L88
242,288
tanghaibao/goatools
goatools/obo_tasks.py
get_all_parents
def get_all_parents(go_objs): """Return a set containing all GO Term parents of multiple GOTerm objects.""" go_parents = set() for go_obj in go_objs: go_parents |= go_obj.get_all_parents() return go_parents
python
def get_all_parents(go_objs): go_parents = set() for go_obj in go_objs: go_parents |= go_obj.get_all_parents() return go_parents
[ "def", "get_all_parents", "(", "go_objs", ")", ":", "go_parents", "=", "set", "(", ")", "for", "go_obj", "in", "go_objs", ":", "go_parents", "|=", "go_obj", ".", "get_all_parents", "(", ")", "return", "go_parents" ]
Return a set containing all GO Term parents of multiple GOTerm objects.
[ "Return", "a", "set", "containing", "all", "GO", "Term", "parents", "of", "multiple", "GOTerm", "objects", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_tasks.py#L3-L8
242,289
tanghaibao/goatools
goatools/statsdescribe.py
StatsDescribe.prt_hdr
def prt_hdr(self, prt=sys.stdout, name="name "): """Print stats header in markdown style.""" hdr = "{NAME} | # {ITEMS:11} | range | 25th percentile | " \ " median | 75th percentile | mean | stddev\n".format(NAME=name, ITEMS=self.desc) div = "{DASHES}|---------------|----------------------|" \ "-----------------|----------|-----------------|----------|-------\n".format( DASHES='-'*(len(name))) prt.write(hdr) prt.write(div)
python
def prt_hdr(self, prt=sys.stdout, name="name "): hdr = "{NAME} | # {ITEMS:11} | range | 25th percentile | " \ " median | 75th percentile | mean | stddev\n".format(NAME=name, ITEMS=self.desc) div = "{DASHES}|---------------|----------------------|" \ "-----------------|----------|-----------------|----------|-------\n".format( DASHES='-'*(len(name))) prt.write(hdr) prt.write(div)
[ "def", "prt_hdr", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ",", "name", "=", "\"name \"", ")", ":", "hdr", "=", "\"{NAME} | # {ITEMS:11} | range | 25th percentile | \"", "\" median | 75th percentile | mean | stddev\\n\"", ".", "format", ...
Print stats header in markdown style.
[ "Print", "stats", "header", "in", "markdown", "style", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L21-L29
242,290
tanghaibao/goatools
goatools/statsdescribe.py
StatsDescribe.prt_data
def prt_data(self, name, vals, prt=sys.stdout): """Print stats data in markdown style.""" fld2val = self.get_fld2val(name, vals) prt.write(self.fmt.format(**fld2val)) return fld2val
python
def prt_data(self, name, vals, prt=sys.stdout): fld2val = self.get_fld2val(name, vals) prt.write(self.fmt.format(**fld2val)) return fld2val
[ "def", "prt_data", "(", "self", ",", "name", ",", "vals", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "fld2val", "=", "self", ".", "get_fld2val", "(", "name", ",", "vals", ")", "prt", ".", "write", "(", "self", ".", "fmt", ".", "format", "("...
Print stats data in markdown style.
[ "Print", "stats", "data", "in", "markdown", "style", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L31-L35
242,291
tanghaibao/goatools
goatools/statsdescribe.py
StatsDescribe.getstr_data
def getstr_data(self, name, vals): """Return stats data string in markdown style.""" fld2val = self.get_fld2val(name, vals) return self.fmt.format(**fld2val)
python
def getstr_data(self, name, vals): fld2val = self.get_fld2val(name, vals) return self.fmt.format(**fld2val)
[ "def", "getstr_data", "(", "self", ",", "name", ",", "vals", ")", ":", "fld2val", "=", "self", ".", "get_fld2val", "(", "name", ",", "vals", ")", "return", "self", ".", "fmt", ".", "format", "(", "*", "*", "fld2val", ")" ]
Return stats data string in markdown style.
[ "Return", "stats", "data", "string", "in", "markdown", "style", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L37-L40
242,292
tanghaibao/goatools
goatools/statsdescribe.py
StatsDescribe.get_fld2val
def get_fld2val(self, name, vals): """Describe summary statistics for a list of numbers.""" if vals: return self._init_fld2val_stats(name, vals) return self._init_fld2val_null(name)
python
def get_fld2val(self, name, vals): if vals: return self._init_fld2val_stats(name, vals) return self._init_fld2val_null(name)
[ "def", "get_fld2val", "(", "self", ",", "name", ",", "vals", ")", ":", "if", "vals", ":", "return", "self", ".", "_init_fld2val_stats", "(", "name", ",", "vals", ")", "return", "self", ".", "_init_fld2val_null", "(", "name", ")" ]
Describe summary statistics for a list of numbers.
[ "Describe", "summary", "statistics", "for", "a", "list", "of", "numbers", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L42-L46
242,293
tanghaibao/goatools
goatools/statsdescribe.py
StatsDescribe._init_fld2val_stats
def _init_fld2val_stats(self, name, vals): """Return statistics on values.""" vals_stats = stats.describe(vals) stddev = math.sqrt(vals_stats[3]) # stats variance p25 = np.percentile(vals, 25) p50 = np.percentile(vals, 50) # median p75 = np.percentile(vals, 75) fld2val = { 'name':name, 'qty'.format(ITEMS=self.desc):vals_stats[0], # stats nobs 'range':self._get_str_range(vals_stats), '25th percentile':p25, 'median':p50, '75th percentile':p75, 'mean':vals_stats[2], # stats mean 'stddev':stddev} fmtflds = set(['25th percentile', 'median', '75th percentile', 'mean', 'stddev']) mkint = "," in self.fmtstr for key, val in fld2val.items(): if key in fmtflds: if mkint: val = int(round(val)) fld2val[key] = self.fmtstr.format(val) return fld2val
python
def _init_fld2val_stats(self, name, vals): vals_stats = stats.describe(vals) stddev = math.sqrt(vals_stats[3]) # stats variance p25 = np.percentile(vals, 25) p50 = np.percentile(vals, 50) # median p75 = np.percentile(vals, 75) fld2val = { 'name':name, 'qty'.format(ITEMS=self.desc):vals_stats[0], # stats nobs 'range':self._get_str_range(vals_stats), '25th percentile':p25, 'median':p50, '75th percentile':p75, 'mean':vals_stats[2], # stats mean 'stddev':stddev} fmtflds = set(['25th percentile', 'median', '75th percentile', 'mean', 'stddev']) mkint = "," in self.fmtstr for key, val in fld2val.items(): if key in fmtflds: if mkint: val = int(round(val)) fld2val[key] = self.fmtstr.format(val) return fld2val
[ "def", "_init_fld2val_stats", "(", "self", ",", "name", ",", "vals", ")", ":", "vals_stats", "=", "stats", ".", "describe", "(", "vals", ")", "stddev", "=", "math", ".", "sqrt", "(", "vals_stats", "[", "3", "]", ")", "# stats variance", "p25", "=", "np...
Return statistics on values.
[ "Return", "statistics", "on", "values", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L48-L71
242,294
tanghaibao/goatools
goatools/statsdescribe.py
StatsDescribe._get_str_range
def _get_str_range(self, vals_stats): """Return a string containing the range of values.""" minmax = vals_stats[1] # stats minmax minval = self.fmtstr.format(minmax[0]) maxval = self.fmtstr.format(minmax[1]) return '{A} to {B:6>}'.format(A=minval, B=maxval)
python
def _get_str_range(self, vals_stats): minmax = vals_stats[1] # stats minmax minval = self.fmtstr.format(minmax[0]) maxval = self.fmtstr.format(minmax[1]) return '{A} to {B:6>}'.format(A=minval, B=maxval)
[ "def", "_get_str_range", "(", "self", ",", "vals_stats", ")", ":", "minmax", "=", "vals_stats", "[", "1", "]", "# stats minmax", "minval", "=", "self", ".", "fmtstr", ".", "format", "(", "minmax", "[", "0", "]", ")", "maxval", "=", "self", ".", "fmtstr...
Return a string containing the range of values.
[ "Return", "a", "string", "containing", "the", "range", "of", "values", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/statsdescribe.py#L85-L90
242,295
tanghaibao/goatools
goatools/grouper/tasks.py
SummarySec2dHdrGos.summarize_sec2hdrgos
def summarize_sec2hdrgos(self, sec2d_hdrgos): """Get counts of header GO IDs and sections.""" hdrgos_all = set([]) hdrgos_grouped = set() hdrgos_ungrouped = set() sections_grouped = set() for sectionname, hdrgos in sec2d_hdrgos: self._chk_hdrgoids(hdrgos) hdrgos_all.update(hdrgos) if sectionname != HdrgosSections.secdflt: hdrgos_grouped.update(hdrgos) sections_grouped.add(sectionname) else: hdrgos_ungrouped.update(hdrgos) return {'G': hdrgos_grouped, 'S': sections_grouped, 'U': hdrgos_all.difference(hdrgos_grouped)}
python
def summarize_sec2hdrgos(self, sec2d_hdrgos): hdrgos_all = set([]) hdrgos_grouped = set() hdrgos_ungrouped = set() sections_grouped = set() for sectionname, hdrgos in sec2d_hdrgos: self._chk_hdrgoids(hdrgos) hdrgos_all.update(hdrgos) if sectionname != HdrgosSections.secdflt: hdrgos_grouped.update(hdrgos) sections_grouped.add(sectionname) else: hdrgos_ungrouped.update(hdrgos) return {'G': hdrgos_grouped, 'S': sections_grouped, 'U': hdrgos_all.difference(hdrgos_grouped)}
[ "def", "summarize_sec2hdrgos", "(", "self", ",", "sec2d_hdrgos", ")", ":", "hdrgos_all", "=", "set", "(", "[", "]", ")", "hdrgos_grouped", "=", "set", "(", ")", "hdrgos_ungrouped", "=", "set", "(", ")", "sections_grouped", "=", "set", "(", ")", "for", "s...
Get counts of header GO IDs and sections.
[ "Get", "counts", "of", "header", "GO", "IDs", "and", "sections", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/tasks.py#L12-L28
242,296
tanghaibao/goatools
goatools/grouper/tasks.py
SummarySec2dHdrGos.summarize_sec2hdrnts
def summarize_sec2hdrnts(self, sec2d_hdrnts): """Given namedtuples in each sectin, get counts of header GO IDs and sections.""" sec2d_hdrgos = [(s, set(nt.GO for nt in nts)) for s, nts in sec2d_hdrnts] return self.summarize_sec2hdrgos(sec2d_hdrgos)
python
def summarize_sec2hdrnts(self, sec2d_hdrnts): sec2d_hdrgos = [(s, set(nt.GO for nt in nts)) for s, nts in sec2d_hdrnts] return self.summarize_sec2hdrgos(sec2d_hdrgos)
[ "def", "summarize_sec2hdrnts", "(", "self", ",", "sec2d_hdrnts", ")", ":", "sec2d_hdrgos", "=", "[", "(", "s", ",", "set", "(", "nt", ".", "GO", "for", "nt", "in", "nts", ")", ")", "for", "s", ",", "nts", "in", "sec2d_hdrnts", "]", "return", "self", ...
Given namedtuples in each sectin, get counts of header GO IDs and sections.
[ "Given", "namedtuples", "in", "each", "sectin", "get", "counts", "of", "header", "GO", "IDs", "and", "sections", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/tasks.py#L30-L33
242,297
tanghaibao/goatools
goatools/grouper/tasks.py
SummarySec2dHdrGos._chk_hdrgoids
def _chk_hdrgoids(hdrgos): """Check that hdrgo set is a set of GO IDs.""" goid = next(iter(hdrgos)) if isinstance(goid, str) and goid[:3] == "GO:": return assert False, "HDRGOS DO NOT CONTAIN GO IDs: {E}".format(E=goid)
python
def _chk_hdrgoids(hdrgos): goid = next(iter(hdrgos)) if isinstance(goid, str) and goid[:3] == "GO:": return assert False, "HDRGOS DO NOT CONTAIN GO IDs: {E}".format(E=goid)
[ "def", "_chk_hdrgoids", "(", "hdrgos", ")", ":", "goid", "=", "next", "(", "iter", "(", "hdrgos", ")", ")", "if", "isinstance", "(", "goid", ",", "str", ")", "and", "goid", "[", ":", "3", "]", "==", "\"GO:\"", ":", "return", "assert", "False", ",",...
Check that hdrgo set is a set of GO IDs.
[ "Check", "that", "hdrgo", "set", "is", "a", "set", "of", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/tasks.py#L36-L41
242,298
tanghaibao/goatools
goatools/go_search.py
GoSearch.get_matching_gos
def get_matching_gos(self, compiled_pattern, **kws): """Return all GOs which match the user regex pattern.""" # kws: prt gos matching_gos = [] obo_dag = self.obo_dag prt = kws['prt'] if 'prt' in kws else self.log prt.write('\nPATTERN SEARCH: "{P}"\n'.format(P=compiled_pattern.pattern)) # Only look through GOs in annotation or user-specified GOs srchgos = kws['gos'] if 'gos' in kws else self.go2items.keys() for go_id in srchgos: go_obj = obo_dag.get(go_id, None) if go_obj is not None: for hdr in self.goa_srch_hdrs: if hdr in go_obj.__dict__: fld_val = getattr(go_obj, hdr) matches = self._search_vals(compiled_pattern, fld_val) for mtch in matches: prt.write("MATCH {go_id}({NAME}) {FLD}: {M}\n".format( FLD=hdr, go_id=go_obj.id, NAME=go_obj.name, M=mtch)) if matches: matching_gos.append(go_id) else: prt.write("**WARNING: {GO} found in annotation is not found in obo\n".format( GO=go_id)) matching_gos = set(matching_gos) # Print summary message self._summary_matching_gos(prt, compiled_pattern.pattern, matching_gos, srchgos) return matching_gos
python
def get_matching_gos(self, compiled_pattern, **kws): # kws: prt gos matching_gos = [] obo_dag = self.obo_dag prt = kws['prt'] if 'prt' in kws else self.log prt.write('\nPATTERN SEARCH: "{P}"\n'.format(P=compiled_pattern.pattern)) # Only look through GOs in annotation or user-specified GOs srchgos = kws['gos'] if 'gos' in kws else self.go2items.keys() for go_id in srchgos: go_obj = obo_dag.get(go_id, None) if go_obj is not None: for hdr in self.goa_srch_hdrs: if hdr in go_obj.__dict__: fld_val = getattr(go_obj, hdr) matches = self._search_vals(compiled_pattern, fld_val) for mtch in matches: prt.write("MATCH {go_id}({NAME}) {FLD}: {M}\n".format( FLD=hdr, go_id=go_obj.id, NAME=go_obj.name, M=mtch)) if matches: matching_gos.append(go_id) else: prt.write("**WARNING: {GO} found in annotation is not found in obo\n".format( GO=go_id)) matching_gos = set(matching_gos) # Print summary message self._summary_matching_gos(prt, compiled_pattern.pattern, matching_gos, srchgos) return matching_gos
[ "def", "get_matching_gos", "(", "self", ",", "compiled_pattern", ",", "*", "*", "kws", ")", ":", "# kws: prt gos", "matching_gos", "=", "[", "]", "obo_dag", "=", "self", ".", "obo_dag", "prt", "=", "kws", "[", "'prt'", "]", "if", "'prt'", "in", "kws", ...
Return all GOs which match the user regex pattern.
[ "Return", "all", "GOs", "which", "match", "the", "user", "regex", "pattern", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L20-L47
242,299
tanghaibao/goatools
goatools/go_search.py
GoSearch._summary_matching_gos
def _summary_matching_gos(prt, pattern, matching_gos, all_gos): """Print summary for get_matching_gos.""" msg = 'Found {N} GO(s) out of {M} matching pattern("{P}")\n' num_gos = len(matching_gos) num_all = len(all_gos) prt.write(msg.format(N=num_gos, M=num_all, P=pattern))
python
def _summary_matching_gos(prt, pattern, matching_gos, all_gos): msg = 'Found {N} GO(s) out of {M} matching pattern("{P}")\n' num_gos = len(matching_gos) num_all = len(all_gos) prt.write(msg.format(N=num_gos, M=num_all, P=pattern))
[ "def", "_summary_matching_gos", "(", "prt", ",", "pattern", ",", "matching_gos", ",", "all_gos", ")", ":", "msg", "=", "'Found {N} GO(s) out of {M} matching pattern(\"{P}\")\\n'", "num_gos", "=", "len", "(", "matching_gos", ")", "num_all", "=", "len", "(", "all_gos"...
Print summary for get_matching_gos.
[ "Print", "summary", "for", "get_matching_gos", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/go_search.py#L50-L55