From fa986389a960185b757d0842e6757271036a499b Mon Sep 17 00:00:00 2001 From: Ethan Bass Date: Sat, 21 Dec 2024 16:19:20 -0500 Subject: [PATCH] CI: add tests for Shimadzu tables --- R/read_peaklist.R | 4 +- tests/testthat/test-extra.R | 82 +++++++++++++++++++++++++++++++ tests/testthat/test-read_chroms.R | 8 +-- 3 files changed, 88 insertions(+), 6 deletions(-) diff --git a/R/read_peaklist.R b/R/read_peaklist.R index b1ded8d..fb40066 100644 --- a/R/read_peaklist.R +++ b/R/read_peaklist.R @@ -106,10 +106,10 @@ read_peaklist <- function(paths, find_files, data <- lapply(seq_along(data), function(i){ if (inherits(data[[i]], "list")){ lapply(data[[i]], function(xx){ - cbind(Sample = file_names[i], xx) + cbind(sample = file_names[i], xx) }) } else { - cbind(Sample = file_names[i], data[[i]]) + cbind(sample = file_names[i], data[[i]]) } }) class(data) <- "peak_list" diff --git a/tests/testthat/test-extra.R b/tests/testthat/test-extra.R index 161b872..1c13d46 100644 --- a/tests/testthat/test-extra.R +++ b/tests/testthat/test-extra.R @@ -592,6 +592,38 @@ test_that("read_chroms can read 'Shimadzu' PDA files (ASCII and LCD)", { round(attr(x2, "time_range"), 3)) }) +test_that("Shimadzu Anthocyanin peak tables match", { + skip_on_cran() + skip_if_not_installed("chromConverterExtraTests") + + path_ascii <- system.file("shimadzuDAD_Anthocyanin.txt", + package = "chromConverterExtraTests") + skip_if_not(file.exists(path_ascii)) + + path_lcd <- system.file("Anthocyanin.lcd", + package = "chromConverterExtraTests") + skip_if_not(file.exists(path_lcd)) + + x <- read_peaklist(path_ascii, format_in = "shimadzu_dad", + data_format = "original", + progress_bar = FALSE)[[1]] + + x1 <- read_shimadzu_lcd(path_lcd, what="peak_table") + x1 <- read_peaklist(path_lcd, format_in = "shimadzu_lcd", progress_bar=FALSE)[[1]] + + expect_equal(x[[1]][,c(3,6:7,4:5,8:9,11,13:18,21:22)],x1[[1]][,-1], tolerance=.001, + ignore_attr=TRUE) + expect_equal(x[[2]][,c(3,6:7,4:5,8:9,11,13:18,21:22)],x1[[3]][,-1], tolerance=.001, + ignore_attr=TRUE) + expect_equal(x[[3]][,c(3,6:7,4:5,8:9,11,13:18,21:22)],x1[[4]][,-1], tolerance=.001, + ignore_attr=TRUE) + expect_equal(x[[4]][,c(3,6:7,4:5,8:9,11,13:18,21:22)],x1[[5]][,-1], tolerance=.001, + ignore_attr=TRUE) + expect_equal(x[[5]][,c(3,6:7,4:5,8:9,11,13:18,21:22)],x1[[6]][,-1], tolerance=.001, + ignore_attr=TRUE) +}) + + test_that("read_chroms can read 2D chromatograms from 'Shimadzu' LCD files", { skip_on_cran() skip_if_not_installed("chromConverterExtraTests") @@ -729,6 +761,36 @@ test_that("read_chroms can read multi-channel chromatograms from 'Shimadzu' LCD expect_equal(x2[x2$lambda == "", "intensity"], x[["B"]], ignore_attr = TRUE) }) +test_that("Shimadzu multichannel peak tables match", { + skip_on_cran() + skip_if_not_installed("chromConverterExtraTests") + + path_asc <- system.file("multichannel_chrom.txt", + package = "chromConverterExtraTests") + + skip_if_not(file.exists(path_asc)) + + path_lcd <- system.file("multichannel_chrom.lcd", + package = "chromConverterExtraTests") + skip_if_not(file.exists(path_lcd)) + + x <- read_peaklist(path_asc, format_in = "shimadzu_dad", + data_format = "original", + progress_bar = FALSE)[[1]] + + x1 <- read_peaklist(path_lcd, format_in = "shimadzu_lcd", + progress_bar=FALSE)[[1]] + + + expect_equal(x[[1]][,c(3,6:7,4:5,8:9,11,13:18,21:22)],x1[[1]][,-1], tolerance=.01, + ignore_attr=TRUE) + expect_equal(x[[2]][,c(3,6:7,4:5,8:9,11,13:18,21:22)],x1[[2]][,-1], tolerance=.001, + ignore_attr=TRUE) + expect_equal(x[[3]][,c(3,6:7,4:5,8:9,11,13:18,21:22)],x1[[3]][,-1], tolerance=.001, + ignore_attr=TRUE) +}) + + test_that("read_chroms can read 'Agilent' .dx files", { skip_on_cran() skip_if_not_installed("chromConverterExtraTests") @@ -874,6 +936,26 @@ test_that("Shimadzu GCD parser works", { expect_equal(as.numeric(attr(txt, "time_range")), round(attr(x, "time_range"), 3)) }) +test_that("Shimadzu FID peak tables match", { + skip_on_cran() + skip_if_not_installed("chromConverterExtraTests") + + path_asc <- test_path("testdata/ladder.txt") + + path_gcd <- system.file("FS19_214.gcd", package = "chromConverterExtraTests") + skip_if_not(file.exists(path_gcd)) + + x <- read_peaklist(path_asc, format_in = "shimadzu_dad", + data_format = "original", + progress_bar = FALSE)[[1]] + + x1 <- read_peaklist(path_gcd, format_in = "shimadzu_gcd", progress_bar=FALSE) + + expect_equal(x[,c(3,6:7,4:5,8:9,11,13:18,21:22)], x1[[1]][,-1], tolerance=.001, + ignore_attr=TRUE) +}) + + test_that("Shimadzu QGD parser works", { skip_on_cran() skip_if_missing_dependencies() diff --git a/tests/testthat/test-read_chroms.R b/tests/testthat/test-read_chroms.R index 5e7f32d..ebd4aaf 100644 --- a/tests/testthat/test-read_chroms.R +++ b/tests/testthat/test-read_chroms.R @@ -298,10 +298,10 @@ test_that("read_peaklist can read `Shimadzu` fid files", { expect_equal(x[[1]][[1,"sample"]], "ladder") expect_equal(x[[1]][[1,"sample"]], "ladder") expect_equal(colnames(x[[1]]), - c("sample","Peak.","R.Time","I.Time","F.Time","Area","Height", - "A.H","Conc.","Mark","ID.","Name", "k.", "Plate..", "Plate.Ht.", - "Tailing", "Resolution", "Sep.Factor", "Area.Ratio", "Height.Ratio", - "Conc...", "Norm.Conc.")) + c("sample","Peak#","R.Time","I.Time","F.Time","Area","Height", + "A/H","Conc.","Mark","ID#","Name", "k'", "Plate #", "Plate Ht.", + "Tailing", "Resolution", "Sep.Factor", "Area Ratio", "Height Ratio", + "Conc. %", "Norm Conc.")) expect_equal(attr(x, "class"), "peak_list") })