idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
34,500
def _init_objaartall ( self ) : kws = { 'sortgo' : lambda nt : [ nt . NS , nt . dcnt ] , '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' ) , 'fmtgo2' : ( '{hdr1usr01:2} {NS} {GO} {s_fdr_bh:8} ' '{dcnt:5} R{reldepth:02} ' '{GO_n...
Get background database info for making ASCII art .
34,501
def wr_xlsx ( self , fout_xlsx ) : objwr = WrXlsxSortedGos ( "GOEA" , self . sortobj ) kws_xlsx = { 'title' : self . ver_list , 'fld2fmt' : { f : '{:8.2e}' for f in self . flds_cur if f [ : 2 ] == 'p_' } , 'prt_flds' : self . flds_cur } objwr . wr_xlsx_nts ( fout_xlsx , self . desc2nts , ** kws_xlsx )
Print grouped GOEA results into an xlsx file .
34,502
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 .
34,503
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 .
34,504
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 .
34,505
def _init_flds_cur ( self ) : flds = [ ] 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 ) f...
Choose fields to print from a multitude of available fields .
34,506
def do_hdr ( self , line , hdrs_usr ) : if self . hdr_ex is None : self . _init_hdr ( line , hdrs_usr ) return True elif self . hdr_ex in line : self . _init_hdr ( line , hdrs_usr ) return True return False
Initialize self . h2i .
34,507
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 .
34,508
def _init_nt_hdr ( self , line ) : line = line . replace ( '.' , '_' ) line = line . replace ( ' ' , '_' ) line = line . replace ( '#' , 'N' ) line = line . replace ( '-' , '_' ) line = line . replace ( '"' , '' ) hdrs = re . split ( self . sep , line ) if '' in hdrs : hdrs = NCBIgeneFileReader . replace_nulls ( hdrs )...
Convert headers into valid namedtuple fields .
34,509
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 .
34,510
def _init_data_line ( self , fnc , lnum , line ) : fld = re . split ( self . sep , line ) 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 ( '# ITE...
Process Data line .
34,511
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 ] flds [ idx ] = int ( flds [ idx ] ) if dig . isdigit ( ) else dig for idx in self . idxs_strpat : hdr = self . hdr2idx . items ( ) [ idx ] [ 0 ] pat = self . str...
Convert strings to ints and floats if so specified .
34,512
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 hdrs_usr is not None : for usr_hdr in hdrs_usr : if usr_hdr in self . hdr2idx : self . hdrs_usr . append ( [ usr_hdr , ...
Initialize self . hdr2idx self . len self . idxs_float and self . idxs_int
34,513
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 .
34,514
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 .
34,515
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 .
34,516
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 .
34,517
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 ( '\n\n' . format ( PYDOC = docstr ) ) ofstrm . write ( "from collections import namedtuple\n\n" ) ofs...
Write namedtuples to a dict in a Python module .
34,518
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 .
34,519
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 .
34,520
def fill_main_goids ( go2obj , goids ) : for goid in goids : goobj = go2obj [ goid ] if goid != goobj . id and goobj . id not in go2obj : go2obj [ goobj . id ] = goobj
Ensure main GO IDs are included in go2obj .
34,521
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 .
34,522
def fill_relationshipobjs ( go2obj , 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 .
34,523
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 .
34,524
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 .
34,525
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 .
34,526
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 .
34,527
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_...
Get sections and GO grouping hdrgos from file if sections exist .
34,528
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 ) 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 .
34,529
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_g...
Read sections variable from a text file of from a Python file .
34,530
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 .
34,531
def _prt_read_msg ( self , prt , fin_txt , exclude_ungrouped ) : if self . sections_seen or exclude_ungrouped : dat = SummarySec2dHdrGos ( ) . summarize_sec2hdrgos ( self . section2goids . items ( ) ) sys . stdout . write ( Grouper . fmtsum . format ( GO_DESC = 'hdr' , SECs = len ( dat [ 'S' ] ) , GOs = len ( dat [ 'G'...
Print which file was read and the number of GO IDs found .
34,532
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 .
34,533
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 .
34,534
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 .
34,535
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 .
34,536
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 .
34,537
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...
Check that user specified edges have a node which exists .
34,538
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 .
34,539
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_...
Get the directed edges from GO term to GO term using relationships .
34,540
def _traverse_relationship_objs ( self , rel2src2dsts , goobj_child , goids_seen ) : child_id = goobj_child . id goids_seen . add ( child_id ) for goid_altid in goobj_child . alt_ids : goids_seen . add ( goid_altid ) for reltype , recs in goobj_child . relationship . items ( ) : if reltype in self . relationships : for...
Traverse from source GO up relationships .
34,541
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...
Traverse through reverse relationships .
34,542
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 : self . _traverse_child_objs ( c2ps , goobj_src , goids_seen ) ret...
Traverse up children .
34,543
def chk ( self , annotations , fout_err ) : for idx , ntd in enumerate ( annotations ) : self . _chk_fld ( ntd , "Qualifier" ) self . _chk_fld ( ntd , "DB_Reference" , 1 ) self . _chk_fld ( ntd , "With_From" ) self . _chk_fld ( ntd , "DB_Name" , 0 , 1 ) self . _chk_fld ( ntd , "DB_Synonym" ) self . _chk_fld ( ntd , "Ta...
Check annotations .
34,544
def get_gafvals ( self , line ) : flds = line . split ( '\t' ) flds [ 3 ] = self . _get_qualifier ( flds [ 3 ] ) flds [ 5 ] = self . _get_set ( flds [ 5 ] ) flds [ 7 ] = self . _get_set ( flds [ 7 ] ) flds [ 8 ] = self . aspect2ns [ flds [ 8 ] ] flds [ 9 ] = self . _get_set ( flds [ 9 ] ) flds [ 10 ] = self . _get_set ...
Convert fields from string to preferred format for GAF ver 2 . 1 and 2 . 0 .
34,545
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
34,546
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 Non...
Further split a GAF value within a single field .
34,547
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 .
34,548
def _prt_line_detail ( self , prt , values , lnum = "" ) : 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 .
34,549
def prt_error_summary ( self , fout_err ) : 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 ( ...
Print a summary about the GAF file that was read .
34,550
def _wrlog_details_illegal_gaf ( self , fout_err , err_cnts ) : 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 se...
Print details regarding illegal GAF lines seen to a log file .
34,551
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 ) print ( "CountRelativesInit RELLLLS" , goid , goobj . id , reltyp , relfwd_goids )
Given GO DAG relationships return summaries per GO ID .
34,552
def get_goone2ntletter ( self , go2dcnt , depth2goobjs ) : ns2dcntgoobj = cx . defaultdict ( list ) for goobj in depth2goobjs [ 1 ] : dcnt = go2dcnt [ goobj . id ] ns2dcntgoobj [ goobj . namespace ] . append ( ( dcnt , goobj ) ) go2nt = { } ntobj = cx . namedtuple ( "NtGoLetters" , "D1 dcnt goobj" ) _go2abc = self . go...
Assign letters to depth - 01 GO terms ordered using descendants cnt .
34,553
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 .
34,554
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 .
34,555
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 .
34,556
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 .
34,557
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 .
34,558
def get_node ( self , goid , goobj ) : 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 .
34,559
def str_fmthdr ( self , goid , goobj ) : 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 .
34,560
def _get_prtflds ( self ) : ntflds = self . gosubdag . prt_attr [ 'flds' ] prt_flds = self . kws . get ( 'prt_flds' ) if prt_flds : return prt_flds . intersection ( ntflds ) exclude = set ( ) 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 .
34,561
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 .
34,562
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 ....
Add the parent count to the GO term box for if not all parents are plotted .
34,563
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
34,564
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
34,565
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...
Get the terms in the study group
34,566
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 ] ) ...
Check that associations is gene2go not go2gene .
34,567
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 ...
Return user GO IDs which have GO Terms .
34,568
def get_gos_all ( self ) : gos_all = set ( ) for hdrgo , usrgos in self . hdrgo2usrgos . items ( ) : gos_all . add ( hdrgo ) gos_all |= usrgos gos_all |= self . hdrgo_is_usrgo assert gos_all == self . usrgos . union ( set ( self . hdrgo2usrgos . keys ( ) ) ) assert len ( self . usrgos . difference ( gos_all ) ) == 0 , ...
Return a flat list of all GO IDs in grouping object .
34,569
def _init_h2us ( self , fnc_most_specific ) : hdrgo2usrgos = cx . defaultdict ( set ) 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 = _go...
Given a set of user GO ids return GO ids grouped under the GO high terms .
34,570
def get_go2nt ( self , usr_go2nt ) : gos_all = self . get_gos_all ( ) 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 len ( set ( prt_flds_all ) . ...
Combine user namedtuple fields GO object fields and format_txt .
34,571
def _init_go2nt_aug ( self , go2nt ) : go2obj = self . gosubdag . go2obj go2nt_aug = { } 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_us...
Augment go2nt with GO ID key to account for alt GO IDs .
34,572
def _get_go2nthdridx ( self , gos_all ) : go2nthdridx = { } obj = GrouperInit . NtMaker ( self ) 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 .
34,573
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 = g...
Initialize go2obj in small dag for source gos .
34,574
def _init ( self ) : for goid in self . godag . go_sources : goobj = self . godag . go2obj [ goid ] self . godag . go2obj [ goid ] = goobj if self . traverse_parent and goid not in self . seen_cids : self . _traverse_parent_objs ( goobj ) if self . traverse_child and goid not in self . seen_pids : self . _traverse_chil...
Given GO ids and GOTerm objects create mini GO dag .
34,575
def prt_hier_rec ( self , item_id , depth = 1 ) : if self . include_only and item_id not in self . include_only : return obj = self . id2obj [ item_id ] if self . space_branches : if depth == 1 and obj . children : self . prt . write ( "\n" ) if self . item_marks : self . prt . write ( '{MARK} ' . format ( MARK = self ...
Write hierarchy for a GO Term record and all GO IDs down to the leaf level .
34,576
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 .
34,577
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 .
34,578
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 .
34,579
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 .
34,580
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 .
34,581
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 .
34,582
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 .
34,583
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 .
34,584
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 .
34,585
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 .
34,586
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 .
34,587
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 .
34,588
def load_obo_file ( self , obo_file , optional_attrs , load_obsolete , prt ) : reader = OBOReader ( obo_file , optional_attrs ) alt2rec = { } for rec in reader : if load_obsolete or not rec . is_obsolete : self [ rec . item_id ] = rec for alt in rec . alt_ids : alt2rec [ alt ] = rec self . typedefs = reader . typedefs ...
Read obo file . Store results .
34,589
def _str_desc ( self , reader ) : data_version = reader . data_version if data_version is not None : data_version = data_version . replace ( "releases/" , "" ) desc = "{OBO}: fmt({FMT}) rel({REL}) {N:,} GO Terms" . format ( OBO = reader . obo_file , FMT = reader . format_version , REL = data_version , N = len ( self ) ...
String containing information about the current GO DAG .
34,590
def _populate_terms ( self , optobj ) : has_relationship = optobj is not None and 'relationship' in optobj . optional_attrs for rec in self . values ( ) : rec . parents = set ( [ self [ goid ] for goid in rec . _parents ] ) for parent_rec in rec . parents : parent_rec . children . add ( rec ) if has_relationship : self...
Convert GO IDs to GO Term record objects . Populate children .
34,591
def _populate_relationships ( self , rec_curr ) : for relationship_type , goids in rec_curr . relationship . items ( ) : parent_recs = set ( [ self [ goid ] for goid in goids ] ) rec_curr . relationship [ relationship_type ] = parent_recs for parent_rec in parent_recs : if relationship_type not in parent_rec . relation...
Convert GO IDs in relationships to GO Term record objects . Populate children .
34,592
def _set_level_depth ( self , optobj ) : has_relationship = optobj is not None and 'relationship' in optobj . optional_attrs def _init_level ( rec ) : if rec . level is None : if rec . parents : rec . level = min ( _init_level ( rec ) for rec in rec . parents ) + 1 else : rec . level = 0 return rec . level def _init_de...
Set level depth and add inverted relationships .
34,593
def write_dag ( self , out = sys . stdout ) : for rec in sorted ( self . values ( ) ) : print ( rec , file = out )
Write info for all GO Terms in obo file sorted numerically .
34,594
def query_term ( self , term , verbose = False ) : if term not in self : sys . stderr . write ( "Term %s not found!\n" % term ) return rec = self [ term ] if verbose : print ( rec ) sys . stderr . write ( "all parents: {}\n" . format ( repr ( rec . get_all_parents ( ) ) ) ) sys . stderr . write ( "all children: {}\n" ....
Given a GO ID return GO object .
34,595
def label_wrap ( self , label ) : wrapped_label = r"%s\n%s" % ( label , self [ label ] . name . replace ( "," , r"\n" ) ) return wrapped_label
Label text for plot .
34,596
def make_graph_pygraphviz ( self , recs , nodecolor , edgecolor , dpi , draw_parents = True , draw_children = True ) : import pygraphviz as pgv grph = pgv . AGraph ( name = "GO tree" ) edgeset = set ( ) for rec in recs : if draw_parents : edgeset . update ( rec . get_all_parent_edges ( ) ) if draw_children : edgeset . ...
Draw AMIGO style network lineage containing one query record .
34,597
def draw_lineage ( self , recs , nodecolor = "mediumseagreen" , edgecolor = "lightslateblue" , dpi = 96 , lineage_img = "GO_lineage.png" , engine = "pygraphviz" , gml = False , draw_parents = True , draw_children = True ) : assert engine in GraphEngines grph = None if engine == "pygraphviz" : grph = self . make_graph_p...
Draw GO DAG subplot .
34,598
def _get_ntgpadvals ( self , flds , add_ns ) : is_set = False qualifiers = self . _get_qualifier ( flds [ 2 ] ) assert flds [ 3 ] [ : 3 ] == 'GO:' , 'UNRECOGNIZED GO({GO})' . format ( GO = flds [ 3 ] ) db_reference = self . _rd_fld_vals ( "DB_Reference" , flds [ 4 ] , is_set , 1 ) assert flds [ 5 ] [ : 4 ] == 'ECO:' , ...
Convert fields from string to preferred format for GPAD ver 2 . 1 and 2 . 0 .
34,599
def _rd_fld_vals ( name , val , set_list_ft = True , qty_min = 0 , qty_max = None ) : if not val and qty_min == 0 : return [ ] if set_list_ft else set ( ) vals = val . split ( '|' ) num_vals = len ( vals ) assert num_vals >= qty_min , "FLD({F}): MIN QUANTITY({Q}) WASN'T MET: {V}" . format ( F = name , Q = qty_min , V =...
Further split a GPAD value within a single field .