id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
75
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
228,500
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._get_objanno
def _get_objanno(self, assoc_fn): """Get an annotation object""" # Determine annotation file format from filename, if possible anno_type = get_anno_desc(assoc_fn, None) # Default annotation file format is id2gos if anno_type is None: anno_type = self.args.annofmt if self.args.annofmt else 'id2gos' kws = {'taxid': self.args.taxid} if anno_type == 'gene2go' else {} return get_objanno(assoc_fn, anno_type, **kws)
python
def _get_objanno(self, assoc_fn): """Get an annotation object""" # Determine annotation file format from filename, if possible anno_type = get_anno_desc(assoc_fn, None) # Default annotation file format is id2gos if anno_type is None: anno_type = self.args.annofmt if self.args.annofmt else 'id2gos' kws = {'taxid': self.args.taxid} if anno_type == 'gene2go' else {} return get_objanno(assoc_fn, anno_type, **kws)
[ "def", "_get_objanno", "(", "self", ",", "assoc_fn", ")", ":", "# Determine annotation file format from filename, if possible", "anno_type", "=", "get_anno_desc", "(", "assoc_fn", ",", "None", ")", "# Default annotation file format is id2gos", "if", "anno_type", "is", "None", ":", "anno_type", "=", "self", ".", "args", ".", "annofmt", "if", "self", ".", "args", ".", "annofmt", "else", "'id2gos'", "kws", "=", "{", "'taxid'", ":", "self", ".", "args", ".", "taxid", "}", "if", "anno_type", "==", "'gene2go'", "else", "{", "}", "return", "get_objanno", "(", "assoc_fn", ",", "anno_type", ",", "*", "*", "kws", ")" ]
Get an annotation object
[ "Get", "an", "annotation", "object" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L191-L199
228,501
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._init_itemid2name
def _init_itemid2name(self): """Print gene symbols instead of gene IDs, if provided.""" if not hasattr(self.args, 'id2sym'): return None fin_id2sym = self.args.id2sym if fin_id2sym is not None and os.path.exists(fin_id2sym): id2sym = {} cmpl = re.compile(r'^\s*(\S+)[\s,;]+(\S+)') with open(fin_id2sym) as ifstrm: for line in ifstrm: mtch = cmpl.search(line) if mtch: id2sym[mtch.group(1)] = mtch.group(2) return id2sym
python
def _init_itemid2name(self): """Print gene symbols instead of gene IDs, if provided.""" if not hasattr(self.args, 'id2sym'): return None fin_id2sym = self.args.id2sym if fin_id2sym is not None and os.path.exists(fin_id2sym): id2sym = {} cmpl = re.compile(r'^\s*(\S+)[\s,;]+(\S+)') with open(fin_id2sym) as ifstrm: for line in ifstrm: mtch = cmpl.search(line) if mtch: id2sym[mtch.group(1)] = mtch.group(2) return id2sym
[ "def", "_init_itemid2name", "(", "self", ")", ":", "if", "not", "hasattr", "(", "self", ".", "args", ",", "'id2sym'", ")", ":", "return", "None", "fin_id2sym", "=", "self", ".", "args", ".", "id2sym", "if", "fin_id2sym", "is", "not", "None", "and", "os", ".", "path", ".", "exists", "(", "fin_id2sym", ")", ":", "id2sym", "=", "{", "}", "cmpl", "=", "re", ".", "compile", "(", "r'^\\s*(\\S+)[\\s,;]+(\\S+)'", ")", "with", "open", "(", "fin_id2sym", ")", "as", "ifstrm", ":", "for", "line", "in", "ifstrm", ":", "mtch", "=", "cmpl", ".", "search", "(", "line", ")", "if", "mtch", ":", "id2sym", "[", "mtch", ".", "group", "(", "1", ")", "]", "=", "mtch", ".", "group", "(", "2", ")", "return", "id2sym" ]
Print gene symbols instead of gene IDs, if provided.
[ "Print", "gene", "symbols", "instead", "of", "gene", "IDs", "if", "provided", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L201-L214
228,502
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.prt_results
def prt_results(self, goea_results): """Print GOEA results to the screen or to a file.""" # objaart = self.prepgrp.get_objaart(goea_results) if self.prepgrp is not None else None if self.args.outfile is None: self._prt_results(goea_results) else: # Users can print to both tab-separated file and xlsx file in one run. outfiles = self.args.outfile.split(",") grpwr = self.prepgrp.get_objgrpwr(goea_results) if self.prepgrp else None if grpwr is None: self.prt_outfiles_flat(goea_results, outfiles) else: grpwr.prt_outfiles_grouped(outfiles)
python
def prt_results(self, goea_results): """Print GOEA results to the screen or to a file.""" # objaart = self.prepgrp.get_objaart(goea_results) if self.prepgrp is not None else None if self.args.outfile is None: self._prt_results(goea_results) else: # Users can print to both tab-separated file and xlsx file in one run. outfiles = self.args.outfile.split(",") grpwr = self.prepgrp.get_objgrpwr(goea_results) if self.prepgrp else None if grpwr is None: self.prt_outfiles_flat(goea_results, outfiles) else: grpwr.prt_outfiles_grouped(outfiles)
[ "def", "prt_results", "(", "self", ",", "goea_results", ")", ":", "# objaart = self.prepgrp.get_objaart(goea_results) if self.prepgrp is not None else None", "if", "self", ".", "args", ".", "outfile", "is", "None", ":", "self", ".", "_prt_results", "(", "goea_results", ")", "else", ":", "# Users can print to both tab-separated file and xlsx file in one run.", "outfiles", "=", "self", ".", "args", ".", "outfile", ".", "split", "(", "\",\"", ")", "grpwr", "=", "self", ".", "prepgrp", ".", "get_objgrpwr", "(", "goea_results", ")", "if", "self", ".", "prepgrp", "else", "None", "if", "grpwr", "is", "None", ":", "self", ".", "prt_outfiles_flat", "(", "goea_results", ",", "outfiles", ")", "else", ":", "grpwr", ".", "prt_outfiles_grouped", "(", "outfiles", ")" ]
Print GOEA results to the screen or to a file.
[ "Print", "GOEA", "results", "to", "the", "screen", "or", "to", "a", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L216-L228
228,503
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._prt_results
def _prt_results(self, goea_results): """Print GOEA results to the screen.""" min_ratio = self.args.ratio if min_ratio is not None: assert 1 <= min_ratio <= 2 self.objgoea.print_date(min_ratio=min_ratio, pval=self.args.pval) results_adj = self.objgoea.get_adj_records(goea_results, min_ratio, self.args.pval) if results_adj: if not self.prepgrp: self.objgoea.print_results_adj(results_adj, indent=self.args.indent) else: grpwr = self.prepgrp.get_objgrpwr(results_adj) grpwr.prt_txt(sys.stdout)
python
def _prt_results(self, goea_results): """Print GOEA results to the screen.""" min_ratio = self.args.ratio if min_ratio is not None: assert 1 <= min_ratio <= 2 self.objgoea.print_date(min_ratio=min_ratio, pval=self.args.pval) results_adj = self.objgoea.get_adj_records(goea_results, min_ratio, self.args.pval) if results_adj: if not self.prepgrp: self.objgoea.print_results_adj(results_adj, indent=self.args.indent) else: grpwr = self.prepgrp.get_objgrpwr(results_adj) grpwr.prt_txt(sys.stdout)
[ "def", "_prt_results", "(", "self", ",", "goea_results", ")", ":", "min_ratio", "=", "self", ".", "args", ".", "ratio", "if", "min_ratio", "is", "not", "None", ":", "assert", "1", "<=", "min_ratio", "<=", "2", "self", ".", "objgoea", ".", "print_date", "(", "min_ratio", "=", "min_ratio", ",", "pval", "=", "self", ".", "args", ".", "pval", ")", "results_adj", "=", "self", ".", "objgoea", ".", "get_adj_records", "(", "goea_results", ",", "min_ratio", ",", "self", ".", "args", ".", "pval", ")", "if", "results_adj", ":", "if", "not", "self", ".", "prepgrp", ":", "self", ".", "objgoea", ".", "print_results_adj", "(", "results_adj", ",", "indent", "=", "self", ".", "args", ".", "indent", ")", "else", ":", "grpwr", "=", "self", ".", "prepgrp", ".", "get_objgrpwr", "(", "results_adj", ")", "grpwr", ".", "prt_txt", "(", "sys", ".", "stdout", ")" ]
Print GOEA results to the screen.
[ "Print", "GOEA", "results", "to", "the", "screen", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L241-L253
228,504
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.chk_genes
def chk_genes(self, study, pop, assoc=None): """Check gene sets.""" if len(pop) < len(study): exit("\nERROR: The study file contains more elements than the population file. " "Please check that the study file is a subset of the population file.\n") # check the fraction of genomic ids that overlap between study and population overlap = self.get_overlap(study, pop) if overlap < 0.95: sys.stderr.write("\nWARNING: only {} fraction of genes/proteins in study are found in " "the population background.\n\n".format(overlap)) if overlap <= self.args.min_overlap: exit("\nERROR: only {} of genes/proteins in the study are found in the " "background population. Please check.\n".format(overlap)) # Population and associations if assoc is not None and pop.isdisjoint(assoc.keys()): if self.objanno.name == 'gene2go': err = ('**FATAL: NO POPULATION ITEMS SEEN IN THE NCBI gene2go ANNOTATIONS ' 'FOR taxid({T}). TRY: --taxid=<taxid number>') exit(err.format(T=next(iter(self.objanno.taxid2asscs.keys())))) else: exit('**FATAL: NO POPULATION ITEMS SEEN IN THE ANNOTATIONS')
python
def chk_genes(self, study, pop, assoc=None): """Check gene sets.""" if len(pop) < len(study): exit("\nERROR: The study file contains more elements than the population file. " "Please check that the study file is a subset of the population file.\n") # check the fraction of genomic ids that overlap between study and population overlap = self.get_overlap(study, pop) if overlap < 0.95: sys.stderr.write("\nWARNING: only {} fraction of genes/proteins in study are found in " "the population background.\n\n".format(overlap)) if overlap <= self.args.min_overlap: exit("\nERROR: only {} of genes/proteins in the study are found in the " "background population. Please check.\n".format(overlap)) # Population and associations if assoc is not None and pop.isdisjoint(assoc.keys()): if self.objanno.name == 'gene2go': err = ('**FATAL: NO POPULATION ITEMS SEEN IN THE NCBI gene2go ANNOTATIONS ' 'FOR taxid({T}). TRY: --taxid=<taxid number>') exit(err.format(T=next(iter(self.objanno.taxid2asscs.keys())))) else: exit('**FATAL: NO POPULATION ITEMS SEEN IN THE ANNOTATIONS')
[ "def", "chk_genes", "(", "self", ",", "study", ",", "pop", ",", "assoc", "=", "None", ")", ":", "if", "len", "(", "pop", ")", "<", "len", "(", "study", ")", ":", "exit", "(", "\"\\nERROR: The study file contains more elements than the population file. \"", "\"Please check that the study file is a subset of the population file.\\n\"", ")", "# check the fraction of genomic ids that overlap between study and population", "overlap", "=", "self", ".", "get_overlap", "(", "study", ",", "pop", ")", "if", "overlap", "<", "0.95", ":", "sys", ".", "stderr", ".", "write", "(", "\"\\nWARNING: only {} fraction of genes/proteins in study are found in \"", "\"the population background.\\n\\n\"", ".", "format", "(", "overlap", ")", ")", "if", "overlap", "<=", "self", ".", "args", ".", "min_overlap", ":", "exit", "(", "\"\\nERROR: only {} of genes/proteins in the study are found in the \"", "\"background population. Please check.\\n\"", ".", "format", "(", "overlap", ")", ")", "# Population and associations", "if", "assoc", "is", "not", "None", "and", "pop", ".", "isdisjoint", "(", "assoc", ".", "keys", "(", ")", ")", ":", "if", "self", ".", "objanno", ".", "name", "==", "'gene2go'", ":", "err", "=", "(", "'**FATAL: NO POPULATION ITEMS SEEN IN THE NCBI gene2go ANNOTATIONS '", "'FOR taxid({T}). TRY: --taxid=<taxid number>'", ")", "exit", "(", "err", ".", "format", "(", "T", "=", "next", "(", "iter", "(", "self", ".", "objanno", ".", "taxid2asscs", ".", "keys", "(", ")", ")", ")", ")", ")", "else", ":", "exit", "(", "'**FATAL: NO POPULATION ITEMS SEEN IN THE ANNOTATIONS'", ")" ]
Check gene sets.
[ "Check", "gene", "sets", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L269-L289
228,505
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.get_results_sig
def get_results_sig(self): """Get significant results.""" # Only print results when uncorrected p-value < this value. print("{N:7,} of {M:,} results have uncorrected P-values <= {PVAL}=pval\n".format( N=sum(1 for r in self.results_all if r.p_uncorrected < self.args.pval), M=len(self.results_all), PVAL=self.args.pval)) pval_fld = self.get_pval_field() results = [r for r in self.results_all if getattr(r, pval_fld) <= self.args.pval] return results
python
def get_results_sig(self): """Get significant results.""" # Only print results when uncorrected p-value < this value. print("{N:7,} of {M:,} results have uncorrected P-values <= {PVAL}=pval\n".format( N=sum(1 for r in self.results_all if r.p_uncorrected < self.args.pval), M=len(self.results_all), PVAL=self.args.pval)) pval_fld = self.get_pval_field() results = [r for r in self.results_all if getattr(r, pval_fld) <= self.args.pval] return results
[ "def", "get_results_sig", "(", "self", ")", ":", "# Only print results when uncorrected p-value < this value.", "print", "(", "\"{N:7,} of {M:,} results have uncorrected P-values <= {PVAL}=pval\\n\"", ".", "format", "(", "N", "=", "sum", "(", "1", "for", "r", "in", "self", ".", "results_all", "if", "r", ".", "p_uncorrected", "<", "self", ".", "args", ".", "pval", ")", ",", "M", "=", "len", "(", "self", ".", "results_all", ")", ",", "PVAL", "=", "self", ".", "args", ".", "pval", ")", ")", "pval_fld", "=", "self", ".", "get_pval_field", "(", ")", "results", "=", "[", "r", "for", "r", "in", "self", ".", "results_all", "if", "getattr", "(", "r", ",", "pval_fld", ")", "<=", "self", ".", "args", ".", "pval", "]", "return", "results" ]
Get significant results.
[ "Get", "significant", "results", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L291-L300
228,506
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.get_pval_field
def get_pval_field(self): """Get 'p_uncorrected' or the user-specified field for determining significant results.""" pval_fld = self.args.pval_field # If --pval_field [VAL] was specified if pval_fld is not None: if pval_fld[:2] != 'p_': pval_fld = 'p_' + pval_fld # If only one method was used, use that instead of the uncorrected pvalue elif len(self.methods) == 1: pval_fld = 'p_' + self.methods[0] # Use 'uncorrected pvalue' if there are many methods & none chosen using --pval_field else: pval_fld = 'p_uncorrected' if self.results_all: assert hasattr(next(iter(self.results_all)), pval_fld), \ 'NO PVAL({P}). EXPECTED ONE OF: {E}'.format( P=self.args.pval_field, E=" ".join([k for k in dir(next(iter(self.results_all))) if k[:2] == 'p_'])) return pval_fld
python
def get_pval_field(self): """Get 'p_uncorrected' or the user-specified field for determining significant results.""" pval_fld = self.args.pval_field # If --pval_field [VAL] was specified if pval_fld is not None: if pval_fld[:2] != 'p_': pval_fld = 'p_' + pval_fld # If only one method was used, use that instead of the uncorrected pvalue elif len(self.methods) == 1: pval_fld = 'p_' + self.methods[0] # Use 'uncorrected pvalue' if there are many methods & none chosen using --pval_field else: pval_fld = 'p_uncorrected' if self.results_all: assert hasattr(next(iter(self.results_all)), pval_fld), \ 'NO PVAL({P}). EXPECTED ONE OF: {E}'.format( P=self.args.pval_field, E=" ".join([k for k in dir(next(iter(self.results_all))) if k[:2] == 'p_'])) return pval_fld
[ "def", "get_pval_field", "(", "self", ")", ":", "pval_fld", "=", "self", ".", "args", ".", "pval_field", "# If --pval_field [VAL] was specified", "if", "pval_fld", "is", "not", "None", ":", "if", "pval_fld", "[", ":", "2", "]", "!=", "'p_'", ":", "pval_fld", "=", "'p_'", "+", "pval_fld", "# If only one method was used, use that instead of the uncorrected pvalue", "elif", "len", "(", "self", ".", "methods", ")", "==", "1", ":", "pval_fld", "=", "'p_'", "+", "self", ".", "methods", "[", "0", "]", "# Use 'uncorrected pvalue' if there are many methods & none chosen using --pval_field", "else", ":", "pval_fld", "=", "'p_uncorrected'", "if", "self", ".", "results_all", ":", "assert", "hasattr", "(", "next", "(", "iter", "(", "self", ".", "results_all", ")", ")", ",", "pval_fld", ")", ",", "'NO PVAL({P}). EXPECTED ONE OF: {E}'", ".", "format", "(", "P", "=", "self", ".", "args", ".", "pval_field", ",", "E", "=", "\" \"", ".", "join", "(", "[", "k", "for", "k", "in", "dir", "(", "next", "(", "iter", "(", "self", ".", "results_all", ")", ")", ")", "if", "k", "[", ":", "2", "]", "==", "'p_'", "]", ")", ")", "return", "pval_fld" ]
Get 'p_uncorrected' or the user-specified field for determining significant results.
[ "Get", "p_uncorrected", "or", "the", "user", "-", "specified", "field", "for", "determining", "significant", "results", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L307-L325
228,507
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc.rd_files
def rd_files(self, study_fn, pop_fn): """Read files and return study and population.""" study, pop = self._read_geneset(study_fn, pop_fn) print("Study: {0} vs. Population {1}\n".format(len(study), len(pop))) return study, pop
python
def rd_files(self, study_fn, pop_fn): """Read files and return study and population.""" study, pop = self._read_geneset(study_fn, pop_fn) print("Study: {0} vs. Population {1}\n".format(len(study), len(pop))) return study, pop
[ "def", "rd_files", "(", "self", ",", "study_fn", ",", "pop_fn", ")", ":", "study", ",", "pop", "=", "self", ".", "_read_geneset", "(", "study_fn", ",", "pop_fn", ")", "print", "(", "\"Study: {0} vs. Population {1}\\n\"", ".", "format", "(", "len", "(", "study", ")", ",", "len", "(", "pop", ")", ")", ")", "return", "study", ",", "pop" ]
Read files and return study and population.
[ "Read", "files", "and", "return", "study", "and", "population", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L327-L331
228,508
tanghaibao/goatools
goatools/cli/find_enrichment.py
GoeaCliFnc._read_geneset
def _read_geneset(self, study_fn, pop_fn): """Open files containing genes. Return study genes and population genes.""" pop = set(_.strip() for _ in open(pop_fn) if _.strip()) study = frozenset(_.strip() for _ in open(study_fn) if _.strip()) if next(iter(pop)).isdigit(): pop = set(int(g) for g in pop) study = frozenset(int(g) for g in study) # some times the pop is a second group to compare, rather than the # population in that case, we need to make sure the overlapping terms # are removed first if self.args.compare: common = pop & study pop |= study pop -= common study -= common sys.stderr.write("removed %d overlapping items\n" % (len(common))) sys.stderr.write("Set 1: {0}, Set 2: {1}\n".format( len(study), len(pop))) return study, pop
python
def _read_geneset(self, study_fn, pop_fn): """Open files containing genes. Return study genes and population genes.""" pop = set(_.strip() for _ in open(pop_fn) if _.strip()) study = frozenset(_.strip() for _ in open(study_fn) if _.strip()) if next(iter(pop)).isdigit(): pop = set(int(g) for g in pop) study = frozenset(int(g) for g in study) # some times the pop is a second group to compare, rather than the # population in that case, we need to make sure the overlapping terms # are removed first if self.args.compare: common = pop & study pop |= study pop -= common study -= common sys.stderr.write("removed %d overlapping items\n" % (len(common))) sys.stderr.write("Set 1: {0}, Set 2: {1}\n".format( len(study), len(pop))) return study, pop
[ "def", "_read_geneset", "(", "self", ",", "study_fn", ",", "pop_fn", ")", ":", "pop", "=", "set", "(", "_", ".", "strip", "(", ")", "for", "_", "in", "open", "(", "pop_fn", ")", "if", "_", ".", "strip", "(", ")", ")", "study", "=", "frozenset", "(", "_", ".", "strip", "(", ")", "for", "_", "in", "open", "(", "study_fn", ")", "if", "_", ".", "strip", "(", ")", ")", "if", "next", "(", "iter", "(", "pop", ")", ")", ".", "isdigit", "(", ")", ":", "pop", "=", "set", "(", "int", "(", "g", ")", "for", "g", "in", "pop", ")", "study", "=", "frozenset", "(", "int", "(", "g", ")", "for", "g", "in", "study", ")", "# some times the pop is a second group to compare, rather than the", "# population in that case, we need to make sure the overlapping terms", "# are removed first", "if", "self", ".", "args", ".", "compare", ":", "common", "=", "pop", "&", "study", "pop", "|=", "study", "pop", "-=", "common", "study", "-=", "common", "sys", ".", "stderr", ".", "write", "(", "\"removed %d overlapping items\\n\"", "%", "(", "len", "(", "common", ")", ")", ")", "sys", ".", "stderr", ".", "write", "(", "\"Set 1: {0}, Set 2: {1}\\n\"", ".", "format", "(", "len", "(", "study", ")", ",", "len", "(", "pop", ")", ")", ")", "return", "study", ",", "pop" ]
Open files containing genes. Return study genes and population genes.
[ "Open", "files", "containing", "genes", ".", "Return", "study", "genes", "and", "population", "genes", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L333-L351
228,509
tanghaibao/goatools
goatools/cli/find_enrichment.py
GroupItems.get_objgrpwr
def get_objgrpwr(self, goea_results): """Get a GrpWr object to write grouped GOEA results.""" sortobj = self.get_sortobj(goea_results) return GrpWr(sortobj, self.pval_fld, ver_list=self.ver_list)
python
def get_objgrpwr(self, goea_results): """Get a GrpWr object to write grouped GOEA results.""" sortobj = self.get_sortobj(goea_results) return GrpWr(sortobj, self.pval_fld, ver_list=self.ver_list)
[ "def", "get_objgrpwr", "(", "self", ",", "goea_results", ")", ":", "sortobj", "=", "self", ".", "get_sortobj", "(", "goea_results", ")", "return", "GrpWr", "(", "sortobj", ",", "self", ".", "pval_fld", ",", "ver_list", "=", "self", ".", "ver_list", ")" ]
Get a GrpWr object to write grouped GOEA results.
[ "Get", "a", "GrpWr", "object", "to", "write", "grouped", "GOEA", "results", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L370-L373
228,510
tanghaibao/goatools
goatools/cli/find_enrichment.py
GroupItems.get_sortobj
def get_sortobj(self, goea_results, **kws): """Return a Grouper object, given a list of GOEnrichmentRecord.""" nts_goea = MgrNtGOEAs(goea_results).get_goea_nts_prt(**kws) goids = set(nt.GO for nt in nts_goea) go2nt = {nt.GO:nt for nt in nts_goea} grprobj = Grouper("GOEA", goids, self.hdrobj, self.grprdflt.gosubdag, go2nt=go2nt) grprobj.prt_summary(sys.stdout) # hdrgo_prt", "section_prt", "top_n", "use_sections" sortobj = Sorter(grprobj, section_sortby=lambda nt: getattr(nt, self.pval_fld)) return sortobj
python
def get_sortobj(self, goea_results, **kws): """Return a Grouper object, given a list of GOEnrichmentRecord.""" nts_goea = MgrNtGOEAs(goea_results).get_goea_nts_prt(**kws) goids = set(nt.GO for nt in nts_goea) go2nt = {nt.GO:nt for nt in nts_goea} grprobj = Grouper("GOEA", goids, self.hdrobj, self.grprdflt.gosubdag, go2nt=go2nt) grprobj.prt_summary(sys.stdout) # hdrgo_prt", "section_prt", "top_n", "use_sections" sortobj = Sorter(grprobj, section_sortby=lambda nt: getattr(nt, self.pval_fld)) return sortobj
[ "def", "get_sortobj", "(", "self", ",", "goea_results", ",", "*", "*", "kws", ")", ":", "nts_goea", "=", "MgrNtGOEAs", "(", "goea_results", ")", ".", "get_goea_nts_prt", "(", "*", "*", "kws", ")", "goids", "=", "set", "(", "nt", ".", "GO", "for", "nt", "in", "nts_goea", ")", "go2nt", "=", "{", "nt", ".", "GO", ":", "nt", "for", "nt", "in", "nts_goea", "}", "grprobj", "=", "Grouper", "(", "\"GOEA\"", ",", "goids", ",", "self", ".", "hdrobj", ",", "self", ".", "grprdflt", ".", "gosubdag", ",", "go2nt", "=", "go2nt", ")", "grprobj", ".", "prt_summary", "(", "sys", ".", "stdout", ")", "# hdrgo_prt\", \"section_prt\", \"top_n\", \"use_sections\"", "sortobj", "=", "Sorter", "(", "grprobj", ",", "section_sortby", "=", "lambda", "nt", ":", "getattr", "(", "nt", ",", "self", ".", "pval_fld", ")", ")", "return", "sortobj" ]
Return a Grouper object, given a list of GOEnrichmentRecord.
[ "Return", "a", "Grouper", "object", "given", "a", "list", "of", "GOEnrichmentRecord", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L375-L384
228,511
tanghaibao/goatools
goatools/cli/find_enrichment.py
GroupItems._init_objaartall
def _init_objaartall(self): """Get background database info for making ASCII art.""" kws = { 'sortgo':lambda nt: [nt.NS, nt.dcnt], # fmtgo=('{p_fdr_bh:8.2e} {GO} ' # Formatting for GO terms in grouped GO list 'fmtgo':('{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} {childcnt:3} R{reldepth:02} ' '{D1:5} {GO_name} ({study_count} study genes)\n'), # Formatting for GO terms listed under each gene 'fmtgo2':('{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} R{reldepth:02} ' '{GO_name} ({study_count} study genes)\n'), # itemid2name=ensmusg2symbol} } return AArtGeneProductSetsAll(self.grprdflt, self.hdrobj, **kws)
python
def _init_objaartall(self): """Get background database info for making ASCII art.""" kws = { 'sortgo':lambda nt: [nt.NS, nt.dcnt], # fmtgo=('{p_fdr_bh:8.2e} {GO} ' # Formatting for GO terms in grouped GO list 'fmtgo':('{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} {childcnt:3} R{reldepth:02} ' '{D1:5} {GO_name} ({study_count} study genes)\n'), # Formatting for GO terms listed under each gene 'fmtgo2':('{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} R{reldepth:02} ' '{GO_name} ({study_count} study genes)\n'), # itemid2name=ensmusg2symbol} } return AArtGeneProductSetsAll(self.grprdflt, self.hdrobj, **kws)
[ "def", "_init_objaartall", "(", "self", ")", ":", "kws", "=", "{", "'sortgo'", ":", "lambda", "nt", ":", "[", "nt", ".", "NS", ",", "nt", ".", "dcnt", "]", ",", "# fmtgo=('{p_fdr_bh:8.2e} {GO} '", "# Formatting for GO terms in grouped GO list", "'fmtgo'", ":", "(", "'{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} '", "'{dcnt:5} {childcnt:3} R{reldepth:02} '", "'{D1:5} {GO_name} ({study_count} study genes)\\n'", ")", ",", "# Formatting for GO terms listed under each gene", "'fmtgo2'", ":", "(", "'{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} '", "'{dcnt:5} R{reldepth:02} '", "'{GO_name} ({study_count} study genes)\\n'", ")", ",", "# itemid2name=ensmusg2symbol}", "}", "return", "AArtGeneProductSetsAll", "(", "self", ".", "grprdflt", ",", "self", ".", "hdrobj", ",", "*", "*", "kws", ")" ]
Get background database info for making ASCII art.
[ "Get", "background", "database", "info", "for", "making", "ASCII", "art", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L392-L407
228,512
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr.wr_xlsx
def wr_xlsx(self, fout_xlsx): """Print grouped GOEA results into an xlsx file.""" objwr = WrXlsxSortedGos("GOEA", self.sortobj) #### fld2fmt['ratio_in_study'] = '{:>8}' #### fld2fmt['ratio_in_pop'] = '{:>12}' #### ntfld2wbfmtdict = { # ntfld_wbfmt = { # 'ratio_in_study': {'align':'right'}, # 'ratio_in_pop':{'align':'right'}} kws_xlsx = { 'title': self.ver_list, 'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'}, #'ntfld_wbfmt': ntfld_wbfmt, #### 'ntval2wbfmtdict': ntval2wbfmtdict, #'hdrs': [], 'prt_flds': self.flds_cur} objwr.wr_xlsx_nts(fout_xlsx, self.desc2nts, **kws_xlsx)
python
def wr_xlsx(self, fout_xlsx): """Print grouped GOEA results into an xlsx file.""" objwr = WrXlsxSortedGos("GOEA", self.sortobj) #### fld2fmt['ratio_in_study'] = '{:>8}' #### fld2fmt['ratio_in_pop'] = '{:>12}' #### ntfld2wbfmtdict = { # ntfld_wbfmt = { # 'ratio_in_study': {'align':'right'}, # 'ratio_in_pop':{'align':'right'}} kws_xlsx = { 'title': self.ver_list, 'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'}, #'ntfld_wbfmt': ntfld_wbfmt, #### 'ntval2wbfmtdict': ntval2wbfmtdict, #'hdrs': [], 'prt_flds': self.flds_cur} objwr.wr_xlsx_nts(fout_xlsx, self.desc2nts, **kws_xlsx)
[ "def", "wr_xlsx", "(", "self", ",", "fout_xlsx", ")", ":", "objwr", "=", "WrXlsxSortedGos", "(", "\"GOEA\"", ",", "self", ".", "sortobj", ")", "#### fld2fmt['ratio_in_study'] = '{:>8}'", "#### fld2fmt['ratio_in_pop'] = '{:>12}'", "#### ntfld2wbfmtdict = {", "# ntfld_wbfmt = {", "# 'ratio_in_study': {'align':'right'},", "# 'ratio_in_pop':{'align':'right'}}", "kws_xlsx", "=", "{", "'title'", ":", "self", ".", "ver_list", ",", "'fld2fmt'", ":", "{", "f", ":", "'{:8.2e}'", "for", "f", "in", "self", ".", "flds_cur", "if", "f", "[", ":", "2", "]", "==", "'p_'", "}", ",", "#'ntfld_wbfmt': ntfld_wbfmt,", "#### 'ntval2wbfmtdict': ntval2wbfmtdict,", "#'hdrs': [],", "'prt_flds'", ":", "self", ".", "flds_cur", "}", "objwr", ".", "wr_xlsx_nts", "(", "fout_xlsx", ",", "self", ".", "desc2nts", ",", "*", "*", "kws_xlsx", ")" ]
Print grouped GOEA results into an xlsx file.
[ "Print", "grouped", "GOEA", "results", "into", "an", "xlsx", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L432-L448
228,513
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr.wr_tsv
def wr_tsv(self, fout_tsv): """Print grouped GOEA results into a tab-separated file.""" with open(fout_tsv, 'w') as prt: kws_tsv = { 'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'}, 'prt_flds':self.flds_cur} prt_tsv_sections(prt, self.desc2nts['sections'], **kws_tsv) print(" WROTE: {TSV}".format(TSV=fout_tsv))
python
def wr_tsv(self, fout_tsv): """Print grouped GOEA results into a tab-separated file.""" with open(fout_tsv, 'w') as prt: kws_tsv = { 'fld2fmt': {f:'{:8.2e}' for f in self.flds_cur if f[:2] == 'p_'}, 'prt_flds':self.flds_cur} prt_tsv_sections(prt, self.desc2nts['sections'], **kws_tsv) print(" WROTE: {TSV}".format(TSV=fout_tsv))
[ "def", "wr_tsv", "(", "self", ",", "fout_tsv", ")", ":", "with", "open", "(", "fout_tsv", ",", "'w'", ")", "as", "prt", ":", "kws_tsv", "=", "{", "'fld2fmt'", ":", "{", "f", ":", "'{:8.2e}'", "for", "f", "in", "self", ".", "flds_cur", "if", "f", "[", ":", "2", "]", "==", "'p_'", "}", ",", "'prt_flds'", ":", "self", ".", "flds_cur", "}", "prt_tsv_sections", "(", "prt", ",", "self", ".", "desc2nts", "[", "'sections'", "]", ",", "*", "*", "kws_tsv", ")", "print", "(", "\" WROTE: {TSV}\"", ".", "format", "(", "TSV", "=", "fout_tsv", ")", ")" ]
Print grouped GOEA results into a tab-separated file.
[ "Print", "grouped", "GOEA", "results", "into", "a", "tab", "-", "separated", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L450-L457
228,514
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr.wr_txt
def wr_txt(self, fout_txt): """Write to a file GOEA results in an ASCII text format.""" with open(fout_txt, 'w') as prt: for line in self.ver_list: prt.write("{LINE}\n".format(LINE=line)) self.prt_txt(prt) print(" WROTE: {TXT}".format(TXT=fout_txt))
python
def wr_txt(self, fout_txt): """Write to a file GOEA results in an ASCII text format.""" with open(fout_txt, 'w') as prt: for line in self.ver_list: prt.write("{LINE}\n".format(LINE=line)) self.prt_txt(prt) print(" WROTE: {TXT}".format(TXT=fout_txt))
[ "def", "wr_txt", "(", "self", ",", "fout_txt", ")", ":", "with", "open", "(", "fout_txt", ",", "'w'", ")", "as", "prt", ":", "for", "line", "in", "self", ".", "ver_list", ":", "prt", ".", "write", "(", "\"{LINE}\\n\"", ".", "format", "(", "LINE", "=", "line", ")", ")", "self", ".", "prt_txt", "(", "prt", ")", "print", "(", "\" WROTE: {TXT}\"", ".", "format", "(", "TXT", "=", "fout_txt", ")", ")" ]
Write to a file GOEA results in an ASCII text format.
[ "Write", "to", "a", "file", "GOEA", "results", "in", "an", "ASCII", "text", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L459-L465
228,515
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr.prt_tsv
def prt_tsv(self, prt=sys.stdout): """Print an ASCII text format.""" prtfmt = self.objprt.get_prtfmt_str(self.flds_cur) prt.write("{FLDS}\n".format(FLDS=" ".join(self.flds_cur))) WrSectionsTxt.prt_sections(prt, self.desc2nts['sections'], prtfmt, secspc=True)
python
def prt_tsv(self, prt=sys.stdout): """Print an ASCII text format.""" prtfmt = self.objprt.get_prtfmt_str(self.flds_cur) prt.write("{FLDS}\n".format(FLDS=" ".join(self.flds_cur))) WrSectionsTxt.prt_sections(prt, self.desc2nts['sections'], prtfmt, secspc=True)
[ "def", "prt_tsv", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "prtfmt", "=", "self", ".", "objprt", ".", "get_prtfmt_str", "(", "self", ".", "flds_cur", ")", "prt", ".", "write", "(", "\"{FLDS}\\n\"", ".", "format", "(", "FLDS", "=", "\" \"", ".", "join", "(", "self", ".", "flds_cur", ")", ")", ")", "WrSectionsTxt", ".", "prt_sections", "(", "prt", ",", "self", ".", "desc2nts", "[", "'sections'", "]", ",", "prtfmt", ",", "secspc", "=", "True", ")" ]
Print an ASCII text format.
[ "Print", "an", "ASCII", "text", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L467-L471
228,516
tanghaibao/goatools
goatools/cli/find_enrichment.py
GrpWr._init_flds_cur
def _init_flds_cur(self): """Choose fields to print from a multitude of available fields.""" flds = [] # ('GO', 'NS', 'enrichment', 'name', 'ratio_in_study', 'ratio_in_pop', 'depth', # 'p_uncorrected', 'p_bonferroni', 'p_sidak', 'p_holm', 'p_fdr_bh', # 'pop_n', 'pop_count', 'pop_items' # 'study_n', 'study_count', 'study_items', # 'is_ratio_different', 'level', 'is_obsolete', # 'namespace', 'reldepth', 'alt_ids', 'format_txt', 'hdr_idx', # 'is_hdrgo', 'is_usrgo', 'num_usrgos', 'hdr1usr01', 'alt', 'GO_name', # 'dcnt', 'D1', 'tcnt', 'tfreq', 'tinfo', 'childcnt', 'REL', # 'REL_short', 'rel', 'id') flds0 = ['GO', 'NS', 'enrichment', self.pval_fld, 'dcnt', 'tinfo', 'depth', 'ratio_in_study', 'ratio_in_pop', 'name'] flds_p = [f for f in self.flds_all if f[:2] == 'p_' and f != self.pval_fld] flds.extend(flds0) if flds_p: flds.extend(flds_p) flds.append('study_count') flds.append('study_items') return flds
python
def _init_flds_cur(self): """Choose fields to print from a multitude of available fields.""" flds = [] # ('GO', 'NS', 'enrichment', 'name', 'ratio_in_study', 'ratio_in_pop', 'depth', # 'p_uncorrected', 'p_bonferroni', 'p_sidak', 'p_holm', 'p_fdr_bh', # 'pop_n', 'pop_count', 'pop_items' # 'study_n', 'study_count', 'study_items', # 'is_ratio_different', 'level', 'is_obsolete', # 'namespace', 'reldepth', 'alt_ids', 'format_txt', 'hdr_idx', # 'is_hdrgo', 'is_usrgo', 'num_usrgos', 'hdr1usr01', 'alt', 'GO_name', # 'dcnt', 'D1', 'tcnt', 'tfreq', 'tinfo', 'childcnt', 'REL', # 'REL_short', 'rel', 'id') flds0 = ['GO', 'NS', 'enrichment', self.pval_fld, 'dcnt', 'tinfo', 'depth', 'ratio_in_study', 'ratio_in_pop', 'name'] flds_p = [f for f in self.flds_all if f[:2] == 'p_' and f != self.pval_fld] flds.extend(flds0) if flds_p: flds.extend(flds_p) flds.append('study_count') flds.append('study_items') return flds
[ "def", "_init_flds_cur", "(", "self", ")", ":", "flds", "=", "[", "]", "# ('GO', 'NS', 'enrichment', 'name', 'ratio_in_study', 'ratio_in_pop', 'depth',", "# 'p_uncorrected', 'p_bonferroni', 'p_sidak', 'p_holm', 'p_fdr_bh',", "# 'pop_n', 'pop_count', 'pop_items'", "# 'study_n', 'study_count', 'study_items',", "# 'is_ratio_different', 'level', 'is_obsolete',", "# 'namespace', 'reldepth', 'alt_ids', 'format_txt', 'hdr_idx',", "# 'is_hdrgo', 'is_usrgo', 'num_usrgos', 'hdr1usr01', 'alt', 'GO_name',", "# 'dcnt', 'D1', 'tcnt', 'tfreq', 'tinfo', 'childcnt', 'REL',", "# 'REL_short', 'rel', 'id')", "flds0", "=", "[", "'GO'", ",", "'NS'", ",", "'enrichment'", ",", "self", ".", "pval_fld", ",", "'dcnt'", ",", "'tinfo'", ",", "'depth'", ",", "'ratio_in_study'", ",", "'ratio_in_pop'", ",", "'name'", "]", "flds_p", "=", "[", "f", "for", "f", "in", "self", ".", "flds_all", "if", "f", "[", ":", "2", "]", "==", "'p_'", "and", "f", "!=", "self", ".", "pval_fld", "]", "flds", ".", "extend", "(", "flds0", ")", "if", "flds_p", ":", "flds", ".", "extend", "(", "flds_p", ")", "flds", ".", "append", "(", "'study_count'", ")", "flds", ".", "append", "(", "'study_items'", ")", "return", "flds" ]
Choose fields to print from a multitude of available fields.
[ "Choose", "fields", "to", "print", "from", "a", "multitude", "of", "available", "fields", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/find_enrichment.py#L479-L499
228,517
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader.do_hdr
def do_hdr(self, line, hdrs_usr): """Initialize self.h2i.""" # If there is no header hint, consider the first line the header. if self.hdr_ex is None: self._init_hdr(line, hdrs_usr) return True # If there is a header hint, examine each beginning line until header hint is found. elif self.hdr_ex in line: self._init_hdr(line, hdrs_usr) return True return False
python
def do_hdr(self, line, hdrs_usr): """Initialize self.h2i.""" # If there is no header hint, consider the first line the header. if self.hdr_ex is None: self._init_hdr(line, hdrs_usr) return True # If there is a header hint, examine each beginning line until header hint is found. elif self.hdr_ex in line: self._init_hdr(line, hdrs_usr) return True return False
[ "def", "do_hdr", "(", "self", ",", "line", ",", "hdrs_usr", ")", ":", "# If there is no header hint, consider the first line the header.", "if", "self", ".", "hdr_ex", "is", "None", ":", "self", ".", "_init_hdr", "(", "line", ",", "hdrs_usr", ")", "return", "True", "# If there is a header hint, examine each beginning line until header hint is found.", "elif", "self", ".", "hdr_ex", "in", "line", ":", "self", ".", "_init_hdr", "(", "line", ",", "hdrs_usr", ")", "return", "True", "return", "False" ]
Initialize self.h2i.
[ "Initialize", "self", ".", "h2i", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L84-L94
228,518
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader.hdr_xform
def hdr_xform(self, hdrs): """Transform NCBI Gene header fields into valid namedtuple fields.""" xform = [] hdrs = self.replace_nulls(hdrs) for hdr in hdrs: hdr = hdr.replace('.', '_') hdr = hdr.replace(' ', '_') hdr = hdr.replace('#', 'N') hdr = hdr.replace('-', '_') hdr = hdr.replace('"', '') xform.append(hdr) return xform
python
def hdr_xform(self, hdrs): """Transform NCBI Gene header fields into valid namedtuple fields.""" xform = [] hdrs = self.replace_nulls(hdrs) for hdr in hdrs: hdr = hdr.replace('.', '_') hdr = hdr.replace(' ', '_') hdr = hdr.replace('#', 'N') hdr = hdr.replace('-', '_') hdr = hdr.replace('"', '') xform.append(hdr) return xform
[ "def", "hdr_xform", "(", "self", ",", "hdrs", ")", ":", "xform", "=", "[", "]", "hdrs", "=", "self", ".", "replace_nulls", "(", "hdrs", ")", "for", "hdr", "in", "hdrs", ":", "hdr", "=", "hdr", ".", "replace", "(", "'.'", ",", "'_'", ")", "hdr", "=", "hdr", ".", "replace", "(", "' '", ",", "'_'", ")", "hdr", "=", "hdr", ".", "replace", "(", "'#'", ",", "'N'", ")", "hdr", "=", "hdr", ".", "replace", "(", "'-'", ",", "'_'", ")", "hdr", "=", "hdr", ".", "replace", "(", "'\"'", ",", "''", ")", "xform", ".", "append", "(", "hdr", ")", "return", "xform" ]
Transform NCBI Gene header fields into valid namedtuple fields.
[ "Transform", "NCBI", "Gene", "header", "fields", "into", "valid", "namedtuple", "fields", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L146-L157
228,519
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_nt_hdr
def _init_nt_hdr(self, line): """Convert headers into valid namedtuple fields.""" line = line.replace('.', '_') line = line.replace(' ', '_') line = line.replace('#', 'N') line = line.replace('-', '_') line = line.replace('"', '') #line = re.sub(r"_$", r"", line) hdrs = re.split(self.sep, line) if '' in hdrs: hdrs = NCBIgeneFileReader.replace_nulls(hdrs) # Init indexes which will be converted to int or float self.idxs_int = [idx for idx, hdr in enumerate(hdrs) if hdr in self.int_hdrs] self.idxs_float = [idx for idx, hdr in enumerate(hdrs) if hdr in self.float_hdrs] assert hdrs[6] == 'Aliases' return namedtuple('ntncbi', ' '.join(hdrs))
python
def _init_nt_hdr(self, line): """Convert headers into valid namedtuple fields.""" line = line.replace('.', '_') line = line.replace(' ', '_') line = line.replace('#', 'N') line = line.replace('-', '_') line = line.replace('"', '') #line = re.sub(r"_$", r"", line) hdrs = re.split(self.sep, line) if '' in hdrs: hdrs = NCBIgeneFileReader.replace_nulls(hdrs) # Init indexes which will be converted to int or float self.idxs_int = [idx for idx, hdr in enumerate(hdrs) if hdr in self.int_hdrs] self.idxs_float = [idx for idx, hdr in enumerate(hdrs) if hdr in self.float_hdrs] assert hdrs[6] == 'Aliases' return namedtuple('ntncbi', ' '.join(hdrs))
[ "def", "_init_nt_hdr", "(", "self", ",", "line", ")", ":", "line", "=", "line", ".", "replace", "(", "'.'", ",", "'_'", ")", "line", "=", "line", ".", "replace", "(", "' '", ",", "'_'", ")", "line", "=", "line", ".", "replace", "(", "'#'", ",", "'N'", ")", "line", "=", "line", ".", "replace", "(", "'-'", ",", "'_'", ")", "line", "=", "line", ".", "replace", "(", "'\"'", ",", "''", ")", "#line = re.sub(r\"_$\", r\"\", line)", "hdrs", "=", "re", ".", "split", "(", "self", ".", "sep", ",", "line", ")", "if", "''", "in", "hdrs", ":", "hdrs", "=", "NCBIgeneFileReader", ".", "replace_nulls", "(", "hdrs", ")", "# Init indexes which will be converted to int or float", "self", ".", "idxs_int", "=", "[", "idx", "for", "idx", ",", "hdr", "in", "enumerate", "(", "hdrs", ")", "if", "hdr", "in", "self", ".", "int_hdrs", "]", "self", ".", "idxs_float", "=", "[", "idx", "for", "idx", ",", "hdr", "in", "enumerate", "(", "hdrs", ")", "if", "hdr", "in", "self", ".", "float_hdrs", "]", "assert", "hdrs", "[", "6", "]", "==", "'Aliases'", "return", "namedtuple", "(", "'ntncbi'", ",", "' '", ".", "join", "(", "hdrs", ")", ")" ]
Convert headers into valid namedtuple fields.
[ "Convert", "headers", "into", "valid", "namedtuple", "fields", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L159-L174
228,520
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader.replace_nulls
def replace_nulls(hdrs): """Replace '' in hdrs.""" ret = [] idx = 0 for hdr in hdrs: if hdr == '': ret.append("no_hdr{}".format(idx)) else: ret.append(hdr) return ret
python
def replace_nulls(hdrs): """Replace '' in hdrs.""" ret = [] idx = 0 for hdr in hdrs: if hdr == '': ret.append("no_hdr{}".format(idx)) else: ret.append(hdr) return ret
[ "def", "replace_nulls", "(", "hdrs", ")", ":", "ret", "=", "[", "]", "idx", "=", "0", "for", "hdr", "in", "hdrs", ":", "if", "hdr", "==", "''", ":", "ret", ".", "append", "(", "\"no_hdr{}\"", ".", "format", "(", "idx", ")", ")", "else", ":", "ret", ".", "append", "(", "hdr", ")", "return", "ret" ]
Replace '' in hdrs.
[ "Replace", "in", "hdrs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L187-L196
228,521
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_data_line
def _init_data_line(self, fnc, lnum, line): """Process Data line.""" fld = re.split(self.sep, line) # Lines may contain different numbers of items. # The line should have all columns requested by the user. if self.usr_max_idx < len(fld): self.convert_ints_floats(fld) fnc(fld) else: for fld in enumerate(zip(self.hdr2idx.keys(), fld)): print(fld) for hdr in self.hdrs_usr: print(hdr) print('# ITEMS ON A LINE:', len(fld)) print('MAX USR IDX:', self.usr_max_idx) raise Exception("ERROR ON LINE {} IN {}".format(lnum+1, self.fin))
python
def _init_data_line(self, fnc, lnum, line): """Process Data line.""" fld = re.split(self.sep, line) # Lines may contain different numbers of items. # The line should have all columns requested by the user. if self.usr_max_idx < len(fld): self.convert_ints_floats(fld) fnc(fld) else: for fld in enumerate(zip(self.hdr2idx.keys(), fld)): print(fld) for hdr in self.hdrs_usr: print(hdr) print('# ITEMS ON A LINE:', len(fld)) print('MAX USR IDX:', self.usr_max_idx) raise Exception("ERROR ON LINE {} IN {}".format(lnum+1, self.fin))
[ "def", "_init_data_line", "(", "self", ",", "fnc", ",", "lnum", ",", "line", ")", ":", "fld", "=", "re", ".", "split", "(", "self", ".", "sep", ",", "line", ")", "# Lines may contain different numbers of items.", "# The line should have all columns requested by the user.", "if", "self", ".", "usr_max_idx", "<", "len", "(", "fld", ")", ":", "self", ".", "convert_ints_floats", "(", "fld", ")", "fnc", "(", "fld", ")", "else", ":", "for", "fld", "in", "enumerate", "(", "zip", "(", "self", ".", "hdr2idx", ".", "keys", "(", ")", ",", "fld", ")", ")", ":", "print", "(", "fld", ")", "for", "hdr", "in", "self", ".", "hdrs_usr", ":", "print", "(", "hdr", ")", "print", "(", "'# ITEMS ON A LINE:'", ",", "len", "(", "fld", ")", ")", "print", "(", "'MAX USR IDX:'", ",", "self", ".", "usr_max_idx", ")", "raise", "Exception", "(", "\"ERROR ON LINE {} IN {}\"", ".", "format", "(", "lnum", "+", "1", ",", "self", ".", "fin", ")", ")" ]
Process Data line.
[ "Process", "Data", "line", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L198-L213
228,522
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader.convert_ints_floats
def convert_ints_floats(self, flds): """Convert strings to ints and floats, if so specified.""" for idx in self.idxs_float: flds[idx] = float(flds[idx]) for idx in self.idxs_int: dig = flds[idx] #print 'idx={} ({}) {}'.format(idx, flds[idx], flds) # DVK flds[idx] = int(flds[idx]) if dig.isdigit() else dig for idx in self.idxs_strpat: hdr = self.hdr2idx.items()[idx][0] pat = self.strpat_hdrs[hdr] flds[idx] = pat.format(flds[idx])
python
def convert_ints_floats(self, flds): """Convert strings to ints and floats, if so specified.""" for idx in self.idxs_float: flds[idx] = float(flds[idx]) for idx in self.idxs_int: dig = flds[idx] #print 'idx={} ({}) {}'.format(idx, flds[idx], flds) # DVK flds[idx] = int(flds[idx]) if dig.isdigit() else dig for idx in self.idxs_strpat: hdr = self.hdr2idx.items()[idx][0] pat = self.strpat_hdrs[hdr] flds[idx] = pat.format(flds[idx])
[ "def", "convert_ints_floats", "(", "self", ",", "flds", ")", ":", "for", "idx", "in", "self", ".", "idxs_float", ":", "flds", "[", "idx", "]", "=", "float", "(", "flds", "[", "idx", "]", ")", "for", "idx", "in", "self", ".", "idxs_int", ":", "dig", "=", "flds", "[", "idx", "]", "#print 'idx={} ({}) {}'.format(idx, flds[idx], flds) # DVK", "flds", "[", "idx", "]", "=", "int", "(", "flds", "[", "idx", "]", ")", "if", "dig", ".", "isdigit", "(", ")", "else", "dig", "for", "idx", "in", "self", ".", "idxs_strpat", ":", "hdr", "=", "self", ".", "hdr2idx", ".", "items", "(", ")", "[", "idx", "]", "[", "0", "]", "pat", "=", "self", ".", "strpat_hdrs", "[", "hdr", "]", "flds", "[", "idx", "]", "=", "pat", ".", "format", "(", "flds", "[", "idx", "]", ")" ]
Convert strings to ints and floats, if so specified.
[ "Convert", "strings", "to", "ints", "and", "floats", "if", "so", "specified", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L215-L226
228,523
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_hdr
def _init_hdr(self, line, hdrs_usr): """Initialize self.hdr2idx, self.len, self.idxs_float, and self.idxs_int""" self.hdr2idx = OrderedDict([(v.strip(), i) for i, v in enumerate(re.split(self.sep, line))]) self.len = len(self.hdr2idx) # If user is requesting specific data fields... if hdrs_usr is not None: # Loop through the user headers for usr_hdr in hdrs_usr: # If the user header is contained in the file.... if usr_hdr in self.hdr2idx: # Add the user header and the field index to a list self.hdrs_usr.append([usr_hdr, self.hdr2idx[usr_hdr]]) else: raise Exception("NO COLUMN({}) FOUND:\n HDR={}\n".format( hdrs_usr, '\n HDR='.join(self.hdr2idx.keys()))) usr_hdrs = [E[0] for E in self.hdrs_usr] if self.hdrs_usr else self.hdr2idx self._init_idxs_float(usr_hdrs) self._init_idxs_int(usr_hdrs) self._init_idxs_strpat(usr_hdrs) self.usr_max_idx = max(E[1] for E in self.hdrs_usr) if self.hdrs_usr else len(self.hdr2idx)-1
python
def _init_hdr(self, line, hdrs_usr): """Initialize self.hdr2idx, self.len, self.idxs_float, and self.idxs_int""" self.hdr2idx = OrderedDict([(v.strip(), i) for i, v in enumerate(re.split(self.sep, line))]) self.len = len(self.hdr2idx) # If user is requesting specific data fields... if hdrs_usr is not None: # Loop through the user headers for usr_hdr in hdrs_usr: # If the user header is contained in the file.... if usr_hdr in self.hdr2idx: # Add the user header and the field index to a list self.hdrs_usr.append([usr_hdr, self.hdr2idx[usr_hdr]]) else: raise Exception("NO COLUMN({}) FOUND:\n HDR={}\n".format( hdrs_usr, '\n HDR='.join(self.hdr2idx.keys()))) usr_hdrs = [E[0] for E in self.hdrs_usr] if self.hdrs_usr else self.hdr2idx self._init_idxs_float(usr_hdrs) self._init_idxs_int(usr_hdrs) self._init_idxs_strpat(usr_hdrs) self.usr_max_idx = max(E[1] for E in self.hdrs_usr) if self.hdrs_usr else len(self.hdr2idx)-1
[ "def", "_init_hdr", "(", "self", ",", "line", ",", "hdrs_usr", ")", ":", "self", ".", "hdr2idx", "=", "OrderedDict", "(", "[", "(", "v", ".", "strip", "(", ")", ",", "i", ")", "for", "i", ",", "v", "in", "enumerate", "(", "re", ".", "split", "(", "self", ".", "sep", ",", "line", ")", ")", "]", ")", "self", ".", "len", "=", "len", "(", "self", ".", "hdr2idx", ")", "# If user is requesting specific data fields...", "if", "hdrs_usr", "is", "not", "None", ":", "# Loop through the user headers", "for", "usr_hdr", "in", "hdrs_usr", ":", "# If the user header is contained in the file....", "if", "usr_hdr", "in", "self", ".", "hdr2idx", ":", "# Add the user header and the field index to a list", "self", ".", "hdrs_usr", ".", "append", "(", "[", "usr_hdr", ",", "self", ".", "hdr2idx", "[", "usr_hdr", "]", "]", ")", "else", ":", "raise", "Exception", "(", "\"NO COLUMN({}) FOUND:\\n HDR={}\\n\"", ".", "format", "(", "hdrs_usr", ",", "'\\n HDR='", ".", "join", "(", "self", ".", "hdr2idx", ".", "keys", "(", ")", ")", ")", ")", "usr_hdrs", "=", "[", "E", "[", "0", "]", "for", "E", "in", "self", ".", "hdrs_usr", "]", "if", "self", ".", "hdrs_usr", "else", "self", ".", "hdr2idx", "self", ".", "_init_idxs_float", "(", "usr_hdrs", ")", "self", ".", "_init_idxs_int", "(", "usr_hdrs", ")", "self", ".", "_init_idxs_strpat", "(", "usr_hdrs", ")", "self", ".", "usr_max_idx", "=", "max", "(", "E", "[", "1", "]", "for", "E", "in", "self", ".", "hdrs_usr", ")", "if", "self", ".", "hdrs_usr", "else", "len", "(", "self", ".", "hdr2idx", ")", "-", "1" ]
Initialize self.hdr2idx, self.len, self.idxs_float, and self.idxs_int
[ "Initialize", "self", ".", "hdr2idx", "self", ".", "len", "self", ".", "idxs_float", "and", "self", ".", "idxs_int" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L228-L247
228,524
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_idxs_float
def _init_idxs_float(self, usr_hdrs): """List of indexes whose values will be floats.""" self.idxs_float = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.float_hdrs]
python
def _init_idxs_float(self, usr_hdrs): """List of indexes whose values will be floats.""" self.idxs_float = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.float_hdrs]
[ "def", "_init_idxs_float", "(", "self", ",", "usr_hdrs", ")", ":", "self", ".", "idxs_float", "=", "[", "Idx", "for", "Hdr", ",", "Idx", "in", "self", ".", "hdr2idx", ".", "items", "(", ")", "if", "Hdr", "in", "usr_hdrs", "and", "Hdr", "in", "self", ".", "float_hdrs", "]" ]
List of indexes whose values will be floats.
[ "List", "of", "indexes", "whose", "values", "will", "be", "floats", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L249-L252
228,525
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_idxs_int
def _init_idxs_int(self, usr_hdrs): """List of indexes whose values will be ints.""" self.idxs_int = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.int_hdrs]
python
def _init_idxs_int(self, usr_hdrs): """List of indexes whose values will be ints.""" self.idxs_int = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in self.int_hdrs]
[ "def", "_init_idxs_int", "(", "self", ",", "usr_hdrs", ")", ":", "self", ".", "idxs_int", "=", "[", "Idx", "for", "Hdr", ",", "Idx", "in", "self", ".", "hdr2idx", ".", "items", "(", ")", "if", "Hdr", "in", "usr_hdrs", "and", "Hdr", "in", "self", ".", "int_hdrs", "]" ]
List of indexes whose values will be ints.
[ "List", "of", "indexes", "whose", "values", "will", "be", "ints", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L254-L257
228,526
tanghaibao/goatools
goatools/parsers/ncbi_gene_file_reader.py
NCBIgeneFileReader._init_idxs_strpat
def _init_idxs_strpat(self, usr_hdrs): """List of indexes whose values will be strings.""" strpat = self.strpat_hdrs.keys() self.idxs_strpat = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in strpat]
python
def _init_idxs_strpat(self, usr_hdrs): """List of indexes whose values will be strings.""" strpat = self.strpat_hdrs.keys() self.idxs_strpat = [ Idx for Hdr, Idx in self.hdr2idx.items() if Hdr in usr_hdrs and Hdr in strpat]
[ "def", "_init_idxs_strpat", "(", "self", ",", "usr_hdrs", ")", ":", "strpat", "=", "self", ".", "strpat_hdrs", ".", "keys", "(", ")", "self", ".", "idxs_strpat", "=", "[", "Idx", "for", "Hdr", ",", "Idx", "in", "self", ".", "hdr2idx", ".", "items", "(", ")", "if", "Hdr", "in", "usr_hdrs", "and", "Hdr", "in", "strpat", "]" ]
List of indexes whose values will be strings.
[ "List", "of", "indexes", "whose", "values", "will", "be", "strings", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/parsers/ncbi_gene_file_reader.py#L259-L263
228,527
tanghaibao/goatools
goatools/cli/ncbi_gene_results_to_python.py
NCBIgeneToPythonCli._get_geneid2nt
def _get_geneid2nt(nts): """Get geneid2nt given a list of namedtuples.""" geneid2nt = {} for ntd in nts: geneid = ntd.GeneID if geneid not in geneid2nt: geneid2nt[geneid] = ntd else: print("DUPLICATE GeneID FOUND {N:9} {SYM}".format(N=geneid, SYM=ntd.Symbol)) return geneid2nt
python
def _get_geneid2nt(nts): """Get geneid2nt given a list of namedtuples.""" geneid2nt = {} for ntd in nts: geneid = ntd.GeneID if geneid not in geneid2nt: geneid2nt[geneid] = ntd else: print("DUPLICATE GeneID FOUND {N:9} {SYM}".format(N=geneid, SYM=ntd.Symbol)) return geneid2nt
[ "def", "_get_geneid2nt", "(", "nts", ")", ":", "geneid2nt", "=", "{", "}", "for", "ntd", "in", "nts", ":", "geneid", "=", "ntd", ".", "GeneID", "if", "geneid", "not", "in", "geneid2nt", ":", "geneid2nt", "[", "geneid", "]", "=", "ntd", "else", ":", "print", "(", "\"DUPLICATE GeneID FOUND {N:9} {SYM}\"", ".", "format", "(", "N", "=", "geneid", ",", "SYM", "=", "ntd", ".", "Symbol", ")", ")", "return", "geneid2nt" ]
Get geneid2nt given a list of namedtuples.
[ "Get", "geneid2nt", "given", "a", "list", "of", "namedtuples", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/ncbi_gene_results_to_python.py#L50-L59
228,528
tanghaibao/goatools
goatools/cli/ncbi_gene_results_to_python.py
NCBIgeneToPythonCli._wrpy_ncbi_gene_nts
def _wrpy_ncbi_gene_nts(fout_py, geneid2nt, log): """Write namedtuples to a dict in a Python module.""" num_genes = len(geneid2nt) with open(fout_py, 'w') as ofstrm: docstr = "Data downloaded from NCBI Gene converted into Python namedtuples." ofstrm.write('"""{PYDOC}"""\n\n'.format(PYDOC=docstr)) ofstrm.write("from collections import namedtuple\n\n") ofstrm.write('WRITTEN = "{DATE}"'.format( DATE=re.sub('-', '_', str(datetime.date.today())))) ofstrm.write(' # {N} items\n\n'.format(N=num_genes)) ntd = next(iter(geneid2nt.values())) # Access one dictionary value in Python 2 ofstrm.write("#pylint: disable=line-too-long,too-many-lines,invalid-name\n") ofstrm.write("{NtName} = namedtuple('{NtName}', '{FLDS}')\n\n".format( NtName=type(ntd).__name__, FLDS=' '.join(ntd._fields))) ofstrm.write("GENEID2NT = {{ # {N:,} items\n".format(N=num_genes)) for geneid, ntd in sorted(geneid2nt.items(), key=lambda t: t[0]): ofstrm.write(" {GeneID} : {NT},\n".format(GeneID=geneid, NT=ntd)) ofstrm.write("}\n") log.write(" {N:9} geneids WROTE: {PY}\n".format(N=num_genes, PY=fout_py))
python
def _wrpy_ncbi_gene_nts(fout_py, geneid2nt, log): """Write namedtuples to a dict in a Python module.""" num_genes = len(geneid2nt) with open(fout_py, 'w') as ofstrm: docstr = "Data downloaded from NCBI Gene converted into Python namedtuples." ofstrm.write('"""{PYDOC}"""\n\n'.format(PYDOC=docstr)) ofstrm.write("from collections import namedtuple\n\n") ofstrm.write('WRITTEN = "{DATE}"'.format( DATE=re.sub('-', '_', str(datetime.date.today())))) ofstrm.write(' # {N} items\n\n'.format(N=num_genes)) ntd = next(iter(geneid2nt.values())) # Access one dictionary value in Python 2 ofstrm.write("#pylint: disable=line-too-long,too-many-lines,invalid-name\n") ofstrm.write("{NtName} = namedtuple('{NtName}', '{FLDS}')\n\n".format( NtName=type(ntd).__name__, FLDS=' '.join(ntd._fields))) ofstrm.write("GENEID2NT = {{ # {N:,} items\n".format(N=num_genes)) for geneid, ntd in sorted(geneid2nt.items(), key=lambda t: t[0]): ofstrm.write(" {GeneID} : {NT},\n".format(GeneID=geneid, NT=ntd)) ofstrm.write("}\n") log.write(" {N:9} geneids WROTE: {PY}\n".format(N=num_genes, PY=fout_py))
[ "def", "_wrpy_ncbi_gene_nts", "(", "fout_py", ",", "geneid2nt", ",", "log", ")", ":", "num_genes", "=", "len", "(", "geneid2nt", ")", "with", "open", "(", "fout_py", ",", "'w'", ")", "as", "ofstrm", ":", "docstr", "=", "\"Data downloaded from NCBI Gene converted into Python namedtuples.\"", "ofstrm", ".", "write", "(", "'\"\"\"{PYDOC}\"\"\"\\n\\n'", ".", "format", "(", "PYDOC", "=", "docstr", ")", ")", "ofstrm", ".", "write", "(", "\"from collections import namedtuple\\n\\n\"", ")", "ofstrm", ".", "write", "(", "'WRITTEN = \"{DATE}\"'", ".", "format", "(", "DATE", "=", "re", ".", "sub", "(", "'-'", ",", "'_'", ",", "str", "(", "datetime", ".", "date", ".", "today", "(", ")", ")", ")", ")", ")", "ofstrm", ".", "write", "(", "' # {N} items\\n\\n'", ".", "format", "(", "N", "=", "num_genes", ")", ")", "ntd", "=", "next", "(", "iter", "(", "geneid2nt", ".", "values", "(", ")", ")", ")", "# Access one dictionary value in Python 2", "ofstrm", ".", "write", "(", "\"#pylint: disable=line-too-long,too-many-lines,invalid-name\\n\"", ")", "ofstrm", ".", "write", "(", "\"{NtName} = namedtuple('{NtName}', '{FLDS}')\\n\\n\"", ".", "format", "(", "NtName", "=", "type", "(", "ntd", ")", ".", "__name__", ",", "FLDS", "=", "' '", ".", "join", "(", "ntd", ".", "_fields", ")", ")", ")", "ofstrm", ".", "write", "(", "\"GENEID2NT = {{ # {N:,} items\\n\"", ".", "format", "(", "N", "=", "num_genes", ")", ")", "for", "geneid", ",", "ntd", "in", "sorted", "(", "geneid2nt", ".", "items", "(", ")", ",", "key", "=", "lambda", "t", ":", "t", "[", "0", "]", ")", ":", "ofstrm", ".", "write", "(", "\" {GeneID} : {NT},\\n\"", ".", "format", "(", "GeneID", "=", "geneid", ",", "NT", "=", "ntd", ")", ")", "ofstrm", ".", "write", "(", "\"}\\n\"", ")", "log", ".", "write", "(", "\" {N:9} geneids WROTE: {PY}\\n\"", ".", "format", "(", "N", "=", "num_genes", ",", "PY", "=", "fout_py", ")", ")" ]
Write namedtuples to a dict in a Python module.
[ "Write", "namedtuples", "to", "a", "dict", "in", "a", "Python", "module", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/cli/ncbi_gene_results_to_python.py#L62-L80
228,529
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
get_goobjs_altgo2goobj
def get_goobjs_altgo2goobj(go2obj): """Separate alt GO IDs and key GO IDs.""" goobjs = set() altgo2goobj = {} for goid, goobj in go2obj.items(): goobjs.add(goobj) if goid != goobj.id: altgo2goobj[goid] = goobj return goobjs, altgo2goobj
python
def get_goobjs_altgo2goobj(go2obj): """Separate alt GO IDs and key GO IDs.""" goobjs = set() altgo2goobj = {} for goid, goobj in go2obj.items(): goobjs.add(goobj) if goid != goobj.id: altgo2goobj[goid] = goobj return goobjs, altgo2goobj
[ "def", "get_goobjs_altgo2goobj", "(", "go2obj", ")", ":", "goobjs", "=", "set", "(", ")", "altgo2goobj", "=", "{", "}", "for", "goid", ",", "goobj", "in", "go2obj", ".", "items", "(", ")", ":", "goobjs", ".", "add", "(", "goobj", ")", "if", "goid", "!=", "goobj", ".", "id", ":", "altgo2goobj", "[", "goid", "]", "=", "goobj", "return", "goobjs", ",", "altgo2goobj" ]
Separate alt GO IDs and key GO IDs.
[ "Separate", "alt", "GO", "IDs", "and", "key", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L99-L107
228,530
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
add_alt_goids
def add_alt_goids(go2values, altgo2goobj): """Add alternate source GO IDs.""" for goobj_key in altgo2goobj.values(): values_curr = go2values[goobj_key.id] for goid_alt in goobj_key.alt_ids: go2values[goid_alt] = values_curr return go2values
python
def add_alt_goids(go2values, altgo2goobj): """Add alternate source GO IDs.""" for goobj_key in altgo2goobj.values(): values_curr = go2values[goobj_key.id] for goid_alt in goobj_key.alt_ids: go2values[goid_alt] = values_curr return go2values
[ "def", "add_alt_goids", "(", "go2values", ",", "altgo2goobj", ")", ":", "for", "goobj_key", "in", "altgo2goobj", ".", "values", "(", ")", ":", "values_curr", "=", "go2values", "[", "goobj_key", ".", "id", "]", "for", "goid_alt", "in", "goobj_key", ".", "alt_ids", ":", "go2values", "[", "goid_alt", "]", "=", "values_curr", "return", "go2values" ]
Add alternate source GO IDs.
[ "Add", "alternate", "source", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L109-L115
228,531
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
fill_main_goids
def fill_main_goids(go2obj, goids): """Ensure main GO IDs are included in go2obj.""" # User GO IDs (goids) may be either main GO IDs or alternate GO IDs. for goid in goids: goobj = go2obj[goid] # If a user specified an ALT GO ID and main GO ID not in go2obj: if goid != goobj.id and goobj.id not in go2obj: # Add main GO ID to go2obj go2obj[goobj.id] = goobj
python
def fill_main_goids(go2obj, goids): """Ensure main GO IDs are included in go2obj.""" # User GO IDs (goids) may be either main GO IDs or alternate GO IDs. for goid in goids: goobj = go2obj[goid] # If a user specified an ALT GO ID and main GO ID not in go2obj: if goid != goobj.id and goobj.id not in go2obj: # Add main GO ID to go2obj go2obj[goobj.id] = goobj
[ "def", "fill_main_goids", "(", "go2obj", ",", "goids", ")", ":", "# User GO IDs (goids) may be either main GO IDs or alternate GO IDs.", "for", "goid", "in", "goids", ":", "goobj", "=", "go2obj", "[", "goid", "]", "# If a user specified an ALT GO ID and main GO ID not in go2obj:", "if", "goid", "!=", "goobj", ".", "id", "and", "goobj", ".", "id", "not", "in", "go2obj", ":", "# Add main GO ID to go2obj", "go2obj", "[", "goobj", ".", "id", "]", "=", "goobj" ]
Ensure main GO IDs are included in go2obj.
[ "Ensure", "main", "GO", "IDs", "are", "included", "in", "go2obj", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L118-L126
228,532
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
fill_altgoids
def fill_altgoids(go2obj): """Given a go2obj containing key GO IDs, fill with all alternate GO IDs.""" alt2obj = {altgo:goobj for goobj in go2obj.values() for altgo in goobj.alt_ids} for goid, goobj in alt2obj.items(): go2obj[goid] = goobj
python
def fill_altgoids(go2obj): """Given a go2obj containing key GO IDs, fill with all alternate GO IDs.""" alt2obj = {altgo:goobj for goobj in go2obj.values() for altgo in goobj.alt_ids} for goid, goobj in alt2obj.items(): go2obj[goid] = goobj
[ "def", "fill_altgoids", "(", "go2obj", ")", ":", "alt2obj", "=", "{", "altgo", ":", "goobj", "for", "goobj", "in", "go2obj", ".", "values", "(", ")", "for", "altgo", "in", "goobj", ".", "alt_ids", "}", "for", "goid", ",", "goobj", "in", "alt2obj", ".", "items", "(", ")", ":", "go2obj", "[", "goid", "]", "=", "goobj" ]
Given a go2obj containing key GO IDs, fill with all alternate GO IDs.
[ "Given", "a", "go2obj", "containing", "key", "GO", "IDs", "fill", "with", "all", "alternate", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L128-L132
228,533
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
fill_relationshipobjs
def fill_relationshipobjs(go2obj, relationships): """Add GO IDs to go2obj that are involved in relationships.""" # Get all GO Term record objects that have relationships obj = RelationshipFill(go2obj, relationships) for goobj in go2obj.values(): if goobj.relationship: obj.fill_relationshipgo2obj(goobj) if goobj.relationship_rev: obj.fill_relationshiprevgo2obj(goobj)
python
def fill_relationshipobjs(go2obj, relationships): """Add GO IDs to go2obj that are involved in relationships.""" # Get all GO Term record objects that have relationships obj = RelationshipFill(go2obj, relationships) for goobj in go2obj.values(): if goobj.relationship: obj.fill_relationshipgo2obj(goobj) if goobj.relationship_rev: obj.fill_relationshiprevgo2obj(goobj)
[ "def", "fill_relationshipobjs", "(", "go2obj", ",", "relationships", ")", ":", "# Get all GO Term record objects that have relationships", "obj", "=", "RelationshipFill", "(", "go2obj", ",", "relationships", ")", "for", "goobj", "in", "go2obj", ".", "values", "(", ")", ":", "if", "goobj", ".", "relationship", ":", "obj", ".", "fill_relationshipgo2obj", "(", "goobj", ")", "if", "goobj", ".", "relationship_rev", ":", "obj", ".", "fill_relationshiprevgo2obj", "(", "goobj", ")" ]
Add GO IDs to go2obj that are involved in relationships.
[ "Add", "GO", "IDs", "to", "go2obj", "that", "are", "involved", "in", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L135-L143
228,534
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
fill_childgoid2obj
def fill_childgoid2obj(childgoid2obj, parent_obj): """Fill childgoid2obj with all child key GO IDs and their objects.""" for child_obj in parent_obj.children: if child_obj.id not in childgoid2obj: childgoid2obj[child_obj.id] = child_obj fill_childgoid2obj(childgoid2obj, child_obj)
python
def fill_childgoid2obj(childgoid2obj, parent_obj): """Fill childgoid2obj with all child key GO IDs and their objects.""" for child_obj in parent_obj.children: if child_obj.id not in childgoid2obj: childgoid2obj[child_obj.id] = child_obj fill_childgoid2obj(childgoid2obj, child_obj)
[ "def", "fill_childgoid2obj", "(", "childgoid2obj", ",", "parent_obj", ")", ":", "for", "child_obj", "in", "parent_obj", ".", "children", ":", "if", "child_obj", ".", "id", "not", "in", "childgoid2obj", ":", "childgoid2obj", "[", "child_obj", ".", "id", "]", "=", "child_obj", "fill_childgoid2obj", "(", "childgoid2obj", ",", "child_obj", ")" ]
Fill childgoid2obj with all child key GO IDs and their objects.
[ "Fill", "childgoid2obj", "with", "all", "child", "key", "GO", "IDs", "and", "their", "objects", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L180-L185
228,535
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
get_leaf_children
def get_leaf_children(gos_user, go2obj_arg): """Find all the GO descendants under all user GO IDs. Return leaf-level GO IDs.""" childgoid2obj = {} for goid_usr in gos_user: goobj_usr = go2obj_arg[goid_usr] fill_childgoid2obj(childgoid2obj, goobj_usr) return set(go for go, o in childgoid2obj.items() if not o.children)
python
def get_leaf_children(gos_user, go2obj_arg): """Find all the GO descendants under all user GO IDs. Return leaf-level GO IDs.""" childgoid2obj = {} for goid_usr in gos_user: goobj_usr = go2obj_arg[goid_usr] fill_childgoid2obj(childgoid2obj, goobj_usr) return set(go for go, o in childgoid2obj.items() if not o.children)
[ "def", "get_leaf_children", "(", "gos_user", ",", "go2obj_arg", ")", ":", "childgoid2obj", "=", "{", "}", "for", "goid_usr", "in", "gos_user", ":", "goobj_usr", "=", "go2obj_arg", "[", "goid_usr", "]", "fill_childgoid2obj", "(", "childgoid2obj", ",", "goobj_usr", ")", "return", "set", "(", "go", "for", "go", ",", "o", "in", "childgoid2obj", ".", "items", "(", ")", "if", "not", "o", ".", "children", ")" ]
Find all the GO descendants under all user GO IDs. Return leaf-level GO IDs.
[ "Find", "all", "the", "GO", "descendants", "under", "all", "user", "GO", "IDs", ".", "Return", "leaf", "-", "level", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L188-L194
228,536
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
chk_goids
def chk_goids(goids, msg=None, raise_except=True): """check that all GO IDs have the proper format.""" for goid in goids: if not goid_is_valid(goid): if raise_except: raise RuntimeError("BAD GO({GO}): {MSG}".format(GO=goid, MSG=msg)) else: return goid
python
def chk_goids(goids, msg=None, raise_except=True): """check that all GO IDs have the proper format.""" for goid in goids: if not goid_is_valid(goid): if raise_except: raise RuntimeError("BAD GO({GO}): {MSG}".format(GO=goid, MSG=msg)) else: return goid
[ "def", "chk_goids", "(", "goids", ",", "msg", "=", "None", ",", "raise_except", "=", "True", ")", ":", "for", "goid", "in", "goids", ":", "if", "not", "goid_is_valid", "(", "goid", ")", ":", "if", "raise_except", ":", "raise", "RuntimeError", "(", "\"BAD GO({GO}): {MSG}\"", ".", "format", "(", "GO", "=", "goid", ",", "MSG", "=", "msg", ")", ")", "else", ":", "return", "goid" ]
check that all GO IDs have the proper format.
[ "check", "that", "all", "GO", "IDs", "have", "the", "proper", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L208-L215
228,537
tanghaibao/goatools
goatools/gosubdag/go_tasks.py
TopologicalSortRelationships._get_sorted_relationships
def _get_sorted_relationships(self, goterm): """Traverse GO Terms above the current GO Term. Then add current GO Term to sorted.""" if goterm.id in self.goids_seen: return self.goids_seen.add(goterm.id) for goterm_upper in goterm.get_goterms_upper(): self._get_sorted_relationships(goterm_upper) self.goterms_sorted.append(goterm)
python
def _get_sorted_relationships(self, goterm): """Traverse GO Terms above the current GO Term. Then add current GO Term to sorted.""" if goterm.id in self.goids_seen: return self.goids_seen.add(goterm.id) for goterm_upper in goterm.get_goterms_upper(): self._get_sorted_relationships(goterm_upper) self.goterms_sorted.append(goterm)
[ "def", "_get_sorted_relationships", "(", "self", ",", "goterm", ")", ":", "if", "goterm", ".", "id", "in", "self", ".", "goids_seen", ":", "return", "self", ".", "goids_seen", ".", "add", "(", "goterm", ".", "id", ")", "for", "goterm_upper", "in", "goterm", ".", "get_goterms_upper", "(", ")", ":", "self", ".", "_get_sorted_relationships", "(", "goterm_upper", ")", "self", ".", "goterms_sorted", ".", "append", "(", "goterm", ")" ]
Traverse GO Terms above the current GO Term. Then add current GO Term to sorted.
[ "Traverse", "GO", "Terms", "above", "the", "current", "GO", "Term", ".", "Then", "add", "current", "GO", "Term", "to", "sorted", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_tasks.py#L32-L39
228,538
tanghaibao/goatools
goatools/grouper/read_goids.py
read_sections
def read_sections(sections_file, exclude_ungrouped=False, prt=sys.stdout): """Get sections and GO grouping hdrgos from file, if sections exist.""" if sections_file is None: return None assert isinstance(sections_file, str), "BAD SECTIONS FILENAME({S})".format( S=sections_file) if os.path.exists(sections_file): return ReadGoids().read_sections(sections_file, False, exclude_ungrouped) # Is 'sections_file' a module string? if '/' not in sections_file and r'\\' not in sections_file and \ pkgutil.find_loader(sections_file) is not None: mod = importlib.import_module(sections_file) var = getattr(mod, 'SECTIONS', None) if var is not None: dat = SummarySec2dHdrGos().summarize_sec2hdrgos(var) print(Grouper.fmtsum.format( GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']), UNGRP="N/A", undesc="unused", ACTION="IMPORTED: ", FILE=sections_file)) return var raise RuntimeError("NO 'SECTIONS' VARIABLE FOUND IN MODULE({M})".format(M=sections_file)) if prt: prt.write("CANNOT READ: {SEC}\n".format(SEC=sections_file))
python
def read_sections(sections_file, exclude_ungrouped=False, prt=sys.stdout): """Get sections and GO grouping hdrgos from file, if sections exist.""" if sections_file is None: return None assert isinstance(sections_file, str), "BAD SECTIONS FILENAME({S})".format( S=sections_file) if os.path.exists(sections_file): return ReadGoids().read_sections(sections_file, False, exclude_ungrouped) # Is 'sections_file' a module string? if '/' not in sections_file and r'\\' not in sections_file and \ pkgutil.find_loader(sections_file) is not None: mod = importlib.import_module(sections_file) var = getattr(mod, 'SECTIONS', None) if var is not None: dat = SummarySec2dHdrGos().summarize_sec2hdrgos(var) print(Grouper.fmtsum.format( GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']), UNGRP="N/A", undesc="unused", ACTION="IMPORTED: ", FILE=sections_file)) return var raise RuntimeError("NO 'SECTIONS' VARIABLE FOUND IN MODULE({M})".format(M=sections_file)) if prt: prt.write("CANNOT READ: {SEC}\n".format(SEC=sections_file))
[ "def", "read_sections", "(", "sections_file", ",", "exclude_ungrouped", "=", "False", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "if", "sections_file", "is", "None", ":", "return", "None", "assert", "isinstance", "(", "sections_file", ",", "str", ")", ",", "\"BAD SECTIONS FILENAME({S})\"", ".", "format", "(", "S", "=", "sections_file", ")", "if", "os", ".", "path", ".", "exists", "(", "sections_file", ")", ":", "return", "ReadGoids", "(", ")", ".", "read_sections", "(", "sections_file", ",", "False", ",", "exclude_ungrouped", ")", "# Is 'sections_file' a module string?", "if", "'/'", "not", "in", "sections_file", "and", "r'\\\\'", "not", "in", "sections_file", "and", "pkgutil", ".", "find_loader", "(", "sections_file", ")", "is", "not", "None", ":", "mod", "=", "importlib", ".", "import_module", "(", "sections_file", ")", "var", "=", "getattr", "(", "mod", ",", "'SECTIONS'", ",", "None", ")", "if", "var", "is", "not", "None", ":", "dat", "=", "SummarySec2dHdrGos", "(", ")", ".", "summarize_sec2hdrgos", "(", "var", ")", "print", "(", "Grouper", ".", "fmtsum", ".", "format", "(", "GO_DESC", "=", "'hdr'", ",", "SECs", "=", "len", "(", "dat", "[", "'S'", "]", ")", ",", "GOs", "=", "len", "(", "dat", "[", "'G'", "]", ")", ",", "UNGRP", "=", "\"N/A\"", ",", "undesc", "=", "\"unused\"", ",", "ACTION", "=", "\"IMPORTED: \"", ",", "FILE", "=", "sections_file", ")", ")", "return", "var", "raise", "RuntimeError", "(", "\"NO 'SECTIONS' VARIABLE FOUND IN MODULE({M})\"", ".", "format", "(", "M", "=", "sections_file", ")", ")", "if", "prt", ":", "prt", ".", "write", "(", "\"CANNOT READ: {SEC}\\n\"", ".", "format", "(", "SEC", "=", "sections_file", ")", ")" ]
Get sections and GO grouping hdrgos from file, if sections exist.
[ "Get", "sections", "and", "GO", "grouping", "hdrgos", "from", "file", "if", "sections", "exist", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L19-L40
228,539
tanghaibao/goatools
goatools/grouper/read_goids.py
ReadGoids.read_py
def read_py(self, fin_txt, get_goids_only, exclude_ungrouped, prt=sys.stdout): """Read GO IDs or sections data from a Python file.""" goids_fin = self._read_py(fin_txt, get_goids_only, exclude_ungrouped) sections = self._read_finish(goids_fin, prt) # Print summary of GO IDs read if prt is not None: self._prt_read_msg(prt, fin_txt, exclude_ungrouped) return sections
python
def read_py(self, fin_txt, get_goids_only, exclude_ungrouped, prt=sys.stdout): """Read GO IDs or sections data from a Python file.""" goids_fin = self._read_py(fin_txt, get_goids_only, exclude_ungrouped) sections = self._read_finish(goids_fin, prt) # Print summary of GO IDs read if prt is not None: self._prt_read_msg(prt, fin_txt, exclude_ungrouped) return sections
[ "def", "read_py", "(", "self", ",", "fin_txt", ",", "get_goids_only", ",", "exclude_ungrouped", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "goids_fin", "=", "self", ".", "_read_py", "(", "fin_txt", ",", "get_goids_only", ",", "exclude_ungrouped", ")", "sections", "=", "self", ".", "_read_finish", "(", "goids_fin", ",", "prt", ")", "# Print summary of GO IDs read", "if", "prt", "is", "not", "None", ":", "self", ".", "_prt_read_msg", "(", "prt", ",", "fin_txt", ",", "exclude_ungrouped", ")", "return", "sections" ]
Read GO IDs or sections data from a Python file.
[ "Read", "GO", "IDs", "or", "sections", "data", "from", "a", "Python", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L74-L81
228,540
tanghaibao/goatools
goatools/grouper/read_goids.py
ReadGoids.read_sections
def read_sections(self, sections_file, get_goids_only, exclude_ungrouped): """Read sections variable from a text file of from a Python file.""" ext = os.path.splitext(sections_file)[1] file_contents = None if ext == '.py': file_contents = self.read_py(sections_file, get_goids_only, exclude_ungrouped) else: file_contents = self.read_txt(sections_file, get_goids_only, exclude_ungrouped) if file_contents: return file_contents.get('sections', None)
python
def read_sections(self, sections_file, get_goids_only, exclude_ungrouped): """Read sections variable from a text file of from a Python file.""" ext = os.path.splitext(sections_file)[1] file_contents = None if ext == '.py': file_contents = self.read_py(sections_file, get_goids_only, exclude_ungrouped) else: file_contents = self.read_txt(sections_file, get_goids_only, exclude_ungrouped) if file_contents: return file_contents.get('sections', None)
[ "def", "read_sections", "(", "self", ",", "sections_file", ",", "get_goids_only", ",", "exclude_ungrouped", ")", ":", "ext", "=", "os", ".", "path", ".", "splitext", "(", "sections_file", ")", "[", "1", "]", "file_contents", "=", "None", "if", "ext", "==", "'.py'", ":", "file_contents", "=", "self", ".", "read_py", "(", "sections_file", ",", "get_goids_only", ",", "exclude_ungrouped", ")", "else", ":", "file_contents", "=", "self", ".", "read_txt", "(", "sections_file", ",", "get_goids_only", ",", "exclude_ungrouped", ")", "if", "file_contents", ":", "return", "file_contents", ".", "get", "(", "'sections'", ",", "None", ")" ]
Read sections variable from a text file of from a Python file.
[ "Read", "sections", "variable", "from", "a", "text", "file", "of", "from", "a", "Python", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L83-L92
228,541
tanghaibao/goatools
goatools/grouper/read_goids.py
ReadGoids._rpt_unused_sections
def _rpt_unused_sections(self, prt): """Report unused sections.""" sections_unused = set(self.sections_seen).difference(self.section2goids.keys()) for sec in sections_unused: prt.write(" UNUSED SECTION: {SEC}\n".format(SEC=sec))
python
def _rpt_unused_sections(self, prt): """Report unused sections.""" sections_unused = set(self.sections_seen).difference(self.section2goids.keys()) for sec in sections_unused: prt.write(" UNUSED SECTION: {SEC}\n".format(SEC=sec))
[ "def", "_rpt_unused_sections", "(", "self", ",", "prt", ")", ":", "sections_unused", "=", "set", "(", "self", ".", "sections_seen", ")", ".", "difference", "(", "self", ".", "section2goids", ".", "keys", "(", ")", ")", "for", "sec", "in", "sections_unused", ":", "prt", ".", "write", "(", "\" UNUSED SECTION: {SEC}\\n\"", ".", "format", "(", "SEC", "=", "sec", ")", ")" ]
Report unused sections.
[ "Report", "unused", "sections", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L161-L165
228,542
tanghaibao/goatools
goatools/grouper/read_goids.py
ReadGoids._prt_read_msg
def _prt_read_msg(self, prt, fin_txt, exclude_ungrouped): """Print which file was read and the number of GO IDs found.""" if self.sections_seen or exclude_ungrouped: # dat = Grouper.get_summary_data(self.section2goids.items(), HdrgosSections.secdflt) dat = SummarySec2dHdrGos().summarize_sec2hdrgos(self.section2goids.items()) sys.stdout.write(Grouper.fmtsum.format( GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']), UNGRP="N/A", undesc="unused", ACTION="READ: ", FILE=fin_txt)) elif self.goids_fin: prt.write(" {G} GO IDs READ: {FIN}\n".format(G=len(self.goids_fin), FIN=fin_txt))
python
def _prt_read_msg(self, prt, fin_txt, exclude_ungrouped): """Print which file was read and the number of GO IDs found.""" if self.sections_seen or exclude_ungrouped: # dat = Grouper.get_summary_data(self.section2goids.items(), HdrgosSections.secdflt) dat = SummarySec2dHdrGos().summarize_sec2hdrgos(self.section2goids.items()) sys.stdout.write(Grouper.fmtsum.format( GO_DESC='hdr', SECs=len(dat['S']), GOs=len(dat['G']), UNGRP="N/A", undesc="unused", ACTION="READ: ", FILE=fin_txt)) elif self.goids_fin: prt.write(" {G} GO IDs READ: {FIN}\n".format(G=len(self.goids_fin), FIN=fin_txt))
[ "def", "_prt_read_msg", "(", "self", ",", "prt", ",", "fin_txt", ",", "exclude_ungrouped", ")", ":", "if", "self", ".", "sections_seen", "or", "exclude_ungrouped", ":", "# dat = Grouper.get_summary_data(self.section2goids.items(), HdrgosSections.secdflt)", "dat", "=", "SummarySec2dHdrGos", "(", ")", ".", "summarize_sec2hdrgos", "(", "self", ".", "section2goids", ".", "items", "(", ")", ")", "sys", ".", "stdout", ".", "write", "(", "Grouper", ".", "fmtsum", ".", "format", "(", "GO_DESC", "=", "'hdr'", ",", "SECs", "=", "len", "(", "dat", "[", "'S'", "]", ")", ",", "GOs", "=", "len", "(", "dat", "[", "'G'", "]", ")", ",", "UNGRP", "=", "\"N/A\"", ",", "undesc", "=", "\"unused\"", ",", "ACTION", "=", "\"READ: \"", ",", "FILE", "=", "fin_txt", ")", ")", "elif", "self", ".", "goids_fin", ":", "prt", ".", "write", "(", "\" {G} GO IDs READ: {FIN}\\n\"", ".", "format", "(", "G", "=", "len", "(", "self", ".", "goids_fin", ")", ",", "FIN", "=", "fin_txt", ")", ")" ]
Print which file was read and the number of GO IDs found.
[ "Print", "which", "file", "was", "read", "and", "the", "number", "of", "GO", "IDs", "found", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/read_goids.py#L182-L191
228,543
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.rm_gos
def rm_gos(self, rm_goids): """Remove any edges that contain user-specified edges.""" self.edges = self._rm_gos_edges(rm_goids, self.edges) self.edges_rel = self._rm_gos_edges_rel(rm_goids, self.edges_rel)
python
def rm_gos(self, rm_goids): """Remove any edges that contain user-specified edges.""" self.edges = self._rm_gos_edges(rm_goids, self.edges) self.edges_rel = self._rm_gos_edges_rel(rm_goids, self.edges_rel)
[ "def", "rm_gos", "(", "self", ",", "rm_goids", ")", ":", "self", ".", "edges", "=", "self", ".", "_rm_gos_edges", "(", "rm_goids", ",", "self", ".", "edges", ")", "self", ".", "edges_rel", "=", "self", ".", "_rm_gos_edges_rel", "(", "rm_goids", ",", "self", ".", "edges_rel", ")" ]
Remove any edges that contain user-specified edges.
[ "Remove", "any", "edges", "that", "contain", "user", "-", "specified", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L64-L67
228,544
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase._rm_gos_edges_rel
def _rm_gos_edges_rel(self, rm_goids, edges_rel): """Remove any relationship that contain user-specified edges.""" edges_ret = {} for rname, edges_cur in edges_rel.items(): edges_new = self._rm_gos_edges(rm_goids, edges_cur) if edges_new: edges_ret[rname] = edges_new return edges_ret
python
def _rm_gos_edges_rel(self, rm_goids, edges_rel): """Remove any relationship that contain user-specified edges.""" edges_ret = {} for rname, edges_cur in edges_rel.items(): edges_new = self._rm_gos_edges(rm_goids, edges_cur) if edges_new: edges_ret[rname] = edges_new return edges_ret
[ "def", "_rm_gos_edges_rel", "(", "self", ",", "rm_goids", ",", "edges_rel", ")", ":", "edges_ret", "=", "{", "}", "for", "rname", ",", "edges_cur", "in", "edges_rel", ".", "items", "(", ")", ":", "edges_new", "=", "self", ".", "_rm_gos_edges", "(", "rm_goids", ",", "edges_cur", ")", "if", "edges_new", ":", "edges_ret", "[", "rname", "]", "=", "edges_new", "return", "edges_ret" ]
Remove any relationship that contain user-specified edges.
[ "Remove", "any", "relationship", "that", "contain", "user", "-", "specified", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L69-L76
228,545
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase._rm_gos_edges
def _rm_gos_edges(rm_goids, edges_all): """Remove any is_a edges that contain user-specified edges.""" edges_reduced = [] for goid_child, goid_parent in sorted(edges_all, key=lambda t: t[1]): if goid_child not in rm_goids and goid_parent not in rm_goids: edges_reduced.append((goid_child, goid_parent)) return edges_reduced
python
def _rm_gos_edges(rm_goids, edges_all): """Remove any is_a edges that contain user-specified edges.""" edges_reduced = [] for goid_child, goid_parent in sorted(edges_all, key=lambda t: t[1]): if goid_child not in rm_goids and goid_parent not in rm_goids: edges_reduced.append((goid_child, goid_parent)) return edges_reduced
[ "def", "_rm_gos_edges", "(", "rm_goids", ",", "edges_all", ")", ":", "edges_reduced", "=", "[", "]", "for", "goid_child", ",", "goid_parent", "in", "sorted", "(", "edges_all", ",", "key", "=", "lambda", "t", ":", "t", "[", "1", "]", ")", ":", "if", "goid_child", "not", "in", "rm_goids", "and", "goid_parent", "not", "in", "rm_goids", ":", "edges_reduced", ".", "append", "(", "(", "goid_child", ",", "goid_parent", ")", ")", "return", "edges_reduced" ]
Remove any is_a edges that contain user-specified edges.
[ "Remove", "any", "is_a", "edges", "that", "contain", "user", "-", "specified", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L79-L85
228,546
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.get_all_edge_nodes
def get_all_edge_nodes(self): """Return a list of all GO IDs that are connected to edges.""" edge_nodes = set(e for es in self.edges for e in es) for edges in self.edges_rel.values(): rel_nodes = set(e for es in edges for e in es) edge_nodes.update(rel_nodes) return edge_nodes
python
def get_all_edge_nodes(self): """Return a list of all GO IDs that are connected to edges.""" edge_nodes = set(e for es in self.edges for e in es) for edges in self.edges_rel.values(): rel_nodes = set(e for es in edges for e in es) edge_nodes.update(rel_nodes) return edge_nodes
[ "def", "get_all_edge_nodes", "(", "self", ")", ":", "edge_nodes", "=", "set", "(", "e", "for", "es", "in", "self", ".", "edges", "for", "e", "in", "es", ")", "for", "edges", "in", "self", ".", "edges_rel", ".", "values", "(", ")", ":", "rel_nodes", "=", "set", "(", "e", "for", "es", "in", "edges", "for", "e", "in", "es", ")", "edge_nodes", ".", "update", "(", "rel_nodes", ")", "return", "edge_nodes" ]
Return a list of all GO IDs that are connected to edges.
[ "Return", "a", "list", "of", "all", "GO", "IDs", "that", "are", "connected", "to", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L87-L93
228,547
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.chk_edges
def chk_edges(self): """Check that all edge nodes exist in local subset.""" goids = set(self.go2obj) self.chk_edges_nodes(self.edges, goids, "is_a") for reltype, edges in self.edges_rel.items(): self.chk_edges_nodes(edges, goids, reltype)
python
def chk_edges(self): """Check that all edge nodes exist in local subset.""" goids = set(self.go2obj) self.chk_edges_nodes(self.edges, goids, "is_a") for reltype, edges in self.edges_rel.items(): self.chk_edges_nodes(edges, goids, reltype)
[ "def", "chk_edges", "(", "self", ")", ":", "goids", "=", "set", "(", "self", ".", "go2obj", ")", "self", ".", "chk_edges_nodes", "(", "self", ".", "edges", ",", "goids", ",", "\"is_a\"", ")", "for", "reltype", ",", "edges", "in", "self", ".", "edges_rel", ".", "items", "(", ")", ":", "self", ".", "chk_edges_nodes", "(", "edges", ",", "goids", ",", "reltype", ")" ]
Check that all edge nodes exist in local subset.
[ "Check", "that", "all", "edge", "nodes", "exist", "in", "local", "subset", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L95-L100
228,548
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.chk_edges_nodes
def chk_edges_nodes(edges, nodes, name): """Check that user specified edges have a node which exists.""" edge_nodes = set(e for es in edges for e in es) missing_nodes = edge_nodes.difference(nodes) assert not missing_nodes, "MISSING: {GOs}\n{NM} EDGES MISSING {N} NODES (OF {T})".format( NM=name, N=len(missing_nodes), T=len(edge_nodes), GOs=missing_nodes)
python
def chk_edges_nodes(edges, nodes, name): """Check that user specified edges have a node which exists.""" edge_nodes = set(e for es in edges for e in es) missing_nodes = edge_nodes.difference(nodes) assert not missing_nodes, "MISSING: {GOs}\n{NM} EDGES MISSING {N} NODES (OF {T})".format( NM=name, N=len(missing_nodes), T=len(edge_nodes), GOs=missing_nodes)
[ "def", "chk_edges_nodes", "(", "edges", ",", "nodes", ",", "name", ")", ":", "edge_nodes", "=", "set", "(", "e", "for", "es", "in", "edges", "for", "e", "in", "es", ")", "missing_nodes", "=", "edge_nodes", ".", "difference", "(", "nodes", ")", "assert", "not", "missing_nodes", ",", "\"MISSING: {GOs}\\n{NM} EDGES MISSING {N} NODES (OF {T})\"", ".", "format", "(", "NM", "=", "name", ",", "N", "=", "len", "(", "missing_nodes", ")", ",", "T", "=", "len", "(", "edge_nodes", ")", ",", "GOs", "=", "missing_nodes", ")" ]
Check that user specified edges have a node which exists.
[ "Check", "that", "user", "specified", "edges", "have", "a", "node", "which", "exists", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L103-L108
228,549
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesBase.get_c2ps
def get_c2ps(self): """Set child2parents dict for all parents used in this set of edges.""" c2ps = defaultdict(set) for goid_child, goid_parent in self.edges: c2ps[goid_child].add(goid_parent) return c2ps
python
def get_c2ps(self): """Set child2parents dict for all parents used in this set of edges.""" c2ps = defaultdict(set) for goid_child, goid_parent in self.edges: c2ps[goid_child].add(goid_parent) return c2ps
[ "def", "get_c2ps", "(", "self", ")", ":", "c2ps", "=", "defaultdict", "(", "set", ")", "for", "goid_child", ",", "goid_parent", "in", "self", ".", "edges", ":", "c2ps", "[", "goid_child", "]", ".", "add", "(", "goid_parent", ")", "return", "c2ps" ]
Set child2parents dict for all parents used in this set of edges.
[ "Set", "child2parents", "dict", "for", "all", "parents", "used", "in", "this", "set", "of", "edges", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L110-L115
228,550
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesRelatives._init_edges_relationships
def _init_edges_relationships(rel2src2dsts, rel2dst2srcs): """Get the directed edges from GO term to GO term using relationships.""" edge_rel2fromto = {} relationships = set(rel2src2dsts).union(rel2dst2srcs) for reltype in relationships: edge_from_to = [] if reltype in rel2src2dsts: for parent, children in rel2src2dsts[reltype].items(): for child in children: edge_from_to.append((child, parent)) if reltype in rel2dst2srcs: for parent, children in rel2dst2srcs[reltype].items(): for child in children: edge_from_to.append((child, parent)) edge_rel2fromto[reltype] = edge_from_to return edge_rel2fromto
python
def _init_edges_relationships(rel2src2dsts, rel2dst2srcs): """Get the directed edges from GO term to GO term using relationships.""" edge_rel2fromto = {} relationships = set(rel2src2dsts).union(rel2dst2srcs) for reltype in relationships: edge_from_to = [] if reltype in rel2src2dsts: for parent, children in rel2src2dsts[reltype].items(): for child in children: edge_from_to.append((child, parent)) if reltype in rel2dst2srcs: for parent, children in rel2dst2srcs[reltype].items(): for child in children: edge_from_to.append((child, parent)) edge_rel2fromto[reltype] = edge_from_to return edge_rel2fromto
[ "def", "_init_edges_relationships", "(", "rel2src2dsts", ",", "rel2dst2srcs", ")", ":", "edge_rel2fromto", "=", "{", "}", "relationships", "=", "set", "(", "rel2src2dsts", ")", ".", "union", "(", "rel2dst2srcs", ")", "for", "reltype", "in", "relationships", ":", "edge_from_to", "=", "[", "]", "if", "reltype", "in", "rel2src2dsts", ":", "for", "parent", ",", "children", "in", "rel2src2dsts", "[", "reltype", "]", ".", "items", "(", ")", ":", "for", "child", "in", "children", ":", "edge_from_to", ".", "append", "(", "(", "child", ",", "parent", ")", ")", "if", "reltype", "in", "rel2dst2srcs", ":", "for", "parent", ",", "children", "in", "rel2dst2srcs", "[", "reltype", "]", ".", "items", "(", ")", ":", "for", "child", "in", "children", ":", "edge_from_to", ".", "append", "(", "(", "child", ",", "parent", ")", ")", "edge_rel2fromto", "[", "reltype", "]", "=", "edge_from_to", "return", "edge_rel2fromto" ]
Get the directed edges from GO term to GO term using relationships.
[ "Get", "the", "directed", "edges", "from", "GO", "term", "to", "GO", "term", "using", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L169-L184
228,551
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesRelatives._traverse_relationship_objs
def _traverse_relationship_objs(self, rel2src2dsts, goobj_child, goids_seen): """Traverse from source GO up relationships.""" child_id = goobj_child.id goids_seen.add(child_id) ##A self.go2obj[child_id] = goobj_child # Update goids_seen and go2obj with child alt_ids for goid_altid in goobj_child.alt_ids: goids_seen.add(goid_altid) ##A self.go2obj[goid_altid] = goobj_child # Loop through relationships of child object for reltype, recs in goobj_child.relationship.items(): if reltype in self.relationships: for relationship_obj in recs: relationship_id = relationship_obj.id rel2src2dsts[reltype][relationship_id].add(child_id) # If relationship has not been seen, traverse if relationship_id not in goids_seen: self._traverse_relationship_objs(rel2src2dsts, relationship_obj, goids_seen)
python
def _traverse_relationship_objs(self, rel2src2dsts, goobj_child, goids_seen): """Traverse from source GO up relationships.""" child_id = goobj_child.id goids_seen.add(child_id) ##A self.go2obj[child_id] = goobj_child # Update goids_seen and go2obj with child alt_ids for goid_altid in goobj_child.alt_ids: goids_seen.add(goid_altid) ##A self.go2obj[goid_altid] = goobj_child # Loop through relationships of child object for reltype, recs in goobj_child.relationship.items(): if reltype in self.relationships: for relationship_obj in recs: relationship_id = relationship_obj.id rel2src2dsts[reltype][relationship_id].add(child_id) # If relationship has not been seen, traverse if relationship_id not in goids_seen: self._traverse_relationship_objs(rel2src2dsts, relationship_obj, goids_seen)
[ "def", "_traverse_relationship_objs", "(", "self", ",", "rel2src2dsts", ",", "goobj_child", ",", "goids_seen", ")", ":", "child_id", "=", "goobj_child", ".", "id", "goids_seen", ".", "add", "(", "child_id", ")", "##A self.go2obj[child_id] = goobj_child", "# Update goids_seen and go2obj with child alt_ids", "for", "goid_altid", "in", "goobj_child", ".", "alt_ids", ":", "goids_seen", ".", "add", "(", "goid_altid", ")", "##A self.go2obj[goid_altid] = goobj_child", "# Loop through relationships of child object", "for", "reltype", ",", "recs", "in", "goobj_child", ".", "relationship", ".", "items", "(", ")", ":", "if", "reltype", "in", "self", ".", "relationships", ":", "for", "relationship_obj", "in", "recs", ":", "relationship_id", "=", "relationship_obj", ".", "id", "rel2src2dsts", "[", "reltype", "]", "[", "relationship_id", "]", ".", "add", "(", "child_id", ")", "# If relationship has not been seen, traverse", "if", "relationship_id", "not", "in", "goids_seen", ":", "self", ".", "_traverse_relationship_objs", "(", "rel2src2dsts", ",", "relationship_obj", ",", "goids_seen", ")" ]
Traverse from source GO up relationships.
[ "Traverse", "from", "source", "GO", "up", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L200-L217
228,552
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesRelatives._init_rel2dst2srcs
def _init_rel2dst2srcs(self, go_sources, traverse_child): """Traverse through reverse relationships.""" if not traverse_child or not self.relationships: return {} rel2dst2srcs = {r:defaultdict(set) for r in self.relationships} goids_seen = set() go2obj = self.go2obj for goid_src in go_sources: goobj_src = go2obj[goid_src] if goid_src not in goids_seen: self._traverse_relationship_rev_objs(rel2dst2srcs, goobj_src, goids_seen) return rel2dst2srcs
python
def _init_rel2dst2srcs(self, go_sources, traverse_child): """Traverse through reverse relationships.""" if not traverse_child or not self.relationships: return {} rel2dst2srcs = {r:defaultdict(set) for r in self.relationships} goids_seen = set() go2obj = self.go2obj for goid_src in go_sources: goobj_src = go2obj[goid_src] if goid_src not in goids_seen: self._traverse_relationship_rev_objs(rel2dst2srcs, goobj_src, goids_seen) return rel2dst2srcs
[ "def", "_init_rel2dst2srcs", "(", "self", ",", "go_sources", ",", "traverse_child", ")", ":", "if", "not", "traverse_child", "or", "not", "self", ".", "relationships", ":", "return", "{", "}", "rel2dst2srcs", "=", "{", "r", ":", "defaultdict", "(", "set", ")", "for", "r", "in", "self", ".", "relationships", "}", "goids_seen", "=", "set", "(", ")", "go2obj", "=", "self", ".", "go2obj", "for", "goid_src", "in", "go_sources", ":", "goobj_src", "=", "go2obj", "[", "goid_src", "]", "if", "goid_src", "not", "in", "goids_seen", ":", "self", ".", "_traverse_relationship_rev_objs", "(", "rel2dst2srcs", ",", "goobj_src", ",", "goids_seen", ")", "return", "rel2dst2srcs" ]
Traverse through reverse relationships.
[ "Traverse", "through", "reverse", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L220-L231
228,553
tanghaibao/goatools
goatools/gosubdag/go_edges.py
EdgesRelatives._init_c2ps
def _init_c2ps(self, go_sources, traverse_child): """Traverse up children.""" if not traverse_child: return {} c2ps = defaultdict(set) goids_seen = set() go2obj = self.go2obj for goid_src in go_sources: goobj_src = go2obj[goid_src] if goid_src not in goids_seen: ##F self._traverse_child_objs(c2ps, goobj_src, go2obj, goids_seen) self._traverse_child_objs(c2ps, goobj_src, goids_seen) return c2ps
python
def _init_c2ps(self, go_sources, traverse_child): """Traverse up children.""" if not traverse_child: return {} c2ps = defaultdict(set) goids_seen = set() go2obj = self.go2obj for goid_src in go_sources: goobj_src = go2obj[goid_src] if goid_src not in goids_seen: ##F self._traverse_child_objs(c2ps, goobj_src, go2obj, goids_seen) self._traverse_child_objs(c2ps, goobj_src, goids_seen) return c2ps
[ "def", "_init_c2ps", "(", "self", ",", "go_sources", ",", "traverse_child", ")", ":", "if", "not", "traverse_child", ":", "return", "{", "}", "c2ps", "=", "defaultdict", "(", "set", ")", "goids_seen", "=", "set", "(", ")", "go2obj", "=", "self", ".", "go2obj", "for", "goid_src", "in", "go_sources", ":", "goobj_src", "=", "go2obj", "[", "goid_src", "]", "if", "goid_src", "not", "in", "goids_seen", ":", "##F self._traverse_child_objs(c2ps, goobj_src, go2obj, goids_seen)", "self", ".", "_traverse_child_objs", "(", "c2ps", ",", "goobj_src", ",", "goids_seen", ")", "return", "c2ps" ]
Traverse up children.
[ "Traverse", "up", "children", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/go_edges.py#L290-L302
228,554
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData.chk
def chk(self, annotations, fout_err): """Check annotations.""" for idx, ntd in enumerate(annotations): self._chk_fld(ntd, "Qualifier") # optional 0 or greater self._chk_fld(ntd, "DB_Reference", 1) # required 1 or greater self._chk_fld(ntd, "With_From") # optional 0 or greater self._chk_fld(ntd, "DB_Name", 0, 1) # optional 0 or 1 self._chk_fld(ntd, "DB_Synonym") # optional 0 or greater self._chk_fld(ntd, "Taxon", 1, 2) flds = list(ntd) self._chk_qty_eq_1(flds) # self._chk_qualifier(ntd.Qualifier, flds, idx) if not ntd.Taxon or len(ntd.Taxon) not in {1, 2}: self.illegal_lines['BAD TAXON'].append((idx, '**{I}) TAXON: {NT}'.format(I=idx, NT=ntd))) if self.illegal_lines: self.prt_error_summary(fout_err) return not self.illegal_lines
python
def chk(self, annotations, fout_err): """Check annotations.""" for idx, ntd in enumerate(annotations): self._chk_fld(ntd, "Qualifier") # optional 0 or greater self._chk_fld(ntd, "DB_Reference", 1) # required 1 or greater self._chk_fld(ntd, "With_From") # optional 0 or greater self._chk_fld(ntd, "DB_Name", 0, 1) # optional 0 or 1 self._chk_fld(ntd, "DB_Synonym") # optional 0 or greater self._chk_fld(ntd, "Taxon", 1, 2) flds = list(ntd) self._chk_qty_eq_1(flds) # self._chk_qualifier(ntd.Qualifier, flds, idx) if not ntd.Taxon or len(ntd.Taxon) not in {1, 2}: self.illegal_lines['BAD TAXON'].append((idx, '**{I}) TAXON: {NT}'.format(I=idx, NT=ntd))) if self.illegal_lines: self.prt_error_summary(fout_err) return not self.illegal_lines
[ "def", "chk", "(", "self", ",", "annotations", ",", "fout_err", ")", ":", "for", "idx", ",", "ntd", "in", "enumerate", "(", "annotations", ")", ":", "self", ".", "_chk_fld", "(", "ntd", ",", "\"Qualifier\"", ")", "# optional 0 or greater", "self", ".", "_chk_fld", "(", "ntd", ",", "\"DB_Reference\"", ",", "1", ")", "# required 1 or greater", "self", ".", "_chk_fld", "(", "ntd", ",", "\"With_From\"", ")", "# optional 0 or greater", "self", ".", "_chk_fld", "(", "ntd", ",", "\"DB_Name\"", ",", "0", ",", "1", ")", "# optional 0 or 1", "self", ".", "_chk_fld", "(", "ntd", ",", "\"DB_Synonym\"", ")", "# optional 0 or greater", "self", ".", "_chk_fld", "(", "ntd", ",", "\"Taxon\"", ",", "1", ",", "2", ")", "flds", "=", "list", "(", "ntd", ")", "self", ".", "_chk_qty_eq_1", "(", "flds", ")", "# self._chk_qualifier(ntd.Qualifier, flds, idx)", "if", "not", "ntd", ".", "Taxon", "or", "len", "(", "ntd", ".", "Taxon", ")", "not", "in", "{", "1", ",", "2", "}", ":", "self", ".", "illegal_lines", "[", "'BAD TAXON'", "]", ".", "append", "(", "(", "idx", ",", "'**{I}) TAXON: {NT}'", ".", "format", "(", "I", "=", "idx", ",", "NT", "=", "ntd", ")", ")", ")", "if", "self", ".", "illegal_lines", ":", "self", ".", "prt_error_summary", "(", "fout_err", ")", "return", "not", "self", ".", "illegal_lines" ]
Check annotations.
[ "Check", "annotations", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L151-L167
228,555
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData.get_gafvals
def get_gafvals(self, line): """Convert fields from string to preferred format for GAF ver 2.1 and 2.0.""" flds = line.split('\t') flds[3] = self._get_qualifier(flds[3]) # 3 Qualifier flds[5] = self._get_set(flds[5]) # 5 DB_Reference flds[7] = self._get_set(flds[7]) # 7 With_From flds[8] = self.aspect2ns[flds[8]] # 8 GAF Aspect field converted to BP, MF, or CC flds[9] = self._get_set(flds[9]) # 9 DB_Name flds[10] = self._get_set(flds[10]) # 10 DB_Synonym flds[12] = self._do_taxons(flds[12]) # 12 Taxon flds[13] = GET_DATE_YYYYMMDD(flds[13]) # self.strptime(flds[13], '%Y%m%d').date(), # 13 Date 20190406 # Version 2.x has these additional fields not found in v1.0 if self.is_long: flds[15] = get_extensions(flds[15]) # Extensions (or Annotation_Extension) flds[16] = self._get_set(flds[16].rstrip()) else: flds[14] = self._get_set(flds[14].rstrip()) return flds
python
def get_gafvals(self, line): """Convert fields from string to preferred format for GAF ver 2.1 and 2.0.""" flds = line.split('\t') flds[3] = self._get_qualifier(flds[3]) # 3 Qualifier flds[5] = self._get_set(flds[5]) # 5 DB_Reference flds[7] = self._get_set(flds[7]) # 7 With_From flds[8] = self.aspect2ns[flds[8]] # 8 GAF Aspect field converted to BP, MF, or CC flds[9] = self._get_set(flds[9]) # 9 DB_Name flds[10] = self._get_set(flds[10]) # 10 DB_Synonym flds[12] = self._do_taxons(flds[12]) # 12 Taxon flds[13] = GET_DATE_YYYYMMDD(flds[13]) # self.strptime(flds[13], '%Y%m%d').date(), # 13 Date 20190406 # Version 2.x has these additional fields not found in v1.0 if self.is_long: flds[15] = get_extensions(flds[15]) # Extensions (or Annotation_Extension) flds[16] = self._get_set(flds[16].rstrip()) else: flds[14] = self._get_set(flds[14].rstrip()) return flds
[ "def", "get_gafvals", "(", "self", ",", "line", ")", ":", "flds", "=", "line", ".", "split", "(", "'\\t'", ")", "flds", "[", "3", "]", "=", "self", ".", "_get_qualifier", "(", "flds", "[", "3", "]", ")", "# 3 Qualifier", "flds", "[", "5", "]", "=", "self", ".", "_get_set", "(", "flds", "[", "5", "]", ")", "# 5 DB_Reference", "flds", "[", "7", "]", "=", "self", ".", "_get_set", "(", "flds", "[", "7", "]", ")", "# 7 With_From", "flds", "[", "8", "]", "=", "self", ".", "aspect2ns", "[", "flds", "[", "8", "]", "]", "# 8 GAF Aspect field converted to BP, MF, or CC", "flds", "[", "9", "]", "=", "self", ".", "_get_set", "(", "flds", "[", "9", "]", ")", "# 9 DB_Name", "flds", "[", "10", "]", "=", "self", ".", "_get_set", "(", "flds", "[", "10", "]", ")", "# 10 DB_Synonym", "flds", "[", "12", "]", "=", "self", ".", "_do_taxons", "(", "flds", "[", "12", "]", ")", "# 12 Taxon", "flds", "[", "13", "]", "=", "GET_DATE_YYYYMMDD", "(", "flds", "[", "13", "]", ")", "# self.strptime(flds[13], '%Y%m%d').date(), # 13 Date 20190406", "# Version 2.x has these additional fields not found in v1.0", "if", "self", ".", "is_long", ":", "flds", "[", "15", "]", "=", "get_extensions", "(", "flds", "[", "15", "]", ")", "# Extensions (or Annotation_Extension)", "flds", "[", "16", "]", "=", "self", ".", "_get_set", "(", "flds", "[", "16", "]", ".", "rstrip", "(", ")", ")", "else", ":", "flds", "[", "14", "]", "=", "self", ".", "_get_set", "(", "flds", "[", "14", "]", ".", "rstrip", "(", ")", ")", "return", "flds" ]
Convert fields from string to preferred format for GAF ver 2.1 and 2.0.
[ "Convert", "fields", "from", "string", "to", "preferred", "format", "for", "GAF", "ver", "2", ".", "1", "and", "2", ".", "0", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L173-L192
228,556
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData._get_qualifier
def _get_qualifier(val): """Get qualifiers. Correct for inconsistent capitalization in GAF files""" quals = set() if val == '': return quals for val in val.split('|'): val = val.lower() quals.add(val if val != 'not' else 'NOT') return quals
python
def _get_qualifier(val): """Get qualifiers. Correct for inconsistent capitalization in GAF files""" quals = set() if val == '': return quals for val in val.split('|'): val = val.lower() quals.add(val if val != 'not' else 'NOT') return quals
[ "def", "_get_qualifier", "(", "val", ")", ":", "quals", "=", "set", "(", ")", "if", "val", "==", "''", ":", "return", "quals", "for", "val", "in", "val", ".", "split", "(", "'|'", ")", ":", "val", "=", "val", ".", "lower", "(", ")", "quals", ".", "add", "(", "val", "if", "val", "!=", "'not'", "else", "'NOT'", ")", "return", "quals" ]
Get qualifiers. Correct for inconsistent capitalization in GAF files
[ "Get", "qualifiers", ".", "Correct", "for", "inconsistent", "capitalization", "in", "GAF", "files" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L195-L203
228,557
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData._chk_fld
def _chk_fld(self, ntd, name, qty_min=0, qty_max=None): """Further split a GAF value within a single field.""" vals = getattr(ntd, name) num_vals = len(vals) if num_vals < qty_min: self.illegal_lines['MIN QTY'].append( (-1, "FIELD({F}): MIN QUANTITY({Q}) WASN'T MET: {V}".format(F=name, Q=qty_min, V=vals))) if qty_max is not None: if num_vals > qty_max: self.illegal_lines['MAX QTY'].append( (-1, "FIELD({F}): MAX QUANTITY({Q}) EXCEEDED: {V}\n{NT}".format( F=name, Q=qty_max, V=vals, NT=ntd)))
python
def _chk_fld(self, ntd, name, qty_min=0, qty_max=None): """Further split a GAF value within a single field.""" vals = getattr(ntd, name) num_vals = len(vals) if num_vals < qty_min: self.illegal_lines['MIN QTY'].append( (-1, "FIELD({F}): MIN QUANTITY({Q}) WASN'T MET: {V}".format(F=name, Q=qty_min, V=vals))) if qty_max is not None: if num_vals > qty_max: self.illegal_lines['MAX QTY'].append( (-1, "FIELD({F}): MAX QUANTITY({Q}) EXCEEDED: {V}\n{NT}".format( F=name, Q=qty_max, V=vals, NT=ntd)))
[ "def", "_chk_fld", "(", "self", ",", "ntd", ",", "name", ",", "qty_min", "=", "0", ",", "qty_max", "=", "None", ")", ":", "vals", "=", "getattr", "(", "ntd", ",", "name", ")", "num_vals", "=", "len", "(", "vals", ")", "if", "num_vals", "<", "qty_min", ":", "self", ".", "illegal_lines", "[", "'MIN QTY'", "]", ".", "append", "(", "(", "-", "1", ",", "\"FIELD({F}): MIN QUANTITY({Q}) WASN'T MET: {V}\"", ".", "format", "(", "F", "=", "name", ",", "Q", "=", "qty_min", ",", "V", "=", "vals", ")", ")", ")", "if", "qty_max", "is", "not", "None", ":", "if", "num_vals", ">", "qty_max", ":", "self", ".", "illegal_lines", "[", "'MAX QTY'", "]", ".", "append", "(", "(", "-", "1", ",", "\"FIELD({F}): MAX QUANTITY({Q}) EXCEEDED: {V}\\n{NT}\"", ".", "format", "(", "F", "=", "name", ",", "Q", "=", "qty_max", ",", "V", "=", "vals", ",", "NT", "=", "ntd", ")", ")", ")" ]
Further split a GAF value within a single field.
[ "Further", "split", "a", "GAF", "value", "within", "a", "single", "field", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L215-L226
228,558
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData.prt_line_detail
def prt_line_detail(self, prt, line): """Print line header and values in a readable format.""" values = line.split('\t') self._prt_line_detail(prt, values)
python
def prt_line_detail(self, prt, line): """Print line header and values in a readable format.""" values = line.split('\t') self._prt_line_detail(prt, values)
[ "def", "prt_line_detail", "(", "self", ",", "prt", ",", "line", ")", ":", "values", "=", "line", ".", "split", "(", "'\\t'", ")", "self", ".", "_prt_line_detail", "(", "prt", ",", "values", ")" ]
Print line header and values in a readable format.
[ "Print", "line", "header", "and", "values", "in", "a", "readable", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L236-L239
228,559
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData._prt_line_detail
def _prt_line_detail(self, prt, values, lnum=""): """Print header and field values in a readable format.""" #### data = zip(self.req_str, self.ntgafobj._fields, values) data = zip(self.req_str, self.flds, values) txt = ["{:2}) {:3} {:20} {}".format(i, req, hdr, val) for i, (req, hdr, val) in enumerate(data)] prt.write("{LNUM}\n{TXT}\n".format(LNUM=lnum, TXT="\n".join(txt)))
python
def _prt_line_detail(self, prt, values, lnum=""): """Print header and field values in a readable format.""" #### data = zip(self.req_str, self.ntgafobj._fields, values) data = zip(self.req_str, self.flds, values) txt = ["{:2}) {:3} {:20} {}".format(i, req, hdr, val) for i, (req, hdr, val) in enumerate(data)] prt.write("{LNUM}\n{TXT}\n".format(LNUM=lnum, TXT="\n".join(txt)))
[ "def", "_prt_line_detail", "(", "self", ",", "prt", ",", "values", ",", "lnum", "=", "\"\"", ")", ":", "#### data = zip(self.req_str, self.ntgafobj._fields, values)", "data", "=", "zip", "(", "self", ".", "req_str", ",", "self", ".", "flds", ",", "values", ")", "txt", "=", "[", "\"{:2}) {:3} {:20} {}\"", ".", "format", "(", "i", ",", "req", ",", "hdr", ",", "val", ")", "for", "i", ",", "(", "req", ",", "hdr", ",", "val", ")", "in", "enumerate", "(", "data", ")", "]", "prt", ".", "write", "(", "\"{LNUM}\\n{TXT}\\n\"", ".", "format", "(", "LNUM", "=", "lnum", ",", "TXT", "=", "\"\\n\"", ".", "join", "(", "txt", ")", ")", ")" ]
Print header and field values in a readable format.
[ "Print", "header", "and", "field", "values", "in", "a", "readable", "format", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L241-L246
228,560
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData.prt_error_summary
def prt_error_summary(self, fout_err): """Print a summary about the GAF file that was read.""" # Get summary of error types and their counts errcnts = [] if self.ignored: errcnts.append(" {N:9,} IGNORED associations\n".format(N=len(self.ignored))) if self.illegal_lines: for err_name, errors in self.illegal_lines.items(): errcnts.append(" {N:9,} {ERROR}\n".format(N=len(errors), ERROR=err_name)) # Save error details into a log file fout_log = self._wrlog_details_illegal_gaf(fout_err, errcnts) sys.stdout.write(" WROTE GAF ERROR LOG: {LOG}:\n".format(LOG=fout_log)) for err_cnt in errcnts: sys.stdout.write(err_cnt)
python
def prt_error_summary(self, fout_err): """Print a summary about the GAF file that was read.""" # Get summary of error types and their counts errcnts = [] if self.ignored: errcnts.append(" {N:9,} IGNORED associations\n".format(N=len(self.ignored))) if self.illegal_lines: for err_name, errors in self.illegal_lines.items(): errcnts.append(" {N:9,} {ERROR}\n".format(N=len(errors), ERROR=err_name)) # Save error details into a log file fout_log = self._wrlog_details_illegal_gaf(fout_err, errcnts) sys.stdout.write(" WROTE GAF ERROR LOG: {LOG}:\n".format(LOG=fout_log)) for err_cnt in errcnts: sys.stdout.write(err_cnt)
[ "def", "prt_error_summary", "(", "self", ",", "fout_err", ")", ":", "# Get summary of error types and their counts", "errcnts", "=", "[", "]", "if", "self", ".", "ignored", ":", "errcnts", ".", "append", "(", "\" {N:9,} IGNORED associations\\n\"", ".", "format", "(", "N", "=", "len", "(", "self", ".", "ignored", ")", ")", ")", "if", "self", ".", "illegal_lines", ":", "for", "err_name", ",", "errors", "in", "self", ".", "illegal_lines", ".", "items", "(", ")", ":", "errcnts", ".", "append", "(", "\" {N:9,} {ERROR}\\n\"", ".", "format", "(", "N", "=", "len", "(", "errors", ")", ",", "ERROR", "=", "err_name", ")", ")", "# Save error details into a log file", "fout_log", "=", "self", ".", "_wrlog_details_illegal_gaf", "(", "fout_err", ",", "errcnts", ")", "sys", ".", "stdout", ".", "write", "(", "\" WROTE GAF ERROR LOG: {LOG}:\\n\"", ".", "format", "(", "LOG", "=", "fout_log", ")", ")", "for", "err_cnt", "in", "errcnts", ":", "sys", ".", "stdout", ".", "write", "(", "err_cnt", ")" ]
Print a summary about the GAF file that was read.
[ "Print", "a", "summary", "about", "the", "GAF", "file", "that", "was", "read", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L265-L278
228,561
tanghaibao/goatools
goatools/anno/init/reader_gaf.py
GafData._wrlog_details_illegal_gaf
def _wrlog_details_illegal_gaf(self, fout_err, err_cnts): """Print details regarding illegal GAF lines seen to a log file.""" # fout_err = "{}.log".format(fin_gaf) gaf_base = os.path.basename(fout_err) with open(fout_err, 'w') as prt: prt.write("ILLEGAL GAF ERROR SUMMARY:\n\n") for err_cnt in err_cnts: prt.write(err_cnt) prt.write("\n\nILLEGAL GAF ERROR DETAILS:\n\n") for lnum, line in self.ignored: prt.write("**WARNING: GAF LINE IGNORED: {FIN}[{LNUM}]:\n{L}\n".format( FIN=gaf_base, L=line, LNUM=lnum)) self.prt_line_detail(prt, line) prt.write("\n\n") for error, lines in self.illegal_lines.items(): for lnum, line in lines: prt.write("**WARNING: GAF LINE ILLEGAL({ERR}): {FIN}[{LNUM}]:\n{L}\n".format( ERR=error, FIN=gaf_base, L=line, LNUM=lnum)) self.prt_line_detail(prt, line) prt.write("\n\n") return fout_err
python
def _wrlog_details_illegal_gaf(self, fout_err, err_cnts): """Print details regarding illegal GAF lines seen to a log file.""" # fout_err = "{}.log".format(fin_gaf) gaf_base = os.path.basename(fout_err) with open(fout_err, 'w') as prt: prt.write("ILLEGAL GAF ERROR SUMMARY:\n\n") for err_cnt in err_cnts: prt.write(err_cnt) prt.write("\n\nILLEGAL GAF ERROR DETAILS:\n\n") for lnum, line in self.ignored: prt.write("**WARNING: GAF LINE IGNORED: {FIN}[{LNUM}]:\n{L}\n".format( FIN=gaf_base, L=line, LNUM=lnum)) self.prt_line_detail(prt, line) prt.write("\n\n") for error, lines in self.illegal_lines.items(): for lnum, line in lines: prt.write("**WARNING: GAF LINE ILLEGAL({ERR}): {FIN}[{LNUM}]:\n{L}\n".format( ERR=error, FIN=gaf_base, L=line, LNUM=lnum)) self.prt_line_detail(prt, line) prt.write("\n\n") return fout_err
[ "def", "_wrlog_details_illegal_gaf", "(", "self", ",", "fout_err", ",", "err_cnts", ")", ":", "# fout_err = \"{}.log\".format(fin_gaf)", "gaf_base", "=", "os", ".", "path", ".", "basename", "(", "fout_err", ")", "with", "open", "(", "fout_err", ",", "'w'", ")", "as", "prt", ":", "prt", ".", "write", "(", "\"ILLEGAL GAF ERROR SUMMARY:\\n\\n\"", ")", "for", "err_cnt", "in", "err_cnts", ":", "prt", ".", "write", "(", "err_cnt", ")", "prt", ".", "write", "(", "\"\\n\\nILLEGAL GAF ERROR DETAILS:\\n\\n\"", ")", "for", "lnum", ",", "line", "in", "self", ".", "ignored", ":", "prt", ".", "write", "(", "\"**WARNING: GAF LINE IGNORED: {FIN}[{LNUM}]:\\n{L}\\n\"", ".", "format", "(", "FIN", "=", "gaf_base", ",", "L", "=", "line", ",", "LNUM", "=", "lnum", ")", ")", "self", ".", "prt_line_detail", "(", "prt", ",", "line", ")", "prt", ".", "write", "(", "\"\\n\\n\"", ")", "for", "error", ",", "lines", "in", "self", ".", "illegal_lines", ".", "items", "(", ")", ":", "for", "lnum", ",", "line", "in", "lines", ":", "prt", ".", "write", "(", "\"**WARNING: GAF LINE ILLEGAL({ERR}): {FIN}[{LNUM}]:\\n{L}\\n\"", ".", "format", "(", "ERR", "=", "error", ",", "FIN", "=", "gaf_base", ",", "L", "=", "line", ",", "LNUM", "=", "lnum", ")", ")", "self", ".", "prt_line_detail", "(", "prt", ",", "line", ")", "prt", ".", "write", "(", "\"\\n\\n\"", ")", "return", "fout_err" ]
Print details regarding illegal GAF lines seen to a log file.
[ "Print", "details", "regarding", "illegal", "GAF", "lines", "seen", "to", "a", "log", "file", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/init/reader_gaf.py#L280-L300
228,562
tanghaibao/goatools
goatools/gosubdag/godag_rcnt_init.py
CountRelativesInit.get_relationship_dicts
def get_relationship_dicts(self): """Given GO DAG relationships, return summaries per GO ID.""" if not self.relationships: return None for goid, goobj in self.go2obj.items(): for reltyp, relset in goobj.relationship.items(): relfwd_goids = set(o.id for o in relset) # for relfwd_goid in relfwd_goids: # assert relfwd_goid in self.go2obj, "{GO} {REL} NOT FOUND {GO_R}".format( # GO=goid, REL=reltyp, GO_R=relfwd_goid) print("CountRelativesInit RELLLLS", goid, goobj.id, reltyp, relfwd_goids)
python
def get_relationship_dicts(self): """Given GO DAG relationships, return summaries per GO ID.""" if not self.relationships: return None for goid, goobj in self.go2obj.items(): for reltyp, relset in goobj.relationship.items(): relfwd_goids = set(o.id for o in relset) # for relfwd_goid in relfwd_goids: # assert relfwd_goid in self.go2obj, "{GO} {REL} NOT FOUND {GO_R}".format( # GO=goid, REL=reltyp, GO_R=relfwd_goid) print("CountRelativesInit RELLLLS", goid, goobj.id, reltyp, relfwd_goids)
[ "def", "get_relationship_dicts", "(", "self", ")", ":", "if", "not", "self", ".", "relationships", ":", "return", "None", "for", "goid", ",", "goobj", "in", "self", ".", "go2obj", ".", "items", "(", ")", ":", "for", "reltyp", ",", "relset", "in", "goobj", ".", "relationship", ".", "items", "(", ")", ":", "relfwd_goids", "=", "set", "(", "o", ".", "id", "for", "o", "in", "relset", ")", "# for relfwd_goid in relfwd_goids:", "# assert relfwd_goid in self.go2obj, \"{GO} {REL} NOT FOUND {GO_R}\".format(", "# GO=goid, REL=reltyp, GO_R=relfwd_goid)", "print", "(", "\"CountRelativesInit RELLLLS\"", ",", "goid", ",", "goobj", ".", "id", ",", "reltyp", ",", "relfwd_goids", ")" ]
Given GO DAG relationships, return summaries per GO ID.
[ "Given", "GO", "DAG", "relationships", "return", "summaries", "per", "GO", "ID", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/godag_rcnt_init.py#L38-L48
228,563
tanghaibao/goatools
goatools/gosubdag/godag_rcnt_init.py
CountRelativesInit.get_goone2ntletter
def get_goone2ntletter(self, go2dcnt, depth2goobjs): """Assign letters to depth-01 GO terms ordered using descendants cnt.""" # 1. Group level-01/depth-01 GO terms by namespace ns2dcntgoobj = cx.defaultdict(list) for goobj in depth2goobjs[1]: dcnt = go2dcnt[goobj.id] ns2dcntgoobj[goobj.namespace].append((dcnt, goobj)) # 2. Assign letters to level-01/depth-01 GO terms go2nt = {} ntobj = cx.namedtuple("NtGoLetters", "D1 dcnt goobj") _go2abc = self.go2letter letters = list(chain(range(ord('A'), ord('Z') + 1), range(ord('a'), ord('z') + 1))) for list_dcnt_goobj in ns2dcntgoobj.values(): letter_idx = 0 for dcnt, goobj in sorted(list_dcnt_goobj, key=lambda t: t[0], reverse=True): letter = chr(letters[letter_idx]) if _go2abc is None else _go2abc.get(goobj.id, '') go2nt[goobj.id] = ntobj._make([letter, dcnt, goobj]) letter_idx += 1 return go2nt
python
def get_goone2ntletter(self, go2dcnt, depth2goobjs): """Assign letters to depth-01 GO terms ordered using descendants cnt.""" # 1. Group level-01/depth-01 GO terms by namespace ns2dcntgoobj = cx.defaultdict(list) for goobj in depth2goobjs[1]: dcnt = go2dcnt[goobj.id] ns2dcntgoobj[goobj.namespace].append((dcnt, goobj)) # 2. Assign letters to level-01/depth-01 GO terms go2nt = {} ntobj = cx.namedtuple("NtGoLetters", "D1 dcnt goobj") _go2abc = self.go2letter letters = list(chain(range(ord('A'), ord('Z') + 1), range(ord('a'), ord('z') + 1))) for list_dcnt_goobj in ns2dcntgoobj.values(): letter_idx = 0 for dcnt, goobj in sorted(list_dcnt_goobj, key=lambda t: t[0], reverse=True): letter = chr(letters[letter_idx]) if _go2abc is None else _go2abc.get(goobj.id, '') go2nt[goobj.id] = ntobj._make([letter, dcnt, goobj]) letter_idx += 1 return go2nt
[ "def", "get_goone2ntletter", "(", "self", ",", "go2dcnt", ",", "depth2goobjs", ")", ":", "# 1. Group level-01/depth-01 GO terms by namespace", "ns2dcntgoobj", "=", "cx", ".", "defaultdict", "(", "list", ")", "for", "goobj", "in", "depth2goobjs", "[", "1", "]", ":", "dcnt", "=", "go2dcnt", "[", "goobj", ".", "id", "]", "ns2dcntgoobj", "[", "goobj", ".", "namespace", "]", ".", "append", "(", "(", "dcnt", ",", "goobj", ")", ")", "# 2. Assign letters to level-01/depth-01 GO terms", "go2nt", "=", "{", "}", "ntobj", "=", "cx", ".", "namedtuple", "(", "\"NtGoLetters\"", ",", "\"D1 dcnt goobj\"", ")", "_go2abc", "=", "self", ".", "go2letter", "letters", "=", "list", "(", "chain", "(", "range", "(", "ord", "(", "'A'", ")", ",", "ord", "(", "'Z'", ")", "+", "1", ")", ",", "range", "(", "ord", "(", "'a'", ")", ",", "ord", "(", "'z'", ")", "+", "1", ")", ")", ")", "for", "list_dcnt_goobj", "in", "ns2dcntgoobj", ".", "values", "(", ")", ":", "letter_idx", "=", "0", "for", "dcnt", ",", "goobj", "in", "sorted", "(", "list_dcnt_goobj", ",", "key", "=", "lambda", "t", ":", "t", "[", "0", "]", ",", "reverse", "=", "True", ")", ":", "letter", "=", "chr", "(", "letters", "[", "letter_idx", "]", ")", "if", "_go2abc", "is", "None", "else", "_go2abc", ".", "get", "(", "goobj", ".", "id", ",", "''", ")", "go2nt", "[", "goobj", ".", "id", "]", "=", "ntobj", ".", "_make", "(", "[", "letter", ",", "dcnt", ",", "goobj", "]", ")", "letter_idx", "+=", "1", "return", "go2nt" ]
Assign letters to depth-01 GO terms ordered using descendants cnt.
[ "Assign", "letters", "to", "depth", "-", "01", "GO", "terms", "ordered", "using", "descendants", "cnt", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/godag_rcnt_init.py#L50-L68
228,564
tanghaibao/goatools
goatools/grouper/grprdflts.py
GrouperDflts._init_goslims
def _init_goslims(self, dagslim): """Get GO IDs in GO slims.""" go2obj_main = self.gosubdag.go2obj go2obj_slim = {go for go, o in dagslim.items() if go in go2obj_main} if self.gosubdag.relationships: return self._get_goslimids_norel(go2obj_slim) return set(dagslim.keys())
python
def _init_goslims(self, dagslim): """Get GO IDs in GO slims.""" go2obj_main = self.gosubdag.go2obj go2obj_slim = {go for go, o in dagslim.items() if go in go2obj_main} if self.gosubdag.relationships: return self._get_goslimids_norel(go2obj_slim) return set(dagslim.keys())
[ "def", "_init_goslims", "(", "self", ",", "dagslim", ")", ":", "go2obj_main", "=", "self", ".", "gosubdag", ".", "go2obj", "go2obj_slim", "=", "{", "go", "for", "go", ",", "o", "in", "dagslim", ".", "items", "(", ")", "if", "go", "in", "go2obj_main", "}", "if", "self", ".", "gosubdag", ".", "relationships", ":", "return", "self", ".", "_get_goslimids_norel", "(", "go2obj_slim", ")", "return", "set", "(", "dagslim", ".", "keys", "(", ")", ")" ]
Get GO IDs in GO slims.
[ "Get", "GO", "IDs", "in", "GO", "slims", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprdflts.py#L48-L54
228,565
tanghaibao/goatools
goatools/grouper/grprdflts.py
GrouperDflts._get_goslimids_norel
def _get_goslimids_norel(self, dagslim): """Get all GO slim GO IDs that do not have a relationship.""" go_slims = set() go2obj = self.gosubdag.go2obj for goid in dagslim: goobj = go2obj[goid] if not goobj.relationship: go_slims.add(goobj.id) return go_slims
python
def _get_goslimids_norel(self, dagslim): """Get all GO slim GO IDs that do not have a relationship.""" go_slims = set() go2obj = self.gosubdag.go2obj for goid in dagslim: goobj = go2obj[goid] if not goobj.relationship: go_slims.add(goobj.id) return go_slims
[ "def", "_get_goslimids_norel", "(", "self", ",", "dagslim", ")", ":", "go_slims", "=", "set", "(", ")", "go2obj", "=", "self", ".", "gosubdag", ".", "go2obj", "for", "goid", "in", "dagslim", ":", "goobj", "=", "go2obj", "[", "goid", "]", "if", "not", "goobj", ".", "relationship", ":", "go_slims", ".", "add", "(", "goobj", ".", "id", ")", "return", "go_slims" ]
Get all GO slim GO IDs that do not have a relationship.
[ "Get", "all", "GO", "slim", "GO", "IDs", "that", "do", "not", "have", "a", "relationship", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprdflts.py#L60-L68
228,566
tanghaibao/goatools
goatools/grouper/grprdflts.py
GrouperDflts.get_gosubdag
def get_gosubdag(gosubdag=None): """Gets a GoSubDag initialized for use by a Grouper object.""" if gosubdag is not None: if gosubdag.rcntobj is not None: return gosubdag else: gosubdag.init_auxobjs() return gosubdag else: go2obj = get_godag() return GoSubDag(None, go2obj, rcntobj=True)
python
def get_gosubdag(gosubdag=None): """Gets a GoSubDag initialized for use by a Grouper object.""" if gosubdag is not None: if gosubdag.rcntobj is not None: return gosubdag else: gosubdag.init_auxobjs() return gosubdag else: go2obj = get_godag() return GoSubDag(None, go2obj, rcntobj=True)
[ "def", "get_gosubdag", "(", "gosubdag", "=", "None", ")", ":", "if", "gosubdag", "is", "not", "None", ":", "if", "gosubdag", ".", "rcntobj", "is", "not", "None", ":", "return", "gosubdag", "else", ":", "gosubdag", ".", "init_auxobjs", "(", ")", "return", "gosubdag", "else", ":", "go2obj", "=", "get_godag", "(", ")", "return", "GoSubDag", "(", "None", ",", "go2obj", ",", "rcntobj", "=", "True", ")" ]
Gets a GoSubDag initialized for use by a Grouper object.
[ "Gets", "a", "GoSubDag", "initialized", "for", "use", "by", "a", "Grouper", "object", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprdflts.py#L71-L81
228,567
tanghaibao/goatools
goatools/anno/opts.py
AnnoOptions.getfnc_qual_ev
def getfnc_qual_ev(self): """Keep annotaion if it passes potentially modified selection.""" fnc_key = ( self.nd_not2desc[(self._keep_nd, self._keep_not)], self.incexc2num[( self.include_evcodes is not None, self.exclude_evcodes is not None)], ) return self.param2fnc[fnc_key]
python
def getfnc_qual_ev(self): """Keep annotaion if it passes potentially modified selection.""" fnc_key = ( self.nd_not2desc[(self._keep_nd, self._keep_not)], self.incexc2num[( self.include_evcodes is not None, self.exclude_evcodes is not None)], ) return self.param2fnc[fnc_key]
[ "def", "getfnc_qual_ev", "(", "self", ")", ":", "fnc_key", "=", "(", "self", ".", "nd_not2desc", "[", "(", "self", ".", "_keep_nd", ",", "self", ".", "_keep_not", ")", "]", ",", "self", ".", "incexc2num", "[", "(", "self", ".", "include_evcodes", "is", "not", "None", ",", "self", ".", "exclude_evcodes", "is", "not", "None", ")", "]", ",", ")", "return", "self", ".", "param2fnc", "[", "fnc_key", "]" ]
Keep annotaion if it passes potentially modified selection.
[ "Keep", "annotaion", "if", "it", "passes", "potentially", "modified", "selection", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/opts.py#L65-L73
228,568
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNodeOpts.get_kws
def get_kws(self): """Only load keywords if they are specified by the user.""" ret = self.kws['dict'].copy() act_set = self.kws['set'] if 'shorten' in act_set and 'goobj2fncname' not in ret: ret['goobj2fncname'] = ShortenText().get_short_plot_name return ret
python
def get_kws(self): """Only load keywords if they are specified by the user.""" ret = self.kws['dict'].copy() act_set = self.kws['set'] if 'shorten' in act_set and 'goobj2fncname' not in ret: ret['goobj2fncname'] = ShortenText().get_short_plot_name return ret
[ "def", "get_kws", "(", "self", ")", ":", "ret", "=", "self", ".", "kws", "[", "'dict'", "]", ".", "copy", "(", ")", "act_set", "=", "self", ".", "kws", "[", "'set'", "]", "if", "'shorten'", "in", "act_set", "and", "'goobj2fncname'", "not", "in", "ret", ":", "ret", "[", "'goobj2fncname'", "]", "=", "ShortenText", "(", ")", ".", "get_short_plot_name", "return", "ret" ]
Only load keywords if they are specified by the user.
[ "Only", "load", "keywords", "if", "they", "are", "specified", "by", "the", "user", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L32-L38
228,569
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode.get_node
def get_node(self, goid, goobj): """Return pydot node.""" # pydot.Node.objdict holds this information. pydot.Node.objdict['name'] return pydot.Node( self.get_node_text(goid, goobj), shape="box", style="rounded, filled", fillcolor=self.go2color.get(goid, "white"), color=self.objcolor.get_bordercolor(goid))
python
def get_node(self, goid, goobj): """Return pydot node.""" # pydot.Node.objdict holds this information. pydot.Node.objdict['name'] return pydot.Node( self.get_node_text(goid, goobj), shape="box", style="rounded, filled", fillcolor=self.go2color.get(goid, "white"), color=self.objcolor.get_bordercolor(goid))
[ "def", "get_node", "(", "self", ",", "goid", ",", "goobj", ")", ":", "# pydot.Node.objdict holds this information. pydot.Node.objdict['name']", "return", "pydot", ".", "Node", "(", "self", ".", "get_node_text", "(", "goid", ",", "goobj", ")", ",", "shape", "=", "\"box\"", ",", "style", "=", "\"rounded, filled\"", ",", "fillcolor", "=", "self", ".", "go2color", ".", "get", "(", "goid", ",", "\"white\"", ")", ",", "color", "=", "self", ".", "objcolor", ".", "get_bordercolor", "(", "goid", ")", ")" ]
Return pydot node.
[ "Return", "pydot", "node", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L56-L64
228,570
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode.str_fmthdr
def str_fmthdr(self, goid, goobj): """Return hdr line seen inside a GO Term box.""" # Shorten: Ex: GO:0007608 -> G0007608 go_txt = goid.replace("GO:", "G") if 'mark_alt_id' in self.present and goid != goobj.id: go_txt += 'a' return go_txt
python
def str_fmthdr(self, goid, goobj): """Return hdr line seen inside a GO Term box.""" # Shorten: Ex: GO:0007608 -> G0007608 go_txt = goid.replace("GO:", "G") if 'mark_alt_id' in self.present and goid != goobj.id: go_txt += 'a' return go_txt
[ "def", "str_fmthdr", "(", "self", ",", "goid", ",", "goobj", ")", ":", "# Shorten: Ex: GO:0007608 -> G0007608", "go_txt", "=", "goid", ".", "replace", "(", "\"GO:\"", ",", "\"G\"", ")", "if", "'mark_alt_id'", "in", "self", ".", "present", "and", "goid", "!=", "goobj", ".", "id", ":", "go_txt", "+=", "'a'", "return", "go_txt" ]
Return hdr line seen inside a GO Term box.
[ "Return", "hdr", "line", "seen", "inside", "a", "GO", "Term", "box", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L66-L72
228,571
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode._get_prtflds
def _get_prtflds(self): """Get print fields for GO header.""" # User-specified print fields ntflds = self.gosubdag.prt_attr['flds'] prt_flds = self.kws.get('prt_flds') if prt_flds: return prt_flds.intersection(ntflds) exclude = set() # Default print fields if self.gosubdag.relationships: exclude.add('level') return set(f for f in ntflds if f not in exclude)
python
def _get_prtflds(self): """Get print fields for GO header.""" # User-specified print fields ntflds = self.gosubdag.prt_attr['flds'] prt_flds = self.kws.get('prt_flds') if prt_flds: return prt_flds.intersection(ntflds) exclude = set() # Default print fields if self.gosubdag.relationships: exclude.add('level') return set(f for f in ntflds if f not in exclude)
[ "def", "_get_prtflds", "(", "self", ")", ":", "# User-specified print fields", "ntflds", "=", "self", ".", "gosubdag", ".", "prt_attr", "[", "'flds'", "]", "prt_flds", "=", "self", ".", "kws", ".", "get", "(", "'prt_flds'", ")", "if", "prt_flds", ":", "return", "prt_flds", ".", "intersection", "(", "ntflds", ")", "exclude", "=", "set", "(", ")", "# Default print fields", "if", "self", ".", "gosubdag", ".", "relationships", ":", "exclude", ".", "add", "(", "'level'", ")", "return", "set", "(", "f", "for", "f", "in", "ntflds", "if", "f", "not", "in", "exclude", ")" ]
Get print fields for GO header.
[ "Get", "print", "fields", "for", "GO", "header", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L132-L143
228,572
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode._get_hdr_childcnt
def _get_hdr_childcnt(self, goobj, ntgo): """Get string representing count of children for this GO term.""" if 'childcnt' in self.present: return "c{N}".format(N=len(goobj.children)) elif self.gosubdag.relationships and not goobj.children and ntgo.dcnt != 0: return "c0"
python
def _get_hdr_childcnt(self, goobj, ntgo): """Get string representing count of children for this GO term.""" if 'childcnt' in self.present: return "c{N}".format(N=len(goobj.children)) elif self.gosubdag.relationships and not goobj.children and ntgo.dcnt != 0: return "c0"
[ "def", "_get_hdr_childcnt", "(", "self", ",", "goobj", ",", "ntgo", ")", ":", "if", "'childcnt'", "in", "self", ".", "present", ":", "return", "\"c{N}\"", ".", "format", "(", "N", "=", "len", "(", "goobj", ".", "children", ")", ")", "elif", "self", ".", "gosubdag", ".", "relationships", "and", "not", "goobj", ".", "children", "and", "ntgo", ".", "dcnt", "!=", "0", ":", "return", "\"c0\"" ]
Get string representing count of children for this GO term.
[ "Get", "string", "representing", "count", "of", "children", "for", "this", "GO", "term", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L145-L150
228,573
tanghaibao/goatools
goatools/gosubdag/plot/go_node.py
GoNode._add_parent_cnt
def _add_parent_cnt(self, hdr, goobj, c2ps): """Add the parent count to the GO term box for if not all parents are plotted.""" if goobj.id in c2ps: parents = c2ps[goobj.id] if 'prt_pcnt' in self.present or parents and len(goobj.parents) != len(parents): assert len(goobj.parents) == len(set(goobj.parents)) hdr.append("p{N}".format(N=len(set(goobj.parents))))
python
def _add_parent_cnt(self, hdr, goobj, c2ps): """Add the parent count to the GO term box for if not all parents are plotted.""" if goobj.id in c2ps: parents = c2ps[goobj.id] if 'prt_pcnt' in self.present or parents and len(goobj.parents) != len(parents): assert len(goobj.parents) == len(set(goobj.parents)) hdr.append("p{N}".format(N=len(set(goobj.parents))))
[ "def", "_add_parent_cnt", "(", "self", ",", "hdr", ",", "goobj", ",", "c2ps", ")", ":", "if", "goobj", ".", "id", "in", "c2ps", ":", "parents", "=", "c2ps", "[", "goobj", ".", "id", "]", "if", "'prt_pcnt'", "in", "self", ".", "present", "or", "parents", "and", "len", "(", "goobj", ".", "parents", ")", "!=", "len", "(", "parents", ")", ":", "assert", "len", "(", "goobj", ".", "parents", ")", "==", "len", "(", "set", "(", "goobj", ".", "parents", ")", ")", "hdr", ".", "append", "(", "\"p{N}\"", ".", "format", "(", "N", "=", "len", "(", "set", "(", "goobj", ".", "parents", ")", ")", ")", ")" ]
Add the parent count to the GO term box for if not all parents are plotted.
[ "Add", "the", "parent", "count", "to", "the", "GO", "term", "box", "for", "if", "not", "all", "parents", "are", "plotted", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/gosubdag/plot/go_node.py#L152-L158
228,574
tanghaibao/goatools
goatools/anno/idtogos_reader.py
IdToGosReader.prt_summary_anno2ev
def prt_summary_anno2ev(self, prt=sys.stdout): """Print a summary of all Evidence Codes seen in annotations""" prt.write('**NOTE: No evidence codes in associations: {F}\n'.format(F=self.filename))
python
def prt_summary_anno2ev(self, prt=sys.stdout): """Print a summary of all Evidence Codes seen in annotations""" prt.write('**NOTE: No evidence codes in associations: {F}\n'.format(F=self.filename))
[ "def", "prt_summary_anno2ev", "(", "self", ",", "prt", "=", "sys", ".", "stdout", ")", ":", "prt", ".", "write", "(", "'**NOTE: No evidence codes in associations: {F}\\n'", ".", "format", "(", "F", "=", "self", ".", "filename", ")", ")" ]
Print a summary of all Evidence Codes seen in annotations
[ "Print", "a", "summary", "of", "all", "Evidence", "Codes", "seen", "in", "annotations" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/anno/idtogos_reader.py#L21-L23
228,575
tanghaibao/goatools
goatools/ratio.py
count_terms
def count_terms(geneset, assoc, obo_dag): """count the number of terms in the study group """ term_cnt = Counter() for gene in (g for g in geneset if g in assoc): for goid in assoc[gene]: if goid in obo_dag: term_cnt[obo_dag[goid].id] += 1 return term_cnt
python
def count_terms(geneset, assoc, obo_dag): """count the number of terms in the study group """ term_cnt = Counter() for gene in (g for g in geneset if g in assoc): for goid in assoc[gene]: if goid in obo_dag: term_cnt[obo_dag[goid].id] += 1 return term_cnt
[ "def", "count_terms", "(", "geneset", ",", "assoc", ",", "obo_dag", ")", ":", "term_cnt", "=", "Counter", "(", ")", "for", "gene", "in", "(", "g", "for", "g", "in", "geneset", "if", "g", "in", "assoc", ")", ":", "for", "goid", "in", "assoc", "[", "gene", "]", ":", "if", "goid", "in", "obo_dag", ":", "term_cnt", "[", "obo_dag", "[", "goid", "]", ".", "id", "]", "+=", "1", "return", "term_cnt" ]
count the number of terms in the study group
[ "count", "the", "number", "of", "terms", "in", "the", "study", "group" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/ratio.py#L10-L19
228,576
tanghaibao/goatools
goatools/ratio.py
get_terms
def get_terms(desc, geneset, assoc, obo_dag, log): """Get the terms in the study group """ _chk_gene2go(assoc) term2itemids = defaultdict(set) genes = [g for g in geneset if g in assoc] for gene in genes: for goid in assoc[gene]: if goid in obo_dag: term2itemids[obo_dag[goid].id].add(gene) if log is not None: num_stu = len(genes) num_pop = len(geneset) perc = 100.0*num_stu/num_pop if num_pop != 0 else 0.0 log.write("{P:3.0f}% {N:>6,} of {M:>6,} {DESC} items found in association\n".format( DESC=desc, N=num_stu, M=num_pop, P=perc)) return term2itemids
python
def get_terms(desc, geneset, assoc, obo_dag, log): """Get the terms in the study group """ _chk_gene2go(assoc) term2itemids = defaultdict(set) genes = [g for g in geneset if g in assoc] for gene in genes: for goid in assoc[gene]: if goid in obo_dag: term2itemids[obo_dag[goid].id].add(gene) if log is not None: num_stu = len(genes) num_pop = len(geneset) perc = 100.0*num_stu/num_pop if num_pop != 0 else 0.0 log.write("{P:3.0f}% {N:>6,} of {M:>6,} {DESC} items found in association\n".format( DESC=desc, N=num_stu, M=num_pop, P=perc)) return term2itemids
[ "def", "get_terms", "(", "desc", ",", "geneset", ",", "assoc", ",", "obo_dag", ",", "log", ")", ":", "_chk_gene2go", "(", "assoc", ")", "term2itemids", "=", "defaultdict", "(", "set", ")", "genes", "=", "[", "g", "for", "g", "in", "geneset", "if", "g", "in", "assoc", "]", "for", "gene", "in", "genes", ":", "for", "goid", "in", "assoc", "[", "gene", "]", ":", "if", "goid", "in", "obo_dag", ":", "term2itemids", "[", "obo_dag", "[", "goid", "]", ".", "id", "]", ".", "add", "(", "gene", ")", "if", "log", "is", "not", "None", ":", "num_stu", "=", "len", "(", "genes", ")", "num_pop", "=", "len", "(", "geneset", ")", "perc", "=", "100.0", "*", "num_stu", "/", "num_pop", "if", "num_pop", "!=", "0", "else", "0.0", "log", ".", "write", "(", "\"{P:3.0f}% {N:>6,} of {M:>6,} {DESC} items found in association\\n\"", ".", "format", "(", "DESC", "=", "desc", ",", "N", "=", "num_stu", ",", "M", "=", "num_pop", ",", "P", "=", "perc", ")", ")", "return", "term2itemids" ]
Get the terms in the study group
[ "Get", "the", "terms", "in", "the", "study", "group" ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/ratio.py#L21-L37
228,577
tanghaibao/goatools
goatools/ratio.py
_chk_gene2go
def _chk_gene2go(assoc): """Check that associations is gene2go, not go2gene.""" if not assoc: raise RuntimeError("NO ITEMS FOUND IN ASSOCIATIONS {A}".format(A=assoc)) for key in assoc: if isinstance(key, str) and key[:3] == "GO:": raise Exception("ASSOCIATIONS EXPECTED TO BE gene2go, NOT go2gene: {EX}".format( EX=assoc.items()[:2])) return
python
def _chk_gene2go(assoc): """Check that associations is gene2go, not go2gene.""" if not assoc: raise RuntimeError("NO ITEMS FOUND IN ASSOCIATIONS {A}".format(A=assoc)) for key in assoc: if isinstance(key, str) and key[:3] == "GO:": raise Exception("ASSOCIATIONS EXPECTED TO BE gene2go, NOT go2gene: {EX}".format( EX=assoc.items()[:2])) return
[ "def", "_chk_gene2go", "(", "assoc", ")", ":", "if", "not", "assoc", ":", "raise", "RuntimeError", "(", "\"NO ITEMS FOUND IN ASSOCIATIONS {A}\"", ".", "format", "(", "A", "=", "assoc", ")", ")", "for", "key", "in", "assoc", ":", "if", "isinstance", "(", "key", ",", "str", ")", "and", "key", "[", ":", "3", "]", "==", "\"GO:\"", ":", "raise", "Exception", "(", "\"ASSOCIATIONS EXPECTED TO BE gene2go, NOT go2gene: {EX}\"", ".", "format", "(", "EX", "=", "assoc", ".", "items", "(", ")", "[", ":", "2", "]", ")", ")", "return" ]
Check that associations is gene2go, not go2gene.
[ "Check", "that", "associations", "is", "gene2go", "not", "go2gene", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/ratio.py#L56-L64
228,578
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit._init_usrgos
def _init_usrgos(self, goids): """Return user GO IDs which have GO Terms.""" usrgos = set() goids_missing = set() _go2obj = self.gosubdag.go2obj for goid in goids: if goid in _go2obj: usrgos.add(goid) else: goids_missing.add(goid) if goids_missing: print("MISSING GO IDs: {GOs}".format(GOs=goids_missing)) print("{N} of {M} GO IDs ARE MISSING".format(N=len(goids_missing), M=len(goids))) return usrgos
python
def _init_usrgos(self, goids): """Return user GO IDs which have GO Terms.""" usrgos = set() goids_missing = set() _go2obj = self.gosubdag.go2obj for goid in goids: if goid in _go2obj: usrgos.add(goid) else: goids_missing.add(goid) if goids_missing: print("MISSING GO IDs: {GOs}".format(GOs=goids_missing)) print("{N} of {M} GO IDs ARE MISSING".format(N=len(goids_missing), M=len(goids))) return usrgos
[ "def", "_init_usrgos", "(", "self", ",", "goids", ")", ":", "usrgos", "=", "set", "(", ")", "goids_missing", "=", "set", "(", ")", "_go2obj", "=", "self", ".", "gosubdag", ".", "go2obj", "for", "goid", "in", "goids", ":", "if", "goid", "in", "_go2obj", ":", "usrgos", ".", "add", "(", "goid", ")", "else", ":", "goids_missing", ".", "add", "(", "goid", ")", "if", "goids_missing", ":", "print", "(", "\"MISSING GO IDs: {GOs}\"", ".", "format", "(", "GOs", "=", "goids_missing", ")", ")", "print", "(", "\"{N} of {M} GO IDs ARE MISSING\"", ".", "format", "(", "N", "=", "len", "(", "goids_missing", ")", ",", "M", "=", "len", "(", "goids", ")", ")", ")", "return", "usrgos" ]
Return user GO IDs which have GO Terms.
[ "Return", "user", "GO", "IDs", "which", "have", "GO", "Terms", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L49-L62
228,579
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit.get_gos_all
def get_gos_all(self): """Return a flat list of all GO IDs in grouping object. All GO IDs: * header GO IDs that are not user GO IDs * user GO IDs that are under header GOs * user GO IDs that are header GOs in groups containing no other user GO IDs """ gos_all = set() # Get: # * Header GO IDs that are not user GO IDs # * User GO IDs that are under header GOs for hdrgo, usrgos in self.hdrgo2usrgos.items(): gos_all.add(hdrgo) gos_all |= usrgos # User GO IDs that are header GOs in groups containing no other user GO IDs gos_all |= self.hdrgo_is_usrgo assert gos_all == self.usrgos.union(set(self.hdrgo2usrgos.keys())) assert len(self.usrgos.difference(gos_all)) == 0, \ "GROUPER ERROR: {GOs}".format(GOs=self.usrgos.difference(gos_all)) return gos_all
python
def get_gos_all(self): """Return a flat list of all GO IDs in grouping object. All GO IDs: * header GO IDs that are not user GO IDs * user GO IDs that are under header GOs * user GO IDs that are header GOs in groups containing no other user GO IDs """ gos_all = set() # Get: # * Header GO IDs that are not user GO IDs # * User GO IDs that are under header GOs for hdrgo, usrgos in self.hdrgo2usrgos.items(): gos_all.add(hdrgo) gos_all |= usrgos # User GO IDs that are header GOs in groups containing no other user GO IDs gos_all |= self.hdrgo_is_usrgo assert gos_all == self.usrgos.union(set(self.hdrgo2usrgos.keys())) assert len(self.usrgos.difference(gos_all)) == 0, \ "GROUPER ERROR: {GOs}".format(GOs=self.usrgos.difference(gos_all)) return gos_all
[ "def", "get_gos_all", "(", "self", ")", ":", "gos_all", "=", "set", "(", ")", "# Get:", "# * Header GO IDs that are not user GO IDs", "# * User GO IDs that are under header GOs", "for", "hdrgo", ",", "usrgos", "in", "self", ".", "hdrgo2usrgos", ".", "items", "(", ")", ":", "gos_all", ".", "add", "(", "hdrgo", ")", "gos_all", "|=", "usrgos", "# User GO IDs that are header GOs in groups containing no other user GO IDs", "gos_all", "|=", "self", ".", "hdrgo_is_usrgo", "assert", "gos_all", "==", "self", ".", "usrgos", ".", "union", "(", "set", "(", "self", ".", "hdrgo2usrgos", ".", "keys", "(", ")", ")", ")", "assert", "len", "(", "self", ".", "usrgos", ".", "difference", "(", "gos_all", ")", ")", "==", "0", ",", "\"GROUPER ERROR: {GOs}\"", ".", "format", "(", "GOs", "=", "self", ".", "usrgos", ".", "difference", "(", "gos_all", ")", ")", "return", "gos_all" ]
Return a flat list of all GO IDs in grouping object. All GO IDs: * header GO IDs that are not user GO IDs * user GO IDs that are under header GOs * user GO IDs that are header GOs in groups containing no other user GO IDs
[ "Return", "a", "flat", "list", "of", "all", "GO", "IDs", "in", "grouping", "object", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L64-L84
228,580
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit._init_h2us
def _init_h2us(self, fnc_most_specific): """Given a set of user GO ids, return GO ids grouped under the "GO high" terms. Example of a grouped go list: gos = ['GO:0044464':[ # grp_term: D1 cell part 'GO:0005737', # child: D3 cytoplasm 'GO:0048471', # child: D4 perinuclear region of cytoplasm 'GO:0016020':[ # grp_term: D1 membrane 'GO:0098589', # child: D2 membrane region 'GO:0005886', # child: D2 plasma membrane ] """ # Header GO IDs are main. User GO IDs are as specified by the user hdrgo2usrgos = cx.defaultdict(set) # Contains user GO IDs which are also header GO IDs, plus user main GO if needed hdrgo_is_usrgo = set() _go2nt = self.gosubdag.go2nt objhi = GrouperInit.GetGoidHigh(self.gosubdag, self.hdrobj.hdrgos, self.most_specific_fncs[fnc_most_specific]) for goid_usr in self.usrgos: goid_main = _go2nt[goid_usr].id # Add current GO ID to parents_all in case curr GO ID is a high GO. goid_high = objhi.get_goid_high(goid_main) # Don't add user GO ID if it is also the GO header if goid_main != goid_high: hdrgo2usrgos[goid_high].add(goid_usr) elif goid_high not in hdrgo2usrgos: hdrgo2usrgos[goid_high] = set() if goid_main == goid_high: hdrgo_is_usrgo.add(goid_main) if goid_main != goid_usr: hdrgo_is_usrgo.add(goid_usr) # Initialize data members self.hdrgo2usrgos = hdrgo2usrgos self.hdrgo_is_usrgo = hdrgo_is_usrgo
python
def _init_h2us(self, fnc_most_specific): """Given a set of user GO ids, return GO ids grouped under the "GO high" terms. Example of a grouped go list: gos = ['GO:0044464':[ # grp_term: D1 cell part 'GO:0005737', # child: D3 cytoplasm 'GO:0048471', # child: D4 perinuclear region of cytoplasm 'GO:0016020':[ # grp_term: D1 membrane 'GO:0098589', # child: D2 membrane region 'GO:0005886', # child: D2 plasma membrane ] """ # Header GO IDs are main. User GO IDs are as specified by the user hdrgo2usrgos = cx.defaultdict(set) # Contains user GO IDs which are also header GO IDs, plus user main GO if needed hdrgo_is_usrgo = set() _go2nt = self.gosubdag.go2nt objhi = GrouperInit.GetGoidHigh(self.gosubdag, self.hdrobj.hdrgos, self.most_specific_fncs[fnc_most_specific]) for goid_usr in self.usrgos: goid_main = _go2nt[goid_usr].id # Add current GO ID to parents_all in case curr GO ID is a high GO. goid_high = objhi.get_goid_high(goid_main) # Don't add user GO ID if it is also the GO header if goid_main != goid_high: hdrgo2usrgos[goid_high].add(goid_usr) elif goid_high not in hdrgo2usrgos: hdrgo2usrgos[goid_high] = set() if goid_main == goid_high: hdrgo_is_usrgo.add(goid_main) if goid_main != goid_usr: hdrgo_is_usrgo.add(goid_usr) # Initialize data members self.hdrgo2usrgos = hdrgo2usrgos self.hdrgo_is_usrgo = hdrgo_is_usrgo
[ "def", "_init_h2us", "(", "self", ",", "fnc_most_specific", ")", ":", "# Header GO IDs are main. User GO IDs are as specified by the user", "hdrgo2usrgos", "=", "cx", ".", "defaultdict", "(", "set", ")", "# Contains user GO IDs which are also header GO IDs, plus user main GO if needed", "hdrgo_is_usrgo", "=", "set", "(", ")", "_go2nt", "=", "self", ".", "gosubdag", ".", "go2nt", "objhi", "=", "GrouperInit", ".", "GetGoidHigh", "(", "self", ".", "gosubdag", ",", "self", ".", "hdrobj", ".", "hdrgos", ",", "self", ".", "most_specific_fncs", "[", "fnc_most_specific", "]", ")", "for", "goid_usr", "in", "self", ".", "usrgos", ":", "goid_main", "=", "_go2nt", "[", "goid_usr", "]", ".", "id", "# Add current GO ID to parents_all in case curr GO ID is a high GO.", "goid_high", "=", "objhi", ".", "get_goid_high", "(", "goid_main", ")", "# Don't add user GO ID if it is also the GO header", "if", "goid_main", "!=", "goid_high", ":", "hdrgo2usrgos", "[", "goid_high", "]", ".", "add", "(", "goid_usr", ")", "elif", "goid_high", "not", "in", "hdrgo2usrgos", ":", "hdrgo2usrgos", "[", "goid_high", "]", "=", "set", "(", ")", "if", "goid_main", "==", "goid_high", ":", "hdrgo_is_usrgo", ".", "add", "(", "goid_main", ")", "if", "goid_main", "!=", "goid_usr", ":", "hdrgo_is_usrgo", ".", "add", "(", "goid_usr", ")", "# Initialize data members", "self", ".", "hdrgo2usrgos", "=", "hdrgo2usrgos", "self", ".", "hdrgo_is_usrgo", "=", "hdrgo_is_usrgo" ]
Given a set of user GO ids, return GO ids grouped under the "GO high" terms. Example of a grouped go list: gos = ['GO:0044464':[ # grp_term: D1 cell part 'GO:0005737', # child: D3 cytoplasm 'GO:0048471', # child: D4 perinuclear region of cytoplasm 'GO:0016020':[ # grp_term: D1 membrane 'GO:0098589', # child: D2 membrane region 'GO:0005886', # child: D2 plasma membrane ]
[ "Given", "a", "set", "of", "user", "GO", "ids", "return", "GO", "ids", "grouped", "under", "the", "GO", "high", "terms", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L86-L121
228,581
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit.get_go2nt
def get_go2nt(self, usr_go2nt): """Combine user namedtuple fields, GO object fields, and format_txt.""" gos_all = self.get_gos_all() # Minimum set of namedtuple fields available for use with Sorter on grouped GO IDs prt_flds_all = get_hdridx_flds() + self.gosubdag.prt_attr['flds'] if not usr_go2nt: return self.__init_go2nt_dflt(gos_all, prt_flds_all) usr_nt_flds = next(iter(usr_go2nt.values()))._fields # If user namedtuple already contains all fields available, then return usr_go2nt if len(set(prt_flds_all).difference(usr_nt_flds)) == 0: return self._init_go2nt_aug(usr_go2nt) # Otherwise, combine user fields and default Sorter fields return self.__init_go2nt_w_usr(gos_all, usr_go2nt, prt_flds_all)
python
def get_go2nt(self, usr_go2nt): """Combine user namedtuple fields, GO object fields, and format_txt.""" gos_all = self.get_gos_all() # Minimum set of namedtuple fields available for use with Sorter on grouped GO IDs prt_flds_all = get_hdridx_flds() + self.gosubdag.prt_attr['flds'] if not usr_go2nt: return self.__init_go2nt_dflt(gos_all, prt_flds_all) usr_nt_flds = next(iter(usr_go2nt.values()))._fields # If user namedtuple already contains all fields available, then return usr_go2nt if len(set(prt_flds_all).difference(usr_nt_flds)) == 0: return self._init_go2nt_aug(usr_go2nt) # Otherwise, combine user fields and default Sorter fields return self.__init_go2nt_w_usr(gos_all, usr_go2nt, prt_flds_all)
[ "def", "get_go2nt", "(", "self", ",", "usr_go2nt", ")", ":", "gos_all", "=", "self", ".", "get_gos_all", "(", ")", "# Minimum set of namedtuple fields available for use with Sorter on grouped GO IDs", "prt_flds_all", "=", "get_hdridx_flds", "(", ")", "+", "self", ".", "gosubdag", ".", "prt_attr", "[", "'flds'", "]", "if", "not", "usr_go2nt", ":", "return", "self", ".", "__init_go2nt_dflt", "(", "gos_all", ",", "prt_flds_all", ")", "usr_nt_flds", "=", "next", "(", "iter", "(", "usr_go2nt", ".", "values", "(", ")", ")", ")", ".", "_fields", "# If user namedtuple already contains all fields available, then return usr_go2nt", "if", "len", "(", "set", "(", "prt_flds_all", ")", ".", "difference", "(", "usr_nt_flds", ")", ")", "==", "0", ":", "return", "self", ".", "_init_go2nt_aug", "(", "usr_go2nt", ")", "# Otherwise, combine user fields and default Sorter fields", "return", "self", ".", "__init_go2nt_w_usr", "(", "gos_all", ",", "usr_go2nt", ",", "prt_flds_all", ")" ]
Combine user namedtuple fields, GO object fields, and format_txt.
[ "Combine", "user", "namedtuple", "fields", "GO", "object", "fields", "and", "format_txt", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L143-L155
228,582
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit._init_go2nt_aug
def _init_go2nt_aug(self, go2nt): """Augment go2nt with GO ID key to account for alt GO IDs.""" go2obj = self.gosubdag.go2obj # Get alt GO IDs go2nt_aug = {} # NOW for goid_usr, nt_usr in go2nt.items(): goobj = go2obj[goid_usr] if goobj.alt_ids: alts = set(goobj.alt_ids) alts.add(goobj.id) for goid_alt in alts: if goid_alt not in go2nt: go2nt_aug[goid_alt] = nt_usr # WAS # Add alt GO IDs to go2nt for goid, gont in go2nt_aug.items(): go2nt[goid] = gont return go2nt
python
def _init_go2nt_aug(self, go2nt): """Augment go2nt with GO ID key to account for alt GO IDs.""" go2obj = self.gosubdag.go2obj # Get alt GO IDs go2nt_aug = {} # NOW for goid_usr, nt_usr in go2nt.items(): goobj = go2obj[goid_usr] if goobj.alt_ids: alts = set(goobj.alt_ids) alts.add(goobj.id) for goid_alt in alts: if goid_alt not in go2nt: go2nt_aug[goid_alt] = nt_usr # WAS # Add alt GO IDs to go2nt for goid, gont in go2nt_aug.items(): go2nt[goid] = gont return go2nt
[ "def", "_init_go2nt_aug", "(", "self", ",", "go2nt", ")", ":", "go2obj", "=", "self", ".", "gosubdag", ".", "go2obj", "# Get alt GO IDs", "go2nt_aug", "=", "{", "}", "# NOW", "for", "goid_usr", ",", "nt_usr", "in", "go2nt", ".", "items", "(", ")", ":", "goobj", "=", "go2obj", "[", "goid_usr", "]", "if", "goobj", ".", "alt_ids", ":", "alts", "=", "set", "(", "goobj", ".", "alt_ids", ")", "alts", ".", "add", "(", "goobj", ".", "id", ")", "for", "goid_alt", "in", "alts", ":", "if", "goid_alt", "not", "in", "go2nt", ":", "go2nt_aug", "[", "goid_alt", "]", "=", "nt_usr", "# WAS", "# Add alt GO IDs to go2nt", "for", "goid", ",", "gont", "in", "go2nt_aug", ".", "items", "(", ")", ":", "go2nt", "[", "goid", "]", "=", "gont", "return", "go2nt" ]
Augment go2nt with GO ID key to account for alt GO IDs.
[ "Augment", "go2nt", "with", "GO", "ID", "key", "to", "account", "for", "alt", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L173-L191
228,583
tanghaibao/goatools
goatools/grouper/grprobj_init.py
GrouperInit._get_go2nthdridx
def _get_go2nthdridx(self, gos_all): """Get GO IDs header index for each user GO ID and corresponding parent GO IDs.""" go2nthdridx = {} # NtHdrIdx Namedtuple fields: # * format_txt: Used to determine the format when writing Excel cells # * hdr_idx: Value printed in an Excel cell # shortcuts obj = GrouperInit.NtMaker(self) # Create go2nthdridx for goid in gos_all: go2nthdridx[goid] = obj.get_nt(goid) return go2nthdridx
python
def _get_go2nthdridx(self, gos_all): """Get GO IDs header index for each user GO ID and corresponding parent GO IDs.""" go2nthdridx = {} # NtHdrIdx Namedtuple fields: # * format_txt: Used to determine the format when writing Excel cells # * hdr_idx: Value printed in an Excel cell # shortcuts obj = GrouperInit.NtMaker(self) # Create go2nthdridx for goid in gos_all: go2nthdridx[goid] = obj.get_nt(goid) return go2nthdridx
[ "def", "_get_go2nthdridx", "(", "self", ",", "gos_all", ")", ":", "go2nthdridx", "=", "{", "}", "# NtHdrIdx Namedtuple fields:", "# * format_txt: Used to determine the format when writing Excel cells", "# * hdr_idx: Value printed in an Excel cell", "# shortcuts", "obj", "=", "GrouperInit", ".", "NtMaker", "(", "self", ")", "# Create go2nthdridx", "for", "goid", "in", "gos_all", ":", "go2nthdridx", "[", "goid", "]", "=", "obj", ".", "get_nt", "(", "goid", ")", "return", "go2nthdridx" ]
Get GO IDs header index for each user GO ID and corresponding parent GO IDs.
[ "Get", "GO", "IDs", "header", "index", "for", "each", "user", "GO", "ID", "and", "corresponding", "parent", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/grouper/grprobj_init.py#L193-L204
228,584
tanghaibao/goatools
goatools/godag_obosm.py
OboToGoDagSmall._init_go2obj
def _init_go2obj(self, **kws): """Initialize go2obj in small dag for source gos.""" if 'goids' in kws and 'obodag' in kws: self.godag.go_sources = kws['goids'] obo = kws['obodag'] for goid in self.godag.go_sources: self.godag.go2obj[goid] = obo[goid] elif 'goid2goobj' in kws: goid2goobj = kws['goid2goobj'] self.godag.go_sources = goid2goobj.keys() for goid, goobj in goid2goobj.items(): self.godag.go2obj[goid] = goobj elif 'goea_results' in kws: goea_results = kws['goea_results'] self.godag.go_sources = [rec.GO for rec in goea_results] self.godag.go2obj = {rec.GO:rec.goterm for rec in goea_results}
python
def _init_go2obj(self, **kws): """Initialize go2obj in small dag for source gos.""" if 'goids' in kws and 'obodag' in kws: self.godag.go_sources = kws['goids'] obo = kws['obodag'] for goid in self.godag.go_sources: self.godag.go2obj[goid] = obo[goid] elif 'goid2goobj' in kws: goid2goobj = kws['goid2goobj'] self.godag.go_sources = goid2goobj.keys() for goid, goobj in goid2goobj.items(): self.godag.go2obj[goid] = goobj elif 'goea_results' in kws: goea_results = kws['goea_results'] self.godag.go_sources = [rec.GO for rec in goea_results] self.godag.go2obj = {rec.GO:rec.goterm for rec in goea_results}
[ "def", "_init_go2obj", "(", "self", ",", "*", "*", "kws", ")", ":", "if", "'goids'", "in", "kws", "and", "'obodag'", "in", "kws", ":", "self", ".", "godag", ".", "go_sources", "=", "kws", "[", "'goids'", "]", "obo", "=", "kws", "[", "'obodag'", "]", "for", "goid", "in", "self", ".", "godag", ".", "go_sources", ":", "self", ".", "godag", ".", "go2obj", "[", "goid", "]", "=", "obo", "[", "goid", "]", "elif", "'goid2goobj'", "in", "kws", ":", "goid2goobj", "=", "kws", "[", "'goid2goobj'", "]", "self", ".", "godag", ".", "go_sources", "=", "goid2goobj", ".", "keys", "(", ")", "for", "goid", ",", "goobj", "in", "goid2goobj", ".", "items", "(", ")", ":", "self", ".", "godag", ".", "go2obj", "[", "goid", "]", "=", "goobj", "elif", "'goea_results'", "in", "kws", ":", "goea_results", "=", "kws", "[", "'goea_results'", "]", "self", ".", "godag", ".", "go_sources", "=", "[", "rec", ".", "GO", "for", "rec", "in", "goea_results", "]", "self", ".", "godag", ".", "go2obj", "=", "{", "rec", ".", "GO", ":", "rec", ".", "goterm", "for", "rec", "in", "goea_results", "}" ]
Initialize go2obj in small dag for source gos.
[ "Initialize", "go2obj", "in", "small", "dag", "for", "source", "gos", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag_obosm.py#L28-L43
228,585
tanghaibao/goatools
goatools/godag_obosm.py
OboToGoDagSmall._init
def _init(self): """Given GO ids and GOTerm objects, create mini GO dag.""" for goid in self.godag.go_sources: goobj = self.godag.go2obj[goid] self.godag.go2obj[goid] = goobj # Traverse up parents if self.traverse_parent and goid not in self.seen_cids: self._traverse_parent_objs(goobj) # Traverse down children if self.traverse_child and goid not in self.seen_pids: self._traverse_child_objs(goobj)
python
def _init(self): """Given GO ids and GOTerm objects, create mini GO dag.""" for goid in self.godag.go_sources: goobj = self.godag.go2obj[goid] self.godag.go2obj[goid] = goobj # Traverse up parents if self.traverse_parent and goid not in self.seen_cids: self._traverse_parent_objs(goobj) # Traverse down children if self.traverse_child and goid not in self.seen_pids: self._traverse_child_objs(goobj)
[ "def", "_init", "(", "self", ")", ":", "for", "goid", "in", "self", ".", "godag", ".", "go_sources", ":", "goobj", "=", "self", ".", "godag", ".", "go2obj", "[", "goid", "]", "self", ".", "godag", ".", "go2obj", "[", "goid", "]", "=", "goobj", "# Traverse up parents", "if", "self", ".", "traverse_parent", "and", "goid", "not", "in", "self", ".", "seen_cids", ":", "self", ".", "_traverse_parent_objs", "(", "goobj", ")", "# Traverse down children", "if", "self", ".", "traverse_child", "and", "goid", "not", "in", "self", ".", "seen_pids", ":", "self", ".", "_traverse_child_objs", "(", "goobj", ")" ]
Given GO ids and GOTerm objects, create mini GO dag.
[ "Given", "GO", "ids", "and", "GOTerm", "objects", "create", "mini", "GO", "dag", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/godag_obosm.py#L45-L55
228,586
tanghaibao/goatools
goatools/rpt/write_hierarchy_base.py
WrHierPrt.prt_hier_rec
def prt_hier_rec(self, item_id, depth=1): """Write hierarchy for a GO Term record and all GO IDs down to the leaf level.""" # Shortens hierarchy report by only printing the hierarchy # for the sub-set of user-specified GO terms which are connected. if self.include_only and item_id not in self.include_only: return obj = self.id2obj[item_id] # Optionally space the branches for readability if self.space_branches: if depth == 1 and obj.children: self.prt.write("\n") # Print marks if provided if self.item_marks: self.prt.write('{MARK} '.format( MARK=self.item_marks.get(item_id, self.mark_dflt))) no_repeat = self.concise_prt and item_id in self.items_printed # Print content dashes = self._str_dash(depth, no_repeat, obj) if self.do_prtfmt: self._prtfmt(item_id, dashes) else: self._prtstr(obj, dashes) self.items_printed.add(item_id) self.items_list.append(item_id) # Do not print hierarchy below this turn if it has already been printed if no_repeat: return depth += 1 if self.max_indent is not None and depth > self.max_indent: return children = obj.children if self.sortby is None else sorted(obj.children, key=self.sortby) for child in children: self.prt_hier_rec(child.item_id, depth)
python
def prt_hier_rec(self, item_id, depth=1): """Write hierarchy for a GO Term record and all GO IDs down to the leaf level.""" # Shortens hierarchy report by only printing the hierarchy # for the sub-set of user-specified GO terms which are connected. if self.include_only and item_id not in self.include_only: return obj = self.id2obj[item_id] # Optionally space the branches for readability if self.space_branches: if depth == 1 and obj.children: self.prt.write("\n") # Print marks if provided if self.item_marks: self.prt.write('{MARK} '.format( MARK=self.item_marks.get(item_id, self.mark_dflt))) no_repeat = self.concise_prt and item_id in self.items_printed # Print content dashes = self._str_dash(depth, no_repeat, obj) if self.do_prtfmt: self._prtfmt(item_id, dashes) else: self._prtstr(obj, dashes) self.items_printed.add(item_id) self.items_list.append(item_id) # Do not print hierarchy below this turn if it has already been printed if no_repeat: return depth += 1 if self.max_indent is not None and depth > self.max_indent: return children = obj.children if self.sortby is None else sorted(obj.children, key=self.sortby) for child in children: self.prt_hier_rec(child.item_id, depth)
[ "def", "prt_hier_rec", "(", "self", ",", "item_id", ",", "depth", "=", "1", ")", ":", "# Shortens hierarchy report by only printing the hierarchy", "# for the sub-set of user-specified GO terms which are connected.", "if", "self", ".", "include_only", "and", "item_id", "not", "in", "self", ".", "include_only", ":", "return", "obj", "=", "self", ".", "id2obj", "[", "item_id", "]", "# Optionally space the branches for readability", "if", "self", ".", "space_branches", ":", "if", "depth", "==", "1", "and", "obj", ".", "children", ":", "self", ".", "prt", ".", "write", "(", "\"\\n\"", ")", "# Print marks if provided", "if", "self", ".", "item_marks", ":", "self", ".", "prt", ".", "write", "(", "'{MARK} '", ".", "format", "(", "MARK", "=", "self", ".", "item_marks", ".", "get", "(", "item_id", ",", "self", ".", "mark_dflt", ")", ")", ")", "no_repeat", "=", "self", ".", "concise_prt", "and", "item_id", "in", "self", ".", "items_printed", "# Print content", "dashes", "=", "self", ".", "_str_dash", "(", "depth", ",", "no_repeat", ",", "obj", ")", "if", "self", ".", "do_prtfmt", ":", "self", ".", "_prtfmt", "(", "item_id", ",", "dashes", ")", "else", ":", "self", ".", "_prtstr", "(", "obj", ",", "dashes", ")", "self", ".", "items_printed", ".", "add", "(", "item_id", ")", "self", ".", "items_list", ".", "append", "(", "item_id", ")", "# Do not print hierarchy below this turn if it has already been printed", "if", "no_repeat", ":", "return", "depth", "+=", "1", "if", "self", ".", "max_indent", "is", "not", "None", "and", "depth", ">", "self", ".", "max_indent", ":", "return", "children", "=", "obj", ".", "children", "if", "self", ".", "sortby", "is", "None", "else", "sorted", "(", "obj", ".", "children", ",", "key", "=", "self", ".", "sortby", ")", "for", "child", "in", "children", ":", "self", ".", "prt_hier_rec", "(", "child", ".", "item_id", ",", "depth", ")" ]
Write hierarchy for a GO Term record and all GO IDs down to the leaf level.
[ "Write", "hierarchy", "for", "a", "GO", "Term", "record", "and", "all", "GO", "IDs", "down", "to", "the", "leaf", "level", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/write_hierarchy_base.py#L34-L68
228,587
tanghaibao/goatools
goatools/rpt/write_hierarchy_base.py
WrHierPrt._init_item_marks
def _init_item_marks(item_marks): """Initialize the makred item dict.""" if isinstance(item_marks, dict): return item_marks if item_marks: return {item_id:'>' for item_id in item_marks}
python
def _init_item_marks(item_marks): """Initialize the makred item dict.""" if isinstance(item_marks, dict): return item_marks if item_marks: return {item_id:'>' for item_id in item_marks}
[ "def", "_init_item_marks", "(", "item_marks", ")", ":", "if", "isinstance", "(", "item_marks", ",", "dict", ")", ":", "return", "item_marks", "if", "item_marks", ":", "return", "{", "item_id", ":", "'>'", "for", "item_id", "in", "item_marks", "}" ]
Initialize the makred item dict.
[ "Initialize", "the", "makred", "item", "dict", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/rpt/write_hierarchy_base.py#L97-L102
228,588
tanghaibao/goatools
goatools/obo_parser.py
OBOReader._add_to_obj
def _add_to_obj(self, rec_curr, typedef_curr, line): """Add information on line to GOTerm or Typedef.""" if rec_curr is not None: self._add_to_ref(rec_curr, line) else: add_to_typedef(typedef_curr, line)
python
def _add_to_obj(self, rec_curr, typedef_curr, line): """Add information on line to GOTerm or Typedef.""" if rec_curr is not None: self._add_to_ref(rec_curr, line) else: add_to_typedef(typedef_curr, line)
[ "def", "_add_to_obj", "(", "self", ",", "rec_curr", ",", "typedef_curr", ",", "line", ")", ":", "if", "rec_curr", "is", "not", "None", ":", "self", ".", "_add_to_ref", "(", "rec_curr", ",", "line", ")", "else", ":", "add_to_typedef", "(", "typedef_curr", ",", "line", ")" ]
Add information on line to GOTerm or Typedef.
[ "Add", "information", "on", "line", "to", "GOTerm", "or", "Typedef", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L87-L92
228,589
tanghaibao/goatools
goatools/obo_parser.py
OBOReader._init_obo_version
def _init_obo_version(self, line): """Save obo version and release.""" if line[0:14] == "format-version": self.format_version = line[16:-1] if line[0:12] == "data-version": self.data_version = line[14:-1]
python
def _init_obo_version(self, line): """Save obo version and release.""" if line[0:14] == "format-version": self.format_version = line[16:-1] if line[0:12] == "data-version": self.data_version = line[14:-1]
[ "def", "_init_obo_version", "(", "self", ",", "line", ")", ":", "if", "line", "[", "0", ":", "14", "]", "==", "\"format-version\"", ":", "self", ".", "format_version", "=", "line", "[", "16", ":", "-", "1", "]", "if", "line", "[", "0", ":", "12", "]", "==", "\"data-version\"", ":", "self", ".", "data_version", "=", "line", "[", "14", ":", "-", "1", "]" ]
Save obo version and release.
[ "Save", "obo", "version", "and", "release", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L94-L99
228,590
tanghaibao/goatools
goatools/obo_parser.py
OBOReader._init_optional_attrs
def _init_optional_attrs(optional_attrs): """Create OboOptionalAttrs or return None.""" if optional_attrs is None: return None opts = OboOptionalAttrs.get_optional_attrs(optional_attrs) if opts: return OboOptionalAttrs(opts)
python
def _init_optional_attrs(optional_attrs): """Create OboOptionalAttrs or return None.""" if optional_attrs is None: return None opts = OboOptionalAttrs.get_optional_attrs(optional_attrs) if opts: return OboOptionalAttrs(opts)
[ "def", "_init_optional_attrs", "(", "optional_attrs", ")", ":", "if", "optional_attrs", "is", "None", ":", "return", "None", "opts", "=", "OboOptionalAttrs", ".", "get_optional_attrs", "(", "optional_attrs", ")", "if", "opts", ":", "return", "OboOptionalAttrs", "(", "opts", ")" ]
Create OboOptionalAttrs or return None.
[ "Create", "OboOptionalAttrs", "or", "return", "None", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L130-L136
228,591
tanghaibao/goatools
goatools/obo_parser.py
GOTerm.has_parent
def has_parent(self, term): """Return True if this GO object has a parent GO ID.""" for parent in self.parents: if parent.item_id == term or parent.has_parent(term): return True return False
python
def has_parent(self, term): """Return True if this GO object has a parent GO ID.""" for parent in self.parents: if parent.item_id == term or parent.has_parent(term): return True return False
[ "def", "has_parent", "(", "self", ",", "term", ")", ":", "for", "parent", "in", "self", ".", "parents", ":", "if", "parent", ".", "item_id", "==", "term", "or", "parent", ".", "has_parent", "(", "term", ")", ":", "return", "True", "return", "False" ]
Return True if this GO object has a parent GO ID.
[ "Return", "True", "if", "this", "GO", "object", "has", "a", "parent", "GO", "ID", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L191-L196
228,592
tanghaibao/goatools
goatools/obo_parser.py
GOTerm.has_child
def has_child(self, term): """Return True if this GO object has a child GO ID.""" for parent in self.children: if parent.item_id == term or parent.has_child(term): return True return False
python
def has_child(self, term): """Return True if this GO object has a child GO ID.""" for parent in self.children: if parent.item_id == term or parent.has_child(term): return True return False
[ "def", "has_child", "(", "self", ",", "term", ")", ":", "for", "parent", "in", "self", ".", "children", ":", "if", "parent", ".", "item_id", "==", "term", "or", "parent", ".", "has_child", "(", "term", ")", ":", "return", "True", "return", "False" ]
Return True if this GO object has a child GO ID.
[ "Return", "True", "if", "this", "GO", "object", "has", "a", "child", "GO", "ID", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L198-L203
228,593
tanghaibao/goatools
goatools/obo_parser.py
GOTerm.get_all_parents
def get_all_parents(self): """Return all parent GO IDs.""" all_parents = set() for parent in self.parents: all_parents.add(parent.item_id) all_parents |= parent.get_all_parents() return all_parents
python
def get_all_parents(self): """Return all parent GO IDs.""" all_parents = set() for parent in self.parents: all_parents.add(parent.item_id) all_parents |= parent.get_all_parents() return all_parents
[ "def", "get_all_parents", "(", "self", ")", ":", "all_parents", "=", "set", "(", ")", "for", "parent", "in", "self", ".", "parents", ":", "all_parents", ".", "add", "(", "parent", ".", "item_id", ")", "all_parents", "|=", "parent", ".", "get_all_parents", "(", ")", "return", "all_parents" ]
Return all parent GO IDs.
[ "Return", "all", "parent", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L205-L211
228,594
tanghaibao/goatools
goatools/obo_parser.py
GOTerm.get_all_upper
def get_all_upper(self): """Return all parent GO IDs through both 'is_a' and all relationships.""" all_upper = set() for upper in self.get_goterms_upper(): all_upper.add(upper.item_id) all_upper |= upper.get_all_upper() return all_upper
python
def get_all_upper(self): """Return all parent GO IDs through both 'is_a' and all relationships.""" all_upper = set() for upper in self.get_goterms_upper(): all_upper.add(upper.item_id) all_upper |= upper.get_all_upper() return all_upper
[ "def", "get_all_upper", "(", "self", ")", ":", "all_upper", "=", "set", "(", ")", "for", "upper", "in", "self", ".", "get_goterms_upper", "(", ")", ":", "all_upper", ".", "add", "(", "upper", ".", "item_id", ")", "all_upper", "|=", "upper", ".", "get_all_upper", "(", ")", "return", "all_upper" ]
Return all parent GO IDs through both 'is_a' and all relationships.
[ "Return", "all", "parent", "GO", "IDs", "through", "both", "is_a", "and", "all", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L213-L219
228,595
tanghaibao/goatools
goatools/obo_parser.py
GOTerm.get_all_children
def get_all_children(self): """Return all children GO IDs.""" all_children = set() for parent in self.children: all_children.add(parent.item_id) all_children |= parent.get_all_children() return all_children
python
def get_all_children(self): """Return all children GO IDs.""" all_children = set() for parent in self.children: all_children.add(parent.item_id) all_children |= parent.get_all_children() return all_children
[ "def", "get_all_children", "(", "self", ")", ":", "all_children", "=", "set", "(", ")", "for", "parent", "in", "self", ".", "children", ":", "all_children", ".", "add", "(", "parent", ".", "item_id", ")", "all_children", "|=", "parent", ".", "get_all_children", "(", ")", "return", "all_children" ]
Return all children GO IDs.
[ "Return", "all", "children", "GO", "IDs", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L221-L227
228,596
tanghaibao/goatools
goatools/obo_parser.py
GOTerm.get_all_lower
def get_all_lower(self): """Return all parent GO IDs through both reverse 'is_a' and all relationships.""" all_lower = set() for lower in self.get_goterms_lower(): all_lower.add(lower.item_id) all_lower |= lower.get_all_lower() return all_lower
python
def get_all_lower(self): """Return all parent GO IDs through both reverse 'is_a' and all relationships.""" all_lower = set() for lower in self.get_goterms_lower(): all_lower.add(lower.item_id) all_lower |= lower.get_all_lower() return all_lower
[ "def", "get_all_lower", "(", "self", ")", ":", "all_lower", "=", "set", "(", ")", "for", "lower", "in", "self", ".", "get_goterms_lower", "(", ")", ":", "all_lower", ".", "add", "(", "lower", ".", "item_id", ")", "all_lower", "|=", "lower", ".", "get_all_lower", "(", ")", "return", "all_lower" ]
Return all parent GO IDs through both reverse 'is_a' and all relationships.
[ "Return", "all", "parent", "GO", "IDs", "through", "both", "reverse", "is_a", "and", "all", "relationships", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L229-L235
228,597
tanghaibao/goatools
goatools/obo_parser.py
GOTerm.get_all_parent_edges
def get_all_parent_edges(self): """Return tuples for all parent GO IDs, containing current GO ID and parent GO ID.""" all_parent_edges = set() for parent in self.parents: all_parent_edges.add((self.item_id, parent.item_id)) all_parent_edges |= parent.get_all_parent_edges() return all_parent_edges
python
def get_all_parent_edges(self): """Return tuples for all parent GO IDs, containing current GO ID and parent GO ID.""" all_parent_edges = set() for parent in self.parents: all_parent_edges.add((self.item_id, parent.item_id)) all_parent_edges |= parent.get_all_parent_edges() return all_parent_edges
[ "def", "get_all_parent_edges", "(", "self", ")", ":", "all_parent_edges", "=", "set", "(", ")", "for", "parent", "in", "self", ".", "parents", ":", "all_parent_edges", ".", "add", "(", "(", "self", ".", "item_id", ",", "parent", ".", "item_id", ")", ")", "all_parent_edges", "|=", "parent", ".", "get_all_parent_edges", "(", ")", "return", "all_parent_edges" ]
Return tuples for all parent GO IDs, containing current GO ID and parent GO ID.
[ "Return", "tuples", "for", "all", "parent", "GO", "IDs", "containing", "current", "GO", "ID", "and", "parent", "GO", "ID", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L237-L243
228,598
tanghaibao/goatools
goatools/obo_parser.py
GOTerm.get_all_child_edges
def get_all_child_edges(self): """Return tuples for all child GO IDs, containing current GO ID and child GO ID.""" all_child_edges = set() for parent in self.children: all_child_edges.add((parent.item_id, self.item_id)) all_child_edges |= parent.get_all_child_edges() return all_child_edges
python
def get_all_child_edges(self): """Return tuples for all child GO IDs, containing current GO ID and child GO ID.""" all_child_edges = set() for parent in self.children: all_child_edges.add((parent.item_id, self.item_id)) all_child_edges |= parent.get_all_child_edges() return all_child_edges
[ "def", "get_all_child_edges", "(", "self", ")", ":", "all_child_edges", "=", "set", "(", ")", "for", "parent", "in", "self", ".", "children", ":", "all_child_edges", ".", "add", "(", "(", "parent", ".", "item_id", ",", "self", ".", "item_id", ")", ")", "all_child_edges", "|=", "parent", ".", "get_all_child_edges", "(", ")", "return", "all_child_edges" ]
Return tuples for all child GO IDs, containing current GO ID and child GO ID.
[ "Return", "tuples", "for", "all", "child", "GO", "IDs", "containing", "current", "GO", "ID", "and", "child", "GO", "ID", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L245-L251
228,599
tanghaibao/goatools
goatools/obo_parser.py
GODag.load_obo_file
def load_obo_file(self, obo_file, optional_attrs, load_obsolete, prt): """Read obo file. Store results.""" reader = OBOReader(obo_file, optional_attrs) # Save alt_ids and their corresponding main GO ID. Add to GODag after populating GO Terms alt2rec = {} for rec in reader: # Save record if: # 1) Argument load_obsolete is True OR # 2) Argument load_obsolete is False and the GO term is "live" (not obsolete) if load_obsolete or not rec.is_obsolete: self[rec.item_id] = rec for alt in rec.alt_ids: alt2rec[alt] = rec # Save the typedefs and parsed optional_attrs # self.optobj = reader.optobj self.typedefs = reader.typedefs self._populate_terms(reader.optobj) self._set_level_depth(reader.optobj) # Add alt_ids to go2obj for goid_alt, rec in alt2rec.items(): self[goid_alt] = rec desc = self._str_desc(reader) if prt is not None: prt.write("{DESC}\n".format(DESC=desc)) return desc
python
def load_obo_file(self, obo_file, optional_attrs, load_obsolete, prt): """Read obo file. Store results.""" reader = OBOReader(obo_file, optional_attrs) # Save alt_ids and their corresponding main GO ID. Add to GODag after populating GO Terms alt2rec = {} for rec in reader: # Save record if: # 1) Argument load_obsolete is True OR # 2) Argument load_obsolete is False and the GO term is "live" (not obsolete) if load_obsolete or not rec.is_obsolete: self[rec.item_id] = rec for alt in rec.alt_ids: alt2rec[alt] = rec # Save the typedefs and parsed optional_attrs # self.optobj = reader.optobj self.typedefs = reader.typedefs self._populate_terms(reader.optobj) self._set_level_depth(reader.optobj) # Add alt_ids to go2obj for goid_alt, rec in alt2rec.items(): self[goid_alt] = rec desc = self._str_desc(reader) if prt is not None: prt.write("{DESC}\n".format(DESC=desc)) return desc
[ "def", "load_obo_file", "(", "self", ",", "obo_file", ",", "optional_attrs", ",", "load_obsolete", ",", "prt", ")", ":", "reader", "=", "OBOReader", "(", "obo_file", ",", "optional_attrs", ")", "# Save alt_ids and their corresponding main GO ID. Add to GODag after populating GO Terms", "alt2rec", "=", "{", "}", "for", "rec", "in", "reader", ":", "# Save record if:", "# 1) Argument load_obsolete is True OR", "# 2) Argument load_obsolete is False and the GO term is \"live\" (not obsolete)", "if", "load_obsolete", "or", "not", "rec", ".", "is_obsolete", ":", "self", "[", "rec", ".", "item_id", "]", "=", "rec", "for", "alt", "in", "rec", ".", "alt_ids", ":", "alt2rec", "[", "alt", "]", "=", "rec", "# Save the typedefs and parsed optional_attrs", "# self.optobj = reader.optobj", "self", ".", "typedefs", "=", "reader", ".", "typedefs", "self", ".", "_populate_terms", "(", "reader", ".", "optobj", ")", "self", ".", "_set_level_depth", "(", "reader", ".", "optobj", ")", "# Add alt_ids to go2obj", "for", "goid_alt", ",", "rec", "in", "alt2rec", ".", "items", "(", ")", ":", "self", "[", "goid_alt", "]", "=", "rec", "desc", "=", "self", ".", "_str_desc", "(", "reader", ")", "if", "prt", "is", "not", "None", ":", "prt", ".", "write", "(", "\"{DESC}\\n\"", ".", "format", "(", "DESC", "=", "desc", ")", ")", "return", "desc" ]
Read obo file. Store results.
[ "Read", "obo", "file", ".", "Store", "results", "." ]
407682e573a108864a79031f8ca19ee3bf377626
https://github.com/tanghaibao/goatools/blob/407682e573a108864a79031f8ca19ee3bf377626/goatools/obo_parser.py#L312-L340