uniprot_id_mapping package

Submodules

uniprot_id_mapping.cache module

Cache management.

class uniprot_id_mapping.cache.CacheManager(cache_dir=None)[source]

Bases: object

Cache manager.

NAME = 'uniprot_id_mapping'[source]
__init__(cache_dir=None)[source]
Parameters:

cache_dir – An optional path to a cache directory. If None, the standard XDG path will be used.

property cache_dir[source]

The cache directory as a pathlib.Path object.

clear()[source]

Remove the cache directory.

get_path(subpath, is_dir=False)[source]

Get the full path to a subdirectory of the cache directory.

Parameters:
  • subpath – The subpath within the cache directory.

  • is_dir – If True, treat the subpath as a directory.

Returns:

The full path to the given subpath. The parent directory will be created if missing. If is_dir is True, so will the final path component.

uniprot_id_mapping.exception module

Custom exceptions.

exception uniprot_id_mapping.exception.UniprotIdMappingException[source]

Bases: Exception

Base exception class for custom exceptions raised by this package.

uniprot_id_mapping.id_mapper module

Map IDs via the UniProt ID mapping service: https://www.uniprot.org/help/id_mapping

class uniprot_id_mapping.id_mapper.IdMapper(cache_man: CacheManager = None, timeout: float = 10)[source]

Bases: object

Wrapper around the UniProt ID mapping service with local caching.

EMPTY_PLACEHOLDER = ''[source]
__init__(cache_man: CacheManager = None, timeout: float = 10)[source]
Parameters:
  • cache_man – A configured CacheManager instance.

  • timeout – Connection timeout for remote requests, in seconds.

property fields[source]

The available databases between which one can map IDs.

property local_database_path[source]

The path to the cached database.

map_ids(db_from, db_to, identifiers, refresh_missing=False)[source]

Map identifiers from one database to another.

Parameters:
  • db_from – The database from which to map the identifiers.

  • db_to – The database to which to map the identifiers.

  • identifiers – The identifiers in db_from that should be mapped to db_to.

  • refresh_missing – If True, check the server if previously missing values have been added since the last query.

Returns:

A dict mapping the found identifiers in db_from to identifiers in db_to.

Raises:

ValueError – Invalid arguments for db_from or db_to.

exception uniprot_id_mapping.id_mapper.IdMapperError[source]

Bases: UniprotIdMappingException

Custom exception raised by IdMapper.

uniprot_id_mapping.main module

Map IDs between databases using UniProt’s ID Mapping service.

uniprot_id_mapping.main.main(pargs)[source]

Main.

Parameters:

pargs – The parsed arguments.

uniprot_id_mapping.main.parse_args(args=None)[source]

Parse command-line arguments.

uniprot_id_mapping.main.run_main(args=None)[source]

Wrapper around main with exception handling.

Module contents

Package stub.

class uniprot_id_mapping.IdMapper(cache_man: CacheManager = None, timeout: float = 10)[source]

Bases: object

Wrapper around the UniProt ID mapping service with local caching.

EMPTY_PLACEHOLDER = ''[source]
__init__(cache_man: CacheManager = None, timeout: float = 10)[source]
Parameters:
  • cache_man – A configured CacheManager instance.

  • timeout – Connection timeout for remote requests, in seconds.

property fields[source]

The available databases between which one can map IDs.

property local_database_path[source]

The path to the cached database.

map_ids(db_from, db_to, identifiers, refresh_missing=False)[source]

Map identifiers from one database to another.

Parameters:
  • db_from – The database from which to map the identifiers.

  • db_to – The database to which to map the identifiers.

  • identifiers – The identifiers in db_from that should be mapped to db_to.

  • refresh_missing – If True, check the server if previously missing values have been added since the last query.

Returns:

A dict mapping the found identifiers in db_from to identifiers in db_to.

Raises:

ValueError – Invalid arguments for db_from or db_to.