Utils

Methods for various purposes.

class pathme.utils.CallCounted(method)[source]

Decorator to determine number of calls for a method.

Init method.

pathme.utils.parse_id_uri(uri: str) → Tuple[str, str, str, str][source]

Get the components of a given uri (with identifier at the last position).

Parameters

uri – URI

Returns

prefix (ex: http://rdf.wikipathways.org/…)

Returns

prefix_namespaces: if there are many namespaces, until the penultimate (ex: …/Pathway/WP22_r97775/…)

Returns

namespace: if there are many namespaces, the last (ex: …/Interaction/)

Returns

identifier (ex: …/c562c/)

pathme.utils.parse_namespace_uri(uri: str) → Tuple[str, str, str][source]

Get the prefix and namespace of a given URI (without identifier, only with a namspace at last position).

Parameters

uri – URI

Returns

prefix (ex: http://purl.org/dc/terms/…)

Returns

namespace (ex: …/isPartOf)

pathme.utils.parse_rdf(path: str, format: Optional[str] = None) → rdflib.graph.Graph[source]

Import a queried pathway into a rdflib Graph object.

Parameters
  • path – RDF file path

  • format – RDF file format, default is turtle

pathme.utils.entry_result_to_dict(entry, **kwargs)[source]

Export to a dictionary a SPARQL query result data structure.

Returns

entries_dict: Dictionary with all the entries id as keys and the entries arguments as values.

Return type

dict

pathme.utils.entries_dict_ids_argument(entries_dict)[source]

Add entries in dictionary.

pathme.utils.query_result_to_dict(entries, **kwargs) → Dict[str, Dict[str, Dict[str, str]]][source]

Export to a dictionary a SPARQL query result data structure.

Returns

entries_dict: Dictionary with all the entries id as keys and the entries arguments as values.

Return type

dict

pathme.utils.get_entry_statitics(types_list, primary_type=None, **kwargs)[source]

Get types statistics for a pathway entries type (nodes or interactions) set.

Parameters
  • rdf_graph (str) – primary entries type identifier (ex: DataNode or Interaction)

  • primary_type (str) – primary entries type identifier (ex: DataNode or Interaction)

pathme.utils.get_pathway_statitics(nodes_types, edges_types, bel_graph, **kwargs)[source]

Calculate pathway statistics.

pathme.utils.statistics_to_df(all_pathways_statistics)[source]

Build a data frame with graph statistics.

Parameters

all_pathways_statistics (dict) – pathway statistics

Return type

pandas.DataFrame

pathme.utils.get_bel_types(path: str)[source]

Get BEL node and edge type statistics.

Parameters

path – path to pickle

Returns

count of all nodes and edges in a BEL graph

Return type

dict

pathme.utils.get_bel_stats(resource_folder: str)[source]

Get all BEL node and edge type statistics.

Parameters

resource_folder – path to BEL pickles folder

Returns

count of all nodes and edges in all BEL graphs from one resource

Return type

dict

pathme.utils.get_genes_from_pickles(resource_folder: str, files: List[str], manager) → Dict[str, set][source]

Get BEL graph gene set for all pathways in resource.

Parameters
  • resource_folder – path to resource folder

  • files (list) – list of BEL graph pickles

  • Manager manager (bio2bel) – Manager

Returns

BEL graph gene sets for each pathway in resource

Return type

dict[str,set]

pathme.utils.get_kegg_genes_from_pickles(resource_folder, files: List[str], manager) → Dict[str, Set][source]

Get BEL graph gene set for all KEGG pathways.

Parameters
  • resource_folder (str) – path to resource folder

  • files (list) – list of BEL graph pickles

  • Manager manager (bio2bel) – Manager

Returns

BEL graph gene sets for each KEGG pathway

Return type

dict[str,set]

pathme.utils.get_genes_in_graph(graph: pybel.struct.graph.BELGraph) → Set[str][source]

Get BEL graph gene set for a pathway.

Parameters

graph – BEL Graph

Returns

BEL graph gene set

pathme.utils.jaccard_similarity(database_gene_set, bel_genes_set)[source]

Get Jaccard similarity for gene sets in database and BEL graphs.

Parameters
  • database_gene_set (dict) – gene sets for each pathway in database

  • bel_genes_set (dict) – gene sets for each BEL graph

Returns

similarity index

Return type

int

pathme.utils.make_downloader(url, path, export_path, decompress_file)[source]

Make a function that downloads the data for you, or uses a cached version at the given path.

Parameters
  • url (str) – The URL of some data

  • export_path (str) – folder where decompressed file will be exported

  • decompress_file (method) – method to decompress file

Returns

A function that downloads the data and returns the path of the data

Return type

(bool -> str)

pathme.utils.summarize_helper(graphs: Iterable[pybel.struct.graph.BELGraph])[source]

Print in console summary of graphs.

pathme.utils.add_bel_metadata(graph: pybel.struct.graph.BELGraph) → None[source]

Add namespaces and annotations to a given bel graph.