diff --git a/cg_lims/EPPs/udf/calculate/base.py b/cg_lims/EPPs/udf/calculate/base.py index 130a51a1..5f4edd97 100644 --- a/cg_lims/EPPs/udf/calculate/base.py +++ b/cg_lims/EPPs/udf/calculate/base.py @@ -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.library_normalization import library_normalization @@ -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) diff --git a/cg_lims/EPPs/udf/calculate/calculate_water.py b/cg_lims/EPPs/udf/calculate/calculate_buffer.py similarity index 58% rename from cg_lims/EPPs/udf/calculate/calculate_water.py rename to cg_lims/EPPs/udf/calculate/calculate_buffer.py index ee32c50c..d0364754 100644 --- a/cg_lims/EPPs/udf/calculate/calculate_water.py +++ b/cg_lims/EPPs/udf/calculate/calculate_buffer.py @@ -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: @@ -50,10 +51,13 @@ 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}") @@ -61,8 +65,9 @@ def volume_water(context: click.Context, sample_volume_limit: float): 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: diff --git a/tests/EPPs/udf/calculate/test_calculate_beads.py b/tests/EPPs/udf/calculate/test_calculate_beads.py index b98be2ec..95d313f9 100644 --- a/tests/EPPs/udf/calculate/test_calculate_beads.py +++ b/tests/EPPs/udf/calculate/test_calculate_beads.py @@ -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 @@ -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 ) @@ -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, @@ -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