Skip to content
Merged
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
22 changes: 12 additions & 10 deletions src/ga4gh/core/enderef.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def ga4gh_enref(o, cra_map, object_store=None, return_id_obj_tuple=False) -> tup
"""Recursively convert "referable attributes" from inlined to
referenced form. Returns a new object.

cra_map: class referrable-attribute map; { o.type: [attr, attr, ...] }

If `object_store` is provided, it must be an
collections.abc.MutableMapping subclass and will be used to store
objects as they are referenced. If `object_store` is not provided
(or None), referenced objects will not be stored.

:param o: VRS object
:param cra_map: class referrable-attribute map; { o.type: [attr, attr, ...] }
:param object_store: `collections.abc.MutableMapping` subclass that stores
objects as they are referenced. If not given, referenced objects are not stored.
:param return_id_obj_tuple: include ID with return value or not
:return: new, enref'd object, as well as object ID if param set
:raise TypeError: if any object IDs are non-GA4GH CURIEs
"""

def _id_and_store(o): # noqa: ANN202 ANN001
Expand All @@ -51,9 +51,11 @@ def _enref(o): # noqa: ANN202 ANN001
elif isinstance(v, str):
pass
elif is_curie_type(v): # already a reference
assert is_ga4gh_identifier(v), ( # noqa: S101
"Identifiable attribute CURIE is contains an invalid identifier"
)
if not is_ga4gh_identifier(v):
msg = (
"Identifiable attribute CURIE is contains an invalid identifier"
)
raise TypeError(msg)
elif v is not None:
_id = _id_and_store(v)
if _id:
Expand Down
6 changes: 5 additions & 1 deletion src/ga4gh/vrs/dataproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,13 @@ def _isoformat(o: datetime.datetime) -> str:
>>> _isoformat(dt)
'2019-10-15T10:23:41.115927Z'

:param o: date object to format
:return: ISO8601-formatted string equivalent
:raise TypeError: if object given isn't a Python datetime instance
"""
# stolen from connexion flask_app.py
assert isinstance(o, datetime.datetime) # noqa: S101
if not isinstance(o, datetime.datetime):
raise TypeError
if o.tzinfo:
# eg: '2015-09-25T23:14:42.588601+00:00'
return o.isoformat("T")
Expand Down
13 changes: 9 additions & 4 deletions src/ga4gh/vrs/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,16 @@ def _normalize_cis_phased_block(o, data_proxy: _DataProxy | None = None): # noq
def normalize(vo, data_proxy: _DataProxy | None = None, **kwargs):
"""Normalize given vrs object, regardless of type

kwargs:
rle_seq_limit: If RLE is set as the new state, set the limit for the length
of the `sequence`. To exclude `state.sequence`, set to 0.
:param vo:
:param data_proxy: GA4GH sequence dataproxy instance, if needed
:keyword rle_seq_limit: If RLE is set as the new state, set the limit for the length
of the `sequence`. To exclude `state.sequence`, set to 0.
:return: normalized object
:raise TypeError: if given object isn't a pydantic.BaseModel
"""
assert is_pydantic_instance(vo) # noqa: S101
if not is_pydantic_instance(vo):
msg = f"Object is of class {vo.__class__} (with parents {vo.__class__.__mro__}), but normalize requires objects that inherit from pydantic.BaseModel."
raise TypeError(msg)
vo_type = vo.type

if vo_type in handlers:
Expand Down
Loading