Query¶
Query builder for PyBEL.
-
exception
pybel.struct.query.
QueryMissingNetworksError
[source]¶ Raised if a query is created from json but doesn’t have a listing of network identifiers.
-
exception
pybel.struct.query.
NodeDegreeIterError
[source]¶ Raised when failing to iterate over node degrees.
-
class
pybel.struct.query.
Query
(network_ids=None, seeding=None, pipeline=None)[source]¶ Represents a query over a network store.
Build a query.
-
append_network
(network_id)[source]¶ Add a network to this query.
- Parameters
network_id (
int
) – The database identifier of the network- Return type
Query
- Returns
self for fluid API
-
append_seeding_induction
(nodes)[source]¶ Add a seed induction method.
- Return type
Seeding
- Returns
seeding container for fluid API
-
append_seeding_neighbors
(nodes)[source]¶ Add a seed by neighbors.
- Return type
Seeding
- Returns
seeding container for fluid API
-
append_seeding_annotation
(annotation, values)[source]¶ Add a seed induction method for single annotation’s values.
-
append_seeding_sample
(**kwargs)[source]¶ Add seed induction methods.
Kwargs can have
number_edges
ornumber_seed_nodes
.- Return type
Seeding
-
append_pipeline
(name, *args, **kwargs)[source]¶ Add an entry to the pipeline. Defers to
pybel_tools.pipeline.Pipeline.append()
.- Parameters
name (str or types.FunctionType) – The name of the function
- Return type
Pipeline
- Returns
This pipeline for fluid query building
-
run
(manager)[source]¶ Run this query and returns the resulting BEL graph.
- Parameters
manager – A cache manager
- Return type
Optional[pybel.BELGraph]
-
static
from_json
(data)[source]¶ Load a query from a JSON dictionary.
- Parameters
data (
Mapping
) – A JSON dictionary- Raises
QueryMissingNetworksError
- Return type
Query
-
-
class
pybel.struct.query.
Seeding
(initlist=None)[source]¶ Represents a container of seeding methods to apply to a network.
-
append_annotation
(annotation, values)[source]¶ Add a seed induction method for single annotation’s values.
-
append_sample
(**kwargs)[source]¶ Add seed induction methods.
Kwargs can have
number_edges
ornumber_seed_nodes
.- Return type
Seeding
- Returns
self for fluid API
-
run
(graph)[source]¶ Seed the graph or return none if not possible.
- Return type
Optional[pybel.BELGraph]
-
-
pybel.struct.query.
get_subgraph
(graph, seed_method=None, seed_data=None, expand_nodes=None, remove_nodes=None)[source]¶ Run a pipeline query on graph with multiple sub-graph filters and expanders.
Order of Operations:
Seeding by given function name and data
Add nodes
Remove nodes
- Parameters
graph (pybel.BELGraph) – A BEL graph
seed_method (
Optional
[str
]) – The name of the get_subgraph_by_* function to useseed_data (
Optional
[Any
]) – The argument to pass to the get_subgraph functionexpand_nodes (
Optional
[List
[BaseEntity
]]) – Add the neighborhoods around all of these nodesremove_nodes (
Optional
[List
[BaseEntity
]]) – Remove these nodes and all of their in/out edges
- Return type
Optional[pybel.BELGraph]