From 462adfdc5fb24c8b15c5d48e30a26ddaf11f2789 Mon Sep 17 00:00:00 2001 From: ChristianOertlin Date: Wed, 12 Jun 2024 11:27:51 +0200 Subject: [PATCH] add(mip analysis upload workaround) (#3332) (patch) # Description allow multiple data analyses mip upload --- cg/meta/workflow/mip_dna.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/cg/meta/workflow/mip_dna.py b/cg/meta/workflow/mip_dna.py index 5d2f245b0c..b96dc6aae5 100644 --- a/cg/meta/workflow/mip_dna.py +++ b/cg/meta/workflow/mip_dna.py @@ -1,3 +1,5 @@ +import logging + from cg.constants import DEFAULT_CAPTURE_KIT, Workflow from cg.constants.constants import AnalysisType from cg.constants.gene_panel import GENOME_BUILD_37 @@ -5,9 +7,11 @@ from cg.meta.workflow.mip import MipAnalysisAPI from cg.models.cg_config import CGConfig from cg.models.mip.mip_analysis import MipAnalysis -from cg.store.models import CaseSample +from cg.store.models import CaseSample, Case from cg.utils import Process +LOG = logging.getLogger(__name__) + class MipDNAAnalysisAPI(MipAnalysisAPI): def __init__(self, config: CGConfig, workflow: Workflow = Workflow.MIP_DNA): @@ -73,3 +77,20 @@ def get_genome_build(self, case_id: str) -> str: """Return the reference genome build version of a MIP-DNA analysis.""" analysis_metadata: MipAnalysis = self.get_latest_metadata(case_id) return analysis_metadata.genome_build + + def get_data_analysis_type(self, case_id: str) -> str: + """ + Return the data analysis type of a MIP-DNA analysis. + Patch for the typical behaviour of the AnalysisAPI function. + It does not raise an error with multiple analysis types. + """ + case: Case = self.get_validated_case(case_id) + analysis_types: set[str] = { + link.sample.application_version.application.analysis_type for link in case.links + } + if len(analysis_types) > 1: + LOG.warning( + f"Multiple analysis types found. Defaulting to {AnalysisType.WHOLE_GENOME_SEQUENCING}." + ) + return AnalysisType.WHOLE_GENOME_SEQUENCING + return analysis_types.pop() if analysis_types else None