Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintenance edits and minor upgrades, v1.1 #200

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: tidyqpcr
Type: Package
Title: Quantitative PCR Analysis with the Tidyverse
Version: 1.0
Version: 1.1
Authors@R: c(person("Edward", "Wallace", email = "[email protected]", role = c("aut", "cre")),
person("Sam", "Haynes", email = "[email protected]", role = c("aut")))
Description: For reproducible quantitative PCR (qPCR) analysis building on packages from the ’tidyverse’, notably ’dplyr’ and ’ggplot2’. It normalizes (by ddCq), summarizes, and plots pre-calculated Cq data, and plots raw amplification and melt curves from Roche Lightcycler (tm) machines. It does NOT (yet) calculate Cq data from amplification curves.
Expand All @@ -25,7 +25,7 @@ Suggests:
VignetteBuilder: knitr
License: Apache License (>= 2)
LazyData: true
RoxygenNote: 7.1.2
RoxygenNote: 7.3.1
Encoding: UTF-8
URL: https://docs.ropensci.org/tidyqpcr, https://github.com/ropensci/tidyqpcr
BugReports: https://github.com/ropensci/tidyqpcr/issues
Expand Down
3 changes: 2 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export(create_rowkey_8_in_16_plain)
export(debaseline)
export(display_plate)
export(display_plate_qpcr)
export(display_plate_sample_id)
export(display_plate_target_id)
export(display_plate_value)
export(label_plate_rowcol)
export(make_row_names_echo1536)
Expand All @@ -29,4 +31,3 @@ importFrom(rlang,.data)
importFrom(stats,median)
importFrom(tibble,as_tibble)
importFrom(tibble,tibble)
importFrom(tidyr,"%>%")
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## News

* May 2024, maintenance upgrades for R 4.4.0, including
- base pipe `|>` rather than magrittr pipe `%>%`
- `display_plate_helpers` new functions to make it easier to display plate plans with varied information
- remove superseded `.data$` syntax
- checking all tests pass, etc.
- update to v1.1
* June 2022, removed plot helper functions `scale_..._nice` and `scale_loglog` from tidyqpcr, because those capabilities are now available in the [scales package](https://scales.r-lib.org) using `label_log` and similar functions. Older code may need to change `scale_y_log10nice` to `scale_y_log10(labels = scales::label_log())`, for example.
* May 2022, Improvements in documentation and testing. Reorganized `display_plate` function to be more flexible, so older code will need to use `display_plate_qpcr` to ensure that `sample_id` and `target_id` info displays. Updated to v0.5.
* January 2022, Improvements in documentation and argument-checking for v0.4.
Expand Down
28 changes: 13 additions & 15 deletions R/amp_melt_curve_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#' }
#'
#' @export
#' @importFrom tidyr %>%
#' @importFrom rlang .data
#'
#' @examples
Expand All @@ -41,7 +40,7 @@
#' program_no = 2)
#'
#' # remove base fluorescence from dataset
#' raw_fluor_tibble %>%
#' raw_fluor_tibble |>
#' debaseline()
#'
debaseline <- function(plateamp, maxcycle = 10) {
Expand All @@ -55,13 +54,13 @@ debaseline <- function(plateamp, maxcycle = 10) {
msg = "plateamp contains a variable called fluor_base, which breaks debaseline"
)
baseline <-
plateamp %>%
dplyr::group_by(.data$well) %>%
plateamp |>
dplyr::group_by(.data$well) |>
dplyr::filter(.data$program_no == 2,
.data$cycle <= maxcycle) %>%
.data$cycle <= maxcycle) |>
dplyr::summarize(fluor_base = stats::median(.data$fluor_raw))
plateamp %>%
dplyr::left_join(baseline, by = "well") %>%
plateamp |>
dplyr::left_join(baseline, by = "well") |>
dplyr::mutate(fluor_signal = .data$fluor_raw - .data$fluor_base)
}

