Title: | A Grammar of Plates |
---|---|
Description: | `gplate` attempts to provide a succinct yet powerful grammar to describe common microwell layouts to aide in both plotting and tidying. |
Authors: | Kai Aragaki [aut, cre] |
Maintainer: | Kai Aragaki <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.2.0 |
Built: | 2024-11-03 06:07:21 UTC |
Source: | https://github.com/KaiAragaki/gplate |
gp
well data relative to user supplied start_corner
Arrange gp
well data relative to user supplied start_corner
arrange_by_dim(gp, dim)
arrange_by_dim(gp, dim)
gp |
A |
dim |
Character. Either "row" or "col" |
A gp
with gp$well_data
arranged by dim and the non-dim (ie if dim
= "row", the 'non-dim' is "col") relative to the start corner (start corner
is at the top, farther from start corner is at bottom)
Coerce object to gp
as_gp(x, ...) ## Default S3 method: as_gp(x, ...) ## S3 method for class 'list' as_gp(x, ...)
as_gp(x, ...) ## Default S3 method: as_gp(x, ...) ## S3 method for class 'list' as_gp(x, ...)
x |
Object to coerce |
... |
Unused |
Create a dimension pattern 'unit' of a section
coordinate(gp, type = c("row", "col"), margin)
coordinate(gp, type = c("row", "col"), margin)
gp |
a |
type |
Character. Either 'row' or 'col'. |
margin |
Named list of integers defining the size of margins at each edge. |
a tibble
A 8x12 matrix of random integers 1-10
example_plate
example_plate
An object of class matrix
(inherits from array
) with 8 rows and 12 columns.
Take a set of numbers and flip them around on a number line
flip_dim(gp, dim)
flip_dim(gp, dim)
gp |
A |
dim |
Symbol. Column to flip. Should be the name of a column that exists in |
This assumes the beginning is 1 and the end is maximum length of the
dimension. Note that this does NOT simply check the maximum value of the
supplied vector, but searches the supplied gp
for a matching ndim
column
that definitively tells how long the given dimension is supposed to be. This
is important, as sometimes a dimension is given that is longer than its
parent dimension, so the maximum numbers would not show in the vector.
A vector.
Make a gp object
gp(rows = NULL, cols = NULL, data = NULL, wells = NULL, tidy = FALSE)
gp(rows = NULL, cols = NULL, data = NULL, wells = NULL, tidy = FALSE)
rows |
Numeric. The number of rows the plate should have. |
cols |
Numeric. The number of columns the plate should have. |
data |
An optional data.frame of well data the same dimensions as the plate to be described |
wells |
Numeric. The number of wells the plate has. If this is specified, rows and cols must be null - they are inferred from common form factors of plates. |
tidy |
Are the data supplied tidy? |
A gp
object has the following components:
nrow
/ncol
: Number of plate rows/cols. This is static and will not be
changed by adding layers.
well_data
: Somewhat transient data used to define plotting coordinates
for layers. See below for more information.
nrow_sec
/ncols_sec
: The number of rows/cols of the current section.
When creating a plate, that number is the number of rows/cols of the plate
(the plate is the section). Can take on a 'mar' suffix, which specifies the
number including margins (if any)
nrow_sec_par
/ncol_sec_par
: The number of rows/cols of the parent
section. When creating a plate, it has no parent, so defaults to being its
own parent. Can take on a 'mar' suffix. See above.
well_data
consists of many columns. The variable names can be broken down
as follows:
row
/col
: row
is always the y axis, col
is always the x axis. By
convention, plates start at 1, 1 in the top left corner.
sec
: Short for 'section'. A section is a rectangular field of wells.
sec
alone refers to the number of the section itself. sec
combined with
row
or col
(eg row_sec
) refers to the coordinates of a given well
relative to it's section corners, with the top left corner of a given section
always being (1, 1).
par
: Short for 'parent'. These columns are all the data from the previous
layer.
index
: These specify (usually) multiwell strips only defined in one
dimension. Together, index_row
and index_col
form
checkerboard-like patterns, where each intersection is a section.
This is a bit more complicated when wrap = TRUE
, so the simile
does not hold for all cases.
a gp
object
# If you specify wells, rows and columns are derived # from a standard plate sizes: gp(wells = 96) # As such, you cannot use the wells argument # if you want to create more exotic plates: try(gp(wells = 102)) # For that, you'll need to specify wells and cols: gp(rows = 6, cols = 17)
# If you specify wells, rows and columns are derived # from a standard plate sizes: gp(wells = 96) # As such, you cannot use the wells argument # if you want to create more exotic plates: try(gp(wells = 102)) # For that, you'll need to specify wells and cols: gp(rows = 6, cols = 17)
Slice out a smaller gp from a gp via coordinates
gp_excise(gp, top, left, bottom, right)
gp_excise(gp, top, left, bottom, right)
gp |
A |
top , left , bottom , right
|
Integer. The coordinates of the corners. Remember that TOP left is (1, 1) |
A gp
with top left coords = (1, 1)
gplate::example_plate |> as_gp() |> gp_excise(2, 2, 4, 4)
gplate::example_plate |> as_gp() |> gp_excise(2, 2, 4, 4)
A theme for making little in-line plots
gp_mini_theme()
gp_mini_theme()
A ggplot2
theme
gp
objectPlot a gp
object
gp_plot(x, name = .sec, ...) ## S3 method for class 'gp' gp_plot(x, name = .sec, ...) ## S3 method for class 'data.frame' gp_plot(x, name = .sec, ...)
gp_plot(x, name = .sec, ...) ## S3 method for class 'gp' gp_plot(x, name = .sec, ...) ## S3 method for class 'data.frame' gp_plot(x, name = .sec, ...)
x |
A |
name |
Symbol. Name of a column in |
... |
Additional arguments to be passed to |
a ggplot
gp(16, 24) |> gp_plot(.row)
gp(16, 24) |> gp_plot(.row)
gp
object.Add a section to a gp
object.
gp_sec(gp, ...) ## S3 method for class 'gp' gp_sec( gp, name, nrow = NULL, ncol = NULL, labels = NULL, start_corner = c("tl", "tr", "bl", "br"), flow = c("row", "col"), margin = 0, wrap = FALSE, break_sections = TRUE, advance = TRUE )
gp_sec(gp, ...) ## S3 method for class 'gp' gp_sec( gp, name, nrow = NULL, ncol = NULL, labels = NULL, start_corner = c("tl", "tr", "bl", "br"), flow = c("row", "col"), margin = 0, wrap = FALSE, break_sections = TRUE, advance = TRUE )
gp |
A |
name |
Character. Name of the section. |
nrow |
Numeric. Section height. If |
ncol |
Numeric. Section width. If |
labels |
Optional. What should the labels of each section be? |
start_corner |
Corner of section to place first item. |
flow |
Direction that subsequent items should be placed relative to first corner. |
margin |
Border width outside the section that will be unfilled. Can take an argument of one (same border all around), two (top/bottom, left/right), three (top, left/right, bottom), or four (top, right, bottom, left). |
wrap |
Should the sections that go off the edge continue on the next row/column? |
break_sections |
Should partial sections be allowed? |
advance |
Should this section be a child or sibling of the one before it? If TRUE (default), it will be a child. |
a gp
gp(16, 24) |> gp_sec("section 1", ncol = 3) pq <- gp(8, 12, protein_quant) |> gp_sec("has_sample", 3, 19, wrap = TRUE, labels = "sample") # Sections can be used to label things for tidying pq |> gp_serve() # They can also be used for plotting: pq |> gp_plot(has_sample)
gp(16, 24) |> gp_sec("section 1", ncol = 3) pq <- gp(8, 12, protein_quant) |> gp_sec("has_sample", 3, 19, wrap = TRUE, labels = "sample") # Sections can be used to label things for tidying pq |> gp_serve() # They can also be used for plotting: pq |> gp_plot(has_sample)
Extract useful, tidy data from a gp object
gp_serve(gp)
gp_serve(gp)
gp |
a gp |
a tibble
, with .row
and .col
, as well as any created section names and data values.
gp(16, 24) |> gp_sec("my_sec", nrow = 9, ncol = 7, labels = c("sample_1", "sample_2", "sample_3")) |> gp_serve()
gp(16, 24) |> gp_sec("my_sec", nrow = 9, ncol = 7, labels = c("sample_1", "sample_2", "sample_3")) |> gp_serve()
Turn data from 'plate form' to 'tidy form' and back
gp_unravel(df, rownames = NULL) gp_reravel(df, row_name = ".row", col_name = ".col", values = "value")
gp_unravel(df, rownames = NULL) gp_reravel(df, row_name = ".row", col_name = ".col", values = "value")
df |
The |
rownames |
Optional character. If there is a colname that specifies the row index, it will be arranged by this column, then dropped. |
a tibble
test_plate <- matrix(sample(1:10, 96, replace = TRUE), nrow = 8, ncol = 12) gp_unravel(test_plate)
test_plate <- matrix(sample(1:10, 96, replace = TRUE), nrow = 8, ncol = 12) gp_unravel(test_plate)
data.frame
into a gp
An opposite to serve()
gp_unserve(x, row = ".row", col = ".col", nrow = NULL, ncol = NULL)
gp_unserve(x, row = ".row", col = ".col", nrow = NULL, ncol = NULL)
x |
A tidy |
row |
Character. The column that represents the rows. Should be numeric, with the lowest number representing the topmost row. |
col |
Character. The name of the column that represents columns. Should be numeric, with the lowest number representing the leftmost column. |
nrow |
Optional numeric, denoting the number of rows in the plate. If not supplied, will be imputed from the largest number in the 'row' column |
ncol |
Optional numeric, denoting the number of columns in the plate. If not supplied, will be imputed from the largest number in the 'col' column |
a gp
'Forwards' is thought of 'left to right' when thinking about moving across columns and 'top to bottom' when moving across rows
is_fwd(gp, dim)
is_fwd(gp, dim)
gp |
A |
dim |
Character. A dimension, either "row" or "col". |
logical.
A constructor for a gp object
new_gp(nrow = 1L, ncol = 1L, data = data.frame(), tidy = FALSE)
new_gp(nrow = 1L, ncol = 1L, data = data.frame(), tidy = FALSE)
nrow |
Integer. Number of rows of the plate. |
ncol |
Integer. Number of columns of the plate. |
data |
An optional dataframe including plate data |
tidy |
Is the supplied data already tidy, or should it be tidied? |
a gp
object
new_gp(nrow = 8L, ncol = 16L)
new_gp(nrow = 8L, ncol = 16L)
Recycle a df a non-integer number of times
non_int_replicate(df, measure)
non_int_replicate(df, measure)
df |
|
measure |
Length-out of replication (not number of times). Can be a numeric, a vector, or a df. If a df, will use number of rows. If a vector, will use length. |
a data.frame
with nrow measure
Data from a PCR experiment on a 384-well plate
pcr_plate
pcr_plate
An object of class matrix
(inherits from array
) with 16 rows and 24 columns.
Standard plate formats for microwell plates
plate_formats
plate_formats
An object of class data.frame
with 9 rows and 3 columns.
Data from a protein quantification assay in a 96-well plate. See the "Using gp to wrangle plate data" vignette for more details
protein_quant
protein_quant
An object of class matrix
(inherits from array
) with 8 rows and 12 columns.
flip_dim
if necessaryPerforms flip_dim
if necessary
rel_dim(gp, dim, rel)
rel_dim(gp, dim, rel)
gp |
A |
dim |
Symbol. Column to conditionally flip. Should be the name of a column that exists in |
rel |
Character. Column to check |
A vector that is flipped (see flip_dim
) if rel
is backwards (see is_fwd
)
Repeat one dimension of a child section across a dimension of a parent section
unroll_sec_dim_along_parent(gp, dim, wrap)
unroll_sec_dim_along_parent(gp, dim, wrap)
gp |
A |
dim |
Either "row" or "col" |
wrap |
Logical. Should this dimension wrap around when it hits a section boundary? |
A gp
Extract well data from an object
well_data(x, ...) ## S3 method for class 'gp' well_data(x, ...)
well_data(x, ...) ## S3 method for class 'gp' well_data(x, ...)
x |
An object to be passed to its respective method |
... |
Additional arguments (unused) |
A tibble
containing the well data of the object
Calculate wells of gp object
wells(x, ...) ## S3 method for class 'gp' wells(x, ...)
wells(x, ...) ## S3 method for class 'gp' wells(x, ...)
x |
a |
... |
Unused |