Skip to content

Commit

Permalink
change constants for fetching app tags from statusdb
Browse files Browse the repository at this point in the history
  • Loading branch information
diitaz93 committed Nov 22, 2024
1 parent fc0b4df commit af476ca
Show file tree
Hide file tree
Showing 12 changed files with 210 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,13 @@
from cg.services.deliver_files.deliver_files_service.error_handling import (
handle_no_delivery_files_error,
)
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.models import DeliveryFiles
from cg.services.deliver_files.file_filter.abstract import FilterDeliveryFilesService
from cg.services.deliver_files.file_formatter.abstract import (
DeliveryFileFormattingService,
)
from cg.services.deliver_files.file_formatter.models import (
FormattedFiles,
)
from cg.services.deliver_files.file_formatter.abstract import DeliveryFileFormattingService
from cg.services.deliver_files.file_formatter.models import FormattedFiles
from cg.services.deliver_files.file_mover.service import DeliveryFilesMover
from cg.services.deliver_files.rsync.service import (
DeliveryRsyncService,
)
from cg.services.deliver_files.rsync.service import DeliveryRsyncService
from cg.store.exc import EntryNotFoundError
from cg.store.models import Case
from cg.store.store import Store
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from cg.apps.housekeeper.hk import HousekeeperAPI
from cg.apps.tb import TrailblazerAPI
from cg.constants import DataDelivery, Workflow
from cg.constants.constants import MICROBIAL_APP_TAGS
from cg.constants.constants import MICROBIAL_APP_TAGS, PrepCategory
from cg.services.analysis_service.analysis_service import AnalysisService
from cg.services.deliver_files.deliver_files_service.deliver_files_service import (
DeliverFilesService,
Expand Down Expand Up @@ -134,14 +134,19 @@ def build_delivery_service(
analysis_service=self.analysis_service,
)

@staticmethod
def _convert_workflow(case: Case) -> Workflow:
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
if case.data_analysis == Workflow.RAW_DATA and tag in MICROBIAL_APP_TAGS:
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

Expand Down
24 changes: 5 additions & 19 deletions cg/services/deliver_files/file_formatter/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,14 @@
import os
from pathlib import Path

from cg.constants.delivery import INBOX_NAME
from cg.services.deliver_files.file_fetcher.models import (
CaseFile,
DeliveryFiles,
SampleFile,
)
from cg.services.deliver_files.file_formatter.abstract import (
DeliveryFileFormattingService,
)
from cg.services.deliver_files.file_formatter.models import (
FormattedFile,
FormattedFiles,
)
from cg.services.deliver_files.file_formatter.utils.case_service import (
CaseFileFormatter,
)
from cg.services.deliver_files.file_fetcher.models import CaseFile, DeliveryFiles, SampleFile
from cg.services.deliver_files.file_formatter.abstract import DeliveryFileFormattingService
from cg.services.deliver_files.file_formatter.models import FormattedFile, FormattedFiles
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_formatter.utils.sample_service import SampleFileFormatter

LOG = logging.getLogger(__name__)

Expand Down
13 changes: 13 additions & 0 deletions cg/store/crud/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,19 @@ def get_current_application_version_by_tag(self, tag: str) -> ApplicationVersion
valid_from=dt.datetime.now(),
).first()

def get_active_applications_by_prep_category(
self, prep_category: PrepCategory
) -> list[Application]:
"""Return all active applications by prep category."""
return apply_application_filter(
applications=self._get_query(table=Application),
filter_functions=[
ApplicationFilter.BY_PREP_CATEGORIES,
ApplicationFilter.IS_NOT_ARCHIVED,
],
prep_categories=[prep_category],
).all()

