idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
34,300 | def sortby ( self , ntd ) : if 'reldepth' in self . grprobj . gosubdag . prt_attr [ 'flds' ] : return [ ntd . NS , - 1 * ntd . dcnt , ntd . reldepth ] else : return [ ntd . NS , - 1 * ntd . dcnt , ntd . depth ] | Return function for sorting . |
34,301 | def get_nts_sorted ( self , hdrgo_prt , hdrgos , hdrgo_sort ) : nts_flat = [ ] self . get_sorted_hdrgo2usrgos ( hdrgos , nts_flat , hdrgo_prt , hdrgo_sort ) return nts_flat | Return a flat list of grouped and sorted GO terms . |
34,302 | def get_sorted_hdrgo2usrgos ( self , hdrgos , flat_list = None , hdrgo_prt = True , hdrgo_sort = True ) : sorted_hdrgos_usrgos = [ ] h2u_get = self . grprobj . hdrgo2usrgos . get hdr_go2nt = self . _get_go2nt ( hdrgos ) if hdrgo_sort is True : hdr_go2nt = sorted ( hdr_go2nt . items ( ) , key = lambda t : self . hdrgo_s... | Return GO IDs sorting using go2nt s namedtuple . |
34,303 | def _get_go2nt ( self , goids ) : go2nt_all = self . grprobj . go2nt return { go : go2nt_all [ go ] for go in goids } | Get go2nt for given goids . |
34,304 | def _init_hdrgo_sortby ( self , hdrgo_sortby , sortby ) : if hdrgo_sortby is not None : return hdrgo_sortby if sortby is not None : return sortby return self . sortby | Initialize header sort function . |
34,305 | def plot_goid2goobj ( fout_png , goid2goobj , * args , ** kws ) : engine = kws [ 'engine' ] if 'engine' in kws else 'pydot' godagsmall = OboToGoDagSmall ( goid2goobj = goid2goobj ) . godag godagplot = GODagSmallPlot ( godagsmall , * args , ** kws ) godagplot . plt ( fout_png , engine ) | Given a dict containing GO id and its goobj create a plot of paths from GO ids . |
34,306 | def _init_study_items_max ( self ) : if self . study_items is None : return None if self . study_items is True : return None if isinstance ( self . study_items , int ) : return self . study_items return None | User can limit the number of genes printed in a GO term . |
34,307 | def _init_go2res ( ** kws ) : if 'goea_results' in kws : return { res . GO : res for res in kws [ 'goea_results' ] } if 'go2nt' in kws : return kws [ 'go2nt' ] | Initialize GOEA results . |
34,308 | def _get_pydot ( self ) : if self . pydot : return self . pydot self . pydot = __import__ ( "pydot" ) return self . pydot | Return pydot package . Load pydot if necessary . |
34,309 | def wr_xlsx ( fout_xlsx , data_xlsx , ** kws ) : from goatools . wr_tbl_class import WrXlsx items_str = kws . get ( "items" , "items" ) if "items" not in kws else kws [ "items" ] if data_xlsx : xlsxobj = WrXlsx ( fout_xlsx , data_xlsx [ 0 ] . _fields , ** kws ) worksheet = xlsxobj . add_worksheet ( ) row_idx = xlsxobj ... | Write a spreadsheet into a xlsx file . |
34,310 | def wr_xlsx_sections ( fout_xlsx , xlsx_data , ** kws ) : from goatools . wr_tbl_class import WrXlsx items_str = "items" if "items" not in kws else kws [ "items" ] prt_hdr_min = 10 num_items = 0 if xlsx_data : assert len ( xlsx_data [ 0 ] ) == 2 , "wr_xlsx_sections EXPECTED: [(section, nts), ..." assert xlsx_data [ 0 ]... | Write xlsx file containing section names followed by lines of namedtuple data . |
34,311 | def wr_tsv ( fout_tsv , tsv_data , ** kws ) : items_str = "items" if "items" not in kws else kws [ "items" ] if tsv_data : ifstrm = sys . stdout if fout_tsv is None else open ( fout_tsv , 'w' ) num_items = prt_tsv ( ifstrm , tsv_data , ** kws ) if fout_tsv is not None : sys . stdout . write ( " {N:>5} {ITEMS} WROTE: {... | Write a file of tab - separated table data |
34,312 | def prt_tsv_sections ( prt , tsv_data , ** kws ) : prt_hdr_min = 10 num_items = 0 if tsv_data : assert len ( tsv_data [ 0 ] ) == 2 , "wr_tsv_sections EXPECTED: [(section, nts), ..." assert tsv_data [ 0 ] [ 1 ] , "wr_tsv_sections EXPECTED SECTION({S}) LIST TO HAVE DATA" . format ( S = tsv_data [ 0 ] [ 0 ] ) hdrs_wrote =... | Write tsv file containing section names followed by lines of namedtuple data . |
34,313 | def prt_tsv ( prt , data_nts , ** kws ) : prt_tsv_hdr ( prt , data_nts , ** kws ) return prt_tsv_dat ( prt , data_nts , ** kws ) | Print tab - separated table headers and data |
34,314 | def prt_tsv_hdr ( prt , data_nts , ** kws ) : sep = "\t" if 'sep' not in kws else kws [ 'sep' ] flds_all = data_nts [ 0 ] . _fields hdrs = get_hdrs ( flds_all , ** kws ) prt . write ( "# {}\n" . format ( sep . join ( hdrs ) ) ) | Print tab - separated table headers |
34,315 | def prt_tsv_dat ( prt , data_nts , ** kws ) : sep = "\t" if 'sep' not in kws else kws [ 'sep' ] fld2fmt = None if 'fld2fmt' not in kws else kws [ 'fld2fmt' ] if 'sort_by' in kws : data_nts = sorted ( data_nts , key = kws [ 'sort_by' ] ) prt_if = kws [ 'prt_if' ] if 'prt_if' in kws else None prt_flds = kws [ 'prt_flds' ... | Print tab - separated table data |
34,316 | def _chk_flds_fmt ( nt_fields , prtfmt ) : fmtflds = get_fmtflds ( prtfmt ) missing_data = set ( fmtflds ) . difference ( set ( nt_fields ) ) if not missing_data : return msg = [ 'CANNOT PRINT USING: "{PF}"' . format ( PF = prtfmt . rstrip ( ) ) ] for fld in fmtflds : errmrk = "" if fld in nt_fields else "ERROR msg . a... | Check that all fields in the prtfmt have corresponding data in the namedtuple . |
34,317 | def _prt_txt_hdr ( prt , prtfmt ) : tblhdrs = get_fmtfldsdict ( prtfmt ) hdrfmt = re . sub ( r':(\d+)\.\S+}' , r':\1}' , prtfmt ) hdrfmt = re . sub ( r':(0+)(\d+)}' , r':\2}' , hdrfmt ) prt . write ( "#{}" . format ( hdrfmt . format ( ** tblhdrs ) ) ) | Print header for text report . |
34,318 | def mk_fmtfld ( nt_item , joinchr = " " , eol = "\n" ) : fldstrs = [ ] fld2fmt = { 'hdrgo' : lambda f : "{{{FLD}:1,}}" . format ( FLD = f ) , 'dcnt' : lambda f : "{{{FLD}:6,}}" . format ( FLD = f ) , 'level' : lambda f : "L{{{FLD}:02,}}" . format ( FLD = f ) , 'depth' : lambda f : "D{{{FLD}:02,}}" . format ( FLD = f ) ... | Given a namedtuple return a format_field string . |
34,319 | def _get_prtfmt ( self , objgowr , verbose ) : prtfmt = objgowr . get_prtfmt ( 'fmt' ) prtfmt = prtfmt . replace ( '# ' , '' ) if not verbose : prtfmt = prtfmt . replace ( '{hdr1usr01:2}' , '' ) prtfmt = prtfmt . replace ( '{childcnt:3} L{level:02} ' , '' ) prtfmt = prtfmt . replace ( '{num_usrgos:>4} uGOs ' , '' ) prt... | Get print format containing markers . |
34,320 | def _wr_ver_n_key ( self , fout_txt , verbose ) : with open ( fout_txt , 'w' ) as prt : self . _prt_ver_n_key ( prt , verbose ) print ( ' WROTE: {TXT}' . format ( TXT = fout_txt ) ) | Write GO DAG version and key indicating presence of GO ID in a list . |
34,321 | def _prt_ver_n_key ( self , prt , verbose ) : pre = '# ' prt . write ( '# ----------------------------------------------------------------\n' ) prt . write ( '# - Description of GO ID fields\n' ) prt . write ( '# ----------------------------------------------------------------\n' ) prt . write ( "# Versions:\n# {VER... | Print GO DAG version and key indicating presence of GO ID in a list . |
34,322 | def get_grouped ( self , go_ntsets , go_all , gosubdag , ** kws ) : kws_grpd = { k : v for k , v in kws . items ( ) if k in Grouped . kws_dict } kws_grpd [ 'go2nt' ] = self . _init_go2ntpresent ( go_ntsets , go_all , gosubdag ) return Grouped ( gosubdag , self . godag . version , ** kws_grpd ) | Get Grouped object . |
34,323 | def _init_go2ntpresent ( go_ntsets , go_all , gosubdag ) : go2ntpresent = { } ntobj = namedtuple ( 'NtPresent' , " " . join ( nt . hdr for nt in go_ntsets ) ) for goid_all in go_all : present_true = [ goid_all in nt . go_set for nt in go_ntsets ] present_str = [ 'X' if tf else '.' for tf in present_true ] go2ntpresent ... | Mark all GO IDs with an X if present in the user GO list . |
34,324 | def get_go_ntsets ( self , go_fins ) : nts = [ ] ntobj = namedtuple ( 'NtGOFiles' , 'hdr go_set, go_fin' ) go_sets = self . _init_go_sets ( go_fins ) hdrs = [ os . path . splitext ( os . path . basename ( f ) ) [ 0 ] for f in go_fins ] assert len ( go_fins ) == len ( go_sets ) assert len ( go_fins ) == len ( hdrs ) for... | For each file containing GOs extract GO IDs store filename and header . |
34,325 | def _init_go_sets ( self , go_fins ) : go_sets = [ ] assert go_fins , "EXPECTED FILES CONTAINING GO IDs" assert len ( go_fins ) >= 2 , "EXPECTED 2+ GO LISTS. FOUND: {L}" . format ( L = ' ' . join ( go_fins ) ) obj = GetGOs ( self . godag ) for fin in go_fins : assert os . path . exists ( fin ) , "GO FILE({F}) DOES NOT ... | Get lists of GO IDs . |
34,326 | def get_parents_letters ( self , goobj ) : parents_all = set . union ( self . go2parents [ goobj . id ] ) parents_all . add ( goobj . id ) parents_d1 = parents_all . intersection ( self . gos_depth1 ) return [ self . goone2ntletter [ g ] . D1 for g in parents_d1 ] | Get the letters representing all parent terms which are depth - 01 GO terms . |
34,327 | def get_d1str ( self , goobj , reverse = False ) : return "" . join ( sorted ( self . get_parents_letters ( goobj ) , reverse = reverse ) ) | Get D1 - string representing all parent terms which are depth - 01 GO terms . |
34,328 | def get_most_specific_dcnt ( goids , go2nt ) : return min ( _get_go2nt ( goids , go2nt ) , key = lambda t : t [ 1 ] . dcnt ) [ 0 ] | Get the GO ID with the lowest descendants count . |
34,329 | def _get_go2nt ( goids , go2nt_all ) : go_nt_list = [ ] goids_seen = set ( ) for goid_usr in goids : ntgo = go2nt_all [ goid_usr ] goid_main = ntgo . id if goid_main not in goids_seen : goids_seen . add ( goid_main ) go_nt_list . append ( ( goid_main , ntgo ) ) return go_nt_list | Get user go2nt using main GO IDs not alt IDs . |
34,330 | def prt_gos_grouped ( self , prt , ** kws_grp ) : prtfmt = self . datobj . kws [ 'fmtgo' ] wrobj = WrXlsxSortedGos ( self . name , self . sortobj ) desc2nts = self . sortobj . get_desc2nts ( ** kws_grp ) wrobj . prt_txt_desc2nts ( prt , desc2nts , prtfmt ) | Print grouped GO list . |
34,331 | def prt_gos_flat ( self , prt ) : prtfmt = self . datobj . kws [ 'fmtgo' ] _go2nt = self . sortobj . grprobj . go2nt go2nt = { go : _go2nt [ go ] for go in self . go2nt } prt . write ( "\n{N} GO IDs:\n" . format ( N = len ( go2nt ) ) ) _sortby = self . _get_sortgo ( ) for ntgo in sorted ( go2nt . values ( ) , key = _so... | Print flat GO list . |
34,332 | def _get_sortgo ( self ) : if 'sortgo' in self . datobj . kws : return self . datobj . kws [ 'sortgo' ] return self . datobj . grprdflt . gosubdag . prt_attr [ 'sort' ] + "\n" | Get function for sorting GO terms in a list of namedtuples . |
34,333 | def get_gene2binvec ( self ) : _sec2chr = self . sec2chr return { g : [ s in s2gos for s in _sec2chr ] for g , s2gos in self . gene2section2gos . items ( ) } | Return a boolean vector for each gene representing GO section membership . |
34,334 | def get_go2nt ( self , goea_results ) : go2obj = self . objaartall . grprdflt . gosubdag . go2obj goea_nts = MgrNtGOEAs ( goea_results ) . get_nts_strpval ( ) return { go2obj [ nt . GO ] . id : nt for nt in goea_nts if nt . GO in go2obj } | Return go2nt with added formatted string versions of the P - values . |
34,335 | def get_sec2gos ( sortobj ) : sec_gos = [ ] for section_name , nts in sortobj . get_desc2nts_fnc ( hdrgo_prt = True ) [ 'sections' ] : sec_gos . append ( ( section_name , set ( nt . GO for nt in nts ) ) ) return cx . OrderedDict ( sec_gos ) | Initialize section_name2goids . |
34,336 | def get_gene2gos ( go2nt ) : gene2gos = cx . defaultdict ( set ) nt0 = next ( iter ( go2nt . values ( ) ) ) b_str = isinstance ( nt0 . study_items , str ) for goid , ntgo in go2nt . items ( ) : study_items = ntgo . study_items . split ( ', ' ) if b_str else ntgo . study_items for geneid in study_items : gene2gos [ gene... | Create a gene product to GO set dict . |
34,337 | def get_gene2aart ( gene2section2gos , sec2chr ) : geneid2str = { } for geneid , section2gos_gene in gene2section2gos . items ( ) : letters = [ abc if s in section2gos_gene else "." for s , abc in sec2chr . items ( ) ] geneid2str [ geneid ] = "" . join ( letters ) return geneid2str | Return a string for each gene representing GO section membership . |
34,338 | def get_gene2section2gos ( gene2gos , sec2gos ) : gene2section2gos = { } for geneid , gos_gene in gene2gos . items ( ) : section2gos = { } for section_name , gos_sec in sec2gos . items ( ) : gos_secgene = gos_gene . intersection ( gos_sec ) if gos_secgene : section2gos [ section_name ] = gos_secgene gene2section2gos [ ... | Get a list of section aliases for each gene product ID . |
34,339 | def _init_objcolor ( self , node_opts , ** kwu ) : objgoea = node_opts . kws [ 'dict' ] . get ( 'objgoea' , None ) return Go2Color ( self . gosubdag , objgoea , ** kwu ) | Return user - created Go2Color object or create one . |
34,340 | def _init_gonodeopts ( self , ** kws_usr ) : options = GoNodeOpts ( self . gosubdag , ** self . kws [ 'node_go' ] ) if not options . kws [ 'set' ] . isdisjoint ( [ 'parentcnt' , 'prt_pcnt' ] ) : options . kws [ 'dict' ] [ 'c2ps' ] = self . edgesobj . get_c2ps ( ) if 'goea_results' in kws_usr : objgoea = GoeaResults ( k... | Initialize a GO Node plot options object GoNodeOpts . |
34,341 | def prt_goids ( self , prt ) : fmt = self . gosubdag . prt_attr [ 'fmta' ] nts = sorted ( self . gosubdag . go2nt . values ( ) , key = lambda nt : [ nt . NS , nt . depth , nt . alt ] ) _get_color = self . pydotnodego . go2color . get for ntgo in nts : gostr = fmt . format ( ** ntgo . _asdict ( ) ) col = _get_color ( nt... | Print all GO IDs in the plot plus their color . |
34,342 | def _init_kws ( self , ** kws_usr ) : kws_self = { } user_keys = set ( kws_usr ) for objname , expset in self . exp_keys . items ( ) : usrkeys_curr = user_keys . intersection ( expset ) kws_self [ objname ] = get_kwargs ( kws_usr , usrkeys_curr , usrkeys_curr ) dpi = str ( kws_self [ 'dag' ] . get ( 'dpi' , self . dflt... | Return a dict containing user - specified plotting options . |
34,343 | def _prt_edge ( dag_edge , attr ) : print ( "Edge {ATTR}: {VAL}" . format ( ATTR = attr , VAL = dag_edge . obj_dict [ attr ] ) ) | Print edge attribute |
34,344 | def prt_goids ( self , goids = None , prtfmt = None , sortby = True , prt = sys . stdout ) : if goids is None : goids = self . go_sources nts = self . get_nts ( goids , sortby ) if prtfmt is None : prtfmt = self . prt_attr [ 'fmta' ] for ntgo in nts : key2val = ntgo . _asdict ( ) prt . write ( "{GO}\n" . format ( GO = ... | Given GO IDs print decriptive info about each GO Term . |
34,345 | def get_nts ( self , goids = None , sortby = None ) : nts = [ ] if goids is None : goids = self . go_sources else : chk_goids ( goids , "GoSubDag::get_nts" ) if goids : ntobj = cx . namedtuple ( "NtGo" , " " . join ( self . prt_attr [ 'flds' ] ) ) go2nt = self . get_go2nt ( goids ) for goid , ntgo in self . _get_sorted... | Given GO IDs get a list of namedtuples . |
34,346 | def get_go2nt ( self , goids ) : get_nt = self . go2nt goids_present = set ( goids ) . intersection ( self . go2obj ) if len ( goids_present ) != len ( goids ) : print ( "GO IDs NOT FOUND IN DAG: {GOs}" . format ( GOs = " " . join ( set ( goids ) . difference ( goids_present ) ) ) ) return { g : get_nt [ g ] for g in g... | Return dict of GO ID as key and GO object information in namedtuple . |
34,347 | def get_key_goids ( self , goids ) : go2obj = self . go2obj return set ( go2obj [ go ] . id for go in goids ) | Given GO IDs return key GO IDs . |
34,348 | def prt_objdesc ( self , prt ) : txt = "INITIALIZING GoSubDag: {N:3} sources in {M:3} GOs rcnt({R}). {A} alt GO IDs\n" alt2obj = { go : o for go , o in self . go2obj . items ( ) if go != o . id } prt . write ( txt . format ( N = len ( self . go_sources ) , M = len ( self . go2obj ) , R = self . rcntobj is not None , A ... | Return description of this GoSubDag object . |
34,349 | def _init_taxids ( taxid , taxids ) : ret = set ( ) if taxids is not None : if taxids is True : return True if isinstance ( taxids , int ) : ret . add ( taxids ) else : ret . update ( taxids ) if taxid is not None : ret . add ( taxid ) if not ret : ret . add ( 9606 ) print ( '**NOTE: DEFAULT TAXID STORED FROM gene2go I... | Return taxid set |
34,350 | def init_associations ( self , fin_anno , taxids = None ) : nts = [ ] if fin_anno is None : return nts tic = timeit . default_timer ( ) lnum = - 1 line = "\t" * len ( self . flds ) try : with open ( fin_anno ) as ifstrm : category2ns = { 'Process' : 'BP' , 'Function' : 'MF' , 'Component' : 'CC' } ntobj = cx . namedtupl... | Read annotation file . Store annotation data in a list of namedtuples . |
34,351 | def _prt_line_detail ( self , prt , line , lnum = "" ) : data = zip ( self . flds , line . split ( '\t' ) ) txt = [ "{:2}) {:13} {}" . format ( i , hdr , val ) for i , ( hdr , val ) in enumerate ( data ) ] prt . write ( "{LNUM}\n{TXT}\n" . format ( LNUM = lnum , TXT = '\n' . join ( txt ) ) ) | Print each field and its value . |
34,352 | def chk_associations ( self , fout_err = "gaf.err" ) : obj = GafData ( "2.1" ) return obj . chk ( self . associations , fout_err ) | Check that fields are legal in GAF |
34,353 | def _update_ret ( ret , goids , go2color ) : if goids : ret [ 'GOs' ] . update ( goids ) if go2color : for goid , color in go2color . items ( ) : ret [ 'go2color' ] [ goid ] = color | Update GOs and go2color in dict with goids and go2color . |
34,354 | def _plt_gogrouped ( self , goids , go2color_usr , ** kws ) : fout_img = self . get_outfile ( kws [ 'outfile' ] , goids ) sections = read_sections ( kws [ 'sections' ] , exclude_ungrouped = True ) grprobj_cur = self . _get_grprobj ( goids , sections ) grpcolor = GrouperColors ( grprobj_cur ) grp_go2color = grpcolor . g... | Plot grouped GO IDs . |
34,355 | def _get_grprobj ( self , goids , sections ) : grprdflt = GrouperDflts ( self . gosubdag , "goslim_generic.obo" ) hdrobj = HdrgosSections ( self . gosubdag , grprdflt . hdrgos_dflt , sections ) return Grouper ( "sections" , goids , hdrobj , self . gosubdag ) | Get Grouper given GO IDs and sections . |
34,356 | def _get_kwsdag ( self , goids , go2obj , ** kws_all ) : kws_dag = { } tcntobj = self . _get_tcntobj ( goids , go2obj , ** kws_all ) if tcntobj is not None : kws_dag [ 'tcntobj' ] = tcntobj if 'go_aliases' in kws_all : fin_go_aliases = kws_all [ 'go_aliases' ] if os . path . exists ( fin_go_aliases ) : go2letter = read... | Get keyword args for a GoSubDag . |
34,357 | def _chk_docopts ( self , kws ) : outfile = kws [ 'outfile' ] if len ( kws ) == 2 and os . path . basename ( kws [ 'obo' ] ) == "go-basic.obo" and kws [ 'outfile' ] == self . dflt_outfile : self . _err ( "NO GO IDS SPECFIED" , err = False ) if 'obo' in outfile : self . _err ( "BAD outfile({O})" . format ( O = outfile )... | Check for common user command - line errors . |
34,358 | def _err ( self , msg , err = True ) : severity = "FATAL" if err else "NOTE" txt = "" . join ( [ self . objdoc . doc , "User's command-line:\n\n" , " % go_plot.py {ARGS}\n\n" . format ( ARGS = " " . join ( sys . argv [ 1 : ] ) ) , "**{SEV}: {MSG}\n" . format ( SEV = severity , MSG = msg ) ] ) if err : raise RuntimeErr... | Print useage and error before exiting . |
34,359 | def get_outfile ( self , outfile , goids = None ) : if outfile != self . dflt_outfile : return outfile if goids is not None and len ( goids ) == 1 : goid = next ( iter ( goids ) ) goobj = self . gosubdag . go2obj [ goid ] fout = "GO_{NN}_{NM}" . format ( NN = goid . replace ( "GO:" , "" ) , NM = goobj . name ) return "... | Return output file for GO Term plot . |
34,360 | def _get_optional_attrs ( kws ) : vals = OboOptionalAttrs . attributes . intersection ( kws . keys ( ) ) if 'sections' in kws : vals . add ( 'relationship' ) if 'norel' in kws : vals . discard ( 'relationship' ) return vals | Given keyword args return optional_attributes to be loaded into the GODag . |
34,361 | def _read_sections ( ifile ) : if os . path . exists ( ifile ) : return read_sections ( ifile , exclude_ungrouped = True , prt = None ) | Read sections_in . txt file if it exists . |
34,362 | def get_paths_from_to ( self , goobj_start , goid_end = None , dn0_up1 = True ) : paths = [ ] working_q = cx . deque ( [ [ goobj_start ] ] ) adjfnc = self . adjdir [ dn0_up1 ] while working_q : path_curr = working_q . popleft ( ) goobj_curr = path_curr [ - 1 ] go_adjlst = adjfnc ( goobj_curr ) if ( goid_end is not None... | Get a list of paths from goobj_start to either top or goid_end . |
34,363 | def prt_paths ( paths , prt = sys . stdout ) : pat = "PATHES: {GO} L{L:02} D{D:02}\n" for path in paths : for go_obj in path : prt . write ( pat . format ( GO = go_obj . id , L = go_obj . level , D = go_obj . depth ) ) prt . write ( "\n" ) | Print list of paths . |
34,364 | def prt_keys ( self , prt , pre ) : prt . write ( '{PRE}Relationship to parent: {ABC}\n' . format ( PRE = pre , ABC = '' . join ( self . rel2chr . values ( ) ) ) ) for rel , alias in self . rel2chr . items ( ) : prt . write ( '{PRE} {A} {DESC}\n' . format ( PRE = pre , A = alias , DESC = rel ) ) prt . write ( '\n{PR... | Print the alias for a relationship and its alias . |
34,365 | def _get_id2gos ( self , associations , ** kws ) : options = AnnoOptions ( self . evobj , ** kws ) assc = self . reduce_annotations ( associations , options ) return self . _get_dbid2goids ( assc ) if options . b_geneid2gos else self . _get_goid2dbids ( assc ) | Return given associations in a dict id2gos |
34,366 | def get_date_yyyymmdd ( yyyymmdd ) : return date ( int ( yyyymmdd [ : 4 ] ) , int ( yyyymmdd [ 4 : 6 ] , base = 10 ) , int ( yyyymmdd [ 6 : ] , base = 10 ) ) | Return datetime . date given string . |
34,367 | def hms ( self , msg , tic = None , prt = sys . stdout ) : if tic is None : tic = self . tic now = timeit . default_timer ( ) hms = str ( datetime . timedelta ( seconds = ( now - tic ) ) ) prt . write ( '{HMS}: {MSG}\n' . format ( HMS = hms , MSG = msg ) ) return now | Print elapsed time and message . |
34,368 | def chk_qualifiers ( self ) : if self . name == 'id2gos' : return for ntd in self . associations : qual = ntd . Qualifier assert isinstance ( qual , set ) , '{NAME}: QUALIFIER MUST BE A LIST: {NT}' . format ( NAME = self . name , NT = ntd ) assert qual != set ( [ '' ] ) , ntd assert qual != set ( [ '-' ] ) , ntd assert... | Check format of qualifier |
34,369 | def _has_not_qual ( ntd ) : for qual in ntd . Qualifier : if 'not' in qual : return True if 'NOT' in qual : return True return False | Return True if the qualifiers contain a NOT |
34,370 | def _get_sorted_section ( self , nts_section ) : if self . section_sortby is True : return sorted ( nts_section , key = lambda nt : self . sortgos . usrgo_sortby ( nt ) ) if self . section_sortby is False or self . section_sortby is None : return nts_section return sorted ( nts_section , key = lambda nt : self . sectio... | Sort GO IDs in each section if requested by user . |
34,371 | def get_relationship_targets ( item_ids , relationships , id2rec ) : reltgt_objs_all = set ( ) for goid in item_ids : obj = id2rec [ goid ] for reltype , reltgt_objs_cur in obj . relationship . items ( ) : if relationships is True or reltype in relationships : reltgt_objs_all . update ( reltgt_objs_cur ) return reltgt_... | Get item ID set of item IDs in a relationship target set . |
34,372 | def _get_id2parents ( id2parents , item_id , item_obj ) : if item_id in id2parents : return id2parents [ item_id ] parent_ids = set ( ) for parent_obj in item_obj . parents : parent_id = parent_obj . item_id parent_ids . add ( parent_id ) parent_ids |= _get_id2parents ( id2parents , parent_id , parent_obj ) id2parents ... | Add the parent item IDs for one item object and their parents . |
34,373 | def _get_id2children ( id2children , item_id , item_obj ) : if item_id in id2children : return id2children [ item_id ] child_ids = set ( ) for child_obj in item_obj . children : child_id = child_obj . item_id child_ids . add ( child_id ) child_ids |= _get_id2children ( id2children , child_id , child_obj ) id2children [... | Add the child item IDs for one item object and their children . |
34,374 | def _get_id2upper ( id2upper , item_id , item_obj ) : if item_id in id2upper : return id2upper [ item_id ] upper_ids = set ( ) for upper_obj in item_obj . get_goterms_upper ( ) : upper_id = upper_obj . item_id upper_ids . add ( upper_id ) upper_ids |= _get_id2upper ( id2upper , upper_id , upper_obj ) id2upper [ item_id... | Add the parent item IDs for one item object and their upper . |
34,375 | def _get_id2lower ( id2lower , item_id , item_obj ) : if item_id in id2lower : return id2lower [ item_id ] lower_ids = set ( ) for lower_obj in item_obj . get_goterms_lower ( ) : lower_id = lower_obj . item_id lower_ids . add ( lower_id ) lower_ids |= _get_id2lower ( id2lower , lower_id , lower_obj ) id2lower [ item_id... | Add the lower item IDs for one item object and the objects below them . |
34,376 | def fill_parentidid2obj_r0 ( self , id2obj , child_obj ) : for parent_obj in child_obj . parents : if parent_obj . item_id not in id2obj : id2obj [ parent_obj . item_id ] = parent_obj self . fill_parentidid2obj_r0 ( id2obj , parent_obj ) | Fill id2obj with all parent key item IDs and their objects . |
34,377 | def prt_ver ( self , prt ) : if self . ver_list is not None : prt . write ( "# Versions:\n# {VER}\n\n" . format ( VER = "\n# " . join ( self . ver_list ) ) ) | Print version of GO - DAG for the GO and for GO slims . |
34,378 | def get_sections_2dnt ( self , sec2d_go ) : return [ ( nm , self . get_ntgos_sorted ( gos ) ) for nm , gos in sec2d_go ] | Return a sections list containing sorted lists of namedtuples . |
34,379 | def get_ntgos_sorted ( self , hdrgos ) : go2nt = self . grprobj . go2nt return sorted ( [ go2nt [ go ] for go in hdrgos if go in go2nt ] , key = self . fncsortnt ) | Return sorted Grouper namedtuples if there are user GO IDs underneath . |
34,380 | def prt_ntgos ( self , prt , ntgos ) : for ntgo in ntgos : key2val = ntgo . _asdict ( ) prt . write ( "{GO_LINE}\n" . format ( GO_LINE = self . prtfmt . format ( ** key2val ) ) ) | Print the Grouper namedtuples . |
34,381 | def wr_py_sections_new ( self , fout_py , doc = None ) : sections = self . grprobj . get_sections_2d ( ) return self . wr_py_sections ( fout_py , sections , doc ) | Write the first sections file . |
34,382 | def wr_py_sections ( self , fout_py , sections , doc = None ) : if sections is None : sections = self . grprobj . get_sections_2d ( ) sec2d_nt = self . get_sections_2dnt ( sections ) with open ( fout_py , 'w' ) as prt : self . _prt_py_sections ( sec2d_nt , prt , doc ) dat = SummarySec2dHdrGos ( ) . summarize_sec2hdrgos... | Write sections 2 - D list into a Python format list . |
34,383 | def _prt_py_sections ( self , sec2d_nt , prt = sys . stdout , doc = None ) : if doc is None : doc = 'Sections variable' prt . write ( '\n\n' . format ( DOC = doc ) ) self . prt_ver ( prt ) prt . write ( "# pylint: disable=line-too-long\n" ) strcnt = self . get_summary_str ( sec2d_nt ) prt . write ( "SECTIONS = [ # {CNT... | Print sections 2 - D list into a Python format list . |
34,384 | def _prt_py_section ( self , prt , section_name , ntgos ) : prt . write ( ' ("{SEC}", [ # {N} GO-headers\n' . format ( SEC = section_name , N = len ( ntgos ) ) ) self . prt_ntgos ( prt , ntgos ) prt . write ( " ]),\n" ) | Print one section and its GO headers . |
34,385 | def prt_goid_cnt ( self , prt = sys . stdout ) : for section_name , hdrgos_sec in self . grprobj . get_sections_2d ( ) : prt . write ( "{NAME} {Us:5,} {Hs:5,} {SEC}\n" . format ( NAME = self . grprobj . grpname , Us = len ( self . grprobj . get_usrgos_g_hdrgos ( hdrgos_sec ) ) , Hs = len ( hdrgos_sec ) , SEC = section_... | Get number of hdrgos and usrgos in each section . |
34,386 | def wr_txt_grouping_gos ( self ) : prt_goids = self . grprobj . gosubdag . prt_goids for hdrgo , usrgos in self . grprobj . hdrgo2usrgos . items ( ) : keygos = usrgos . union ( [ hdrgo ] ) fout_txt = "{BASE}.txt" . format ( BASE = self . grprobj . get_fout_base ( hdrgo ) ) with open ( fout_txt , 'w' ) as prt : prt_goid... | Write one file per GO group . |
34,387 | def wr_txt_section_hdrgos ( self , fout_txt , sortby = None , prt_section = True ) : sec2d_go = self . grprobj . get_sections_2d ( ) sec2d_nt = self . get_sections_2dnt ( sec2d_go ) if sortby is None : sortby = self . fncsortnt with open ( fout_txt , 'w' ) as prt : self . prt_ver ( prt ) prt . write ( "# GROUP NAME: {N... | Write high GO IDs that are actually used to group current set of GO IDs . |
34,388 | def prt_num_sig ( self , prt = sys . stdout , alpha = 0.05 ) : ctr = self . get_num_sig ( alpha ) prt . write ( "{N:6,} TOTAL: {TXT}\n" . format ( N = len ( self . nts ) , TXT = " " . join ( [ "FDR({FDR:4})" . format ( FDR = ctr [ 'FDR' ] ) , "Bonferroni({B:4})" . format ( B = ctr [ 'Bonferroni' ] ) , "Benjamini({B:4})... | Print the number of significant GO terms . |
34,389 | def get_num_sig ( self , alpha = 0.05 ) : ctr = cx . Counter ( ) flds = set ( [ 'FDR' , 'Bonferroni' , 'Benjamini' , 'PValue' ] ) for ntd in self . nts : for fld in flds : if getattr ( ntd , fld ) < alpha : ctr [ fld ] += 1 return ctr | Print the number of significant results using various metrics . |
34,390 | def get_nts ( self , fin_davidchart ) : nts = [ ] with open ( fin_davidchart ) as ifstrm : hdr_seen = False for line in ifstrm : line = line . rstrip ( ) flds = line . split ( '\t' ) if hdr_seen : ntd = self . _init_nt ( flds ) nts . append ( ntd ) else : if line [ : 8 ] == 'Category' : assert len ( flds ) == 13 , len ... | Read DAVID Chart file . Store each line in a namedtuple . |
34,391 | def _init_nt ( self , flds ) : term = flds [ 1 ] genes_str = flds [ 5 ] return self . ntobj ( Category = flds [ 0 ] , GO = term [ : 10 ] , name = term [ 10 : ] , Count = int ( flds [ 2 ] ) , Perc = float ( flds [ 3 ] ) , PValue = float ( flds [ 4 ] ) , Genes = genes_str , Genes_set = self . get_genes ( genes_str ) , Li... | Given string fields from a DAVID chart file return namedtuple . |
34,392 | def get_genes ( genes_str ) : gene_set = genes_str . split ( ', ' ) if gene_set and gene_set [ 0 ] . isdigit ( ) : gene_set = set ( int ( g ) for g in gene_set ) return gene_set | Given a string containng genes return a list . |
34,393 | def get_extensions ( extstr ) : if not extstr : return None exts = [ ] for ext_lst in extstr . split ( '|' ) : grp = [ ] for ext in ext_lst . split ( ',' ) : idx = ext . find ( '(' ) if idx != - 1 and ext [ - 1 ] == ')' : grp . append ( AnnotationExtension ( ext [ : idx ] , ext [ idx + 1 : - 1 ] ) ) else : sys . stdout... | Return zero or greater Annotation Extensions given a line of text . |
34,394 | def _set_intvals ( kws , keys ) : for key in keys : if key in kws : kws [ key ] = int ( kws [ key ] ) | Convert keyword values to int . |
34,395 | def _chk_docopt_exit ( self , args , exp_letters ) : if args is None : args = sys . argv [ 1 : ] keys_all = self . exp_keys . union ( self . exp_elems ) if exp_letters : keys_all |= exp_letters unknown_args = self . _chk_docunknown ( args , keys_all ) if unknown_args : raise RuntimeError ( "{USAGE}\n **FATAL: UNKNOW... | Check if docopt exit was for an unknown argument . |
34,396 | def _chk_docopt_kws ( self , docdict , exp ) : for key , val in docdict . items ( ) : if isinstance ( val , str ) : assert '=' not in val , self . _err ( "'=' FOUND IN VALUE" , key , val , exp ) elif key != 'help' and key not in self . exp_keys and key not in self . exp_elems : raise RuntimeError ( self . _err ( "UNKNO... | Check for common user errors when running from the command - line . |
34,397 | def _chk_docunknown ( args , exp ) : unknown = [ ] for arg in args : if arg [ : 2 ] == '--' : val = arg [ 2 : ] if val not in exp : unknown . append ( arg ) elif arg [ : 1 ] == '-' : val = arg [ 1 : ] if val not in exp : unknown . append ( arg ) if '-h' in unknown or '--help' in unknown : return [ ] return unknown | Return any unknown args . |
34,398 | def dnld_goa ( self , species , ext = 'gaf' , item = None , fileout = None ) : basename = self . get_basename ( species , ext , item ) src = os . path . join ( self . ftp_src_goa , species . upper ( ) , "{F}.gz" . format ( F = basename ) ) dst = os . path . join ( os . getcwd ( ) , basename ) if fileout is None else fi... | Download GOA source file name on EMBL - EBI ftp server . |
34,399 | def read_associations ( assoc_fn , anno_type = 'id2gos' , ** kws ) : obj = get_objanno ( assoc_fn , anno_type , ** kws ) return obj . get_id2gos ( ** kws ) | Return associatinos in id2gos format |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.