Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
^README\.Rmd$
^README\.md$
^README-.*\.png$
^NEWS\.md$
^cran-comments\.md$
^\.github$
53 changes: 53 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -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")'
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ inst/doc
.Rhistory
.pdf
excluded/
tests/
23 changes: 12 additions & 11 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 <njekin@gmail.com>
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
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
8 changes: 8 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
45 changes: 24 additions & 21 deletions R/functions_tcpl_based.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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())

}

Expand Down Expand Up @@ -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"
)
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand All @@ -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"
)
Expand Down Expand Up @@ -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))

Expand Down
13 changes: 12 additions & 1 deletion R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -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!")
}

Expand Down Expand Up @@ -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)
}
13 changes: 9 additions & 4 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")
```
Expand Down
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,21 @@ 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
devtools::install_github('njekin/ToxPlot-R-Package')
library(toxplot)
```

or install from CRAN.
After CRAN reinstatement, install from CRAN.

``` r
install.packages("toxplot")
Expand Down Expand Up @@ -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")
```
Expand Down
Loading