Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/ga4gh/vrs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,10 @@ def _recurse_ga4gh_serialize(obj):
if isinstance(obj, RootModel):
return _recurse_ga4gh_serialize(obj.model_dump())
if isinstance(obj, str):
return obj
# A referable attribute set to a plain GA4GH CURIE (as ga4gh_enref does)
# serializes to its digest, the same as an iriReference or inlined object.
m = GA4GH_IR_REGEXP.match(obj)
return m["digest"] if m else obj
if isinstance(obj, list):
return [_recurse_ga4gh_serialize(x) for x in obj]
return obj
Expand Down
35 changes: 31 additions & 4 deletions tests/test_vrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ def test_enref2():
object_store = {}
a = {
"type": "Allele",
"id": "ga4gh:VA.LDzK5JahEZG2Ua_5itDtVV8v3O1ptTgI",
"digest": "LDzK5JahEZG2Ua_5itDtVV8v3O1ptTgI",
"id": "ga4gh:VA.0AePZIWZUNsUlQTamyLrjm2HWUw2opLt",
"digest": "0AePZIWZUNsUlQTamyLrjm2HWUw2opLt",
"location": {
"id": "ga4gh:SL.wIlaGykfwHIpPY2Fcxtbx4TINbbODFVz",
"digest": "wIlaGykfwHIpPY2Fcxtbx4TINbbODFVz",
Expand All @@ -273,14 +273,41 @@ def test_enref2():
)
assert a_enreffed.location == "ga4gh:SL.wIlaGykfwHIpPY2Fcxtbx4TINbbODFVz"
assert a_enreffed.model_dump(exclude_none=True) == {
"id": "ga4gh:VA.LDzK5JahEZG2Ua_5itDtVV8v3O1ptTgI",
"digest": "LDzK5JahEZG2Ua_5itDtVV8v3O1ptTgI",
"id": "ga4gh:VA.0AePZIWZUNsUlQTamyLrjm2HWUw2opLt",
"digest": "0AePZIWZUNsUlQTamyLrjm2HWUw2opLt",
"type": "Allele",
"location": "ga4gh:SL.wIlaGykfwHIpPY2Fcxtbx4TINbbODFVz",
"state": {"type": "LiteralSequenceExpression", "sequence": "T"},
}


def test_enref_without_precomputed_ids():
"""Enref must not change the identifier of an object whose ids are not set yet"""
allele_dict = {
"type": "Allele",
"location": {
"type": "SequenceLocation",
"sequenceReference": {
"type": "SequenceReference",
"refgetAccession": "SQ.IIB53T8CNeJJdUqzn9V_JnRtQadwWCbl",
},
"start": 44908821,
"end": 44908822,
},
"state": {"type": "LiteralSequenceExpression", "sequence": "T"},
}
expected_id = ga4gh_identify(models.Allele(**allele_dict), in_place="never")

object_store = {}
enreffed = vrs_enref(models.Allele(**allele_dict), object_store=object_store)
assert enreffed.location == "ga4gh:SL.wIlaGykfwHIpPY2Fcxtbx4TINbbODFVz"
assert enreffed.id == expected_id

dereffed = vrs_deref(enreffed, object_store=object_store)
assert dereffed.id == expected_id
assert dereffed.location.id == "ga4gh:SL.wIlaGykfwHIpPY2Fcxtbx4TINbbODFVz"


def test_class_refatt_map():
class_refatt_map_expected = {
"Allele": ["location"],
Expand Down