Skip to content

Commit

Permalink
Skip lims data retrieval if downsampled for rnafusion report (#2705)
Browse files Browse the repository at this point in the history
### Changed

- Skip lims sample metadata collection for rnafusion report generation if down sampled
  • Loading branch information
fevac authored Nov 28, 2023
1 parent 22c22bf commit 0478077
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
12 changes: 10 additions & 2 deletions cg/meta/report/rnafusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)

Expand Down
34 changes: 32 additions & 2 deletions tests/meta/report/test_rnafusion_api.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

0 comments on commit 0478077

Please sign in to comment.