def get_bed_version_by_file_name(self, bed_version_file_name: str) -> BedVersion:
"""Return bed version with file name."""
return apply_bed_version_filter(
Expand Down
8 changes: 2 additions & 6 deletions cg/store/filters/status_application_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from sqlalchemy.orm import Query

from cg.constants import PrepCategory, Workflow
from cg.constants import PrepCategory
from cg.store.models import Application


Expand Down Expand Up @@ -42,19 +42,15 @@ def apply_application_filter(
filter_functions: list[Callable],
applications: Query,
tag: str = None,
prep_category: str = None,
prep_categories: list[Workflow] = None,
entry_id: int = None,
prep_categories: list[PrepCategory] = None,
) -> Query:
"""Apply filtering functions to the sample queries and return filtered results."""

for filter_function in filter_functions:
applications: Query = filter_function(
applications=applications,
tag=tag,
prep_category=prep_category,
prep_categories=prep_categories,
entry_id=entry_id,
)
return applications

Expand Down
23 changes: 5 additions & 18 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,7 @@
from cg.apps.tb.dto.summary_response import AnalysisSummary, StatusSummary
from cg.clients.freshdesk.freshdesk_client import FreshdeskClient
from cg.constants import FileExtensions, SequencingFileTag, Workflow
from cg.constants.constants import (
CaseActions,
CustomerId,
FileFormat,
GenomeVersion,
Strandedness,
)
from cg.constants.constants import CaseActions, CustomerId, FileFormat, GenomeVersion, Strandedness
from cg.constants.gene_panel import GenePanelMasterList
from cg.constants.housekeeper_tags import HK_DELIVERY_REPORT_TAG
from cg.constants.priority import SlurmQos
Expand All @@ -57,22 +51,14 @@
from cg.models import CompressionData
from cg.models.cg_config import CGConfig, PDCArchivingDirectory
from cg.models.downsample.downsample_data import DownsampleData
from cg.models.raredisease.raredisease import (
RarediseaseParameters,
RarediseaseSampleSheetHeaders,
)
from cg.models.raredisease.raredisease import RarediseaseParameters, RarediseaseSampleSheetHeaders
from cg.models.rnafusion.rnafusion import RnafusionParameters, RnafusionSampleSheetEntry
from cg.models.run_devices.illumina_run_directory_data import IlluminaRunDirectoryData
from cg.models.taxprofiler.taxprofiler import (
TaxprofilerParameters,
TaxprofilerSampleSheetEntry,
)
from cg.models.taxprofiler.taxprofiler import TaxprofilerParameters, TaxprofilerSampleSheetEntry
from cg.models.tomte.tomte import TomteParameters, TomteSampleSheetHeaders
from cg.services.deliver_files.rsync.service import DeliveryRsyncService
from cg.services.illumina.backup.encrypt_service import IlluminaRunEncryptionService
from cg.services.illumina.data_transfer.data_transfer_service import (
IlluminaDataTransferService,
)
from cg.services.illumina.data_transfer.data_transfer_service import IlluminaDataTransferService
from cg.store.database import create_all_tables, drop_all_tables, initialize_database
from cg.store.models import (
Application,
Expand Down Expand Up @@ -146,6 +132,7 @@
"tests.fixture_plugins.pacbio_fixtures.unprocessed_runs_fixtures",
"tests.fixture_plugins.quality_controller_fixtures.sequencing_qc_check_scenario",
"tests.fixture_plugins.quality_controller_fixtures.sequencing_qc_fixtures",
"tests.fixture_plugins.store_fixtures",
"tests.fixture_plugins.timestamp_fixtures",
]

Expand Down
140 changes: 140 additions & 0 deletions tests/fixture_plugins/store_fixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
from typing import Generator

import pytest

from cg.constants.constants import ControlOptions
from cg.store.store import Store
from tests.store_helpers import StoreHelpers


@pytest.fixture
def applications_store(store: Store, helpers: StoreHelpers) -> Store:
"""Return a store populated with applications from excel file"""
app_tags: list[str] = ["PGOTTTR020", "PGOTTTR030", "PGOTTTR040"]
for app_tag in app_tags:
helpers.ensure_application(store=store, tag=app_tag)
return store


@pytest.fixture
def microbial_store(store: Store, helpers: StoreHelpers) -> Generator[Store, None, None]:
"""Populate a store with microbial application tags"""
microbial_active_apptags = ["MWRNXTR003", "MWGNXTR003", "MWMNXTR003", "MWLNXTR003"]
microbial_inactive_apptags = ["MWXNXTR003", "VWGNXTR001", "VWLNXTR001"]

for app_tag in microbial_active_apptags:
helpers.ensure_application(store=store, tag=app_tag, prep_category="mic", is_archived=False)

for app_tag in microbial_inactive_apptags:
helpers.ensure_application(store=store, tag=app_tag, prep_category="mic", is_archived=True)

return store


@pytest.fixture
def mutant_store(store: Store, helpers: StoreHelpers) -> Store:
# Add mutant application and application_version
application = helpers.add_application(
store=store, application_tag="VWGDPTR001", target_reads=2000000, percent_reads_guaranteed=1
)

# Add cases
case_qc_pass = helpers.add_case(store=store, name="case_qc_pass", internal_id="case_qc_pass")
case_qc_fail = helpers.add_case(store=store, name="case_qc_fail", internal_id="case_qc_fail")

case_qc_fail_with_failing_controls = helpers.add_case(
store=store,
name="case_qc_fail_with_failing_controls",
internal_id="case_qc_fail_with_failing_controls",
)

# Add samples
sample_qc_pass = helpers.add_sample(
store=store,
internal_id="sample_qc_pass",
name="sample_qc_pass",
control=ControlOptions.EMPTY,
reads=861966,
application_tag=application.tag,
)

sample_qc_fail = helpers.add_sample(
store=store,
internal_id="sample_qc_fail",
name="sample_qc_fail",
control=ControlOptions.EMPTY,
reads=438776,
application_tag=application.tag,
)

external_negative_control_qc_pass = helpers.add_sample(
store=store,
internal_id="external_negative_control_qc_pass",
name="external_negative_control_qc_pass",
control=ControlOptions.NEGATIVE,
reads=20674,
application_tag=application.tag,
)

internal_negative_control_qc_pass = helpers.add_sample(
store=store,
internal_id="internal_negative_control_qc_pass",
name="internal_negative_control_qc_pass",
control=ControlOptions.NEGATIVE,
reads=0,
application_tag=application.tag,
)

sample_qc_pass_with_failing_controls = helpers.add_sample(
store=store,
internal_id="sample_qc_pass_with_failing_controls",
name="sample_qc_pass",
control=ControlOptions.EMPTY,
reads=861966,
application_tag=application.tag,
)

internal_negative_control_qc_fail = helpers.add_sample(
store=store,
internal_id="internal_negative_control_qc_fail",
name="internal_negative_control_qc_fail",
control=ControlOptions.NEGATIVE,
reads=3000,
application_tag=application.tag,
)

external_negative_control_qc_fail = helpers.add_sample(
store=store,
internal_id="external_negative_control_qc_fail",
name="external_negative_control_qc_fail",
control=ControlOptions.NEGATIVE,
reads=200000,
application_tag=application.tag,
)

# Add CaseSample relationships
# case_qc_pass
helpers.add_relationship(store=store, case=case_qc_pass, sample=sample_qc_pass)
helpers.add_relationship(
store=store, case=case_qc_pass, sample=external_negative_control_qc_pass
)

# case_qc_fail
helpers.add_relationship(store=store, case=case_qc_fail, sample=sample_qc_fail)
helpers.add_relationship(
store=store, case=case_qc_fail, sample=external_negative_control_qc_pass
)

# case_qc_fail_with_failing_controls
helpers.add_relationship(
store=store,
case=case_qc_fail_with_failing_controls,
sample=sample_qc_pass_with_failing_controls,
)
helpers.add_relationship(
store=store,
case=case_qc_fail_with_failing_controls,
sample=external_negative_control_qc_fail,
)

return store
Loading

0 comments on commit af476ca

Please sign in to comment.