library(designit)
library(ggplot2)
library(dplyr)
library(tidyr)
In some cases it may be essential to avoid samples of the same group being put into the same row or column on a plate, i.e. these variables are regarded as factor levels of their own, in addition to the spatial relation of the samples.
Plate scoring functions can use an specific penalty for these ‘linearly arranged’ samples on top of the distance metrics chosen.
# Setting up the batch container
example5 <- BatchContainer$new(
dimensions = c(
plate = 1, row = 8, col = 12
)
)
# Assign samples randomly to start from lower score (avoid `Inf` values when doing the 'hard' penalization)
example5 <- assign_random(example5, samples = tibble::tibble(
Group = rep.int(paste("Group", 1:5), times = c(8, 8, 8, 8, 64)),
ID = 1:96
))
penalize_lines <- "hard"
scoring_f <- c(
Group = mk_plate_scoring_functions(example5, row = "row", column = "col", group = "Group", p = 2, penalize_lines = penalize_lines)
)
example5$score(scoring_f)
#> Group.Plate
#> 10.78471
set.seed(42)
bc <- optimize_design(
example5,
scoring = scoring_f,
max_iter = 5000,
n_shuffle = 1,
acceptance_func = mk_simanneal_acceptance_func(mk_simanneal_temp_func(T0 = 500, alpha = 0.1)),
quiet = T
)
bc$trace$elapsed
#> Time difference of 19.83435 secs
bc$score(scoring_f)
#> Group.Plate
#> 8.861759
plot_plate(bc, plate = plate, row = row, column = col, .color = Group, title = stringr::str_c("Line penalization: ", penalize_lines))