From 0478077123aba38625d68059843bf8cd4c9c769d Mon Sep 17 00:00:00 2001 From: Eva C <29628428+fevac@users.noreply.github.com> Date: Tue, 28 Nov 2023 12:19:41 +0100 Subject: [PATCH] Skip lims data retrieval if downsampled for rnafusion report (#2705) ### Changed - Skip lims sample metadata collection for rnafusion report generation if down sampled --- cg/meta/report/rnafusion.py | 12 +++++++-- tests/meta/report/test_rnafusion_api.py | 34 +++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/cg/meta/report/rnafusion.py b/cg/meta/report/rnafusion.py index 6a5772c1c0..ef0cfafeda 100644 --- a/cg/meta/report/rnafusion.py +++ b/cg/meta/report/rnafusion.py @@ -38,11 +38,19 @@ def get_sample_metadata( ) -> RnafusionSampleMetadataModel: """Return sample metadata to include in the report.""" sample_metrics: RnafusionQCMetrics = analysis_metadata.sample_metrics[sample.internal_id] + + # Skip LIMS data collection if down sampled + input_amount = None + rin = None + if not sample.downsampled_to: + input_amount = self.lims_api.get_latest_rna_input_amount(sample_id=sample.internal_id) + rin = self.lims_api.get_sample_rin(sample_id=sample.internal_id) + return RnafusionSampleMetadataModel( bias_5_3=sample_metrics.bias_5_3, duplicates=sample_metrics.pct_duplication, gc_content=sample_metrics.after_filtering_gc_content, - input_amount=self.lims_api.get_latest_rna_input_amount(sample_id=sample.internal_id), + input_amount=input_amount, insert_size=None, insert_size_peak=None, mapped_reads=sample_metrics.reads_aligned @@ -58,7 +66,7 @@ def get_sample_metadata( q20_rate=sample_metrics.after_filtering_q20_rate, q30_rate=sample_metrics.after_filtering_q30_rate, ribosomal_bases=sample_metrics.pct_ribosomal_bases, - rin=self.lims_api.get_sample_rin(sample_id=sample.internal_id), + rin=rin, uniquely_mapped_reads=sample_metrics.uniquely_mapped_percent, ) diff --git a/tests/meta/report/test_rnafusion_api.py b/tests/meta/report/test_rnafusion_api.py index fa046ce844..fa50b111db 100644 --- a/tests/meta/report/test_rnafusion_api.py +++ b/tests/meta/report/test_rnafusion_api.py @@ -1,6 +1,5 @@ """Test module for the Rnafusion delivery report API.""" - - +from cg.constants import NA_FIELD from cg.meta.report.rnafusion import RnafusionReportAPI from cg.models.report.metadata import RnafusionSampleMetadataModel from cg.models.rnafusion.rnafusion import RnafusionAnalysis @@ -34,3 +33,34 @@ def test_get_sample_metadata( # THEN the sample metadata should be correctly retrieved and match the expected validated metrics assert sample_metadata.model_dump() == rnafusion_validated_metrics + + +def test_get_down_sample_metadata( + report_api_rnafusion: RnafusionReportAPI, + sample_id: str, + rnafusion_case_id: str, + rnafusion_validated_metrics: dict[str, str], + mock_analysis_finish, +): + """Test Rnafusion sample metadata extraction.""" + + # GIVEN a Rnafusion case and associated sample that has been down sampled + case: Case = report_api_rnafusion.status_db.get_case_by_internal_id( + internal_id=rnafusion_case_id + ) + sample: Sample = report_api_rnafusion.status_db.get_sample_by_internal_id(internal_id=sample_id) + sample.downsampled_to = 10000 + + # GIVEN an analysis metadata object + latest_metadata: RnafusionAnalysis = report_api_rnafusion.analysis_api.get_latest_metadata( + case_id=rnafusion_case_id + ) + + # WHEN getting the sample metadata + sample_metadata: RnafusionSampleMetadataModel = report_api_rnafusion.get_sample_metadata( + case=case, sample=sample, analysis_metadata=latest_metadata + ) + + # THEN the rin and input_amount should be N/A + assert sample_metadata.rin == NA_FIELD + assert sample_metadata.input_amount == NA_FIELD