Pipeline Builder

This module assists in running complex workflows on BEL graphs.

Example Pipeline #1

This example shows a pipeline that acquires a subgraph and finds possible additions to the subgraph.

>>> network = ...
>>> example = Pipeline()
>>> example.append('get_subgraph_by_annotation_value', 'Subgraph', 'Blood vessel dilation subgraph')
>>> example.append('enrich_unqualified')
>>> example.append('infer_central_dogma')
>>> example.append('expand_periphery')
>>> result = example.run(network)

Example Pipeline #2

This example shows how additional data can be integrated into a graph.

>>> from pybel.constants import PROTEIN
>>> network = ...
>>> example = Pipeline()
>>> example.append('infer_central_dogma')
>>> example.append('enrich_unqualified')
>>> example.append('infer_central_dogma')
>>> example.append('expand_periphery')
>>> example.append('expand_nodes_neighborhoods', [(PROTEIN, 'HGNC', 'AKT1'), (PROTEIN, 'HGNC', 'AKT2')])
>>> result = example.run(network)

Example Pipeline #3

This example shows how the results from multiple pipelines can be combine.

>>> network = ...
>>> pipeline_a = Pipeline()
>>> pipeline_a.append('get_subgraph_by_annotation_value', 'Subgraph', 'Blood vessel dilation subgraph')
>>> pipeline_b = Pipeline()
>>> pipeline_b.append('get_subgraph_by_annotation_value', 'Subgraph', 'Tau protein subgraph')
>>> pipeline_c = Pipeline.union(pipeline_a, pipeline_b)
>>> result = pipeline_c.run(network)
class pybel_tools.pipeline.Pipeline(protocol=None, universe=None)[source]

Builds and runs analytical pipelines on BEL graphs

Parameters:
  • protocol (list[dict]) – The list of dictionaries describing how to mutate/filter a network
  • universe (pybel.BELGraph) – The entire set of known knowledge to draw from
has_function(name)[source]

Checks if a function is a valid pipeline function

Parameters:name (str) – The name of the function
Return type:bool
get_function(name)[source]

Wraps a function with the universe and in-place

Parameters:name (str) – The name of the function
Return type:types.FunctionType
append(name, *args, **kwargs)[source]

Adds a function and arguments to the pipeline

Parameters:
  • name (str) – The name of the function
  • args – The positional arguments to call in the function
  • kwargs – The keyword arguments to call in the function
Returns:

This pipeline for fluid query building

Return type:

Pipeline

extend(pipeline)[source]

Adds another pipeline to the end of the current pipeline

Parameters:pipeline (Pipeline) – Another pipeline
Returns:This pipeline for fluid query building
Return type:Pipeline
run(graph, universe=None, in_place=True)[source]

Runs the contained protocol on a seed graph

Parameters:
  • graph (pybel.BELGraph) – The seed BEL graph
  • universe (pybel.BELGraph) – Allows just-in-time setting of the universe in case it wasn’t set before. Defaults to the given network.
  • in_place (bool) – Should the graph be copied before applying the algorithm?
Returns:

The new graph is returned if not applied in-place

wrap_universe(f)[source]

Takes a function that needs a universe graph as the first argument and returns a wrapped one

static wrap_in_place(f)[source]

Takes a function that doesn’t return the graph and returns the graph

to_json()[source]

Gives this pipeline as json

Return type:list[dict]
to_jsons()[source]

Gives this pipeline as a JSON string

Return type:str
dump_json(file)[source]

Dumps this protocol to a file in JSON

static from_json(d)[source]

Loads a pipeline from a JSON object

Parameters:d (list[dict]) –
Returns:The pipeline represented by the JSON
Return type:Pipeline
static from_jsons(s)[source]

Loads a pipeline from the JSON in a string

Parameters:s (str) – A string containing the JSON representing a pipeline
Return type:Pipeline
static from_json_file(file)[source]

Loads a protocol from JSON contained in file using Pipeline.from_json().

Returns:The pipeline represented by the JSON in the file
Return type:Pipeline
static union(*pipelines)[source]

Takes the union of multiple pipelines

Returns:The union of the results from multiple pipelines
Return type:Pipeline
static intersection(*pipelines)[source]

Takes the intersection of the results from multiple pipelines

Returns:The intersection of results from multiple pipelines
Return type:Pipeline