Query Builder

A wrapper around the PyBEL query builder.

exception pybel_tools.query.QueryMissingNetworksError[source]

Raised if a query is created from json but doesn’t have a listing of network identifiers.

class pybel_tools.query.Query(network_ids=None, seeding=None, pipeline=None)[source]

Represents a query over a network store.

Build a query.

Parameters:network_ids (None or int or iter[int]) – Database network identifiers identifiers
append_network(network_id)[source]

Add a network to this query.

Parameters:network_id (int) – The database identifier of the network
Returns:self for fluid API
Return type:Query
append_seeding_induction(nodes)[source]

Add a seed induction method.

Parameters:or Node or BaseEntity] nodes (list[tuple) – A list of PyBEL node tuples
Returns:seeding container for fluid API
Return type:Seeding
append_seeding_neighbors(nodes)[source]

Add a seed by neighbors.

Parameters:nodes (BaseEntity or iter[BaseEntity]) – A list of PyBEL node tuples
append_seeding_annotation(annotation, values)[source]

Add a seed induction method for single annotation’s values.

Parameters:
  • annotation (str) – The annotation to filter by
  • values (set[str]) – The values of the annotation to keep
append_seeding_sample(**kwargs)[source]

Add seed induction methods.

Kwargs can have number_edges or number_seed_nodes.

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
Returns:This pipeline for fluid query building
Return type:Pipeline
run(manager)[source]

Run this query and returns the resulting BEL graph.

Parameters:manager – A cache manager
Return type:Optional[pybel.BELGraph]
to_json()[source]

Return this query as a JSON object.

Return type:dict
dump(file, **kwargs)[source]

Dump this query to a file as JSON.

dumps(**kwargs)[source]

Dump this query to a string as JSON

Return type:str
static from_json(data)[source]

Load a query from a JSON dictionary.

Parameters:data (dict) – A JSON dictionary
Return type:Query
Raises:QueryMissingNetworksError
static load(file)[source]

Load a query from a JSON file.

Parameters:file – A file or file-like
Return type:Query
Raises:QueryMissingNetworksError
static loads(s)[source]

Load a query from a JSON string

Parameters:s (str) – A stringified JSON query
Return type:Query
Raises:QueryMissingNetworksError