Filters¶
This module contains functions for filtering node and edge iterables.
It relies heavily on the concepts of functional programming and the concept of predicates.
-
pybel.struct.filters.invert_edge_predicate(edge_predicate)[source]¶ Build an edge predicate that is the inverse of the given edge predicate.
-
pybel.struct.filters.and_edge_predicates(edge_predicates)[source]¶ Concatenate multiple edge predicates to a new predicate that requires all predicates to be met.
-
pybel.struct.filters.filter_edges(graph, edge_predicates)[source]¶ Apply a set of filters to the edges iterator of a BEL graph.
-
pybel.struct.filters.count_passed_edge_filter(graph, edge_predicates)[source]¶ Return the number of edges passing a given set of predicates.
- Return type
-
pybel.struct.filters.edge_predicate(func)[source]¶ Decorate an edge predicate function that only takes a dictionary as its singular argument.
Apply this as a decorator to a function that takes a single argument, a PyBEL node data dictionary, to make sure that it can also accept a pair of arguments, a BELGraph and a PyBEL node tuple as well.
-
pybel.struct.filters.keep_edge_permissive(*args, **kwargs)[source]¶ Return true for all edges.
- Parameters
data (dict) – A PyBEL edge data dictionary from a
pybel.BELGraph- Return type
- Returns
Always returns
True
-
pybel.struct.filters.has_provenance(edge_data)[source]¶ Check if the edge has provenance information (i.e. citation and evidence).
- Return type
-
pybel.struct.filters.has_pubmed(edge_data)[source]¶ Check if the edge has a PubMed citation.
- Return type
Check if the edge contains author information for its citation.
- Return type
-
pybel.struct.filters.is_causal_relation(edge_data)[source]¶ Check if the given relation is causal.
- Return type
-
pybel.struct.filters.not_causal_relation(edge_data)[source]¶ Check if the given relation is not causal.
- Return type
-
pybel.struct.filters.is_direct_causal_relation(edge_data)[source]¶ Check if the edge is a direct causal relation.
- Return type
-
pybel.struct.filters.is_associative_relation(edge_data)[source]¶ Check if the edge has an association relation.
- Return type
-
pybel.struct.filters.edge_has_activity(edge_data)[source]¶ Check if the edge contains an activity in either the subject or object.
- Return type
-
pybel.struct.filters.edge_has_degradation(edge_data)[source]¶ Check if the edge contains a degradation in either the subject or object.
- Return type
-
pybel.struct.filters.edge_has_translocation(edge_data)[source]¶ Check if the edge has a translocation in either the subject or object.
- Return type
-
pybel.struct.filters.edge_has_annotation(edge_data, key)[source]¶ Check if an edge has the given annotation.
- Parameters
- Return type
- Returns
If the annotation key is present in the current data dictionary
For example, it might be useful to print all edges that are annotated with ‘Subgraph’:
>>> from pybel.examples import sialic_acid_graph >>> for u, v, data in sialic_acid_graph.edges(data=True): >>> if edge_has_annotation(data, 'Species') >>> print(u, v, data)
-
pybel.struct.filters.has_pathology_causal(graph, u, v, k)[source]¶ Check if the subject is a pathology and has a causal relationship with a non bioprocess/pathology.
- Return type
- Returns
If the subject of this edge is a pathology and it participates in a causal reaction.
-
pybel.struct.filters.build_annotation_dict_all_filter(annotations)[source]¶ Build an edge predicate for edges whose annotations are super-dictionaries of the given dictionary.
If no annotations are given, will always evaluate to true.
-
pybel.struct.filters.build_annotation_dict_any_filter(annotations)[source]¶ Build an edge predicate that passes for edges whose data dictionaries match the given dictionary.
If the given dictionary is empty, will always evaluate to true.
-
pybel.struct.filters.build_upstream_edge_predicate(nodes)[source]¶ Build an edge predicate that pass for relations for which one of the given nodes is the object.
-
pybel.struct.filters.build_downstream_edge_predicate(nodes)[source]¶ Build an edge predicate that passes for edges for which one of the given nodes is the subject.
-
pybel.struct.filters.build_relation_predicate(relations)[source]¶ Build an edge predicate that passes for edges with the given relation.
-
pybel.struct.filters.build_pmid_inclusion_filter(pmids)[source]¶ Build an edge predicate that passes for edges with citations from the given PubMed identifier(s).
Build an edge predicate that passes for edges with citations written by the given author(s).
-
pybel.struct.filters.invert_node_predicate(node_predicate)[source]¶ Build a node predicate that is the inverse of the given node predicate.
-
pybel.struct.filters.concatenate_node_predicates(node_predicates)[source]¶ Concatenate multiple node predicates to a new predicate that requires all predicates to be met.
Example usage:
>>> from pybel.dsl import protein, gene >>> from pybel.struct.filters.node_predicates import not_pathology, node_exclusion_predicate_builder >>> app_protein = protein(name='APP', namespace='HGNC') >>> app_gene = gene(name='APP', namespace='HGNC') >>> app_predicate = node_exclusion_predicate_builder([app_protein, app_gene]) >>> my_predicate = concatenate_node_predicates([not_pathology, app_predicate])
-
pybel.struct.filters.filter_nodes(graph, node_predicates)[source]¶ Apply a set of predicates to the nodes iterator of a BEL graph.
- Return type
Iterable[BaseEntity]
-
pybel.struct.filters.get_nodes(graph, node_predicates)[source]¶ Get the set of all nodes that pass the predicates.
- Return type
Set[BaseEntity]
-
pybel.struct.filters.count_passed_node_filter(graph, node_predicates)[source]¶ Count how many nodes pass a given set of node predicates.
- Return type
-
pybel.struct.filters.function_inclusion_filter_builder(func)[source]¶ Build a filter that only passes on nodes of the given function(s).
-
pybel.struct.filters.data_missing_key_builder(key)[source]¶ Build a filter that passes only on nodes that don’t have the given key in their data dictionary.
-
pybel.struct.filters.build_node_data_search(key, data_predicate)[source]¶ Build a filter for nodes whose associated data with the given key passes the given predicate.
-
pybel.struct.filters.build_node_graph_data_search(key, data_predicate)[source]¶ Build a function for testing data associated with the node in the graph.
-
pybel.struct.filters.build_node_key_search(query, key)[source]¶ Build a node filter for nodes whose values for the given key are superstrings of the query string(s).
-
pybel.struct.filters.build_node_name_search(query)[source]¶ Search nodes’ names.
Is a thin wrapper around
build_node_key_search()withpybel.constants.NAME
-
pybel.struct.filters.namespace_inclusion_builder(namespace)[source]¶ Build a predicate for namespace inclusion.
-
pybel.struct.filters.node_predicate(f)[source]¶ Tag a node predicate that takes a dictionary to also accept a pair of (BELGraph, node).
Apply this as a decorator to a function that takes a single argument, a PyBEL node, to make sure that it can also accept a pair of arguments, a BELGraph and a PyBEL node as well.
-
pybel.struct.filters.keep_node_permissive(_)[source]¶ Return true for all nodes.
Given BEL graph
graph, applyingkeep_node_permissive()with a predicate on the nodes iterable as infilter(keep_node_permissive, graph)will result in the same iterable as iterating directly over aBELGraph- Return type
-
pybel.struct.filters.is_abundance(node)[source]¶ Return true if the node is an abundance.
- Return type
-
pybel.struct.filters.is_pathology(node)[source]¶ Return true if the node is a pathology.
- Return type
-
pybel.struct.filters.not_pathology(node)[source]¶ Return false if the node is a pathology.
- Return type
-
pybel.struct.filters.has_variant(node)[source]¶ Return true if the node has any variants.
- Return type
-
pybel.struct.filters.has_protein_modification(node)[source]¶ Return true if the node has a protein modification variant.
- Return type
-
pybel.struct.filters.has_gene_modification(node)[source]¶ Return true if the node has a gene modification.
- Return type
-
pybel.struct.filters.has_hgvs(node)[source]¶ Return true if the node has an HGVS variant.
- Return type
-
pybel.struct.filters.has_fragment(node)[source]¶ Return true if the node has a fragment.
- Return type
-
pybel.struct.filters.has_activity(graph, node)[source]¶ Return true if over any of the node’s edges, it has a molecular activity.
- Return type
-
pybel.struct.filters.is_degraded(graph, node)[source]¶ Return true if over any of the node’s edges, it is degraded.
- Return type
-
pybel.struct.filters.is_translocated(graph, node)[source]¶ Return true if over any of the node’s edges, it is translocated.
- Return type
-
pybel.struct.filters.has_causal_in_edges(graph, node)[source]¶ Return true if the node contains any in_edges that are causal.
- Return type
-
pybel.struct.filters.has_causal_out_edges(graph, node)[source]¶ Return true if the node contains any out_edges that are causal.
- Return type
-
pybel.struct.filters.node_inclusion_predicate_builder(nodes)[source]¶ Build a function that returns true for the given nodes.
-
pybel.struct.filters.node_exclusion_predicate_builder(nodes)[source]¶ Build a node predicate that returns false for the given nodes.
-
pybel.struct.filters.is_causal_source(graph, node)[source]¶ Return true of the node is a causal source.
Doesn’t have any causal in edge(s)
Does have causal out edge(s)
- Return type
-
pybel.struct.filters.is_causal_sink(graph, node)[source]¶ Return true if the node is a causal sink.
Does have causal in edge(s)
Doesn’t have any causal out edge(s)
- Return type
-
pybel.struct.filters.is_causal_central(graph, node)[source]¶ Return true if the node is neither a causal sink nor a causal source.
Does have causal in edges(s)
Does have causal out edge(s)
- Return type
-
pybel.struct.filters.is_isolated_list_abundance(graph, node, cls=<class 'pybel.dsl.node_classes.ListAbundance'>)[source]¶ Return if the node is a list abundance but has no qualified edges.
- Return type
-
pybel.struct.filters.get_nodes_by_function(graph, func)[source]¶ Get all nodes with the given function(s).
- Return type
Set[BaseEntity]
-
pybel.struct.filters.get_nodes_by_namespace(graph, namespaces)[source]¶ Get all nodes identified by the given namespace(s).
- Return type
Set[BaseEntity]
-
pybel.struct.filters.part_has_modifier(edge_data, part, modifier)[source]¶ Return true if the modifier is in the given subject/object part.
- Parameters
edge_data (
Mapping) – PyBEL edge data dictionarypart (
str) – eitherpybel.constants.SUBJECTorpybel.constants.OBJECTmodifier (
str) – The modifier to look for
- Return type