anyvar.anyvar

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

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

Define core AnyVar class.

__init__(translator, object_store, projector=None)[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

  • projector (VariantProjectorProtocol | None) – Optional VariantProjector instance for variant projection

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

delete_object_extensions(object_id, extension_name=None)[source]

Delete extensions

  • If no extension_name is given, delete all associated extensions.

  • Delete all instances of extensions by the given name

Parameters:
  • object_id (str) – object ID to delete extensions for

  • extension_name (str | None) – optionally, the name of extensions to delete

Raises:

ObjectNotFoundError – if object_id can’t be found in DB

Return type:

None

get_ca_catvar(catvar_id)[source]

Fetch a Canonical Allele catvar by ID

Return type:

CanonicalAllele | 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=None, 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 | None) – 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

get_psq_catvar(catvar_id)[source]

Fetch a ProteinSequenceConsequence catvar by ID

Return type:

ProteinSequenceConsequence | None

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

register_ca_catvar(catvar)[source]

Register a Canonical Allele Categorical Variant

Beyond the data structure validation performed by the catvar pydantic model, this function also validates that the defining allele must be on a genomic sequence

Following successful validation, the catvar is stored for future reference.

Parameters:

catvar (CanonicalAllele) – user-supplied catvar

Raises:

InvalidCategoricalVariantError – if the molecule type for the defining allele can’t be validated as genomic

Return type:

None

register_psq_catvar(catvar)[source]

Register a Protein Sequence Consequence Categorical Variant

Beyond the data structure validation performed by the catvar pydantic model, this function also validates that the defining allele must be on a protein sequence

Following successful validation, the catvar is stored for future reference.

Parameters:

catvar (ProteinSequenceConsequence) – user-supplied catvar

Raises:

InvalidCategoricalVariantError – if the molecule type for the defining allele can’t be validated as protein

Return type:

None

exception anyvar.anyvar.InvalidCategoricalVariantError[source]

Raise when a provided categorical variant has invalid or missing required fields

exception anyvar.anyvar.ObjectNotFoundError[source]

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

class anyvar.anyvar.VariantProjectorProtocol(*args, **kwargs)[source]

Protocol for variant projection across the central dogma.

__init__(*args, **kwargs)[source]
add_projections(variation, storage)[source]
Return type:

None

anyvar.anyvar.create_projector(translator)[source]

Create a VariantProjector if projection is enabled and cool-seq-tool is installed.

Projection is enabled when: - ANYVAR_ENABLE_PROJECTION env var is set to true - cool-seq-tool package is installed

Parameters:

translator (Translator) – Translator instance (provides the SeqRepo DataProxy)

Returns:

VariantProjector instance, or None if not available/enabled

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]

  • DuckDB: duckdb:///:memory:` or ``duckdb:///relative/path/to/file

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

anyvar.anyvar.has_variations_queueing_enabled()[source]

Determine whether or not asynchronous task queueing is enabled for variations

Return type:

bool