Skip to content

Commit

Permalink
addresses #338 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahwagner committed Feb 4, 2024
1 parent 593edde commit b5c4c1d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/ga4gh/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
parse_ga4gh_identifier, GA4GHComputeIdentifierWhen, use_ga4gh_compute_identifier_when
)
from ._internal.pydantic import (
is_pydantic_instance, is_curie_type, is_identifiable, is_literal, pydantic_copy
is_pydantic_instance, is_curie_type, is_ga4gh_identifiable, is_literal, pydantic_copy
)
from ._internal import models as core_models

Expand Down
6 changes: 3 additions & 3 deletions src/ga4gh/core/_internal/enderef.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
is_pydantic_instance,
is_list,
is_curie_type,
is_identifiable,
is_ga4gh_identifiable,
get_pydantic_root,
pydantic_copy)

Expand Down Expand Up @@ -60,7 +60,7 @@ def _enref(o):

if not is_pydantic_instance(o):
raise ValueError("Called ga4gh_enref() with non-pydantic instance")
if not is_identifiable(o):
if not is_ga4gh_identifiable(o):
raise ValueError("Called ga4gh_enref() with non-identifiable object")

# in-place replacement on object copy
Expand Down Expand Up @@ -101,7 +101,7 @@ def _deref(o):

if not is_pydantic_instance(o):
raise ValueError("Called ga4gh_deref() with non-non-pydantic instance")
if not is_identifiable(o):
if not is_ga4gh_identifiable(o):
raise ValueError("Called ga4gh_deref() with non-identifiable object")

# in-place replacement on object copy
Expand Down
6 changes: 3 additions & 3 deletions src/ga4gh/core/_internal/identifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from .pydantic import (
is_pydantic_instance,
is_curie_type,
is_identifiable,
is_ga4gh_identifiable,
getattr_in,
get_pydantic_root,
is_pydantic_custom_type
Expand Down Expand Up @@ -143,7 +143,7 @@ def ga4gh_identify(vro):
'ga4gh:VSL.u5fspwVbQ79QkX6GHLF8tXPCAXFJqRPx'
"""
if is_identifiable(vro):
if is_ga4gh_identifiable(vro):
when_rule = ga4gh_compute_identifier_when.get(GA4GHComputeIdentifierWhen.ALWAYS)
do_compute = False
ir = None
Expand Down Expand Up @@ -307,7 +307,7 @@ def identify_all(
# Assumes any obj with 'digest' should be collapsed.
collapsed_output_obj = collapse_identifiable_values(output_obj)
# Add a digest to the output if it is identifiable
if is_identifiable(input_obj):
if is_ga4gh_identifiable(input_obj):
# Compute digest for updated object, not re-running compaction
output_obj["digest"] = ga4gh_digest(collapsed_output_obj, do_compact=False)
else:
Expand Down
10 changes: 5 additions & 5 deletions src/ga4gh/core/_internal/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ def getattr_in(obj, names) -> Any:
return v


def is_identifiable(o: Any) -> bool:
def is_ga4gh_identifiable(o: Any) -> bool:
"""
Determine if object is identifiable. An object is considered identifiable if
contains a `ga4gh_digest` attribute
Determine if object is GA4GH identifiable. An object is considered
GA4GH identifiable if it contains a `ga4gh_prefix` attribute
:param o: Object
:return: `True` if `o` has `ga4gh_digest` attribute. `False` otherwise.
:return: `True` if `o` has `ga4gh_prefix` attribute. `False` otherwise.
"""
return getattr_in(o, ['ga4gh', 'identifiable'])
return bool(getattr_in(o, ['ga4gh', 'prefix']))


def is_literal(o: Any) -> bool:
Expand Down
19 changes: 9 additions & 10 deletions src/ga4gh/vrs/_internal/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from pydantic import BaseModel, ConfigDict, Field, RootModel, constr

from ga4gh.core._internal.pydantic import (
is_identifiable,
is_ga4gh_identifiable,
getattr_in
)
from ga4gh.core._internal.models import IRI, _Entity
Expand Down Expand Up @@ -91,7 +91,7 @@ def pydantic_class_refatt_map():
# Types directly reffable
reffable_classes = list(filter(
lambda c: ('id' in c.model_fields
and is_identifiable(c)),
and is_ga4gh_identifiable(c)),
model_classes
))
# Types reffable because they are a union of reffable types
Expand Down Expand Up @@ -172,16 +172,17 @@ class _ValueObject(_Entity):
description='A sha512t24u digest created using the VRS Computed Identifier algorithm.',
)

class ga4gh:
keys: List[str]


class _Ga4ghIdentifiableObject(_ValueObject):
"""A contextual value object for which a GA4GH computed identifier can be created."""

type: str

class ga4gh:
identifiable = True
class ga4gh(_ValueObject.ga4gh):
prefix: str
keys: List[str]


class Expression(BaseModel):
Expand Down Expand Up @@ -239,7 +240,7 @@ class SequenceReference(_ValueObject):
)
residueAlphabet: Optional[ResidueAlphabet] = None

class ga4gh(_Ga4ghIdentifiableObject.ga4gh):
class ga4gh(_ValueObject.ga4gh):
assigned: bool = Field(
True,
description='This special property indicates that the `digest` field follows an alternate convention and is expected to have the value assigned following that convention. For SequenceReference, it is expected the digest will be the refget accession value without the `SQ.` prefix.'
Expand All @@ -262,7 +263,7 @@ class ReferenceLengthExpression(_ValueObject):
None, description='The number of residues in the repeat subunit.'
)

class ga4gh(_Ga4ghIdentifiableObject.ga4gh):
class ga4gh(_ValueObject.ga4gh):
keys = [
'length',
'repeatSubunitLength',
Expand All @@ -278,8 +279,7 @@ class LiteralSequenceExpression(_ValueObject):
)
sequence: SequenceString = Field(..., description='the literal sequence')

class ga4gh(_Ga4ghIdentifiableObject.ga4gh):
identifiable = False
class ga4gh(_ValueObject.ga4gh):
keys = [
'sequence',
'type'
Expand Down Expand Up @@ -421,7 +421,6 @@ class GenotypeMember(_ValueObject):
)

class ga4gh(_Ga4ghIdentifiableObject.ga4gh):
identifiable = False
keys = [
'type',
'count',
Expand Down

0 comments on commit b5c4c1d

Please sign in to comment.