anyvar.anyvar

full-service interface to converting, validating, and registering biological sequence variation

class anyvar.anyvar.AnyVar(translator, object_store)[source]

Define core AnyVar class.

__init__(translator, object_store)[source]

Initialize anyvar instance. It’s easiest to use factory methods to create translator and object_store instances but manual construction works too.

Parameters:
  • translator (Translator) – Translator instance

  • object_store (Storage) – Object storage instance

create_timestamp_if_missing(object_id)[source]

Store a ‘creation_timestamp’ extension if missing for an object

Parameters:

object_id (str) – The ID of the object to create a timestamp extension for

Return type:

int | None

Returns:

ID of newly created extension. If timestamp extension exists, will return None.

delete_object(object_id)[source]

Delete an object and associated mappings/extensions by ID

Doesn’t delete wrapped objects (e.g. deleting a variant won’t delete the associated location)

Parameters:

object_id (str) – ID of object to delete

Raises:

ObjectNotFoundError – if no stored object matches given ID

Return type:

None

get_object(object_id, object_type=None)[source]

Retrieve registered VRS Object.

Parameters:
  • object_id (str) – object identifier

  • object_type (type[Allele | SequenceLocation | SequenceReference] | None) – specific object type to search (optional - if not provided, searches all types)

Return type:

Allele | SequenceLocation | SequenceReference

Returns:

VRS object if found.

Raises:

KeyError if identifier is not found

get_object_extensions(object_id, extension_name=None)[source]

Get all extensions for the specified object, optionally filtered by type.

Parameters:
  • object_id (str) – The ID of the object to retrieve extensions for

  • extension_type – The type of extension to retrieve (defaults to None to retrieve all extensions for the object)

Return type:

list[Extension]

Returns:

A list of extensions

Raises:

ObjectNotFoundError – if object_id can’t be found in DB

get_object_mappings(object_id, mapping_type, as_source=True)[source]

Get all variation mappings given source object ID and mapping type

Parameters:
  • object_id (str) – ID of the source object

  • mapping_type (VariationMappingType) – kind of mapping to retrieve

  • as_source (bool) – whether to retrieve mappings where object_id is the source of the mapping, or the destination

Return type:

Iterable[VariationMapping]

Returns:

iterable collection of mapping objects

Raises:

ObjectNotFoundError – if source_object_id can’t be found in DB

put_extension(extension)[source]

Attempt to store an extension.

Parameters:

extension (Extension) – an Extension object

Return type:

int | None

Returns:

extension ID if successful, None otherwise

put_mapping(mapping)[source]

Attempt to store a mapping between two objects

Parameters:

mapping (VariationMapping) – a Mapping object

Return type:

None

put_objects(variation_objects)[source]

Attempt to register variation objects

The provided list may contain any supported variation object – i.e. not just Alleles or molecular variations – and is not required to contain only one kind of object.

Parameters:

variation_objects (list[Allele | SequenceLocation | SequenceReference]) – list of complete variation objects (i.e. VRS-Python models)

Return type:

None

exception anyvar.anyvar.ObjectNotFoundError[source]

Raised when an ID is given for a non-existent object.

anyvar.anyvar.create_storage(uri=None)[source]

Provide factory to create storage based on uri or the ANYVAR_STORAGE_URI environment value.

The URI format is as follows:

  • PostgreSQL: postgresql://[username]:[password]@[domain]/[database]

  • Snowflake: snowflake://sf_username:@sf_account_identifier/sf_db_name/sf_schema_name?password=sf_password

For no database (for testing or non-persistent use cases), use an empty string.

Parameters:

uri (str | None) – storage URI

Return type:

Storage

anyvar.anyvar.create_translator()[source]

Create variation translator middleware.

Try to build the VRS-Python wrapper class with default args. In the future, could provide assistance constructing other kinds of translators.

Note that the default factory utilized by the VRS-Python translator that is called here can be configured with the SEQREPO_DATAPROXY_URI environment variable, with values like the following:

  • seqrepo+file:///path/to/seqrepo/root

  • seqrepo+:../relative/path/to/seqrepo/root

  • seqrepo+http://localhost:5000/seqrepo

  • seqrepo+https://somewhere:5000/seqrepo

Return type:

Translator

Returns:

instantiated Translator instance

anyvar.anyvar.has_queueing_enabled()[source]

Determine whether or not asynchronous task queueing is enabled

Return type:

bool