anyvar.storage.orm

SQLAlchemy ORM models for AnyVar database schema.

class anyvar.storage.orm.Allele(**kwargs)[source]

AnyVar ORM model for Alleles

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

get_disassembler()[source]

Recursively disassemble to yield self + constituent Location and SequenceReference objects

Return type:

Iterator[Base]

id: Mapped[str][source]
location: Mapped[Location][source]
location_id: Mapped[str][source]
state: Mapped[dict][source]
class anyvar.storage.orm.Base(**kwargs)[source]

Base class for all AnyVar ORM models.

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

disassemble()[source]

Returns a dict containing this entity + all of its constituent ORM objects, keyed by type. If there are no constituent ORM objects, dict will just contain a single entry referring to this entity.

Example: >>> sequence_reference = orm.SequenceReference( … id=”SQ.Ya6Rs7DHhDeg7YaOSg1EoNi3U_nQ9SvO”, … # etc… … ) >>> location = orm.Location( … id=”ga4gh:SL.U8b3eMCw6QjGA9cnDx_KYxqbol0UrEKx”, … sequence_reference_id=sequence_reference.id, … sequence_reference=sequence_reference, … # etc… … ) >>> allele = orm.Allele( … id=”ga4gh:VA.uR23Z7AAFaLHhPUymUEYNG4o2CCE560T”, … location_id=location.id, … location=location, … # etc… … ) >>> disassembled_allele = allele.disassemble() >>> print(disassembled_allele) {‘Allele’: <anyvar.storage.orm.Allele object at 0x108dfa780>, ‘Location’: <anyvar.storage.orm.Location object at 0x101416db0>, ‘SequenceReference’: <anyvar.storage.orm.SequenceReference object at 0x100af5250>}

Return type:

dict[str, Base]

get_disassembler()[source]

Yields an Iterator that recursively disassembles this entity into itself + its constituent ORM objects. Will simply yield self if object contains no other entities.

Return type:

Iterator[Base]

Returns:

An Iterator yielding this entity + its constituent ORM objects

registry: ClassVar[_RegistryType] = <sqlalchemy.orm.decl_api.registry object>[source]

Refers to the _orm.registry in use where new _orm.Mapper objects will be associated.

to_dict()[source]

Convert the model fields to a dictionary (non-recursive).

Return type:

dict

class anyvar.storage.orm.CanonicalAllele(**kwargs)[source]

AnyVar ORM model for canonical allele variants

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

allele: Mapped[Allele][source]
allele_id: Mapped[str][source]
id: Mapped[str][source]
name: Mapped[str][source]
class anyvar.storage.orm.Extension(**kwargs)[source]

AnyVar ORM model for extensions table.

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

id: Mapped[int][source]
name: Mapped[str][source]
object_id: Mapped[str][source]
value: Mapped[dict][source]
class anyvar.storage.orm.Location(**kwargs)[source]

AnyVar ORM model for Locations

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

end: Mapped[int | None][source]
end_inner: Mapped[int | None][source]
end_outer: Mapped[int | None][source]
get_disassembler()[source]

Recursively disassemble to yield self + constituent SequenceReference object

Return type:

Iterator[Base]

id: Mapped[str][source]
sequence_reference: Mapped[SequenceReference][source]
sequence_reference_id: Mapped[str][source]
start: Mapped[int | None][source]
start_inner: Mapped[int | None][source]
start_outer: Mapped[int | None][source]
class anyvar.storage.orm.ProteinSequenceConsequence(**kwargs)[source]

AnyVar ORM model for canonical allele variants

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

allele: Mapped[Allele][source]
allele_id: Mapped[str][source]
id: Mapped[str][source]
name: Mapped[str][source]
class anyvar.storage.orm.SequenceReference(**kwargs)[source]

AnyVar ORM model for SequenceReferences

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

id: Mapped[str][source]
molecule_type: Mapped[MoleculeType | None][source]
class anyvar.storage.orm.VariationMapping(**kwargs)[source]

AnyVar ORM model for variation-to-variation mapping

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

dest_id: Mapped[str][source]
mapping_type: Mapped[str][source]
source_id: Mapped[str][source]
class anyvar.storage.orm.VrsObject(**kwargs)[source]

AnyVar ORM model for vrs_objects table.

__init__(**kwargs)[source]

A simple constructor that allows initialization from kwargs.

Sets attributes on the constructed instance using the names and values in kwargs.

Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.

id: Mapped[str][source]
vrs_object: Mapped[dict][source]
anyvar.storage.orm.create_tables(db_url)[source]

Create all tables in the database.

Parameters:

db_url (str) – Database connection URL (e.g., postgresql://user:pass@host:port/db)

Return type:

None

anyvar.storage.orm.session_factory(db_url)[source]

Create a SQLAlchemy session factory.

Returns a sessionmaker factory that should be used to create sessions. Follows SQLAlchemy 2.0 recommended semantics where the session lifecycle is managed externally using context managers.

Example usage:

>>> sf = session_factory(db_url)
>>> with sf() as session:
...     with session.begin():  # Perform database operations
...         session.add(some_object)
...         session.execute(some_query)
>>> # Transaction from session.begin() automatically commits if no exceptions occur
>>> # Session automatically closes

See: https://docs.sqlalchemy.org/en/20/orm/session_basics.html#using-a-sessionmaker

Parameters:

db_url (str) – Database connection URL (e.g., postgresql://user:pass@host:port/db)

Return type:

sessionmaker

Returns:

SQLAlchemy sessionmaker factory