Skip to content

Commit

Permalink
Creates display_plate_qpcr function. Update vignettes, docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DimmestP committed May 4, 2022
1 parent f707c5c commit bd482f2
Show file tree
Hide file tree
Showing 18 changed files with 94 additions and 54 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export(create_rowkey_4_in_16)
export(create_rowkey_8_in_16_plain)
export(debaseline)
export(display_plate)
export(display_plate_qpcr)
export(display_well_value)
export(label_plate_rowcol)
export(make_row_names_echo1536)
Expand Down
73 changes: 49 additions & 24 deletions R/plate_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -375,27 +375,19 @@ label_plate_rowcol <- function(plate,
}


#' Display plate plan with sample_id, target_id, prep_type per well
#' Display an empty plate plan which can be populated with
#' ggplot2 geom elements.
#'
#' @param plate tibble with variables well_col, well_row, sample_id, target_id,
#' prep_type. Output from label_plate_rowcol.
#' @param plate tibble with variables well_col, well_row.
#'
#' @return ggplot object; major output is to plot it
#'
#' @examples
#' library(dplyr)
#'
#' # create basic 384 well plate
#' basic_plate <- label_plate_rowcol(create_blank_plate(),
#' create_rowkey_8_in_16_plain(target_id = c("T_1", "T_2",
#' "T_3", "T_4",
#' "T_5", "T_6",
#' "T_7", "T_8")),
#' create_colkey_6diln_2ctrl_in_24() %>%
#' mutate(sample_id = paste0(dilution_nice, "_", tech_rep)))
#' @examples
#' library(ggplot2)
#'
#' # display full plate
#' display_plate(basic_plate)
#' # display wells of empty plate
#' display_plate(create_blank_plate_1536well()) +
#' geom_tile(aes(fill = well_row), colour = "black")
#'
#' @family plate creation functions
#'
Expand All @@ -412,14 +404,6 @@ display_plate <- function(plate) {
ggplot2::ggplot(data = plate,
ggplot2::aes(x = as_factor(.data$well_col),
y = as_factor(.data$well_row))) +
ggplot2::geom_tile(ggplot2::aes(fill = .data$target_id),
alpha = 0.3) +
ggplot2::geom_text(ggplot2::aes(label =
paste(.data$target_id,
.data$sample_id,
.data$prep_type,
sep = "\n")),
size = 2.5, lineheight = 1) +
ggplot2::scale_x_discrete(expand = c(0, 0)) +
ggplot2::scale_y_discrete(expand = c(0, 0),
limits = rev(rowlevels)) +
Expand All @@ -432,6 +416,47 @@ display_plate <- function(plate) {
panel.border = ggplot2::element_blank())
}

#' Display qPCR plate plan with sample_id, target_id, prep_type per well
#'
#' @param plate tibble with variables well_col, well_row, sample_id, target_id,
#' prep_type. Output from label_plate_rowcol.
#'
#' @return ggplot object; major output is to plot it
#'
#' @examples
#' library(dplyr)
#'
#' # create basic 384 well plate
#' basic_plate <- label_plate_rowcol(create_blank_plate(),
#' create_rowkey_8_in_16_plain(target_id = c("T_1", "T_2",
#' "T_3", "T_4",
#' "T_5", "T_6",
#' "T_7", "T_8")),
#' create_colkey_6diln_2ctrl_in_24() %>%
#' mutate(sample_id = paste0(dilution_nice, "_", tech_rep)))
#'
#' # display full plate
#' display_plate_qpcr(basic_plate)
#'
#' @family plate creation functions
#'
#' @export
#' @importFrom forcats as_factor
#' @importFrom rlang .data
#'
display_plate_qpcr <- function(plate) {

display_plate(plate) +
ggplot2::geom_tile(ggplot2::aes(fill = .data$target_id),
alpha = 0.3) +
ggplot2::geom_text(ggplot2::aes(label =
paste(.data$target_id,
.data$sample_id,
.data$prep_type,
sep = "\n")),
size = 2.5, lineheight = 1)
}

#' Display the value of each well across the plate.
#'
#' Plots the plate with each well coloured by its value. Example values are Cq, Delta Cq or Delta Delta Cq.
Expand Down
1 change: 1 addition & 0 deletions man/create_blank_plate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/create_colkey_4diln_2ctrl_in_24.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/create_colkey_6_in_24.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/create_colkey_6diln_2ctrl_in_24.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/create_rowkey_4_in_16.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/create_rowkey_8_in_16_plain.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 10 additions & 16 deletions man/display_plate.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/display_well_value.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/label_plate_rowcol.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/make_row_names_echo1536.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/make_row_names_lc1536.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion tests/testthat/test-plate_functions.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# Units test for displaying a blank 1536 well

### Test functions give expected output ###

test_that("functions for displaying a blank 1536 well works", {
blank_plate_schematic <- display_plate(create_blank_plate_1536well())

expect_true(ggplot2::is.ggplot(blank_plate_schematic))
})

# Units test for creating, labeling and displaying a 384 well,
# primer calibration plate with 4 * dilution

Expand Down Expand Up @@ -73,7 +83,7 @@ test_that("functions for creating a 384 well, primer calibration plate work with
calculated_rowkey,
calculated_colkey)

