From ad0ce8fa3fe6199788bfd2a5a4178bfddc1e1452 Mon Sep 17 00:00:00 2001 From: Kori Kuzma Date: Tue, 16 Jul 2024 16:24:47 -0400 Subject: [PATCH] feat!: update/rename classes to refect public API access and ABC * `_DomainEntity` -> `DomainEntity` * `_Entity` -> `Entity` * Abstract classes inherit from ABC --- src/ga4gh/core/domain_models.py | 18 +++++++++--------- src/ga4gh/core/entity_models.py | 5 +++-- src/ga4gh/vrs/models.py | 11 ++++++----- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/ga4gh/core/domain_models.py b/src/ga4gh/core/domain_models.py index d6d0918f..e9a070c7 100644 --- a/src/ga4gh/core/domain_models.py +++ b/src/ga4gh/core/domain_models.py @@ -15,7 +15,7 @@ from pydantic import Field, RootModel -from ga4gh.core.entity_models import _DomainEntity +from ga4gh.core.entity_models import DomainEntity class CommonDomainType(str, Enum): @@ -30,7 +30,7 @@ class CommonDomainType(str, Enum): TR_COMB = "CombinationTherapy" GENE = "Gene" -class Phenotype(_DomainEntity): +class Phenotype(DomainEntity): """An observable characteristic or trait of an organism.""" type: Literal[CommonDomainType.PHENOTYPE] = Field( @@ -39,7 +39,7 @@ class Phenotype(_DomainEntity): ) -class Disease(_DomainEntity): +class Disease(DomainEntity): """A particular abnormal condition that negatively affects the structure or function of all or part of an organism and is not immediately due to any external injury. """ @@ -50,7 +50,7 @@ class Disease(_DomainEntity): ) -class TraitSet(_DomainEntity): +class TraitSet(DomainEntity): """A set of phenotype and/or disease concepts that together constitute a condition.""" type: Literal[CommonDomainType.TRAIT_SET] = Field( @@ -73,7 +73,7 @@ class Condition(RootModel): ) -class TherapeuticAction(_DomainEntity): +class TherapeuticAction(DomainEntity): """A therapeutic action taken that is intended to alter or stop a pathologic process.""" type: Literal[CommonDomainType.TR_ACTION] = Field( @@ -82,7 +82,7 @@ class TherapeuticAction(_DomainEntity): ) -class TherapeuticAgent(_DomainEntity): +class TherapeuticAgent(DomainEntity): """An administered therapeutic agent that is intended to alter or stop a pathologic process.""" type: Literal[CommonDomainType.TR_AGENT] = Field( @@ -91,7 +91,7 @@ class TherapeuticAgent(_DomainEntity): ) -class TherapeuticSubstituteGroup(_DomainEntity): +class TherapeuticSubstituteGroup(DomainEntity): """A group of therapeutic procedures that may be treated as substitutes for one another.""" type: Literal[CommonDomainType.TR_SUB] = Field( @@ -105,7 +105,7 @@ class TherapeuticSubstituteGroup(_DomainEntity): ) -class CombinationTherapy(_DomainEntity): +class CombinationTherapy(DomainEntity): """A therapeutic procedure that involves multiple different therapeutic procedures performed in combination. """ @@ -133,7 +133,7 @@ class TherapeuticProcedure(RootModel): ) -class Gene(_DomainEntity): +class Gene(DomainEntity): """A basic physical and functional unit of heredity.""" type: Literal[CommonDomainType.GENE] = Field( diff --git a/src/ga4gh/core/entity_models.py b/src/ga4gh/core/entity_models.py index bf91f597..0e00ef61 100644 --- a/src/ga4gh/core/entity_models.py +++ b/src/ga4gh/core/entity_models.py @@ -10,6 +10,7 @@ * `import ga4gh.core`, and refer to models using the fully-qualified module name, e.g., `ga4gh.core.entity_models.Coding` """ +from abc import ABC from typing import Any, Dict, Annotated, Optional, Union, List from enum import Enum @@ -153,7 +154,7 @@ class Expression(BaseModel): ######################################### -class _Entity(BaseModel): +class Entity(ABC, BaseModel): """Entity is the root class of the 'gks-common' core information model classes - those that have identifiers and other general metadata like labels, xrefs, urls, descriptions, etc. All common classes descend from and inherit its attributes. @@ -176,7 +177,7 @@ class _Entity(BaseModel): extensions: Optional[List[Extension]] = Field(None, description="A list of extensions to the entity. Extensions are not expected to be natively understood, but may be used for pre-negotiated exchange of message attributes between systems.") -class _DomainEntity(_Entity): +class DomainEntity(Entity, ABC): """An Entity that is specific to a particular biomedical domain such as disease, therapeutics, or genes. Domain Entities are considered as 'concept-level' entities, as opposed to particular instances. e.g. 'Lung Cancer', not 'patient123's lung diff --git a/src/ga4gh/vrs/models.py b/src/ga4gh/vrs/models.py index 348c5497..b0ec9126 100644 --- a/src/ga4gh/vrs/models.py +++ b/src/ga4gh/vrs/models.py @@ -10,6 +10,7 @@ * `import ga4gh.vrs`, and refer to models using the fully-qualified module name, e.g., `ga4gh.vrs.models.Allele` """ +from abc import ABC from typing import List, Literal, Optional, Union, Dict, Annotated from collections import OrderedDict from enum import Enum @@ -24,7 +25,7 @@ is_ga4gh_identifiable, getattr_in ) -from ga4gh.core.entity_models import IRI, Expression, _DomainEntity +from ga4gh.core.entity_models import IRI, Expression, DomainEntity def flatten(vals): @@ -181,7 +182,7 @@ def _recurse_ga4gh_serialize(obj): return obj -class _ValueObject(_DomainEntity): +class _ValueObject(DomainEntity, ABC): """A contextual value whose equality is based on value, not identity. See https://en.wikipedia.org/wiki/Value_object for more on Value Objects. """ @@ -205,7 +206,7 @@ def is_ga4gh_identifiable(): return False -class _Ga4ghIdentifiableObject(_ValueObject): +class _Ga4ghIdentifiableObject(_ValueObject, ABC): """A contextual value object for which a GA4GH computed identifier can be created. All GA4GH Identifiable Objects may have computed digests from the VRS Computed Identifier algorithm. @@ -502,7 +503,7 @@ class ga4gh(_Ga4ghIdentifiableObject.ga4gh): ######################################### -class _VariationBase(_Ga4ghIdentifiableObject): +class _VariationBase(_Ga4ghIdentifiableObject, ABC): """Base class for variation""" expressions: Optional[List[Expression]] = None @@ -646,7 +647,7 @@ class ga4gh(_Ga4ghIdentifiableObject.ga4gh): ######################################### -class _CopyNumber(_VariationBase): +class _CopyNumber(_VariationBase, ABC): """A measure of the copies of a `Location` within a system (e.g. genome, cell, etc.)""" location: Union[IRI, SequenceLocation] = Field(