From cdd1b7a3320bd7623b3728b4ab4f5568a5c3a6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Sv=C3=A4rd?= Date: Thu, 22 Feb 2024 10:54:11 +0100 Subject: [PATCH 1/3] add new max input for skip rc samples --- .../EPPs/udf/calculate/twist_aliquot_amount.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py b/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py index be4e3aa6..fcc9f8d5 100644 --- a/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py +++ b/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py @@ -16,6 +16,21 @@ MAXIMUM_SAMPLE_AMOUNT = 250 +def get_skip_rc_input_amount(artifact: Artifact) -> float: + """Return the maximum input amount for a sample which has skipped reception control.""" + process = artifact.parent_process + total_volume = process.udf.get("Total Volume (ul)") + concentration = artifact.samples[0].udf.get("Concentration (ng/ul)") + return total_volume * concentration + + +def get_maximum_input_for_aliquot(artifact: Artifact) -> float: + """Return the maximum allowed input amount for the specified artifact.""" + if artifact.samples[0].udf.get("Skip Reception Control QC"): + return get_skip_rc_input_amount(artifact=artifact) + return get_maximum_amount(artifact=artifact, default_amount=MAXIMUM_SAMPLE_AMOUNT) + + def set_amount_needed(artifacts: List[Artifact]): """The maximum amount taken into the prep is MAXIMUM_SAMPLE_AMOUNT. Any amount below this can be used in the prep if the total amount is limited.""" @@ -23,7 +38,7 @@ def set_amount_needed(artifacts: List[Artifact]): missing_udfs = 0 for artifact in artifacts: amount = artifact.udf.get("Amount (ng)") - maximum_amount = get_maximum_amount(artifact=artifact, default_amount=MAXIMUM_SAMPLE_AMOUNT) + maximum_amount = get_maximum_input_for_aliquot(artifact=artifact) if not amount: missing_udfs += 1 continue From 55184204948f7ac078c6737bf0d14791077be690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Sv=C3=A4rd?= Date: Sat, 24 Feb 2024 13:13:25 +0100 Subject: [PATCH 2/3] more fixes --- cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py b/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py index fcc9f8d5..45db1478 100644 --- a/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py +++ b/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py @@ -19,9 +19,11 @@ def get_skip_rc_input_amount(artifact: Artifact) -> float: """Return the maximum input amount for a sample which has skipped reception control.""" process = artifact.parent_process + sample_volume = artifact.udf.get("Volume (ul)") total_volume = process.udf.get("Total Volume (ul)") - concentration = artifact.samples[0].udf.get("Concentration (ng/ul)") - return total_volume * concentration + max_volume = min(sample_volume, total_volume) + concentration = artifact.udf.get("Concentration") + return max_volume * concentration def get_maximum_input_for_aliquot(artifact: Artifact) -> float: @@ -32,7 +34,10 @@ def get_maximum_input_for_aliquot(artifact: Artifact) -> float: def set_amount_needed(artifacts: List[Artifact]): - """The maximum amount taken into the prep is MAXIMUM_SAMPLE_AMOUNT. + """For samples that have skipped RC QC: + - The maximum amount taken into the prep is decided by calculating * . + For all other samples: + - The maximum amount is decided by MAXIMUM_SAMPLE_AMOUNT. Any amount below this can be used in the prep if the total amount is limited.""" missing_udfs = 0 From 6f58c5d8376efbf46871cd33ab841417ff162c78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Sv=C3=A4rd?= Date: Sat, 24 Feb 2024 14:22:51 +0100 Subject: [PATCH 3/3] generalize the fixes, and solve old issue --- .../udf/calculate/twist_aliquot_amount.py | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py b/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py index 45db1478..f6d86bd3 100644 --- a/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py +++ b/cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py @@ -16,8 +16,8 @@ MAXIMUM_SAMPLE_AMOUNT = 250 -def get_skip_rc_input_amount(artifact: Artifact) -> float: - """Return the maximum input amount for a sample which has skipped reception control.""" +def get_possible_input_amount(artifact: Artifact) -> float: + """Return the maximum input amount possible for a sample, depending on the total volume required.""" process = artifact.parent_process sample_volume = artifact.udf.get("Volume (ul)") total_volume = process.udf.get("Total Volume (ul)") @@ -28,33 +28,29 @@ def get_skip_rc_input_amount(artifact: Artifact) -> float: def get_maximum_input_for_aliquot(artifact: Artifact) -> float: """Return the maximum allowed input amount for the specified artifact.""" - if artifact.samples[0].udf.get("Skip Reception Control QC"): - return get_skip_rc_input_amount(artifact=artifact) - return get_maximum_amount(artifact=artifact, default_amount=MAXIMUM_SAMPLE_AMOUNT) + possible_input_amount = get_possible_input_amount(artifact=artifact) + max_input_amount = get_maximum_amount(artifact=artifact, default_amount=MAXIMUM_SAMPLE_AMOUNT) + return min(possible_input_amount, max_input_amount) def set_amount_needed(artifacts: List[Artifact]): - """For samples that have skipped RC QC: - - The maximum amount taken into the prep is decided by calculating * . - For all other samples: - - The maximum amount is decided by MAXIMUM_SAMPLE_AMOUNT. - Any amount below this can be used in the prep if the total amount is limited.""" + """The maximum amount taken into the prep is decided by calculating the minimum between MAXIMUM_SAMPLE_AMOUNT and + * . + + Any amount below this can be used in the prep if the total amount or sample volume is limited. + """ missing_udfs = 0 for artifact in artifacts: - amount = artifact.udf.get("Amount (ng)") - maximum_amount = get_maximum_input_for_aliquot(artifact=artifact) - if not amount: + if not artifact.udf.get("Concentration") or not artifact.udf.get("Volume (ul)"): missing_udfs += 1 continue - if amount >= maximum_amount: - artifact.udf["Amount needed (ng)"] = maximum_amount - else: - artifact.udf["Amount needed (ng)"] = amount + maximum_amount = get_maximum_input_for_aliquot(artifact=artifact) + artifact.udf["Amount needed (ng)"] = maximum_amount artifact.put() if missing_udfs: - raise MissingUDFsError(f"Udf missing for {missing_udfs} samples") + raise MissingUDFsError(f"UDF missing for {missing_udfs} samples") @click.command()