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

patch - Concatenate Microbial fastq files #3958

Merged
merged 13 commits into from
Nov 25, 2024
12 changes: 6 additions & 6 deletions cg/cli/deliver/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import click

from cg.apps.tb import TrailblazerAPI
from cg.cli.deliver.utils import deliver_raw_data_for_analyses
from cg.cli.deliver.utils import deliver_raw_data_for_analyses, get_pseudo_workflow
from cg.cli.utils import CLICK_CONTEXT_SETTINGS
from cg.constants import Workflow
from cg.constants.cli_options import DRY_RUN
Expand All @@ -18,9 +18,7 @@
from cg.services.deliver_files.deliver_files_service.deliver_files_service_factory import (
DeliveryServiceFactory,
)
from cg.services.deliver_files.rsync.service import (
DeliveryRsyncService,
)
from cg.services.deliver_files.rsync.service import DeliveryRsyncService
from cg.store.models import Analysis, Case

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -89,9 +87,10 @@ def deliver_case(
if not case:
LOG.error(f"Could not find case with id {case_id}")
return
pseudo_workflow: str = get_pseudo_workflow(case=cases[0])
diitaz93 marked this conversation as resolved.
Show resolved Hide resolved
delivery_service: DeliverFilesService = service_builder.build_delivery_service(
delivery_type=delivery_type if delivery_type else case.data_delivery,
workflow=case.data_analysis,
workflow=pseudo_workflow,
)
delivery_service.deliver_files_for_case(
case=case, delivery_base_path=Path(inbox), dry_run=dry_run
Expand Down Expand Up @@ -124,9 +123,10 @@ def deliver_ticket(
if not cases:
LOG.error(f"Could not find case connected to ticket {ticket}")
return
pseudo_workflow: str = get_pseudo_workflow(case=cases[0])
delivery_service: DeliverFilesService = service_builder.build_delivery_service(
delivery_type=delivery_type if delivery_type else cases[0].data_delivery,
workflow=cases[0].data_analysis,
workflow=pseudo_workflow,
)
delivery_service.deliver_files_for_ticket(
ticket_id=ticket, delivery_base_path=Path(inbox), dry_run=dry_run
Expand Down
9 changes: 9 additions & 0 deletions cg/cli/deliver/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pathlib import Path

from cg.constants import Workflow
from cg.constants.constants import MICROBIAL_APP_TAGS
from cg.services.deliver_files.deliver_files_service.deliver_files_service import (
DeliverFilesService,
)
Expand Down Expand Up @@ -43,3 +44,11 @@ def deliver_raw_data_for_analyses(
)
LOG.error(f"Could not deliver files for analysis {analysis.id}: {error}")
continue


def get_pseudo_workflow(case: Case) -> str:
"""Return the literal '' if the case is Microbial-fastq, otherwise return the case workflow."""
tag: str = case.samples[0].application_version.application.tag
if case.data_analysis == Workflow.RAW_DATA and tag in MICROBIAL_APP_TAGS:
return "microbial-fastq"
return case.data_analysis
diitaz93 marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions cg/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ class MicrosaltAppTags(StrEnum):
PREP_CATEGORY: str = "mic"


MICROBIAL_APP_TAGS = [
MicrosaltAppTags.MWRNXTR003,
MicrosaltAppTags.MWXNXTR003,
MicrosaltAppTags.VWGNXTR001,
]
ChrOertlin marked this conversation as resolved.
Show resolved Hide resolved
diitaz93 marked this conversation as resolved.
Show resolved Hide resolved


class MutantQC:
EXTERNAL_NEGATIVE_CONTROL_READS_THRESHOLD: int = 100000
INTERNAL_NEGATIVE_CONTROL_READS_THRESHOLD: int = 2000
Expand Down
Original file line number Diff line number Diff line change
@@ -1,60 +1,38 @@
"""Module for the factory of the deliver files service."""

from typing import Type

from cg.apps.housekeeper.hk import HousekeeperAPI
from cg.apps.tb import TrailblazerAPI
from cg.constants import Workflow, DataDelivery
from cg.constants import DataDelivery, Workflow
from cg.services.analysis_service.analysis_service import AnalysisService
from cg.services.deliver_files.file_filter.sample_service import SampleFileFilter
from cg.services.deliver_files.tag_fetcher.bam_service import (
BamDeliveryTagsFetcher,
)
from cg.services.fastq_concatenation_service.fastq_concatenation_service import (
FastqConcatenationService,
)
from cg.services.deliver_files.deliver_files_service.deliver_files_service import (
DeliverFilesService,
)
from cg.services.deliver_files.deliver_files_service.exc import DeliveryTypeNotSupported
from cg.services.deliver_files.tag_fetcher.abstract import (
FetchDeliveryFileTagsService,
)
from cg.services.deliver_files.tag_fetcher.sample_and_case_service import (
SampleAndCaseDeliveryTagsFetcher,
)
from cg.services.deliver_files.file_fetcher.analysis_service import (
AnalysisDeliveryFileFetcher,
)
from cg.services.deliver_files.file_fetcher.abstract import (
FetchDeliveryFilesService,
)
from cg.services.deliver_files.file_fetcher.abstract import FetchDeliveryFilesService
from cg.services.deliver_files.file_fetcher.analysis_raw_data_service import (
RawDataAndAnalysisDeliveryFileFetcher,
)
from cg.services.deliver_files.file_fetcher.raw_data_service import (
RawDataDeliveryFileFetcher,
)
from cg.services.deliver_files.file_formatter.service import (
DeliveryFileFormatter,
)

from cg.services.deliver_files.file_formatter.abstract import (
DeliveryFileFormattingService,
)
from cg.services.deliver_files.file_formatter.utils.case_service import (
CaseFileFormatter,
)
from cg.services.deliver_files.file_fetcher.analysis_service import AnalysisDeliveryFileFetcher
from cg.services.deliver_files.file_fetcher.raw_data_service import RawDataDeliveryFileFetcher
from cg.services.deliver_files.file_filter.sample_service import SampleFileFilter
from cg.services.deliver_files.file_formatter.abstract import DeliveryFileFormattingService
from cg.services.deliver_files.file_formatter.service import DeliveryFileFormatter
from cg.services.deliver_files.file_formatter.utils.case_service import CaseFileFormatter
from cg.services.deliver_files.file_formatter.utils.sample_concatenation_service import (
SampleFileConcatenationFormatter,
)
from cg.services.deliver_files.file_formatter.utils.sample_service import (
SampleFileFormatter,
)
from cg.services.deliver_files.file_mover.service import (
DeliveryFilesMover,
from cg.services.deliver_files.file_formatter.utils.sample_service import SampleFileFormatter
from cg.services.deliver_files.file_mover.service import DeliveryFilesMover
from cg.services.deliver_files.rsync.service import DeliveryRsyncService
from cg.services.deliver_files.tag_fetcher.abstract import FetchDeliveryFileTagsService
from cg.services.deliver_files.tag_fetcher.bam_service import BamDeliveryTagsFetcher
from cg.services.deliver_files.tag_fetcher.sample_and_case_service import (
SampleAndCaseDeliveryTagsFetcher,
)
from cg.services.deliver_files.rsync.service import (
DeliveryRsyncService,
from cg.services.fastq_concatenation_service.fastq_concatenation_service import (
FastqConcatenationService,
)
from cg.store.store import Store

Expand Down Expand Up @@ -104,10 +82,10 @@ def _get_file_fetcher(self, delivery_type: DataDelivery) -> FetchDeliveryFilesSe

@staticmethod
def _get_sample_file_formatter(
workflow: Workflow,
workflow: str,
) -> SampleFileFormatter | SampleFileConcatenationFormatter:
"""Get the file formatter service based on the workflow."""
if workflow in [Workflow.MICROSALT]:
if workflow in [Workflow.MICROSALT, "microbial-fastq"]:
return SampleFileConcatenationFormatter(FastqConcatenationService())
return SampleFileFormatter()
diitaz93 marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -126,7 +104,7 @@ def _validate_delivery_type(delivery_type: DataDelivery):
)

def build_delivery_service(
self, workflow: Workflow, delivery_type: DataDelivery
self, workflow: str, delivery_type: DataDelivery
) -> DeliverFilesService:
"""Build a delivery service based on the workflow and delivery type."""
delivery_type: DataDelivery = self._sanitise_delivery_type(delivery_type)
Expand Down
Loading