_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
75
19.8k
language
stringclasses
1 value
meta_information
dict
q224000
SetupHelper.check_version
train
def check_version(self, name, majorv=2, minorv=7): """ Make sure the package runs on the supported Python version """ if sys.version_info.major == majorv and sys.version_info.minor != minorv: sys.stderr.write("ERROR: %s is only for >= Python %d.%d but you are running %d.%d\n" %\ ...
python
{ "resource": "" }
q224001
SetupHelper.get_init
train
def get_init(self, filename="__init__.py"): """ Get various info from the package without importing them """ import ast with open(filename) as init_file: module = ast.parse(init_file.read()) itr = lambda x: (ast.literal_eval(node.value) for node in ast.walk(module) ...
python
{ "resource": "" }
q224002
SetupHelper.missing_requirements
train
def missing_requirements(self, specifiers): """ Find what's missing """ for specifier in specifiers: try: pkg_resources.require(specifier) except pkg_resources.DistributionNotFound: yield specifier
python
{ "resource": "" }
q224003
SetupHelper.install_requirements
train
def install_requirements(self, requires): """ Install the listed requirements """ # Temporarily install dependencies required by setup.py before trying to import them. sys.path[0:0] = ['setup-requires'] pkg_resources.working_set.add_entry('setup-requires') to_install = l...
python
{ "resource": "" }
q224004
SetupHelper.get_long_description
train
def get_long_description(self, filename='README.md'): """ I really prefer Markdown to reStructuredText. PyPi does not. """ try: import pypandoc description = pypandoc.convert_file('README.md', 'rst', 'md') except (IOError, ImportError): description = o...
python
{ "resource": "" }
q224005
Sorter.prt_gos
train
def prt_gos(self, prt=sys.stdout, **kws_usr): """Sort user GO ids, grouped under broader GO terms or sections. Print to screen.""" # deprecated # Keyword arguments (control content): hdrgo_prt section_prt use_sections # desc2nts contains: (sections hdrgo_prt sortobj) or (flat hdrgo_prt s...
python
{ "resource": "" }
q224006
Sorter.get_nts_flat
train
def get_nts_flat(self, hdrgo_prt=True, use_sections=True): """Return a flat list of sorted nts.""" # Either there are no sections OR we are not using them if self.sectobj is None or not use_sections: return self.sortgos.get_nts_sorted( hdrgo_prt, hdrgo...
python
{ "resource": "" }
q224007
Grouper.get_sections_2d
train
def get_sections_2d(self): """Get 2-D list of sections and hdrgos sets actually used in grouping.""" sections_hdrgos_act = [] hdrgos_act_all = self.get_hdrgos() # Header GOs actually used to group hdrgos_act_secs = set() if self.hdrobj.sections: for section_name, hdr...
python
{ "resource": "" }
q224008
Grouper.get_usrgos_g_section
train
def get_usrgos_g_section(self, section=None): """Get usrgos in a requested section.""" if section is None: section = self.hdrobj.secdflt if section is True: return self.usrgos # Get dict of sections and hdrgos actually used in grouping section2hdrgos = cx....
python
{ "resource": "" }
q224009
Grouper.get_section2usrnts
train
def get_section2usrnts(self): """Get dict section2usrnts.""" sec_nts = [] for section_name, _ in self.get_sections_2d(): usrgos = self.get_usrgos_g_section(section_name) sec_nts.append((section_name, [self.go2nt.get(u) for u in usrgos])) return cx.OrderedDict(sec_...
python
{ "resource": "" }
q224010
Grouper.get_section2items
train
def get_section2items(self, itemkey): """Collect all items into a single set per section.""" sec_items = [] section2usrnts = self.get_section2usrnts() for section, usrnts in section2usrnts.items(): items = set([e for nt in usrnts for e in getattr(nt, itemkey, set())]) ...
python
{ "resource": "" }
q224011
Grouper.get_hdrgos_g_usrgos
train
def get_hdrgos_g_usrgos(self, usrgos): """Return hdrgos which contain the usrgos.""" hdrgos_for_usrgos = set() hdrgos_all = self.get_hdrgos() usrgo2hdrgo = self.get_usrgo2hdrgo() for usrgo in usrgos: if usrgo in hdrgos_all: hdrgos_for_usrgos.add(usrgo)...
python
{ "resource": "" }
q224012
Grouper.get_section_hdrgos_nts
train
def get_section_hdrgos_nts(self, sortby=None): """Get a flat list of sections and hdrgos actually used in grouping.""" nts_all = [] section_hdrgos_actual = self.get_sections_2d() flds_all = ['Section'] + self.gosubdag.prt_attr['flds'] ntobj = cx.namedtuple("NtGoSec", " ".join(fld...
python
{ "resource": "" }
q224013
Grouper.get_sections_2d_nts
train
def get_sections_2d_nts(self, sortby=None): """Get high GO IDs that are actually used to group current set of GO IDs.""" sections_2d_nts = [] for section_name, hdrgos_actual in self.get_sections_2d(): hdrgo_nts = self.gosubdag.get_nts(hdrgos_actual, sortby=sortby) section...
python
{ "resource": "" }
q224014
Grouper.get_usrgos_g_hdrgos
train
def get_usrgos_g_hdrgos(self, hdrgos): """Return usrgos under provided hdrgos.""" usrgos_all = set() if isinstance(hdrgos, str): hdrgos = [hdrgos] for hdrgo in hdrgos: usrgos_cur = self.hdrgo2usrgos.get(hdrgo, None) if usrgos_cur is not None: ...
python
{ "resource": "" }
q224015
Grouper.get_hdrgo2usrgos
train
def get_hdrgo2usrgos(self, hdrgos): """Return a subset of hdrgo2usrgos.""" get_usrgos = self.hdrgo2usrgos.get hdrgos_actual = self.get_hdrgos().intersection(hdrgos) return {h:get_usrgos(h) for h in hdrgos_actual}
python
{ "resource": "" }
q224016
Grouper.get_usrgo2hdrgo
train
def get_usrgo2hdrgo(self): """Return a dict with all user GO IDs as keys and their respective header GOs as values.""" usrgo2hdrgo = {} for hdrgo, usrgos in self.hdrgo2usrgos.items(): for usrgo in usrgos: assert usrgo not in usrgo2hdrgo usrgo2hdrgo[usr...
python
{ "resource": "" }
q224017
Grouper.get_go2sectiontxt
train
def get_go2sectiontxt(self): """Return a dict with actual header and user GO IDs as keys and their sections as values.""" go2txt = {} _get_secs = self.hdrobj.get_sections hdrgo2sectxt = {h:" ".join(_get_secs(h)) for h in self.get_hdrgos()} usrgo2hdrgo = self.get_usrgo2hdrgo() ...
python
{ "resource": "" }
q224018
Grouper.get_usrgo2sections
train
def get_usrgo2sections(self): """Return a dict with all user GO IDs as keys and their sections as values.""" usrgo2sections = cx.defaultdict(set) usrgo2hdrgo = self.get_usrgo2hdrgo() get_sections = self.hdrobj.get_sections for usrgo, hdrgo in usrgo2hdrgo.items(): sect...
python
{ "resource": "" }
q224019
Grouper.get_fout_base
train
def get_fout_base(self, goid, name=None, pre="gogrp"): """Get filename for a group of GO IDs under a single header GO ID.""" goobj = self.gosubdag.go2obj[goid] if name is None: name = self.grpname.replace(" ", "_") sections = "_".join(self.hdrobj.get_sections(goid)) r...
python
{ "resource": "" }
q224020
Grouper._get_depthsr
train
def _get_depthsr(self, goobj): """Return DNN or RNN depending on if relationships are loaded.""" if 'reldepth' in self.gosubdag.prt_attr['flds']: return "R{R:02}".format(R=goobj.reldepth) return "D{D:02}".format(D=goobj.depth)
python
{ "resource": "" }
q224021
Grouper._str_replace
train
def _str_replace(txt): """Makes a small text amenable to being used in a filename.""" txt = txt.replace(",", "") txt = txt.replace(" ", "_") txt = txt.replace(":", "") txt = txt.replace(".", "") txt = txt.replace("/", "") txt = txt.replace("", "") return t...
python
{ "resource": "" }
q224022
PrtFmt.get_prtfmt_list
train
def get_prtfmt_list(self, flds, add_nl=True): """Get print format, given fields.""" fmts = [] for fld in flds: if fld[:2] == 'p_': fmts.append('{{{FLD}:8.2e}}'.format(FLD=fld)) elif fld in self.default_fld2fmt: fmts.append(self.default_fld2...
python
{ "resource": "" }
q224023
main
train
def main(): """Fetch simple gene-term assocaitions from Golr using bioentity document type, one line per gene.""" import argparse prs = argparse.ArgumentParser(__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter) prs.add_argument('--taxon_id', type=str, ...
python
{ "resource": "" }
q224024
ShortenText.get_short_plot_name
train
def get_short_plot_name(self, goobj): """Shorten some GO names so plots are smaller.""" name = goobj.name if self._keep_this(name): return self.replace_greek(name) name = name.replace("cellular response to chemical stimulus", "cellular rsp. to chem...
python
{ "resource": "" }
q224025
ShortenText.shorten_go_name_ptbl1
train
def shorten_go_name_ptbl1(self, name): """Shorten GO name for tables in paper.""" if self._keep_this(name): return name name = name.replace("negative", "neg.") name = name.replace("positive", "pos.") name = name.replace("response", "rsp.") name = name.replace(...
python
{ "resource": "" }
q224026
ShortenText.shorten_go_name_ptbl3
train
def shorten_go_name_ptbl3(self, name, dcnt): """Shorten GO description for Table 3 in manuscript.""" if self._keep_this(name): return name name = name.replace("positive regulation of immune system process", "+ reg. of immune sys. process") name = n...
python
{ "resource": "" }
q224027
ShortenText.shorten_go_name_all
train
def shorten_go_name_all(self, name): """Shorten GO name for tables in paper, supplemental materials, and plots.""" name = self.replace_greek(name) name = name.replace("MHC class I", "MHC-I") return name
python
{ "resource": "" }
q224028
ShortenText._keep_this
train
def _keep_this(self, name): """Return True if there are to be no modifications to name.""" for keep_name in self.keep: if name == keep_name: return True return False
python
{ "resource": "" }
q224029
read_d1_letter
train
def read_d1_letter(fin_txt): """Reads letter aliases from a text file created by GoDepth1LettersWr.""" go2letter = {} re_goid = re.compile(r"(GO:\d{7})") with open(fin_txt) as ifstrm: for line in ifstrm: mtch = re_goid.search(line) if mtch and line[:1] != ' ': ...
python
{ "resource": "" }
q224030
GoSubDagWr.get_goids_sections
train
def get_goids_sections(sections): """Return all the GO IDs in a 2-D sections list.""" goids_all = set() for _, goids_sec in sections: goids_all |= set(goids_sec) return goids_all
python
{ "resource": "" }
q224031
GoDepth1LettersWr.prt_txt
train
def prt_txt(self, prt=sys.stdout, pre=''): """Print letters, descendant count, and GO information.""" data_nts = self.get_d1nts() for ntdata in data_nts: prt.write("{PRE}{L:1} {NS} {d:6,} D{D:02} {GO} {NAME}\n".format( PRE=pre, L=ntdata.D1, ...
python
{ "resource": "" }
q224032
GoDepth1LettersWr.wr_xlsx
train
def wr_xlsx(self, fout_xlsx="gos_depth01.xlsx", **kws): """Write xlsx table of depth-01 GO terms and their letter representation.""" data_nts = self.get_d1nts() if 'fld2col_widths' not in kws: kws['fld2col_widths'] = {'D1': 6, 'NS':3, 'depth': 5, 'GO': 12, 'name': 40} if 'hdr...
python
{ "resource": "" }
q224033
GoDepth1LettersWr.get_d1nts
train
def get_d1nts(self): """Get letters for depth-01 GO terms, descendants count, and GO information.""" data = [] ntdata = cx.namedtuple("NtPrt", "D1 NS dcnt depth GO name") namespace = None for ntlet in sorted(self.goone2ntletter.values(), key=lambda nt:...
python
{ "resource": "" }
q224034
GoDepth1LettersWr._init_ns2nt
train
def _init_ns2nt(rcntobj): """Save depth-00 GO terms ordered using descendants cnt.""" go2dcnt = rcntobj.go2dcnt ntobj = cx.namedtuple("NtD1", "D1 dcnt goobj") d0s = rcntobj.depth2goobjs[0] ns_nt = [(o.namespace, ntobj(D1="", dcnt=go2dcnt[o.id], goobj=o)) for o in d0s] ret...
python
{ "resource": "" }
q224035
WrXlsxSortedGos._get_xlsx_kws
train
def _get_xlsx_kws(self, **kws_usr): """Return keyword arguments relevant to writing an xlsx.""" kws_xlsx = {'fld2col_widths':self._get_fld2col_widths(**kws_usr), 'items':'GO IDs'} remaining_keys = set(['title', 'hdrs', 'prt_flds', 'fld2fmt', 'ntval2wbfmtdict', 'ntfl...
python
{ "resource": "" }
q224036
WrXlsxSortedGos._adjust_prt_flds
train
def _adjust_prt_flds(self, kws_xlsx, desc2nts, shade_hdrgos): """Print user-requested fields or provided fields minus info fields.""" # Use xlsx prt_flds from the user, if provided if "prt_flds" in kws_xlsx: return kws_xlsx["prt_flds"] # If the user did not provide specific f...
python
{ "resource": "" }
q224037
WrXlsxSortedGos._get_fld2col_widths
train
def _get_fld2col_widths(self, **kws): """Return xlsx column widths based on default and user-specified field-value pairs.""" fld2col_widths = self._init_fld2col_widths() if 'fld2col_widths' not in kws: return fld2col_widths for fld, val in kws['fld2col_widths'].items(): ...
python
{ "resource": "" }
q224038
WrXlsxSortedGos._init_fld2col_widths
train
def _init_fld2col_widths(self): """Return default column widths for writing an Excel Spreadsheet.""" # GO info namedtuple fields: NS dcnt level depth GO D1 name # GO header namedtuple fields: format_txt hdr_idx fld2col_widths = GoSubDagWr.fld2col_widths.copy() for fld, wid in sel...
python
{ "resource": "" }
q224039
WrXlsxSortedGos._get_shade_hdrgos
train
def _get_shade_hdrgos(**kws): """If no hdrgo_prt specified, and these conditions are present -> hdrgo_prt=F.""" # KWS: shade_hdrgos hdrgo_prt section_sortby top_n if 'shade_hdrgos' in kws: return kws['shade_hdrgos'] # Return user-sepcified hdrgo_prt, if provided if 'h...
python
{ "resource": "" }
q224040
MgrNtGOEAs.dflt_sortby_objgoea
train
def dflt_sortby_objgoea(goea_res): """Default sorting of GOEA results.""" return [getattr(goea_res, 'enrichment'), getattr(goea_res, 'namespace'), getattr(goea_res, 'p_uncorrected'), getattr(goea_res, 'depth'), getattr(goea_res, 'GO')]
python
{ "resource": "" }
q224041
MgrNtGOEAs.dflt_sortby_ntgoea
train
def dflt_sortby_ntgoea(ntgoea): """Default sorting of GOEA results stored in namedtuples.""" return [ntgoea.enrichment, ntgoea.namespace, ntgoea.p_uncorrected, ntgoea.depth, ntgoea.GO]
python
{ "resource": "" }
q224042
MgrNtGOEAs.get_goea_nts_prt
train
def get_goea_nts_prt(self, fldnames=None, **usr_kws): """Return list of namedtuples removing fields which are redundant or verbose.""" kws = usr_kws.copy() if 'not_fldnames' not in kws: kws['not_fldnames'] = ['goterm', 'parents', 'children', 'id'] if 'rpt_fmt' not in kws: ...
python
{ "resource": "" }
q224043
MgrNtGOEAs._get_field_values
train
def _get_field_values(item, fldnames, rpt_fmt=None, itemid2name=None): """Return fieldnames and values of either a namedtuple or GOEnrichmentRecord.""" if hasattr(item, "_fldsdefprt"): # Is a GOEnrichmentRecord return item.get_field_values(fldnames, rpt_fmt, itemid2name) if hasattr(i...
python
{ "resource": "" }
q224044
MgrNtGOEAs._get_fieldnames
train
def _get_fieldnames(item): """Return fieldnames of either a namedtuple or GOEnrichmentRecord.""" if hasattr(item, "_fldsdefprt"): # Is a GOEnrichmentRecord return item.get_prtflds_all() if hasattr(item, "_fields"): # Is a namedtuple return item._fields
python
{ "resource": "" }
q224045
GrouperColors.get_bordercolor
train
def get_bordercolor(self): """Get bordercolor based on hdrgos and usergos.""" hdrgos_all = self.grprobj.hdrobj.get_hdrgos() hdrgos_unused = hdrgos_all.difference(self.hdrgos_actual) go2bordercolor = {} # hdrgos that went unused for hdrgo in hdrgos_unused: go2b...
python
{ "resource": "" }
q224046
GrouperColors.get_go2color_users
train
def get_go2color_users(self, usrgo_color='#feffa3', # yellow hdrusrgo_color='#d4ffea', # green hdrgo_color='#eee6f6'): # purple """Get go2color for GO DAG plots.""" go2color = {} # Color user GO IDs for goid...
python
{ "resource": "" }
q224047
AArtGeneProductSetsAll.run
train
def run(self, name, goea_nts, log): """Run gene product ASCII art.""" objaart = AArtGeneProductSetsOne(name, goea_nts, self) if self.hdrobj.sections: return objaart.prt_report_grp1(log) else: return objaart.prt_report_grp0(log)
python
{ "resource": "" }
q224048
AArtGeneProductSetsAll.get_chr2idx
train
def get_chr2idx(self): """Return a dict with the ASCII art character as key and its index as value.""" return {chr(ascii_int):idx for idx, ascii_int in enumerate(self.all_chrints)}
python
{ "resource": "" }
q224049
AArtGeneProductSetsAll._init_kws
train
def _init_kws(self): """Fill default values for keyword args, if necessary.""" # Return user-specified GO formatting, if specfied: if 'fmtgo' not in self.kws: self.kws['fmtgo'] = self.grprdflt.gosubdag.prt_attr['fmt'] + "\n" if 'fmtgo2' not in self.kws: self.kws['...
python
{ "resource": "" }
q224050
InitGOs._init_relationships
train
def _init_relationships(self, relationships_arg): """Return a set of relationships found in all subset GO Terms.""" if relationships_arg: relationships_all = self._get_all_relationships() if relationships_arg is True: return relationships_all else: ...
python
{ "resource": "" }
q224051
InitGOs._get_all_relationships
train
def _get_all_relationships(self): """Return all relationships seen in GO Dag subset.""" relationships_all = set() for goterm in self.go2obj.values(): if goterm.relationship: relationships_all.update(goterm.relationship) if goterm.relationship_rev: ...
python
{ "resource": "" }
q224052
InitGOs._init_gos
train
def _init_gos(self, go_sources_arg, relationships_arg): """Initialize GO sources.""" # No GO sources provided if not go_sources_arg: assert self.go2obj_orig, "go2obj MUST BE PRESENT IF go_sources IS NOT" self.go_sources = set(self.go2obj_orig) self.go2obj = se...
python
{ "resource": "" }
q224053
InitGOs._add_goterms_kws
train
def _add_goterms_kws(self, go2obj_user, kws_gos): """Add more GOTerms to go2obj_user, if requested and relevant.""" if 'go2color' in kws_gos: for goid in kws_gos['go2color'].keys(): self._add_goterms(go2obj_user, goid)
python
{ "resource": "" }
q224054
InitGOs._add_goterms
train
def _add_goterms(self, go2obj_user, goid): """Add alt GO IDs to go2obj subset, if requested and relevant.""" goterm = self.go2obj_orig[goid] if goid != goterm.id and goterm.id in go2obj_user and goid not in go2obj_user: go2obj_user[goid] = goterm
python
{ "resource": "" }
q224055
InitGOs._init_go_sources
train
def _init_go_sources(self, go_sources_arg, go2obj_arg): """Return GO sources which are present in GODag.""" gos_user = set(go_sources_arg) if 'children' in self.kws and self.kws['children']: gos_user |= get_leaf_children(gos_user, go2obj_arg) gos_godag = set(go2obj_arg) ...
python
{ "resource": "" }
q224056
InitFields.get_rcntobj
train
def get_rcntobj(self): """Return None or user-provided CountRelatives object.""" # rcntobj value in kws can be: None, False, True, CountRelatives object if 'rcntobj' in self.kws: rcntobj = self.kws['rcntobj'] if isinstance(rcntobj, CountRelatives): return ...
python
{ "resource": "" }
q224057
InitFields.get_prt_fmt
train
def get_prt_fmt(self, alt=False): """Return the format for printing GO named tuples and their related information.""" # prt_fmt = [ # rcnt # '{GO} # {NS} L{level:02} D{depth:02} {GO_name}', # '{GO} # {NS} {dcnt:6,} L{level:0...
python
{ "resource": "" }
q224058
InitFields._init_kwelems
train
def _init_kwelems(self): """Init set elements.""" ret = set() if 'rcntobj' in self.kws: ret.add('dcnt') ret.add('D1') if 'tcntobj' in self.kws: ret.add('tcnt') ret.add('tfreq') ret.add('tinfo') return ret
python
{ "resource": "" }
q224059
AnnotationExtensions.get_relations_cnt
train
def get_relations_cnt(self): """Get the set of all relations.""" return cx.Counter([e.relation for es in self.exts for e in es])
python
{ "resource": "" }
q224060
Go2Color._init_equiv
train
def _init_equiv(self): """Add equivalent GO IDs to go2color, if necessary.""" gocolored_all = set(self.go2color) go2obj_usr = self.gosubdag.go2obj go2color_add = {} for gocolored_cur, color in self.go2color.items(): # Ignore GOs in go2color that are not in the user se...
python
{ "resource": "" }
q224061
GOEnrichmentRecord.get_pvalue
train
def get_pvalue(self): """Returns pval for 1st method, if it exists. Else returns uncorrected pval.""" if self.method_flds: return getattr(self, "p_{m}".format(m=self.get_method_name())) return getattr(self, "p_uncorrected")
python
{ "resource": "" }
q224062
GOEnrichmentRecord.set_corrected_pval
train
def set_corrected_pval(self, nt_method, pvalue): """Add object attribute based on method name.""" self.method_flds.append(nt_method) fieldname = "".join(["p_", nt_method.fieldname]) setattr(self, fieldname, pvalue)
python
{ "resource": "" }
q224063
GOEnrichmentRecord._chk_fields
train
def _chk_fields(field_data, field_formatter): """Check that expected fields are present.""" if len(field_data) == len(field_formatter): return len_dat = len(field_data) len_fmt = len(field_formatter) msg = [ "FIELD DATA({d}) != FORMATTER({f})".format(d=len...
python
{ "resource": "" }
q224064
GOEnrichmentRecord.set_goterm
train
def set_goterm(self, go2obj): """Set goterm and copy GOTerm's name and namespace.""" if self.GO in go2obj: goterm = go2obj[self.GO] self.goterm = goterm self.name = goterm.name self.depth = goterm.depth self.NS = self.namespace2NS[self.goterm.n...
python
{ "resource": "" }
q224065
GOEnrichmentRecord._init_enrichment
train
def _init_enrichment(self): """Mark as 'enriched' or 'purified'.""" if self.study_n: return 'e' if ((1.0 * self.study_count / self.study_n) > (1.0 * self.pop_count / self.pop_n)) else 'p' return 'p'
python
{ "resource": "" }
q224066
GOEnrichmentRecord.get_prtflds_default
train
def get_prtflds_default(self): """Get default fields.""" return self._fldsdefprt[:-1] + \ ["p_{M}".format(M=m.fieldname) for m in self.method_flds] + \ [self._fldsdefprt[-1]]
python
{ "resource": "" }
q224067
GOEnrichmentRecord.get_prtflds_all
train
def get_prtflds_all(self): """When converting to a namedtuple, get all possible fields in their original order.""" flds = [] dont_add = set(['_parents', 'method_flds', 'relationship_rev', 'relationship']) # Fields: GO NS enrichment name ratio_in_study ratio_in_pop p_uncorrected #...
python
{ "resource": "" }
q224068
GOEnrichmentRecord._flds_append
train
def _flds_append(flds, addthese, dont_add): """Retain order of fields as we add them once to the list.""" for fld in addthese: if fld not in flds and fld not in dont_add: flds.append(fld)
python
{ "resource": "" }
q224069
GOEnrichmentRecord.get_field_values
train
def get_field_values(self, fldnames, rpt_fmt=True, itemid2name=None): """Get flat namedtuple fields for one GOEnrichmentRecord.""" row = [] # Loop through each user field desired for fld in fldnames: # 1. Check the GOEnrichmentRecord's attributes val = getattr(sel...
python
{ "resource": "" }
q224070
GOEnrichmentRecord._get_rpt_fmt
train
def _get_rpt_fmt(fld, val, itemid2name=None): """Return values in a format amenable to printing in a table.""" if fld.startswith("ratio_"): return "{N}/{TOT}".format(N=val[0], TOT=val[1]) elif fld in set(['study_items', 'pop_items', 'alt_ids']): if itemid2name is not None...
python
{ "resource": "" }
q224071
GOEnrichmentRecord._err_fld
train
def _err_fld(self, fld, fldnames): """Unrecognized field. Print detailed Failure message.""" msg = ['ERROR. UNRECOGNIZED FIELD({F})'.format(F=fld)] actual_flds = set(self.get_prtflds_default() + self.goterm.__dict__.keys()) bad_flds = set(fldnames).difference(set(actual_flds)) if...
python
{ "resource": "" }
q224072
GOEnrichmentStudy.run_study_nts
train
def run_study_nts(self, study, **kws): """Run GOEA on study ids. Return results as a list of namedtuples.""" goea_results = self.run_study(study, **kws) return MgrNtGOEAs(goea_results).get_goea_nts_all()
python
{ "resource": "" }
q224073
GOEnrichmentStudy.get_results_msg
train
def get_results_msg(self, results, study): """Return summary for GOEA results.""" # To convert msg list to string: "\n".join(msg) msg = [] if results: fmt = "{M:6,} GO terms are associated with {N:6,} of {NT:6,}" stu_items, num_gos_stu = self.get_item_cnt(results,...
python
{ "resource": "" }
q224074
GOEnrichmentStudy.get_pval_uncorr
train
def get_pval_uncorr(self, study, log=sys.stdout): """Calculate the uncorrected pvalues for study items.""" results = [] study_in_pop = self.pop.intersection(study) # " 99% 378 of 382 study items found in population" go2studyitems = get_terms("study", study_in_pop, self.asso...
python
{ "resource": "" }
q224075
GOEnrichmentStudy.get_study_items
train
def get_study_items(results): """Return a list of study items associated with the given results.""" study_items = set() for obj in results: study_items.update(obj.study_items) return study_items
python
{ "resource": "" }
q224076
GOEnrichmentStudy._update_pvalcorr
train
def _update_pvalcorr(ntmt, corrected_pvals): """Add data members to store multiple test corrections.""" if corrected_pvals is None: return for rec, val in zip(ntmt.results, corrected_pvals): rec.set_corrected_pval(ntmt.nt_method, val)
python
{ "resource": "" }
q224077
GOEnrichmentStudy.wr_txt
train
def wr_txt(self, fout_txt, goea_results, prtfmt=None, **kws): """Print GOEA results to text file.""" if not goea_results: sys.stdout.write(" 0 GOEA results. NOT WRITING {FOUT}\n".format(FOUT=fout_txt)) return with open(fout_txt, 'w') as prt: if 'title' in...
python
{ "resource": "" }
q224078
GOEnrichmentStudy.prt_txt
train
def prt_txt(prt, goea_results, prtfmt=None, **kws): """Print GOEA results in text format.""" objprt = PrtFmt() if prtfmt is None: flds = ['GO', 'NS', 'p_uncorrected', 'ratio_in_study', 'ratio_in_pop', 'depth', 'name', 'study_items'] prtfmt = objprt.get...
python
{ "resource": "" }
q224079
GOEnrichmentStudy.wr_xlsx
train
def wr_xlsx(self, fout_xlsx, goea_results, **kws): """Write a xlsx file.""" # kws: prt_if indent itemid2name(study_items) objprt = PrtFmt() prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results)) xlsx_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws...
python
{ "resource": "" }
q224080
GOEnrichmentStudy.wr_tsv
train
def wr_tsv(self, fout_tsv, goea_results, **kws): """Write tab-separated table data to file""" prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results)) tsv_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws) RPT.wr_tsv(fout_tsv, tsv_data, **kws)
python
{ "resource": "" }
q224081
GOEnrichmentStudy.prt_tsv
train
def prt_tsv(self, prt, goea_results, **kws): """Write tab-separated table data""" prt_flds = kws.get('prt_flds', self.get_prtflds_default(goea_results)) tsv_data = MgrNtGOEAs(goea_results).get_goea_nts_prt(prt_flds, **kws) RPT.prt_tsv(prt, tsv_data, **kws)
python
{ "resource": "" }
q224082
GOEnrichmentStudy.get_ns2nts
train
def get_ns2nts(results, fldnames=None, **kws): """Get namedtuples of GOEA results, split into BP, MF, CC.""" ns2nts = cx.defaultdict(list) nts = MgrNtGOEAs(results).get_goea_nts_all(fldnames, **kws) for ntgoea in nts: ns2nts[ntgoea.NS].append(ntgoea) return ns2nts
python
{ "resource": "" }
q224083
GOEnrichmentStudy.print_date
train
def print_date(min_ratio=None, pval=0.05): """Print GOATOOLS version and the date the GOEA was run.""" import goatools # Header contains provenance and parameters date = datetime.date.today() print("# Generated by GOATOOLS v{0} ({1})".format(goatools.__version__, date)) ...
python
{ "resource": "" }
q224084
GOEnrichmentStudy.print_results
train
def print_results(self, results, min_ratio=None, indent=False, pval=0.05, prt=sys.stdout): """Print GOEA results with some additional statistics calculated.""" results_adj = self.get_adj_records(results, min_ratio, pval) self.print_results_adj(results_adj, indent, prt)
python
{ "resource": "" }
q224085
GOEnrichmentStudy.get_adj_records
train
def get_adj_records(results, min_ratio=None, pval=0.05): """Return GOEA results with some additional statistics calculated.""" records = [] for rec in results: # calculate some additional statistics # (over_under, is_ratio_different) rec.update_remaining_fldsd...
python
{ "resource": "" }
q224086
GOEnrichmentStudy.print_results_adj
train
def print_results_adj(results, indent=False, prt=sys.stdout): """Print GOEA results.""" # Print column headers if there are results to be printed if results: prt.write("{R}\n".format(R="\t".join(GOEnrichmentStudy.get_prtflds_default(results)))) # Print the GOEA results ...
python
{ "resource": "" }
q224087
GOEnrichmentStudy.wr_py_goea_results
train
def wr_py_goea_results(self, fout_py, goea_results, **kws): """Save GOEA results into Python package containing list of namedtuples.""" var_name = kws.get("var_name", "goea_results") docstring = kws.get("docstring", "") sortby = kws.get("sortby", None) if goea_results: ...
python
{ "resource": "" }
q224088
_ensure_click
train
def _ensure_click(self): """Ensures a click gets made, because Selenium can be a bit buggy about clicks This method gets added to the selenium element returned in '__ensure_element_by_xpath'. We should probably add it to more selenium methods, such as all the 'find**' methods though. I wrote this meth...
python
{ "resource": "" }
q224089
Session.transfer_session_cookies_to_driver
train
def transfer_session_cookies_to_driver(self, domain=None): """Copies the Session's cookies into the webdriver Using the 'domain' parameter we choose the cookies we wish to transfer, we only transfer the cookies which belong to that domain. The domain defaults to our last visited site if...
python
{ "resource": "" }
q224090
Session.copy_user_agent_from_driver
train
def copy_user_agent_from_driver(self): """ Updates requests' session user-agent with the driver's user agent This method will start the browser process if its not already running. """ selenium_user_agent = self.driver.execute_script("return navigator.userAgent;") self.headers.up...
python
{ "resource": "" }
q224091
DriverMixin.ensure_add_cookie
train
def ensure_add_cookie(self, cookie, override_domain=None): """Ensures a cookie gets added to the driver Selenium needs the driver to be currently at the domain of the cookie before allowing you to add it, so we need to get through this limitation. The cookie parameter is a dict which m...
python
{ "resource": "" }
q224092
DriverMixin.is_cookie_in_driver
train
def is_cookie_in_driver(self, cookie): """We check that the cookie is correctly added to the driver We only compare name, value and domain, as the rest can produce false negatives. We are a bit lenient when comparing domains. """ for driver_cookie in self.get_cookies(): ...
python
{ "resource": "" }
q224093
DriverMixin.ensure_element
train
def ensure_element(self, locator, selector, state="present", timeout=None): """This method allows us to wait till an element appears or disappears in the browser The webdriver runs in parallel with our scripts, so we must wait for it everytime it runs javascript. Selenium automatically waits ti...
python
{ "resource": "" }
q224094
parse_buffer_to_ppm
train
def parse_buffer_to_ppm(data): """ Parse PPM file bytes to Pillow Image """ images = [] index = 0 while index < len(data): code, size, rgb = tuple(data[index:index + 40].split(b'\n')[0:3]) size_x, size_y = tuple(size.split(b' ')) file_size = len(code) + len(size) +...
python
{ "resource": "" }
q224095
parse_buffer_to_jpeg
train
def parse_buffer_to_jpeg(data): """ Parse JPEG file bytes to Pillow Image """ return [ Image.open(BytesIO(image_data + b'\xff\xd9')) for image_data in data.split(b'\xff\xd9')[:-1] # Last element is obviously empty ]
python
{ "resource": "" }
q224096
parse_buffer_to_png
train
def parse_buffer_to_png(data): """ Parse PNG file bytes to Pillow Image """ images = [] c1 = 0 c2 = 0 data_len = len(data) while c1 < data_len: # IEND can appear in a PNG without being the actual end if data[c2:c2 + 4] == b'IEND' and (c2 + 8 == data_len or data[c2+9...
python
{ "resource": "" }
q224097
configure
train
def configure(*args, **kwargs): """ Configure logging. Borrowed from logging.basicConfig Uses the IndentFormatter instead of the regular Formatter Also, opts the caller into Syslog output, unless syslog could not be opened for some reason or another, in which case a warning will be printe...
python
{ "resource": "" }
q224098
get_syslog_facility
train
def get_syslog_facility(): """Get syslog facility from ENV var""" facil = os.getenv('WALE_SYSLOG_FACILITY', 'user') valid_facility = True try: facility = handlers.SysLogHandler.facility_names[facil.lower()] except KeyError: valid_facility = False facility = handlers.SysLogHa...
python
{ "resource": "" }
q224099
set_level
train
def set_level(level): """Adjust the logging level of WAL-E""" for handler in HANDLERS: handler.setLevel(level) logging.root.setLevel(level)
python
{ "resource": "" }