Skip to content

Commit

Permalink
reorder functions
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed Nov 22, 2024
1 parent f0d7eda commit 5c8e60d
Showing 1 changed file with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,36 @@ def __init__(
self.tb_service = tb_service
self.analysis_service = analysis_service

@staticmethod
def _sanitise_delivery_type(delivery_type: DataDelivery) -> DataDelivery:
"""Sanitise the delivery type."""
if delivery_type in [DataDelivery.FASTQ_QC, DataDelivery.FASTQ_SCOUT]:
return DataDelivery.FASTQ
if delivery_type in [DataDelivery.ANALYSIS_SCOUT]:
return DataDelivery.ANALYSIS_FILES
if delivery_type in [
DataDelivery.FASTQ_ANALYSIS_SCOUT,
DataDelivery.FASTQ_QC_ANALYSIS,
]:
return DataDelivery.FASTQ_ANALYSIS
return delivery_type

@staticmethod
def _validate_delivery_type(delivery_type: DataDelivery):
"""Check if the delivery type is supported. Raises DeliveryTypeNotSupported error."""
if delivery_type in [
DataDelivery.FASTQ,
DataDelivery.ANALYSIS_FILES,
DataDelivery.FASTQ_ANALYSIS,
DataDelivery.BAM,
]:
return
raise DeliveryTypeNotSupported(
f"Delivery type {delivery_type} is not supported. Supported delivery types are"
f" {DataDelivery.FASTQ}, {DataDelivery.ANALYSIS_FILES},"
f" {DataDelivery.FASTQ_ANALYSIS}, {DataDelivery.BAM}."
)

@staticmethod
def _get_file_tag_fetcher(delivery_type: DataDelivery) -> FetchDeliveryFileTagsService:
"""Get the file tag fetcher based on the delivery type."""
Expand All @@ -82,6 +112,22 @@ def _get_file_fetcher(self, delivery_type: DataDelivery) -> FetchDeliveryFilesSe
tags_fetcher=file_tag_fetcher,
)

def _convert_workflow(self, case: Case) -> Workflow:
"""Converts a workflow with the introduction of the microbial-fastq delivery type an
unsupported combination of delivery type and workflow setup is required. This function
makes sure that a raw data workflow with microbial fastq delivery type is treated as a
microsalt workflow so that the microbial-fastq sample files can be concatenated."""
tag: str = case.samples[0].application_version.application.tag
microbial_tags: list[str] = [
application.tag
for application in self.store.get_active_applications_by_prep_category(
prep_category=PrepCategory.MICROBIAL
)
]
if case.data_analysis == Workflow.RAW_DATA and tag in microbial_tags:
return Workflow.MICROSALT
return case.data_analysis

def _get_sample_file_formatter(
self,
case: Case,
Expand All @@ -92,22 +138,6 @@ def _get_sample_file_formatter(
return SampleFileConcatenationFormatter(FastqConcatenationService())
return SampleFileFormatter()

@staticmethod
def _validate_delivery_type(delivery_type: DataDelivery):
"""Check if the delivery type is supported. Raises DeliveryTypeNotSupported error."""
if delivery_type in [
DataDelivery.FASTQ,
DataDelivery.ANALYSIS_FILES,
DataDelivery.FASTQ_ANALYSIS,
DataDelivery.BAM,
]:
return
raise DeliveryTypeNotSupported(
f"Delivery type {delivery_type} is not supported. Supported delivery types are"
f" {DataDelivery.FASTQ}, {DataDelivery.ANALYSIS_FILES},"
f" {DataDelivery.FASTQ_ANALYSIS}, {DataDelivery.BAM}."
)

def build_delivery_service(
self, case: Case, delivery_type: DataDelivery | None = None
) -> DeliverFilesService:
Expand All @@ -133,33 +163,3 @@ def build_delivery_service(
tb_service=self.tb_service,
analysis_service=self.analysis_service,
)

def _convert_workflow(self, case: Case) -> Workflow:
"""Converts a workflow with the introduction of the microbial-fastq delivery type an
unsupported combination of delivery type and workflow setup is required. This function
makes sure that a raw data workflow with microbial fastq delivery type is treated as a
microsalt workflow so that the microbial-fastq sample files can be concatenated."""
tag: str = case.samples[0].application_version.application.tag
microbial_tags: list[str] = [
application.tag
for application in self.store.get_active_applications_by_prep_category(
prep_category=PrepCategory.MICROBIAL
)
]
if case.data_analysis == Workflow.RAW_DATA and tag in microbial_tags:
return Workflow.MICROSALT
return case.data_analysis

@staticmethod
def _sanitise_delivery_type(delivery_type: DataDelivery) -> DataDelivery:
"""Sanitise the delivery type."""
if delivery_type in [DataDelivery.FASTQ_QC, DataDelivery.FASTQ_SCOUT]:
return DataDelivery.FASTQ
if delivery_type in [DataDelivery.ANALYSIS_SCOUT]:
return DataDelivery.ANALYSIS_FILES
if delivery_type in [
DataDelivery.FASTQ_ANALYSIS_SCOUT,
DataDelivery.FASTQ_QC_ANALYSIS,
]:
return DataDelivery.FASTQ_ANALYSIS
return delivery_type

0 comments on commit 5c8e60d

Please sign in to comment.