idx
int64
0
63k
question
stringlengths
53
5.28k
target
stringlengths
5
805
29,400
def validate_signature ( uri , nonce , signature , auth_token = '' ) : auth_token = bytes ( auth_token . encode ( 'utf-8' ) ) nonce = bytes ( nonce . encode ( 'utf-8' ) ) signature = bytes ( signature . encode ( 'utf-8' ) ) parsed_uri = urlparse ( uri . encode ( 'utf-8' ) ) base_url = urlunparse ( ( parsed_uri . scheme...
Validates requests made by Plivo to your servers .
29,401
def fetch_credentials ( auth_id , auth_token ) : if not ( auth_id and auth_token ) : try : auth_id = os . environ [ 'PLIVO_AUTH_ID' ] auth_token = os . environ [ 'PLIVO_AUTH_TOKEN' ] except KeyError : raise AuthenticationError ( 'The Plivo Python SDK ' 'could not find your auth credentials.' ) if not ( is_valid_mainacc...
Fetches the right credentials either from params or from environment
29,402
def process_response ( self , method , response , response_type = None , objects_type = None ) : try : response_json = response . json ( object_hook = lambda x : ResponseObject ( x ) if isinstance ( x , dict ) else x ) if response_type : r = response_type ( self , response_json . __dict__ ) response_json = r if 'object...
Processes the API response based on the status codes and method used to access the API
29,403
def jackknife_indexes ( data ) : base = np . arange ( 0 , len ( data ) ) return ( np . delete ( base , i ) for i in base )
Given data points data where axis 0 is considered to delineate points return a list of arrays where each array is a set of jackknife indexes .
29,404
def bootstrap_indexes_moving_block ( data , n_samples = 10000 , block_length = 3 , wrap = False ) : n_obs = data . shape [ 0 ] n_blocks = int ( ceil ( n_obs / block_length ) ) nexts = np . repeat ( np . arange ( 0 , block_length ) [ None , : ] , n_blocks , axis = 0 ) if wrap : last_block = n_obs else : last_block = n_o...
Generate moving - block bootstrap samples .
29,405
def get_protein_substitution_language ( ) -> ParserElement : parser_element = psub_tag + nest ( amino_acid ( PSUB_REFERENCE ) , ppc . integer ( PSUB_POSITION ) , amino_acid ( PSUB_VARIANT ) , ) parser_element . setParseAction ( _handle_psub ) return parser_element
Build a protein substitution parser .
29,406
def postpend_location ( bel_string : str , location_model ) -> str : if not all ( k in location_model for k in { NAMESPACE , NAME } ) : raise ValueError ( 'Location model missing namespace and/or name keys: {}' . format ( location_model ) ) return "{}, loc({}:{}))" . format ( bel_string [ : - 1 ] , location_model [ NAM...
Rip off the closing parentheses and adds canonicalized modification .
29,407
def _decanonicalize_edge_node ( node : BaseEntity , edge_data : EdgeData , node_position : str ) -> str : node_str = node . as_bel ( ) if node_position not in edge_data : return node_str node_edge_data = edge_data [ node_position ] if LOCATION in node_edge_data : node_str = postpend_location ( node_str , node_edge_data...
Canonicalize a node with its modifiers stored in the given edge to a BEL string .
29,408
def edge_to_bel ( u : BaseEntity , v : BaseEntity , data : EdgeData , sep : Optional [ str ] = None ) -> str : sep = sep or ' ' u_str = _decanonicalize_edge_node ( u , data , node_position = SUBJECT ) v_str = _decanonicalize_edge_node ( v , data , node_position = OBJECT ) return sep . join ( ( u_str , data [ RELATION ]...
Take two nodes and gives back a BEL string representing the statement .
29,409
def sort_qualified_edges ( graph ) -> Iterable [ EdgeTuple ] : qualified_edges = ( ( u , v , k , d ) for u , v , k , d in graph . edges ( keys = True , data = True ) if graph . has_edge_citation ( u , v , k ) and graph . has_edge_evidence ( u , v , k ) ) return sorted ( qualified_edges , key = _sort_qualified_edges_hel...
Return the qualified edges sorted first by citation then by evidence then by annotations .
29,410
def _citation_sort_key ( t : EdgeTuple ) -> str : return '"{}", "{}"' . format ( t [ 3 ] [ CITATION ] [ CITATION_TYPE ] , t [ 3 ] [ CITATION ] [ CITATION_REFERENCE ] )
Make a confusing 4 tuple sortable by citation .
29,411
def _set_annotation_to_str ( annotation_data : Mapping [ str , Mapping [ str , bool ] ] , key : str ) -> str : value = annotation_data [ key ] if len ( value ) == 1 : return 'SET {} = "{}"' . format ( key , list ( value ) [ 0 ] ) x = ( '"{}"' . format ( v ) for v in sorted ( value ) ) return 'SET {} = {{{}}}' . format ...
Return a set annotation string .
29,412
def _unset_annotation_to_str ( keys : List [ str ] ) -> str : if len ( keys ) == 1 : return 'UNSET {}' . format ( list ( keys ) [ 0 ] ) return 'UNSET {{{}}}' . format ( ', ' . join ( '{}' . format ( key ) for key in keys ) )
Return an unset annotation string .
29,413
def _to_bel_lines_header ( graph ) -> Iterable [ str ] : yield '# This document was created by PyBEL v{} and bel-resources v{} on {}\n' . format ( VERSION , bel_resources . constants . VERSION , time . asctime ( ) ) yield from make_knowledge_header ( namespace_url = graph . namespace_url , namespace_patterns = graph . ...
Iterate the lines of a BEL graph s corresponding BEL script s header .
29,414
def group_citation_edges ( edges : Iterable [ EdgeTuple ] ) -> Iterable [ Tuple [ str , Iterable [ EdgeTuple ] ] ] : return itt . groupby ( edges , key = _citation_sort_key )
Return an iterator over pairs of citation values and their corresponding edge iterators .
29,415
def group_evidence_edges ( edges : Iterable [ EdgeTuple ] ) -> Iterable [ Tuple [ str , Iterable [ EdgeTuple ] ] ] : return itt . groupby ( edges , key = _evidence_sort_key )
Return an iterator over pairs of evidence values and their corresponding edge iterators .
29,416
def _to_bel_lines_body ( graph ) -> Iterable [ str ] : qualified_edges = sort_qualified_edges ( graph ) for citation , citation_edges in group_citation_edges ( qualified_edges ) : yield 'SET Citation = {{{}}}\n' . format ( citation ) for evidence , evidence_edges in group_evidence_edges ( citation_edges ) : yield 'SET ...
Iterate the lines of a BEL graph s corresponding BEL script s body .
29,417
def _to_bel_lines_footer ( graph ) -> Iterable [ str ] : unqualified_edges_to_serialize = [ ( u , v , d ) for u , v , d in graph . edges ( data = True ) if d [ RELATION ] in UNQUALIFIED_EDGES and EVIDENCE not in d ] isolated_nodes_to_serialize = [ node for node in graph if not graph . pred [ node ] and not graph . succ...
Iterate the lines of a BEL graph s corresponding BEL script s footer .
29,418
def to_bel_path ( graph , path : str , mode : str = 'w' , ** kwargs ) -> None : with open ( path , mode = mode , ** kwargs ) as bel_file : to_bel ( graph , bel_file )
Write the BEL graph as a canonical BEL Script to the given path .
29,419
def calculate_canonical_name ( data : BaseEntity ) -> str : if data [ FUNCTION ] == COMPLEX and NAMESPACE in data : return data [ NAME ] if VARIANTS in data : return data . as_bel ( ) if FUSION in data : return data . as_bel ( ) if data [ FUNCTION ] in { REACTION , COMPOSITE , COMPLEX } : return data . as_bel ( ) if VA...
Calculate the canonical name for a given node .
29,420
def graph_from_edges ( edges : Iterable [ Edge ] , ** kwargs ) -> BELGraph : graph = BELGraph ( ** kwargs ) for edge in edges : edge . insert_into_graph ( graph ) return graph
Build a BEL graph from edges .
29,421
def query_nodes ( self , bel : Optional [ str ] = None , type : Optional [ str ] = None , namespace : Optional [ str ] = None , name : Optional [ str ] = None , ) -> List [ Node ] : q = self . session . query ( Node ) if bel : q = q . filter ( Node . bel . contains ( bel ) ) if type : q = q . filter ( Node . type == ty...
Query nodes in the database .
29,422
def get_edges_with_citation ( self , citation : Citation ) -> List [ Edge ] : return self . session . query ( Edge ) . join ( Evidence ) . filter ( Evidence . citation == citation )
Get the edges with the given citation .
29,423
def get_edges_with_citations ( self , citations : Iterable [ Citation ] ) -> List [ Edge ] : return self . session . query ( Edge ) . join ( Evidence ) . filter ( Evidence . citation . in_ ( citations ) ) . all ( )
Get edges with one of the given citations .
29,424
def search_edges_with_evidence ( self , evidence : str ) -> List [ Edge ] : return self . session . query ( Edge ) . join ( Evidence ) . filter ( Evidence . text . like ( evidence ) ) . all ( )
Search edges with the given evidence .
29,425
def search_edges_with_bel ( self , bel : str ) -> List [ Edge ] : return self . session . query ( Edge ) . filter ( Edge . bel . like ( bel ) )
Search edges with given BEL .
29,426
def _add_edge_function_filter ( query , edge_node_id , node_type ) : return query . join ( Node , edge_node_id == Node . id ) . filter ( Node . type == node_type )
See usage in self . query_edges .
29,427
def query_edges ( self , bel : Optional [ str ] = None , source_function : Optional [ str ] = None , source : Union [ None , str , Node ] = None , target_function : Optional [ str ] = None , target : Union [ None , str , Node ] = None , relation : Optional [ str ] = None , ) : if bel : return self . search_edges_with_b...
Return a query over the edges in the database .
29,428
def query_citations ( self , type : Optional [ str ] = None , reference : Optional [ str ] = None , name : Optional [ str ] = None , author : Union [ None , str , List [ str ] ] = None , date : Union [ None , str , datetime . date ] = None , evidence_text : Optional [ str ] = None , ) -> List [ Citation ] : query = sel...
Query citations in the database .
29,429
def query_edges_by_pubmed_identifiers ( self , pubmed_identifiers : List [ str ] ) -> List [ Edge ] : fi = and_ ( Citation . type == CITATION_TYPE_PUBMED , Citation . reference . in_ ( pubmed_identifiers ) ) return self . session . query ( Edge ) . join ( Evidence ) . join ( Citation ) . filter ( fi ) . all ( )
Get all edges annotated to the documents identified by the given PubMed identifiers .
29,430
def _edge_both_nodes ( nodes : List [ Node ] ) : node_ids = [ node . id for node in nodes ] return and_ ( Edge . source_id . in_ ( node_ids ) , Edge . target_id . in_ ( node_ids ) , )
Get edges where both the source and target are in the list of nodes .
29,431
def _edge_one_node ( nodes : List [ Node ] ) : node_ids = [ node . id for node in nodes ] return or_ ( Edge . source_id . in_ ( node_ids ) , Edge . target_id . in_ ( node_ids ) , )
Get edges where either the source or target are in the list of nodes .
29,432
def query_neighbors ( self , nodes : List [ Node ] ) -> List [ Edge ] : return self . session . query ( Edge ) . filter ( self . _edge_one_node ( nodes ) ) . all ( )
Get all edges incident to any of the given nodes .
29,433
def get_subgraphs_by_annotation ( graph , annotation , sentinel = None ) : if sentinel is not None : subgraphs = _get_subgraphs_by_annotation_keep_undefined ( graph , annotation , sentinel ) else : subgraphs = _get_subgraphs_by_annotation_disregard_undefined ( graph , annotation ) cleanup ( graph , subgraphs ) return s...
Stratify the given graph into sub - graphs based on the values for edges annotations .
29,434
def extract_shared_optional ( bel_resource , definition_header : str = 'Namespace' ) : shared_mapping = { 'description' : ( definition_header , 'DescriptionString' ) , 'version' : ( definition_header , 'VersionString' ) , 'author' : ( 'Author' , 'NameString' ) , 'license' : ( 'Author' , 'CopyrightString' ) , 'contact' ...
Get the optional annotations shared by BEL namespace and annotation resource documents .
29,435
def update_insert_values ( bel_resource : Mapping , mapping : Mapping [ str , Tuple [ str , str ] ] , values : Dict [ str , str ] ) -> None : for database_column , ( section , key ) in mapping . items ( ) : if section in bel_resource and key in bel_resource [ section ] : values [ database_column ] = bel_resource [ sect...
Update the value dictionary with a BEL resource dictionary .
29,436
def int_or_str ( v : Optional [ str ] ) -> Union [ None , int , str ] : if v is None : return try : return int ( v ) except ValueError : return v
Safe converts an string represent an integer to an integer or passes through None .
29,437
def from_web ( network_id : int , host : Optional [ str ] = None ) -> BELGraph : if host is None : host = _get_host ( ) url = host + GET_ENDPOINT . format ( network_id ) res = requests . get ( url ) graph_json = res . json ( ) graph = from_json ( graph_json ) return graph
Retrieve a public network from BEL Commons .
29,438
def get_fusion_language ( identifier : ParserElement , permissive : bool = True ) -> ParserElement : range_coordinate = Suppress ( '"' ) + range_coordinate_unquoted + Suppress ( '"' ) if permissive : range_coordinate = range_coordinate | range_coordinate_unquoted return fusion_tags + nest ( Group ( identifier ) ( PARTN...
Build a fusion parser .
29,439
def get_legacy_fusion_langauge ( identifier : ParserElement , reference : str ) -> ParserElement : break_start = ( ppc . integer | '?' ) . setParseAction ( _fusion_break_handler_wrapper ( reference , start = True ) ) break_end = ( ppc . integer | '?' ) . setParseAction ( _fusion_break_handler_wrapper ( reference , star...
Build a legacy fusion parser .
29,440
def _fusion_legacy_handler ( _ , __ , tokens ) : if RANGE_5P not in tokens : tokens [ RANGE_5P ] = { FUSION_MISSING : '?' } if RANGE_3P not in tokens : tokens [ RANGE_3P ] = { FUSION_MISSING : '?' } return tokens
Handle a legacy fusion .
29,441
def to_csv ( graph : BELGraph , file : Optional [ TextIO ] = None , sep : Optional [ str ] = None ) -> None : if sep is None : sep = '\t' for u , v , data in graph . edges ( data = True ) : print ( graph . edge_to_bel ( u , v , edge_data = data , sep = sep ) , json . dumps ( data ) , sep = sep , file = file , )
Write the graph as a tab - separated edge list .
29,442
def to_csv_path ( graph : BELGraph , path : str , sep : Optional [ str ] = None ) -> None : with open ( path , 'w' ) as file : to_csv ( graph , file , sep = sep )
Write the graph as a tab - separated edge list to a file at the given path .
29,443
def to_sif ( graph : BELGraph , file : Optional [ TextIO ] = None , sep : Optional [ str ] = None ) -> None : if sep is None : sep = '\t' for u , v , data in graph . edges ( data = True ) : print ( graph . edge_to_bel ( u , v , edge_data = data , sep = sep ) , file = file , )
Write the graph as a tab - separated SIF file .
29,444
def to_sif_path ( graph : BELGraph , path : str , sep : Optional [ str ] = None ) -> None : with open ( path , 'w' ) as file : to_sif ( graph , file , sep = sep )
Write the graph as a tab - separated SIF file . to a file at the given path .
29,445
def append_sample ( self , ** kwargs ) -> 'Seeding' : data = { 'seed' : random . randint ( 0 , 1000000 ) } data . update ( kwargs ) return self . _append_seed ( SEED_TYPE_SAMPLE , data )
Add seed induction methods .
29,446
def run ( self , graph ) : if not self : log . debug ( 'no seeding, returning graph: %s' , graph ) return graph subgraphs = [ ] for seed in self : seed_method , seed_data = seed [ SEED_METHOD ] , seed [ SEED_DATA ] log . debug ( 'seeding with %s: %s' , seed_method , seed_data ) subgraph = get_subgraph ( graph , seed_me...
Seed the graph or return none if not possible .
29,447
def dump ( self , file , sort_keys : bool = True , ** kwargs ) -> None : json . dump ( self . to_json ( ) , file , sort_keys = sort_keys , ** kwargs )
Dump this seeding container to a file as JSON .
29,448
def dumps ( self , sort_keys : bool = True , ** kwargs ) -> str : return json . dumps ( self . to_json ( ) , sort_keys = sort_keys , ** kwargs )
Dump this query to a string as JSON .
29,449
def _single_function_inclusion_filter_builder ( func : str ) -> NodePredicate : def function_inclusion_filter ( _ : BELGraph , node : BaseEntity ) -> bool : return node . function == func return function_inclusion_filter
Build a function inclusion filter for a single function .
29,450
def _collection_function_inclusion_builder ( funcs : Iterable [ str ] ) -> NodePredicate : funcs = set ( funcs ) if not funcs : raise ValueError ( 'can not build function inclusion filter with empty list of functions' ) def functions_inclusion_filter ( _ : BELGraph , node : BaseEntity ) -> bool : return node . function...
Build a function inclusion filter for a collection of functions .
29,451
def data_missing_key_builder ( key : str ) -> NodePredicate : def data_does_not_contain_key ( graph : BELGraph , node : BaseEntity ) -> bool : return key not in graph . nodes [ node ] return data_does_not_contain_key
Build a filter that passes only on nodes that don t have the given key in their data dictionary .
29,452
def build_node_data_search ( key : str , data_predicate : Callable [ [ Any ] , bool ] ) -> NodePredicate : def node_data_filter ( _ : BELGraph , node : BaseEntity ) -> bool : value = node . get ( key ) return value is not None and data_predicate ( value ) return node_data_filter
Build a filter for nodes whose associated data with the given key passes the given predicate .
29,453
def build_node_graph_data_search ( key : str , data_predicate : Callable [ [ Any ] , bool ] ) : def node_data_filter ( graph : BELGraph , node : BaseEntity ) -> bool : value = graph . nodes [ node ] . get ( key ) return value is not None and data_predicate ( value ) return node_data_filter
Build a function for testing data associated with the node in the graph .
29,454
def namespace_inclusion_builder ( namespace : Strings ) -> NodePredicate : if isinstance ( namespace , str ) : def namespace_filter ( _ : BELGraph , node : BaseEntity ) -> bool : return NAMESPACE in node and node [ NAMESPACE ] == namespace elif isinstance ( namespace , Iterable ) : namespaces = set ( namespace ) def na...
Build a predicate for namespace inclusion .
29,455
def has_namespace ( self , namespace : str ) -> bool : return self . has_enumerated_namespace ( namespace ) or self . has_regex_namespace ( namespace )
Check that the namespace has either been defined by an enumeration or a regular expression .
29,456
def has_enumerated_namespace_name ( self , namespace : str , name : str ) -> bool : return self . has_enumerated_namespace ( namespace ) and name in self . namespace_to_terms [ namespace ]
Check that the namespace is defined by an enumeration and that the name is a member .
29,457
def has_regex_namespace_name ( self , namespace : str , name : str ) -> bool : return self . has_regex_namespace ( namespace ) and self . namespace_to_pattern [ namespace ] . match ( name )
Check that the namespace is defined as a regular expression and the name matches it .
29,458
def has_namespace_name ( self , line : str , position : int , namespace : str , name : str ) -> bool : self . raise_for_missing_namespace ( line , position , namespace , name ) return self . has_enumerated_namespace_name ( namespace , name ) or self . has_regex_namespace_name ( namespace , name )
Check that the namespace is defined and has the given name .
29,459
def raise_for_missing_namespace ( self , line : str , position : int , namespace : str , name : str ) -> None : if not self . has_namespace ( namespace ) : raise UndefinedNamespaceWarning ( self . get_line_number ( ) , line , position , namespace , name )
Raise an exception if the namespace is not defined .
29,460
def raise_for_missing_name ( self , line : str , position : int , namespace : str , name : str ) -> None : self . raise_for_missing_namespace ( line , position , namespace , name ) if self . has_enumerated_namespace ( namespace ) and not self . has_enumerated_namespace_name ( namespace , name ) : raise MissingNamespace...
Raise an exception if the namespace is not defined or if it does not validate the given name .
29,461
def raise_for_missing_default ( self , line : str , position : int , name : str ) -> None : if not self . default_namespace : raise ValueError ( 'Default namespace is not set' ) if name not in self . default_namespace : raise MissingDefaultNameWarning ( self . get_line_number ( ) , line , position , name )
Raise an exeception if the name does not belong to the default namespace .
29,462
def handle_identifier_qualified ( self , line : str , position : int , tokens : ParseResults ) -> ParseResults : namespace , name = tokens [ NAMESPACE ] , tokens [ NAME ] self . raise_for_missing_namespace ( line , position , namespace , name ) self . raise_for_missing_name ( line , position , namespace , name ) return...
Handle parsing a qualified identifier .
29,463
def handle_namespace_default ( self , line : str , position : int , tokens : ParseResults ) -> ParseResults : name = tokens [ NAME ] self . raise_for_missing_default ( line , position , name ) return tokens
Handle parsing an identifier for the default namespace .
29,464
def handle_namespace_lenient ( line : str , position : int , tokens : ParseResults ) -> ParseResults : tokens [ NAMESPACE ] = DIRTY log . debug ( 'Naked namespace: [%d] %s' , position , line ) return tokens
Handle parsing an identifier for name missing a namespac ethat are outside the default namespace .
29,465
def handle_namespace_invalid ( self , line : str , position : int , tokens : ParseResults ) -> None : name = tokens [ NAME ] raise NakedNameWarning ( self . get_line_number ( ) , line , position , name )
Raise an exception when parsing a name missing a namespace .
29,466
def hbp_namespace ( name : str , sha : Optional [ str ] = None ) -> str : return HBP_NAMESPACE_URL . format ( sha = sha or LAST_HASH , keyword = name )
Format a namespace URL .
29,467
def edge_predicate ( func : DictEdgePredicate ) -> EdgePredicate : @ wraps ( func ) def _wrapped ( * args ) : x = args [ 0 ] if isinstance ( x , BELGraph ) : u , v , k = args [ 1 : 4 ] return func ( x [ u ] [ v ] [ k ] ) return func ( * args ) return _wrapped
Decorate an edge predicate function that only takes a dictionary as its singular argument .
29,468
def has_pubmed ( edge_data : EdgeData ) -> bool : return CITATION in edge_data and CITATION_TYPE_PUBMED == edge_data [ CITATION ] [ CITATION_TYPE ]
Check if the edge has a PubMed citation .
29,469
def has_authors ( edge_data : EdgeData ) -> bool : return CITATION in edge_data and CITATION_AUTHORS in edge_data [ CITATION ] and edge_data [ CITATION ] [ CITATION_AUTHORS ]
Check if the edge contains author information for its citation .
29,470
def _has_modifier ( edge_data : EdgeData , modifier : str ) -> bool : return part_has_modifier ( edge_data , SUBJECT , modifier ) or part_has_modifier ( edge_data , OBJECT , modifier )
Check if the edge has the given modifier .
29,471
def edge_has_annotation ( edge_data : EdgeData , key : str ) -> Optional [ Any ] : annotations = edge_data . get ( ANNOTATIONS ) if annotations is None : return None return annotations . get ( key )
Check if an edge has the given annotation .
29,472
def get_gene_substitution_language ( ) -> ParserElement : parser_element = gsub_tag + nest ( dna_nucleotide ( GSUB_REFERENCE ) , ppc . integer ( GSUB_POSITION ) , dna_nucleotide ( GSUB_VARIANT ) , ) parser_element . setParseAction ( _handle_gsub ) return parser_element
Build a gene substitution parser .
29,473
def append_seeding_induction ( self , nodes : Union [ BaseEntity , List [ BaseEntity ] , List [ Dict ] ] ) -> Seeding : return self . seeding . append_induction ( nodes )
Add a seed induction method .
29,474
def append_seeding_neighbors ( self , nodes : Union [ BaseEntity , List [ BaseEntity ] , List [ Dict ] ] ) -> Seeding : return self . seeding . append_neighbors ( nodes )
Add a seed by neighbors .
29,475
def run ( self , manager ) : universe = self . _get_universe ( manager ) graph = self . seeding . run ( universe ) return self . pipeline . run ( graph , universe = universe )
Run this query and returns the resulting BEL graph .
29,476
def to_json ( self ) -> Dict : rv = { 'network_ids' : self . network_ids , } if self . seeding : rv [ 'seeding' ] = self . seeding . to_json ( ) if self . pipeline : rv [ 'pipeline' ] = self . pipeline . to_json ( ) return rv
Return this query as a JSON object .
29,477
def from_json ( data : Mapping ) -> 'Query' : network_ids = data . get ( 'network_ids' ) if network_ids is None : raise QueryMissingNetworksError ( 'query JSON did not have key "network_ids"' ) seeding_data = data . get ( 'seeding' ) seeding = ( Seeding . from_json ( seeding_data ) if seeding_data is not None else None...
Load a query from a JSON dictionary .
29,478
def handle_molecular_activity_default ( _ : str , __ : int , tokens : ParseResults ) -> ParseResults : upgraded = language . activity_labels [ tokens [ 0 ] ] tokens [ NAMESPACE ] = BEL_DEFAULT_NAMESPACE tokens [ NAME ] = upgraded return tokens
Handle a BEL 2 . 0 style molecular activity with BEL default names .
29,479
def handle_activity_legacy ( _ : str , __ : int , tokens : ParseResults ) -> ParseResults : legacy_cls = language . activity_labels [ tokens [ MODIFIER ] ] tokens [ MODIFIER ] = ACTIVITY tokens [ EFFECT ] = { NAME : legacy_cls , NAMESPACE : BEL_DEFAULT_NAMESPACE } log . log ( 5 , 'upgraded legacy activity to %s' , lega...
Handle BEL 1 . 0 activities .
29,480
def handle_legacy_tloc ( line : str , position : int , tokens : ParseResults ) -> ParseResults : log . log ( 5 , 'legacy translocation statement: %s [%d]' , line , position ) return tokens
Handle translocations that lack the fromLoc and toLoc entries .
29,481
def handle_nested_relation ( self , line : str , position : int , tokens : ParseResults ) : if not self . allow_nested : raise NestedRelationWarning ( self . get_line_number ( ) , line , position ) self . _handle_relation_harness ( line , position , { SUBJECT : tokens [ SUBJECT ] , RELATION : tokens [ RELATION ] , OBJE...
Handle nested statements .
29,482
def check_function_semantics ( self , line : str , position : int , tokens : ParseResults ) -> ParseResults : if not self . _namespace_dict or NAMESPACE not in tokens : return tokens namespace , name = tokens [ NAMESPACE ] , tokens [ NAME ] if namespace in self . identifier_parser . namespace_to_pattern : return tokens...
Raise an exception if the function used on the tokens is wrong .
29,483
def _add_qualified_edge_helper ( self , u , v , relation , annotations , subject_modifier , object_modifier ) -> str : return self . graph . add_qualified_edge ( u , v , relation = relation , evidence = self . control_parser . evidence , citation = self . control_parser . citation . copy ( ) , annotations = annotations...
Add a qualified edge from the internal aspects of the parser .
29,484
def _add_qualified_edge ( self , u , v , relation , annotations , subject_modifier , object_modifier ) -> str : sha512 = self . _add_qualified_edge_helper ( u , v , relation = relation , annotations = annotations , subject_modifier = subject_modifier , object_modifier = object_modifier , ) if relation in TWO_WAY_RELATI...
Add an edge then adds the opposite direction edge if it should .
29,485
def _handle_relation ( self , tokens : ParseResults ) -> str : subject_node_dsl = self . ensure_node ( tokens [ SUBJECT ] ) object_node_dsl = self . ensure_node ( tokens [ OBJECT ] ) subject_modifier = modifier_po_to_dict ( tokens [ SUBJECT ] ) object_modifier = modifier_po_to_dict ( tokens [ OBJECT ] ) annotations = {...
Handle a relation .
29,486
def _handle_relation_harness ( self , line : str , position : int , tokens : Union [ ParseResults , Dict ] ) -> ParseResults : if not self . control_parser . citation : raise MissingCitationException ( self . get_line_number ( ) , line , position ) if not self . control_parser . evidence : raise MissingSupportWarning (...
Handle BEL relations based on the policy specified on instantiation .
29,487
def handle_unqualified_relation ( self , _ , __ , tokens : ParseResults ) -> ParseResults : subject_node_dsl = self . ensure_node ( tokens [ SUBJECT ] ) object_node_dsl = self . ensure_node ( tokens [ OBJECT ] ) relation = tokens [ RELATION ] self . graph . add_unqualified_edge ( subject_node_dsl , object_node_dsl , re...
Handle unqualified relations .
29,488
def ensure_node ( self , tokens : ParseResults ) -> BaseEntity : if MODIFIER in tokens : return self . ensure_node ( tokens [ TARGET ] ) node = parse_result_to_dsl ( tokens ) self . graph . add_node_from_data ( node ) return node
Turn parsed tokens into canonical node name and makes sure its in the graph .
29,489
def handle_translocation_illegal ( self , line : str , position : int , tokens : ParseResults ) -> None : raise MalformedTranslocationWarning ( self . get_line_number ( ) , line , position , tokens )
Handle a malformed translocation .
29,490
def get_dsl_by_hash ( self , node_hash : str ) -> Optional [ BaseEntity ] : node = self . get_node_by_hash ( node_hash ) if node is not None : return node . as_bel ( )
Look up a node by the hash and returns the corresponding PyBEL node tuple .
29,491
def get_node_by_hash ( self , node_hash : str ) -> Optional [ Node ] : return self . session . query ( Node ) . filter ( Node . sha512 == node_hash ) . one_or_none ( )
Look up a node by its hash .
29,492
def get_nodes_by_hashes ( self , node_hashes : List [ str ] ) -> List [ Node ] : return self . session . query ( Node ) . filter ( Node . sha512 . in_ ( node_hashes ) ) . all ( )
Look up several nodes by their hashes .
29,493
def get_edge_by_hash ( self , edge_hash : str ) -> Optional [ Edge ] : return self . session . query ( Edge ) . filter ( Edge . sha512 == edge_hash ) . one_or_none ( )
Look up an edge by the hash of a PyBEL edge data dictionary .
29,494
def get_edges_by_hashes ( self , edge_hashes : List [ str ] ) -> List [ Edge ] : return self . session . query ( Edge ) . filter ( Edge . sha512 . in_ ( edge_hashes ) ) . all ( )
Look up several edges by hashes of their PyBEL edge data dictionaries .
29,495
def get_citation_by_pmid ( self , pubmed_identifier : str ) -> Optional [ Citation ] : return self . get_citation_by_reference ( reference = pubmed_identifier , type = CITATION_TYPE_PUBMED )
Get a citation object by its PubMed identifier .
29,496
def get_citation_by_reference ( self , type : str , reference : str ) -> Optional [ Citation ] : citation_hash = hash_citation ( type = type , reference = reference ) return self . get_citation_by_hash ( citation_hash )
Get a citation object by its type and reference .
29,497
def get_citation_by_hash ( self , citation_hash : str ) -> Optional [ Citation ] : return self . session . query ( Citation ) . filter ( Citation . sha512 == citation_hash ) . one_or_none ( )
Get a citation object by its hash .
29,498
def get_author_by_name ( self , name : str ) -> Optional [ Author ] : return self . session . query ( Author ) . filter ( Author . has_name ( name ) ) . one_or_none ( )
Get an author by name if it exists in the database .
29,499
def get_evidence_by_hash ( self , evidence_hash : str ) -> Optional [ Evidence ] : return self . session . query ( Evidence ) . filter ( Evidence . sha512 == evidence_hash ) . one_or_none ( )
Look up an evidence by its hash .