idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
17,900
def filter_pmids ( pmid_list , source_type ) : global pmids_fulltext_dict if source_type not in ( 'fulltext' , 'oa_xml' , 'oa_txt' , 'auth_xml' ) : raise ValueError ( "source_type must be one of: 'fulltext', 'oa_xml', " "'oa_txt', or 'auth_xml'." ) if pmids_fulltext_dict . get ( source_type ) is None : fulltext_list_pa...
Filter a list of PMIDs for ones with full text from PMC .
17,901
def get_example_extractions ( fname ) : "Get extractions from one of the examples in `cag_examples`." with open ( fname , 'r' ) as f : sentences = f . read ( ) . splitlines ( ) rdf_xml_dict = { } for sentence in sentences : logger . info ( "Reading \"%s\"..." % sentence ) html = tc . send_query ( sentence , 'cwms' ) tr...
Get extractions from one of the examples in cag_examples .
17,902
def make_example_graphs ( ) : "Make graphs from all the examples in cag_examples." cag_example_rdfs = { } for i , fname in enumerate ( os . listdir ( 'cag_examples' ) ) : cag_example_rdfs [ i + 1 ] = get_example_extractions ( fname ) return make_cag_graphs ( cag_example_rdfs )
Make graphs from all the examples in cag_examples .
17,903
def _join_list ( lst , oxford = False ) : if len ( lst ) > 2 : s = ', ' . join ( lst [ : - 1 ] ) if oxford : s += ',' s += ' and ' + lst [ - 1 ] elif len ( lst ) == 2 : s = lst [ 0 ] + ' and ' + lst [ 1 ] elif len ( lst ) == 1 : s = lst [ 0 ] else : s = '' return s
Join a list of words in a gramatically correct way .
17,904
def _assemble_activeform ( stmt ) : subj_str = _assemble_agent_str ( stmt . agent ) if stmt . is_active : is_active_str = 'active' else : is_active_str = 'inactive' if stmt . activity == 'activity' : stmt_str = subj_str + ' is ' + is_active_str elif stmt . activity == 'kinase' : stmt_str = subj_str + ' is kinase-' + is...
Assemble ActiveForm statements into text .
17,905
def _assemble_modification ( stmt ) : sub_str = _assemble_agent_str ( stmt . sub ) if stmt . enz is not None : enz_str = _assemble_agent_str ( stmt . enz ) if _get_is_direct ( stmt ) : mod_str = ' ' + _mod_process_verb ( stmt ) + ' ' else : mod_str = ' leads to the ' + _mod_process_noun ( stmt ) + ' of ' stmt_str = enz...
Assemble Modification statements into text .
17,906
def _assemble_association ( stmt ) : member_strs = [ _assemble_agent_str ( m . concept ) for m in stmt . members ] stmt_str = member_strs [ 0 ] + ' is associated with ' + _join_list ( member_strs [ 1 : ] ) return _make_sentence ( stmt_str )
Assemble Association statements into text .
17,907
def _assemble_complex ( stmt ) : member_strs = [ _assemble_agent_str ( m ) for m in stmt . members ] stmt_str = member_strs [ 0 ] + ' binds ' + _join_list ( member_strs [ 1 : ] ) return _make_sentence ( stmt_str )
Assemble Complex statements into text .
17,908
def _assemble_autophosphorylation ( stmt ) : enz_str = _assemble_agent_str ( stmt . enz ) stmt_str = enz_str + ' phosphorylates itself' if stmt . residue is not None : if stmt . position is None : mod_str = 'on ' + ist . amino_acids [ stmt . residue ] [ 'full_name' ] else : mod_str = 'on ' + stmt . residue + stmt . pos...
Assemble Autophosphorylation statements into text .
17,909
def _assemble_regulate_activity ( stmt ) : subj_str = _assemble_agent_str ( stmt . subj ) obj_str = _assemble_agent_str ( stmt . obj ) if stmt . is_activation : rel_str = ' activates ' else : rel_str = ' inhibits ' stmt_str = subj_str + rel_str + obj_str return _make_sentence ( stmt_str )
Assemble RegulateActivity statements into text .
17,910
def _assemble_regulate_amount ( stmt ) : obj_str = _assemble_agent_str ( stmt . obj ) if stmt . subj is not None : subj_str = _assemble_agent_str ( stmt . subj ) if isinstance ( stmt , ist . IncreaseAmount ) : rel_str = ' increases the amount of ' elif isinstance ( stmt , ist . DecreaseAmount ) : rel_str = ' decreases ...
Assemble RegulateAmount statements into text .
17,911
def _assemble_translocation ( stmt ) : agent_str = _assemble_agent_str ( stmt . agent ) stmt_str = agent_str + ' translocates' if stmt . from_location is not None : stmt_str += ' from the ' + stmt . from_location if stmt . to_location is not None : stmt_str += ' to the ' + stmt . to_location return _make_sentence ( stm...
Assemble Translocation statements into text .
17,912
def _assemble_gap ( stmt ) : subj_str = _assemble_agent_str ( stmt . gap ) obj_str = _assemble_agent_str ( stmt . ras ) stmt_str = subj_str + ' is a GAP for ' + obj_str return _make_sentence ( stmt_str )
Assemble Gap statements into text .
17,913
def _assemble_gef ( stmt ) : subj_str = _assemble_agent_str ( stmt . gef ) obj_str = _assemble_agent_str ( stmt . ras ) stmt_str = subj_str + ' is a GEF for ' + obj_str return _make_sentence ( stmt_str )
Assemble Gef statements into text .
17,914
def _assemble_conversion ( stmt ) : reactants = _join_list ( [ _assemble_agent_str ( r ) for r in stmt . obj_from ] ) products = _join_list ( [ _assemble_agent_str ( r ) for r in stmt . obj_to ] ) if stmt . subj is not None : subj_str = _assemble_agent_str ( stmt . subj ) stmt_str = '%s catalyzes the conversion of %s i...
Assemble a Conversion statement into text .
17,915
def _assemble_influence ( stmt ) : subj_str = _assemble_agent_str ( stmt . subj . concept ) obj_str = _assemble_agent_str ( stmt . obj . concept ) if stmt . subj . delta [ 'polarity' ] is not None : subj_delta_str = ' decrease' if stmt . subj . delta [ 'polarity' ] == - 1 else 'n increase' subj_str = 'a%s in %s' % ( su...
Assemble an Influence statement into text .
17,916
def _make_sentence ( txt ) : txt = txt . strip ( ' ' ) txt = txt [ 0 ] . upper ( ) + txt [ 1 : ] + '.' return txt
Make a sentence from a piece of text .
17,917
def _get_is_hypothesis ( stmt ) : for ev in stmt . evidence : if not ev . epistemics . get ( 'hypothesis' ) is True : return True return False
Returns true if there is evidence that the statement is only hypothetical . If all of the evidences associated with the statement indicate a hypothetical interaction then we assume the interaction is hypothetical .
17,918
def make_model ( self ) : stmt_strs = [ ] for stmt in self . statements : if isinstance ( stmt , ist . Modification ) : stmt_strs . append ( _assemble_modification ( stmt ) ) elif isinstance ( stmt , ist . Autophosphorylation ) : stmt_strs . append ( _assemble_autophosphorylation ( stmt ) ) elif isinstance ( stmt , ist...
Assemble text from the set of collected INDRA Statements .
17,919
def add_statements ( self , stmts ) : for stmt in stmts : if not self . statement_exists ( stmt ) : self . statements . append ( stmt )
Add INDRA Statements to the assembler s list of statements .
17,920
def make_model ( self ) : ppa = PysbPreassembler ( self . statements ) ppa . replace_activities ( ) self . statements = ppa . statements self . sbgn = emaker . sbgn ( ) self . _map = emaker . map ( ) self . sbgn . append ( self . _map ) for stmt in self . statements : if isinstance ( stmt , Modification ) : self . _ass...
Assemble the SBGN model from the collected INDRA Statements .
17,921
def print_model ( self , pretty = True , encoding = 'utf8' ) : return lxml . etree . tostring ( self . sbgn , pretty_print = pretty , encoding = encoding , xml_declaration = True )
Return the assembled SBGN model as an XML string .
17,922
def save_model ( self , file_name = 'model.sbgn' ) : model = self . print_model ( ) with open ( file_name , 'wb' ) as fh : fh . write ( model )
Save the assembled SBGN model in a file .
17,923
def _glyph_for_complex_pattern ( self , pattern ) : monomer_glyphs = [ ] for monomer_pattern in pattern . monomer_patterns : glyph = self . _glyph_for_monomer_pattern ( monomer_pattern ) monomer_glyphs . append ( glyph ) if len ( monomer_glyphs ) > 1 : pattern . matches_key = lambda : str ( pattern ) agent_id = self . ...
Add glyph and member glyphs for a PySB ComplexPattern .
17,924
def _glyph_for_monomer_pattern ( self , pattern ) : pattern . matches_key = lambda : str ( pattern ) agent_id = self . _make_agent_id ( pattern ) if pattern . monomer . name in ( '__source' , '__sink' ) : return None glyph = emaker . glyph ( emaker . label ( text = pattern . monomer . name ) , emaker . bbox ( ** self ....
Add glyph for a PySB MonomerPattern .
17,925
def load_go_graph ( go_fname ) : global _go_graph if _go_graph is None : _go_graph = rdflib . Graph ( ) logger . info ( "Parsing GO OWL file" ) _go_graph . parse ( os . path . abspath ( go_fname ) ) return _go_graph
Load the GO data from an OWL file and parse into an RDF graph .
17,926
def update_id_mappings ( g ) : g = load_go_graph ( go_owl_path ) query = _prefixes + logger . info ( "Querying for GO ID mappings" ) res = g . query ( query ) mappings = [ ] for id_lit , label_lit in sorted ( res , key = lambda x : x [ 0 ] ) : mappings . append ( ( id_lit . value , label_lit . value ) ) write_unicode_c...
Compile all ID - > label mappings and save to a TSV file .
17,927
def get_default_ndex_cred ( ndex_cred ) : if ndex_cred : username = ndex_cred . get ( 'user' ) password = ndex_cred . get ( 'password' ) if username is not None and password is not None : return username , password username = get_config ( 'NDEX_USERNAME' ) password = get_config ( 'NDEX_PASSWORD' ) return username , pas...
Gets the NDEx credentials from the dict or tries the environment if None
17,928
def send_request ( ndex_service_url , params , is_json = True , use_get = False ) : if use_get : res = requests . get ( ndex_service_url , json = params ) else : res = requests . post ( ndex_service_url , json = params ) status = res . status_code if status == 200 : if is_json : return res . json ( ) else : return res ...
Send a request to the NDEx server .
17,929
def update_network ( cx_str , network_id , ndex_cred = None ) : server = 'http://public.ndexbio.org' username , password = get_default_ndex_cred ( ndex_cred ) nd = ndex2 . client . Ndex2 ( server , username , password ) try : logger . info ( 'Getting network summary...' ) summary = nd . get_network_summary ( network_id...
Update an existing CX network on NDEx with new CX content .
17,930
def set_style ( network_id , ndex_cred = None , template_id = None ) : if not template_id : template_id = "ea4ea3b7-6903-11e7-961c-0ac135e8bacf" server = 'http://public.ndexbio.org' username , password = get_default_ndex_cred ( ndex_cred ) source_network = ndex2 . create_nice_cx_from_server ( username = username , pass...
Set the style of the network to a given template network s style
17,931
def initialize ( self , cfg_file = None , mode = None ) : self . sim = ScipyOdeSimulator ( self . model ) self . state = numpy . array ( copy . copy ( self . sim . initials ) [ 0 ] ) self . time = numpy . array ( 0.0 ) self . status = 'initialized'
Initialize the model for simulation possibly given a config file .
17,932
def update ( self , dt = None ) : dt = dt if ( dt is not None and dt > 0 ) else self . dt tspan = [ 0 , dt ] res = self . sim . run ( tspan = tspan , initials = self . state ) self . state = res . species [ - 1 ] self . time += dt if self . time > self . stop_time : self . DONE = True print ( ( self . time , self . sta...
Simulate the model for a given time interval .
17,933
def set_value ( self , var_name , value ) : if var_name in self . outside_name_map : var_name = self . outside_name_map [ var_name ] print ( '%s=%.5f' % ( var_name , 1e9 * value ) ) if var_name == 'Precipitation' : value = 1e9 * value species_idx = self . species_name_map [ var_name ] self . state [ species_idx ] = val...
Set the value of a given variable to a given value .
17,934
def get_value ( self , var_name ) : if var_name in self . outside_name_map : var_name = self . outside_name_map [ var_name ] species_idx = self . species_name_map [ var_name ] return self . state [ species_idx ]
Return the value of a given variable .
17,935
def get_input_var_names ( self ) : in_vars = copy . copy ( self . input_vars ) for idx , var in enumerate ( in_vars ) : if self . _map_in_out ( var ) is not None : in_vars [ idx ] = self . _map_in_out ( var ) return in_vars
Return a list of variables names that can be set as input .
17,936
def get_output_var_names ( self ) : all_vars = list ( self . species_name_map . keys ( ) ) output_vars = list ( set ( all_vars ) - set ( self . input_vars ) ) for idx , var in enumerate ( output_vars ) : if self . _map_in_out ( var ) is not None : output_vars [ idx ] = self . _map_in_out ( var ) return output_vars
Return a list of variables names that can be read as output .
17,937
def make_repository_component ( self ) : component = etree . Element ( 'component' ) comp_name = etree . Element ( 'comp_name' ) comp_name . text = self . model . name component . append ( comp_name ) mod_path = etree . Element ( 'module_path' ) mod_path . text = os . getcwd ( ) component . append ( mod_path ) mod_name...
Return an XML string representing this BMI in a workflow .
17,938
def _map_in_out ( self , inside_var_name ) : for out_name , in_name in self . outside_name_map . items ( ) : if inside_var_name == in_name : return out_name return None
Return the external name of a variable mapped from inside .
17,939
def read_pmid ( pmid , source , cont_path , sparser_version , outbuf = None , cleanup = True ) : "Run sparser on a single pmid." signal . signal ( signal . SIGALRM , _timeout_handler ) signal . alarm ( 60 ) try : if ( source is 'content_not_found' or source . startswith ( 'unhandled_content_type' ) or source . endswith...
Run sparser on a single pmid .
17,940
def get_stmts ( pmids_unread , cleanup = True , sparser_version = None ) : "Run sparser on the pmids in pmids_unread." if sparser_version is None : sparser_version = sparser . get_version ( ) stmts = { } now = datetime . now ( ) outbuf_fname = 'sparser_%s_%s.log' % ( now . strftime ( '%Y%m%d-%H%M%S' ) , mp . current_pr...
Run sparser on the pmids in pmids_unread .
17,941
def run_sparser ( pmid_list , tmp_dir , num_cores , start_index , end_index , force_read , force_fulltext , cleanup = True , verbose = True ) : 'Run the sparser reader on the pmids in pmid_list.' reader_version = sparser . get_version ( ) _ , _ , _ , pmids_read , pmids_unread , _ = get_content_to_read ( pmid_list , sta...
Run the sparser reader on the pmids in pmid_list .
17,942
def get_all_descendants ( parent ) : children = parent . __subclasses__ ( ) descendants = children [ : ] for child in children : descendants += get_all_descendants ( child ) return descendants
Get all the descendants of a parent class recursively .
17,943
def get_type_hierarchy ( s ) : tp = type ( s ) if not isinstance ( s , type ) else s p_list = [ tp ] for p in tp . __bases__ : if p is not Statement : p_list . extend ( get_type_hierarchy ( p ) ) else : p_list . append ( p ) return p_list
Get the sequence of parents from s to Statement .
17,944
def get_statement_by_name ( stmt_name ) : stmt_classes = get_all_descendants ( Statement ) for stmt_class in stmt_classes : if stmt_class . __name__ . lower ( ) == stmt_name . lower ( ) : return stmt_class raise NotAStatementName ( '\"%s\" is not recognized as a statement type!' % stmt_name )
Get a statement class given the name of the statement class .
17,945
def get_unresolved_support_uuids ( stmts ) : return { s . uuid for stmt in stmts for s in stmt . supports + stmt . supported_by if isinstance ( s , Unresolved ) }
Get uuids unresolved in support from stmts from stmts_from_json .
17,946
def stmt_type ( obj , mk = True ) : if isinstance ( obj , Statement ) and mk : return type ( obj ) else : return type ( obj ) . __name__
Return standardized backwards compatible object type String .
17,947
def get_hash ( self , shallow = True , refresh = False ) : if shallow : if not hasattr ( self , '_shallow_hash' ) or self . _shallow_hash is None or refresh : self . _shallow_hash = make_hash ( self . matches_key ( ) , 14 ) ret = self . _shallow_hash else : if not hasattr ( self , '_full_hash' ) or self . _full_hash is...
Get a hash for this Statement .
17,948
def _tag_evidence ( self ) : h = self . get_hash ( shallow = False ) for ev in self . evidence : ev . stmt_tag = h return
Set all the Evidence stmt_tag to my deep matches - key hash .
17,949
def agent_list ( self , deep_sorted = False ) : ag_list = [ ] for ag_name in self . _agent_order : ag_attr = getattr ( self , ag_name ) if isinstance ( ag_attr , Concept ) or ag_attr is None : ag_list . append ( ag_attr ) elif isinstance ( ag_attr , list ) : if not all ( [ isinstance ( ag , Concept ) for ag in ag_attr ...
Get the canonicallized agent list .
17,950
def to_json ( self , use_sbo = False ) : stmt_type = type ( self ) . __name__ all_stmts = [ self ] + self . supports + self . supported_by for st in all_stmts : if not hasattr ( st , 'uuid' ) : st . uuid = '%s' % uuid . uuid4 ( ) json_dict = _o ( type = stmt_type ) json_dict [ 'belief' ] = self . belief if self . evide...
Return serialized Statement as a JSON dict .
17,951
def to_graph ( self ) : def json_node ( graph , element , prefix ) : if not element : return None node_id = '|' . join ( prefix ) if isinstance ( element , list ) : graph . add_node ( node_id , label = '' ) for i , sub_element in enumerate ( element ) : sub_id = json_node ( graph , sub_element , prefix + [ '%s' % i ] )...
Return Statement as a networkx graph .
17,952
def make_generic_copy ( self , deeply = False ) : if deeply : kwargs = deepcopy ( self . __dict__ ) else : kwargs = self . __dict__ . copy ( ) for attr in [ 'evidence' , 'belief' , 'uuid' , 'supports' , 'supported_by' , 'is_activation' ] : kwargs . pop ( attr , None ) for attr in [ '_full_hash' , '_shallow_hash' ] : my...
Make a new matching Statement with no provenance .
17,953
def load_lincs_csv ( url ) : resp = requests . get ( url , params = { 'output_type' : '.csv' } , timeout = 120 ) resp . raise_for_status ( ) if sys . version_info [ 0 ] < 3 : csv_io = BytesIO ( resp . content ) else : csv_io = StringIO ( resp . text ) data_rows = list ( read_unicode_csv_fileobj ( csv_io , delimiter = '...
Helper function to turn csv rows into dicts .
17,954
def get_small_molecule_name ( self , hms_lincs_id ) : entry = self . _get_entry_by_id ( self . _sm_data , hms_lincs_id ) if not entry : return None name = entry [ 'Name' ] return name
Get the name of a small molecule from the LINCS sm metadata .
17,955
def get_small_molecule_refs ( self , hms_lincs_id ) : refs = { 'HMS-LINCS' : hms_lincs_id } entry = self . _get_entry_by_id ( self . _sm_data , hms_lincs_id ) if not entry : return refs mappings = dict ( chembl = 'ChEMBL ID' , chebi = 'ChEBI ID' , pubchem = 'PubChem CID' , lincs = 'LINCS ID' ) for k , v in mappings . i...
Get the id refs of a small molecule from the LINCS sm metadata .
17,956
def get_protein_refs ( self , hms_lincs_id ) : refs = { 'HMS-LINCS' : hms_lincs_id } entry = self . _get_entry_by_id ( self . _prot_data , hms_lincs_id ) if not entry : return refs mappings = dict ( egid = 'Gene ID' , up = 'UniProt ID' ) for k , v in mappings . items ( ) : if entry . get ( v ) : refs [ k . upper ( ) ] ...
Get the refs for a protein from the LINCs protein metadata .
17,957
def get_bel_stmts ( self , filter = False ) : if self . basename is not None : bel_stmt_path = '%s_bel_stmts.pkl' % self . basename if self . basename is not None and os . path . isfile ( bel_stmt_path ) : logger . info ( "Loading BEL statements from %s" % bel_stmt_path ) with open ( bel_stmt_path , 'rb' ) as f : bel_s...
Get relevant statements from the BEL large corpus .
17,958
def get_biopax_stmts ( self , filter = False , query = 'pathsbetween' , database_filter = None ) : if self . basename is not None : biopax_stmt_path = '%s_biopax_stmts.pkl' % self . basename biopax_ras_owl_path = '%s_pc_pathsbetween.owl' % self . basename if self . basename is not None and os . path . isfile ( biopax_s...
Get relevant statements from Pathway Commons .
17,959
def get_statements ( self , filter = False ) : bp_stmts = self . get_biopax_stmts ( filter = filter ) bel_stmts = self . get_bel_stmts ( filter = filter ) return bp_stmts + bel_stmts
Return the combined list of statements from BEL and Pathway Commons .
17,960
def run_preassembly ( self , stmts , print_summary = True ) : pa1 = Preassembler ( hierarchies , stmts ) logger . info ( "Combining duplicates" ) pa1 . combine_duplicates ( ) logger . info ( "Mapping sites" ) ( valid , mapped ) = sm . map_sites ( pa1 . unique_stmts ) correctly_mapped_stmts = [ ] for ms in mapped : if a...
Run complete preassembly procedure on the given statements .
17,961
def _get_grounding ( entity ) : db_refs = { 'TEXT' : entity [ 'text' ] } groundings = entity . get ( 'grounding' ) if not groundings : return db_refs def get_ont_concept ( concept ) : if concept . startswith ( '/' ) : concept = concept [ 1 : ] concept = concept . replace ( ' ' , '_' ) while concept not in hume_onto_ent...
Return Hume grounding .
17,962
def _find_relations ( self ) : extractions = list ( self . tree . execute ( "$.extractions[(@.@type is 'Extraction')]" ) ) relations = [ ] for e in extractions : label_set = set ( e . get ( 'labels' , [ ] ) ) if 'DirectedRelation' in label_set : self . relation_dict [ e [ '@id' ] ] = e subtype = e . get ( 'subtype' ) i...
Find all relevant relation elements and return them in a list .
17,963
def _get_documents ( self ) : documents = self . tree . execute ( "$.documents" ) for doc in documents : sentences = { s [ '@id' ] : s [ 'text' ] for s in doc . get ( 'sentences' , [ ] ) } self . document_dict [ doc [ '@id' ] ] = { 'sentences' : sentences , 'location' : doc [ 'location' ] }
Populate sentences attribute with a dict keyed by document id .
17,964
def _make_context ( self , entity ) : loc_context = None time_context = None for argument in entity [ "arguments" ] : if argument [ "type" ] == "place" : entity_id = argument [ "value" ] [ "@id" ] loc_entity = self . concept_dict [ entity_id ] place = loc_entity . get ( "canonicalName" ) if not place : place = loc_enti...
Get place and time info from the json for this entity .
17,965
def _make_concept ( self , entity ) : name = self . _sanitize ( entity [ 'canonicalName' ] ) db_refs = _get_grounding ( entity ) concept = Concept ( name , db_refs = db_refs ) metadata = { arg [ 'type' ] : arg [ 'value' ] [ '@id' ] for arg in entity [ 'arguments' ] } return concept , metadata
Return Concept from a Hume entity .
17,966
def _get_event_and_context ( self , event , arg_type ) : eid = _choose_id ( event , arg_type ) ev = self . concept_dict [ eid ] concept , metadata = self . _make_concept ( ev ) ev_delta = { 'adjectives' : [ ] , 'states' : get_states ( ev ) , 'polarity' : get_polarity ( ev ) } context = self . _make_context ( ev ) event...
Return an INDRA Event based on an event entry .
17,967
def _get_evidence ( self , event , adjectives ) : provenance = event . get ( 'provenance' ) doc_id = provenance [ 0 ] [ 'document' ] [ '@id' ] sent_id = provenance [ 0 ] [ 'sentence' ] text = self . document_dict [ doc_id ] [ 'sentences' ] [ sent_id ] text = self . _sanitize ( text ) bounds = [ provenance [ 0 ] [ 'docu...
Return the Evidence object for the INDRA Statement .
17,968
def _is_statement_in_list ( new_stmt , old_stmt_list ) : for old_stmt in old_stmt_list : if old_stmt . equals ( new_stmt ) : return True elif old_stmt . evidence_equals ( new_stmt ) and old_stmt . matches ( new_stmt ) : if isinstance ( new_stmt , Complex ) : agent_pairs = zip ( old_stmt . sorted_members ( ) , new_stmt ...
Return True of given statement is equivalent to on in a list
17,969
def normalize_medscan_name ( name ) : suffix = ' complex' for i in range ( 2 ) : if name . endswith ( suffix ) : name = name [ : - len ( suffix ) ] return name
Removes the complex and complex complex suffixes from a medscan agent name so that it better corresponds with the grounding map .
17,970
def _urn_to_db_refs ( urn ) : if urn is None : return { } , None m = URN_PATT . match ( urn ) if m is None : return None , None urn_type , urn_id = m . groups ( ) db_refs = { } db_name = None if urn_type == 'agi-cas' : chebi_id = get_chebi_id_from_cas ( urn_id ) if chebi_id : db_refs [ 'CHEBI' ] = 'CHEBI:%s' % chebi_id...
Converts a Medscan URN to an INDRA db_refs dictionary with grounding information .
17,971
def _untag_sentence ( tagged_sentence ) : untagged_sentence = TAG_PATT . sub ( '\\2' , tagged_sentence ) clean_sentence = JUNK_PATT . sub ( '' , untagged_sentence ) return clean_sentence . strip ( )
Removes all tags in the sentence returning the original sentence without Medscan annotations .
17,972
def _extract_sentence_tags ( tagged_sentence ) : untagged_sentence = _untag_sentence ( tagged_sentence ) decluttered_sentence = JUNK_PATT . sub ( '' , tagged_sentence ) tags = { } endpos = 0 while True : match = TAG_PATT . search ( decluttered_sentence , pos = endpos ) if not match : break endpos = match . end ( ) text...
Given a tagged sentence extracts a dictionary mapping tags to the words or phrases that they tag .
17,973
def get_sites ( self ) : st = self . site_text suffixes = [ ' residue' , ' residues' , ',' , '/' ] for suffix in suffixes : if st . endswith ( suffix ) : st = st [ : - len ( suffix ) ] assert ( not st . endswith ( ',' ) ) st = st . replace ( '(' , '' ) st = st . replace ( ')' , '' ) st = st . replace ( ' or ' , ' and '...
Parse the site - text string and return a list of sites .
17,974
def process_csxml_file ( self , filename , interval = None , lazy = False ) : if interval is None : interval = ( None , None ) tmp_fname = tempfile . mktemp ( os . path . basename ( filename ) ) fix_character_encoding ( filename , tmp_fname ) self . __f = open ( tmp_fname , 'rb' ) self . _gen = self . _iter_through_csx...
Processes a filehandle to MedScan csxml input into INDRA statements .
17,975
def get_parser ( description , input_desc ) : parser = ArgumentParser ( description = description ) parser . add_argument ( dest = 'input_file' , help = input_desc ) parser . add_argument ( '-r' , '--readers' , choices = [ 'reach' , 'sparser' , 'trips' ] , help = 'List of readers to be used.' , nargs = '+' ) parser . a...
Get a parser that is generic to reading scripts .
17,976
def send_request ( endpoint , ** kwargs ) : if api_key is None : logger . error ( 'NewsAPI cannot be used without an API key' ) return None url = '%s/%s' % ( newsapi_url , endpoint ) if 'apiKey' not in kwargs : kwargs [ 'apiKey' ] = api_key if 'pageSize' not in kwargs : kwargs [ 'pageSize' ] = 100 res = requests . get ...
Return the response to a query as JSON from the NewsAPI web service .
17,977
def process_cx_file ( file_name , require_grounding = True ) : with open ( file_name , 'rt' ) as fh : json_list = json . load ( fh ) return process_cx ( json_list , require_grounding = require_grounding )
Process a CX JSON file into Statements .
17,978
def process_ndex_network ( network_id , username = None , password = None , require_grounding = True ) : nd = ndex2 . client . Ndex2 ( username = username , password = password ) res = nd . get_network_as_cx_stream ( network_id ) if res . status_code != 200 : logger . error ( 'Problem downloading network: status code %...
Process an NDEx network into Statements .
17,979
def process_cx ( cx_json , summary = None , require_grounding = True ) : ncp = NdexCxProcessor ( cx_json , summary = summary , require_grounding = require_grounding ) ncp . get_statements ( ) return ncp
Process a CX JSON object into Statements .
17,980
def read_files ( files , readers , ** kwargs ) : reading_content = [ Content . from_file ( filepath ) for filepath in files ] output_list = [ ] for reader in readers : res_list = reader . read ( reading_content , ** kwargs ) if res_list is None : logger . info ( "Nothing read by %s." % reader . name ) else : logger . i...
Read the files in files with the reader objects in readers .
17,981
def expand_families ( self , stmts ) : new_stmts = [ ] for stmt in stmts : families_list = [ ] for ag in stmt . agent_list ( ) : ag_children = self . get_children ( ag ) if len ( ag_children ) == 0 : families_list . append ( [ ag ] ) else : families_list . append ( ag_children ) for ag_combo in itertools . product ( * ...
Generate statements by expanding members of families and complexes .
17,982
def update_ontology ( ont_url , rdf_path ) : yaml_root = load_yaml_from_url ( ont_url ) G = rdf_graph_from_yaml ( yaml_root ) save_hierarchy ( G , rdf_path )
Load an ontology formatted like Eidos from github .
17,983
def rdf_graph_from_yaml ( yaml_root ) : G = Graph ( ) for top_entry in yaml_root : assert len ( top_entry ) == 1 node = list ( top_entry . keys ( ) ) [ 0 ] build_relations ( G , node , top_entry [ node ] , None ) return G
Convert the YAML object into an RDF Graph object .
17,984
def load_yaml_from_url ( ont_url ) : res = requests . get ( ont_url ) if res . status_code != 200 : raise Exception ( 'Could not load ontology from %s' % ont_url ) root = yaml . load ( res . content ) return root
Return a YAML object loaded from a YAML file URL .
17,985
def register_preprocessed_file ( self , infile , pmid , extra_annotations ) : infile_base = os . path . basename ( infile ) outfile = os . path . join ( self . preprocessed_dir , infile_base ) shutil . copyfile ( infile , outfile ) infile_key = os . path . splitext ( infile_base ) [ 0 ] self . pmids [ infile_key ] = pm...
Set up already preprocessed text file for reading with ISI reader .
17,986
def preprocess_plain_text_string ( self , text , pmid , extra_annotations ) : output_file = '%s.txt' % self . next_file_id output_file = os . path . join ( self . preprocessed_dir , output_file ) sentences = nltk . sent_tokenize ( text ) first_sentence = True with codecs . open ( output_file , 'w' , encoding = 'utf-8' ...
Preprocess plain text string for use by ISI reader .
17,987
def preprocess_plain_text_file ( self , filename , pmid , extra_annotations ) : with codecs . open ( filename , 'r' , encoding = 'utf-8' ) as f : content = f . read ( ) self . preprocess_plain_text_string ( content , pmid , extra_annotations )
Preprocess a plain text file for use with ISI reder .
17,988
def preprocess_nxml_file ( self , filename , pmid , extra_annotations ) : tmp_dir = tempfile . mkdtemp ( 'indra_isi_nxml2txt_output' ) if nxml2txt_path is None : logger . error ( 'NXML2TXT_PATH not specified in config file or ' + 'environment variable' ) return if python2_path is None : logger . error ( 'PYTHON2_PATH n...
Preprocess an NXML file for use with the ISI reader .
17,989
def preprocess_abstract_list ( self , abstract_list ) : for abstract_struct in abstract_list : abs_format = abstract_struct [ 'format' ] content_type = abstract_struct [ 'text_type' ] content_zipped = abstract_struct [ 'content' ] tcid = abstract_struct [ 'tcid' ] trid = abstract_struct [ 'trid' ] assert ( abs_format =...
Preprocess abstracts in database pickle dump format for ISI reader .
17,990
def process_geneways_files ( input_folder = data_folder , get_evidence = True ) : gp = GenewaysProcessor ( input_folder , get_evidence ) return gp
Reads in Geneways data and returns a list of statements .
17,991
def post_flag_create ( self , post_id , reason ) : params = { 'post_flag[post_id]' : post_id , 'post_flag[reason]' : reason } return self . _get ( 'post_flags.json' , params , 'POST' , auth = True )
Function to flag a post .
17,992
def post_versions_list ( self , updater_name = None , updater_id = None , post_id = None , start_id = None ) : params = { 'search[updater_name]' : updater_name , 'search[updater_id]' : updater_id , 'search[post_id]' : post_id , 'search[start_id]' : start_id } return self . _get ( 'post_versions.json' , params )
Get list of post versions .
17,993
def artist_list ( self , query = None , artist_id = None , creator_name = None , creator_id = None , is_active = None , is_banned = None , empty_only = None , order = None ) : params = { 'search[name]' : query , 'search[id]' : artist_id , 'search[creator_name]' : creator_name , 'search[creator_id]' : creator_id , 'sear...
Get an artist of a list of artists .
17,994
def artist_commentary_list ( self , text_matches = None , post_id = None , post_tags_match = None , original_present = None , translated_present = None ) : params = { 'search[text_matches]' : text_matches , 'search[post_id]' : post_id , 'search[post_tags_match]' : post_tags_match , 'search[original_present]' : original...
list artist commentary .
17,995
def artist_commentary_versions ( self , post_id , updater_id ) : params = { 'search[updater_id]' : updater_id , 'search[post_id]' : post_id } return self . _get ( 'artist_commentary_versions.json' , params )
Return list of artist commentary versions .
17,996
def note_list ( self , body_matches = None , post_id = None , post_tags_match = None , creator_name = None , creator_id = None , is_active = None ) : params = { 'search[body_matches]' : body_matches , 'search[post_id]' : post_id , 'search[post_tags_match]' : post_tags_match , 'search[creator_name]' : creator_name , 'se...
Return list of notes .
17,997
def note_versions ( self , updater_id = None , post_id = None , note_id = None ) : params = { 'search[updater_id]' : updater_id , 'search[post_id]' : post_id , 'search[note_id]' : note_id } return self . _get ( 'note_versions.json' , params )
Get list of note versions .
17,998
def user_list ( self , name = None , name_matches = None , min_level = None , max_level = None , level = None , user_id = None , order = None ) : params = { 'search[name]' : name , 'search[name_matches]' : name_matches , 'search[min_level]' : min_level , 'search[max_level]' : max_level , 'search[level]' : level , 'sear...
Function to get a list of users or a specific user .
17,999
def pool_list ( self , name_matches = None , pool_ids = None , category = None , description_matches = None , creator_name = None , creator_id = None , is_deleted = None , is_active = None , order = None ) : params = { 'search[name_matches]' : name_matches , 'search[id]' : pool_ids , 'search[description_matches]' : des...
Get a list of pools .