Utilities

Utilities for Bio2BEL.

bio2bel.utils.get_data_dir(module_name)[source]

Ensure the appropriate Bio2BEL data directory exists for the given module, then returns the file path.

Parameters

module_name (str) – The name of the module. Ex: ‘chembl’

Return type

str

Returns

The module’s data directory

bio2bel.utils.prefix_directory_join(prefix, *parts)[source]

Join the parts onto the prefix directory.

Return type

str

bio2bel.utils.get_url_filename(url)[source]

Get the URL’s file name.

Return type

str

bio2bel.utils.ensure_path(prefix, url, path=None)[source]

Download a file if it doesn’t exist.

Return type

str

bio2bel.utils.get_connection(module_name, connection=None)[source]

Return the SQLAlchemy connection string if it is set.

Order of operations:

  1. Return the connection if given as a parameter

  2. Check the environment for BIO2BEL_{module_name}_CONNECTION

  3. Look in the bio2bel config file for module-specific connection. Create if doesn’t exist. Check the module-specific section for connection

  4. Look in the bio2bel module folder for a config file. Don’t create if doesn’t exist. Check the default section for connection

  5. Check the environment for BIO2BEL_CONNECTION

  6. Check the bio2bel config file for default

  7. Fall back to standard default cache connection

Parameters
  • module_name (str) – The name of the module to get the configuration for

  • connection (Optional[str]) – get the SQLAlchemy connection string

Return type

str

Returns

The SQLAlchemy connection string based on the configuration

bio2bel.utils.get_bio2bel_modules()[source]

Get all Bio2BEL modules.

Return type

Mapping[str, module]

bio2bel.utils.clear_cache(module_name, keep_database=True)[source]

Clear all downloaded files.

Return type

None