Skip to content

Commit

Permalink
feat(sex): Use Sex
Browse files Browse the repository at this point in the history
  • Loading branch information
henrikstranneheim committed May 16, 2024
1 parent 8a98147 commit 9cf75d5
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 17 deletions.
6 changes: 3 additions & 3 deletions cg/meta/orders/case_submitter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime as dt
import logging

from cg.constants import DataDelivery, Priority
from cg.constants import DataDelivery, Priority, Sex
from cg.constants.constants import CaseActions, Workflow
from cg.constants.pedigree import Pedigree
from cg.exc import OrderError
Expand Down Expand Up @@ -38,7 +38,7 @@ def _validate_subject_sex(self, samples: [Of1508Sample], customer_id: str):
if not subject_id:
continue
new_gender: str = sample.sex
if new_gender == "unknown":
if new_gender == Sex.UNKNOWN:
continue

existing_samples: list[Sample] = self.status.get_samples_by_customer_and_subject_id(
Expand All @@ -47,7 +47,7 @@ def _validate_subject_sex(self, samples: [Of1508Sample], customer_id: str):
existing_sample: Sample
for existing_sample in existing_samples:
previous_gender = existing_sample.sex
if previous_gender == "unknown":
if previous_gender == Sex.UNKNOWN:
continue

if previous_gender != new_gender:
Expand Down
4 changes: 2 additions & 2 deletions cg/meta/orders/microbial_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from cg.constants import DataDelivery
from cg.constants.constants import Workflow
from cg.constants.subject import Sex
from cg.constants.subject import PhenotypeStatus, Sex
from cg.meta.orders.lims import process_lims
from cg.meta.orders.submitter import Submitter
from cg.models.orders.order import OrderIn
Expand Down Expand Up @@ -146,7 +146,7 @@ def store_items_in_status(
priority = new_sample.priority
sample_objs.append(new_sample)
link: CaseSample = self.status.relate_sample(
case=case, sample=new_sample, status="unknown"
case=case, sample=new_sample, status=PhenotypeStatus.UNKNOWN
)
self.status.session.add(link)
new_samples.append(new_sample)
Expand Down
4 changes: 2 additions & 2 deletions cg/meta/orders/pool_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from cg.constants import DataDelivery
from cg.constants.constants import Workflow
from cg.constants.subject import Sex
from cg.constants.subject import PhenotypeStatus, Sex
from cg.exc import OrderError
from cg.meta.orders.lims import process_lims
from cg.meta.orders.submitter import Submitter
Expand Down Expand Up @@ -162,7 +162,7 @@ def store_items_in_status(
)
new_samples.append(new_sample)
link: CaseSample = self.status.relate_sample(
case=case, sample=new_sample, status="unknown"
case=case, sample=new_sample, status=PhenotypeStatus.UNKNOWN
)
self.status.session.add(link)
new_pools.append(new_pool)
Expand Down
6 changes: 4 additions & 2 deletions cg/meta/upload/gisaid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from pydantic import BaseModel, ConfigDict, model_validator

from cg.constants import Sex
from cg.constants.subject import PhenotypeStatus
from cg.meta.upload.gisaid.constants import AUTHORS


Expand Down Expand Up @@ -57,9 +59,9 @@ class GisaidSample(BaseModel):
covv_passage: str | None = "Original"
covv_location: str | None = None
covv_host: str | None = "Human"
covv_gender: str | None = "unknown"
covv_gender: str | None = Sex.UNKNOWN
covv_patient_age: str | None = "unknown"
covv_patient_status: str | None = "unknown"
covv_patient_status: str | None = PhenotypeStatus.UNKNOWN
covv_seq_technology: str | None = "Illumina NovaSeq"
covv_orig_lab_addr: str | None = None
covv_subm_lab: str | None = "Karolinska University Hospital"
Expand Down
2 changes: 1 addition & 1 deletion cg/meta/upload/mutacc.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def resolve_parent(scout_parent: str) -> str:

def resolve_phenotype(scout_phenotype: int) -> str:
"""Convert scout phenotype to mutacc phenotype"""
mutacc_phenotype = "unknown"
mutacc_phenotype = PhenotypeStatus.UNKNOWN
if scout_phenotype == 1:
mutacc_phenotype = PhenotypeStatus.UNAFFECTED
if scout_phenotype == 2:
Expand Down
4 changes: 2 additions & 2 deletions cg/models/lims/sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Udf(BaseModel):
require_qc_ok: bool = False
rml_plate_name: str | None
selection_criteria: str | None
sex: Literal["M", "F", "unknown"] = "unknown"
sex: Literal["M", "F", "unknown"] = Sex.UNKNOWN
skip_reception_control: bool | None = None
source: str = "NA"
tissue_block_size: str | None
Expand All @@ -54,7 +54,7 @@ class Udf(BaseModel):

@validator("sex", pre=True)
def validate_sex(cls, value: str):
return SEX_MAP.get(value, "unknown")
return SEX_MAP.get(value, Sex.UNKNOWN)


class LimsSample(BaseModel):
Expand Down
3 changes: 2 additions & 1 deletion cg/models/orders/validators/excel_sample_validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from cg.constants.orderforms import REV_SEX_MAP, SOURCE_TYPES
from cg.constants.subject import Sex
from cg.models.orders.sample_base import PriorityEnum


Expand Down Expand Up @@ -59,7 +60,7 @@ def convert_sex(sex: str) -> str | None:
if not sex:
return None
sex = sex.strip()
return REV_SEX_MAP.get(sex, "unknown")
return REV_SEX_MAP.get(sex, Sex.UNKNOWN)


def convert_to_lower(value: str) -> str:
Expand Down
3 changes: 2 additions & 1 deletion tests/apps/madeline/test_madeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

from cg.apps.madeline.api import MadelineAPI
from cg.constants.subject import Sex


def get_ind_info(columns, line):
Expand Down Expand Up @@ -48,7 +49,7 @@ def test_generate_madeline_input_no_sex(madeline_columns, proband):

# GIVEN a case id and a ind with unknown sex
case_id = "test"
proband["sex"] = "unknown"
proband["sex"] = Sex.UNKNOWN
inds = [proband]
# WHEN generating madeline formated lines
madeline_lines = MadelineAPI.make_ped(case_id, inds)
Expand Down
4 changes: 2 additions & 2 deletions tests/meta/archive/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from cg.constants import SequencingFileTag
from cg.constants.archiving import ArchiveLocations
from cg.constants.constants import DataDelivery, FileFormat, Workflow
from cg.constants.subject import Sex
from cg.constants.subject import PhenotypeStatus, Sex
from cg.io.controller import WriteStream
from cg.meta.archive.archive import SpringArchiveAPI
from cg.meta.archive.ddn.constants import ROOT_TO_TRIM
Expand Down Expand Up @@ -282,7 +282,7 @@ def archive_store(
ticket="123",
customer_id=customer_ddn.id,
)
base_store.relate_sample(case=case, sample=new_samples[0], status="unknown")
base_store.relate_sample(case=case, sample=new_samples[0], status=PhenotypeStatus.UNKNOWN)
order = Order(
customer_id=customer_ddn.id,
ticket_id=new_samples[0].original_ticket,
Expand Down
2 changes: 1 addition & 1 deletion tests/meta/orders/test_meta_orders_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ def test_validate_sex_unknown_new_sex(
name=sample.name,
subject_id=sample.subject_id,
)
sample.sex = "unknown"
sample.sex = Sex.UNKNOWN
store.session.add(sample_obj)
store.session.commit()

Expand Down

0 comments on commit 9cf75d5

Please sign in to comment.