idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
29,500 | def invert_node_predicate ( node_predicate : NodePredicate ) -> NodePredicate : def inverse_predicate ( graph : BELGraph , node : BaseEntity ) -> bool : return not node_predicate ( graph , node ) return inverse_predicate | Build a node predicate that is the inverse of the given node predicate . |
29,501 | def concatenate_node_predicates ( node_predicates : NodePredicates ) -> NodePredicate : if not isinstance ( node_predicates , Iterable ) : return node_predicates node_predicates = tuple ( node_predicates ) if 1 == len ( node_predicates ) : return node_predicates [ 0 ] def concatenated_node_predicate ( graph : BELGraph ... | Concatenate multiple node predicates to a new predicate that requires all predicates to be met . |
29,502 | def filter_nodes ( graph : BELGraph , node_predicates : NodePredicates ) -> Iterable [ BaseEntity ] : concatenated_predicate = concatenate_node_predicates ( node_predicates = node_predicates ) for node in graph : if concatenated_predicate ( graph , node ) : yield node | Apply a set of predicates to the nodes iterator of a BEL graph . |
29,503 | def get_nodes ( graph : BELGraph , node_predicates : NodePredicates ) -> Set [ BaseEntity ] : return set ( filter_nodes ( graph , node_predicates = node_predicates ) ) | Get the set of all nodes that pass the predicates . |
29,504 | def count_passed_node_filter ( graph : BELGraph , node_predicates : NodePredicates ) -> int : return sum ( 1 for _ in filter_nodes ( graph , node_predicates = node_predicates ) ) | Count how many nodes pass a given set of node predicates . |
29,505 | def get_gene_leaves ( graph ) -> Iterable [ BaseEntity ] : for node in get_nodes_by_function ( graph , GENE ) : if graph . in_degree ( node ) != 0 : continue if graph . out_degree ( node ) != 1 : continue _ , _ , d = list ( graph . out_edges ( node , data = True ) ) [ 0 ] if d [ RELATION ] == TRANSCRIBED_TO : yield nod... | Iterate over all genes who have only one connection that s a transcription to its RNA . |
29,506 | def get_rna_leaves ( graph ) -> Iterable [ BaseEntity ] : for node in get_nodes_by_function ( graph , RNA ) : if graph . in_degree ( node ) != 0 : continue if graph . out_degree ( node ) != 1 : continue _ , _ , d = list ( graph . out_edges ( node , data = True ) ) [ 0 ] if d [ RELATION ] == TRANSLATED_TO : yield node | Iterate over all RNAs who have only one connection that s a translation to its protein . |
29,507 | def _entity_list_as_bel ( entities : Iterable [ BaseEntity ] ) -> str : return ', ' . join ( e . as_bel ( ) for e in entities ) | Stringify a list of BEL entities . |
29,508 | def get_parent ( self ) -> Optional [ 'CentralDogma' ] : if VARIANTS not in self : return return self . __class__ ( namespace = self . namespace , name = self . name , identifier = self . identifier ) | Get the parent or none if it s already a reference node . |
29,509 | def with_variants ( self , variants : Union [ 'Variant' , List [ 'Variant' ] ] ) -> 'CentralDogma' : return self . __class__ ( namespace = self . namespace , name = self . name , identifier = self . identifier , variants = variants , ) | Create a new entity with the given variants . |
29,510 | def as_bel ( self ) -> str : return 'pmod({}{})' . format ( str ( self [ IDENTIFIER ] ) , '' . join ( ', {}' . format ( self [ x ] ) for x in PMOD_ORDER [ 2 : ] if x in self ) ) | Return this protein modification variant as a BEL string . |
29,511 | def range ( self ) -> str : if FRAGMENT_MISSING in self : return '?' return '{}_{}' . format ( self [ FRAGMENT_START ] , self [ FRAGMENT_STOP ] ) | Get the range of this fragment . |
29,512 | def as_bel ( self ) -> str : res = '"{}"' . format ( self . range ) if FRAGMENT_DESCRIPTION in self : res += ', "{}"' . format ( self [ FRAGMENT_DESCRIPTION ] ) return 'frag({})' . format ( res ) | Return this fragment variant as a BEL string . |
29,513 | def get_gene ( self ) -> Gene : if self . variants : raise InferCentralDogmaException ( 'can not get gene for variant' ) return Gene ( namespace = self . namespace , name = self . name , identifier = self . identifier ) | Get the corresponding gene or raise an exception if it s not the reference node . |
29,514 | def get_rna ( self ) -> Rna : if self . variants : raise InferCentralDogmaException ( 'can not get rna for variant' ) return Rna ( namespace = self . namespace , name = self . name , identifier = self . identifier ) | Get the corresponding RNA or raise an exception if it s not the reference node . |
29,515 | def as_bel ( self ) -> str : return '{reference}.{start}_{stop}' . format ( reference = self [ FUSION_REFERENCE ] , start = self [ FUSION_START ] , stop = self [ FUSION_STOP ] , ) | Return this fusion range as a BEL string . |
29,516 | def as_bel ( self ) -> str : return '{}(fus({}:{}, "{}", {}:{}, "{}"))' . format ( self . _func , self . partner_5p . namespace , self . partner_5p . _priority_id , self . range_5p . as_bel ( ) , self . partner_3p . namespace , self . partner_3p . _priority_id , self . range_3p . as_bel ( ) , ) | Return this fusion as a BEL string . |
29,517 | def iter_annotation_values ( graph , annotation : str ) -> Iterable [ str ] : return ( value for _ , _ , data in graph . edges ( data = True ) if edge_has_annotation ( data , annotation ) for value in data [ ANNOTATIONS ] [ annotation ] ) | Iterate over all of the values for an annotation used in the graph . |
29,518 | def _group_dict_set ( iterator ) : d = defaultdict ( set ) for key , value in iterator : d [ key ] . add ( value ) return dict ( d ) | Make a dict that accumulates the values for each key in an iterator of doubles . |
29,519 | def get_annotation_values ( graph , annotation : str ) -> Set [ str ] : return set ( iter_annotation_values ( graph , annotation ) ) | Get all values for the given annotation . |
29,520 | def count_relations ( graph ) -> Counter : return Counter ( data [ RELATION ] for _ , _ , data in graph . edges ( data = True ) ) | Return a histogram over all relationships in a graph . |
29,521 | def _annotation_iter_helper ( graph ) -> Iterable [ str ] : return ( key for _ , _ , data in graph . edges ( data = True ) if ANNOTATIONS in data for key in data [ ANNOTATIONS ] ) | Iterate over the annotation keys . |
29,522 | def get_unused_list_annotation_values ( graph ) -> Mapping [ str , Set [ str ] ] : result = { } for annotation , values in graph . annotation_list . items ( ) : used_values = get_annotation_values ( graph , annotation ) if len ( used_values ) == len ( values ) : continue result [ annotation ] = set ( values ) - used_va... | Get all of the unused values for list annotations . |
29,523 | def from_lines ( lines : Iterable [ str ] , ** kwargs ) -> BELGraph : graph = BELGraph ( ) parse_lines ( graph = graph , lines = lines , ** kwargs ) return graph | Load a BEL graph from an iterable over the lines of a BEL script . |
29,524 | def from_url ( url : str , ** kwargs ) -> BELGraph : log . info ( 'Loading from url: %s' , url ) res = download ( url ) lines = ( line . decode ( 'utf-8' ) for line in res . iter_lines ( ) ) graph = BELGraph ( path = url ) parse_lines ( graph = graph , lines = lines , ** kwargs ) return graph | Load a BEL graph from a URL resource . |
29,525 | def expand_node_predecessors ( universe , graph , node : BaseEntity ) -> None : skip_successors = set ( ) for successor in universe . successors ( node ) : if successor in graph : skip_successors . add ( successor ) continue graph . add_node ( successor , ** universe . nodes [ successor ] ) graph . add_edges_from ( ( s... | Expand around the predecessors of the given node in the result graph . |
29,526 | def expand_node_successors ( universe , graph , node : BaseEntity ) -> None : skip_predecessors = set ( ) for predecessor in universe . predecessors ( node ) : if predecessor in graph : skip_predecessors . add ( predecessor ) continue graph . add_node ( predecessor , ** universe . nodes [ predecessor ] ) graph . add_ed... | Expand around the successors of the given node in the result graph . |
29,527 | def expand_all_node_neighborhoods ( universe , graph , filter_pathologies : bool = False ) -> None : for node in list ( graph ) : if filter_pathologies and is_pathology ( node ) : continue expand_node_neighborhood ( universe , graph , node ) | Expand the neighborhoods of all nodes in the given graph . |
29,528 | def parse_lines ( graph : BELGraph , lines : Iterable [ str ] , manager : Optional [ Manager ] = None , allow_nested : bool = False , citation_clearing : bool = True , use_tqdm : bool = False , tqdm_kwargs : Optional [ Mapping [ str , Any ] ] = None , no_identifier_validation : bool = False , disallow_unqualified_trans... | Parse an iterable of lines into this graph . |
29,529 | def parse_document ( graph : BELGraph , enumerated_lines : Iterable [ Tuple [ int , str ] ] , metadata_parser : MetadataParser , ) -> None : parse_document_start_time = time . time ( ) for line_number , line in enumerated_lines : try : metadata_parser . parseString ( line , line_number = line_number ) except VersionFor... | Parse the lines in the document section of a BEL script . |
29,530 | def parse_definitions ( graph : BELGraph , enumerated_lines : Iterable [ Tuple [ int , str ] ] , metadata_parser : MetadataParser , allow_failures : bool = False , use_tqdm : bool = False , tqdm_kwargs : Optional [ Mapping [ str , Any ] ] = None , ) -> None : parse_definitions_start_time = time . time ( ) if use_tqdm :... | Parse the lines in the definitions section of a BEL script . |
29,531 | def parse_statements ( graph : BELGraph , enumerated_lines : Iterable [ Tuple [ int , str ] ] , bel_parser : BELParser , use_tqdm : bool = False , tqdm_kwargs : Optional [ Mapping [ str , Any ] ] = None , ) -> None : parse_statements_start_time = time . time ( ) if use_tqdm : _tqdm_kwargs = dict ( desc = 'Statements' )... | Parse a list of statements from a BEL Script . |
29,532 | def to_database ( graph , manager : Optional [ Manager ] = None , store_parts : bool = True , use_tqdm : bool = False ) : if manager is None : manager = Manager ( ) try : return manager . insert_graph ( graph , store_parts = store_parts , use_tqdm = use_tqdm ) except ( IntegrityError , OperationalError ) : manager . se... | Store a graph in a database . |
29,533 | def from_database ( name : str , version : Optional [ str ] = None , manager : Optional [ Manager ] = None ) : if manager is None : manager = Manager ( ) if version is None : return manager . get_graph_by_most_recent ( name ) return manager . get_graph_by_name_version ( name , version ) | Load a BEL graph from a database . |
29,534 | def _node_has_variant ( node : BaseEntity , variant : str ) -> bool : return VARIANTS in node and any ( variant_dict [ KIND ] == variant for variant_dict in node [ VARIANTS ] ) | Return true if the node has at least one of the given variant . |
29,535 | def _node_has_modifier ( graph : BELGraph , node : BaseEntity , modifier : str ) -> bool : modifier_in_subject = any ( part_has_modifier ( d , SUBJECT , modifier ) for _ , _ , d in graph . out_edges ( node , data = True ) ) modifier_in_object = any ( part_has_modifier ( d , OBJECT , modifier ) for _ , _ , d in graph . ... | Return true if over any of a nodes edges it has a given modifier . |
29,536 | def has_activity ( graph : BELGraph , node : BaseEntity ) -> bool : return _node_has_modifier ( graph , node , ACTIVITY ) | Return true if over any of the node s edges it has a molecular activity . |
29,537 | def is_degraded ( graph : BELGraph , node : BaseEntity ) -> bool : return _node_has_modifier ( graph , node , DEGRADATION ) | Return true if over any of the node s edges it is degraded . |
29,538 | def is_translocated ( graph : BELGraph , node : BaseEntity ) -> bool : return _node_has_modifier ( graph , node , TRANSLOCATION ) | Return true if over any of the node s edges it is translocated . |
29,539 | def has_causal_in_edges ( graph : BELGraph , node : BaseEntity ) -> bool : return any ( data [ RELATION ] in CAUSAL_RELATIONS for _ , _ , data in graph . in_edges ( node , data = True ) ) | Return true if the node contains any in_edges that are causal . |
29,540 | def has_causal_out_edges ( graph : BELGraph , node : BaseEntity ) -> bool : return any ( data [ RELATION ] in CAUSAL_RELATIONS for _ , _ , data in graph . out_edges ( node , data = True ) ) | Return true if the node contains any out_edges that are causal . |
29,541 | def node_exclusion_predicate_builder ( nodes : Iterable [ BaseEntity ] ) -> NodePredicate : nodes = set ( nodes ) @ node_predicate def node_exclusion_predicate ( node : BaseEntity ) -> bool : return node not in nodes return node_exclusion_predicate | Build a node predicate that returns false for the given nodes . |
29,542 | def node_inclusion_predicate_builder ( nodes : Iterable [ BaseEntity ] ) -> NodePredicate : nodes = set ( nodes ) @ node_predicate def node_inclusion_predicate ( node : BaseEntity ) -> bool : return node in nodes return node_inclusion_predicate | Build a function that returns true for the given nodes . |
29,543 | def is_causal_source ( graph : BELGraph , node : BaseEntity ) -> bool : return not has_causal_in_edges ( graph , node ) and has_causal_out_edges ( graph , node ) | Return true of the node is a causal source . |
29,544 | def is_causal_sink ( graph : BELGraph , node : BaseEntity ) -> bool : return has_causal_in_edges ( graph , node ) and not has_causal_out_edges ( graph , node ) | Return true if the node is a causal sink . |
29,545 | def is_causal_central ( graph : BELGraph , node : BaseEntity ) -> bool : return has_causal_in_edges ( graph , node ) and has_causal_out_edges ( graph , node ) | Return true if the node is neither a causal sink nor a causal source . |
29,546 | def is_isolated_list_abundance ( graph : BELGraph , node : BaseEntity , cls : Type [ ListAbundance ] = ListAbundance ) -> bool : return ( isinstance ( node , cls ) and 0 == graph . in_degree ( node ) and all ( data [ RELATION ] == HAS_COMPONENT for _ , __ , data in graph . out_edges ( node , data = True ) ) ) | Return if the node is a list abundance but has no qualified edges . |
29,547 | def collapse_pair ( graph , survivor : BaseEntity , victim : BaseEntity ) -> None : graph . add_edges_from ( ( survivor , successor , key , data ) for _ , successor , key , data in graph . out_edges ( victim , keys = True , data = True ) if successor != survivor ) graph . add_edges_from ( ( predecessor , survivor , key... | Rewire all edges from the synonymous node to the survivor node then deletes the synonymous node . |
29,548 | def collapse_nodes ( graph , survivor_mapping : Mapping [ BaseEntity , Set [ BaseEntity ] ] ) -> None : inconsistencies = surviors_are_inconsistent ( survivor_mapping ) if inconsistencies : raise ValueError ( 'survivor mapping is inconsistent: {}' . format ( inconsistencies ) ) for survivor , victims in survivor_mappin... | Collapse all nodes in values to the key nodes in place . |
29,549 | def surviors_are_inconsistent ( survivor_mapping : Mapping [ BaseEntity , Set [ BaseEntity ] ] ) -> Set [ BaseEntity ] : victim_mapping = set ( ) for victim in itt . chain . from_iterable ( survivor_mapping . values ( ) ) : if victim in survivor_mapping : victim_mapping . add ( victim ) return victim_mapping | Check that there s no transitive shit going on . |
29,550 | def collapse_all_variants ( graph ) -> None : has_variant_predicate = build_relation_predicate ( HAS_VARIANT ) edges = list ( filter_edges ( graph , has_variant_predicate ) ) for u , v , _ in edges : collapse_pair ( graph , survivor = u , victim = v ) _remove_self_edges ( graph ) | Collapse all genes RNAs miRNAs and proteins variants to their parents . |
29,551 | def update_metadata ( source , target ) -> None : target . namespace_url . update ( source . namespace_url ) target . namespace_pattern . update ( source . namespace_pattern ) target . annotation_url . update ( source . annotation_url ) target . annotation_pattern . update ( source . annotation_pattern ) for keyword , ... | Update the namespace and annotation metadata in the target graph . |
29,552 | def update_node_helper ( source : nx . Graph , target : nx . Graph ) -> None : for node in target : if node in source : target . nodes [ node ] . update ( source . nodes [ node ] ) | Update the nodes data dictionaries in the target graph from the source graph . |
29,553 | def get_syntax_errors ( graph : BELGraph ) -> List [ WarningTuple ] : return [ ( path , exc , an ) for path , exc , an in graph . warnings if isinstance ( exc , BELSyntaxError ) ] | List the syntax errors encountered during compilation of a BEL script . |
29,554 | def count_error_types ( graph : BELGraph ) -> Counter : return Counter ( exc . __class__ . __name__ for _ , exc , _ in graph . warnings ) | Count the occurrence of each type of error in a graph . |
29,555 | def _naked_names_iter ( graph : BELGraph ) -> Iterable [ str ] : for _ , exc , _ in graph . warnings : if isinstance ( exc , NakedNameWarning ) : yield exc . name | Iterate over naked name warnings from a graph . |
29,556 | def calculate_incorrect_name_dict ( graph : BELGraph ) -> Mapping [ str , List [ str ] ] : missing = defaultdict ( list ) for namespace , name in _iterate_namespace_name ( graph ) : missing [ namespace ] . append ( name ) return dict ( missing ) | Get missing names grouped by namespace . |
29,557 | def calculate_error_by_annotation ( graph : BELGraph , annotation : str ) -> Mapping [ str , List [ str ] ] : results = defaultdict ( list ) for _ , exc , ctx in graph . warnings : if not ctx or not edge_has_annotation ( ctx , annotation ) : continue values = ctx [ ANNOTATIONS ] [ annotation ] if isinstance ( values , ... | Group error names by a given annotation . |
29,558 | def get_subgraph_by_edge_filter ( graph , edge_predicates : Optional [ EdgePredicates ] = None ) : rv = graph . fresh_copy ( ) expand_by_edge_filter ( graph , rv , edge_predicates = edge_predicates ) return rv | Induce a sub - graph on all edges that pass the given filters . |
29,559 | def get_subgraph_by_induction ( graph , nodes : Iterable [ BaseEntity ] ) : nodes = tuple ( nodes ) if all ( node not in graph for node in nodes ) : return return subgraph ( graph , nodes ) | Induce a sub - graph over the given nodes or return None if none of the nodes are in the given graph . |
29,560 | def get_multi_causal_upstream ( graph , nbunch : Union [ BaseEntity , Iterable [ BaseEntity ] ] ) : result = get_upstream_causal_subgraph ( graph , nbunch ) expand_upstream_causal ( graph , result ) return result | Get the union of all the 2 - level deep causal upstream subgraphs from the nbunch . |
29,561 | def get_multi_causal_downstream ( graph , nbunch : Union [ BaseEntity , Iterable [ BaseEntity ] ] ) : result = get_downstream_causal_subgraph ( graph , nbunch ) expand_downstream_causal ( graph , result ) return result | Get the union of all of the 2 - level deep causal downstream subgraphs from the nbunch . |
29,562 | def get_subgraph_by_second_neighbors ( graph , nodes : Iterable [ BaseEntity ] , filter_pathologies : bool = False ) : result = get_subgraph_by_neighborhood ( graph , nodes ) if result is None : return expand_all_node_neighborhoods ( graph , result , filter_pathologies = filter_pathologies ) return result | Get a graph around the neighborhoods of the given nodes and expand to the neighborhood of those nodes . |
29,563 | def _normalize_url ( graph : BELGraph , keyword : str ) -> Optional [ str ] : if keyword == BEL_DEFAULT_NAMESPACE and BEL_DEFAULT_NAMESPACE not in graph . namespace_url : return BEL_DEFAULT_NAMESPACE_URL return graph . namespace_url . get ( keyword ) | Normalize a URL for the BEL graph . |
29,564 | def drop_namespaces ( self ) : self . session . query ( NamespaceEntry ) . delete ( ) self . session . query ( Namespace ) . delete ( ) self . session . commit ( ) | Drop all namespaces . |
29,565 | def drop_namespace_by_url ( self , url : str ) -> None : namespace = self . get_namespace_by_url ( url ) self . session . query ( NamespaceEntry ) . filter ( NamespaceEntry . namespace == namespace ) . delete ( ) self . session . delete ( namespace ) self . session . commit ( ) | Drop the namespace at the given URL . |
29,566 | def get_namespace_by_url ( self , url : str ) -> Optional [ Namespace ] : return self . session . query ( Namespace ) . filter ( Namespace . url == url ) . one_or_none ( ) | Look up a namespace by url . |
29,567 | def get_namespace_by_keyword_version ( self , keyword : str , version : str ) -> Optional [ Namespace ] : filt = and_ ( Namespace . keyword == keyword , Namespace . version == version ) return self . session . query ( Namespace ) . filter ( filt ) . one_or_none ( ) | Get a namespace with a given keyword and version . |
29,568 | def ensure_default_namespace ( self ) -> Namespace : namespace = self . get_namespace_by_keyword_version ( BEL_DEFAULT_NAMESPACE , BEL_DEFAULT_NAMESPACE_VERSION ) if namespace is None : namespace = Namespace ( name = 'BEL Default Namespace' , contact = 'charles.hoyt@scai.fraunhofer.de' , keyword = BEL_DEFAULT_NAMESPACE... | Get or create the BEL default namespace . |
29,569 | def get_namespace_by_keyword_pattern ( self , keyword : str , pattern : str ) -> Optional [ Namespace ] : filt = and_ ( Namespace . keyword == keyword , Namespace . pattern == pattern ) return self . session . query ( Namespace ) . filter ( filt ) . one_or_none ( ) | Get a namespace with a given keyword and pattern . |
29,570 | def ensure_regex_namespace ( self , keyword : str , pattern : str ) -> Namespace : if pattern is None : raise ValueError ( 'cannot have null pattern' ) namespace = self . get_namespace_by_keyword_pattern ( keyword , pattern ) if namespace is None : log . info ( 'creating regex namespace: %s:%s' , keyword , pattern ) na... | Get or create a regular expression namespace . |
29,571 | def get_namespace_entry ( self , url : str , name : str ) -> Optional [ NamespaceEntry ] : entry_filter = and_ ( Namespace . url == url , NamespaceEntry . name == name ) result = self . session . query ( NamespaceEntry ) . join ( Namespace ) . filter ( entry_filter ) . all ( ) if 0 == len ( result ) : return if 1 < len... | Get a given NamespaceEntry object . |
29,572 | def get_or_create_regex_namespace_entry ( self , namespace : str , pattern : str , name : str ) -> NamespaceEntry : namespace = self . ensure_regex_namespace ( namespace , pattern ) n_filter = and_ ( Namespace . pattern == pattern , NamespaceEntry . name == name ) name_model = self . session . query ( NamespaceEntry ) ... | Get a namespace entry from a regular expression . |
29,573 | def list_annotations ( self ) -> List [ Namespace ] : return self . session . query ( Namespace ) . filter ( Namespace . is_annotation ) . all ( ) | List all annotations . |
29,574 | def count_annotations ( self ) -> int : return self . session . query ( Namespace ) . filter ( Namespace . is_annotation ) . count ( ) | Count the number of annotations in the database . |
29,575 | def count_annotation_entries ( self ) -> int : return self . session . query ( NamespaceEntry ) . filter ( NamespaceEntry . is_annotation ) . count ( ) | Count the number of annotation entries in the database . |
29,576 | def get_annotation_entry_names ( self , url : str ) -> Set [ str ] : annotation = self . get_or_create_annotation ( url ) return { x . name for x in self . session . query ( NamespaceEntry . name ) . filter ( NamespaceEntry . namespace == annotation ) } | Return a dict of annotations and their labels for the given annotation file . |
29,577 | def get_annotation_entries_by_names ( self , url : str , names : Iterable [ str ] ) -> List [ NamespaceEntry ] : annotation_filter = and_ ( Namespace . url == url , NamespaceEntry . name . in_ ( names ) ) return self . session . query ( NamespaceEntry ) . join ( Namespace ) . filter ( annotation_filter ) . all ( ) | Get annotation entries by URL and names . |
29,578 | def drop_networks ( self ) -> None : for network in self . session . query ( Network ) . all ( ) : self . drop_network ( network ) | Drop all networks . |
29,579 | def drop_network_by_id ( self , network_id : int ) -> None : network = self . session . query ( Network ) . get ( network_id ) self . drop_network ( network ) | Drop a network by its database identifier . |
29,580 | def drop_network ( self , network : Network ) -> None : edge_ids = [ result . edge_id for result in self . query_singleton_edges_from_network ( network ) ] self . session . query ( network_node ) . filter ( network_node . c . network_id == network . id ) . delete ( synchronize_session = False ) self . session . query (... | Drop a network while also cleaning up any edges that are no longer part of any network . |
29,581 | def query_singleton_edges_from_network ( self , network : Network ) -> sqlalchemy . orm . query . Query : ne1 = aliased ( network_edge , name = 'ne1' ) ne2 = aliased ( network_edge , name = 'ne2' ) singleton_edge_ids_for_network = ( self . session . query ( ne1 . c . edge_id ) . outerjoin ( ne2 , and_ ( ne1 . c . edge_... | Return a query selecting all edge ids that only belong to the given network . |
29,582 | def get_network_versions ( self , name : str ) -> Set [ str ] : return { version for version , in self . session . query ( Network . version ) . filter ( Network . name == name ) . all ( ) } | Return all of the versions of a network with the given name . |
29,583 | def get_network_by_name_version ( self , name : str , version : str ) -> Optional [ Network ] : name_version_filter = and_ ( Network . name == name , Network . version == version ) network = self . session . query ( Network ) . filter ( name_version_filter ) . one_or_none ( ) return network | Load the network with the given name and version if it exists . |
29,584 | def get_graph_by_name_version ( self , name : str , version : str ) -> Optional [ BELGraph ] : network = self . get_network_by_name_version ( name , version ) if network is None : return return network . as_bel ( ) | Load the BEL graph with the given name or allows for specification of version . |
29,585 | def get_networks_by_name ( self , name : str ) -> List [ Network ] : return self . session . query ( Network ) . filter ( Network . name . like ( name ) ) . all ( ) | Get all networks with the given name . Useful for getting all versions of a given network . |
29,586 | def get_most_recent_network_by_name ( self , name : str ) -> Optional [ Network ] : return self . session . query ( Network ) . filter ( Network . name == name ) . order_by ( Network . created . desc ( ) ) . first ( ) | Get the most recently created network with the given name . |
29,587 | def get_network_by_id ( self , network_id : int ) -> Network : return self . session . query ( Network ) . get ( network_id ) | Get a network from the database by its identifier . |
29,588 | def get_graph_by_id ( self , network_id : int ) -> BELGraph : network = self . get_network_by_id ( network_id ) log . debug ( 'converting network [id=%d] %s to bel graph' , network_id , network ) return network . as_bel ( ) | Get a network from the database by its identifier and converts it to a BEL graph . |
29,589 | def get_networks_by_ids ( self , network_ids : Iterable [ int ] ) -> List [ Network ] : log . debug ( 'getting networks by identifiers: %s' , network_ids ) return self . session . query ( Network ) . filter ( Network . id_in ( network_ids ) ) . all ( ) | Get a list of networks with the given identifiers . |
29,590 | def get_graphs_by_ids ( self , network_ids : Iterable [ int ] ) -> List [ BELGraph ] : rv = [ self . get_graph_by_id ( network_id ) for network_id in network_ids ] log . debug ( 'returning graphs for network identifiers: %s' , network_ids ) return rv | Get a list of networks with the given identifiers and converts to BEL graphs . |
29,591 | def get_graph_by_ids ( self , network_ids : List [ int ] ) -> BELGraph : if len ( network_ids ) == 1 : return self . get_graph_by_id ( network_ids [ 0 ] ) log . debug ( 'getting graph by identifiers: %s' , network_ids ) graphs = self . get_graphs_by_ids ( network_ids ) log . debug ( 'getting union of graphs: %s' , netw... | Get a combine BEL Graph from a list of network identifiers . |
29,592 | def insert_graph ( self , graph : BELGraph , store_parts : bool = True , use_tqdm : bool = False ) -> Network : if not graph . name : raise ValueError ( 'Can not upload a graph without a name' ) if not graph . version : raise ValueError ( 'Can not upload a graph without a version' ) log . debug ( 'inserting %s v%s' , g... | Insert a graph in the database and returns the corresponding Network model . |
29,593 | def _store_graph_parts ( self , graph : BELGraph , use_tqdm : bool = False ) -> Tuple [ List [ Node ] , List [ Edge ] ] : log . debug ( 'inserting %s into edge store' , graph ) log . debug ( 'building node models' ) node_model_build_start = time . time ( ) nodes = list ( graph ) if use_tqdm : nodes = tqdm ( nodes , tot... | Store the given graph into the edge store . |
29,594 | def _get_annotation_entries_from_data ( self , graph : BELGraph , data : EdgeData ) -> Optional [ List [ NamespaceEntry ] ] : annotations_dict = data . get ( ANNOTATIONS ) if annotations_dict is not None : return [ entry for url , names in self . _iter_from_annotations_dict ( graph , annotations_dict = annotations_dict... | Get the annotation entries from an edge data dictionary . |
29,595 | def _add_qualified_edge ( self , graph : BELGraph , source : Node , target : Node , key : str , bel : str , data : EdgeData ) : citation_dict = data [ CITATION ] citation = self . get_or_create_citation ( type = citation_dict . get ( CITATION_TYPE ) , reference = citation_dict . get ( CITATION_REFERENCE ) , name = cita... | Add a qualified edge to the network . |
29,596 | def _add_unqualified_edge ( self , source : Node , target : Node , key : str , bel : str , data : EdgeData ) -> Edge : return self . get_or_create_edge ( source = source , target = target , relation = data [ RELATION ] , bel = bel , sha512 = key , data = data , ) | Add an unqualified edge to the network . |
29,597 | def get_or_create_evidence ( self , citation : Citation , text : str ) -> Evidence : sha512 = hash_evidence ( text = text , type = str ( citation . type ) , reference = str ( citation . reference ) ) if sha512 in self . object_cache_evidence : evidence = self . object_cache_evidence [ sha512 ] self . session . add ( ev... | Create an entry and object for given evidence if it does not exist . |
29,598 | def get_or_create_node ( self , graph : BELGraph , node : BaseEntity ) -> Optional [ Node ] : sha512 = node . as_sha512 ( ) if sha512 in self . object_cache_node : return self . object_cache_node [ sha512 ] node_model = self . get_node_by_hash ( sha512 ) if node_model is not None : self . object_cache_node [ sha512 ] =... | Create an entry and object for given node if it does not exist . |
29,599 | def drop_nodes ( self ) -> None : t = time . time ( ) self . session . query ( Node ) . delete ( ) self . session . commit ( ) log . info ( 'dropped all nodes in %.2f seconds' , time . time ( ) - t ) | Drop all nodes in the database . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.