Pipeline¶
-
class
pybel.
Pipeline
(protocol=None)[source]¶ Build and runs analytical pipelines on BEL graphs.
Example usage:
>>> from pybel import BELGraph >>> from pybel.struct.pipeline import Pipeline >>> from pybel.struct.mutation import enrich_protein_and_rna_origins, prune_protein_rna_origins >>> graph = BELGraph() >>> example = Pipeline() >>> example.append(enrich_protein_and_rna_origins) >>> example.append(prune_protein_rna_origins) >>> result = example.run(graph)
Initialize the pipeline with an optional pre-defined protocol.
- Parameters
protocol (
Optional
[Iterable
[Dict
]]) – An iterable of dictionaries describing how to transform a network
-
static
from_functions
(functions)[source]¶ Build a pipeline from a list of functions.
- Parameters
functions (iter[((pybel.BELGraph) -> pybel.BELGraph) or ((pybel.BELGraph) -> None) or str]) – A list of functions or names of functions
Example with function:
>>> from pybel.struct.pipeline import Pipeline >>> from pybel.struct.mutation import remove_associations >>> pipeline = Pipeline.from_functions([remove_associations])
Equivalent example with function names:
>>> from pybel.struct.pipeline import Pipeline >>> pipeline = Pipeline.from_functions(['remove_associations'])
Lookup by name is possible for built in functions, and those that have been registered correctly using one of the four decorators:
pybel.struct.pipeline.transformation()
,pybel.struct.pipeline.in_place_transformation()
,pybel.struct.pipeline.uni_transformation()
,pybel.struct.pipeline.uni_in_place_transformation()
,
- Return type
Pipeline
-
append
(name, *args, **kwargs)[source]¶ Add a function (either as a reference, or by name) and arguments to the pipeline.
- Parameters
name (str or (pybel.BELGraph -> pybel.BELGraph)) – The name of the function
args – The positional arguments to call in the function
kwargs – The keyword arguments to call in the function
- Return type
Pipeline
- Returns
This pipeline for fluid query building
- Raises
MissingPipelineFunctionError – If the function is not registered
-
extend
(protocol)[source]¶ Add another pipeline to the end of the current pipeline.
- Parameters
protocol (
Union
[Iterable
[Dict
],Pipeline
]) – An iterable of dictionaries (or another Pipeline)- Return type
Pipeline
- Returns
This pipeline for fluid query building
Example: >>> p1 = Pipeline.from_functions([‘enrich_protein_and_rna_origins’]) >>> p2 = Pipeline.from_functions([‘remove_pathologies’]) >>> p1.extend(p2)
-
run
(graph, universe=None)[source]¶ Run 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.
- Returns
The new graph is returned if not applied in-place
- Return type
-
static
load
(file)[source]¶ Load a protocol from JSON contained in file.
- Return type
Pipeline
- Returns
The pipeline represented by the JSON in the file
- Raises
MissingPipelineFunctionError – If any functions are not registered
-
static
loads
(s)[source]¶ Load a protocol from a JSON string.
- Parameters
s (
str
) – A JSON string- Return type
Pipeline
- Returns
The pipeline represented by the JSON in the file
- Raises
MissingPipelineFunctionError – If any functions are not registered
Transformation Decorators¶
This module contains the functions for decorating transformation functions.
A transformation function takes in a pybel.BELGraph
and either returns None (in-place) or a new
pybel.BELGraph
(out-of-place).
-
pybel.struct.pipeline.decorators.
in_place_transformation
(func)¶ A decorator for functions that modify BEL graphs in-place
-
pybel.struct.pipeline.decorators.
uni_in_place_transformation
(func)¶ A decorator for functions that require a “universe” graph and modify BEL graphs in-place
-
pybel.struct.pipeline.decorators.
uni_transformation
(func)¶ A decorator for functions that require a “universe” graph and create new BEL graphs from old BEL graphs
-
pybel.struct.pipeline.decorators.
transformation
(func)¶ A decorator for functions that create new BEL graphs from old BEL graphs
-
pybel.struct.pipeline.decorators.
get_transformation
(name)[source]¶ Get a transformation function and error if its name is not registered.
- Parameters
name (
str
) – The name of a function to look up- Returns
A transformation function
- Raises
MissingPipelineFunctionError – If the given function name is not registered
Exceptions¶
Exceptions for the pybel.struct.pipeline
module.
-
exception
pybel.struct.pipeline.exc.
MissingPipelineFunctionError
[source]¶ Raised when trying to run the pipeline with a function that isn’t registered.
-
exception
pybel.struct.pipeline.exc.
MetaValueError
[source]¶ Raised when getting an invalid meta value.
-
exception
pybel.struct.pipeline.exc.
MissingUniverseError
[source]¶ Raised when running a universe function without a universe being present.