Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Skip RC samples in TWIST Aliquot step #475

Merged
merged 3 commits into from
Feb 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading