From 61bd4966359de5cf0cfee1e76001c4ac6354a635 Mon Sep 17 00:00:00 2001 From: idalindegaard Date: Thu, 21 Dec 2023 14:02:57 +0100 Subject: [PATCH 1/8] Update error message for normalization script --- cg_lims/EPPs/udf/calculate/pool_normalization.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cg_lims/EPPs/udf/calculate/pool_normalization.py b/cg_lims/EPPs/udf/calculate/pool_normalization.py index 2f579944..e6aa8fd5 100644 --- a/cg_lims/EPPs/udf/calculate/pool_normalization.py +++ b/cg_lims/EPPs/udf/calculate/pool_normalization.py @@ -54,11 +54,11 @@ def calculate_sample_volume( """Calculate and return the sample volume needed to reach the desired final concentration.""" if final_concentration > sample_concentration: error_message: str = ( - f"The final concentration ({final_concentration} nM) can't be" - f" higher than the original one ({sample_concentration} nM)." + f"The final concentration ({final_concentration} nM) is" + f" higher than the original one ({sample_concentration} nM). No dilution needed." ) - LOG.error(error_message) - raise InvalidValueError(error_message) + LOG.warning(error_message) + return total_volume return (final_concentration * total_volume) / sample_concentration From d6376e45b9ea6fe9e56658961baec56ae1bd6fc0 Mon Sep 17 00:00:00 2001 From: idalindegaard Date: Thu, 21 Dec 2023 14:14:41 +0100 Subject: [PATCH 2/8] test different log levels --- cg_lims/EPPs/udf/calculate/pool_normalization.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cg_lims/EPPs/udf/calculate/pool_normalization.py b/cg_lims/EPPs/udf/calculate/pool_normalization.py index e6aa8fd5..c2a457b5 100644 --- a/cg_lims/EPPs/udf/calculate/pool_normalization.py +++ b/cg_lims/EPPs/udf/calculate/pool_normalization.py @@ -57,7 +57,7 @@ def calculate_sample_volume( f"The final concentration ({final_concentration} nM) is" f" higher than the original one ({sample_concentration} nM). No dilution needed." ) - LOG.warning(error_message) + LOG.error(error_message) return total_volume return (final_concentration * total_volume) / sample_concentration From b637c1616ddea178b6e525ce1288d8069a099565 Mon Sep 17 00:00:00 2001 From: idalindegaard Date: Thu, 4 Jan 2024 13:47:34 +0100 Subject: [PATCH 3/8] fixing error message --- cg_lims/EPPs/udf/calculate/pool_normalization.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/cg_lims/EPPs/udf/calculate/pool_normalization.py b/cg_lims/EPPs/udf/calculate/pool_normalization.py index c2a457b5..8f255f3d 100644 --- a/cg_lims/EPPs/udf/calculate/pool_normalization.py +++ b/cg_lims/EPPs/udf/calculate/pool_normalization.py @@ -10,7 +10,7 @@ from cg_lims.get.artifacts import get_artifacts LOG = logging.getLogger(__name__) - +failed_samples = [] def get_final_concentration(process: Process, final_concentration_udf: str) -> float: """Return final concentration value from process.""" @@ -49,15 +49,21 @@ def get_total_volume(artifact: Artifact, total_volume_udf: str) -> float: def calculate_sample_volume( - final_concentration: float, total_volume: float, sample_concentration: float + final_concentration: float, artifact: Artifact ) -> float: """Calculate and return the sample volume needed to reach the desired final concentration.""" + sample_concentration: float = get_artifact_concentration( + artifact=artifact, concentration_udf=concentration_udf + ) + total_volume: float = get_total_volume(artifact=artifact, total_volume_udf=total_volume_udf) if final_concentration > sample_concentration: error_message: str = ( f"The final concentration ({final_concentration} nM) is" f" higher than the original one ({sample_concentration} nM). No dilution needed." ) LOG.error(error_message) + global failed_samples + failed_samples = failed_samples.append(artifact.samples[0].id) return total_volume return (final_concentration * total_volume) / sample_concentration @@ -119,6 +125,10 @@ def pool_normalization(ctx: click.Context): buffer_volume_udf="Volume Buffer (ul)", concentration_udf="Concentration (nM)", ) + if failed_samples: + error_message = f"The following samples had a lower concentration than targeted: {failed_samples}" + LOG.info(error_message) + raise InvalidValueError(error_message) message: str = "Volumes were successfully calculated." LOG.info(message) click.echo(message) From ea7e82bd06a2369be77ed801d6585d8e92595dfa Mon Sep 17 00:00:00 2001 From: idalindegaard Date: Thu, 4 Jan 2024 13:55:05 +0100 Subject: [PATCH 4/8] fixed bug --- cg_lims/EPPs/udf/calculate/pool_normalization.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cg_lims/EPPs/udf/calculate/pool_normalization.py b/cg_lims/EPPs/udf/calculate/pool_normalization.py index 8f255f3d..803e1013 100644 --- a/cg_lims/EPPs/udf/calculate/pool_normalization.py +++ b/cg_lims/EPPs/udf/calculate/pool_normalization.py @@ -49,7 +49,7 @@ def get_total_volume(artifact: Artifact, total_volume_udf: str) -> float: def calculate_sample_volume( - final_concentration: float, artifact: Artifact + final_concentration: float, artifact: Artifact, total_volume_udf: str ) -> float: """Calculate and return the sample volume needed to reach the desired final concentration.""" sample_concentration: float = get_artifact_concentration( @@ -88,14 +88,10 @@ def set_artifact_volumes( ) -> None: """Set volume UDFs on artifact level, given a list of artifacts, final concentration, and UDF names.""" for artifact in artifacts: - concentration: float = get_artifact_concentration( - artifact=artifact, concentration_udf=concentration_udf - ) - total_volume: float = get_total_volume(artifact=artifact, total_volume_udf=total_volume_udf) sample_volume: float = calculate_sample_volume( final_concentration=final_concentration, - total_volume=total_volume, - sample_concentration=concentration, + artifact=artifact, + total_volume_udf=total_volume_udf, ) buffer_volume: float = calculate_buffer_volume( total_volume=total_volume, sample_volume=sample_volume From 6657fa59947adb168c71258974b9f849eff72e6f Mon Sep 17 00:00:00 2001 From: idalindegaard Date: Thu, 4 Jan 2024 13:57:06 +0100 Subject: [PATCH 5/8] fixed another bug --- cg_lims/EPPs/udf/calculate/pool_normalization.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cg_lims/EPPs/udf/calculate/pool_normalization.py b/cg_lims/EPPs/udf/calculate/pool_normalization.py index 803e1013..2631ce9f 100644 --- a/cg_lims/EPPs/udf/calculate/pool_normalization.py +++ b/cg_lims/EPPs/udf/calculate/pool_normalization.py @@ -49,7 +49,7 @@ def get_total_volume(artifact: Artifact, total_volume_udf: str) -> float: def calculate_sample_volume( - final_concentration: float, artifact: Artifact, total_volume_udf: str + final_concentration: float, artifact: Artifact, total_volume_udf: str, concentration_udf: str ) -> float: """Calculate and return the sample volume needed to reach the desired final concentration.""" sample_concentration: float = get_artifact_concentration( @@ -92,6 +92,7 @@ def set_artifact_volumes( final_concentration=final_concentration, artifact=artifact, total_volume_udf=total_volume_udf, + concentration_udf=concentration_udf, ) buffer_volume: float = calculate_buffer_volume( total_volume=total_volume, sample_volume=sample_volume From 502aed087a0efabfd0908919a03b46e5d849ebe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Sv=C3=A4rd?= Date: Thu, 4 Jan 2024 14:06:24 +0100 Subject: [PATCH 6/8] this time it will work --- .../EPPs/udf/calculate/pool_normalization.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cg_lims/EPPs/udf/calculate/pool_normalization.py b/cg_lims/EPPs/udf/calculate/pool_normalization.py index 2631ce9f..d2d2f933 100644 --- a/cg_lims/EPPs/udf/calculate/pool_normalization.py +++ b/cg_lims/EPPs/udf/calculate/pool_normalization.py @@ -12,6 +12,7 @@ LOG = logging.getLogger(__name__) failed_samples = [] + def get_final_concentration(process: Process, final_concentration_udf: str) -> float: """Return final concentration value from process.""" final_concentration: Optional[float] = process.udf.get(final_concentration_udf) @@ -49,13 +50,9 @@ def get_total_volume(artifact: Artifact, total_volume_udf: str) -> float: def calculate_sample_volume( - final_concentration: float, artifact: Artifact, total_volume_udf: str, concentration_udf: str + final_concentration: float, total_volume: float, sample_concentration: float, artifact: Artifact ) -> float: """Calculate and return the sample volume needed to reach the desired final concentration.""" - sample_concentration: float = get_artifact_concentration( - artifact=artifact, concentration_udf=concentration_udf - ) - total_volume: float = get_total_volume(artifact=artifact, total_volume_udf=total_volume_udf) if final_concentration > sample_concentration: error_message: str = ( f"The final concentration ({final_concentration} nM) is" @@ -88,11 +85,15 @@ def set_artifact_volumes( ) -> None: """Set volume UDFs on artifact level, given a list of artifacts, final concentration, and UDF names.""" for artifact in artifacts: + sample_concentration: float = get_artifact_concentration( + artifact=artifact, concentration_udf=concentration_udf + ) + total_volume: float = get_total_volume(artifact=artifact, total_volume_udf=total_volume_udf) sample_volume: float = calculate_sample_volume( final_concentration=final_concentration, artifact=artifact, - total_volume_udf=total_volume_udf, - concentration_udf=concentration_udf, + total_volume=total_volume, + sample_concentration=sample_concentration, ) buffer_volume: float = calculate_buffer_volume( total_volume=total_volume, sample_volume=sample_volume @@ -123,7 +124,9 @@ def pool_normalization(ctx: click.Context): concentration_udf="Concentration (nM)", ) if failed_samples: - error_message = f"The following samples had a lower concentration than targeted: {failed_samples}" + error_message = ( + f"The following samples had a lower concentration than targeted: {failed_samples}" + ) LOG.info(error_message) raise InvalidValueError(error_message) message: str = "Volumes were successfully calculated." From 3d6b655d97513738d0eaada4ebd9725494494f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Sv=C3=A4rd?= Date: Thu, 4 Jan 2024 14:14:50 +0100 Subject: [PATCH 7/8] or this time --- cg_lims/EPPs/udf/calculate/pool_normalization.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cg_lims/EPPs/udf/calculate/pool_normalization.py b/cg_lims/EPPs/udf/calculate/pool_normalization.py index d2d2f933..452380cc 100644 --- a/cg_lims/EPPs/udf/calculate/pool_normalization.py +++ b/cg_lims/EPPs/udf/calculate/pool_normalization.py @@ -55,12 +55,12 @@ def calculate_sample_volume( """Calculate and return the sample volume needed to reach the desired final concentration.""" if final_concentration > sample_concentration: error_message: str = ( - f"The final concentration ({final_concentration} nM) is" - f" higher than the original one ({sample_concentration} nM). No dilution needed." + f"The final concentration ({final_concentration} nM) is higher than the original one" + f" ({sample_concentration} nM) for sample {artifact.samples[0].id}. No dilution needed." ) LOG.error(error_message) global failed_samples - failed_samples = failed_samples.append(artifact.samples[0].id) + failed_samples.append(artifact.samples[0].id) return total_volume return (final_concentration * total_volume) / sample_concentration From 86dbf484c9f814bcb09d2e8a72a8818b9d437c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Sv=C3=A4rd?= Date: Thu, 4 Jan 2024 15:44:04 +0100 Subject: [PATCH 8/8] improved error msg --- cg_lims/EPPs/udf/calculate/pool_normalization.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/cg_lims/EPPs/udf/calculate/pool_normalization.py b/cg_lims/EPPs/udf/calculate/pool_normalization.py index 452380cc..767cb1e2 100644 --- a/cg_lims/EPPs/udf/calculate/pool_normalization.py +++ b/cg_lims/EPPs/udf/calculate/pool_normalization.py @@ -60,7 +60,7 @@ def calculate_sample_volume( ) LOG.error(error_message) global failed_samples - failed_samples.append(artifact.samples[0].id) + failed_samples.append(artifact.name) return total_volume return (final_concentration * total_volume) / sample_concentration @@ -124,9 +124,8 @@ def pool_normalization(ctx: click.Context): concentration_udf="Concentration (nM)", ) if failed_samples: - error_message = ( - f"The following samples had a lower concentration than targeted: {failed_samples}" - ) + failed_samples_string = ", ".join(failed_samples) + error_message = f"The following artifacts had a lower concentration than targeted: {failed_samples_string}" LOG.info(error_message) raise InvalidValueError(error_message) message: str = "Volumes were successfully calculated."