BatchContainer {designit} | R Documentation |
R6 Class representing a batch container.
Description
Describes container dimensions and samples to container location assignment.
Details
A typical workflow starts with creating a BatchContainer
. Then
samples can be assigned to locations in that container.
Public fields
trace
Optimization trace, a
tibble::tibble()
Active bindings
scoring_f
Scoring functions used for optimization. Each scoring function should receive a BatchContainer. This function should return a floating point score value for the assignment. This a list of functions. Upon assignment a single function will be automatically converted to a list In the later case each function is called.
has_samples
Returns TRUE if
BatchContainer
has samples.has_samples_attr
Returns TRUE if
BatchContainer
has sample atrributes assigned.n_locations
Returns number of locations in a
BatchContainer
.n_dimensions
Returns number of dimensions in a
BatchContainer
. This field cannot be assigned.dimension_names
character vector with dimension names. This field cannot be assigned.
samples
Samples in the batch container. When assigning data.frame should not have column named .sample_id column.
samples_attr
Extra attributes of samples. If set, this is included into
BatchContainer$get_samples()
output.assignment
Sample assignment vector. Should contain NAs for empty locations.
Assigning this field is deprecated, please use
$move_samples()
instead.
Methods
Public methods
Method new()
Create a new BatchContainer object.
Usage
BatchContainer$new(locations_table, dimensions, exclude = NULL)
Arguments
locations_table
A table with available locations.
dimensions
A vector or list of dimensions. Every dimension should have a name. Could be an integer vector of dimensions or a named list. Every value of a list could be either dimension size or parameters for BatchContainerDimension$new(). Can be used as an alternative to passing
locations_table
.exclude
data.frame with excluded locations of a container. Only used together with dimensions.
Examples
bc <- BatchContainer$new( dimensions = list( "plate" = 3, "row" = list(values = letters[1:3]), "column" = list(values = c(1, 3)) ), exclude = data.frame(plate = 1, row = "a", column = c(1, 3), stringsAsFactors = FALSE) ) bc
Method get_samples()
Return table with samples and sample assignment.
Usage
BatchContainer$get_samples( assignment = TRUE, include_id = FALSE, remove_empty_locations = FALSE, as_tibble = TRUE )
Arguments
assignment
Return sample assignment. If FALSE, only samples table is returned, with out batch assignment.
include_id
Keep .sample_id in the table. Use
TRUE
for lower overhead.remove_empty_locations
Removes empty locations from the result tibble.
as_tibble
Return
tibble
. IfFALSE
returnsdata.table
. This should have lower overhead, as internally there is a cacheddata.table
.
Returns
table with samples and sample assignment.
Method get_locations()
Get a table with all the locations in a BatchContainer
.
Usage
BatchContainer$get_locations()
Returns
A tibble
with all the available locations.
Method move_samples()
Move samples between locations
This method can receive either src
and dst
or locations_assignment
.
Usage
BatchContainer$move_samples(src, dst, location_assignment)
Arguments
src
integer vector of source locations
dst
integer vector of destination locations (the same length as
src
).location_assignment
integer vector with location assignment. The length of the vector should match the number of locations,
NA
should be used for empty locations.
Returns
BatchContainer
, invisibly
Method score()
Score current sample assignment,
Usage
BatchContainer$score(scoring)
Arguments
scoring
a function or a names list of scoring functions. Each function should return a numeric vector.
Returns
Returns a named vector of all scoring functions values.
Method copy()
Create an independent copy (clone) of a BatchContainer
Usage
BatchContainer$copy()
Returns
Returns a new BatchContainer
Method print()
Prints information about BatchContainer
.
Usage
BatchContainer$print(...)
Arguments
...
not used.
Method scores_table()
Return a table with scores from an optimization.
Usage
BatchContainer$scores_table(index = NULL, include_aggregated = FALSE)
Arguments
index
optimization index, all by default
include_aggregated
include aggregated scores
Returns
a tibble::tibble()
with scores
Method plot_trace()
Plot trace
Usage
BatchContainer$plot_trace(index = NULL, include_aggregated = FALSE, ...)
Arguments
index
optimization index, all by default
include_aggregated
include aggregated scores
...
not used.
Returns
a ggplot2::ggplot()
object
List of scoring functions.
Tibble with batch container locations.
Tibble with sample information and sample ids.
Sample attributes, a data.table.
Vector with assignment of sample ids to locations.
Cached data.table with samples assignment.
Validate sample assignment.
Examples
## ------------------------------------------------
## Method `BatchContainer$new`
## ------------------------------------------------
bc <- BatchContainer$new(
dimensions = list(
"plate" = 3,
"row" = list(values = letters[1:3]),
"column" = list(values = c(1, 3))
),
exclude = data.frame(plate = 1, row = "a", column = c(1, 3), stringsAsFactors = FALSE)
)
bc