Database Service

class pybel_tools.api.DatabaseService(manager, autocache=False)[source]

The dictionary service contains functions that implement the PyBEL API with a in-memory backend using dictionaries.

Parameters:manager (pybel.manager.Manager) – A cache manager
networks = None

dictionary of {int id: BELGraph graph}

node_nid = None

dictionary of {tuple node: int id}

nid_node = None

dictionary of {int id: tuple node}

bel_id = None

dictionary of {str BEL: int id}

universe = None

The complete graph of all knowledge stored in the cache

node_degrees = None

A dictionary from {int id: {tuple node: int degree}}

overlap_cache = None

A dictionary from {int network_id: {int network_id: float tanimoto node overlap}}

relabel_nodes_to_identifiers(graph, copy=True)[source]

Relabels all nodes by their identifiers, in place. This function is a thin wrapper around networkx.relabel.relabel_nodes() with the module level variable node_nid used as the mapping.

Parameters:
Return type:

pybel.BELGraph

cache_networks(force_reload=False, eager=False, maintain_universe=True)[source]

This function needs to get all networks from the graph cache manager and make a dictionary

Parameters:
  • force_reload (bool) – Should all graphs be reloaded even if they have already been cached?
  • eager (bool) – Should difficult to preload features be calculated?
get_graph_by_id(network_id=None)[source]

Gets a network by its ID or super network if identifier is not specified

Parameters:network_id (int) – The internal ID of the network to get
Returns:A BEL Graph
Return type:pybel.BELGraph
get_graphs_by_ids(network_ids)[source]

Gets a list of networks given the ids

Parameters:network_ids (list[int]) – A list of network identifiers
Return type:list[pybel.BELGraph]
get_graph_by_ids(network_ids)[source]

Gets a networks by a list of database identifiers

Parameters:network_ids (list[int]) – A list of network identifiers
Return type:pybel.BELGraph
get_node_hash(node)[source]

Gets the hashes of the PyBEL node tuple

Parameters:node (tuple) – A PyBEL node tuple
get_node_hashes(node_tuples)[source]

Converts a list of BEL nodes to their node identifiers

Parameters:node_tuples (list[tuple]) – A list of PyBEL node tuples
Return type:list
get_node_tuple_by_hash(node_hash)[source]

Returns the node tuple based on the node id

Parameters:node_hash – The node’s identifier
Returns:A PyBEL node tuple
Return type:tuple
get_nodes_by_hashes(node_hashes)[source]

Gets a list of node tuples from a list of ids

Parameters:node_hashes (list) – A list of node identifiers
Return type:list[tuple]
paths_tuples_to_ids(paths)[source]

List of lists of node tuples

Parameters:paths (list[list[tuple]]) – list of lists (tuples)
Return type:list[list[tuple]]: list of lists (ids)
get_nodes_containing_keyword(keyword)[source]

Gets a list with all cnames that contain a certain keyword adding to the duplicates their function

Parameters:keyword (str) – Search for nodes whose cnames have this as a substring
Return type:list[dict]
get_pubmed_containing_keyword(keyword)[source]

Gets a list of PubMed identifiers that contain a certain keyword

Parameters:keyword (str) – Search for PubMed identifiers who have this as a substring
Return type:list[str]
get_authors_containing_keyword(keyword)[source]

Gets a list with authors that contain a certain keyword

Parameters:keyword (str) – Search for authors whose names have this as a substring
Return type:list[str]
get_cname_by_node_hash(node_hash)[source]

Gets the canonical name of a node

Parameters:node_hash – A BEL node identifier
Return type:str
get_cname(node)[source]

Gets the canonical name of a node

Parameters:node (tuple) – A BEL node
Return type:str
get_top_degree(network_id, count=20)[source]

Gets the nodes with the highest degrees

Parameters:
  • network_id (int) – The network database identifier
  • count (int) – The number of top degree nodes to get
Return type:

dict[str,int]

get_top_pathologies[source]

Gets the top most frequent pathologies mentioned in a graph

Parameters:
  • network_id (int) – The network database identifier
  • count (int) – The number of most frequently mentioned pathologies to get
Return type:

dict[str,int]

get_tree_annotations[source]

Gets tree annotations for the given graph

Parameters:graph (pybel.BELGraph) – A BEL Graph
Returns:Annotations for the given graph
Return type:list[dict]
get_node_overlap(network_id)[source]

Calculates overlaps to all other networks in the database

Parameters:network_id (int) – The network database identifier
Returns:A dictionary from {int network_id: float similarity} for this network to all other networks
Return type:collections.Counter[int, float]
get_annotations_containing_keyword(keyword)[source]

Gets annotation/value pairs for values for whom the search string is a substring

Parameters:keyword (str) – Search for annotations whose values have this as a substring
Return type:list[dict[str,str]
forget_network(network_id)[source]

Removes all cached data from the given network id