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

v0.6.0 #30

Merged
merged 30 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
81b8c75
set maxI = NULL as default in `preprocess`
ethanbass Aug 20, 2023
e86e10f
feat: improve flexibility in `get_peaktable` input
ethanbass Aug 20, 2023
6cd6212
docs: minor improvements to vignette
ethanbass Aug 20, 2023
cac2230
style: adjusted whitespace (correct_rt)
ethanbass Aug 20, 2023
5da369d
feat: permit parallel processing with socketCluster
ethanbass Aug 20, 2023
20d7a69
docs: updated news, v0.6.0
ethanbass Aug 20, 2023
e6578ef
Update DESCRIPTION
ethanbass Aug 20, 2023
89e1973
Update chromatographR-package.R
ethanbass Aug 20, 2023
87b06cf
Merge branch 'master' into 0.6.0
ethanbass Aug 20, 2023
24b69bb
ci: add dev to github CI
ethanbass Aug 20, 2023
e28982d
fix: logic in choose_apply_fnc
ethanbass Aug 20, 2023
d26146b
fix: close socketClusters in test
ethanbass Aug 20, 2023
59d2624
test: fix choose_apply_fnc tests on windows
ethanbass Aug 20, 2023
1cef044
test: fix choose_apply_fnc tests on windows
ethanbass Aug 20, 2023
673af40
Merge branch 'dev' of https://github.com/ethanbass/chromatographR int…
ethanbass Aug 20, 2023
fbb6d31
edit NEWS
ethanbass Aug 20, 2023
7f832aa
metadata: fix license in zenodo.json
ethanbass Aug 20, 2023
b948993
added test for stripplot
ethanbass Aug 30, 2023
53bec5e
style: whitespace
ethanbass Aug 30, 2023
1e879cc
Update WORDLIST
ethanbass Aug 30, 2023
536c168
fixed attach_metadata bug with NA values
ethanbass Aug 30, 2023
354c17b
Merge branch 'master' into dev
ethanbass Aug 30, 2023
d7b5fef
add back write_peaktable tests
ethanbass Aug 30, 2023
1119d1c
test: skip stripplot test on windows
ethanbass Aug 30, 2023
45a4975
fix: possible bug in ordering of labels with reshape_peaktable
ethanbass Sep 4, 2023
6a95434
Merge branch 'master' (v0.5.6) into dev
ethanbass Sep 22, 2023
2450b94
Update .zenodo.json
ethanbass Sep 22, 2023
df7ab3e
changed vignette to use only one wavelength
ethanbass Sep 26, 2023
ed96451
Update NEWS.md
ethanbass Sep 26, 2023
e93e096
Merge branch 'master' into dev
ethanbass Sep 26, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
branches: [main, master, dev]
pull_request:
branches: [main, master]
branches: [main, master, dev]

name: R-CMD-check

Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: chromatographR
Title: Chromatographic Data Analysis Toolset
Version: 0.5.6
Version: 0.6.0
Authors@R: c(
person("Ethan", "Bass", , "ethanbass@gmail.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-6175-6739")),
Expand Down
17 changes: 16 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# chromatographR 0.6.0

#### New features

* Enabled use of `parallel` package for parallel processing (in addition to current options using `mcapply`). (These options require the installation of suggested package `pbapply`).
* Updated `get_peaktable` for greater flexibility (e.g. for usage of 'Chemstation' peak lists as input).

#### Other changes

* Made some minor changes to vignette to improve clarity (e.g. using single wavelength for integration, etc.)

#### Bug fixes

* Fixed error in `attach_metadata` when there are NA values in merge column.

# chromatographR 0.5.6

* Fixed bug in preprocess function causing fatal error due to misrecognition of matrices.
Expand All @@ -22,7 +37,7 @@
# chromatographR 0.5.2

* Added `metadata` argument to `reshape_peaktable` for filtering metadata fields.
* Added option to for renaming peaks via `reshape_peaktable` by providing a named list.
* Added option for renaming peaks via `reshape_peaktable` by providing a named character vector.

# chromatographR 0.5.1

Expand Down
2 changes: 1 addition & 1 deletion R/attach_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ attach_metadata <- function(peak_table, metadata, column){
}
if (!(column %in% colnames(metadata)))
stop(paste0("Column, ", column, ", is not found."))
if (sum((duplicated(metadata[,column]))) > 0)
if (sum((duplicated(metadata[,column], incomparables = NA))) > 0)
stop(paste("Sample names must be unique. Please check column", sQuote(column),
"for duplicates."))
if (!inherits(peak_table,"peak_table"))
Expand Down
4 changes: 3 additions & 1 deletion R/chromatographR-package.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@


