Skip to content

Commit

Permalink
fix: Scout files logs for delivery report & remove outdated UDF access (
Browse files Browse the repository at this point in the history
#2923)

### Fixed:
- File retrieval logging for Scout upload files to be specific to its respective pipeline (delivery report generation).
- Removed outdated UDF usage for retrieving the application version (delivery report generation).
  • Loading branch information
ivadym authored Feb 12, 2024
1 parent 96a9f0c commit cd59694
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
16 changes: 14 additions & 2 deletions cg/meta/report/balsamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
BalsamicTargetedSampleMetadataModel,
BalsamicWGSSampleMetadataModel,
)
from cg.models.report.report import CaseModel
from cg.models.report.report import CaseModel, ScoutReportFiles
from cg.models.report.sample import SampleModel
from cg.store.models import Bed, BedVersion, Case, Sample

Expand Down Expand Up @@ -91,8 +91,9 @@ def get_panel_metadata(
gc_dropout=sample_metrics.gc_dropout if sample_metrics else None,
)

@staticmethod
def get_wgs_metadata(
self, million_read_pairs: float, sample_metrics: BalsamicWGSQCMetrics
million_read_pairs: float, sample_metrics: BalsamicWGSQCMetrics
) -> BalsamicWGSSampleMetadataModel:
"""Return report metadata for Balsamic WGS analysis."""
return BalsamicWGSSampleMetadataModel(
Expand Down Expand Up @@ -162,6 +163,17 @@ def is_report_accredited(
return True
return False

def get_scout_uploaded_files(self, case: Case) -> ScoutReportFiles:
"""Return files that will be uploaded to Scout."""
return ScoutReportFiles(
snv_vcf=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="snv_vcf"
),
sv_vcf=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="sv_vcf"
),
)

def get_required_fields(self, case: CaseModel) -> dict:
"""Return a dictionary with the delivery report required fields for Balsamic."""
analysis_type: str = case.data_analysis.type
Expand Down
19 changes: 18 additions & 1 deletion cg/meta/report/mip_dna.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from cg.models.mip.mip_analysis import MipAnalysis
from cg.models.mip.mip_metrics_deliverables import get_sample_id_metric
from cg.models.report.metadata import MipDNASampleMetadataModel
from cg.models.report.report import CaseModel
from cg.models.report.report import CaseModel, ScoutReportFiles
from cg.models.report.sample import SampleModel
from cg.store.models import Case, Sample

Expand Down Expand Up @@ -88,6 +88,23 @@ def is_report_accredited(
return False
return True

def get_scout_uploaded_files(self, case: Case) -> ScoutReportFiles:
"""Return files that will be uploaded to Scout."""
return ScoutReportFiles(
snv_vcf=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="snv_vcf"
),
sv_vcf=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="sv_vcf"
),
vcf_str=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="vcf_str"
),
smn_tsv=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="smn_tsv"
),
)

def get_required_fields(self, case: CaseModel) -> dict:
"""Return dictionary with the delivery report required fields for MIP DNA."""
return {
Expand Down
26 changes: 6 additions & 20 deletions cg/meta/report/report_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,9 @@ def get_samples_data(self, case: Case, analysis_metadata: AnalysisModel) -> list
gender=sample.sex,
source=lims_sample.get("source") if lims_sample else None,
tumour=sample.is_tumour,
application=self.get_sample_application_data(lims_sample=lims_sample),
application=self.get_sample_application_data(
sample=sample, lims_sample=lims_sample
),
methods=self.get_sample_methods_data(sample_id=sample.internal_id),
status=case_sample.status,
metadata=self.get_sample_metadata(
Expand Down Expand Up @@ -289,15 +291,15 @@ def get_workflow_accreditation_limitation(self, application_tag: str) -> str | N
)
return application_limitation.limitations if application_limitation else None

def get_sample_application_data(self, lims_sample: dict) -> ApplicationModel:
def get_sample_application_data(self, sample: Sample, lims_sample: dict) -> ApplicationModel:
"""Retrieves the analysis application attributes."""
application: Application = self.status_db.get_application_by_tag(
tag=lims_sample.get("application")
)
return (
ApplicationModel(
tag=application.tag,
version=lims_sample.get("application_version"),
version=sample.application_version.version,
prep_category=application.prep_category,
description=application.description,
details=application.details,
Expand Down Expand Up @@ -352,23 +354,7 @@ def get_case_analysis_data(

def get_scout_uploaded_files(self, case: Case) -> ScoutReportFiles:
"""Return files that will be uploaded to Scout."""
return ScoutReportFiles(
snv_vcf=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="snv_vcf"
),
sv_vcf=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="sv_vcf"
),
vcf_str=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="vcf_str"
),
smn_tsv=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="smn_tsv"
),
vcf_fusion=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="vcf_fusion"
),
)
raise NotImplementedError

@staticmethod
def get_sample_timestamp_data(sample: Sample) -> TimestampModel:
Expand Down
10 changes: 9 additions & 1 deletion cg/meta/report/rnafusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from cg.models.analysis import AnalysisModel
from cg.models.cg_config import CGConfig
from cg.models.report.metadata import RnafusionSampleMetadataModel
from cg.models.report.report import CaseModel
from cg.models.report.report import CaseModel, ScoutReportFiles
from cg.models.report.sample import SampleModel
from cg.models.rnafusion.rnafusion import RnafusionAnalysis, RnafusionQCMetrics
from cg.store.models import Case, Sample
Expand Down Expand Up @@ -88,6 +88,14 @@ def get_template_name(self) -> str:
"""Return template name to render the delivery report."""
return Workflow.RNAFUSION + "_report.html"

def get_scout_uploaded_files(self, case: Case) -> ScoutReportFiles:
"""Return files that will be uploaded to Scout."""
return ScoutReportFiles(
vcf_fusion=self.get_scout_uploaded_file_from_hk(
case_id=case.internal_id, scout_tag="vcf_fusion"
)
)

def get_required_fields(self, case: CaseModel) -> dict:
"""Return dictionary with the delivery report required fields for Rnafusion."""
return {
Expand Down
9 changes: 5 additions & 4 deletions tests/meta/report/test_report_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
SampleModel,
TimestampModel,
)
from cg.store.models import Analysis, Case, CaseSample
from cg.store.models import Analysis, Case, CaseSample, Sample
from cg.store.store import Store
from tests.meta.report.helper import recursive_assert
from tests.store_helpers import StoreHelpers
Expand Down Expand Up @@ -307,16 +307,17 @@ def test_get_sample_application_data(
# GIVEN a lims sample instance

# GIVEN the expected application data
expected_application_data: dict = case_samples_data[0].sample.to_dict().get("application")
sample: Sample = case_samples_data[0].sample
expected_application_data: dict = sample.to_dict().get("application")

# WHEN retrieving application data from status DB
application_data: ApplicationModel = report_api_mip_dna.get_sample_application_data(
lims_samples[0]
sample=sample, lims_sample=lims_samples[0]
)

# THEN verify that the application data corresponds to what is expected
assert application_data.tag == str(expected_application_data.get("tag"))
assert application_data.version == str(lims_samples[0].get("application_version"))
assert application_data.version == str(sample.application_version.version)
assert application_data.prep_category == str(expected_application_data.get("prep_category"))
assert application_data.description == str(expected_application_data.get("description"))
assert application_data.limitations == str(expected_application_data.get("limitations"))
Expand Down

0 comments on commit cd59694

Please sign in to comment.