Skip to content

Commit

Permalink
rework error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Karl-Svard committed May 24, 2024
1 parent 4e7e6b0 commit 72cf020
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cg_lims/EPPs/files/xml_to_udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def get_run_parameters(process: Process) -> str:
"""Return RunParameters-file from location on the server."""
flow_cell_id: str = get_flow_cell_id(process=process)
return max(
glob.glob(f"/home/gls/hiseq_data/novaseq-clinical-preproc/*{flow_cell_id}/RunParameters.xml"),
glob.glob(
f"/home/gls/hiseq_data/novaseq-clinical-preproc/*{flow_cell_id}/RunParameters.xml"
),
key=os.path.getctime,
)

Expand Down
15 changes: 11 additions & 4 deletions cg_lims/EPPs/udf/calculate/qpcr_concentration.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import sys
from pathlib import Path
from statistics import mean
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Tuple

import click
import numpy as np
Expand All @@ -12,6 +12,7 @@
from cg_lims.exceptions import FailingQCError, LimsError, MissingFileError, MissingValueError
from cg_lims.get.artifacts import get_artifact_by_name, get_artifacts
from cg_lims.get.files import get_file_path
from cg_lims.get.samples import get_one_sample_from_artifact
from genologics.entities import Artifact, Process

LOG = logging.getLogger(__name__)
Expand Down Expand Up @@ -146,12 +147,12 @@ def qpcr_concentration(
summary_file=file_path
)
failed_samples: int = 0
missing_samples: List[Tuple[str, str]] = []
for artifact in artifacts:
artifact_well: str = artifact.location[1]
if artifact_well not in quantification_data.keys():
raise MissingValueError(
f"No values found for well {artifact_well} in the result file! "
f"Please double check if sample {artifact.samples[0].id} has been placed correctly."
missing_samples.append(
(get_one_sample_from_artifact(artifact=artifact).id, artifact_well)
)
well_results: WellValues = quantification_data[artifact.location[1]]
well_results.connect_artifact(artifact=artifact)
Expand All @@ -163,6 +164,12 @@ def qpcr_concentration(
if well_results.artifact.qc_flag == "FAILED":
failed_samples += 1

if missing_samples:
raise MissingValueError(
f"No values found for the following samples in the result file! "
f"Please double check if the samples {missing_samples} have been placed correctly."
)

if failed_samples:
error_message: str = (
f" {failed_samples} sample(s) failed the QC! See the logs for further information."
Expand Down

0 comments on commit 72cf020

Please sign in to comment.