idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
17,400 | def gather_implicit_activities ( self ) : for stmt in self . statements : if isinstance ( stmt , Phosphorylation ) or isinstance ( stmt , Transphosphorylation ) or isinstance ( stmt , Autophosphorylation ) : if stmt . enz is not None : enz_base = self . _get_base ( stmt . enz ) enz_base . add_activity ( 'kinase' ) enz_... | Aggregate all implicit activities and active forms of Agents . |
17,401 | def require_active_forms ( self ) : logger . info ( 'Setting required active forms on %d statements...' % len ( self . statements ) ) new_stmts = [ ] for stmt in self . statements : if isinstance ( stmt , Modification ) : if stmt . enz is None : new_stmts . append ( stmt ) continue enz_base = self . _get_base ( stmt . ... | Rewrites Statements with Agents active forms in active positions . |
17,402 | def reduce_activities ( self ) : for stmt in self . statements : agents = stmt . agent_list ( ) for agent in agents : if agent is not None and agent . activity is not None : agent_base = self . _get_base ( agent ) act_red = agent_base . get_activity_reduction ( agent . activity . activity_type ) if act_red is not None ... | Rewrite the activity types referenced in Statements for consistency . |
17,403 | def infer_complexes ( stmts ) : interact_stmts = _get_statements_by_type ( stmts , Modification ) linked_stmts = [ ] for mstmt in interact_stmts : if mstmt . enz is None : continue st = Complex ( [ mstmt . enz , mstmt . sub ] , evidence = mstmt . evidence ) linked_stmts . append ( st ) return linked_stmts | Return inferred Complex from Statements implying physical interaction . |
17,404 | def infer_activations ( stmts ) : linked_stmts = [ ] af_stmts = _get_statements_by_type ( stmts , ActiveForm ) mod_stmts = _get_statements_by_type ( stmts , Modification ) for af_stmt , mod_stmt in itertools . product ( * ( af_stmts , mod_stmts ) ) : if mod_stmt . enz is None or ( not af_stmt . agent . entity_matches (... | Return inferred RegulateActivity from Modification + ActiveForm . |
17,405 | def infer_active_forms ( stmts ) : linked_stmts = [ ] for act_stmt in _get_statements_by_type ( stmts , RegulateActivity ) : if not ( act_stmt . subj . activity is not None and act_stmt . subj . activity . activity_type == 'kinase' and act_stmt . subj . activity . is_active ) : continue matching = [ ] ev = act_stmt . e... | Return inferred ActiveForm from RegulateActivity + Modification . |
17,406 | def infer_modifications ( stmts ) : linked_stmts = [ ] for act_stmt in _get_statements_by_type ( stmts , RegulateActivity ) : for af_stmt in _get_statements_by_type ( stmts , ActiveForm ) : if not af_stmt . agent . entity_matches ( act_stmt . obj ) : continue mods = af_stmt . agent . mods if af_stmt . agent . mutations... | Return inferred Modification from RegulateActivity + ActiveForm . |
17,407 | def replace_complexes ( self , linked_stmts = None ) : if linked_stmts is None : linked_stmts = self . infer_complexes ( self . statements ) new_stmts = [ ] for stmt in self . statements : if not isinstance ( stmt , Complex ) : new_stmts . append ( stmt ) continue found = False for linked_stmt in linked_stmts : if link... | Remove Complex Statements that can be inferred out . |
17,408 | def replace_activations ( self , linked_stmts = None ) : if linked_stmts is None : linked_stmts = self . infer_activations ( self . statements ) new_stmts = [ ] for stmt in self . statements : if not isinstance ( stmt , RegulateActivity ) : new_stmts . append ( stmt ) continue found = False for linked_stmt in linked_st... | Remove RegulateActivity Statements that can be inferred out . |
17,409 | def get_create_base_agent ( self , agent ) : try : base_agent = self . agents [ agent . name ] except KeyError : base_agent = BaseAgent ( agent . name ) self . agents [ agent . name ] = base_agent return base_agent | Return BaseAgent from an Agent creating it if needed . |
17,410 | def apply_to ( self , agent ) : agent . bound_conditions = self . bound_conditions agent . mods = self . mods agent . mutations = self . mutations agent . location = self . location return self . evidence | Apply this object s state to an Agent . |
17,411 | def submit_curation ( ) : if request . json is None : abort ( Response ( 'Missing application/json header.' , 415 ) ) corpus_id = request . json . get ( 'corpus_id' ) curations = request . json . get ( 'curations' , { } ) try : curator . submit_curation ( corpus_id , curations ) except InvalidCorpusError : abort ( Resp... | Submit curations for a given corpus . |
17,412 | def update_beliefs ( ) : if request . json is None : abort ( Response ( 'Missing application/json header.' , 415 ) ) corpus_id = request . json . get ( 'corpus_id' ) try : belief_dict = curator . update_beliefs ( corpus_id ) except InvalidCorpusError : abort ( Response ( 'The corpus_id "%s" is unknown.' % corpus_id , 4... | Return updated beliefs based on current probability model . |
17,413 | def reset_scorer ( self ) : self . scorer = get_eidos_bayesian_scorer ( ) for corpus_id , corpus in self . corpora . items ( ) : corpus . curations = { } | Reset the scorer used for couration . |
17,414 | def get_corpus ( self , corpus_id ) : try : corpus = self . corpora [ corpus_id ] return corpus except KeyError : raise InvalidCorpusError | Return a corpus given an ID . |
17,415 | def update_beliefs ( self , corpus_id ) : corpus = self . get_corpus ( corpus_id ) be = BeliefEngine ( self . scorer ) stmts = list ( corpus . statements . values ( ) ) be . set_prior_probs ( stmts ) for uuid , correct in corpus . curations . items ( ) : stmt = corpus . statements . get ( uuid ) if stmt is None : logge... | Return updated belief scores for a given corpus . |
17,416 | def get_python_list ( scala_list ) : python_list = [ ] for i in range ( scala_list . length ( ) ) : python_list . append ( scala_list . apply ( i ) ) return python_list | Return list from elements of scala . collection . immutable . List |
17,417 | def get_python_dict ( scala_map ) : python_dict = { } keys = get_python_list ( scala_map . keys ( ) . toList ( ) ) for key in keys : python_dict [ key ] = scala_map . apply ( key ) return python_dict | Return a dict from entries in a scala . collection . immutable . Map |
17,418 | def get_python_json ( scala_json ) : def convert_node ( node ) : if node . __class__ . __name__ in ( 'org.json4s.JsonAST$JValue' , 'org.json4s.JsonAST$JObject' ) : values_raw = get_python_dict ( node . values ( ) ) values = { } for k , v in values_raw . items ( ) : values [ k ] = convert_node ( v ) return values elif n... | Return a JSON dict from a org . json4s . JsonAST |
17,419 | def get_heat_kernel ( network_id ) : url = ndex_relevance + '/%s/generate_ndex_heat_kernel' % network_id res = ndex_client . send_request ( url , { } , is_json = True , use_get = True ) if res is None : logger . error ( 'Could not get heat kernel for network %s.' % network_id ) return None kernel_id = res . get ( 'kern... | Return the identifier of a heat kernel calculated for a given network . |
17,420 | def get_relevant_nodes ( network_id , query_nodes ) : url = ndex_relevance + '/rank_entities' kernel_id = get_heat_kernel ( network_id ) if kernel_id is None : return None if isinstance ( query_nodes , basestring ) : query_nodes = [ query_nodes ] params = { 'identifier_set' : query_nodes , 'kernel_id' : kernel_id } res... | Return a set of network nodes relevant to a given query set . |
17,421 | def _get_belief_package ( stmt ) : belief_packages = [ ] for st in stmt . supports : parent_packages = _get_belief_package ( st ) package_stmt_keys = [ pkg . statement_key for pkg in belief_packages ] for package in parent_packages : if package . statement_key not in package_stmt_keys : belief_packages . append ( packa... | Return the belief packages of a given statement recursively . |
17,422 | def sample_statements ( stmts , seed = None ) : if seed : numpy . random . seed ( seed ) new_stmts = [ ] r = numpy . random . rand ( len ( stmts ) ) for i , stmt in enumerate ( stmts ) : if r [ i ] < stmt . belief : new_stmts . append ( stmt ) return new_stmts | Return statements sampled according to belief . |
17,423 | def evidence_random_noise_prior ( evidence , type_probs , subtype_probs ) : ( stype , subtype ) = tag_evidence_subtype ( evidence ) if subtype_probs is not None : if stype in subtype_probs : if subtype in subtype_probs [ stype ] : return subtype_probs [ stype ] [ subtype ] return type_probs [ stype ] | Determines the random - noise prior probability for this evidence . |
17,424 | def tag_evidence_subtype ( evidence ) : source_api = evidence . source_api annotations = evidence . annotations if source_api == 'biopax' : subtype = annotations . get ( 'source_sub_id' ) elif source_api in ( 'reach' , 'eidos' ) : if 'found_by' in annotations : from indra . sources . reach . processor import determine_... | Returns the type and subtype of an evidence object as a string typically the extraction rule or database from which the statement was generated . |
17,425 | def score_evidence_list ( self , evidences ) : def _score ( evidences ) : if not evidences : return 0 sources = [ ev . source_api for ev in evidences ] uniq_sources = numpy . unique ( sources ) syst_factors = { s : self . prior_probs [ 'syst' ] [ s ] for s in uniq_sources } rand_factors = { k : [ ] for k in uniq_source... | Return belief score given a list of supporting evidences . |
17,426 | def score_statement ( self , st , extra_evidence = None ) : if extra_evidence is None : extra_evidence = [ ] all_evidence = st . evidence + extra_evidence return self . score_evidence_list ( all_evidence ) | Computes the prior belief probability for an INDRA Statement . |
17,427 | def check_prior_probs ( self , statements ) : sources = set ( ) for stmt in statements : sources |= set ( [ ev . source_api for ev in stmt . evidence ] ) for err_type in ( 'rand' , 'syst' ) : for source in sources : if source not in self . prior_probs [ err_type ] : msg = 'BeliefEngine missing probability parameter' + ... | Throw Exception if BeliefEngine parameter is missing . |
17,428 | def update_probs ( self ) : syst_error = 0.05 prior_probs = { 'syst' : { } , 'rand' : { } } for source , ( p , n ) in self . prior_counts . items ( ) : if n + p == 0 : continue prior_probs [ 'syst' ] [ source ] = syst_error prior_probs [ 'rand' ] [ source ] = 1 - min ( ( float ( p ) / ( n + p ) , 1 - syst_error ) ) - s... | Update the internal probability values given the counts . |
17,429 | def update_counts ( self , prior_counts , subtype_counts ) : for source , ( pos , neg ) in prior_counts . items ( ) : if source not in self . prior_counts : self . prior_counts [ source ] = [ 0 , 0 ] self . prior_counts [ source ] [ 0 ] += pos self . prior_counts [ source ] [ 1 ] += neg for source , subtype_dict in sub... | Update the internal counts based on given new counts . |
17,430 | def set_prior_probs ( self , statements ) : self . scorer . check_prior_probs ( statements ) for st in statements : st . belief = self . scorer . score_statement ( st ) | Sets the prior belief probabilities for a list of INDRA Statements . |
17,431 | def set_hierarchy_probs ( self , statements ) : def build_hierarchy_graph ( stmts ) : g = networkx . DiGraph ( ) for st1 in stmts : g . add_node ( st1 . matches_key ( ) , stmt = st1 ) for st2 in st1 . supported_by : g . add_node ( st2 . matches_key ( ) , stmt = st2 ) g . add_edge ( st2 . matches_key ( ) , st1 . matches... | Sets hierarchical belief probabilities for INDRA Statements . |
17,432 | def set_linked_probs ( self , linked_statements ) : for st in linked_statements : source_probs = [ s . belief for s in st . source_stmts ] st . inferred_stmt . belief = numpy . prod ( source_probs ) | Sets the belief probabilities for a list of linked INDRA Statements . |
17,433 | def extract_statements ( self ) : for p_info in self . _json : para = RlimspParagraph ( p_info , self . doc_id_type ) self . statements . extend ( para . get_statements ( ) ) return | Extract the statements from the json . |
17,434 | def _get_agent ( self , entity_id ) : if entity_id is None : return None entity_info = self . _entity_dict . get ( entity_id ) if entity_info is None : logger . warning ( "Entity key did not resolve to entity." ) return None return get_agent_from_entity_info ( entity_info ) | Convert the entity dictionary into an INDRA Agent . |
17,435 | def _get_evidence ( self , trigger_id , args , agent_coords , site_coords ) : trigger_info = self . _entity_dict [ trigger_id ] s_idx_set = { self . _entity_dict [ eid ] [ 'sentenceIndex' ] for eid in args . values ( ) if 'sentenceIndex' in self . _entity_dict [ eid ] } if s_idx_set : i_min = min ( s_idx_set ) i_max = ... | Get the evidence using the info in the trigger entity . |
17,436 | def get_reader_classes ( parent = Reader ) : children = parent . __subclasses__ ( ) descendants = children [ : ] for child in children : grandchildren = get_reader_classes ( child ) if grandchildren : descendants . remove ( child ) descendants . extend ( grandchildren ) return descendants | Get all childless the descendants of a parent class recursively . |
17,437 | def get_reader_class ( reader_name ) : for reader_class in get_reader_classes ( ) : if reader_class . name . lower ( ) == reader_name . lower ( ) : return reader_class else : logger . error ( "No such reader: %s" % reader_name ) return None | Get a particular reader class by name . |
17,438 | def from_file ( cls , file_path , compressed = False , encoded = False ) : file_id = '.' . join ( path . basename ( file_path ) . split ( '.' ) [ : - 1 ] ) file_format = file_path . split ( '.' ) [ - 1 ] content = cls ( file_id , file_format , compressed , encoded ) content . file_exists = True content . _location = pa... | Create a content object from a file path . |
17,439 | def change_id ( self , new_id ) : self . _load_raw_content ( ) self . _id = new_id self . get_filename ( renew = True ) self . get_filepath ( renew = True ) return | Change the id of this content . |
17,440 | def change_format ( self , new_format ) : self . _load_raw_content ( ) self . _format = new_format self . get_filename ( renew = True ) self . get_filepath ( renew = True ) return | Change the format label of this content . |
17,441 | def get_text ( self ) : self . _load_raw_content ( ) if self . _text is None : assert self . _raw_content is not None ret_cont = self . _raw_content if self . compressed : ret_cont = zlib . decompress ( ret_cont , zlib . MAX_WBITS + 16 ) if self . encoded : ret_cont = ret_cont . decode ( 'utf-8' ) self . _text = ret_co... | Get the loaded decompressed and decoded text of this content . |
17,442 | def get_filename ( self , renew = False ) : if self . _fname is None or renew : self . _fname = '%s.%s' % ( self . _id , self . _format ) return self . _fname | Get the filename of this content . |
17,443 | def get_filepath ( self , renew = False ) : if self . _location is None or renew : self . _location = '.' return path . join ( self . _location , self . get_filename ( ) ) | Get the file path joining the name and location for this file . |
17,444 | def get_statements ( self , reprocess = False ) : if self . _statements is None or reprocess : if self . content is None : self . _statements = [ ] return [ ] if self . reader == ReachReader . name : if self . format == formats . JSON : json_str = json . dumps ( self . content ) processor = reach . process_json_str ( j... | General method to create statements . |
17,445 | def add_result ( self , content_id , content , ** kwargs ) : result_object = self . ResultClass ( content_id , self . name , self . version , formats . JSON , content , ** kwargs ) self . results . append ( result_object ) return | Add a result to the list of results . |
17,446 | def _check_content ( self , content_str ) : if self . do_content_check : space_ratio = float ( content_str . count ( ' ' ) ) / len ( content_str ) if space_ratio > self . max_space_ratio : return "space-ratio: %f > %f" % ( space_ratio , self . max_space_ratio ) if len ( content_str ) > self . input_character_limit : re... | Check if the content is likely to be successfully read . |
17,447 | def _check_reach_env ( ) : path_to_reach = get_config ( 'REACHPATH' ) if path_to_reach is None : path_to_reach = environ . get ( 'REACHPATH' , None ) if path_to_reach is None or not path . exists ( path_to_reach ) : raise ReachError ( 'Reach path unset or invalid. Check REACHPATH environment var ' 'and/or config file.'... | Check that the environment supports runnig reach . |
17,448 | def prep_input ( self , read_list ) : logger . info ( "Prepping input." ) i = 0 for content in read_list : quality_issue = self . _check_content ( content . get_text ( ) ) if quality_issue is not None : logger . warning ( "Skipping %d due to: %s" % ( content . get_id ( ) , quality_issue ) ) continue cid = content . get... | Apply the readers to the content . |
17,449 | def get_output ( self ) : logger . info ( "Getting outputs." ) json_files = glob . glob ( path . join ( self . output_dir , '*.json' ) ) json_prefixes = set ( ) for json_file in json_files : prefix = '.' . join ( path . basename ( json_file ) . split ( '.' ) [ : - 3 ] ) json_prefixes . add ( path . join ( self . output... | Get the output of a reading job as a list of filenames . |
17,450 | def read ( self , read_list , verbose = False , log = False ) : ret = [ ] mem_tot = _get_mem_total ( ) if mem_tot is not None and mem_tot <= self . REACH_MEM + self . MEM_BUFFER : logger . error ( "Too little memory to run reach. At least %s required." % ( self . REACH_MEM + self . MEM_BUFFER ) ) logger . info ( "REACH... | Read the content returning a list of ReadingData objects . |
17,451 | def prep_input ( self , read_list ) : "Prepare the list of files or text content objects to be read." logger . info ( 'Prepping input for sparser.' ) self . file_list = [ ] for content in read_list : quality_issue = self . _check_content ( content . get_text ( ) ) if quality_issue is not None : logger . warning ( "Skip... | Prepare the list of files or text content objects to be read . |
17,452 | def get_output ( self , output_files , clear = True ) : "Get the output files as an id indexed dict." patt = re . compile ( r'(.*?)-semantics.*?' ) for outpath in output_files : if outpath is None : logger . warning ( "Found outpath with value None. Skipping." ) continue re_out = patt . match ( path . basename ( outpat... | Get the output files as an id indexed dict . |
17,453 | def read_some ( self , fpath_list , outbuf = None , verbose = False ) : "Perform a few readings." outpath_list = [ ] for fpath in fpath_list : output , outbuf = self . read_one ( fpath , outbuf , verbose ) if output is not None : outpath_list . append ( output ) return outpath_list , outbuf | Perform a few readings . |
17,454 | def read ( self , read_list , verbose = False , log = False , n_per_proc = None ) : "Perform the actual reading." ret = [ ] self . prep_input ( read_list ) L = len ( self . file_list ) if L == 0 : return ret logger . info ( "Beginning to run sparser." ) output_file_list = [ ] if log : log_name = 'sparser_run_%s.log' % ... | Perform the actual reading . |
17,455 | def process_text ( text , pmid = None , cleanup = True , add_grounding = True ) : pp_dir = tempfile . mkdtemp ( 'indra_isi_pp_output' ) pp = IsiPreprocessor ( pp_dir ) extra_annotations = { } pp . preprocess_plain_text_string ( text , pmid , extra_annotations ) ip = process_preprocessed ( pp ) if add_grounding : ip . a... | Process a string using the ISI reader and extract INDRA statements . |
17,456 | def process_nxml ( nxml_filename , pmid = None , extra_annotations = None , cleanup = True , add_grounding = True ) : if extra_annotations is None : extra_annotations = { } pp_dir = tempfile . mkdtemp ( 'indra_isi_pp_output' ) pp = IsiPreprocessor ( pp_dir ) extra_annotations = { } pp . preprocess_nxml_file ( nxml_file... | Process an NXML file using the ISI reader |
17,457 | def process_output_folder ( folder_path , pmids = None , extra_annotations = None , add_grounding = True ) : pmids = pmids if pmids is not None else { } extra_annotations = extra_annotations if extra_annotations is not None else { } ips = [ ] for entry in glob . glob ( os . path . join ( folder_path , '*.json' ) ) : en... | Recursively extracts statements from all ISI output files in the given directory and subdirectories . |
17,458 | def process_json_file ( file_path , pmid = None , extra_annotations = None , add_grounding = True ) : logger . info ( 'Extracting from %s' % file_path ) with open ( file_path , 'rb' ) as fh : jd = json . load ( fh ) ip = IsiProcessor ( jd , pmid , extra_annotations ) ip . get_statements ( ) if add_grounding : ip . add_... | Extracts statements from the given ISI output file . |
17,459 | def process_text ( text , save_xml = 'cwms_output.xml' ) : xml = client . send_query ( text , 'cwmsreader' ) first_end = xml . find ( '</ekb>' ) second_start = xml . find ( '<ekb' , first_end ) second_end = xml . find ( '</ekb>' , second_start ) second_ekb = xml [ second_start : second_end + len ( '</ekb>' ) ] if save_... | Processes text using the CWMS web service . |
17,460 | def process_ekb_file ( fname ) : with open ( fname , 'rb' ) as fh : ekb_str = fh . read ( ) . decode ( 'utf-8' ) return process_ekb ( ekb_str ) | Processes an EKB file produced by CWMS . |
17,461 | def im_json_to_graph ( im_json ) : imap_data = im_json [ 'influence map' ] [ 'map' ] graph = MultiDiGraph ( ) id_node_dict = { } for node_dict in imap_data [ 'nodes' ] : node_type , node = list ( node_dict . items ( ) ) [ 0 ] attrs = { 'fillcolor' : '#b7d2ff' if node_type == 'rule' else '#cdffc9' , 'shape' : 'box' if n... | Return networkx graph from Kappy s influence map JSON . |
17,462 | def cm_json_to_graph ( im_json ) : cmap_data = im_json [ 'contact map' ] [ 'map' ] graph = AGraph ( ) edges = [ ] for node_idx , node in enumerate ( cmap_data ) : sites_in_node = [ ] for site_idx , site in enumerate ( node [ 'node_sites' ] ) : site_key = ( node_idx , site_idx ) sites_in_node . append ( site_key ) graph... | Return pygraphviz Agraph from Kappy s contact map JSON . |
17,463 | def fetch_email ( M , msg_id ) : res , data = M . fetch ( msg_id , '(RFC822)' ) if res == 'OK' : raw_msg_txt = data [ 0 ] [ 1 ] try : msg = email . message_from_bytes ( raw_msg_txt ) except AttributeError : msg = email . message_from_string ( raw_msg_txt ) return msg else : return None | Returns the given email message as a unicode string . |
17,464 | def get_headers ( msg ) : headers = { } for k in msg . keys ( ) : ( header_txt , charset ) = email . header . decode_header ( msg [ k ] ) [ 0 ] if charset is not None : header_txt = header_txt . decode ( charset ) headers [ k ] = header_txt return headers | Takes email . message . Message object initialized from unicode string returns dict with header fields . |
17,465 | def populate_config_dict ( config_path ) : try : config_dict = { } parser = RawConfigParser ( ) parser . optionxform = lambda x : x parser . read ( config_path ) sections = parser . sections ( ) for section in sections : options = parser . options ( section ) for option in options : config_dict [ option ] = str ( parse... | Load the configuration file into the config_file dictionary |
17,466 | def get_config ( key , failure_ok = True ) : err_msg = "Key %s not in environment or config file." % key if key in os . environ : return os . environ [ key ] elif key in CONFIG_DICT : val = CONFIG_DICT [ key ] if val is None and not failure_ok : msg = 'Key %s is set to an empty value in config file.' % key raise IndraC... | Get value by key from config file or environment . |
17,467 | def read_unicode_csv_fileobj ( fileobj , delimiter = ',' , quotechar = '"' , quoting = csv . QUOTE_MINIMAL , lineterminator = '\n' , encoding = 'utf-8' , skiprows = 0 ) : if sys . version_info [ 0 ] >= 3 : csv_reader = csv . reader ( fileobj , delimiter = delimiter , quotechar = quotechar , quoting = quoting , lineterm... | fileobj can be a StringIO in Py3 but should be a BytesIO in Py2 . |
17,468 | def fast_deepcopy ( obj ) : with BytesIO ( ) as buf : pickle . dump ( obj , buf ) buf . seek ( 0 ) obj_new = pickle . load ( buf ) return obj_new | This is a faster implementation of deepcopy via pickle . |
17,469 | def batch_iter ( iterator , batch_size , return_func = None , padding = None ) : for batch in zip_longest ( * [ iter ( iterator ) ] * batch_size , fillvalue = padding ) : gen = ( thing for thing in batch if thing is not padding ) if return_func is None : yield gen else : yield return_func ( gen ) | Break an iterable into batches of size batch_size |
17,470 | def read_pmid_sentences ( pmid_sentences , ** drum_args ) : def _set_pmid ( statements , pmid ) : for stmt in statements : for evidence in stmt . evidence : evidence . pmid = pmid run_drum = drum_args . get ( 'run_drum' , False ) drum_process = None all_statements = { } for pmid , sentences in pmid_sentences . items ( ... | Read sentences from a PMID - keyed dictonary and return all Statements |
17,471 | def graph_query ( kind , source , target = None , neighbor_limit = 1 , database_filter = None ) : default_databases = [ 'wp' , 'smpdb' , 'reconx' , 'reactome' , 'psp' , 'pid' , 'panther' , 'netpath' , 'msigdb' , 'mirtarbase' , 'kegg' , 'intact' , 'inoh' , 'humancyc' , 'hprd' , 'drugbank' , 'dip' , 'corum' ] if not data... | Perform a graph query on PathwayCommons . |
17,472 | def owl_str_to_model ( owl_str ) : io_class = autoclass ( 'org.biopax.paxtools.io.SimpleIOHandler' ) io = io_class ( autoclass ( 'org.biopax.paxtools.model.BioPAXLevel' ) . L3 ) bais = autoclass ( 'java.io.ByteArrayInputStream' ) scs = autoclass ( 'java.nio.charset.StandardCharsets' ) jstr = autoclass ( 'java.lang.Stri... | Return a BioPAX model object from an OWL string . |
17,473 | def owl_to_model ( fname ) : io_class = autoclass ( 'org.biopax.paxtools.io.SimpleIOHandler' ) io = io_class ( autoclass ( 'org.biopax.paxtools.model.BioPAXLevel' ) . L3 ) try : file_is = autoclass ( 'java.io.FileInputStream' ) ( fname ) except JavaException : logger . error ( 'Could not open data file %s' % fname ) re... | Return a BioPAX model object from an OWL file . |
17,474 | def model_to_owl ( model , fname ) : io_class = autoclass ( 'org.biopax.paxtools.io.SimpleIOHandler' ) io = io_class ( autoclass ( 'org.biopax.paxtools.model.BioPAXLevel' ) . L3 ) try : fileOS = autoclass ( 'java.io.FileOutputStream' ) ( fname ) except JavaException : logger . error ( 'Could not open data file %s' % fn... | Save a BioPAX model object as an OWL file . |
17,475 | def make_model ( self , * args , ** kwargs ) : for stmt in self . statements : if isinstance ( stmt , RegulateActivity ) : self . _add_regulate_activity ( stmt ) elif isinstance ( stmt , RegulateAmount ) : self . _add_regulate_amount ( stmt ) elif isinstance ( stmt , Modification ) : self . _add_modification ( stmt ) e... | Assemble a Cytoscape JS network from INDRA Statements . |
17,476 | def get_gene_names ( self ) : gene_names = [ ] for node in self . _nodes : members = node [ 'data' ] . get ( 'members' ) if members : gene_names += list ( members . keys ( ) ) else : if node [ 'data' ] [ 'name' ] . startswith ( 'Group' ) : continue gene_names . append ( node [ 'data' ] [ 'name' ] ) self . _gene_names =... | Gather gene names of all nodes and node members |
17,477 | def set_CCLE_context ( self , cell_types ) : self . get_gene_names ( ) exp_values = context_client . get_protein_expression ( self . _gene_names , cell_types ) mut_values = context_client . get_mutations ( self . _gene_names , cell_types ) muts = { cell_line : { } for cell_line in cell_types } for cell_line , entries i... | Set context of all nodes and node members from CCLE . |
17,478 | def print_cyjs_graph ( self ) : cyjs_dict = { 'edges' : self . _edges , 'nodes' : self . _nodes } cyjs_str = json . dumps ( cyjs_dict , indent = 1 , sort_keys = True ) return cyjs_str | Return the assembled Cytoscape JS network as a json string . |
17,479 | def print_cyjs_context ( self ) : context = self . _context context_str = json . dumps ( context , indent = 1 , sort_keys = True ) return context_str | Return a list of node names and their respective context . |
17,480 | def save_json ( self , fname_prefix = 'model' ) : cyjs_str = self . print_cyjs_graph ( ) with open ( fname_prefix + '.json' , 'wb' ) as fh : fh . write ( cyjs_str . encode ( 'utf-8' ) ) context_str = self . print_cyjs_context ( ) with open ( fname_prefix + '_context.json' , 'wb' ) as fh : fh . write ( context_str . enc... | Save the assembled Cytoscape JS network in a json file . |
17,481 | def save_model ( self , fname = 'model.js' ) : exp_colorscale_str = json . dumps ( self . _exp_colorscale ) mut_colorscale_str = json . dumps ( self . _mut_colorscale ) cyjs_dict = { 'edges' : self . _edges , 'nodes' : self . _nodes } model_str = json . dumps ( cyjs_dict , indent = 1 , sort_keys = True ) model_dict = {... | Save the assembled Cytoscape JS network in a js file . |
17,482 | def _get_edge_dict ( self ) : edge_dict = collections . defaultdict ( lambda : [ ] ) if len ( self . _edges ) > 0 : for e in self . _edges : data = e [ 'data' ] key = tuple ( [ data [ 'i' ] , data [ 'source' ] , data [ 'target' ] , data [ 'polarity' ] ] ) edge_dict [ key ] = data [ 'id' ] return edge_dict | Return a dict of edges . |
17,483 | def _get_node_key ( self , node_dict_item ) : s = tuple ( sorted ( node_dict_item [ 'sources' ] ) ) t = tuple ( sorted ( node_dict_item [ 'targets' ] ) ) return ( s , t ) | Return a tuple of sorted sources and targets given a node dict . |
17,484 | def _get_node_groups ( self ) : node_dict = { node [ 'data' ] [ 'id' ] : { 'sources' : [ ] , 'targets' : [ ] } for node in self . _nodes } for edge in self . _edges : edge_data = ( edge [ 'data' ] [ 'i' ] , edge [ 'data' ] [ 'polarity' ] , edge [ 'data' ] [ 'source' ] ) node_dict [ edge [ 'data' ] [ 'target' ] ] [ 'sou... | Return a list of node id lists that are topologically identical . |
17,485 | def _group_edges ( self ) : edges_to_add = [ [ ] , [ ] ] for e in self . _edges : new_edge = deepcopy ( e ) new_edge [ 'data' ] . pop ( 'id' , None ) uuid_list = new_edge [ 'data' ] . pop ( 'uuid_list' , [ ] ) source = e [ 'data' ] [ 'source' ] target = e [ 'data' ] [ 'target' ] source_node = [ x for x in self . _nodes... | Group all edges that are topologically identical . |
17,486 | def make_stmt ( stmt_cls , tf_agent , target_agent , pmid ) : ev = Evidence ( source_api = 'trrust' , pmid = pmid ) return stmt_cls ( deepcopy ( tf_agent ) , deepcopy ( target_agent ) , evidence = [ ev ] ) | Return a Statement based on its type agents and PMID . |
17,487 | def get_grounded_agent ( gene_name ) : db_refs = { 'TEXT' : gene_name } if gene_name in hgnc_map : gene_name = hgnc_map [ gene_name ] hgnc_id = hgnc_client . get_hgnc_id ( gene_name ) if hgnc_id : db_refs [ 'HGNC' ] = hgnc_id up_id = hgnc_client . get_uniprot_id ( hgnc_id ) if up_id : db_refs [ 'UP' ] = up_id agent = A... | Return a grounded Agent based on an HGNC symbol . |
17,488 | def extract_statements ( self ) : for _ , ( tf , target , effect , refs ) in self . df . iterrows ( ) : tf_agent = get_grounded_agent ( tf ) target_agent = get_grounded_agent ( target ) if effect == 'Activation' : stmt_cls = IncreaseAmount elif effect == 'Repression' : stmt_cls = DecreaseAmount else : continue pmids = ... | Process the table to extract Statements . |
17,489 | def process_paper ( model_name , pmid ) : json_directory = os . path . join ( model_name , 'jsons' ) json_path = os . path . join ( json_directory , 'PMID%s.json' % pmid ) if pmid . startswith ( 'api' ) or pmid . startswith ( 'PMID' ) : logger . warning ( 'Invalid PMID: %s' % pmid ) if os . path . exists ( json_path ) ... | Process a paper with the given pubmed identifier |
17,490 | def process_paper_helper ( model_name , pmid , start_time_local ) : try : if not aws_available : rp , txt_format = process_paper ( model_name , pmid ) else : rp , txt_format = process_paper_aws ( pmid , start_time_local ) except : logger . exception ( 'uncaught exception while processing %s' , pmid ) return None , None... | Wraps processing a paper by either a local or remote service and caches any uncaught exceptions |
17,491 | def _load_data ( ) : csv_path = path . join ( HERE , path . pardir , path . pardir , 'resources' , DATAFILE_NAME ) data_iter = list ( read_unicode_csv ( csv_path ) ) headers = data_iter [ 0 ] headers [ headers . index ( 'Approved.Symbol' ) ] = 'approved_symbol' return [ { header : val for header , val in zip ( headers ... | Load the data from the csv in data . |
17,492 | def run_eidos ( endpoint , * args ) : call_class = '%s.%s' % ( eidos_package , endpoint ) cmd = [ 'java' , '-Xmx12G' , '-cp' , eip , call_class ] + list ( args ) logger . info ( 'Running Eidos with command "%s"' % ( ' ' . join ( cmd ) ) ) subprocess . call ( cmd ) | Run a given enpoint of Eidos through the command line . |
17,493 | def extract_from_directory ( path_in , path_out ) : path_in = os . path . realpath ( os . path . expanduser ( path_in ) ) path_out = os . path . realpath ( os . path . expanduser ( path_out ) ) logger . info ( 'Running Eidos on input folder %s' % path_in ) run_eidos ( 'apps.ExtractFromDirectory' , path_in , path_out ) | Run Eidos on a set of text files in a folder . |
17,494 | def extract_and_process ( path_in , path_out ) : path_in = os . path . realpath ( os . path . expanduser ( path_in ) ) path_out = os . path . realpath ( os . path . expanduser ( path_out ) ) extract_from_directory ( path_in , path_out ) jsons = glob . glob ( os . path . join ( path_out , '*.jsonld' ) ) logger . info ( ... | Run Eidos on a set of text files and process output with INDRA . |
17,495 | def get_statements ( subject = None , object = None , agents = None , stmt_type = None , use_exact_type = False , persist = True , timeout = None , simple_response = False , ev_limit = 10 , best_first = True , tries = 2 , max_stmts = None ) : processor = IndraDBRestProcessor ( subject , object , agents , stmt_type , us... | Get a processor for the INDRA DB web API matching given agents and type . |
17,496 | def get_statements_by_hash ( hash_list , ev_limit = 100 , best_first = True , tries = 2 ) : if not isinstance ( hash_list , list ) : raise ValueError ( "The `hash_list` input is a list, not %s." % type ( hash_list ) ) if not hash_list : return [ ] if isinstance ( hash_list [ 0 ] , str ) : hash_list = [ int ( h ) for h ... | Get fully formed statements from a list of hashes . |
17,497 | def get_statements_for_paper ( ids , ev_limit = 10 , best_first = True , tries = 2 , max_stmts = None ) : id_l = [ { 'id' : id_val , 'type' : id_type } for id_type , id_val in ids ] resp = submit_statement_request ( 'post' , 'from_papers' , data = { 'ids' : id_l } , ev_limit = ev_limit , best_first = best_first , tries... | Get the set of raw Statements extracted from a paper given by the id . |
17,498 | def submit_curation ( hash_val , tag , curator , text = None , source = 'indra_rest_client' , ev_hash = None , is_test = False ) : data = { 'tag' : tag , 'text' : text , 'curator' : curator , 'source' : source , 'ev_hash' : ev_hash } url = 'curation/submit/%s' % hash_val if is_test : qstr = '?test' else : qstr = '' ret... | Submit a curation for the given statement at the relevant level . |
17,499 | def get_statement_queries ( stmts , ** params ) : def pick_ns ( ag ) : for ns in [ 'HGNC' , 'FPLX' , 'CHEMBL' , 'CHEBI' , 'GO' , 'MESH' ] : if ns in ag . db_refs . keys ( ) : dbid = ag . db_refs [ ns ] break else : ns = 'TEXT' dbid = ag . name return '%s@%s' % ( dbid , ns ) queries = [ ] url_base = get_url_base ( 'stat... | Get queries used to search based on a statement . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.