Skip to content

Commit

Permalink
Update Calculate Amount EPP in TWIST Aliquot step (#475)
Browse files Browse the repository at this point in the history
### Changed
- Updated the twist_aliquot_amount EPP to not give in negative aliquot volumes for samples with lower concentrations.
  • Loading branch information
Karl-Svard authored Feb 27, 2024
1 parent 986fe0d commit 1466d79
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions cg_lims/EPPs/udf/calculate/twist_aliquot_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,41 @@
MAXIMUM_SAMPLE_AMOUNT = 250


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)")
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:
"""Return the maximum allowed input amount for the specified artifact."""
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]):
"""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."""
"""The maximum amount taken into the prep is decided by calculating the minimum between MAXIMUM_SAMPLE_AMOUNT and
<the sample concentration> * <the total volume>.
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_amount(artifact=artifact, default_amount=MAXIMUM_SAMPLE_AMOUNT)
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()
Expand Down

0 comments on commit 1466d79

Please sign in to comment.