GA4GH VRS and VRSATILE Pydantic Models
raw JSON → 0.2.0 verified Sat May 09 auth: no python
Provides Pydantic data models for the GA4GH Variation Representation Specification (VRS) and VRSATILE schemas. Currently at v0.2.0, this library transitioned from Pydantic v1 to v2 in a major breaking change. Active development with experimental pre-releases.
pip install ga4gh-vrsatile-pydantic Common errors
error ga4gh.vrsatile.pydantic doesn't exist ↓
cause Version mismatch: code assumes Pydantic v1 import path (pre-0.2.0) or uses wrong submodule.
fix
Install ga4gh-vrsatile-pydantic>=0.2.0 and ensure imports are from ga4gh.vrsatile.pydantic.
error AttributeError: 'Allele' object has no attribute 'dict' ↓
cause Code written for Pydantic v1 (.dict()) but using v0.2.0 which uses Pydantic v2 (.model_dump()).
fix
Replace .dict() with .model_dump() and .json() with .model_dump_json().
Warnings
breaking v0.2.0 migrated from Pydantic v1 to v2. All .dict() calls must be replaced with .model_dump(), and .json() with .model_dump_json(). ↓
fix Replace all .dict() with .model_dump() and .json() with .model_dump_json() in your code.
deprecated v0.1.0-dev releases (pre-release) used Pydantic v1. These are not compatible with v0.2.0. Avoid using dev versions in production. ↓
fix Upgrade to v0.2.0 and migrate code to Pydantic v2 syntax.
gotcha The import path changed after v0.2.0. Models were previously under ga4gh.vrsatile.models but now under ga4gh.vrsatile.pydantic. ↓
fix Update imports: from ga4gh.vrsatile.pydantic import Allele (instead of from ga4gh.vrsatile.models import Allele).
Imports
- Allele wrong
from ga4gh.vrsatile.models import Allelecorrectfrom ga4gh.vrsatile.pydantic import Allele - CopyNumberChange wrong
from ga4gh.vrsatile.pydantic.vrsatile_models import CopyNumberChangecorrectfrom ga4gh.vrsatile.pydantic import CopyNumberChange
Quickstart
from ga4gh.vrsatile.pydantic import Allele, CopyNumberChange
# Example: creating an Allele
allele = Allele(
type="Allele",
location={
"type": "SequenceLocation",
"sequence_id": "ga4gh:SQ._0wi-qoPhFdH",
"interval": {
"type": "SequenceInterval",
"start": {"type": "Number", "value": 55181320},
"end": {"type": "Number", "value": 55181321}
}
},
state={
"type": "LiteralSequenceExpression",
"sequence": "A"
}
)
# Validate
print(allele.model_dump_json(exclude_none=True))