-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Watchmaker EPP updates (#536)(minor)
### Added - New flag to specify max volume in the calculate volume-buffer EPP ### Changed - Renamed the TWIST aliquot amount EPP to just "aliquot-amount" - Also generalized it by moving all hard-coded UDF names and constants to click options instead
- Loading branch information
1 parent
5bc48f0
commit e3afad5
Showing
5 changed files
with
136 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import logging | ||
import sys | ||
from typing import List | ||
|
||
import click | ||
from cg_lims import options | ||
from cg_lims.exceptions import LimsError, MissingUDFsError | ||
from cg_lims.get.artifacts import get_artifacts | ||
from cg_lims.get.udfs import get_maximum_amount | ||
from genologics.entities import Artifact, Process | ||
|
||
LOG = logging.getLogger(__name__) | ||
|
||
|
||
def get_possible_input_amount( | ||
artifact: Artifact, sample_volume_udf: str, total_volume_udf: str, concentration_udf: str | ||
) -> float: | ||
"""Return the maximum input amount possible for a sample, depending on the total volume required.""" | ||
process: Process = artifact.parent_process | ||
sample_volume: float = artifact.udf.get(sample_volume_udf) | ||
total_volume: float = process.udf.get(total_volume_udf) | ||
max_volume: float = min(sample_volume, total_volume) | ||
concentration: float = artifact.udf.get(concentration_udf) | ||
return max_volume * concentration | ||
|
||
|
||
def get_maximum_input_for_aliquot( | ||
artifact: Artifact, | ||
sample_volume_udf: str, | ||
total_volume_udf: str, | ||
concentration_udf: str, | ||
maximum_sample_amount: float, | ||
) -> float: | ||
"""Return the maximum allowed input amount for the specified artifact.""" | ||
possible_input_amount: float = get_possible_input_amount( | ||
artifact=artifact, | ||
sample_volume_udf=sample_volume_udf, | ||
total_volume_udf=total_volume_udf, | ||
concentration_udf=concentration_udf, | ||
) | ||
max_input_amount: float = 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], | ||
sample_volume_udf: str, | ||
total_volume_udf: str, | ||
concentration_udf: str, | ||
amount_udf: str, | ||
maximum_sample_amount: float, | ||
) -> None: | ||
"""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: int = 0 | ||
for artifact in artifacts: | ||
if not artifact.udf.get(concentration_udf) or not artifact.udf.get(sample_volume_udf): | ||
missing_udfs += 1 | ||
continue | ||
maximum_amount: float = get_maximum_input_for_aliquot( | ||
artifact=artifact, | ||
sample_volume_udf=sample_volume_udf, | ||
total_volume_udf=total_volume_udf, | ||
concentration_udf=concentration_udf, | ||
maximum_sample_amount=maximum_sample_amount, | ||
) | ||
artifact.udf[amount_udf] = maximum_amount | ||
artifact.put() | ||
|
||
if missing_udfs: | ||
raise MissingUDFsError(f"UDF missing for {missing_udfs} samples") | ||
|
||
|
||
@click.command() | ||
@options.volume_udf(help="Sample volume artifact UDF name.") | ||
@options.total_volume_udf(help="Total volume process UDF name.") | ||
@options.concentration_udf(help="Sample concentration artifact UDF name.") | ||
@options.amount_ng_udf(help="Sample amount (ng) artifact UDF name.") | ||
@options.maximum_amount(help="The maximum input amount of the prep.") | ||
@click.pass_context | ||
def aliquot_amount( | ||
ctx, | ||
volume_udf: str, | ||
total_volume_udf: str, | ||
concentration_udf: str, | ||
amount_ng_udf: str, | ||
max_amount: str, | ||
): | ||
"""Calculates amount needed for samples.""" | ||
|
||
LOG.info(f"Running {ctx.command_path} with params: {ctx.params}") | ||
|
||
process: Process = ctx.obj["process"] | ||
|
||
try: | ||
artifacts: List[Artifact] = get_artifacts(process=process, input=False) | ||
set_amount_needed( | ||
artifacts=artifacts, | ||
sample_volume_udf=volume_udf, | ||
total_volume_udf=total_volume_udf, | ||
concentration_udf=concentration_udf, | ||
amount_udf=amount_ng_udf, | ||
maximum_sample_amount=int(max_amount), | ||
) | ||
message: str = "Amount needed has been calculated for all samples." | ||
LOG.info(message) | ||
click.echo(message) | ||
except LimsError as e: | ||
LOG.error(e.message) | ||
sys.exit(e.message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters