From 676a98cfc4598aa6ae4d439dacd7b8fdfc00554d Mon Sep 17 00:00:00 2001 From: Ethan Bass Date: Sat, 11 Feb 2023 11:32:37 -0500 Subject: [PATCH] fix bug with variable length headers in shimadzu ascii files --- DESCRIPTION | 2 +- NEWS.md | 4 +++ R/parsers.R | 71 +++++++++++++++++++++++++++------------------------ README.md | 6 ++--- inst/CITATION | 2 +- 5 files changed, 47 insertions(+), 38 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e55650a..c70a6aa 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: chromConverter Title: Chromatographic File Converter -Version: 0.3.1 +Version: 0.3.2 Authors@R: c( person(given = "Ethan", family = "Bass", email = "ethanbass@gmail.com", role = c("aut", "cre"), diff --git a/NEWS.md b/NEWS.md index c72d5fa..5af1061 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +## chromConverter 0.3.2 + +* Fix 'Shimadzu' ascii parser so it can cope with variable entries in PDA header. + ## chromConverter 0.3.1 * Added support for "Chemstation" UV (`.ch`) files (version 130). diff --git a/R/parsers.R b/R/parsers.R index 5e60ef4..edc1167 100644 --- a/R/parsers.R +++ b/R/parsers.R @@ -78,39 +78,44 @@ read_shimadzu <- function(file, format_in, met[c(2:3), 2] <- gsub(",", ".", met[c(2:3), 2]) } - if (format_in == "fid"){ - xx <- read.csv(file, skip = header[[2]], sep = sep, colClasses="numeric", - na.strings=c("[FractionCollectionReport]","#ofFractions"), - dec = decimal_separator) - - xx <- as.matrix(xx[!is.na(xx[,1]),]) - rownames(xx) <- xx[,1] - xx <- xx[, 2, drop = FALSE] - colnames(xx) <- "Intensity" - data_format <- "long" - } else if (format_in == "dad"){ - xx <- read.csv(file, skip = header[[2]], sep = sep, colClasses="numeric", - na.strings=c("[FractionCollectionReport]","#ofFractions"), row.names = 1, - nrows = as.numeric(met[7,2]), dec = decimal_separator) - xx <- as.matrix(xx[!is.na(xx[,1]),]) - times <- round(seq(met[2,2], met[3,2], length.out = as.numeric(met[7,2])),2) - wavelengths <- round(seq(met[4,2], met[5,2], length.out = as.numeric(met[6,2])),2) - colnames(xx) <- wavelengths - if (data_format == "long"){ - xx <- reshape_chrom(xx) - } - } - if (format_out == "data.frame"){ - xx <- as.data.frame(xx) - } - } else{ - if (length(what) == 1){ - stop("Chromatogram not found.") - } else{ - warning("Chromatogram not found.") - what = "peak_table" + if (format_in == "fid"){ + xx <- read.csv(file, skip = header[[2]], sep = sep, colClasses="numeric", + na.strings=c("[FractionCollectionReport]","#ofFractions"), + dec = decimal_separator) + xx <- as.matrix(xx[!is.na(xx[,1]),]) + rownames(xx) <- xx[,1] + xx <- xx[, 2, drop = FALSE] + colnames(xx) <- "Intensity" + data_format <- "long" + } else if (format_in == "dad"){ + nrows <- as.numeric(met[grep("# of Time Axis Points", met[,1]),2]) + ncols <- as.numeric(met[grep("# of Wavelength Axis Points", met[,1]),2]) + xx <- read.csv(file, skip = header[[2]], sep = sep, colClasses="numeric", + na.strings=c("[FractionCollectionReport]","#ofFractions"), row.names = 1, + nrows = nrows, dec = decimal_separator) + xx <- as.matrix(xx[!is.na(xx[,1]),]) + times <- round(seq(met[grep("Start Time", met[,1]),2], + met[grep("End Time", met[,1]),2], + length.out = nrows), 2) + wavelengths <- round(seq(met[grep("Start Wavelength", met[,1]), 2], + met[grep("End Wavelength", met[,1]), 2], + length.out = ncols), 2) + colnames(xx) <- wavelengths + if (data_format == "long"){ + xx <- reshape_chrom(xx) } } + if (format_out == "data.frame"){ + xx <- as.data.frame(xx) + } + } else{ + if (length(what) == 1){ + stop("Chromatogram not found.") + } else{ + warning("Chromatogram not found.") + what = "peak_table" + } + } } ### extract peak_table @@ -172,8 +177,8 @@ read_shimadzu <- function(file, format_in, }) } else{ xx <- attach_metadata(xx, meta, format_in = "shimadzu", format_out = format_out, - data_format = data_format, - parser = "chromConverter") + data_format = data_format, + parser = "chromConverter") } } xx diff --git a/README.md b/README.md index e2897b6..ec47573 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ chromConverter aims to facilitate the conversion of chromatography data from var - mzML (`.mzml`) - Shimadzu LabSolutions ascii (`.txt`) - Waters ascii (`.arw`) (*provisional support*) -- 'Agilent Chemstation' FID (`.ch` versions 81, 179, 181) +- 'Agilent Chemstation' `.ch` files (versions 8, 81, 130, 179, 181) ### Installation @@ -52,8 +52,8 @@ install.packages("chromConverter") Alternatively, the development version of chromConverter can be installed from GitHub as follows: ``` -install.packages("devtools") -devtools::install_github("https://github.com/ethanbass/chromConverter/") +install.packages("remotes") +remotes::install_github("https://github.com/ethanbass/chromConverter/") ``` or from [R Universe](https://r-universe.dev/): diff --git a/inst/CITATION b/inst/CITATION index 93240f9..a32702c 100644 --- a/inst/CITATION +++ b/inst/CITATION @@ -5,7 +5,7 @@ citEntry( title = "chromConverter: chromatographic file converter", author = "Ethan Bass", year = "2022", - version = "version 0.3.1", + version = "version 0.3.2", doi = "10.5281/zenodo.6792521", url = "https://ethanbass.github.io/chromConverter/", textVersion = paste("Bass, E. (2022).",