diff --git a/.Rbuildignore b/.Rbuildignore index 5e005dd..77fb256 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -4,5 +4,5 @@ ^README\.Rmd$ ^README\.md$ ^README-.*\.png$ -^NEWS\.md$ ^cran-comments\.md$ +^\.github$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml new file mode 100644 index 0000000..3f3af2d --- /dev/null +++ b/.github/workflows/R-CMD-check.yaml @@ -0,0 +1,53 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help +on: + push: + branches: [main, master] + pull_request: + workflow_dispatch: + +name: R-CMD-check.yaml + +permissions: + contents: read + +jobs: + R-CMD-check: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + fail-fast: false + matrix: + config: + - {os: macos-latest, r: 'release'} + - {os: windows-latest, r: 'release'} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} + + env: + GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes + + steps: + - uses: actions/checkout@v6 + + - uses: r-lib/actions/setup-pandoc@v2 + + - uses: r-lib/actions/setup-r@v2 + with: + r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::rcmdcheck + needs: check + + - uses: r-lib/actions/check-r-package@v2 + with: + upload-snapshots: true + error-on: '"warning"' + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.gitignore b/.gitignore index 0d757a1..d72f989 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,3 @@ inst/doc .Rhistory .pdf excluded/ -tests/ diff --git a/DESCRIPTION b/DESCRIPTION index eca66ba..4f76ec6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,24 +1,25 @@ Package: toxplot Type: Package Title: Batch Processing, Modeling and Visualizing the Dose-Response of High-Throughput Screening Bioassay -Version: 0.1.1 -Author: Jun Wang -Maintainer: Jun Wang +Version: 0.1.2 +Authors@R: person("Jun", "Wang", email = "njekin@gmail.com", + role = c("aut", "cre")) Description: A convenient interface to batch process high-throughput toxicology bioassay screening data. It's designed specifically for screening experiment that features a primary inhibition-type assay and a companion cytotoxicity assay. This package provides functions for data normalization, quality-control analysis, dose-response curve fitting (using the Hill model provided in the 'tcpl' package), visualization, and a unique toxicity-adjusted potency ranking system. -URL: http://github.com/njekin/ToxPlot-R-Package -License: GPL (>=2) +URL: https://github.com/njekin/ToxPlot-R-Package +BugReports: https://github.com/njekin/ToxPlot-R-Package/issues +License: GPL (>= 2) Encoding: UTF-8 LazyData: true Depends: R (>= 3.3.0) Imports: dplyr (>= 0.5.0), - tidyr (>= 0.5.0), tcpl (>= 1.0.0), - ggplot2 (>= 2.2.0), + ggplot2 (>= 3.4.0), ggthemes (>= 3.4.0) Suggests: knitr, rmarkdown, - testthat, - plotly, - devtools, -RoxygenNote: 6.0.1 + testthat (>= 3.0.0), + plotly +VignetteBuilder: knitr +Config/testthat/edition: 3 +RoxygenNote: 7.3.1 diff --git a/NEWS.md b/NEWS.md index a9db257..db6d977 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,17 @@ +# toxplot 0.1.2 + +* Fix the CRAN archive-blocking example failure when `tcplFit()` returns + vectors and NULL predictions: model tables now contain one row per fit, + with list columns for concentration and prediction vectors. +* Correct the plate identifier extracted from assay data and use the exact + primary assay name when checking the assay configuration. +* Use `linewidth` for ggplot2 lines and a proper margin object for legends. +* Close the PDF graphics device even when plot printing fails. +* Remove the unused tidyr import and development-only devtools suggestion. +* Build the vignette using the installed package and declare knitr as its builder. +* Add regression coverage for the complete archived failing example, inactive + curves, insufficient concentrations, ranking, plotting and PDF cleanup. + # toxplot v0.1.1 ------------------ ## Bug fixes diff --git a/R/data.R b/R/data.R index a28774b..969dc56 100644 --- a/R/data.R +++ b/R/data.R @@ -17,3 +17,11 @@ #' "demo_mc_norm" + +#' Normalized example multi-concentration screening data +#' +#' A dataset containing normalized example data for a primary inhibition assay +#' and the parallel cytotoxicity assay, retained for compatibility. +#' +#' @format See vignette for description of the demo data. +"mc_norm" diff --git a/R/functions_tcpl_based.R b/R/functions_tcpl_based.R index 1263c02..e2e7b3e 100644 --- a/R/functions_tcpl_based.R +++ b/R/functions_tcpl_based.R @@ -82,7 +82,10 @@ auc_hill_tcpl <- function(p, lower, upper) { #' @param prim_cutoff significance cutoff for primary assay (eg. 3sigma or 3bMAD) #' @param toxi_cutoff significance cutoff for cytotoxicity assay (eg. 3sigma or 3bMAD) #' -#' @return A list object containing modeling results, the corresponding data for each chemical. +#' @return A list object containing modeling results and the corresponding data +#' for each chemical. Each model is a one-row data.frame. Vector outputs from +#' tcpl (logc, hill_modl and gnls_modl) are retained as list columns, including +#' NULL predictions when a model was not fitted. #' #' @examples #' ## fit curve with default significant threshold 20 @@ -120,7 +123,7 @@ fit_curve_tcpl <- function(df, assay_info, prim_cutoff = 20, toxi_cutoff = 20) { # get log concentration df <- df %>% dplyr::mutate(logc = log10(conc)) spid_list <- unique(df$spid) - if (is.null(assay_info$prim) & is.null(assay_info$toxi_assay)) { + if (is.null(assay_info$prim_assay) & is.null(assay_info$toxi_assay)) { stop("assay_info cannot be NULL for both primary and cytotoxicity assay") } n <- 1 @@ -138,17 +141,17 @@ fit_curve_tcpl <- function(df, assay_info, prim_cutoff = 20, toxi_cutoff = 20) { } else { prim_dt <- df %>% dplyr::filter(spid == id, assay == assay_info$prim_assay) - m <- tcpl::tcplFit(logc = prim_dt$logc, resp = 100 - prim_dt$nval_median, bmad_prim) + m <- tcpl::tcplFit(logc = prim_dt$logc, resp = 100 - prim_dt$nval_median, bmad = bmad_prim) absIC50 <- log_abs_ec(c(m$hill_tp, m$hill_ga, m$hill_gw), 50) absIC20 <- log_abs_ec(c(m$hill_tp, m$hill_ga, m$hill_gw), 20) m[["absIC20"]] <- absIC20 m[["absIC50"]] <- absIC50 - m[["apid"]] <- prim_dt[[1,1]] + m[["apid"]] <- prim_dt$apid[1] m[["assay"]] <- assay_info$prim_assay m[["spid"]] <- id #prim_md <- dplyr::bind_rows(prim_md, m) # print(m) - prim_md <- data.frame(m) %>% dplyr::select(apid, assay, spid, everything()) + prim_md <- tcpl_fit_row(m) %>% dplyr::select(apid, assay, spid, everything()) } # model cytotox data @@ -158,17 +161,17 @@ fit_curve_tcpl <- function(df, assay_info, prim_cutoff = 20, toxi_cutoff = 20) { toxi_dt <- NA } else { toxi_dt <- df %>% dplyr::filter(spid == id, assay==assay_info$toxi_assay) - m <- tcpl::tcplFit(logc = toxi_dt$logc, resp = 100 - toxi_dt$nval_median, bmad_toxi) + m <- tcpl::tcplFit(logc = toxi_dt$logc, resp = 100 - toxi_dt$nval_median, bmad = bmad_toxi) absIC50 <- log_abs_ec(c(m$hill_tp, m$hill_ga, m$hill_gw), 50) absIC20 <- log_abs_ec(c(m$hill_tp, m$hill_ga, m$hill_gw), 20) m[["absIC20"]] <- absIC20 m[["absIC50"]] <- absIC50 - m[["apid"]] <- toxi_dt[[1,1]] + m[["apid"]] <- toxi_dt$apid[1] m[["assay"]] <- assay_info$toxi_assay m[["spid"]] <- id #toxi_md <- dplyr::bind_rows(toxi_md, m) - toxi_md <- data.frame(m) %>% dplyr::select(apid, assay, spid, everything()) + toxi_md <- tcpl_fit_row(m) %>% dplyr::select(apid, assay, spid, everything()) } @@ -701,13 +704,13 @@ plot_tcpl <- #test and plot cytotox model if (!is.na(m_toxi$hill) & m_toxi$hill == 1) { para_cyto <- c(m_toxi$hill_tp, m_toxi$hill_ga, m_toxi$hill_gw) - p1 <- 100 - hill_model(para_cyto, s) + p1 <- 100 - hill_model(para_cyto, s$logc) p1 <- dplyr::bind_cols(s, data.frame(p1)) names(p1) <- c("logc", "pred") g <- g + geom_line( data = p1, aes(x = logc, y = pred), - size = 2, + linewidth = 2, alpha = 0.9, color = "#e02929" ) @@ -720,13 +723,13 @@ plot_tcpl <- if (!is.na(m_prim$hill) & m_prim$hill == 1) { para_raiu <- c(m_prim$hill_tp, m_prim$hill_ga, m_prim$hill_gw) - p2 <- 100 - hill_model(para_raiu, s) + p2 <- 100 - hill_model(para_raiu, s$logc) p2 <- bind_cols(s, data.frame(p2)) names(p2) <- c("logc", "pred") g <- g + geom_line( data = p2, aes(x = logc, y = pred), - size = 2, + linewidth = 2, alpha = 0.9, color = "#377eb8" ) @@ -738,7 +741,7 @@ plot_tcpl <- geom_hline( yintercept = 100 - cutoff_toxi, alpha = 0.5, - size = 0.5, + linewidth = 0.5, linetype = "dashed", color = "#e02929" ) @@ -747,7 +750,7 @@ plot_tcpl <- geom_hline( yintercept = 100 - cutoff_prim, alpha = 0.5, - size = 0.5, + linewidth = 0.5, linetype = "dashed", color = "#377eb8" ) @@ -948,13 +951,13 @@ plot_tcpl_minimal <- #test and plot cytotox model if (!is.na(m_toxi$hill) & m_toxi$hill == 1) { para_cyto <- c(m_toxi$hill_tp, m_toxi$hill_ga, m_toxi$hill_gw) - p1 <- 100 - hill_model(para_cyto, s) + p1 <- 100 - hill_model(para_cyto, s$logc) p1 <- dplyr::bind_cols(s, data.frame(p1)) names(p1) <- c("logc", "pred") g <- g + geom_line( data = p1, aes(x = logc, y = pred), - size = 2, + linewidth = 2, alpha = 0.9, color = "#e02929" ) @@ -967,13 +970,13 @@ plot_tcpl_minimal <- if (!is.na(m_prim$hill) & m_prim$hill == 1) { para_raiu <- c(m_prim$hill_tp, m_prim$hill_ga, m_prim$hill_gw) - p2 <- 100 - hill_model(para_raiu, s) + p2 <- 100 - hill_model(para_raiu, s$logc) p2 <- bind_cols(s, data.frame(p2)) names(p2) <- c("logc", "pred") g <- g + geom_line( data = p2, aes(x = logc, y = pred), - size = 2, + linewidth = 2, alpha = 0.9, color = "#377eb8" ) @@ -985,7 +988,7 @@ plot_tcpl_minimal <- geom_hline( yintercept = 100 - cutoff_toxi, alpha = 0.5, - size = 0.5, + linewidth = 0.5, linetype = "dashed", color = "#e02929" ) @@ -994,7 +997,7 @@ plot_tcpl_minimal <- geom_hline( yintercept = 100 - cutoff_prim, alpha = 0.5, - size = 0.5, + linewidth = 0.5, linetype = "dashed", color = "#377eb8" ) @@ -1028,7 +1031,7 @@ plot_tcpl_minimal <- theme(axis.title.y = element_blank()) + theme(legend.title = element_blank(), legend.position = "none") + - theme(legend.margin=unit(0, "null")) + + theme(legend.margin = margin(0, 0, 0, 0)) + scale_color_manual(values=c("#e02929", "#377eb8"))+ theme(plot.title=element_text(hjust=0.5, size = 16)) diff --git a/R/utilities.R b/R/utilities.R index 1d90d27..14069c0 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -37,9 +37,9 @@ save_plot_pdf <- function(plot_list, filename) { assay <- spid <- apid <- rval <- NULL grDevices::pdf(filename) + on.exit(grDevices::dev.off(), add = TRUE) cat("Preparing file...\n") invisible(lapply(plot_list, print)) - grDevices::dev.off() cat("Finished!") } @@ -82,3 +82,14 @@ generate_index <- function(x) { index <- rank(uls)[match(x, uls)] return(as.integer(index)) } + +# Preserve vector and NULL components without recycling scalar fit statistics. +tcpl_fit_row <- function(x) { + vector_fields <- c("logc", "hill_modl", "gnls_modl") + for (nm in names(x)) { + if (nm %in% vector_fields || length(x[[nm]]) != 1L) { + x[nm] <- list(I(list(x[[nm]]))) + } + } + as.data.frame(x, optional = TRUE, stringsAsFactors = FALSE) +} diff --git a/README.Rmd b/README.Rmd index 3d79404..c0dc437 100644 --- a/README.Rmd +++ b/README.Rmd @@ -30,12 +30,18 @@ Below you will find a brief demo usage of the package. # Installation +Version 0.1.2 is a maintenance candidate for resubmission to CRAN. +The previous release was archived on 2018-12-10; CRAN installation will +be available again only after the resubmission is accepted. +The published demo output below is historical and may differ with current tcpl. + + You can install the package in R from github using *devtools*. ```{r, eval = FALSE} devtools::install_github('njekin/ToxPlot-R-Package') library(toxplot) ``` -or install from CRAN. +After CRAN reinstatement, install from CRAN. ```{r, eval = FALSE} install.packages("toxplot") library(toxplot) @@ -71,9 +77,8 @@ pc: positive control for celltiter-glo cytotixicity assay (DCNQ) # Demo data included in the package Load the demo dataset included in the package. Below is the head of the dataframe. ```{r, message=FALSE, warning=FALSE} -library(devtools) -library(tidyverse) -load_all() +library(toxplot) +library(dplyr) knitr::kable(head(demo_mc), caption = "Head rows of demo data") ``` diff --git a/README.md b/README.md index 1932d63..29a4cd2 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,13 @@ Below you will find a brief demo usage of the package. Installation ============ +Version 0.1.2 is a maintenance candidate for resubmission to CRAN. +The previous release was archived on 2018-12-10; CRAN installation will +be available again only after the resubmission is accepted. +The published demo output below is historical and may differ with current tcpl. + + + You can install the package in R from github using *devtools*. ``` r @@ -25,7 +32,7 @@ devtools::install_github('njekin/ToxPlot-R-Package') library(toxplot) ``` -or install from CRAN. +After CRAN reinstatement, install from CRAN. ``` r install.packages("toxplot") @@ -61,9 +68,8 @@ Demo data included in the package Load the demo dataset included in the package. Below is the head of the dataframe. ``` r -library(devtools) -library(tidyverse) -load_all() +library(toxplot) +library(dplyr) knitr::kable(head(demo_mc), caption = "Head rows of demo data") ``` diff --git a/cran-comments.md b/cran-comments.md index 91abc8f..27cebbf 100644 --- a/cran-comments.md +++ b/cran-comments.md @@ -1,105 +1,40 @@ -## Test environments -* local OS X install, R 4.0.0 -* local Windows 10 install, R 4.0.0 +## Resubmission of archived package +This is toxplot 0.1.2, maintained by the original author Jun Wang +(njekin@gmail.com). -## R CMD check results -There were no ERRORs, WARNINGs or NOTES. +The package was archived on 2018-12-10 because examples failed while +converting tcplFit results to a data.frame: +"arguments imply differing number of rows: 1, 18, 0". -Below is the build record: +The conversion now retains vector and NULL outputs as list columns while +keeping scalar model statistics in a single row. Regression tests exercise +the full failing example, inactive and insufficient-concentration curves, +ranking, both plotting functions, and PDF device cleanup. The unused tidyr +import has been removed, ggplot2 line parameters updated, and the vignette +now builds against the installed package. -==> devtools::check(document = FALSE) +## Verified local environment -Setting env vars -------------------------------------------------------------- -CFLAGS : -Wall -pedantic -CXXFLAGS: -Wall -pedantic -Building toxplot -------------------------------------------------------------- -'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ \ - --no-save --no-restore --quiet CMD build '/Users/junwang/Dropbox/EPA \ - works/toxplot' --no-resave-data --no-manual +* macOS, Apple silicon, R 4.2.3 +* tcpl 3.3.1, ggplot2 4.0.3, ggthemes 6.0.0, dplyr 1.2.1 +* R CMD build, including the HTML vignette +* R CMD check --as-cran --no-manual -* checking for file ‘/Users/junwang/Dropbox/EPA works/toxplot/DESCRIPTION’ ... OK -* preparing ‘toxplot’: -* checking DESCRIPTION meta-information ... OK -* installing the package to build vignettes -* creating vignettes ... OK -* checking for LF line-endings in source and make files -* checking for empty or unneeded directories -* looking to see if a ‘data/datalist’ file should be added -* building ‘toxplot_0.1.0.tar.gz’ +Local check result: 0 ERRORs, 0 WARNINGs, 2 NOTEs. -Setting env vars -------------------------------------------------------------- -_R_CHECK_CRAN_INCOMING_ : FALSE -_R_CHECK_FORCE_SUGGESTS_: FALSE -Checking toxplot -------------------------------------------------------------- -'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ \ - --no-save --no-restore --quiet CMD check \ - '/var/folders/9x/8jptjf_d5kxgjnj9qxrkzp200000gn/T//RtmpMyJWKG/toxplot_0.1.0.tar.gz' \ - --as-cran --timings --no-manual +1. CRAN incoming feasibility identifies a new submission of an archived + package. This is the intended reinstatement request. +2. The local system could not verify the current time. -* using log directory ‘/Users/junwang/Dropbox/EPA works/toxplot.Rcheck’ -* using R version 3.4.0 (2017-04-21) -* using platform: x86_64-apple-darwin15.6.0 (64-bit) -* using session charset: UTF-8 -* using options ‘--no-manual --as-cran’ -* checking for file ‘toxplot/DESCRIPTION’ ... OK -* checking extension type ... Package -* this is package ‘toxplot’ version ‘0.1.0’ -* package encoding: UTF-8 -* checking package namespace information ... OK -* checking package dependencies ... OK -* checking if this is a source package ... OK -* checking if there is a namespace ... OK -* checking for executable files ... OK -* checking for hidden files and directories ... OK -* checking for portable file names ... OK -* checking for sufficient/correct file permissions ... OK -* checking whether package ‘toxplot’ can be installed ... OK -* checking installed package size ... OK -* checking package directory ... OK -* checking ‘build’ directory ... OK -* checking DESCRIPTION meta-information ... OK -* checking top-level files ... OK -* checking for left-over files ... OK -* checking index information ... OK -* checking package subdirectories ... OK -* checking R files for non-ASCII characters ... OK -* checking R files for syntax errors ... OK -* checking whether the package can be loaded ... OK -* checking whether the package can be loaded with stated dependencies ... OK -* checking whether the package can be unloaded cleanly ... OK -* checking whether the namespace can be loaded with stated dependencies ... OK -* checking whether the namespace can be unloaded cleanly ... OK -* checking dependencies in R code ... OK -* checking S3 generic/method consistency ... OK -* checking replacement functions ... OK -* checking foreign function calls ... OK -* checking R code for possible problems ... OK -* checking Rd files ... OK -* checking Rd metadata ... OK -* checking Rd line widths ... OK -* checking Rd cross-references ... OK -* checking for missing documentation entries ... OK -* checking for code/documentation mismatches ... OK -* checking Rd \usage sections ... OK -* checking Rd contents ... OK -* checking for unstated dependencies in examples ... OK -* checking contents of ‘data’ directory ... OK -* checking data for non-ASCII characters ... OK -* checking data for ASCII and uncompressed saves ... OK -* checking installed files from ‘inst/doc’ ... OK -* checking files in ‘vignettes’ ... OK -* checking examples ... NONE -* checking for unstated dependencies in vignettes ... OK -* checking package vignettes in ‘inst/doc’ ... OK -* checking re-building of vignette outputs ... OK -* DONE -Status: OK +Examples, tests and rebuilding vignette outputs pass. +The PDF reference manual was not checked (--no-manual). +## Still required before submission - -R CMD check results -0 errors | 0 warnings | 0 notes - -R CMD check succeeded - +This file is a preparation draft, not a claim of completed cross-platform +validation. Run the supplied GitHub Actions workflow on current R release, +R-devel and R-oldrel across Linux, macOS and Windows, and update this file +with the actual results. Check the PDF reference manual on a TeX-equipped +machine. Do not submit until any remaining significant check issues are +resolved or explained. diff --git a/man/demo_mc.Rd b/man/demo_mc.Rd index ee1d87a..0666bc6 100644 --- a/man/demo_mc.Rd +++ b/man/demo_mc.Rd @@ -4,7 +4,9 @@ \name{demo_mc} \alias{demo_mc} \title{Example multi-concentration screening data} -\format{See vignette for description of the demo data.} +\format{ +See vignette for description of the demo data. +} \usage{ demo_mc } diff --git a/man/demo_mc_norm.Rd b/man/demo_mc_norm.Rd index e373aa7..754b397 100644 --- a/man/demo_mc_norm.Rd +++ b/man/demo_mc_norm.Rd @@ -4,7 +4,9 @@ \name{demo_mc_norm} \alias{demo_mc_norm} \title{Normalized example multi-concentration screening data} -\format{See vignette for description of the demo data.} +\format{ +See vignette for description of the demo data. +} \usage{ demo_mc_norm } diff --git a/man/fit_curve_tcpl.Rd b/man/fit_curve_tcpl.Rd index 8acfef3..dae9ae6 100644 --- a/man/fit_curve_tcpl.Rd +++ b/man/fit_curve_tcpl.Rd @@ -17,7 +17,10 @@ use NULL if either one of the assay does not need to be modeled.} \item{toxi_cutoff}{significance cutoff for cytotoxicity assay (eg. 3sigma or 3bMAD)} } \value{ -A list object containing modeling results, the corresponding data for each chemical. +A list object containing modeling results and the corresponding data +for each chemical. Each model is a one-row data.frame. Vector outputs from +tcpl (logc, hill_modl and gnls_modl) are retained as list columns, including +NULL predictions when a model was not fitted. } \description{ Curve fitting using the tcplFit function in `tcpl` package. diff --git a/man/mc_norm.Rd b/man/mc_norm.Rd index 08e31c8..f5844d6 100644 --- a/man/mc_norm.Rd +++ b/man/mc_norm.Rd @@ -4,11 +4,14 @@ \name{mc_norm} \alias{mc_norm} \title{Normalized example multi-concentration screening data} -\format{See vignette for description of the demo data.} +\format{ +See vignette for description of the demo data. +} \usage{ mc_norm } \description{ -A dataset contains normalized example data for a primary inhibition assay and the parallel cytotoxicity assay +A dataset containing normalized example data for a primary inhibition assay +and the parallel cytotoxicity assay, retained for compatibility. } \keyword{datasets} diff --git a/man/plot_tcpl.Rd b/man/plot_tcpl.Rd index 756c421..6b57a9f 100644 --- a/man/plot_tcpl.Rd +++ b/man/plot_tcpl.Rd @@ -4,8 +4,13 @@ \alias{plot_tcpl} \title{Plot dose-resonse curves based on the tcpl hill model} \usage{ -plot_tcpl(tcpl_models, rank_table = NULL, spid_chnm_table = NULL, - notation = FALSE, cunit = "M") +plot_tcpl( + tcpl_models, + rank_table = NULL, + spid_chnm_table = NULL, + notation = FALSE, + cunit = "M" +) } \arguments{ \item{tcpl_models}{the list object created by 'fit_curve_tcpl' function} diff --git a/man/plot_tcpl_minimal.Rd b/man/plot_tcpl_minimal.Rd index ab08a4c..eda52ad 100644 --- a/man/plot_tcpl_minimal.Rd +++ b/man/plot_tcpl_minimal.Rd @@ -7,8 +7,13 @@ This funciton plots dose-response curve with minimal text annotation, no x and y axis label, 0 borders. Useful when need to present several plots together.} \usage{ -plot_tcpl_minimal(tcpl_models, rank_table = NULL, spid_chnm_table = NULL, - notation = FALSE, cunit = "M") +plot_tcpl_minimal( + tcpl_models, + rank_table = NULL, + spid_chnm_table = NULL, + notation = FALSE, + cunit = "M" +) } \arguments{ \item{tcpl_models}{the list object created by 'fit_curve_tcpl' function} diff --git a/man/rank_tcpl.Rd b/man/rank_tcpl.Rd index 62d1f4e..f0dfdb4 100644 --- a/man/rank_tcpl.Rd +++ b/man/rank_tcpl.Rd @@ -4,8 +4,12 @@ \alias{rank_tcpl} \title{function to calculate ranking score, TAA, med_diff, EC values based on tcpl hill model} \usage{ -rank_tcpl(tcpl_models, spid_chnm_table = NULL, med_taa = NULL, - med_med_diff = NULL) +rank_tcpl( + tcpl_models, + spid_chnm_table = NULL, + med_taa = NULL, + med_med_diff = NULL +) } \arguments{ \item{tcpl_models}{the list object returned by 'fit_curve_tcpl' function} diff --git a/man/save_plot_pdf.Rd b/man/save_plot_pdf.Rd index 9fb1b1c..800559d 100644 --- a/man/save_plot_pdf.Rd +++ b/man/save_plot_pdf.Rd @@ -30,10 +30,10 @@ demo_rank <- rank_tcpl(demo_md, med_taa = NULL, med_med_diff = NULL) demo_plots <- plot_tcpl_minimal(demo_md, demo_rank, notation = TRUE) ## save all the plots as pdf -# save_plot_pdf(demo_plots, ".\\output plots\\all_plots.pdf") +# save_plot_pdf(demo_plots, ".\output plots\all_plots.pdf") ## save the 1st plot as pdf -# save_plot_pdf(demo_plots[1], ".\\output plots\\plot1.pdf") +# save_plot_pdf(demo_plots[1], ".\output plots\plot1.pdf") diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 0000000..2db1589 --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,3 @@ +library(testthat) +library(toxplot) +test_check("toxplot") diff --git a/tests/testthat/test-tcpl-compatibility.R b/tests/testthat/test-tcpl-compatibility.R new file mode 100644 index 0000000..92ab965 --- /dev/null +++ b/tests/testthat/test-tcpl-compatibility.R @@ -0,0 +1,62 @@ +test_that("tcpl results preserve scalar, vector and absent predictions", { + fit <- list(hill = NA_integer_, logc = 1:18, hill_modl = NULL, + gnls_modl = NULL, hill_tp = NA_real_) + result <- toxplot:::tcpl_fit_row(fit) + expect_equal(nrow(result), 1L) + expect_identical(result$logc[[1]], 1:18) + expect_null(result$hill_modl[[1]]) + expect_null(result$gnls_modl[[1]]) + expect_identical(result$hill, NA_integer_) +}) + +test_that("the complete archived failing example fits, ranks and renders", { + info <- list(prim_assay = "Primary", toxi_assay = "Cytotox") + models <- fit_curve_tcpl(demo_mc_norm, info) + expect_length(models, length(unique(demo_mc_norm$spid))) + for (m in models) { + for (assay in c("prim", "toxi")) { + fit <- m[[paste0("model_", assay)]] + dat <- m[[paste0("data_", assay)]] + expect_equal(nrow(fit), 1L) + expect_identical(fit$logc[[1]], dat$logc) + expect_equal(fit$apid, dat$apid[1]) + } + } + ranked <- rank_tcpl(models) + expect_equal(nrow(ranked), length(models)) + expect_equal(nrow(summary_tcpl(models)), length(models)) + grDevices::pdf(file = NULL) + on.exit(grDevices::dev.off(), add = TRUE) + for (plotter in list(plot_tcpl, plot_tcpl_minimal)) { + plots <- plotter(models, ranked, notation = TRUE) + expect_length(plots, length(models)) + expect_warning(lapply(plots, ggplot2::ggplotGrob), NA) + } +}) + +test_that("inactive and insufficient-concentration series remain one row", { + info <- list(prim_assay = "Primary", toxi_assay = "Cytotox") + d <- subset(demo_mc_norm, spid == "TP0001502B03") + d$nval_median <- 100 + for (dat in list(d, subset(d, conc == min(conc)))) { + result <- fit_curve_tcpl(dat, info) + expect_equal(nrow(result[[1]]$model_prim), 1L) + expect_true(is.na(result[[1]]$model_prim$hill)) + expect_null(result[[1]]$model_prim$hill_modl[[1]]) + expect_equal(nrow(rank_tcpl(result)), 1L) + } +}) + +test_that("PDF export closes its device even if printing fails", { + before <- grDevices::dev.cur() + output <- tempfile(fileext = ".pdf") + on.exit(unlink(output), add = TRUE) + save_plot_pdf(list(ggplot2::ggplot()), output) + expect_identical(grDevices::dev.cur(), before) + expect_gt(file.info(output)$size, 0) + bad <- ggplot2::ggplot(data.frame(x = 1), + ggplot2::aes(x = x, y = not_a_column)) + + ggplot2::geom_point() + expect_error(save_plot_pdf(list(bad), output), "not_a_column") + expect_identical(grDevices::dev.cur(), before) +}) diff --git a/vignettes/Using_ToxPlot_Package_to_Analyze_in_vitro_Screening_Data.Rmd b/vignettes/Using_ToxPlot_Package_to_Analyze_in_vitro_Screening_Data.Rmd index 9014e5a..38c7b47 100644 --- a/vignettes/Using_ToxPlot_Package_to_Analyze_in_vitro_Screening_Data.Rmd +++ b/vignettes/Using_ToxPlot_Package_to_Analyze_in_vitro_Screening_Data.Rmd @@ -4,7 +4,7 @@ author: "Jun Wang" date: "`r Sys.Date()`" output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{Vignette Title} + %\VignetteIndexEntry{Using ToxPlot Package to Analyze in vitro Screening Data} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -46,7 +46,7 @@ pc: positive control for celltiter-glo cytotixicity assay (DCNQ) Load the demo dataset included in the package. Below is the head of the dataframe. ```{r, message=FALSE, warning=FALSE} library(dplyr) -devtools::load_all() +library(toxplot) knitr::kable(head(demo_mc), caption = "Head rows of demo data") ```