#' chromatographR
#'
#' chromatographR
#'
#' \tabular{ll}{ Package: \tab chromatographR\cr Type: \tab Package\cr Version:
#' \tab 0.5.6 \cr Date: \tab 2023-09-18\cr License: GPL (>= 2) }
#' \tab 0.6.0 \cr Date: \tab 2023-09-22\cr License: GPL (>= 2) }
#'
#' @name chromatographR-package
#' @aliases chromatographR-package chromatographR
Expand Down
6 changes: 3 additions & 3 deletions R/preprocess.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ preprocess <- function(X, dim1, ## time axis
dim2, ## spectral axis
remove.time.baseline = TRUE,
spec.smooth = TRUE,
maxI, parallel = NULL,
maxI = NULL, parallel = NULL,
interpolate_rows = TRUE,
interpolate_cols = TRUE,
mc.cores, cl = 2, show_progress = NULL, ...){
Expand Down Expand Up @@ -148,7 +148,7 @@ preprocess_matrix <- function(X,
dim2, ## spectral axis
remove.time.baseline = TRUE,
spec.smooth = TRUE,
maxI,
maxI = NULL,
interpolate_rows = TRUE,
interpolate_cols = TRUE,
...) {
Expand Down Expand Up @@ -186,7 +186,7 @@ preprocess_matrix <- function(X,
if (min(X, na.rm = TRUE) < 0){
X[X < 0] <- 0
}
if (!missing(maxI)){
if (!is.null(maxI)){
X <- maxI * X / max(X)
}
dimnames(X) <- list(dim1, dim2)
Expand Down
5 changes: 3 additions & 2 deletions R/reshape_chroms.R
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,12 @@ reshape_peaktable <- function(x, peaks, metadata){
if (!missing(peaks)){
x$tab <- x$tab[,which(colnames(x$tab) %in% peaks), drop = FALSE]
if (!is.null(names(peaks))){
colnames(x$tab) <- names(peaks)
colnames(x$tab) <- names(peaks)[match(colnames(x$tab), peaks)]
}
}
if (!missing(metadata)){
x$sample_meta <- x$sample_meta[,which(colnames(x$sample_meta) %in% metadata), drop = FALSE]
meta_idx <- which(colnames(x$sample_meta) %in% metadata)
x$sample_meta <- x$sample_meta[, meta_idx, drop = FALSE]
}
xx <- reshape(as.data.frame(chr = rownames(x$tab), x$tab), direction = "long",
varying = list(1:ncol(x$tab)), v.names = x$args[["response"]],
Expand Down
30 changes: 19 additions & 11 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -238,28 +238,36 @@ transfer_metadata <- function(new_object, old_object,
#' otherwise returns \code{\link{lapply}}.
#' @noRd
choose_apply_fnc <- function(show_progress, parallel = NULL, cl = 2){
pbapply_installed <- check_for_pkg("pbapply", return_boolean = TRUE)
is_not_windows <- .Platform$OS.type != "windows"

if (is.null(show_progress)){
show_progress <- check_for_pkg("pbapply", return_boolean = TRUE)
show_progress <- pbapply_installed
}

if (is.null(parallel)){
parallel <- .Platform$OS.type != "windows"
} else if (parallel & .Platform$OS.type == "windows"){
parallel <- FALSE
warning("Parallel processing is not currently available on Windows.")
}
if (is.null(cl) || cl == 1){
parallel <- FALSE
if (!is.null(cl) && (class(cl)[1] == "SOCKcluster" || (is_not_windows && cl > 1))){
parallel <- TRUE
} else {
parallel <- FALSE
}
}

if (!parallel){
cl <- 1
}

if (.Platform$OS.type == "windows" && parallel && !pbapply_installed){
stop("Please install the pbapply package to use parallel processing on Windows.")
}

if (show_progress){
check_for_pkg("pbapply")
pblapply <- pbapply::pblapply
fn <- purrr::partial(pblapply, cl = cl)
} else if (!show_progress && parallel){
fn <- purrr::partial(mclapply, mc.cores = cl)
} else{
} else if (!show_progress && is_not_windows && is.numeric(cl) && cl > 1){
fn <- purrr::partial(mclapply, mc.cores = cl)
} else {
fn <- lapply
}
fn
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ Also see the [contributing.md](https://github.com/ethanbass/chromatographR/blob/

If you use chromatographR in published work, please cite it as follows:

Bass, E. (2023). chromatographR: chromatographic data analysis toolset (version 0.5.6).
http://doi.org/10.5281/zenodo.6944334
Bass, E. (2023). chromatographR: chromatographic data analysis toolset (version 0.6.0). http://doi.org/10.5281/zenodo.6944334
4 changes: 2 additions & 2 deletions inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ citEntry(
title = "chromatographR: chromatographic data analysis toolset",
author = "Ethan Bass",
year = "2023",
note = "version 0.5.6",
note = "version 0.6.0",
url = "https://ethanbass.github.io/chromatographR/",
doi = "10.5281/zenodo.6944334",
textVersion = paste("Bass, E. (2023).",
"chromatographR: chromatographic data analysis toolset (version 0.5.6).",
"chromatographR: chromatographic data analysis toolset (version 0.6.0).",
"http://doi.org/10.5281/zenodo.6944334"
)
)
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Broeckling
CMD
Carvalho
ChemStation
Chemstation
Chromatograms
Chromatographia
Chromatographic
Expand Down
2 changes: 1 addition & 1 deletion man/chromatographR-package.Rd

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

2 changes: 1 addition & 1 deletion man/preprocess.Rd

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

83 changes: 41 additions & 42 deletions tests/testthat/test-pipeline.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ test_that("plot_chroms works to plot alignments", {
expect_error(plot_chroms(pktab))
})

test_that("plot_chroms works with plotly", {
skip_on_cran()
skip_if_not_installed("vdiffr")
skip_if_not_installed("plotly")
skip_if_not_installed("reticulate")
skip_if_not_installed("rsvg")

p <- plot_chroms(warp, lambdas="210", engine="plotly")
suppressWarnings(expect_doppelganger_plotly(name = "alignment_plotly", p = p))
})

test_that("plot_chroms works to plot alignments with ggplot", {
skip_on_cran()
skip_if_not_installed("vdiffr")
Expand Down Expand Up @@ -366,6 +355,16 @@ test_that("plot_spectrum works with plotly engine", {
expect_doppelganger_plotly("plot_spectrum_plotly", p = p3)
})

test_that("plot_chroms works with plotly", {
skip_on_cran()
skip_if_not_installed("vdiffr")
skip_if_not_installed("plotly")
skip_if_not_installed("reticulate")
skip_if_not_installed("rsvg")
p <- plot_chroms(warp, lambdas="210", engine="plotly")
suppressWarnings(expect_doppelganger_plotly(name = "alignment_plotly", p = p))
})

test_that("plot_spectrum works with ggplot2", {
skip_on_cran()
skip_if_not_installed("vdiffr")
Expand Down Expand Up @@ -465,35 +464,35 @@ test_that("cluster_spectra works", {
expect_equal(class(cl[[2]]), "list")
})

# test_that("write_peaktable writes csvs correctly", {
# data(pk_tab)
# skip_on_cran()
# path <- tempdir(check = TRUE)
# on.exit(unlink(c(fs::path(path,"peak_table-tab", ext="csv"),
# fs::path(path,"peak_table-pk_meta", ext="csv"),
# path)))
# write_peaktable(peak_table = pk_tab, path = path, format = "csv", what=c("tab", "pk_meta"))
# path_table <- paste0(file.path(path,"peak_table-tab"), ext =".csv")
# path_meta <- paste0(file.path(path,"peak_table-pk_meta"), ext =".csv")
#
# expect_true(file.exists(path_table))
# expect_true(file.exists(path_meta))
#
# expect_equal(pk_tab$tab, read.csv(file = path_table, row.names = 1), ignore_attr=TRUE)
# expect_equal(pk_tab$pk_meta, read.csv(file = path_meta, row.names = 1), ignore_attr=TRUE)
# expect_error(write_peaktable(pk_tab, path="fake_path"))
# })
test_that("write_peaktable writes csvs correctly", {
data(pk_tab)
skip_on_cran()
path <- tempdir(check = TRUE)
on.exit(unlink(c(fs::path(path,"peak_table-tab", ext="csv"),
fs::path(path,"peak_table-pk_meta", ext="csv"),
path)))
write_peaktable(peak_table = pk_tab, path = path, format = "csv", what=c("tab", "pk_meta"))
path_table <- paste0(file.path(path,"peak_table-tab"), ext =".csv")
path_meta <- paste0(file.path(path,"peak_table-pk_meta"), ext =".csv")

# test_that("write_peaktable writes xlsx correctly", {
# skip_on_cran()
# skip_if_not_installed("openxlsx")
# data(pk_tab)
# path <- tempdir()
# on.exit(unlink(c(fs::path(path, "peak_table", ext="xlsx"), path)))
#
# write_peaktable(pk_tab, path = path, format = "xlsx")
# file <- fs::path(path, "peak_table", ext = "xlsx")
# xx <- openxlsx::read.xlsx(file, sheet = 1, rowNames = TRUE)
# expect_equal(pk_tab$tab, xx, ignore_attr=TRUE)
# expect_equal(pk_tab$pk_meta, openxlsx::read.xlsx(file, sheet = 2, rowNames = TRUE), ignore_attr=TRUE)
# })
expect_true(file.exists(path_table))
expect_true(file.exists(path_meta))

expect_equal(pk_tab$tab, read.csv(file = path_table, row.names = 1), ignore_attr=TRUE)
expect_equal(pk_tab$pk_meta, read.csv(file = path_meta, row.names = 1), ignore_attr=TRUE)
expect_error(write_peaktable(pk_tab, path="fake_path"))
})

test_that("write_peaktable writes xlsx correctly", {
skip_on_cran()
skip_if_not_installed("openxlsx")
data(pk_tab)
path <- tempdir()
on.exit(unlink(c(fs::path(path, "peak_table", ext="xlsx"), path)))

write_peaktable(pk_tab, path = path, format = "xlsx")
file <- fs::path(path, "peak_table", ext = "xlsx")
xx <- openxlsx::read.xlsx(file, sheet = 1, rowNames = TRUE)
expect_equal(pk_tab$tab, xx, ignore_attr=TRUE)
expect_equal(pk_tab$pk_meta, openxlsx::read.xlsx(file, sheet = 2, rowNames = TRUE), ignore_attr=TRUE)
})
36 changes: 26 additions & 10 deletions tests/testthat/test-utility-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,40 +12,56 @@ test_that("get_lambdas works as expected", {
})

test_that("choose_apply_fnc works as expected", {
skip_on_cran()
skip_if_not_installed("pbapply")
fn <- choose_apply_fnc(show_progress = TRUE)
expect_equal(class(fn), c("purrr_function_partial","function"))
expect_equal(class(fn), c("purrr_function_partial", "function"))

fn <- choose_apply_fnc(show_progress = FALSE, parallel = FALSE)
expect_equal(fn, lapply)
fn <- choose_apply_fnc(show_progress = FALSE, cl=1)
fn <- choose_apply_fnc(show_progress = FALSE, cl = 1)
expect_equal(fn, lapply)
fn <- choose_apply_fnc(show_progress = FALSE, cl=NULL)
fn <- choose_apply_fnc(show_progress = FALSE, cl = NULL)
expect_equal(fn, lapply)
})

test_that("choose apply_fnc works as expected on unix/linux", {
skip_on_cran()
skip_on_os("windows")
fn <- choose_apply_fnc(show_progress = TRUE, parallel=TRUE)

fn <- choose_apply_fnc(show_progress = TRUE, parallel = TRUE)
expect_equal(class(fn), c("purrr_function_partial","function"))

fn <- choose_apply_fnc(show_progress = FALSE, parallel=TRUE)
fn <- choose_apply_fnc(show_progress = FALSE, parallel = TRUE)
expect_equal(class(fn), c("purrr_function_partial","function"))

fn<-choose_apply_fnc(show_progress=NULL, parallel = TRUE)
pbapply_exists <- check_for_pkg("pbapply", return_boolean=TRUE)
pbapply_exists <- check_for_pkg("pbapply", return_boolean = TRUE)
expect_equal(fn, choose_apply_fnc(show_progress = pbapply_exists, parallel = TRUE))

cl <- parallel::makeCluster(2)
fn <- choose_apply_fnc(show_progress = NULL, cl = cl)
expect_equal(class(fn), c("purrr_function_partial", "function"))
parallel::stopCluster(cl)

fn <- choose_apply_fnc(show_progress = NULL, cl = 2)
expect_equal(class(fn), c("purrr_function_partial", "function"))
})

test_that("choose apply_fnc works as expected on windows", {
skip_on_cran()
skip_on_os(c("mac","linux","solaris"))
expect_warning(choose_apply_fnc(show_progress = TRUE, parallel=TRUE))
expect_warning(choose_apply_fnc(show_progress = FALSE, parallel=TRUE))
expect_warning(choose_apply_fnc(show_progress=NULL, parallel = TRUE))
skip_if_not_installed("pbapply")

cl <- parallel::makeCluster(2)
fn <- choose_apply_fnc(show_progress = NULL, cl = cl)
parallel::stopCluster(cl)
expect_equal(class(fn), c("purrr_function_partial", "function"))
})

test_that("choose_apply_fnc works as expected with NULL value", {
pbapply_exists <- check_for_pkg("pbapply", return_boolean=TRUE)
skip_on_cran()
pbapply_exists <- check_for_pkg("pbapply", return_boolean = TRUE)

fn<-choose_apply_fnc(show_progress=NULL, parallel = FALSE)
expect_equal(fn, choose_apply_fnc(show_progress = pbapply_exists, parallel = FALSE))
Expand Down
Loading