Filters

Filters to supplement pybel.struct.filters.

Node filters to supplement pybel.struct.filters.node_filters.

pybel_tools.filters.node_filters.summarize_node_filter(graph, node_filters)[source]

Print a summary of the number of nodes passing a given set of filters.

Parameters
  • graph (BELGraph) – A BEL graph

  • node_filters (Union[Callable[[BELGraph, BaseEntity], bool], Iterable[Callable[[BELGraph, BaseEntity], bool]]]) – A node filter or list/tuple of node filters

Return type

None

pybel_tools.filters.node_filters.node_inclusion_filter_builder(nodes)[source]

Build a filter that only passes on nodes in the given list.

Parameters

nodes (Iterable[BaseEntity]) – An iterable of BEL nodes

Return type

Callable[[BELGraph, BaseEntity], bool]

pybel_tools.filters.node_filters.node_exclusion_filter_builder(nodes)[source]

Build a filter that fails on nodes in the given list.

Return type

Callable[[BELGraph, BaseEntity], bool]

pybel_tools.filters.node_filters.function_inclusion_filter_builder(func)[source]

Build a filter that only passes on nodes of the given function(s).

Parameters

func (Union[str, Iterable[str]]) – A BEL Function or list/set/tuple of BEL functions

Return type

Callable[[BELGraph, BaseEntity], bool]

pybel_tools.filters.node_filters.function_exclusion_filter_builder(func)[source]

Build a filter that fails on nodes of the given function(s).

Parameters

func (Union[str, Iterable[str]]) – A BEL Function or list/set/tuple of BEL functions

Return type

Callable[[BELGraph, BaseEntity], bool]

pybel_tools.filters.node_filters.function_namespace_inclusion_builder(func, namespace)[source]

Build a filter function for matching the given BEL function with the given namespace or namespaces.

Parameters
Return type

Callable[[BELGraph, BaseEntity], bool]

pybel_tools.filters.node_filters.data_contains_key_builder(key)[source]

Build a filter that passes only on nodes that have the given key in their data dictionary.

Parameters

key (str) – A key for the node’s data dictionary

Return type

Callable[[BELGraph, BaseEntity], bool]

pybel_tools.filters.node_filters.node_has_label(_, node)

Passes for nodes that have been annotated with a label

Return type

bool

pybel_tools.filters.node_filters.node_missing_label(graph, node)

Fails for nodes that have been annotated with a label

Return type

bool

pybel_tools.filters.node_filters.include_pathology_filter(_, node)

A filter that passes for nodes that are pybel.constants.PATHOLOGY

Return type

bool

pybel_tools.filters.node_filters.exclude_pathology_filter(_, node)

A filter that fails for nodes that are pybel.constants.PATHOLOGY

Return type

bool

pybel_tools.filters.node_filters.variants_of(graph, node, modifications=None)[source]

Returns all variants of the given node.

Return type

Set[Protein]

pybel_tools.filters.node_filters.get_variants_to_controllers(graph, node, modifications=None)[source]

Get a mapping from variants of the given node to all of its upstream controllers.

Return type

Mapping[Protein, Set[Protein]]

pybel_tools.filters.node_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.

Parameters

key (str) – A key for the node’s data dictionary

Return type

Callable[[BELGraph, BaseEntity], bool]

Build a filter for nodes whose associated data with the given key passes the given predicate.

Parameters
  • key (str) – The node data dictionary key to check

  • data_predicate (Callable[[Any], bool]) – The filter to apply to the node data dictionary

Return type

Callable[[BELGraph, BaseEntity], bool]

Build a node filter for nodes whose values for the given key are superstrings of the query string(s).

Parameters
  • query (str or iter[str]) – The query string or strings to check if they’re in the node name

  • key (str) – The key for the node data dictionary. Should refer only to entries that have str values

Return type

Callable[[BELGraph, BaseEntity], bool]

Edge filters to supplement pybel.struct.filters.edge_filters.

pybel_tools.filters.edge_filters.summarize_edge_filter(graph, edge_predicates)[source]

Print a summary of the number of edges passing a given set of filters.

Return type

None

pybel_tools.filters.edge_filters.build_edge_data_filter(annotations, partial_match=True)[source]

Build a filter that keeps edges whose data dictionaries are super-dictionaries to the given dictionary.

Parameters
  • annotations (Mapping[~KT, +VT_co]) – The annotation query dict to match

  • partial_match (bool) – Should the query values be used as partial or exact matches? Defaults to True.

Return type

Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]

pybel_tools.filters.edge_filters.build_pmid_inclusion_filter(pmids)[source]

Pass for edges with citations whose references are one of the given PubMed identifiers.

Parameters

pmids (Union[str, Iterable[str]]) – A PubMed identifier or list of PubMed identifiers to filter for

Return type

Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]

pybel_tools.filters.edge_filters.build_pmid_exclusion_filter(pmids)[source]

Fail for edges with citations whose references are one of the given PubMed identifiers.

Parameters

pmids (Union[str, Iterable[str]]) – A PubMed identifier or list of PubMed identifiers to filter against

Return type

Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]

pybel_tools.filters.edge_filters.build_author_inclusion_filter(authors)[source]

Pass only for edges with author information that matches one of the given authors.

Parameters

authors (Union[str, Iterable[str]]) – The author or list of authors to filter by

Return type

Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]

pybel_tools.filters.edge_filters.build_source_namespace_filter(namespaces)[source]

Pass for edges whose source nodes have the given namespace or one of the given namespaces.

Parameters

namespaces (Union[str, Iterable[str]]) – The namespace or namespaces to filter by

Return type

Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]

pybel_tools.filters.edge_filters.build_target_namespace_filter(namespaces)[source]

Only passes for edges whose target nodes have the given namespace or one of the given namespaces

Parameters

namespaces (Union[str, Iterable[str]]) – The namespace or namespaces to filter by

Return type

Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]

pybel_tools.filters.edge_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.

Parameters

annotations (Mapping[str, Iterable[str]]) – The annotation query dict to match

Return type

Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]

pybel_tools.filters.edge_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.

Parameters

annotations (Mapping[str, Iterable[str]]) – The annotation query dict to match

Return type

Callable[[BELGraph, BaseEntity, BaseEntity, str], bool]

pybel_tools.filters.edge_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

bool

Returns

If the subject of this edge is a pathology and it participates in a causal reaction.