idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
29,600 | def drop_edges ( self ) -> None : t = time . time ( ) self . session . query ( Edge ) . delete ( ) self . session . commit ( ) log . info ( 'dropped all edges in %.2f seconds' , time . time ( ) - t ) | Drop all edges in the database . |
29,601 | def get_or_create_edge ( self , source : Node , target : Node , relation : str , bel : str , sha512 : str , data : EdgeData , evidence : Optional [ Evidence ] = None , annotations : Optional [ List [ NamespaceEntry ] ] = None , properties : Optional [ List [ Property ] ] = None , ) -> Edge : if sha512 in self . object_... | Create an edge if it does not exist or return it if it does . |
29,602 | def get_or_create_citation ( self , reference : str , type : Optional [ str ] = None , name : Optional [ str ] = None , title : Optional [ str ] = None , volume : Optional [ str ] = None , issue : Optional [ str ] = None , pages : Optional [ str ] = None , date : Optional [ str ] = None , first : Optional [ str ] = Non... | Create a citation if it does not exist or return it if it does . |
29,603 | def get_or_create_author ( self , name : str ) -> Author : author = self . object_cache_author . get ( name ) if author is not None : self . session . add ( author ) return author author = self . get_author_by_name ( name ) if author is not None : self . object_cache_author [ name ] = author return author author = self... | Get an author by name or creates one if it does not exist . |
29,604 | def get_modification_by_hash ( self , sha512 : str ) -> Optional [ Modification ] : return self . session . query ( Modification ) . filter ( Modification . sha512 == sha512 ) . one_or_none ( ) | Get a modification by a SHA512 hash . |
29,605 | def get_property_by_hash ( self , property_hash : str ) -> Optional [ Property ] : return self . session . query ( Property ) . filter ( Property . sha512 == property_hash ) . one_or_none ( ) | Get a property by its hash if it exists . |
29,606 | def _make_property_from_dict ( self , property_def : Dict ) -> Property : property_hash = hash_dump ( property_def ) edge_property_model = self . object_cache_property . get ( property_hash ) if edge_property_model is None : edge_property_model = self . get_property_by_hash ( property_hash ) if not edge_property_model ... | Build an edge property from a dictionary . |
29,607 | def _clean_annotations ( annotations_dict : AnnotationsHint ) -> AnnotationsDict : return { key : ( values if isinstance ( values , dict ) else { v : True for v in values } if isinstance ( values , set ) else { values : True } ) for key , values in annotations_dict . items ( ) } | Fix the formatting of annotation dict . |
29,608 | def defined_namespace_keywords ( self ) -> Set [ str ] : return set ( self . namespace_pattern ) | set ( self . namespace_url ) | The set of all keywords defined as namespaces in this graph . |
29,609 | def defined_annotation_keywords ( self ) -> Set [ str ] : return ( set ( self . annotation_pattern ) | set ( self . annotation_url ) | set ( self . annotation_list ) ) | Get the set of all keywords defined as annotations in this graph . |
29,610 | def skip_storing_namespace ( self , namespace : Optional [ str ] ) -> bool : return ( namespace is not None and namespace in self . namespace_url and self . namespace_url [ namespace ] in self . uncached_namespaces ) | Check if the namespace should be skipped . |
29,611 | def add_warning ( self , exception : BELParserWarning , context : Optional [ Mapping [ str , Any ] ] = None , ) -> None : self . warnings . append ( ( self . path , exception , { } if context is None else context , ) ) | Add a warning to the internal warning log in the graph with optional context information . |
29,612 | def _help_add_edge ( self , u : BaseEntity , v : BaseEntity , attr : Mapping ) -> str : self . add_node_from_data ( u ) self . add_node_from_data ( v ) return self . _help_add_edge_helper ( u , v , attr ) | Help add a pre - built edge . |
29,613 | def add_unqualified_edge ( self , u : BaseEntity , v : BaseEntity , relation : str ) -> str : attr = { RELATION : relation } return self . _help_add_edge ( u , v , attr ) | Add a unique edge that has no annotations . |
29,614 | def add_transcription ( self , gene : Gene , rna : Union [ Rna , MicroRna ] ) -> str : return self . add_unqualified_edge ( gene , rna , TRANSCRIBED_TO ) | Add a transcription relation from a gene to an RNA or miRNA node . |
29,615 | def add_translation ( self , rna : Rna , protein : Protein ) -> str : return self . add_unqualified_edge ( rna , protein , TRANSLATED_TO ) | Add a translation relation from a RNA to a protein . |
29,616 | def _add_two_way_unqualified_edge ( self , u : BaseEntity , v : BaseEntity , relation : str ) -> str : self . add_unqualified_edge ( v , u , relation ) return self . add_unqualified_edge ( u , v , relation ) | Add an unqualified edge both ways . |
29,617 | def add_qualified_edge ( self , u , v , * , relation : str , evidence : str , citation : Union [ str , Mapping [ str , str ] ] , annotations : Optional [ AnnotationsHint ] = None , subject_modifier : Optional [ Mapping ] = None , object_modifier : Optional [ Mapping ] = None , ** attr ) -> str : attr . update ( { RELAT... | Add a qualified edge . |
29,618 | def add_node_from_data ( self , node : BaseEntity ) -> BaseEntity : assert isinstance ( node , BaseEntity ) if node in self : return node self . add_node ( node ) if VARIANTS in node : self . add_has_variant ( node . get_parent ( ) , node ) elif MEMBERS in node : for member in node [ MEMBERS ] : self . add_has_componen... | Add an entity to the graph . |
29,619 | def has_edge_citation ( self , u : BaseEntity , v : BaseEntity , key : str ) -> bool : return self . _has_edge_attr ( u , v , key , CITATION ) | Check if the given edge has a citation . |
29,620 | def has_edge_evidence ( self , u : BaseEntity , v : BaseEntity , key : str ) -> bool : return self . _has_edge_attr ( u , v , key , EVIDENCE ) | Check if the given edge has an evidence . |
29,621 | def get_edge_citation ( self , u : BaseEntity , v : BaseEntity , key : str ) -> Optional [ CitationDict ] : return self . _get_edge_attr ( u , v , key , CITATION ) | Get the citation for a given edge . |
29,622 | def get_edge_evidence ( self , u : BaseEntity , v : BaseEntity , key : str ) -> Optional [ str ] : return self . _get_edge_attr ( u , v , key , EVIDENCE ) | Get the evidence for a given edge . |
29,623 | def get_edge_annotations ( self , u , v , key : str ) -> Optional [ AnnotationsDict ] : return self . _get_edge_attr ( u , v , key , ANNOTATIONS ) | Get the annotations for a given edge . |
29,624 | def get_node_description ( self , node : BaseEntity ) -> Optional [ str ] : return self . _get_node_attr ( node , DESCRIPTION ) | Get the description for a given node . |
29,625 | def set_node_description ( self , node : BaseEntity , description : str ) -> None : self . _set_node_attr ( node , DESCRIPTION , description ) | Set the description for a given node . |
29,626 | def edge_to_bel ( u : BaseEntity , v : BaseEntity , edge_data : EdgeData , sep : Optional [ str ] = None ) -> str : return edge_to_bel ( u , v , data = edge_data , sep = sep ) | Serialize a pair of nodes and related edge data as a BEL relation . |
29,627 | def _equivalent_node_iterator_helper ( self , node : BaseEntity , visited : Set [ BaseEntity ] ) -> BaseEntity : for v in self [ node ] : if v in visited : continue if self . _has_no_equivalent_edge ( node , v ) : continue visited . add ( v ) yield v yield from self . _equivalent_node_iterator_helper ( v , visited ) | Iterate over nodes and their data that are equal to the given node starting with the original . |
29,628 | def iter_equivalent_nodes ( self , node : BaseEntity ) -> Iterable [ BaseEntity ] : yield node yield from self . _equivalent_node_iterator_helper ( node , { node } ) | Iterate over nodes that are equivalent to the given node including the original . |
29,629 | def get_equivalent_nodes ( self , node : BaseEntity ) -> Set [ BaseEntity ] : if isinstance ( node , BaseEntity ) : return set ( self . iter_equivalent_nodes ( node ) ) return set ( self . iter_equivalent_nodes ( node ) ) | Get a set of equivalent nodes to this node excluding the given node . |
29,630 | def _node_has_namespace_helper ( node : BaseEntity , namespace : str ) -> bool : return namespace == node . get ( NAMESPACE ) | Check that the node has namespace information . |
29,631 | def node_has_namespace ( self , node : BaseEntity , namespace : str ) -> bool : return any ( self . _node_has_namespace_helper ( n , namespace ) for n in self . iter_equivalent_nodes ( node ) ) | Check if the node have the given namespace . |
29,632 | def _describe_list ( self ) -> List [ Tuple [ str , float ] ] : number_nodes = self . number_of_nodes ( ) return [ ( 'Number of Nodes' , number_nodes ) , ( 'Number of Edges' , self . number_of_edges ( ) ) , ( 'Number of Citations' , self . number_of_citations ( ) ) , ( 'Number of Authors' , self . number_of_authors ( )... | Return useful information about the graph as a list of tuples . |
29,633 | def summary_str ( self ) -> str : return '{}\n' . format ( self ) + '\n' . join ( '{}: {}' . format ( label , value ) for label , value in self . _describe_list ( ) ) | Return a string that summarizes the graph . |
29,634 | def summarize ( self , file : Optional [ TextIO ] = None ) -> None : print ( self . summary_str ( ) , file = file ) | Print a summary of the graph . |
29,635 | def serialize ( self , * , fmt : str = 'nodelink' , file : Union [ None , str , TextIO ] = None , ** kwargs ) : if file is None : return self . _serialize_object ( fmt = fmt , ** kwargs ) elif isinstance ( file , str ) : with open ( file , 'w' ) as file_obj : self . _serialize_file ( fmt = fmt , file = file_obj , ** kw... | Serialize the graph to an object or file if given . |
29,636 | def remove_isolated_nodes ( graph ) : nodes = list ( nx . isolates ( graph ) ) graph . remove_nodes_from ( nodes ) | Remove isolated nodes from the network in place . |
29,637 | def remove_isolated_nodes_op ( graph ) : rv = graph . copy ( ) nodes = list ( nx . isolates ( rv ) ) rv . remove_nodes_from ( nodes ) return rv | Build a new graph excluding the isolated nodes . |
29,638 | def expand_by_edge_filter ( source , target , edge_predicates : EdgePredicates ) : target . add_edges_from ( ( u , v , k , source [ u ] [ v ] [ k ] ) for u , v , k in filter_edges ( source , edge_predicates = edge_predicates ) ) update_node_helper ( source , target ) update_metadata ( source , target ) | Expand a target graph by edges in the source matching the given predicates . |
29,639 | def handle_document ( self , line : str , position : int , tokens : ParseResults ) -> ParseResults : key = tokens [ 'key' ] value = tokens [ 'value' ] if key not in DOCUMENT_KEYS : raise InvalidMetadataException ( self . get_line_number ( ) , line , position , key , value ) norm_key = DOCUMENT_KEYS [ key ] if norm_key ... | Handle statements like SET DOCUMENT X = Y . |
29,640 | def raise_for_redefined_namespace ( self , line : str , position : int , namespace : str ) -> None : if self . disallow_redefinition and self . has_namespace ( namespace ) : raise RedefinedNamespaceError ( self . get_line_number ( ) , line , position , namespace ) | Raise an exception if a namespace is already defined . |
29,641 | def handle_namespace_url ( self , line : str , position : int , tokens : ParseResults ) -> ParseResults : namespace = tokens [ 'name' ] self . raise_for_redefined_namespace ( line , position , namespace ) url = tokens [ 'url' ] self . namespace_url_dict [ namespace ] = url if self . skip_validation : return tokens name... | Handle statements like DEFINE NAMESPACE X AS URL Y . |
29,642 | def handle_namespace_pattern ( self , line : str , position : int , tokens : ParseResults ) -> ParseResults : namespace = tokens [ 'name' ] self . raise_for_redefined_namespace ( line , position , namespace ) self . namespace_to_pattern [ namespace ] = re . compile ( tokens [ 'value' ] ) return tokens | Handle statements like DEFINE NAMESPACE X AS PATTERN Y . |
29,643 | def raise_for_redefined_annotation ( self , line : str , position : int , annotation : str ) -> None : if self . disallow_redefinition and self . has_annotation ( annotation ) : raise RedefinedAnnotationError ( self . get_line_number ( ) , line , position , annotation ) | Raise an exception if the given annotation is already defined . |
29,644 | def handle_annotations_url ( self , line : str , position : int , tokens : ParseResults ) -> ParseResults : keyword = tokens [ 'name' ] self . raise_for_redefined_annotation ( line , position , keyword ) url = tokens [ 'url' ] self . annotation_url_dict [ keyword ] = url if self . skip_validation : return tokens self .... | Handle statements like DEFINE ANNOTATION X AS URL Y . |
29,645 | def handle_annotation_pattern ( self , line : str , position : int , tokens : ParseResults ) -> ParseResults : annotation = tokens [ 'name' ] self . raise_for_redefined_annotation ( line , position , annotation ) self . annotation_to_pattern [ annotation ] = re . compile ( tokens [ 'value' ] ) return tokens | Handle statements like DEFINE ANNOTATION X AS PATTERN Y . |
29,646 | def has_annotation ( self , annotation : str ) -> bool : return ( self . has_enumerated_annotation ( annotation ) or self . has_regex_annotation ( annotation ) or self . has_local_annotation ( annotation ) ) | Check if this annotation is defined . |
29,647 | def raise_for_version ( self , line : str , position : int , version : str ) -> None : if valid_date_version ( version ) : return if not SEMANTIC_VERSION_STRING_RE . match ( version ) : raise VersionFormatWarning ( self . get_line_number ( ) , line , position , version ) | Check that a version string is valid for BEL documents . |
29,648 | def chebi ( name = None , identifier = None ) -> Abundance : return Abundance ( namespace = 'CHEBI' , name = name , identifier = identifier ) | Build a ChEBI abundance node . |
29,649 | def hgnc ( name = None , identifier = None ) -> Protein : return Protein ( namespace = 'HGNC' , name = name , identifier = identifier ) | Build an HGNC protein node . |
29,650 | def build_engine_session ( connection : str , echo : bool = False , autoflush : Optional [ bool ] = None , autocommit : Optional [ bool ] = None , expire_on_commit : Optional [ bool ] = None , scopefunc = None ) -> Tuple : if connection is None : raise ValueError ( 'can not build engine when connection is None' ) engin... | Build an engine and a session . |
29,651 | def create_all ( self , checkfirst : bool = True ) -> None : self . base . metadata . create_all ( bind = self . engine , checkfirst = checkfirst ) | Create the PyBEL cache s database and tables . |
29,652 | def drop_all ( self , checkfirst : bool = True ) -> None : self . session . close ( ) self . base . metadata . drop_all ( bind = self . engine , checkfirst = checkfirst ) | Drop all data tables and databases for the PyBEL cache . |
29,653 | def bind ( self ) -> None : self . base . metadata . bind = self . engine self . base . query = self . session . query_property ( ) | Bind the metadata to the engine and session . |
29,654 | def _list_model ( self , model_cls : Type [ X ] ) -> List [ X ] : return self . session . query ( model_cls ) . all ( ) | List the models in this class . |
29,655 | def sanitize_date ( publication_date : str ) -> str : if re1 . search ( publication_date ) : return datetime . strptime ( publication_date , '%Y %b %d' ) . strftime ( '%Y-%m-%d' ) if re2 . search ( publication_date ) : return datetime . strptime ( publication_date , '%Y %b' ) . strftime ( '%Y-%m-01' ) if re3 . search (... | Sanitize lots of different date strings into ISO - 8601 . |
29,656 | def clean_pubmed_identifiers ( pmids : Iterable [ str ] ) -> List [ str ] : return sorted ( { str ( pmid ) . strip ( ) for pmid in pmids } ) | Clean a list of PubMed identifiers with string strips deduplicates and sorting . |
29,657 | def get_pubmed_citation_response ( pubmed_identifiers : Iterable [ str ] ) : pubmed_identifiers = list ( pubmed_identifiers ) url = EUTILS_URL_FMT . format ( ',' . join ( pubmed_identifier for pubmed_identifier in pubmed_identifiers if pubmed_identifier ) ) response = requests . get ( url ) return response . json ( ) | Get the response from PubMed E - Utils for a given list of PubMed identifiers . |
29,658 | def enrich_citation_model ( manager , citation , p ) -> bool : if 'error' in p : log . warning ( 'Error downloading PubMed' ) return False citation . name = p [ 'fulljournalname' ] citation . title = p [ 'title' ] citation . volume = p [ 'volume' ] citation . issue = p [ 'issue' ] citation . pages = p [ 'pages' ] citat... | Enrich a citation model with the information from PubMed . |
29,659 | def get_citations_by_pmids ( manager , pmids : Iterable [ Union [ str , int ] ] , group_size : Optional [ int ] = None , sleep_time : Optional [ int ] = None , ) -> Tuple [ Dict [ str , Dict ] , Set [ str ] ] : group_size = group_size if group_size is not None else 200 sleep_time = sleep_time if sleep_time is not None ... | Get citation information for the given list of PubMed identifiers using the NCBI s eUtils service . |
29,660 | def enrich_pubmed_citations ( manager , graph , group_size : Optional [ int ] = None , sleep_time : Optional [ int ] = None , ) -> Set [ str ] : pmids = get_pubmed_identifiers ( graph ) pmid_data , errors = get_citations_by_pmids ( manager , pmids = pmids , group_size = group_size , sleep_time = sleep_time ) for u , v ... | Overwrite all PubMed citations with values from NCBI s eUtils lookup service . |
29,661 | def _build_collapse_to_gene_dict ( graph ) -> Dict [ BaseEntity , Set [ BaseEntity ] ] : collapse_dict = defaultdict ( set ) r2g = { } for gene_node , rna_node , d in graph . edges ( data = True ) : if d [ RELATION ] != TRANSCRIBED_TO : continue collapse_dict [ gene_node ] . add ( rna_node ) r2g [ rna_node ] = gene_nod... | Build a collapse dictionary . |
29,662 | def collapse_to_genes ( graph ) : enrich_protein_and_rna_origins ( graph ) collapse_dict = _build_collapse_to_gene_dict ( graph ) collapse_nodes ( graph , collapse_dict ) | Collapse all protein RNA and miRNA nodes to their corresponding gene nodes . |
29,663 | def main ( ctx , connection ) : ctx . obj = Manager ( connection = connection ) ctx . obj . bind ( ) | Command line interface for PyBEL . |
29,664 | def compile ( manager , path , allow_naked_names , allow_nested , disallow_unqualified_translocations , no_identifier_validation , no_citation_clearing , required_annotations , skip_tqdm , verbose ) : if verbose : logging . basicConfig ( level = logging . DEBUG ) log . setLevel ( logging . DEBUG ) log . debug ( 'using ... | Compile a BEL script to a graph . |
29,665 | def insert ( manager , graph : BELGraph ) : to_database ( graph , manager = manager , use_tqdm = True ) | Insert a graph to the database . |
29,666 | def post ( graph : BELGraph , host : str ) : resp = to_web ( graph , host = host ) resp . raise_for_status ( ) | Upload a graph to BEL Commons . |
29,667 | def serialize ( graph : BELGraph , csv , sif , gsea , graphml , json , bel ) : if csv : log . info ( 'Outputting CSV to %s' , csv ) to_csv ( graph , csv ) if sif : log . info ( 'Outputting SIF to %s' , sif ) to_sif ( graph , sif ) if graphml : log . info ( 'Outputting GraphML to %s' , graphml ) to_graphml ( graph , gra... | Serialize a graph to various formats . |
29,668 | def neo ( graph : BELGraph , connection : str , password : str ) : import py2neo neo_graph = py2neo . Graph ( connection , password = password ) to_neo4j ( graph , neo_graph ) | Upload to neo4j . |
29,669 | def machine ( manager : Manager , agents : List [ str ] , local : bool , host : str ) : from indra . sources import indra_db_rest from pybel import from_indra_statements statements = indra_db_rest . get_statements ( agents = agents ) click . echo ( 'got {} statements from INDRA' . format ( len ( statements ) ) ) graph ... | Get content from the INDRA machine and upload to BEL Commons . |
29,670 | def examples ( manager : Manager ) : for graph in ( sialic_acid_graph , statin_graph , homology_graph , braf_graph , egf_graph ) : if manager . has_name_version ( graph . name , graph . version ) : click . echo ( 'already inserted {}' . format ( graph ) ) continue click . echo ( 'inserting {}' . format ( graph ) ) mana... | Load examples to the database . |
29,671 | def ls ( manager : Manager , url : Optional [ str ] , namespace_id : Optional [ int ] ) : if url : n = manager . get_or_create_namespace ( url ) if isinstance ( n , Namespace ) : _page ( n . entries ) else : click . echo ( 'uncachable namespace' ) elif namespace_id is not None : _ls ( manager , Namespace , namespace_id... | List cached namespaces . |
29,672 | def ls ( manager : Manager ) : for n in manager . list_networks ( ) : click . echo ( '{}\t{}\t{}' . format ( n . id , n . name , n . version ) ) | List network names versions and optionally descriptions . |
29,673 | def drop ( manager : Manager , network_id : Optional [ int ] , yes ) : if network_id : manager . drop_network_by_id ( network_id ) elif yes or click . confirm ( 'Drop all networks?' ) : manager . drop_networks ( ) | Drop a network by its identifier or drop all networks . |
29,674 | def ls ( manager : Manager , offset : Optional [ int ] , limit : Optional [ int ] ) : q = manager . session . query ( Edge ) if offset : q = q . offset ( offset ) if limit > 0 : q = q . limit ( limit ) for e in q : click . echo ( e . bel ) | List edges . |
29,675 | def prune ( manager : Manager ) : nodes_to_delete = [ node for node in tqdm ( manager . session . query ( Node ) , total = manager . count_nodes ( ) ) if not node . networks ] manager . session . delete ( nodes_to_delete ) manager . session . commit ( ) | Prune nodes not belonging to any edges . |
29,676 | def summarize ( manager : Manager ) : click . echo ( 'Networks: {}' . format ( manager . count_networks ( ) ) ) click . echo ( 'Edges: {}' . format ( manager . count_edges ( ) ) ) click . echo ( 'Nodes: {}' . format ( manager . count_nodes ( ) ) ) click . echo ( 'Namespaces: {}' . format ( manager . count_namespaces ( ... | Summarize the contents of the database . |
29,677 | def echo_warnings_via_pager ( warnings : List [ WarningTuple ] , sep : str = '\t' ) -> None : if not warnings : click . echo ( 'Congratulations! No warnings.' ) sys . exit ( 0 ) max_line_width = max ( len ( str ( exc . line_number ) ) for _ , exc , _ in warnings ) max_warning_width = max ( len ( exc . __class__ . __nam... | Output the warnings from a BEL graph with Click and the system s pager . |
29,678 | def parse_result_to_dsl ( tokens ) : if MODIFIER in tokens : return parse_result_to_dsl ( tokens [ TARGET ] ) elif REACTION == tokens [ FUNCTION ] : return _reaction_po_to_dict ( tokens ) elif VARIANTS in tokens : return _variant_po_to_dict ( tokens ) elif MEMBERS in tokens : return _list_po_to_dict ( tokens ) elif FUS... | Convert a ParseResult to a PyBEL DSL object . |
29,679 | def _fusion_to_dsl ( tokens ) -> FusionBase : func = tokens [ FUNCTION ] fusion_dsl = FUNC_TO_FUSION_DSL [ func ] member_dsl = FUNC_TO_DSL [ func ] partner_5p = member_dsl ( namespace = tokens [ FUSION ] [ PARTNER_5P ] [ NAMESPACE ] , name = tokens [ FUSION ] [ PARTNER_5P ] [ NAME ] ) partner_3p = member_dsl ( namespac... | Convert a PyParsing data dictionary to a PyBEL fusion data dictionary . |
29,680 | def _fusion_range_to_dsl ( tokens ) -> FusionRangeBase : if FUSION_MISSING in tokens : return missing_fusion_range ( ) return fusion_range ( reference = tokens [ FUSION_REFERENCE ] , start = tokens [ FUSION_START ] , stop = tokens [ FUSION_STOP ] ) | Convert a PyParsing data dictionary into a PyBEL . |
29,681 | def _simple_po_to_dict ( tokens ) -> BaseAbundance : dsl = FUNC_TO_DSL . get ( tokens [ FUNCTION ] ) if dsl is None : raise ValueError ( 'invalid tokens: {}' . format ( tokens ) ) return dsl ( namespace = tokens [ NAMESPACE ] , name = tokens . get ( NAME ) , identifier = tokens . get ( IDENTIFIER ) , ) | Convert a simple named entity to a DSL object . |
29,682 | def _variant_to_dsl_helper ( tokens ) -> Variant : kind = tokens [ KIND ] if kind == HGVS : return hgvs ( tokens [ IDENTIFIER ] ) if kind == GMOD : return gmod ( name = tokens [ IDENTIFIER ] [ NAME ] , namespace = tokens [ IDENTIFIER ] [ NAMESPACE ] , ) if kind == PMOD : return pmod ( name = tokens [ IDENTIFIER ] [ NAM... | Convert variant tokens to DSL objects . |
29,683 | def _reaction_po_to_dict ( tokens ) -> Reaction : return Reaction ( reactants = _reaction_part_po_to_dict ( tokens [ REACTANTS ] ) , products = _reaction_part_po_to_dict ( tokens [ PRODUCTS ] ) , ) | Convert a reaction parse object to a DSL . |
29,684 | def _list_po_to_dict ( tokens ) -> ListAbundance : func = tokens [ FUNCTION ] dsl = FUNC_TO_LIST_DSL [ func ] members = [ parse_result_to_dsl ( token ) for token in tokens [ MEMBERS ] ] return dsl ( members ) | Convert a list parse object to a node . |
29,685 | def get_subgraph_by_annotations ( graph , annotations , or_ = None ) : edge_filter_builder = ( build_annotation_dict_any_filter if ( or_ is None or or_ ) else build_annotation_dict_all_filter ) return get_subgraph_by_edge_filter ( graph , edge_filter_builder ( annotations ) ) | Induce a sub - graph given an annotations filter . |
29,686 | def get_subgraph_by_annotation_value ( graph , annotation , values ) : if isinstance ( values , str ) : values = { values } return get_subgraph_by_annotations ( graph , { annotation : values } ) | Induce a sub - graph over all edges whose annotations match the given key and value . |
29,687 | def invert_edge_predicate ( edge_predicate : EdgePredicate ) -> EdgePredicate : def _inverse_filter ( graph , u , v , k ) : return not edge_predicate ( graph , u , v , k ) return _inverse_filter | Build an edge predicate that is the inverse of the given edge predicate . |
29,688 | def and_edge_predicates ( edge_predicates : EdgePredicates ) -> EdgePredicate : if not isinstance ( edge_predicates , Iterable ) : return edge_predicates edge_predicates = tuple ( edge_predicates ) if 1 == len ( edge_predicates ) : return edge_predicates [ 0 ] def concatenated_edge_predicate ( graph : BELGraph , u : Ba... | Concatenate multiple edge predicates to a new predicate that requires all predicates to be met . |
29,689 | def filter_edges ( graph : BELGraph , edge_predicates : EdgePredicates ) -> EdgeIterator : compound_edge_predicate = and_edge_predicates ( edge_predicates = edge_predicates ) for u , v , k in graph . edges ( keys = True ) : if compound_edge_predicate ( graph , u , v , k ) : yield u , v , k | Apply a set of filters to the edges iterator of a BEL graph . |
29,690 | def count_passed_edge_filter ( graph : BELGraph , edge_predicates : EdgePredicates ) -> int : return sum ( 1 for _ in filter_edges ( graph , edge_predicates = edge_predicates ) ) | Return the number of edges passing a given set of predicates . |
29,691 | def subgraph ( graph , nodes : Iterable [ BaseEntity ] ) : sg = graph . subgraph ( nodes ) result = graph . fresh_copy ( ) result . graph . update ( sg . graph ) for node , data in sg . nodes ( data = True ) : result . add_node ( node , ** data ) result . add_edges_from ( ( u , v , key , datadict . copy ( ) ) for u , v... | Induce a sub - graph over the given nodes . |
29,692 | def left_full_join ( g , h ) -> None : g . add_nodes_from ( ( node , data ) for node , data in h . nodes ( data = True ) if node not in g ) g . add_edges_from ( ( u , v , key , data ) for u , v , key , data in h . edges ( keys = True , data = True ) if u not in g or v not in g [ u ] or key not in g [ u ] [ v ] ) update... | Add all nodes and edges from h to g in - place for g . |
29,693 | def left_outer_join ( g , h ) -> None : g_nodes = set ( g ) for comp in nx . weakly_connected_components ( h ) : if g_nodes . intersection ( comp ) : h_subgraph = subgraph ( h , comp ) left_full_join ( g , h_subgraph ) | Only add components from the h that are touching g . |
29,694 | def union ( graphs , use_tqdm : bool = False ) : it = iter ( graphs ) if use_tqdm : it = tqdm ( it , desc = 'taking union' ) try : target = next ( it ) except StopIteration as e : raise ValueError ( 'no graphs given' ) from e try : graph = next ( it ) except StopIteration : return target else : target = target . copy (... | Take the union over a collection of graphs into a new graph . |
29,695 | def left_node_intersection_join ( g , h ) : intersecting = set ( g ) . intersection ( set ( h ) ) g_inter = subgraph ( g , intersecting ) h_inter = subgraph ( h , intersecting ) left_full_join ( g_inter , h_inter ) return g_inter | Take the intersection over two graphs . |
29,696 | def node_intersection ( graphs ) : graphs = tuple ( graphs ) n_graphs = len ( graphs ) if n_graphs == 0 : raise ValueError ( 'no graphs given' ) if n_graphs == 1 : return graphs [ 0 ] nodes = set ( graphs [ 0 ] . nodes ( ) ) for graph in graphs [ 1 : ] : nodes . intersection_update ( graph ) return union ( subgraph ( g... | Take the node intersection over a collection of graphs into a new graph . |
29,697 | def strip_annotations ( graph ) : for u , v , k in graph . edges ( keys = True ) : if ANNOTATIONS in graph [ u ] [ v ] [ k ] : del graph [ u ] [ v ] [ k ] [ ANNOTATIONS ] | Strip all the annotations from a BEL graph . |
29,698 | def remove_citation_metadata ( graph ) : for u , v , k in graph . edges ( keys = True ) : if CITATION not in graph [ u ] [ v ] [ k ] : continue for key in list ( graph [ u ] [ v ] [ k ] [ CITATION ] ) : if key not in _CITATION_KEEP_KEYS : del graph [ u ] [ v ] [ k ] [ CITATION ] [ key ] | Remove the metadata associated with a citation . |
29,699 | def to_json ( graph : BELGraph ) -> Mapping [ str , Any ] : graph_json_dict = node_link_data ( graph ) graph_json_dict [ 'graph' ] [ GRAPH_ANNOTATION_LIST ] = { keyword : list ( sorted ( values ) ) for keyword , values in graph_json_dict [ 'graph' ] . get ( GRAPH_ANNOTATION_LIST , { } ) . items ( ) } graph_json_dict [ ... | Convert this graph to a Node - Link JSON object . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.