Skip to content

Commit

Permalink
Refactor prep category (#3961)
Browse files Browse the repository at this point in the history
### Changed

- Rename PrpeCategory to SeqLibPrepCategory
- Move the class to sequencing.py under constants
- Removed implicit import from constant/__init__.py
- DRY: Removed SequencingMethod as it is dictated by SeqLibPrepCategory
  • Loading branch information
henrikstranneheim authored Nov 26, 2024
1 parent a450324 commit 75cc99e
Show file tree
Hide file tree
Showing 53 changed files with 343 additions and 315 deletions.
5 changes: 3 additions & 2 deletions cg/apps/gens.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import logging

from cg.constants.constants import PrepCategory
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.store.models import Case
from cg.utils import Process
from cg.utils.dict import get_list_from_dictionary
Expand Down Expand Up @@ -51,7 +51,8 @@ def load(
def is_suitable_for_upload(case: Case) -> bool:
"""Check if a cancer case supports Gens upload."""
return all(
sample.prep_category == PrepCategory.WHOLE_GENOME_SEQUENCING for sample in case.samples
sample.prep_category == SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING
for sample in case.samples
)

def __str__(self):
Expand Down
2 changes: 1 addition & 1 deletion cg/apps/orderform/excel_orderform_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ExcelOrderformParser(OrderformParser):
SHEET_NAMES: list[str] = ["Orderform", "orderform", "order form", "Order Form"]
VALID_ORDERFORMS: list[str] = [
f"{Orderform.MIP_DNA}:{Orderform.get_current_orderform_version(Orderform.MIP_DNA)}", # Orderform MIP-DNA, Balsamic, sequencing only, MIP-RNA
f"{Orderform.MICROSALT}:{Orderform.get_current_orderform_version(Orderform.MICROSALT)}", # Microbial WGS
f"{Orderform.MICROSALT}:{Orderform.get_current_orderform_version(Orderform.MICROSALT)}", # Microbial WHOLE_GENOME_SEQUENCING
f"{Orderform.RML}:{Orderform.get_current_orderform_version(Orderform.RML)}", # Orderform Ready made libraries (RML)
f"{Orderform.METAGENOME}:{Orderform.get_current_orderform_version(Orderform.METAGENOME)}", # Microbial meta genomes
f"{Orderform.SARS_COV_2}:{Orderform.get_current_orderform_version(Orderform.SARS_COV_2)}", # Orderform SARS-CoV-2
Expand Down
2 changes: 1 addition & 1 deletion cg/cli/workflow/balsamic/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
type=click.Path(exists=True),
multiple=True,
required=False,
help="VCF paths of clinical and/or cancer SNVs and SVs observations (WGS analysis only). Set this option to "
help="VCF paths of clinical and/or cancer SNVs and SVs observations (WHOLE_GENOME_SEQUENCING analysis only). Set this option to "
"override the latest Loqusdb dump files.",
)

Expand Down
1 change: 0 additions & 1 deletion cg/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
STATUS_OPTIONS,
DataDelivery,
FileExtensions,
PrepCategory,
SequencingRunDataAvailability,
SexOptions,
)
Expand Down
10 changes: 0 additions & 10 deletions cg/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,6 @@ class CancerAnalysisType(StrEnum):
TUMOR_WGS = auto()


class PrepCategory(StrEnum):
COVID: str = "cov"
MICROBIAL: str = "mic"
READY_MADE_LIBRARY: str = "rml"
TARGETED_GENOME_SEQUENCING: str = "tgs"
WHOLE_EXOME_SEQUENCING: str = "wes"
WHOLE_GENOME_SEQUENCING: str = "wgs"
WHOLE_TRANSCRIPTOME_SEQUENCING: str = "wts"


class SexOptions(StrEnum):
MALE: str = "male"
FEMALE: str = "female"
Expand Down
7 changes: 5 additions & 2 deletions cg/constants/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enum import Enum, StrEnum

from cg.constants.constants import CancerAnalysisType, CustomerId, Workflow
from cg.constants.sequencing import SequencingMethod
from cg.constants.sequencing import SeqLibraryPrepCategory

LOQUSDB_ID = "_id"
LOQUSDB_SUPPORTED_WORKFLOWS = [Workflow.BALSAMIC, Workflow.MIP_DNA, Workflow.RAREDISEASE]
Expand All @@ -14,7 +14,10 @@
CustomerId.CUST143,
CustomerId.CUST147,
]
LOQUSDB_RARE_DISEASE_SEQUENCING_METHODS = [SequencingMethod.WGS, SequencingMethod.WES]
LOQUSDB_RARE_DISEASE_SEQUENCING_METHODS = [
SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING,
SeqLibraryPrepCategory.WHOLE_EXOME_SEQUENCING,
]
LOQUSDB_CANCER_SEQUENCING_METHODS = [
CancerAnalysisType.TUMOR_WGS,
CancerAnalysisType.TUMOR_NORMAL_WGS,
Expand Down
2 changes: 1 addition & 1 deletion cg/constants/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@
"mean_length_r1",
]

