IO Utilities

Utilities for loading and exporting BEL graphs

pybel_tools.ioutils.get_paths_recursive(directory, extension='.bel', exclude_directory_pattern=None)[source]

Gets all file paths in a given directory to BEL documents

Parameters:
  • directory (str) – The base directory to walk
  • extension (str) – Extensions of files to keep
  • exclude_directory_pattern (str) – Any directory names to exclude
pybel_tools.ioutils.convert_paths(paths, connection=None, upload=False, canonicalize=True, infer_central_dogma=True, enrich_citations=False, send=False, **kwargs)[source]

Recursively parses and either uploads/pickles graphs in a given set of files

Parameters:
  • paths (iter[str]) – The paths to convert
  • connection (None or str or pybel.manager.Manager) – The connection
  • upload (bool) – Should the networks be uploaded to the cache?
  • canonicalize (bool) – Calculate canonical nodes?
  • infer_central_dogma (bool) – Should the central dogma be inferred for all proteins, RNAs, and miRNAs
  • enrich_citations (bool) – Should the citations be enriched using Entrez Utils?
  • send (bool) – Send to PyBEL Web?
  • kwargs – Parameters to pass to pybel.from_path()
Returns:

A pair of a dictionary {path: bel graph} and list of failed paths

Return type:

tuple[dict[str,pybel.BELGraph],list[str]]

pybel_tools.ioutils.convert_directory(directory, connection=None, upload=False, pickle=False, canonicalize=True, infer_central_dogma=True, enrich_citations=False, enrich_genes=False, enrich_go=False, send=False, exclude_directory_pattern=None, version_in_path=False, **kwargs)[source]

Recursively parses and either uploads/pickles graphs in a given directory and sub-directories

Parameters:
  • directory (str) – The directory to look through
  • connection (None or str or pybel.manager.Manage.) – The connection
  • upload (bool) – Should the networks be uploaded to the cache?
  • pickle (bool) – Should the networks be saved as pickles?
  • infer_central_dogma (bool) – Should the central dogma be inferred for all proteins, RNAs, and miRNAs
  • enrich_citations (bool) – Should the citations be enriched using Entrez Utils?
  • enrich_genes (bool) – Should the genes’ descriptions be downloaded from Gene Cards?
  • enrich_go (bool) – Should the biological processes’ descriptions be downloaded from Gene Ontology?
  • send (bool) – Send to PyBEL Web?
  • exclude_directory_pattern (str) – A pattern to use to skip directories
  • version_in_path (bool) – Add the current pybel version to the pathname
  • kwargs – Parameters to pass to pybel.from_path()
pybel_tools.ioutils.upload_recursive(directory, connection=None, exclude_directory_pattern=None)[source]

Recursively uploads all gpickles in a given directory and sub-directories

Parameters:
  • directory (str) – the directory to traverse
  • connection (Optional[str or pybel.manage.Manager]) – A connection string or manager
  • exclude_directory_pattern (Optional[str]) – Any directory names to exclude
pybel_tools.ioutils.subgraphs_to_pickles(network, annotation, directory=None)[source]

Groups the given graph into subgraphs by the given annotation with get_subgraph_by_annotation() and outputs them as gpickle files to the given directory with pybel.to_pickle()

Parameters:
  • network (pybel.BELGraph) – A BEL network
  • annotation (str) – An annotation to split by. Suggestion: Subgraph
  • directory (Optional[str]) – A directory to output the pickles