Skip to content

Commit b6add62

Browse files
committed
fix: behavior of shimadzu parser with multiple 2d chroms
1 parent 0f7ceef commit b6add62

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Fixed bug affecting some `mdf` files lacking null bytes after the file header.
55
* Sped up `read_shimadzu_lcd` by dealing with twos-complements more sensibly.
66
* Allow relative paths for `path_out` when using 'ThermoRawFileParser' and 'OpenChrom' parsers.
7+
* Updated handling of multiple chromatograms by `read_shimadzu_lcd`. The function now returns a list of named chromatograms if `data_format == "wide"` and returns multiple chromatograms in one data.frame if `data_format == "long"`.
78

89
## chromConverter 0.6.4
910

R/read_shimadzu_lcd.R

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,9 @@ read_sz_lcd_2d <- function(path, format_out = "matrix",
220220
read_metadata = TRUE,
221221
metadata_format = "shimadzu_lcd",
222222
scale = TRUE){
223-
223+
if (data_format == "long"){
224+
format_out <- "data.frame"
225+
}
224226
existing_streams <- check_streams(path, what = "chromatogram")
225227
if (length(existing_streams) == 0){
226228
stop("Chromatogram streams not detected.")
@@ -243,7 +245,8 @@ read_sz_lcd_2d <- function(path, format_out = "matrix",
243245
dat <- dat*DI$detector.vf
244246
}
245247
if (data_format == "long"){
246-
cbind(rt = times, int = dat$int)
248+
dat <- data.frame(rt = times, int = dat$int, detector = DI$DETN,
249+
channel = DI$DSCN, wavelength = DI$ADN)
247250
}
248251
if (format_out == "matrix"){
249252
dat <- as.matrix(dat)
@@ -255,6 +258,16 @@ read_sz_lcd_2d <- function(path, format_out = "matrix",
255258
}
256259
dat
257260
})
261+
262+
names(dat) <- sapply(dat, function(x){
263+
det <- gsub("Detector ", "", attr(x,"detector"))
264+
wv <- attr(x, "wavelength")
265+
ifelse(wv == "", det, paste(det, wv, sep = ", "))
266+
})
267+
268+
if (data_format == "long"){
269+
dat <- do.call(rbind, c(dat, make.row.names = FALSE))
270+
}
258271
if (length(dat) == 1){
259272
dat <- dat[[1]]
260273
}
@@ -295,7 +308,7 @@ read_sz_tic <- function(path, format_out = c("matrix", "data.frame"),
295308
on.exit(close(f))
296309
dat <- decode_sz_tic(f)
297310
if (data_format == "wide"){
298-
row.names(dat) <- dat[,"rt"]
311+
row.names(dat) <- dat[, "rt"]
299312
dat <- dat[,"int", drop=FALSE]
300313
}
301314
if (format_out == "data.frame"){
@@ -323,7 +336,7 @@ decode_sz_tic <- function(f){
323336
count <- count + 1
324337
}
325338
mat[,1] <- mat[,1]/1000
326-
colnames(mat) <- c("rt","index","int")
339+
colnames(mat) <- c("rt", "index", "int")
327340
mat
328341
}
329342

@@ -365,7 +378,6 @@ read_sz_method <- function(path, stream = c("GUMM_Information", "ShimadzuPDA.1",
365378
}
366379
data
367380
}
368-
369381
sz_extract_upd_elements(method_stream, xpath = "/GUD/UP/UPD")
370382
}
371383
}
@@ -689,7 +701,7 @@ read_sz_file_properties <- function(path){
689701
collapse = "\n")
690702
xml_doc <- xml2::read_xml(xml_content)
691703
})
692-
names(props) <- sapply(props, xml_name)
704+
names(props) <- sapply(props, xml2::xml_name)
693705
meta <- suppressWarnings(unlist(lapply(props, sz_decode_props),
694706
recursive = FALSE))
695707
meta
@@ -719,8 +731,9 @@ read_sz_3DDI <- function(path){
719731
meta <- as.list(xml2::xml_text(nodes[-rm]))
720732
names(meta) <- xml2::xml_name(nodes[-rm])
721733

722-
meta[c("WVB","WVE","WLS")] <- lapply(meta[c("WVB","WVE","WLS")], function(x){
723-
sz_float(x)/100
734+
meta[c("WVB","WVE","WLS")] <-
735+
lapply(meta[c("WVB","WVE","WLS")], function(x){
736+
sz_float(x)/100
724737
})
725738
meta <- c(meta, read_sz_2DDI(xml2::xml_find_all(doc, ".//GUD[@Type='2DDataItem']"),
726739
read_file = FALSE))

man/read_mdf.Rd

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)