Skip to content

Commit

Permalink
Prepare for CRAN v0.1.14 release
Browse files Browse the repository at this point in the history
  • Loading branch information
idblr committed Jan 23, 2024
1 parent 02c7a4f commit f95d530
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 130 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: gateR
Type: Package
Title: Flow/Mass Cytometry Gating via Spatial Kernel Density Estimation
Version: 0.1.13
Date: 2023-02-01
Version: 0.1.14
Date: 2024-01-22
Authors@R:
c(person(given = "Ian D.",
family = "Buller",
Expand Down
102 changes: 53 additions & 49 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,76 @@
# gateR (development version)

## gateR v0.1.14
* Fixed bug in calculation of False Discovery Rate in internal `pval_correct()` function
* Argument `plot_cols` correctly renamed `cols` in `lrr_plot()` function

## gateR v0.1.13
* Migrated R-spatial dependency
* Replaced `raster` in Imports with `terra` because of imminent package retirement
* Updated documentation throughout
* Added GitHub R-CMD-check
* Updated citation style for CITATION file
* Migrated R-spatial dependency
* Replaced `raster` in Imports with `terra` because of imminent package retirement
* Updated documentation throughout
* Added GitHub R-CMD-check
* Updated citation style for CITATION file

## gateR v0.1.12
* Updated maintainer contact information
* Updated maintainer contact information

## gateR v0.1.11
* Updated package URL and BugReports to renamed GitHub account "lance-waller-lab" (previously "Waller-SUSAN")
* Replaced `if()` conditions comparing `class()` to string with `inherits()` in functions
* `tools` is no longer Imports
* `utils` is now Suggests because "zzz.R" calls the `packageDescription()` function
* `ncdfFlow`, `flowWorkspaceData` are no longer Suggests (for generating random data set `randCyto`) because "Package suggested but not available for checking" in the some CRAN environments
* Added CITATION file
* Fixed typos in documentation throughout
* Updated package URL and BugReports to renamed GitHub account "lance-waller-lab" (previously "Waller-SUSAN")
* Replaced `if()` conditions comparing `class()` to string with `inherits()` in functions
* `tools` is no longer Imports
* `utils` is now Suggests because "zzz.R" calls the `packageDescription()` function
* `ncdfFlow`, `flowWorkspaceData` are no longer Suggests (for generating random data set `randCyto`) because "Package suggested but not available for checking" in the some CRAN environments
* Added CITATION file
* Fixed typos in documentation throughout

## gateR v0.1.10
* Updated dependencies `spatstat.core` and `spatstat.linnet` packages based on feedback from the Spatstat Team (Adrian Baddeley and Ege Rubak). All random generators in `spatstat.core` were moved to a new package `spatstat.random`
* `spatstat.geom`, `spatstat.core`, `spatstat.linnet`, and `spatstat (>=2.0-0)` are no longer Depends
* `spatstat.geom` is now Imports
* `dplyr`, `ncdfFlow`, `flowWorkspaceData`, and `usethis` now Suggests (for generating random data set `randCyto`)
* Fixed annotation typos in the vignette. Removed packages no longer used in the vignette
* Updated dependencies `spatstat.core` and `spatstat.linnet` packages based on feedback from the Spatstat Team (Adrian Baddeley and Ege Rubak). All random generators in `spatstat.core` were moved to a new package `spatstat.random`
* `spatstat.geom`, `spatstat.core`, `spatstat.linnet`, and `spatstat (>=2.0-0)` are no longer Depends
* `spatstat.geom` is now Imports
* `dplyr`, `ncdfFlow`, `flowWorkspaceData`, and `usethis` now Suggests (for generating random data set `randCyto`)
* Fixed annotation typos in the vignette. Removed packages no longer used in the vignette

## gateR v0.1.9
* Now `rlang` is in Depends.
* Output for `gating()` now includes a diagnostic message saved as a character string for reference in a slot called `note`
* A diagnostic message can be viewed running `rlang::last_error()$out$note` after the unsuccessful run of `gating()`
* Removed redundant `@importFrom fields image.plot` in 'package.R'
* Now `rlang` is in Depends.
* Output for `gating()` now includes a diagnostic message saved as a character string for reference in a slot called `note`
* A diagnostic message can be viewed running `rlang::last_error()$out$note` after the unsuccessful run of `gating()`
* Removed redundant `@importFrom fields image.plot` in 'package.R'

## gateR v0.1.8
* Updated `spatstat` package to new subsetted packages based on feedback from the Spatstat Team (Adrian Baddeley and Ege Rubak). Now `spatstat.geom`, `spatstat.core`, `spatstat.linnet`, and `spatstat (>= 2.0-0)` are in Depends
* Fixed check for `vars` in `dat` within the `gating()` function
* Updated `spatstat` package to new subsetted packages based on feedback from the Spatstat Team (Adrian Baddeley and Ege Rubak). Now `spatstat.geom`, `spatstat.core`, `spatstat.linnet`, and `spatstat (>= 2.0-0)` are in Depends
* Fixed check for `vars` in `dat` within the `gating()` function

## gateR v0.1.7
* Updated `spatstat` package to new subsetted packages based on feedback from the Spatstat Team (Adrian Baddeley and Ege Rubak). `spatstat.geom` package replaces `spatstat` package in Imports
* Added additional multiple testing corrections, including False Discovery Rate, spatially dependent Sidak correction, independent Sidak correction, and two corrections based on Random Field Theory (Adler and Hasofer or Friston)
* The latter two corrections required a new argument `bandw` to be added to `gating()`, `lotrrs()`, and `rrs()` functions to allow users to specify bandwidth for the kernel density estimation
* Updated the calculation of the spatial correlogram in internal `pval_correct()` function from the `correlog()` function in the `pgrimess` package to the `modified.ttest()` function in the `SpatialPack` package
* Imports `lifecycle` package to document deprecated arguments `doplot` and `verbose` in `lotrrs()`, `rrs()`, and `gating()` functions
* In `gating()` function, creates a categorized `im` based on critical p-value, assigns that value to every point in a `ppp` object, and subsets points by category
* Removed `maptools` and `sp` packages from Imports
* Updated links in 'gateR-package.Rd' for package updates
* Updated `spatstat` package to new subsetted packages based on feedback from the Spatstat Team (Adrian Baddeley and Ege Rubak). `spatstat.geom` package replaces `spatstat` package in Imports
* Added additional multiple testing corrections, including False Discovery Rate, spatially dependent Sidak correction, independent Sidak correction, and two corrections based on Random Field Theory (Adler and Hasofer or Friston)
* The latter two corrections required a new argument `bandw` to be added to `gating()`, `lotrrs()`, and `rrs()` functions to allow users to specify bandwidth for the kernel density estimation
* Updated the calculation of the spatial correlogram in internal `pval_correct()` function from the `correlog()` function in the `pgrimess` package to the `modified.ttest()` function in the `SpatialPack` package
* Imports `lifecycle` package to document deprecated arguments `doplot` and `verbose` in `lotrrs()`, `rrs()`, and `gating()` functions
* In `gating()` function, creates a categorized `im` based on critical p-value, assigns that value to every point in a `ppp` object, and subsets points by category
* Removed `maptools` and `sp` packages from Imports
* Updated links in 'gateR-package.Rd' for package updates

## gateR v0.1.6
* Updated URLs in 'gateR-package.Rd'
* Updated year in DESCRIPTION
* Updated URLs in 'gateR-package.Rd'
* Updated year in DESCRIPTION

## gateR v0.1.5
* Added arguments `save_gate`, `name_gate`, and `path_gate` in `lotrrs()`, `rrs()`, and `gating()` to save plots as PNG files as output
* Renamed `doplot` argument as `plot_gate` for consistency with new plotting arguments
* Added a stop (and return no results) if no significant clusters detected during first gate
* Deprecate `verbose` argument in `gating()`, `rrs()`, and `lotrrs()`
* Added `try()` error catches in `rrs()` and `lotrrs()` for `c1n` and `c2n` arguments
* Changed the `right` argument in `cut()` in `pval_plot()` to "TRUE" (the default for cut)
* Removed fullstop in error messages
* Added a `make.names()` check for `vars` and `colnames(dat)` in `gating()`
* Added arguments `save_gate`, `name_gate`, and `path_gate` in `lotrrs()`, `rrs()`, and `gating()` to save plots as PNG files as output
* Renamed `doplot` argument as `plot_gate` for consistency with new plotting arguments
* Added a stop (and return no results) if no significant clusters detected during first gate
* Deprecate `verbose` argument in `gating()`, `rrs()`, and `lotrrs()`
* Added `try()` error catches in `rrs()` and `lotrrs()` for `c1n` and `c2n` arguments
* Changed the `right` argument in `cut()` in `pval_plot()` to "TRUE" (the default for cut)
* Removed fullstop in error messages
* Added a `make.names()` check for `vars` and `colnames(dat)` in `gating()`

## gateR v0.1.4
* Added documentation to `lotrrs()`, `rrs()`, and `gating()` about the levels of condition(s)
* Fixed bug in `lotrrs()` that was mislabeling numerator and denominator levels of second condition
* Added parameters `c1n` and `c2n` in `lotrrs()`, `rrs()`, and `gating()` to specify the numerator level
* Added documentation to `lotrrs()`, `rrs()`, and `gating()` about the levels of condition(s)
* Fixed bug in `lotrrs()` that was mislabeling numerator and denominator levels of second condition
* Added parameters `c1n` and `c2n` in `lotrrs()`, `rrs()`, and `gating()` to specify the numerator level

## gateR v0.1.3
* Removed `ncdFlow`, `flowWorkspaceData`, and `knitr` packages from Suggests
* Created a random data set `randCyto` and all documentation
* Updated examples and testthat to use `randCyto` data
* Updated vignette with clearer language
* Removed `ncdFlow`, `flowWorkspaceData`, and `knitr` packages from Suggests
* Created a random data set `randCyto` and all documentation
* Updated examples and testthat to use `randCyto` data
* Updated vignette with clearer language
2 changes: 1 addition & 1 deletion R/lrr_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' Internal function to convert an object of class 'im' to values readable by \code{\link[fields]{image.plot}} function within the \code{\link{rrs}} and \code{\link{lotrrs}} functions.
#'
#' @param input An object of class 'rrs' from the \code{\link{rrs}} or \code{\link{lotrrs}} function.
#' @param plot_cols Character string of length three (3) specifying the colors for plotting: 1) numerator, 2) insignificant, and 3) denominator from the \code{\link{rrs}} or \code{\link{lotrrs}} function.
#' @param cols Character string of length three (3) specifying the colors for plotting: 1) numerator, 2) insignificant, and 3) denominator from the \code{\link{rrs}} or \code{\link{lotrrs}} function.
#' @param midpoint Numeric. The value to center the diverging color palette.
#' @param lower_lrr Numeric. The lower value to concatenate the color key. The default (NULL) uses the minimum value from \code{input}.
#' @param upper_lrr Numeric. The upper value to concatenate the color key. The default (NULL) uses the maximum value from \code{input}.
Expand Down
118 changes: 53 additions & 65 deletions R/pval_correct.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#' Calculate p-value corrections
#' Calculate p-value corrections for multiple testing
#'
#' Internal function to calculate various p-value corrections for use within the \code{\link{rrs}} and \code{\link{lotrrs}} functions.
#'
Expand Down Expand Up @@ -31,75 +31,63 @@ pval_correct <- function(input,
type = c("FDR", "correlated Sidak", "correlated Bonferroni", "uncorrelated Sidak", "uncorrelated Bonferroni", "Adler and Hasofer", "Friston"),
alpha = 0.05,
nbc = NULL) {

# False Discovery Rate
if (type == "FDR") {
sort_pvals <- sort(as.vector(input$P$v), decreasing = TRUE)

fdr <- function(pvals, alpha) {
m <- length(pvals)
for (i in 1:length(pvals)) {
if (pvals[i] <= (i/m) * alpha) {
pcrit <- pvals[i]
return(pcrit)
}
}
max(pcrit, min(pvals, na.rm = TRUE))
# False Discovery Rate
if (type == "FDR") {
sort_pvals <- sort(as.vector(input$P$v))
p_critical <- fdr(sort_pvals, alpha)
return(p_critical)
}

out_alpha <- fdr(sort_pvals, alpha)
return(out_alpha)
}

# Correlated Bonferroni correction
# Correlated Bonferroni correction
if (type == "correlated Bonferroni" | type == "correlated Sidak") {
## Prepare data
### Coordinates of grid points within input 'im'
rx <- rep(input$lrr$xcol, length(input$lrr$yrow))
for(i in 1:length(input$lrr$yrow)) {
if (i == 1) { ry <- rep(input$lrr$yrow[i], length(input$lrr$xcol)) }
if (i != 1) { ry <- c(ry, rep(input$lrr$yrow[i], length(input$lrr$xcol))) }
}
### Create data frame of values to estimate spatial correlation
out <- data.frame("x" = rx,
"y" = ry,
"v" = as.vector(t(input$lrr$v)))
out$v <- ifelse(is.infinite(out$v), NA, out$v) # omit inifite values
out <- out[!is.na(out$v),] # omit NA values

if(is.null(nbc)) { nbc <- 30 }

## Estimate spatial correlation
out_cor <- SpatialPack::modified.ttest(x = out[ , 3],
y = out[ , 3],
coords = out[ , 1:2],
nclass = nbc)

# Find shortest distance without significant correlation
corr_eff <- out_cor$upper.bounds[min(which(out_cor$imoran[, 1] <= 0))]
## Prepare data
### Coordinates of grid points within input 'im'
rx <- rep(input$lrr$xcol, length(input$lrr$yrow))
for(i in 1:length(input$lrr$yrow)) {
if (i == 1) { ry <- rep(input$lrr$yrow[i], length(input$lrr$xcol)) }
if (i != 1) { ry <- c(ry, rep(input$lrr$yrow[i], length(input$lrr$xcol))) }
}
### Create data frame of values to estimate spatial correlation
out <- data.frame("x" = rx,
"y" = ry,
"v" = as.vector(t(input$lrr$v)))
out$v <- ifelse(is.infinite(out$v), NA, out$v) # omit inifite values
out <- out[!is.na(out$v),] # omit NA values

## Bonferroni
x_kern <- length(input$lrr$xcol) # number of kernels in x-axis
y_kern <- length(input$lrr$yrow) # number of kernels in y-axis
x_dist_kern <- input$lrr$xstep # distance between kernels in x-axis
y_dist_kern <- input$lrr$ystep # distance between kernels in y-axis
n_x_kern <- corr_eff / x_dist_kern # number of x-axis kernels within correlation distance
n_y_kern <- corr_eff / y_dist_kern # number of y- axis kernels within correlation distance
x_uncorr <- x_kern / n_x_kern # number of uncorrelated x-axis kernels
y_uncorr <- y_kern / n_y_kern # number of uncorrelated y-axis kernels
n_uncorr <- x_uncorr * y_uncorr # total number of uncorrelated kernels

# Correlated Sidak correction
if (type == "correlated Sidak") {
p_critical <- 1 - (1 - alpha) ^ (1 / n_uncorr )
}

# Correlated Bonferroni correction
if (type == "correlated Bonferroni") {
p_critical <- alpha / n_uncorr
}

return(p_critical)
if(is.null(nbc)) { nbc <- 30 }

## Estimate spatial correlation
out_cor <- SpatialPack::modified.ttest(x = out[ , 3],
y = out[ , 3],
coords = out[ , 1:2],
nclass = nbc)

# Find shortest distance without significant correlation
corr_eff <- out_cor$upper.bounds[min(which(out_cor$imoran[, 1] <= 0))]

## Bonferroni
x_kern <- length(input$lrr$xcol) # number of kernels in x-axis
y_kern <- length(input$lrr$yrow) # number of kernels in y-axis
x_dist_kern <- input$lrr$xstep # distance between kernels in x-axis
y_dist_kern <- input$lrr$ystep # distance between kernels in y-axis
n_x_kern <- corr_eff / x_dist_kern # number of x-axis kernels within correlation distance
n_y_kern <- corr_eff / y_dist_kern # number of y- axis kernels within correlation distance
x_uncorr <- x_kern / n_x_kern # number of uncorrelated x-axis kernels
y_uncorr <- y_kern / n_y_kern # number of uncorrelated y-axis kernels
n_uncorr <- x_uncorr * y_uncorr # total number of uncorrelated kernels

# Correlated Sidak correction
if (type == "correlated Sidak") {
p_critical <- 1 - (1 - alpha) ^ (1 / n_uncorr )
}

# Correlated Bonferroni correction
if (type == "correlated Bonferroni") {
p_critical <- alpha / n_uncorr
}

return(p_critical)
}

# Uncorrelated Sidak correction
Expand Down
12 changes: 12 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
# Not within. Opposite of %in%
`%!in%` <- function(x, y)!(`%in%`(x, y))

# False Discovery Rate (Benjamini & Hochberg)
fdr <- function(pvals, alpha) {
pcrit <- NULL
m <- length(pvals)
for (i in 1:m) {
if (pvals[i] <= (i/m) * alpha) {
pcrit <- pvals[i]
}
}
return(max(pcrit, pvals[1]))
}
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ gateR: Flow/Mass Cytometry Gating via Spatial Kernel Density Estimation <img src
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.5347892.svg)](https://doi.org/10.5281/zenodo.5347892)
<!-- badges: end -->

**Date repository last updated**: February 01, 2023
**Date repository last updated**: January 22, 2024

<h2 id="overview">

Expand Down Expand Up @@ -250,6 +250,17 @@ test_rrs <- gateR::rrs(dat = obs_dat[ , -7:-6])
## A p-value uncorrected for multiple testing
## For "arcsinh_CD8" and "arcsinh_CD3"
test_lotrrs <- gateR::lotrrs(dat = obs_dat[ , -5:-4])

# ------------------------------------------ #
# Run gateR with multiple testing correction #
# ------------------------------------------ #

## False Discovery Rate
test_gating_fdr <- gateR::gating(dat = obs_dat,
vars = c("arcsinh_CD4", "arcsinh_CD38",
"arcsinh_CD8", "arcsinh_CD3"),
n_condition = 1,
p_correct = "FDR")
```

### Funding
Expand Down
8 changes: 3 additions & 5 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
## This is the thirteenth resubmission
## This is the fourteenth resubmission

* Updates since previous submission:
* Migrated R-spatial dependency
* Replaced `raster` in Imports with `terra` because of imminent package retirement
* Updated documentation throughout
* Updated citation style for CITATION file
* Fixed bug in calculation of False Discovery Rate in internal `pval_correct()` function
* Argument `plot_cols` correctly renamed `cols` in `lrr_plot()` function

* Documentation for DESCRIPTION references the following DOIs that throw a NOTE in win-builder, Fedora Linux, and Ubuntu Linux but are valid URLs:
* <https://doi.org/10.1002/sim.4780090616>
Expand Down
8 changes: 4 additions & 4 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ bibentry(bibtype = "manual",
title = "gateR: Flow/Mass Cytometry Gating via Spatial Kernel Density Estimation",
author = as.person("Ian D. Buller"),
publisher = "The Comprehensive R Archive Network",
year = "2023",
number = "0.1.13",
year = "2024",
number = "0.1.14",
doi = "10.5281/zenodo.5347892",
url = "https://cran.r-project.org/package=gateR",

textVersion =
paste("Ian D. Buller (2023).",
paste("Ian D. Buller (2024).",
"gateR: Flow/Mass Cytometry Gating via Spatial Kernel Density Estimation.",
"The Comprehensive R Archive Network.",
"v0.1.13",
"v0.1.14",
"DOI:10.5281/zenodo.5347892",
"Accessed by: https://cran.r-project.org/package=gateR"),

Expand Down
Loading

0 comments on commit f95d530

Please sign in to comment.