# WTS metadata required fields (OPTIONAL: "rin", "dv200")
# WHOLE_TRANSCRIPTOME_SEQUENCING metadata required fields (OPTIONAL: "rin", "dv200")
_REQUIRED_SAMPLE_METADATA_WTS_FIELDS: list[str] = _REQUIRED_SAMPLE_METADATA_SEQUENCING_FIELDS + [
"bias_5_3",
"input_amount",
Expand Down
19 changes: 10 additions & 9 deletions cg/constants/sequencing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,6 @@ class Sequencers(StrEnum):
}


class SequencingMethod(StrEnum):
"""Sequencing method types."""

TGS: str = "tgs"
WES: str = "wes"
WGS: str = "wgs"
WTS: str = "wts"


class Variants(StrEnum):
"""Type of variants."""

Expand All @@ -71,3 +62,13 @@ class RecordType(StrEnum):
class SequencingPlatform(StrEnum):
ILLUMINA: str = "ILLUMINA"
OXFORD_NANOPORE: str = "OXFORD_NANOPORE"


class SeqLibraryPrepCategory(StrEnum):
COVID: str = "cov"
MICROBIAL: str = "mic"
READY_MADE_LIBRARY: str = "rml"
TARGETED_GENOME_SEQUENCING: str = "tgs"
WHOLE_EXOME_SEQUENCING: str = "wes"
WHOLE_GENOME_SEQUENCING: str = "wgs"
WHOLE_TRANSCRIPTOME_SEQUENCING: str = "wts"
10 changes: 3 additions & 7 deletions cg/meta/delivery_report/balsamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@
BalsamicTargetedSampleMetadataModel,
BalsamicWGSSampleMetadataModel,
)
from cg.models.delivery_report.report import (
CaseModel,
ReportRequiredFields,
ScoutVariantsFiles,
)
from cg.models.delivery_report.report import CaseModel, ReportRequiredFields, ScoutVariantsFiles
from cg.models.delivery_report.sample import SampleModel
from cg.store.models import Bed, BedVersion, Case, Sample

