Skip to content

Commit

Permalink
fix bug with variable length headers in shimadzu ascii files
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbass committed Feb 11, 2023
1 parent 3089624 commit 676a98c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 38 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]",
role = c("aut", "cre"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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).
Expand Down
71 changes: 38 additions & 33 deletions R/parsers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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/):
Expand Down
2 changes: 1 addition & 1 deletion inst/CITATION
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down

0 comments on commit 676a98c

Please sign in to comment.