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

Enum Example for PhenotypeStatus #3065

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
6 changes: 3 additions & 3 deletions cg/apps/mip/confighandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from marshmallow import Schema, fields, validate

from cg.constants import DEFAULT_CAPTURE_KIT
from cg.constants.subject import RelationshipStatus
from cg.constants.subject import PhenotypeStatus, RelationshipStatus
from cg.exc import PedigreeConfigError

LOG = logging.getLogger(__name__)
Expand All @@ -26,9 +26,9 @@ class SampleSchema(Schema):
)
father = fields.Str(dump_default=RelationshipStatus.HAS_NO_PARENT)
mother = fields.Str(dump_default=RelationshipStatus.HAS_NO_PARENT)
phenotype = fields.Str(
phenotype = fields.Enum(
PhenotypeStatus,
required=True,
validate=validate.OneOf(choices=["affected", "unaffected", "unknown"]),
)
sex = fields.Str(required=True, validate=validate.OneOf(choices=["female", "male", "unknown"]))
expected_coverage = fields.Float()
Expand Down
11 changes: 5 additions & 6 deletions cg/constants/subject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from enum import IntEnum, StrEnum
from enum import Enum, IntEnum, StrEnum, auto


class Sex(StrEnum):
Expand All @@ -9,11 +9,10 @@ class Sex(StrEnum):
MISSING = ""


class PhenotypeStatus(StrEnum):
UNKNOWN = "unknown"
UNAFFECTED = "unaffected"
AFFECTED = "affected"
MISSING = ""
class PhenotypeStatus(Enum):
UNKNOWN = auto()
UNAFFECTED = auto()
AFFECTED = auto()


class PlinkPhenotypeStatus(IntEnum):
Expand Down
6 changes: 3 additions & 3 deletions cg/meta/workflow/raredisease.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from cg.constants import GenePanelMasterList, Workflow
from cg.constants.gene_panel import GENOME_BUILD_37
from cg.constants.subject import PlinkPhenotypeStatus, PlinkSex
from cg.constants.subject import PhenotypeStatus, PlinkPhenotypeStatus, PlinkSex
from cg.meta.workflow.analysis import add_gene_panel_combo
from cg.meta.workflow.nf_analysis import NfAnalysisAPI
from cg.models.cg_config import CGConfig
Expand Down Expand Up @@ -81,11 +81,11 @@ def get_workflow_parameters(self, case_id: str) -> WorkflowParameters:
)

@staticmethod
def get_phenotype_code(phenotype: str) -> int:
def get_phenotype_code(phenotype: PhenotypeStatus) -> int:
"""Return Raredisease phenotype code."""
LOG.debug("Translate phenotype to integer code")
try:
code = PlinkPhenotypeStatus[phenotype.upper()]
code = PlinkPhenotypeStatus[phenotype.name]
except KeyError:
raise ValueError(f"{phenotype} is not a valid phenotype")
return code
Expand Down
3 changes: 2 additions & 1 deletion cg/models/scout/scout_load_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing_extensions import Annotated, Literal

from cg.constants.scout import UploadTrack
from cg.constants.subject import PhenotypeStatus
from cg.models.scout.validators import field_not_none


Expand Down Expand Up @@ -44,7 +45,7 @@ class ScoutIndividual(BaseModel):
confirmed_sex: bool | None = None
father: str | None = None
mother: str | None = None
phenotype: str | None = None
phenotype: PhenotypeStatus | None = None
sample_id: Annotated[str, BeforeValidator(field_not_none)] = None
sample_name: str | None = None
sex: Annotated[str | None, BeforeValidator(field_not_none)] = None
Expand Down
5 changes: 2 additions & 3 deletions cg/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
StatusOptions,
)
from cg.constants.priority import SlurmQos
from cg.constants.subject import PhenotypeStatus
from cg.constants.symbols import EMPTY_STRING

BigInt = Annotated[int, None]
Expand Down Expand Up @@ -618,9 +619,7 @@ class CaseSample(Base):
id: Mapped[PrimaryKeyInt]
case_id: Mapped[str] = mapped_column(ForeignKey("case.id", ondelete="CASCADE"))
sample_id: Mapped[int] = mapped_column(ForeignKey("sample.id", ondelete="CASCADE"))
status: Mapped[str] = mapped_column(
types.Enum(*(status.value for status in StatusOptions)), default=StatusOptions.UNKNOWN.value
)
status: Mapped[PhenotypeStatus] = mapped_column(default=StatusOptions.UNKNOWN)