Expand Down Expand Up @@ -78,7 +74,7 @@ def get_panel_metadata(
sample_metrics: BalsamicTargetedQCMetrics,
analysis_metadata: BalsamicAnalysis,
) -> BalsamicTargetedSampleMetadataModel:
"""Return report metadata for Balsamic TGS analysis."""
"""Return report metadata for Balsamic TARGETED_GENOME_SEQUENCING analysis."""
bed_version: BedVersion = self.status_db.get_bed_version_by_file_name(
analysis_metadata.balsamic_config.panel.capture_kit
)
Expand All @@ -105,7 +101,7 @@ def get_wgs_metadata(
passed_initial_qc: bool | None,
sample_metrics: BalsamicWGSQCMetrics,
) -> BalsamicWGSSampleMetadataModel:
"""Return report metadata for Balsamic WGS analysis."""
"""Return report metadata for Balsamic WHOLE_GENOME_SEQUENCING analysis."""
return BalsamicWGSSampleMetadataModel(
duplicates=sample_metrics.percent_duplication if sample_metrics else None,
fold_80=sample_metrics.fold_80_base_penalty if sample_metrics else None,
Expand Down
7 changes: 4 additions & 3 deletions cg/meta/delivery_report/raredisease.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""Raredisease Delivery Report API."""

from cg.clients.chanjo2.models import CoverageMetrics
from cg.constants.constants import PrepCategory
from cg.constants.report import (
REQUIRED_APPLICATION_FIELDS,
REQUIRED_CASE_FIELDS,
Expand All @@ -15,14 +14,15 @@
REQUIRED_SAMPLE_TIMESTAMP_FIELDS,
)
from cg.constants.scout import ScoutUploadKey
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.meta.delivery_report.data_validators import get_million_read_pairs
from cg.meta.delivery_report.delivery_report_api import DeliveryReportAPI
from cg.meta.workflow.raredisease import RarediseaseAnalysisAPI
from cg.models.analysis import AnalysisModel, NextflowAnalysis
from cg.models.raredisease.raredisease import RarediseaseQCMetrics
from cg.models.delivery_report.metadata import RarediseaseSampleMetadataModel
from cg.models.delivery_report.report import CaseModel, ReportRequiredFields, ScoutVariantsFiles
from cg.models.delivery_report.sample import SampleModel
from cg.models.raredisease.raredisease import RarediseaseQCMetrics
from cg.store.models import Case, Sample


Expand Down Expand Up @@ -85,7 +85,8 @@ def get_sample_metadata_required_fields(case: CaseModel) -> dict:
for sample in case.samples:
required_fields = (
REQUIRED_SAMPLE_METADATA_RAREDISEASE_WGS_FIELDS
if PrepCategory.WHOLE_GENOME_SEQUENCING in sample.application.prep_category.lower()
if SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING
in sample.application.prep_category.lower()
else REQUIRED_SAMPLE_METADATA_RAREDISEASE_FIELDS
)
required_sample_metadata_fields.update({sample.id: required_fields})
Expand Down
15 changes: 9 additions & 6 deletions cg/meta/observations/mip_dna_observations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
MipDNALoadParameters,
MipDNAObservationsAnalysisTag,
)
from cg.constants.sequencing import SequencingMethod
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.exc import CaseNotFoundError, LoqusdbDuplicateRecordError
from cg.meta.observations.observations_api import ObservationsAPI
from cg.meta.workflow.mip_dna import MipDNAAnalysisAPI
Expand Down Expand Up @@ -64,10 +64,12 @@ def is_case_eligible_for_observations_upload(self, case: Case) -> bool:

def set_loqusdb_instance(self, case_id: str) -> None:
"""Return the Loqusdb instance associated to the sequencing method."""
sequencing_method: SequencingMethod = self.analysis_api.get_data_analysis_type(case_id)
loqusdb_instances: dict[SequencingMethod, LoqusdbInstance] = {
SequencingMethod.WGS: LoqusdbInstance.WGS,
SequencingMethod.WES: LoqusdbInstance.WES,
sequencing_method: SeqLibraryPrepCategory = self.analysis_api.get_data_analysis_type(
case_id
)
loqusdb_instances: dict[SeqLibraryPrepCategory, LoqusdbInstance] = {
SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING: LoqusdbInstance.WGS,
SeqLibraryPrepCategory.WHOLE_EXOME_SEQUENCING: LoqusdbInstance.WES,
}
self.loqusdb_api = self.get_loqusdb_api(loqusdb_instances[sequencing_method])

Expand Down Expand Up @@ -117,7 +119,8 @@ def get_observations_files_from_hk(
self.housekeeper_api.files(
version=hk_version.id, tags=[MipDNAObservationsAnalysisTag.SV_VCF]
).first()
if self.analysis_api.get_data_analysis_type(case_id) == SequencingMethod.WGS
if self.analysis_api.get_data_analysis_type(case_id)
== SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING
else None
),
"profile_vcf_path": self.housekeeper_api.files(
Expand Down
4 changes: 2 additions & 2 deletions cg/meta/observations/observations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from cg.constants.constants import CustomerId
from cg.constants.observations import LoqusdbInstance
from cg.constants.sample_sources import SourceType
from cg.constants.sequencing import SequencingMethod
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.exc import LoqusdbUploadCaseError
from cg.meta.workflow.analysis import AnalysisAPI
from cg.models.cg_config import CGConfig, CommonAppConfig
Expand Down Expand Up @@ -123,7 +123,7 @@ def is_customer_eligible_for_observations_upload(self, customer_id: str) -> bool

def is_sequencing_method_eligible_for_observations_upload(self, case_id: str) -> bool:
"""Return whether a sequencing method is valid for observations upload."""
sequencing_method: SequencingMethod | None = self.analysis_api.get_data_analysis_type(
sequencing_method: SeqLibraryPrepCategory | None = self.analysis_api.get_data_analysis_type(
case_id
)
if sequencing_method not in self.loqusdb_sequencing_methods:
Expand Down
20 changes: 10 additions & 10 deletions cg/meta/observations/raredisease_observations_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
RarediseaseLoadParameters,
RarediseaseObservationsAnalysisTag,
)
from cg.constants.sequencing import SequencingMethod
from cg.exc import (
CaseNotFoundError,
LoqusdbDuplicateRecordError,
)
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.exc import CaseNotFoundError, LoqusdbDuplicateRecordError
from cg.meta.observations.observations_api import ObservationsAPI
from cg.meta.workflow.raredisease import RarediseaseAnalysisAPI
from cg.models.cg_config import CGConfig
Expand Down Expand Up @@ -67,10 +64,12 @@ def is_case_eligible_for_observations_upload(self, case: Case) -> bool:

def set_loqusdb_instance(self, case_id: str) -> None:
"""Set the Loqusdb instance associated to the sequencing method."""
sequencing_method: SequencingMethod = self.analysis_api.get_data_analysis_type(case_id)
loqusdb_instances: dict[SequencingMethod, LoqusdbInstance] = {
SequencingMethod.WGS: LoqusdbInstance.WGS,
SequencingMethod.WES: LoqusdbInstance.WES,
sequencing_method: SeqLibraryPrepCategory = self.analysis_api.get_data_analysis_type(
case_id
)
loqusdb_instances: dict[SeqLibraryPrepCategory, LoqusdbInstance] = {
SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING: LoqusdbInstance.WGS,
SeqLibraryPrepCategory.WHOLE_EXOME_SEQUENCING: LoqusdbInstance.WES,
}
self.loqusdb_api = self.get_loqusdb_api(loqusdb_instances[sequencing_method])

Expand Down Expand Up @@ -119,7 +118,8 @@ def get_observations_files_from_hk(
self.housekeeper_api.files(
version=hk_version.id, tags=[RarediseaseObservationsAnalysisTag.SV_VCF]
).first()
if self.analysis_api.get_data_analysis_type(case_id) == SequencingMethod.WGS
if self.analysis_api.get_data_analysis_type(case_id)
== SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING
else None
),
"profile_vcf_path": self.housekeeper_api.files(
Expand Down
4 changes: 2 additions & 2 deletions cg/meta/upload/balsamic/balsamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from cg.cli.upload.observations import upload_observations_to_loqusdb
from cg.cli.upload.scout import upload_to_scout
from cg.constants import REPORT_SUPPORTED_DATA_DELIVERY, DataDelivery
from cg.constants.sequencing import SequencingMethod
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.meta.upload.gt import UploadGenotypesAPI
from cg.meta.upload.upload_api import UploadAPI
from cg.meta.workflow.balsamic import BalsamicAnalysisAPI
Expand Down Expand Up @@ -61,7 +61,7 @@ def upload(self, ctx: click.Context, case: Case, restart: bool) -> None:
# Observations upload
if (
self.analysis_api.get_case_application_type(case_id=case.internal_id)
== SequencingMethod.WGS
== SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING
):
ctx.invoke(upload_observations_to_loqusdb, case_id=case.internal_id)
else:
Expand Down
10 changes: 7 additions & 3 deletions cg/meta/upload/gt.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

from cg.apps.gt import GenotypeAPI
from cg.apps.housekeeper.hk import HousekeeperAPI
from cg.constants.constants import FileExtensions, FileFormat, PrepCategory, Workflow
from cg.constants.constants import FileExtensions, FileFormat, Workflow
from cg.constants.housekeeper_tags import GenotypeAnalysisTag, HkAnalysisMetricsTag
from cg.constants.nf_analysis import RAREDISEASE_PREDICTED_SEX_METRIC
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.constants.subject import Sex
from cg.io.controller import ReadFile
from cg.models.deliverables.metric_deliverables import MetricsBase
Expand Down Expand Up @@ -69,10 +70,13 @@ def upload(self, genotype_load_config: dict, replace: bool = False):

@staticmethod
def is_suitable_for_genotype_upload(case: Case) -> bool:
"""Returns True if there are any non-tumor WGS samples in the case."""
"""Returns True if there are any non-tumor WHOLE_GENOME_SEQUENCING samples in the case."""
samples: list[Sample] = case.samples
return any(
(not sample.is_tumour and PrepCategory.WHOLE_GENOME_SEQUENCING == sample.prep_category)
(
not sample.is_tumour
and SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING == sample.prep_category
)
for sample in samples
)

Expand Down
20 changes: 7 additions & 13 deletions cg/meta/upload/scout/uploadscoutapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
from cg.apps.madeline.api import MadelineAPI
from cg.apps.scout.scoutapi import ScoutAPI
from cg.constants import HK_MULTIQC_HTML_TAG, Workflow
from cg.constants.constants import FileFormat, GenomeVersion, PrepCategory
from cg.constants.housekeeper_tags import (
HK_DELIVERY_REPORT_TAG,
AlignmentFileTag,
AnalysisTag,
)
from cg.constants.constants import FileFormat, GenomeVersion
from cg.constants.housekeeper_tags import HK_DELIVERY_REPORT_TAG, AlignmentFileTag, AnalysisTag
from cg.constants.scout import ScoutCustomCaseReportTags
from cg.constants.sequencing import SeqLibraryPrepCategory
from cg.exc import CgDataError, HousekeeperBundleVersionMissingError
from cg.io.controller import WriteFile
from cg.meta.upload.scout.balsamic_config_builder import BalsamicConfigBuilder
Expand All @@ -27,10 +24,7 @@
from cg.meta.upload.scout.rnafusion_config_builder import RnafusionConfigBuilder
from cg.meta.upload.scout.scout_config_builder import ScoutConfigBuilder
from cg.meta.workflow.analysis import AnalysisAPI
from cg.meta.workflow.utils.genome_build_helpers import (
genome_to_scout_format,
get_genome_build,
)
from cg.meta.workflow.utils.genome_build_helpers import genome_to_scout_format, get_genome_build
from cg.models.scout.scout_load_config import ScoutLoadConfig
from cg.store.models import Analysis, Case, Customer, Sample
from cg.store.store import Store
Expand Down Expand Up @@ -765,9 +759,9 @@ def _get_application_prep_category(
for sample in subject_id_samples
if sample.prep_category
in [
PrepCategory.WHOLE_GENOME_SEQUENCING.value,
PrepCategory.TARGETED_GENOME_SEQUENCING.value,
PrepCategory.WHOLE_EXOME_SEQUENCING.value,
SeqLibraryPrepCategory.WHOLE_GENOME_SEQUENCING.value,
SeqLibraryPrepCategory.TARGETED_GENOME_SEQUENCING.value,
SeqLibraryPrepCategory.WHOLE_EXOME_SEQUENCING.value,
]
]

Expand Down
2 changes: 1 addition & 1 deletion cg/meta/workflow/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ def get_case_source_type(self, case_id: str) -> str | None:
return source_types.pop()

def has_case_only_exome_samples(self, case_id: str) -> bool:
"""Returns True if the application type for all samples in a case is WES."""
"""Returns True if the application type for all samples in a case is WHOLE_EXOME_SEQUENCING."""
application_type: str = self.get_case_application_type(case_id)
return application_type == AnalysisType.WHOLE_EXOME_SEQUENCING

Expand Down
2 changes: 1 addition & 1 deletion cg/meta/workflow/balsamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def get_verified_bed(self, panel_bed: str, sample_data: dict) -> str | None:
raise BalsamicStartError("Multiple application types found in LIMS")
if not application_types.issubset(self.__BALSAMIC_BED_APPLICATIONS):
if panel_bed:
raise BalsamicStartError("Cannot set panel_bed for WGS sample!")
raise BalsamicStartError("Cannot set panel_bed for WHOLE_GENOME_SEQUENCING sample!")
return None
if panel_bed:
return panel_bed.as_posix()
Expand Down
2 changes: 1 addition & 1 deletion cg/meta/workflow/raredisease.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def is_gene_panel_required(self) -> bool:

def get_target_bed(self, case_id: str, analysis_type: str) -> str:
"""
Return the target bed file from LIMS and use default capture kit for WGS.
Return the target bed file from LIMS and use default capture kit for WHOLE_GENOME_SEQUENCING.
"""
target_bed: str = self.get_target_bed_from_lims(case_id=case_id)
if not target_bed:
Expand Down
Loading

0 comments on commit 75cc99e

Please sign in to comment.