calculated_plate_schematic <- display_plate(calculated_labeled_384_plate)
calculated_plate_schematic <- display_plate_qpcr(calculated_labeled_384_plate)

expect_equal(calculated_colkey,
simulated_colkey)
Expand Down
2 changes: 1 addition & 1 deletion vignettes/calibration_vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ plate1plan %>%
This can be printed out to facilitate loading the plate correctly.

```{r display_plates,fig.height=8,fig.width=12,dependson="label_plates"}
display_plate(plate1plan)
display_plate_qpcr(plate1plan)
```


Expand Down
6 changes: 3 additions & 3 deletions vignettes/deltacq_96well_vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -133,13 +133,13 @@ Again, we print the table to check that the columns and data are correct.

## Display the plate layout

It is easier to understand pictures than tables of text. To display the layout of samples within a microplate, tidyqpcr has a function `display_plate`. We use that here to show how the samples are laid out within the plate.
It is easier to understand pictures than tables of text. To display the layout of samples within a microplate, tidyqpcr has a function `display_plate_qpcr`. We use that here to show how the samples are laid out within the plate.

```{r display_plates,fig.height=6,fig.width=9,dependson="add_sample_target_data"}
display_plate(plate_cq_data)
display_plate_qpcr(plate_cq_data)
```

Here, the different colours indicate different `target_ids`, which is default behaviour of `display_plate`. This display makes it possible to see that there are three identically-labeled wells - technical replicates - in a row.
Here, the different colours indicate different `target_ids`, which is default behaviour of `display_plate_qpcr`. This display makes it possible to see that there are three identically-labeled wells - technical replicates - in a row.

## Plot unnormalized Cq data

Expand Down
6 changes: 3 additions & 3 deletions vignettes/multifactor_vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ plateplan <-
)
```

Display the plate plan using display_plate.
Display the plate plan using display_plate_qpcr.

```{r display_plates,fig.height=9,fig.width=10,dependson="label_plates"}
display_plate(plateplan %>%
display_plate_qpcr(plateplan %>%
mutate(sample_id = condition))
```

Note that display_plate requires a column called `sample_id`, which here we had to make from the `condition` variable using `mutate(sample_id=condition)`. The reason for doing this is that we have replicate samples of the same condition in different plates, and so we assign the unique sample name for each replicate after loading the plates together using `unite` in the next code chunk.
Note that display_plate_qpcr requires a column called `sample_id`, which here we had to make from the `condition` variable using `mutate(sample_id=condition)`. The reason for doing this is that we have replicate samples of the same condition in different plates, and so we assign the unique sample name for each replicate after loading the plates together using `unite` in the next code chunk.

## Load and summarize data

Expand Down
12 changes: 6 additions & 6 deletions vignettes/platesetup_vignette.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ We chose to name this variable "target_id" to make it clear that this could refe
Note again that the current version of tidyqpcr has been tested on SYBR/intercalating dye data with one primer set per well only.

**sample_id** should uniquely identify a nucleic acid sample in your experiment. sample_id can either describe all the relevant information, for example `HeatShock_10min_RepA`, `InputControl_WildType_Rep3`; or provide other unique identifying information, for example `S013`.
Functions including `display_plate` and `calculate_deltacq_bysampleid` assume that there is a column called `sample_id`, and use it to decide which wells get analysed together.
Functions including `display_plate_qpcr` and `calculate_deltacq_bysampleid` assume that there is a column called `sample_id`, and use it to decide which wells get analysed together.
We discuss below how to add other kinds of information/metadata to help your analysis.

**prep_type** is used for different types of nucleic acid preps from the same sample.
Expand Down Expand Up @@ -142,10 +142,10 @@ plate_plan12 <- label_plate_rowcol(
print(plate_plan12)
```

We visualise this plate plan using the `display_plate` function:
We visualise this plate plan using the `display_plate_qpcr` function:

```{r minimal_noreps_display,results="show",echo=TRUE,fig.height=3,fig.width=3}
display_plate(plate_plan12)
display_plate_qpcr(plate_plan12)
```

Expanding this practice plan to incorporate replicates can be done by taking this little rectangle and making copies across a larger plate.
Expand Down Expand Up @@ -189,10 +189,10 @@ plate_plan48 <- label_plate_rowcol(
print(plate_plan48)
```

We again visualise this plate plan using the `display_plate` function
We again visualise this plate plan using the `display_plate_qpcr` function

```{r minimal_48_display,results="show",echo=TRUE,fig.height=3,fig.width=8}
display_plate(plate_plan48)
display_plate_qpcr(plate_plan48)
```


Expand Down Expand Up @@ -289,7 +289,7 @@ Again, check the help file with `?unite`. The line `unite(sample_id, condition,
Now we display the plate to check that we have everything in place:

```{r twocondition_96_display,results="show",echo=TRUE,fig.height=6,fig.width=8}
display_plate(plate_plan96)
display_plate_qpcr(plate_plan96)
```

We could print this plate map and take it into the lab as a visual aid for plate loading.
Expand Down

0 comments on commit bd482f2

Please sign in to comment.