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

Generalize and rename buffer aliquotation script used in the Sample Placement step in several LIMS workflows #534

Merged
merged 7 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions cg_lims/EPPs/udf/calculate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
calculate_resuspension_buffer_volume,
)
from cg_lims.EPPs.udf.calculate.calculate_saphyr_concentration import calculate_saphyr_concentration
from cg_lims.EPPs.udf.calculate.calculate_water import volume_water
from cg_lims.EPPs.udf.calculate.calculate_buffer import volume_buffer
from cg_lims.EPPs.udf.calculate.calculate_water_volume_rna import calculate_water_volume_rna
from cg_lims.EPPs.udf.calculate.get_missing_reads import get_missing_reads
from cg_lims.EPPs.udf.calculate.maf_calculate_volume import maf_calculate_volume
Expand Down Expand Up @@ -51,7 +51,7 @@ def calculate(ctx):
calculate.add_command(get_missing_reads)
calculate.add_command(calculate_amount_ng)
calculate.add_command(calculate_amount_ng_fmol)
calculate.add_command(volume_water)
calculate.add_command(volume_buffer)
calculate.add_command(molar_concentration)
calculate.add_command(calculate_beads)
calculate.add_command(missing_reads_in_pool)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,31 @@
LOG = logging.getLogger(__name__)


def calculate_water_volume(sample_volume: float, sample_volume_limit: float) -> float:
"""Calculates the H20 volume based on the sample volume"""
def calculate_buffer_volume(sample_volume: float, sample_volume_limit: float) -> float:
"""Calculates the buffer volume based on the sample volume"""
return sample_volume_limit - sample_volume if sample_volume < sample_volume_limit else 0.0


def calculate_volumes(artifacts: List[Artifact], sample_volume_limit: float):
"""Calculates water volume and total volume"""
def calculate_volumes(artifacts: List[Artifact], total_volume_udf: str,
volume_udf: str, buffer_udf: str, sample_volume_limit: float):
"""Calculates buffer volume and total volume"""

missing_udfs = 0
high_volume_warning = False
warning_message = ""
for artifact in artifacts:
sample_volume: float = artifact.udf.get("Sample Volume (ul)")
sample_volume: float = artifact.udf.get(volume_udf)
if sample_volume is None:
missing_udfs += 1
continue
h2o_volume = calculate_water_volume(
buffer_volume = calculate_buffer_volume(
sample_volume=sample_volume, sample_volume_limit=sample_volume_limit
)
total_volume = h2o_volume + sample_volume
total_volume = buffer_volume + sample_volume
if total_volume > 100:
high_volume_warning = True
artifact.udf["Volume H2O (ul)"] = h2o_volume
artifact.udf["Total Volume (uL)"] = total_volume
artifact.udf[buffer_udf] = buffer_volume
artifact.udf[total_volume_udf] = total_volume
artifact.put()

if missing_udfs:
Expand All @@ -50,19 +51,23 @@ def calculate_volumes(artifacts: List[Artifact], sample_volume_limit: float):


@click.command()
@options.total_volume_udf()
@options.volume_udf()
@options.buffer_udf()
@options.sample_volume_limit()
@click.pass_context
def volume_water(context: click.Context, sample_volume_limit: float):
"""Water volume calculation."""
def volume_buffer(context: click.Context, total_volume_udf: str, volume_udf: str, buffer_udf: str, sample_volume_limit: float):
"""Buffer volume calculation."""

LOG.info(f"Running {context.command_path} with params: {context.params}")

process = context.obj["process"]

try:
artifacts: List[Artifact] = get_artifacts(process=process, input=False)
calculate_volumes(artifacts=artifacts, sample_volume_limit=sample_volume_limit)
message = "Beads volumes have been calculated."
calculate_volumes(artifacts=artifacts, total_volume_udf=total_volume_udf,
volume_udf=volume_udf, buffer_udf=buffer_udf, sample_volume_limit=sample_volume_limit)
message = "Volumes have been calculated."
LOG.info(message)
click.echo(message)
except LimsError as e:
Expand Down
16 changes: 8 additions & 8 deletions tests/EPPs/udf/calculate/test_calculate_beads.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
calculate_elution_volume,
calculate_volumes,
)
from cg_lims.EPPs.udf.calculate.calculate_water import calculate_water_volume
from cg_lims.EPPs.udf.calculate.calculate_buffer import calculate_buffer_volume
from cg_lims.exceptions import MissingUDFsError
from genologics.entities import Artifact
from genologics.lims import Lims
Expand Down Expand Up @@ -36,11 +36,11 @@ def test_calculate_elution_volume():
(SAMPLE_VOLUME_LIMIT + OFFSET, 0.0),
],
)
def test_calculate_water_volume(sample_volume: float, expected_return_value: float):
def test_calculate_buffer_volume(sample_volume: float, expected_return_value: float):
# GIVEN a sample volume less than, equal to, and greater than SAMPLE_VOLUME_LIMIT

# WHEN calculating the water volume
result = calculate_water_volume(
result = calculate_buffer_volume(
sample_volume=sample_volume, sample_volume_limit=SAMPLE_VOLUME_LIMIT
)

Expand Down Expand Up @@ -106,19 +106,19 @@ def test_calculate_volumes_single_artifact_missing_sample_volume_udf(


@mock.patch("cg_lims.EPPs.udf.calculate.calculate_beads.calculate_elution_volume")
@mock.patch("cg_lims.EPPs.udf.calculate.calculate_water.calculate_water_volume")
@mock.patch("cg_lims.EPPs.udf.calculate.calculate_buffer.calculate_buffer_volume")
@mock.patch("cg_lims.EPPs.udf.calculate.calculate_beads.calculate_beads_volume")
@pytest.mark.parametrize(
"sample_volume, elution_volume, water_volume, beads_volume",
"sample_volume, elution_volume, buffer_volume, beads_volume",
[(20.0, 40.0, 30.0, 100.0)],
)
def test_calculate_volumes_multiple_artifacts_missing_sample_volume_udf(
mock_beads_volume,
mock_water_volume,
mock_buffer_volume,
mock_elution_volume,
sample_volume: float,
elution_volume: float,
water_volume: float,
buffer_volume: float,
beads_volume: float,
lims: Lims,
artifact_1: Artifact,
Expand All @@ -132,7 +132,7 @@ def test_calculate_volumes_multiple_artifacts_missing_sample_volume_udf(
artifacts = [artifact_1, artifact_2]

mock_elution_volume.return_value = elution_volume
mock_water_volume.return_value = water_volume
mock_buffer_volume.return_value = buffer_volume
mock_beads_volume.return_value = beads_volume

# WHEN calculating the volumes
Expand Down
Loading