created_at: Mapped[datetime | None]
updated_at: Mapped[datetime | None]
Expand Down
6 changes: 4 additions & 2 deletions tests/cli/workflow/mip/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from cg.apps.scout.scoutapi import ScoutAPI
from cg.apps.tb import TrailblazerAPI
from cg.constants import Workflow
from cg.constants.subject import Sex
from cg.constants.subject import PhenotypeStatus, Sex
from cg.meta.compress import CompressAPI
from cg.meta.workflow.mip_dna import MipDNAAnalysisAPI
from cg.meta.workflow.mip_rna import MipRNAAnalysisAPI
Expand Down Expand Up @@ -149,7 +149,9 @@ def mip_dna_context(
customer_id="cust000",
sex=Sex.UNKNOWN,
)
helpers.add_relationship(store=_store, sample=sample, case=case_obj, status="affected")
helpers.add_relationship(
store=_store, sample=sample, case=case_obj, status=PhenotypeStatus.AFFECTED
)
cg_context.meta_apis["analysis_api"] = mip_analysis_api
return cg_context

Expand Down
13 changes: 8 additions & 5 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from cg.constants.housekeeper_tags import HK_DELIVERY_REPORT_TAG
from cg.constants.priority import SlurmQos
from cg.constants.sequencing import SequencingPlatform
from cg.constants.subject import Sex
from cg.constants.subject import PhenotypeStatus, Sex
from cg.io.controller import WriteFile
from cg.io.json import read_json, write_json
from cg.io.yaml import read_yaml, write_yaml
Expand All @@ -50,7 +50,10 @@
from cg.models.flow_cell.flow_cell import FlowCellDirectoryData
from cg.models.raredisease.raredisease import RarediseaseSampleSheetHeaders
from cg.models.rnafusion.rnafusion import RnafusionParameters, RnafusionSampleSheetEntry
from cg.models.taxprofiler.taxprofiler import TaxprofilerParameters, TaxprofilerSampleSheetEntry
from cg.models.taxprofiler.taxprofiler import (
TaxprofilerParameters,
TaxprofilerSampleSheetEntry,
)
from cg.models.tomte.tomte import TomteSampleSheetHeaders
from cg.store.database import create_all_tables, drop_all_tables, initialize_database
from cg.store.models import Bed, BedVersion, Case, Customer, Order, Organism, Sample
Expand Down Expand Up @@ -266,7 +269,7 @@ def analysis_family(case_id: str, family_name: str, sample_id: str, ticket_id: s
"internal_id": sample_id,
"father": "ADM2",
"mother": "ADM3",
"status": "affected",
"status": PhenotypeStatus.AFFECTED,
"original_ticket": ticket_id,
"reads": 5000000,
"capture_kit": "GMSmyeloid",
Expand All @@ -275,7 +278,7 @@ def analysis_family(case_id: str, family_name: str, sample_id: str, ticket_id: s
"name": "father",
"sex": Sex.MALE,
"internal_id": "ADM2",
"status": "unaffected",
"status": PhenotypeStatus.UNAFFECTED,
"original_ticket": ticket_id,
"reads": 6000000,
"capture_kit": "GMSmyeloid",
Expand All @@ -284,7 +287,7 @@ def analysis_family(case_id: str, family_name: str, sample_id: str, ticket_id: s
"name": "mother",
"sex": Sex.FEMALE,
"internal_id": "ADM3",
"status": "unaffected",
"status": PhenotypeStatus.UNAFFECTED,
"original_ticket": ticket_id,
"reads": 7000000,
"capture_kit": "GMSmyeloid",
Expand Down
2 changes: 1 addition & 1 deletion tests/store_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def add_relationship(
store: Store,
sample: Sample,
case: Case,
status: str = PhenotypeStatus.UNKNOWN,
status: PhenotypeStatus = PhenotypeStatus.UNKNOWN,
father: Sample = None,
mother: Sample = None,
) -> CaseSample:
Expand Down
Loading