Expand Down Expand Up @@ -142,7 +141,6 @@ calculate_dydx <- function(x, y, method = "spline", ...) {
#' @family melt_curve_functions
#'
#' @export
#' @importFrom tidyr %>%
#'
#' @examples
#' # create simple curve
Expand All @@ -157,15 +155,15 @@ calculate_dydx <- function(x, y, method = "spline", ...) {
#'
#' # calculate drdt of all melt curves
#' #----- use case 1 : using splines
#' temp_tibble %>%
#' temp_tibble |>
#' calculate_drdt_plate()
#'
#' # optional arguments are passed to smooth.splines function
#' temp_tibble %>%
#' temp_tibble |>
#' calculate_drdt_plate(spar = 0.5)
#'
#' #----- use case 2 : using difference between adjacent points
#' temp_tibble %>%
#' temp_tibble |>
#' calculate_drdt_plate(method = "diff")
#'
calculate_drdt_plate <- function(platemelt, method = "spline", ...) {
Expand All @@ -177,14 +175,14 @@ calculate_drdt_plate <- function(platemelt, method = "spline", ...) {
if (assertthat::has_name(platemelt,"plate") ) {
warning("platemelt has a plate column, but calculate_drdt_plate works only for single plates.")
}
platemelt %>%
dplyr::arrange(.data$well, .data$temperature) %>%
dplyr::group_by(.data$well) %>%
platemelt |>
dplyr::arrange(.data$well, .data$temperature) |>
dplyr::group_by(.data$well) |>
dplyr::mutate(dRdT =
calculate_dydx(x = .data$temperature,
y = .data$fluor_raw,
method = method,
...)
) %>%
) |>
dplyr::ungroup()
}
47 changes: 22 additions & 25 deletions R/calculate_deltacq.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#' etc.
#'
#' @export
#' @importFrom tidyr %>%
#' @importFrom stats median
#'
#' @examples
Expand All @@ -38,13 +37,13 @@
#' # normalise cq to reference target_id called 'T_norm'
#'
#' #----- use case 1: median reference target_id value
#' cq_tibble %>%
#' cq_tibble |>
#' calculate_normvalue(ref_ids = "T_norm",
#' value_name = "cq",
#' id_name = "target_id")
#'
#' #----- use case 2: mean reference target_id value
#' cq_tibble %>%
#' cq_tibble |>
#' calculate_normvalue(ref_ids = "T_norm",
#' value_name = "cq",
#' id_name = "target_id",
Expand All @@ -62,8 +61,8 @@ calculate_normvalue <- function(value_df,

# make subset of value_df where gene is one or more ref_ids
value_to_norm_by <- dplyr::filter(value_df,
.data[[id_name]] %in% ref_ids) %>%
dplyr::pull({{value_name}}) %>%
.data[[id_name]] %in% ref_ids) |>
dplyr::pull({{value_name}}) |>
norm_function(na.rm = TRUE)

# assign summary (median) value to value_df$value_to_norm_by
Expand Down Expand Up @@ -98,7 +97,6 @@ calculate_normvalue <- function(value_df,
#' rel_abund \tab normalized ratio, \eqn{2^(-\Delta Cq)} }
#'
#' @export
#' @importFrom tidyr %>%
#' @importFrom stats median
#' @importFrom rlang .data
#'
Expand All @@ -118,11 +116,11 @@ calculate_normvalue <- function(value_df,
#' # calculate deltacq using reference target_id called 'T_norm'
#'
#' #----- use case 1: median reference target_id value
#' cq_tibble %>%
#' cq_tibble |>
#' calculate_deltacq_bysampleid(ref_target_ids = "T_norm")
#'
#' #----- use case 2: mean reference target_id value
#' cq_tibble %>%
#' cq_tibble |>
#' calculate_deltacq_bysampleid(ref_target_ids = "T_norm",
#' norm_function = mean)
#'
Expand All @@ -134,18 +132,18 @@ calculate_deltacq_bysampleid <- function(cq_df,
assertthat::has_name(cq_df,
c("target_id", "sample_id","cq")))

cq_df %>%
dplyr::group_by(.data$sample_id) %>%
cq_df |>
dplyr::group_by(sample_id) |>
dplyr::do(calculate_normvalue(.data,
ref_ids = ref_target_ids,
value_name = "cq",
id_name = "target_id",
norm_function = norm_function)) %>%
dplyr::rename(ref_cq = .data$value_to_norm_by) %>%
dplyr::ungroup() %>%
norm_function = norm_function)) |>
dplyr::rename(ref_cq = value_to_norm_by) |>
dplyr::ungroup() |>
dplyr::mutate(
delta_cq = .data$cq - .data$ref_cq,
rel_abund = 2^-.data$delta_cq)
delta_cq = cq - ref_cq,
rel_abund = 2^ - delta_cq)
}


