From 20a139ebda80fea255a7a161383f7e3e5e21d440 Mon Sep 17 00:00:00 2001 From: Charles Plessy Date: Tue, 26 Sep 2023 17:04:46 +0900 Subject: [PATCH] Fix add option and symmetric pairwise dispensing. Add a private `set_block_` function to ease debugging. --- R/dispensing.R | 4 ++-- R/plates.R | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/R/dispensing.R b/R/dispensing.R index 9345d3e..0a14020 100644 --- a/R/dispensing.R +++ b/R/dispensing.R @@ -54,11 +54,11 @@ dispense_pairs <- function (plate, set1, set2 = set1, volume, start = "A01") { } for (Nth in seq_along(set1)) { - plate <- set_block(plate, dispense_pairs_first(Nth), set1[Nth], volume) + plate <- set_block(plate, dispense_pairs_first(Nth), set1[Nth], volume, add = TRUE) } for (Nth in seq_along(set2)) { - plate <- set_block(plate, dispense_pairs_second(Nth), set2[Nth], volume) + plate <- set_block(plate, dispense_pairs_second(Nth), set2[Nth], volume, add = TRUE) } plate diff --git a/R/plates.R b/R/plates.R index ef98a52..6a5ca25 100644 --- a/R/plates.R +++ b/R/plates.R @@ -379,15 +379,16 @@ setMethod( "setWell", c("Plate", "Well", "character", "logical") setGeneric("set_block", function(plate, block, what, value, add = FALSE) standardGeneric("set_block")) -#' @rdname set_block -#' @export - -setMethod( "set_block", c("Plate", "character", "character", "numeric") - , function(plate, block, what, value, add) { +set_block_ <- function(plate, block, what, value, add) { plate$well <- rownames(plate) if (isTRUE(add)) { - oldVolumes <- plate[,what] - oldVolumes[is.na(oldVolumes)] <- 0 + if(what %in% colnames(plate)) { + oldVolumes <- plate[,what] + oldVolumes[is.na(oldVolumes)] <- 0 + } else { + oldVolumes <- 0 + } + plate[,what] <- 0 plate <- platetools::set_block(plate, block, what, value) plate[,what] <- plate[,what] + oldVolumes } else { @@ -395,7 +396,15 @@ setMethod( "set_block", c("Plate", "character", "character", "numeric") } plate$well <- NULL plate -}) +} + + +#' @rdname set_block +#' @export + +setMethod( "set_block" + , c("Plate", "character", "character", "numeric") + , set_block_) #' Get reagent name #'