Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: split gks-common module into domain + entity #422

Merged
merged 26 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1eafdf0
build!: remove support for python 3.9 and make 3.12 the dev default
korikuzma Jun 26, 2024
5173587
feat!: update vrs/core models
korikuzma Jul 2, 2024
c685227
Merge branch 'main' into issue-409
korikuzma Jul 2, 2024
76a2e7c
chore: update submodule
korikuzma Jul 2, 2024
e0367d7
update submodules
korikuzma Jul 3, 2024
e5fc9dc
take order property into account
korikuzma Jul 3, 2024
5d11602
update serialization for ordered property
korikuzma Jul 5, 2024
3c58567
update common/vrs submodules
korikuzma Jul 8, 2024
fda5e00
fixes
korikuzma Jul 9, 2024
5b89f0b
more fixes
korikuzma Jul 9, 2024
4fb88d9
clean up forward references
korikuzma Jul 9, 2024
eb88d9f
Merge branch 'main' into issue-409
korikuzma Jul 9, 2024
d5bcaf5
feat: create enum for gks-common + vrs types
korikuzma Jul 10, 2024
456b744
refactor: remove _internal directories
korikuzma Jul 10, 2024
8d5afda
refactor!: split gks-common module into domain + entity
korikuzma Jul 10, 2024
5b351a1
remove
korikuzma Jul 10, 2024
5c1a9d4
refactor: remove _internal directories (#421)
korikuzma Jul 10, 2024
855630c
Merge branch 'main' into split-gks-common-models
korikuzma Jul 10, 2024
f836e6f
Merge branch 'main' into issue-407
korikuzma Jul 10, 2024
5b671d8
Merge branch 'issue-407' into split-gks-common-models
korikuzma Jul 10, 2024
d925b45
rm
korikuzma Jul 10, 2024
3992a0a
Merge branch 'main' into issue-407
korikuzma Jul 10, 2024
66fd5ab
Merge branch 'issue-407' into split-gks-common-models
korikuzma Jul 10, 2024
07f1519
Merge branch 'main' into split-gks-common-models
korikuzma Jul 10, 2024
fa30257
update docstring
korikuzma Jul 10, 2024
68574e1
Merge branch 'main' into split-gks-common-models
korikuzma Jul 11, 2024
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: 3 additions & 2 deletions src/ga4gh/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .pydantic import (
is_pydantic_instance, is_curie_type, is_ga4gh_identifiable, is_literal, pydantic_copy
)
from . import models as common_models
from . import entity_models, domain_models

__all__ = [
"sha512t24u",
Expand All @@ -37,7 +37,8 @@
"is_ga4gh_identifiable",
"is_literal",
"pydantic_copy",
"common_models"
"entity_models",
"domain_models"
]

try:
Expand Down
142 changes: 142 additions & 0 deletions src/ga4gh/core/domain_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"""GKS Common Library Domain Entity models

**This module should not be imported directly.**

Instead, users should use one of the following:

* `from ga4gh.core import domain_models`, and refer to models with the
abbreviated name, e.g., `domain_models.Gene` (recommended)

* `import ga4gh.core`, and refer to models using the fully-qualified
module name, e.g., `ga4gh.core.domain_models.Gene`
"""
from typing import Literal, Union, List
from enum import Enum

from pydantic import Field, RootModel

from ga4gh.core.entity_models import _DomainEntity


class CommonDomainType(str, Enum):
"""Define GKS Common Domain Entity types"""

PHENOTYPE = "Phenotype"
DISEASE = "Disease"
TRAIT_SET = "TraitSet"
TR_ACTION = "TherapeuticAction"
TR_AGENT = "TherapeuticAgent"
TR_SUB = "TherapeuticSubstituteGroup"
TR_COMB = "CombinationTherapy"
GENE = "Gene"

class Phenotype(_DomainEntity):
"""An observable characteristic or trait of an organism."""

type: Literal[CommonDomainType.PHENOTYPE] = Field(
CommonDomainType.PHENOTYPE,
description=f'MUST be "{CommonDomainType.PHENOTYPE.value}".'
)


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.
"""

type: Literal[CommonDomainType.DISEASE] = Field(
CommonDomainType.DISEASE,
description=f'MUST be "{CommonDomainType.DISEASE.value}".'
)


class TraitSet(_DomainEntity):
"""A set of phenotype and/or disease concepts that together constitute a condition."""

type: Literal[CommonDomainType.TRAIT_SET] = Field(
CommonDomainType.TRAIT_SET,
description=f'MUST be "{CommonDomainType.TRAIT_SET.value}".'
)
traits: List[Union[Disease, Phenotype]] = Field(
...,
min_length=2
)


class Condition(RootModel):
"""A disease or other medical disorder."""

root: Union[TraitSet, Disease, Phenotype] = Field(
...,
json_schema_extra={'description': 'A disease or other medical disorder.'},
discriminator='type',
)


class TherapeuticAction(_DomainEntity):
"""A therapeutic action taken that is intended to alter or stop a pathologic process."""

type: Literal[CommonDomainType.TR_ACTION] = Field(
CommonDomainType.TR_ACTION,
description=f'MUST be "{CommonDomainType.TR_ACTION.value}".'
)


class TherapeuticAgent(_DomainEntity):
"""An administered therapeutic agent that is intended to alter or stop a pathologic process."""

type: Literal[CommonDomainType.TR_AGENT] = Field(
CommonDomainType.TR_AGENT,
description=f'MUST be "{CommonDomainType.TR_AGENT.value}".'
)


class TherapeuticSubstituteGroup(_DomainEntity):
"""A group of therapeutic procedures that may be treated as substitutes for one another."""

type: Literal[CommonDomainType.TR_SUB] = Field(
CommonDomainType.TR_SUB,
description=f'MUST be "{CommonDomainType.TR_SUB.value}".'
)
substitutes: List[Union[TherapeuticAction, TherapeuticAgent]] = Field(
...,
description='The individual therapeutic procedures that may be treated as substitutes.',
min_length=2
)


class CombinationTherapy(_DomainEntity):
"""A therapeutic procedure that involves multiple different therapeutic procedures
performed in combination.
"""

type: Literal[CommonDomainType.TR_COMB] = Field(
CommonDomainType.TR_COMB,
description=f'MUST be "{CommonDomainType.TR_COMB.value}".'
)
components: List[Union[TherapeuticSubstituteGroup, TherapeuticAction, TherapeuticAgent]] = Field(
...,
description='The individual therapeutic procedure components that constitute the combination therapy.',
min_length=2
)


class TherapeuticProcedure(RootModel):
"""An action or administration of therapeutic agents to produce an effect that is
intended to alter or stop a pathologic process.
"""

root: Union[CombinationTherapy, TherapeuticSubstituteGroup, TherapeuticAction, TherapeuticAgent] = Field(
...,
json_schema_extra={'description': 'An action or administration of therapeutic agents to produce an effect that is intended to alter or stop a pathologic process.'},
discriminator='type',
)


class Gene(_DomainEntity):
"""A basic physical and functional unit of heredity."""

type: Literal[CommonDomainType.GENE] = Field(
CommonDomainType.GENE,
description=f'MUST be "{CommonDomainType.GENE.value}".'
)
12 changes: 4 additions & 8 deletions src/ga4gh/core/models.py → src/ga4gh/core/entity_models.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""GKS Common Library models
"""GKS Common Library Entity models

**This module should not be imported directly.**

Instead, users should use one of the following:

* `from ga4gh.core import common_models`, and refer to models with the
abbreviated name, e.g., `common_models.Gene` (recommended)
* `from ga4gh.core import entity_models`, and refer to models with the
abbreviated name, e.g., `entity_models.Coding` (recommended)

* `import ga4gh.core`, and refer to models using the fully-qualified
module name, e.g., `ga4gh.core.common_models.Gene`
module name, e.g., `ga4gh.core.entity_models.Coding`
"""
from typing import Any, Dict, Literal, Annotated, Optional, Union, List
from enum import Enum
Expand All @@ -18,10 +18,6 @@
from ga4gh.core import GA4GH_IR_REGEXP


#########################################
# GKS Common Utility Class Definitions
#########################################


class Relation(str, Enum):
"""A mapping relation between concepts as defined by the Simple Knowledge
Expand Down
2 changes: 1 addition & 1 deletion src/ga4gh/vrs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
is_ga4gh_identifiable,
getattr_in
)
from ga4gh.core.models import IRI, Expression, _DomainEntity
from ga4gh.core.entity_models import IRI, Expression, _DomainEntity


def flatten(vals):
Expand Down
Loading