idx
int64
0
63k
question
stringlengths
61
4.03k
target
stringlengths
6
1.23k
34,600
def _get_taxon ( taxon ) : if not taxon : return None sep = taxon . find ( ':' ) taxid = taxon [ sep + 1 : ] assert taxid . isdigit ( ) , "UNEXPECTED TAXON({T})" . format ( T = taxid ) return int ( taxid )
Return Interacting taxon ID | optional | 0 or 1 | gaf column 13 .
34,601
def _get_ntgpadnt ( self , ver , add_ns ) : hdrs = self . gpad_columns [ ver ] if add_ns : hdrs = hdrs + [ 'NS' ] return cx . namedtuple ( "ntgpadobj" , hdrs )
Create a namedtuple object for each annotation
34,602
def _split_line ( self , line ) : line = line . rstrip ( '\r\n' ) flds = re . split ( '\t' , line ) assert len ( flds ) == self . exp_numcol , "EXPECTED({E}) COLUMNS, ACTUAL({A}): {L}" . format ( E = self . exp_numcol , A = len ( flds ) , L = line ) return flds
Split line into field values .
34,603
def chkaddhdr ( self , line ) : mtch = self . cmpline . search ( line ) if mtch : self . gpadhdr . append ( mtch . group ( 1 ) )
If this line contains desired header info save it .
34,604
def get_dict_w_id2nts ( ids , id2nts , flds , dflt_null = "" ) : assert len ( ids ) == len ( set ( ids ) ) , "NOT ALL IDs ARE UNIQUE: {IDs}" . format ( IDs = ids ) assert len ( flds ) == len ( set ( flds ) ) , "DUPLICATE FIELDS: {IDs}" . format ( IDs = cx . Counter ( flds ) . most_common ( ) ) usr_id_nt = [ ] ntobj = c...
Return a new dict of namedtuples by combining dicts of namedtuples or objects .
34,605
def get_list_w_id2nts ( ids , id2nts , flds , dflt_null = "" ) : combined_nt_list = [ ] ntobj = cx . namedtuple ( "Nt" , " " . join ( flds ) ) for item_id in ids : nts = [ id2nt . get ( item_id ) for id2nt in id2nts ] vals = _combine_nt_vals ( nts , flds , dflt_null ) combined_nt_list . append ( ntobj . _make ( vals ) ...
Return a new list of namedtuples by combining dicts of namedtuples or objects .
34,606
def combine_nt_lists ( lists , flds , dflt_null = "" ) : combined_nt_list = [ ] lens = [ len ( lst ) for lst in lists ] assert len ( set ( lens ) ) == 1 , "LIST LENGTHS MUST BE EQUAL: {Ls}" . format ( Ls = " " . join ( str ( l ) for l in lens ) ) ntobj = cx . namedtuple ( "Nt" , " " . join ( flds ) ) for lst0_lstn in z...
Return a new list of namedtuples by zipping lists of namedtuples or objects .
34,607
def wr_py_nts ( fout_py , nts , docstring = None , varname = "nts" ) : if nts : with open ( fout_py , 'w' ) as prt : prt . write ( '\n\n' . format ( DOCSTRING = docstring ) ) prt . write ( "# Created: {DATE}\n" . format ( DATE = str ( datetime . date . today ( ) ) ) ) prt_nts ( prt , nts , varname ) sys . stdout . writ...
Save namedtuples into a Python module .
34,608
def prt_nts ( prt , nts , varname , spc = ' ' ) : first_nt = nts [ 0 ] nt_name = type ( first_nt ) . __name__ prt . write ( "import collections as cx\n\n" ) prt . write ( "NT_FIELDS = [\n" ) for fld in first_nt . _fields : prt . write ( '{SPC}"{F}",\n' . format ( SPC = spc , F = fld ) ) prt . write ( "]\n\n" ) prt ....
Print namedtuples into a Python module .
34,609
def get_unique_fields ( fld_lists ) : flds = [ ] fld_set = set ( [ f for flst in fld_lists for f in flst ] ) fld_seen = set ( ) for fld_list in fld_lists : for fld in fld_list : if fld not in fld_seen : flds . append ( fld ) fld_seen . add ( fld ) assert len ( flds ) == len ( fld_set ) return flds
Get unique namedtuple fields despite potential duplicates in lists of fields .
34,610
def _combine_nt_vals ( lst0_lstn , flds , dflt_null ) : vals = [ ] for fld in flds : fld_seen = False for nt_curr in lst0_lstn : if hasattr ( nt_curr , fld ) : vals . append ( getattr ( nt_curr , fld ) ) fld_seen = True break if fld_seen is False : vals . append ( dflt_null ) return vals
Given a list of lists of nts return a single namedtuple .
34,611
def get_go2obj ( self , goids ) : goids = goids . intersection ( self . go2obj . keys ( ) ) if len ( goids ) != len ( goids ) : goids_missing = goids . difference ( goids ) print ( " {N} MISSING GO IDs: {GOs}" . format ( N = len ( goids_missing ) , GOs = goids_missing ) ) return { go : self . go2obj [ go ] for go in g...
Return GO Terms for each user - specified GO ID . Note missing GO IDs .
34,612
def no_duplicates_sections2d ( sections2d , prt = None ) : no_dups = True ctr = cx . Counter ( ) for _ , hdrgos in sections2d : for goid in hdrgos : ctr [ goid ] += 1 for goid , cnt in ctr . most_common ( ) : if cnt == 1 : break no_dups = False if prt is not None : prt . write ( "**SECTIONS WARNING FOUND: {N:3} {GO}\n"...
Check for duplicate header GO IDs in the 2 - D sections variable .
34,613
def get_evcodes ( self , inc_set = None , exc_set = None ) : codes = self . get_evcodes_all ( inc_set , exc_set ) codes . discard ( 'ND' ) return codes
Get evidence code for all but NOT No biological data
34,614
def get_evcodes_all ( self , inc_set = None , exc_set = None ) : codes = self . _get_grps_n_codes ( inc_set ) if inc_set else set ( self . code2nt ) if exc_set : codes . difference_update ( self . _get_grps_n_codes ( exc_set ) ) return codes
Get set of evidence codes given include set and exclude set
34,615
def _get_grps_n_codes ( self , usr_set ) : codes = usr_set . intersection ( self . code2nt ) for grp in usr_set . intersection ( self . grp2codes ) : codes . update ( self . grp2codes [ grp ] ) return codes
Get codes given codes or groups .
34,616
def sort_nts ( self , nt_list , codekey ) : sortby = lambda nt : self . ev2idx . get ( getattr ( nt , codekey ) , - 1 ) return sorted ( nt_list , key = sortby )
Sort list of namedtuples such so evidence codes in same order as code2nt .
34,617
def get_grp_name ( self , code ) : nt_code = self . code2nt . get ( code . strip ( ) , None ) if nt_code is not None : return nt_code . group , nt_code . name return "" , ""
Return group and name for an evidence code .
34,618
def prt_ev_cnts ( self , ctr , prt = sys . stdout ) : for key , cnt in ctr . most_common ( ) : grp , name = self . get_grp_name ( key . replace ( "NOT " , "" ) ) prt . write ( "{CNT:7,} {EV:>7} {GROUP:<15} {NAME}\n" . format ( CNT = cnt , EV = key , GROUP = grp , NAME = name ) )
Prints evidence code counts stored in a collections Counter .
34,619
def get_order ( self , codes ) : return sorted ( codes , key = lambda e : [ self . ev2idx . get ( e ) ] )
Return evidence codes in order shown in code2name .
34,620
def get_grp2code2nt ( self ) : grp2code2nt = cx . OrderedDict ( [ ( g , [ ] ) for g in self . grps ] ) for code , ntd in self . code2nt . items ( ) : grp2code2nt [ ntd . group ] . append ( ( code , ntd ) ) for grp , nts in grp2code2nt . items ( ) : grp2code2nt [ grp ] = cx . OrderedDict ( nts ) return grp2code2nt
Return ordered dict for group to namedtuple
34,621
def _init_grps ( code2nt ) : seen = set ( ) seen_add = seen . add groups = [ nt . group for nt in code2nt . values ( ) ] return [ g for g in groups if not ( g in seen or seen_add ( g ) ) ]
Return list of groups in same order as in code2nt
34,622
def get_grp2codes ( self ) : grp2codes = cx . defaultdict ( set ) for code , ntd in self . code2nt . items ( ) : grp2codes [ ntd . group ] . add ( code ) return dict ( grp2codes )
Get dict of group name to namedtuples .
34,623
def plot_sections ( self , fout_dir = "." , ** kws_usr ) : kws_plt , _ = self . _get_kws_plt ( None , ** kws_usr ) PltGroupedGos ( self ) . plot_sections ( fout_dir , ** kws_plt )
Plot groups of GOs which have been placed in sections .
34,624
def get_pltdotstr ( self , ** kws_usr ) : dotstrs = self . get_pltdotstrs ( ** kws_usr ) assert len ( dotstrs ) == 1 return dotstrs [ 0 ]
Plot one GO header group in Grouper .
34,625
def plot_groups_unplaced ( self , fout_dir = "." , ** kws_usr ) : plotobj = PltGroupedGos ( self ) return plotobj . plot_groups_unplaced ( fout_dir , ** kws_usr )
Plot each GO group .
34,626
def _get_kws_plt ( self , usrgos , ** kws_usr ) : kws_plt = kws_usr . copy ( ) kws_dag = { } hdrgo = kws_plt . get ( 'hdrgo' , None ) objcolor = GrouperColors ( self . grprobj ) if 'go2color' not in kws_usr : kws_plt [ 'go2color' ] = objcolor . get_go2color_users ( ) elif hdrgo is not None : go2color = kws_plt . get ( ...
Add go2color and go2bordercolor relevant to this grouping into plot .
34,627
def get_go2txt ( grprobj_cur , grp_go2color , grp_go2bordercolor ) : goids_main = set ( o . id for o in grprobj_cur . gosubdag . go2obj . values ( ) ) hdrobj = grprobj_cur . hdrobj grprobj_all = Grouper ( "all" , grprobj_cur . usrgos . union ( goids_main ) , hdrobj , grprobj_cur . gosubdag ) _secdflt = hdrobj . secdflt...
Adds section text in all GO terms if not Misc . Adds Misc in terms of interest .
34,628
def download_go_basic_obo ( obo = "go-basic.obo" , prt = sys . stdout , loading_bar = True ) : if not os . path . isfile ( obo ) : http = "http://purl.obolibrary.org/obo/go" if "slim" in obo : http = "http://www.geneontology.org/ontology/subsets" obo_remote = "{HTTP}/{OBO}" . format ( HTTP = http , OBO = os . path . ba...
Download Ontologies if necessary .
34,629
def download_ncbi_associations ( gene2go = "gene2go" , prt = sys . stdout , loading_bar = True ) : gzip_file = "{GENE2GO}.gz" . format ( GENE2GO = gene2go ) if not os . path . isfile ( gene2go ) : file_remote = "ftp://ftp.ncbi.nlm.nih.gov/gene/DATA/{GZ}" . format ( GZ = os . path . basename ( gzip_file ) ) dnld_file ( ...
Download associations from NCBI if necessary
34,630
def gunzip ( gzip_file , file_gunzip = None ) : if file_gunzip is None : file_gunzip = os . path . splitext ( gzip_file ) [ 0 ] gzip_open_to ( gzip_file , file_gunzip ) return file_gunzip
Unzip . gz file . Return filename of unzipped file .
34,631
def get_godag ( fin_obo = "go-basic.obo" , prt = sys . stdout , loading_bar = True , optional_attrs = None ) : from goatools . obo_parser import GODag download_go_basic_obo ( fin_obo , prt , loading_bar ) return GODag ( fin_obo , optional_attrs , load_obsolete = False , prt = prt )
Return GODag object . Initialize if necessary .
34,632
def dnld_gaf ( species_txt , prt = sys . stdout , loading_bar = True ) : return dnld_gafs ( [ species_txt ] , prt , loading_bar ) [ 0 ]
Download GAF file if necessary .
34,633
def dnld_gafs ( species_list , prt = sys . stdout , loading_bar = True ) : http = "http://current.geneontology.org/annotations" fin_gafs = [ ] cwd = os . getcwd ( ) for species_txt in species_list : gaf_base = '{ABC}.gaf' . format ( ABC = species_txt ) gaf_cwd = os . path . join ( cwd , gaf_base ) wget_cmd = "{HTTP}/{G...
Download GAF files if necessary .
34,634
def http_get ( url , fout = None ) : print ( 'requests.get({URL}, stream=True)' . format ( URL = url ) ) rsp = requests . get ( url , stream = True ) if rsp . status_code == 200 and fout is not None : with open ( fout , 'wb' ) as prt : for chunk in rsp : prt . write ( chunk ) print ( ' WROTE: {F}\n' . format ( F = fou...
Download a file from http . Save it in a file named by fout
34,635
def ftp_get ( fin_src , fout ) : assert fin_src [ : 6 ] == 'ftp://' , fin_src dir_full , fin_ftp = os . path . split ( fin_src [ 6 : ] ) pt0 = dir_full . find ( '/' ) assert pt0 != - 1 , pt0 ftphost = dir_full [ : pt0 ] chg_dir = dir_full [ pt0 + 1 : ] print ( 'FTP RETR {HOST} {DIR} {SRC} -> {DST}' . format ( HOST = ft...
Download a file from an ftp server
34,636
def dnld_file ( src_ftp , dst_file , prt = sys . stdout , loading_bar = True ) : if os . path . isfile ( dst_file ) : return do_gunzip = src_ftp [ - 3 : ] == '.gz' and dst_file [ - 3 : ] != '.gz' dst_wget = "{DST}.gz" . format ( DST = dst_file ) if do_gunzip else dst_file wget_msg = "wget({SRC} out={DST})\n" . format (...
Download specified file if necessary .
34,637
def init_datamembers ( self , rec ) : if 'synonym' in self . optional_attrs : rec . synonym = [ ] if 'xref' in self . optional_attrs : rec . xref = set ( ) if 'subset' in self . optional_attrs : rec . subset = set ( ) if 'comment' in self . optional_attrs : rec . comment = "" if 'relationship' in self . optional_attrs ...
Initialize current GOTerm with data members for storing optional attributes .
34,638
def _get_synonym ( self , line ) : mtch = self . attr2cmp [ 'synonym' ] . match ( line ) text , scope , typename , dbxrefs , _ = mtch . groups ( ) typename = typename . strip ( ) dbxrefs = set ( dbxrefs . split ( ', ' ) ) if dbxrefs else set ( ) return self . attr2cmp [ 'synonym nt' ] . _make ( [ text , scope , typenam...
Given line return optional attribute synonym value in a namedtuple .
34,639
def _get_xref ( self , line ) : mtch = self . attr2cmp [ 'xref' ] . match ( line ) return mtch . group ( 1 ) . replace ( ' ' , '' )
Given line return optional attribute xref value in a dict of sets .
34,640
def _init_compile_patterns ( optional_attrs ) : attr2cmp = { } if optional_attrs is None : return attr2cmp if 'synonym' in optional_attrs : attr2cmp [ 'synonym' ] = re . compile ( r'"(\S.*\S)" ([A-Z]+) (.*)\[(.*)\](.*)$' ) attr2cmp [ 'synonym nt' ] = cx . namedtuple ( "synonym" , "text scope typename dbxrefs" ) if 'xre...
Compile search patterns for optional attributes if needed .
34,641
def cli ( ) : objcli = WrHierCli ( sys . argv [ 1 : ] ) fouts_txt = objcli . get_fouts ( ) if fouts_txt : for fout_txt in fouts_txt : objcli . wrtxt_hier ( fout_txt ) else : objcli . prt_hier ( sys . stdout )
Command - line script to print a GO term s lower - level hierarchy .
34,642
def get_fouts ( self ) : fouts_txt = [ ] if 'o' in self . kws : fouts_txt . append ( self . kws [ 'o' ] ) if 'f' in self . kws : fouts_txt . append ( self . _get_fout_go ( ) ) return fouts_txt
Get output filename .
34,643
def _get_fout_go ( self ) : assert self . goids , "NO VALID GO IDs WERE PROVIDED AS STARTING POINTS FOR HIERARCHY REPORT" base = next ( iter ( self . goids ) ) . replace ( ':' , '' ) upstr = '_up' if 'up' in self . kws else '' return "hier_{BASE}{UP}.{EXT}" . format ( BASE = base , UP = upstr , EXT = 'txt' )
Get the name of an output file based on the top GO term .
34,644
def wrtxt_hier ( self , fout_txt ) : with open ( fout_txt , 'wb' ) as prt : self . prt_hier ( prt ) print ( " WROTE: {TXT}" . format ( TXT = fout_txt ) )
Write hierarchy below specfied GO IDs to an ASCII file .
34,645
def prt_hier ( self , prt = sys . stdout ) : objwr = WrHierGO ( self . gosubdag , ** self . kws ) assert self . goids , "NO VALID GO IDs WERE PROVIDED" if 'up' not in objwr . usrset : for goid in self . goids : objwr . prt_hier_down ( goid , prt ) else : objwr . prt_hier_up ( self . goids , prt )
Write hierarchy below specfied GO IDs .
34,646
def _adj_for_assc ( self ) : if self . gene2gos : gos_assoc = set ( get_b2aset ( self . gene2gos ) . keys ( ) ) if 'item_marks' not in self . kws : self . kws [ 'item_marks' ] = { go : '>' for go in gos_assoc } if 'include_only' not in self . kws : gosubdag = GoSubDag ( gos_assoc , self . gosubdag . go2obj , self . gos...
Print only GO IDs from associations and their ancestors .
34,647
def calc_pvalue ( self , study_count , study_n , pop_count , pop_n ) : fnc_call = "calc_pvalue({SCNT}, {STOT}, {PCNT} {PTOT})" . format ( SCNT = study_count , STOT = study_n , PCNT = pop_count , PTOT = pop_n ) raise Exception ( "NOT IMPLEMENTED: {FNC_CALL} using {FNC}." . format ( FNC_CALL = fnc_call , FNC = self . pva...
pvalues are calculated in derived classes .
34,648
def _init_pval_obj ( self ) : if self . pval_fnc_name in self . options . keys ( ) : try : fisher_obj = self . options [ self . pval_fnc_name ] ( self . pval_fnc_name , self . log ) except ImportError : print ( "fisher module not installed. Falling back on scipy.stats.fisher_exact" ) fisher_obj = self . options [ 'fis...
Returns a Fisher object based on user - input .
34,649
def check_version ( self , name , majorv = 2 , minorv = 7 ) : 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" % ( name , majorv , minorv , sys . version_info . major , sys . version_info . minor...
Make sure the package runs on the supported Python version
34,650
def get_init ( self , filename = "__init__.py" ) : 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 ) if isinstance ( node , ast . Assign ) and node . targets [ 0 ] . id == x ) try : retu...
Get various info from the package without importing them
34,651
def missing_requirements ( self , specifiers ) : for specifier in specifiers : try : pkg_resources . require ( specifier ) except pkg_resources . DistributionNotFound : yield specifier
Find what s missing
34,652
def install_requirements ( self , requires ) : sys . path [ 0 : 0 ] = [ 'setup-requires' ] pkg_resources . working_set . add_entry ( 'setup-requires' ) to_install = list ( self . missing_requirements ( requires ) ) if to_install : cmd = [ sys . executable , "-m" , "pip" , "install" , "-t" , "setup-requires" ] + to_inst...
Install the listed requirements
34,653
def get_long_description ( self , filename = 'README.md' ) : try : import pypandoc description = pypandoc . convert_file ( 'README.md' , 'rst' , 'md' ) except ( IOError , ImportError ) : description = open ( "README.md" ) . read ( ) return description
I really prefer Markdown to reStructuredText . PyPi does not .
34,654
def prt_gos ( self , prt = sys . stdout , ** kws_usr ) : desc2nts = self . get_desc2nts ( ** kws_usr ) self . prt_nts ( desc2nts , prt , kws_usr . get ( 'prtfmt' ) ) return desc2nts
Sort user GO ids grouped under broader GO terms or sections . Print to screen .
34,655
def get_nts_flat ( self , hdrgo_prt = True , use_sections = True ) : if self . sectobj is None or not use_sections : return self . sortgos . get_nts_sorted ( hdrgo_prt , hdrgos = self . grprobj . get_hdrgos ( ) , hdrgo_sort = True ) if not use_sections : return self . sectobj . get_sorted_nts_omit_section ( hdrgo_prt ,...
Return a flat list of sorted nts .
34,656
def get_sections_2d ( self ) : sections_hdrgos_act = [ ] hdrgos_act_all = self . get_hdrgos ( ) hdrgos_act_secs = set ( ) if self . hdrobj . sections : for section_name , hdrgos_all_lst in self . hdrobj . sections : hdrgos_all_set = set ( hdrgos_all_lst ) hdrgos_act_set = hdrgos_all_set . intersection ( hdrgos_act_all ...
Get 2 - D list of sections and hdrgos sets actually used in grouping .
34,657
def get_usrgos_g_section ( self , section = None ) : if section is None : section = self . hdrobj . secdflt if section is True : return self . usrgos section2hdrgos = cx . OrderedDict ( self . get_sections_2d ( ) ) hdrgos_lst = section2hdrgos . get ( section , None ) if hdrgos_lst is not None : hdrgos_set = set ( hdrgo...
Get usrgos in a requested section .
34,658
def get_section2usrnts ( self ) : 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_nts )
Get dict section2usrnts .
34,659
def get_section2items ( self , itemkey ) : 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 ( ) ) ] ) sec_items . append ( ( section , items ) ) return cx . OrderedDict ( sec_items...
Collect all items into a single set per section .
34,660
def get_hdrgos_g_usrgos ( self , 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 ) continue hdrgo_cur = usrgo2hdrgo . get ( usrgo , None ) if hdrgo_cur is not None : hdrgos_f...
Return hdrgos which contain the usrgos .
34,661
def get_section_hdrgos_nts ( self , sortby = None ) : nts_all = [ ] section_hdrgos_actual = self . get_sections_2d ( ) flds_all = [ 'Section' ] + self . gosubdag . prt_attr [ 'flds' ] ntobj = cx . namedtuple ( "NtGoSec" , " " . join ( flds_all ) ) flds_go = None if sortby is None : sortby = lambda nt : - 1 * nt . dcnt ...
Get a flat list of sections and hdrgos actually used in grouping .
34,662
def get_sections_2d_nts ( self , sortby = None ) : sections_2d_nts = [ ] for section_name , hdrgos_actual in self . get_sections_2d ( ) : hdrgo_nts = self . gosubdag . get_nts ( hdrgos_actual , sortby = sortby ) sections_2d_nts . append ( ( section_name , hdrgo_nts ) ) return sections_2d_nts
Get high GO IDs that are actually used to group current set of GO IDs .
34,663
def get_usrgos_g_hdrgos ( self , 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 : usrgos_all |= usrgos_cur if hdrgo in self . hdrgo_is_usrgo : usrgos_all . add ( hdrgo ) return u...
Return usrgos under provided hdrgos .
34,664
def get_hdrgo2usrgos ( self , hdrgos ) : get_usrgos = self . hdrgo2usrgos . get hdrgos_actual = self . get_hdrgos ( ) . intersection ( hdrgos ) return { h : get_usrgos ( h ) for h in hdrgos_actual }
Return a subset of hdrgo2usrgos .
34,665
def get_usrgo2hdrgo ( self ) : usrgo2hdrgo = { } for hdrgo , usrgos in self . hdrgo2usrgos . items ( ) : for usrgo in usrgos : assert usrgo not in usrgo2hdrgo usrgo2hdrgo [ usrgo ] = hdrgo for goid in self . hdrgo_is_usrgo : usrgo2hdrgo [ goid ] = goid assert len ( self . usrgos ) <= len ( usrgo2hdrgo ) , "USRGOS({U}) ...
Return a dict with all user GO IDs as keys and their respective header GOs as values .
34,666
def get_go2sectiontxt ( self ) : go2txt = { } _get_secs = self . hdrobj . get_sections hdrgo2sectxt = { h : " " . join ( _get_secs ( h ) ) for h in self . get_hdrgos ( ) } usrgo2hdrgo = self . get_usrgo2hdrgo ( ) for goid , ntgo in self . go2nt . items ( ) : hdrgo = ntgo . GO if ntgo . is_hdrgo else usrgo2hdrgo [ ntgo ...
Return a dict with actual header and user GO IDs as keys and their sections as values .
34,667
def get_usrgo2sections ( self ) : usrgo2sections = cx . defaultdict ( set ) usrgo2hdrgo = self . get_usrgo2hdrgo ( ) get_sections = self . hdrobj . get_sections for usrgo , hdrgo in usrgo2hdrgo . items ( ) : sections = set ( get_sections ( hdrgo ) ) usrgo2sections [ usrgo ] |= sections assert len ( usrgo2sections ) >= ...
Return a dict with all user GO IDs as keys and their sections as values .
34,668
def get_fout_base ( self , goid , name = None , pre = "gogrp" ) : goobj = self . gosubdag . go2obj [ goid ] if name is None : name = self . grpname . replace ( " " , "_" ) sections = "_" . join ( self . hdrobj . get_sections ( goid ) ) return "{PRE}_{BP}_{NAME}_{SEC}_{DSTR}_{D1s}_{GO}" . format ( PRE = pre , BP = Const...
Get filename for a group of GO IDs under a single header GO ID .
34,669
def _get_depthsr ( self , goobj ) : if 'reldepth' in self . gosubdag . prt_attr [ 'flds' ] : return "R{R:02}" . format ( R = goobj . reldepth ) return "D{D:02}" . format ( D = goobj . depth )
Return DNN or RNN depending on if relationships are loaded .
34,670
def _str_replace ( txt ) : txt = txt . replace ( "," , "" ) txt = txt . replace ( " " , "_" ) txt = txt . replace ( ":" , "" ) txt = txt . replace ( "." , "" ) txt = txt . replace ( "/" , "" ) txt = txt . replace ( "" , "" ) return txt
Makes a small text amenable to being used in a filename .
34,671
def get_prtfmt_list ( self , flds , add_nl = True ) : 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_fld2fmt [ fld ] ) else : raise Exception ( "UNKNOWN FORMAT: {FLD}" . format ( FLD = fl...
Get print format given fields .
34,672
def main ( ) : import argparse prs = argparse . ArgumentParser ( __doc__ , formatter_class = argparse . ArgumentDefaultsHelpFormatter ) prs . add_argument ( '--taxon_id' , type = str , help = 'NCBI taxon ID, must match exact species/strain used by GO Central, e.g. 4896 for S Pombe' ) prs . add_argument ( '--golr_url' ,...
Fetch simple gene - term assocaitions from Golr using bioentity document type one line per gene .
34,673
def get_short_plot_name ( self , goobj ) : name = goobj . name if self . _keep_this ( name ) : return self . replace_greek ( name ) name = name . replace ( "cellular response to chemical stimulus" , "cellular rsp. to chemical stim." ) depth = goobj . depth if depth > 1 : name = name . replace ( "regulation of " , "reg....
Shorten some GO names so plots are smaller .
34,674
def shorten_go_name_ptbl1 ( self , name ) : 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 ( "regulation" , "reg." ) name = name . replace ( "antigen processing an...
Shorten GO name for tables in paper .
34,675
def shorten_go_name_ptbl3 ( self , name , dcnt ) : if self . _keep_this ( name ) : return name name = name . replace ( "positive regulation of immune system process" , "+ reg. of immune sys. process" ) name = name . replace ( "positive regulation of immune response" , "+ reg. of immune response" ) name = name . replace...
Shorten GO description for Table 3 in manuscript .
34,676
def shorten_go_name_all ( self , name ) : name = self . replace_greek ( name ) name = name . replace ( "MHC class I" , "MHC-I" ) return name
Shorten GO name for tables in paper supplemental materials and plots .
34,677
def _keep_this ( self , name ) : for keep_name in self . keep : if name == keep_name : return True return False
Return True if there are to be no modifications to name .
34,678
def read_d1_letter ( fin_txt ) : 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 ] != ' ' : go2letter [ mtch . group ( 1 ) ] = line [ : 1 ] return go2letter
Reads letter aliases from a text file created by GoDepth1LettersWr .
34,679
def get_goids_sections ( sections ) : goids_all = set ( ) for _ , goids_sec in sections : goids_all |= set ( goids_sec ) return goids_all
Return all the GO IDs in a 2 - D sections list .
34,680
def prt_txt ( self , prt = sys . stdout , pre = '' ) : 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 , d = ntdata . dcnt , NS = ntdata . NS , D = ntdata . depth , GO = ntdata . GO , NAME = ntdata . name ) ) re...
Print letters descendant count and GO information .
34,681
def wr_xlsx ( self , fout_xlsx = "gos_depth01.xlsx" , ** kws ) : 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 'hdrs' not in kws : kws [ 'hdrs' ] = self . hdrs wr_xlsx_tbl ( fout_xlsx , data_nts , ** kws )
Write xlsx table of depth - 01 GO terms and their letter representation .
34,682
def get_d1nts ( self ) : data = [ ] ntdata = cx . namedtuple ( "NtPrt" , "D1 NS dcnt depth GO name" ) namespace = None for ntlet in sorted ( self . goone2ntletter . values ( ) , key = lambda nt : [ nt . goobj . namespace , - 1 * nt . dcnt , nt . D1 ] ) : goobj = ntlet . goobj goid = goobj . id assert len ( goobj . pare...
Get letters for depth - 01 GO terms descendants count and GO information .
34,683
def _init_ns2nt ( rcntobj ) : 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 ] return cx . OrderedDict ( ns_nt )
Save depth - 00 GO terms ordered using descendants cnt .
34,684
def _get_xlsx_kws ( self , ** kws_usr ) : kws_xlsx = { 'fld2col_widths' : self . _get_fld2col_widths ( ** kws_usr ) , 'items' : 'GO IDs' } remaining_keys = set ( [ 'title' , 'hdrs' , 'prt_flds' , 'fld2fmt' , 'ntval2wbfmtdict' , 'ntfld_wbfmt' ] ) for usr_key , usr_val in kws_usr . items ( ) : if usr_key in remaining_key...
Return keyword arguments relevant to writing an xlsx .
34,685
def _adjust_prt_flds ( self , kws_xlsx , desc2nts , shade_hdrgos ) : if "prt_flds" in kws_xlsx : return kws_xlsx [ "prt_flds" ] dont_print = set ( [ 'hdr_idx' , 'is_hdrgo' , 'is_usrgo' ] ) prt_flds_adjusted = [ ] nt_flds = self . sortobj . get_fields ( desc2nts ) for nt_fld in nt_flds : if nt_fld not in dont_print : if...
Print user - requested fields or provided fields minus info fields .
34,686
def _get_fld2col_widths ( self , ** kws ) : fld2col_widths = self . _init_fld2col_widths ( ) if 'fld2col_widths' not in kws : return fld2col_widths for fld , val in kws [ 'fld2col_widths' ] . items ( ) : fld2col_widths [ fld ] = val return fld2col_widths
Return xlsx column widths based on default and user - specified field - value pairs .
34,687
def _init_fld2col_widths ( self ) : fld2col_widths = GoSubDagWr . fld2col_widths . copy ( ) for fld , wid in self . oprtfmt . default_fld2col_widths . items ( ) : fld2col_widths [ fld ] = wid for fld in get_hdridx_flds ( ) : fld2col_widths [ fld ] = 2 return fld2col_widths
Return default column widths for writing an Excel Spreadsheet .
34,688
def _get_shade_hdrgos ( ** kws ) : if 'shade_hdrgos' in kws : return kws [ 'shade_hdrgos' ] if 'hdrgo_prt' in kws : return kws [ 'hdrgo_prt' ] if 'section_sortby' in kws and kws [ 'section_sortby' ] : return False if 'top_n' in kws and isinstance ( kws [ 'top_n' ] , int ) : return False return True
If no hdrgo_prt specified and these conditions are present - > hdrgo_prt = F .
34,689
def dflt_sortby_objgoea ( goea_res ) : return [ getattr ( goea_res , 'enrichment' ) , getattr ( goea_res , 'namespace' ) , getattr ( goea_res , 'p_uncorrected' ) , getattr ( goea_res , 'depth' ) , getattr ( goea_res , 'GO' ) ]
Default sorting of GOEA results .
34,690
def dflt_sortby_ntgoea ( ntgoea ) : return [ ntgoea . enrichment , ntgoea . namespace , ntgoea . p_uncorrected , ntgoea . depth , ntgoea . GO ]
Default sorting of GOEA results stored in namedtuples .
34,691
def get_goea_nts_prt ( self , fldnames = None , ** usr_kws ) : kws = usr_kws . copy ( ) if 'not_fldnames' not in kws : kws [ 'not_fldnames' ] = [ 'goterm' , 'parents' , 'children' , 'id' ] if 'rpt_fmt' not in kws : kws [ 'rpt_fmt' ] = True return self . get_goea_nts_all ( fldnames , ** kws )
Return list of namedtuples removing fields which are redundant or verbose .
34,692
def _get_field_values ( item , fldnames , rpt_fmt = None , itemid2name = None ) : if hasattr ( item , "_fldsdefprt" ) : return item . get_field_values ( fldnames , rpt_fmt , itemid2name ) if hasattr ( item , "_fields" ) : return [ getattr ( item , f ) for f in fldnames ]
Return fieldnames and values of either a namedtuple or GOEnrichmentRecord .
34,693
def _get_fieldnames ( item ) : if hasattr ( item , "_fldsdefprt" ) : return item . get_prtflds_all ( ) if hasattr ( item , "_fields" ) : return item . _fields
Return fieldnames of either a namedtuple or GOEnrichmentRecord .
34,694
def get_bordercolor ( self ) : hdrgos_all = self . grprobj . hdrobj . get_hdrgos ( ) hdrgos_unused = hdrgos_all . difference ( self . hdrgos_actual ) go2bordercolor = { } for hdrgo in hdrgos_unused : go2bordercolor [ hdrgo ] = self . hdrcol_all for hdrgo in self . grprobj . hdrgo2usrgos . keys ( ) : go2bordercolor [ hd...
Get bordercolor based on hdrgos and usergos .
34,695
def get_go2color_users ( self , usrgo_color = '#feffa3' , hdrusrgo_color = '#d4ffea' , hdrgo_color = '#eee6f6' ) : go2color = { } for goid in self . usrgos : go2color [ goid ] = usrgo_color for goid_hdr in self . hdrgos_actual : go2color [ goid_hdr ] = hdrusrgo_color if goid_hdr in self . usrgos else hdrgo_color return...
Get go2color for GO DAG plots .
34,696
def run ( self , name , goea_nts , log ) : objaart = AArtGeneProductSetsOne ( name , goea_nts , self ) if self . hdrobj . sections : return objaart . prt_report_grp1 ( log ) else : return objaart . prt_report_grp0 ( log )
Run gene product ASCII art .
34,697
def get_chr2idx ( self ) : return { chr ( ascii_int ) : idx for idx , ascii_int in enumerate ( self . all_chrints ) }
Return a dict with the ASCII art character as key and its index as value .
34,698
def _init_kws ( self ) : if 'fmtgo' not in self . kws : self . kws [ 'fmtgo' ] = self . grprdflt . gosubdag . prt_attr [ 'fmt' ] + "\n" if 'fmtgo2' not in self . kws : self . kws [ 'fmtgo2' ] = self . grprdflt . gosubdag . prt_attr [ 'fmt' ] + "\n" if 'fmtgene' not in self . kws : if 'itemid2name' not in self . kws : s...
Fill default values for keyword args if necessary .
34,699
def _init_relationships ( self , relationships_arg ) : if relationships_arg : relationships_all = self . _get_all_relationships ( ) if relationships_arg is True : return relationships_all else : return relationships_all . intersection ( relationships_arg ) return set ( )
Return a set of relationships found in all subset GO Terms .