Expand Down Expand Up @@ -189,7 +187,6 @@ calculate_deltacq_bysampleid <- function(cq_df,
#' normalized fold-change ratio, \eqn{2^(-\Delta \Delta Cq)} }
#'
#' @export
#' @importFrom tidyr %>%
#' @importFrom stats median
#'
#' @examples
Expand All @@ -208,11 +205,11 @@ calculate_deltacq_bysampleid <- function(cq_df,
#' # calculate deltadeltacq using reference target_id called 'S_norm'
#'
#' #----- use case 1: median reference sample_id value
#' deltacq_tibble %>%
#' deltacq_tibble |>
#' calculate_deltadeltacq_bytargetid(ref_sample_ids = "S_norm")
#'
#' #----- use case 2: mean reference sample_id value
#' deltacq_tibble %>%
#' deltacq_tibble |>
#' calculate_deltadeltacq_bytargetid(ref_sample_ids = "S_norm",
#' norm_function = mean)
#'
Expand All @@ -227,17 +224,17 @@ calculate_deltadeltacq_bytargetid <- function(deltacq_df,

ddcq_factor <- (-1) ^ ddcq_positive

deltacq_df %>%
dplyr::group_by(.data$target_id) %>%
deltacq_df |>
dplyr::group_by(target_id) |>
dplyr::do(calculate_normvalue(.data,
ref_ids = ref_sample_ids,
value_name = "delta_cq",
id_name = "sample_id",
norm_function = norm_function)) %>%
dplyr::rename(ref_delta_cq = .data$value_to_norm_by) %>%
dplyr::ungroup() %>%
norm_function = norm_function)) |>
dplyr::rename(ref_delta_cq = value_to_norm_by) |>
dplyr::ungroup() |>
dplyr::mutate(
deltadelta_cq = ddcq_factor *
(.data$delta_cq - .data$ref_delta_cq),
fold_change = 2 ^ .data$deltadelta_cq)
(delta_cq - ref_delta_cq),
fold_change = 2 ^ deltadelta_cq)
}
17 changes: 8 additions & 9 deletions R/calculate_efficiency.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@
#' # calculate primer efficiency
#'
#' #----- use case 1: include difference across replicates in model
#' dilution_tibble %>%
#' dilution_tibble |>
#' calculate_efficiency()
#'
#' #----- use case 2: ignore difference across replicates
#' dilution_tibble %>%
#' dilution_tibble |>
#' calculate_efficiency(formula = cq ~ log2(dilution))
#'
calculate_efficiency <- function(cq_df_1, formula = cq ~ log2(dilution) + biol_rep) {
Expand Down Expand Up @@ -90,7 +90,6 @@ calculate_efficiency <- function(cq_df_1, formula = cq ~ log2(dilution) + biol_r
#' @seealso calculate_efficiency
#'
#' @export
#' @importFrom tidyr %>%
#' @importFrom rlang .data
#'
#' @examples
Expand All @@ -111,11 +110,11 @@ calculate_efficiency <- function(cq_df_1, formula = cq ~ log2(dilution) + biol_r
#' # calculate primer efficiency for multiple targets
#'
#' #----- use case 1: include difference across replicates in model
#' dilution_tibble %>%
#' dilution_tibble |>
#' calculate_efficiency_bytargetid()
#'
#' #----- use case 2: ignore difference across replicates
#' dilution_tibble %>%
#' dilution_tibble |>
#' calculate_efficiency_bytargetid(formula = cq ~ log2(dilution))
#'
calculate_efficiency_bytargetid <- function(cq_df,
Expand All @@ -125,10 +124,10 @@ calculate_efficiency_bytargetid <- function(cq_df,

if (!is.na(use_prep_types)) {
assertthat::assert_that(assertthat::has_name(cq_df, "prep_type"))
cq_df <- dplyr::filter(cq_df, .data$prep_type %in% use_prep_types)
cq_df <- dplyr::filter(cq_df, prep_type %in% use_prep_types)
}
cq_df %>%
dplyr::group_by(.data$target_id) %>%
dplyr::do(calculate_efficiency(.data, formula = formula)) %>%
cq_df |>
dplyr::group_by(target_id) |>
dplyr::do(calculate_efficiency(.data, formula = formula)) |>
dplyr::ungroup()
}
Loading
Loading