Skip to content

Commit 3a25c55

Browse files
committed
v0.5.1 bug fixes
remove default legend in plot_chroms
1 parent 0ac1312 commit 3a25c55

File tree

9 files changed

+58
-50
lines changed

9 files changed

+58
-50
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: chromatographR
33
Title: Chromatographic Data Analysis Toolset
4-
Version: 0.5.0
4+
Version: 0.5.1
55
Authors@R: c(
66
person("Ethan", "Bass", , "[email protected]", role = c("aut", "cre"),
77
comment = c(ORCID = "0000-0002-6175-6739")),

NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# chromatographR 0.5.1
2+
3+
* In `plot_chroms`, `show_legend` now defaults to FALSE to prevent overloading of the plot.
4+
5+
#### Bug fixes
6+
7+
* Fixed syntactical bug in `get_peaktable` when applied to gaussian peak list.
8+
* Fixed bug caused by improper transfer of `time.units` metadata by `filter_peaks` function.
9+
* Added default for missing `time.units` in `plot.peak_list`.
10+
111
# chromatographR 0.5.0
212

313
#### New features

R/filter_peaks.R

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,13 @@ filter_peaks <- function(peak_list, min_height, min_area,
6262
lapply(smpl,
6363
function(comp)
6464
comp[which(comp[,"sd"] < max_sd &
65-
comp[,"sd"] > min_sd &
66-
comp[,"height"] > min_height &
67-
comp[,"area"] > min_area &
68-
comp[,"rt"] > as.numeric(min_rt) &
69-
comp[,"rt"] < as.numeric(max_rt)), , drop = FALSE]))
65+
comp[, "sd"] > min_sd &
66+
comp[, "height"] > min_height &
67+
comp[, "area"] > min_area &
68+
comp[, "rt"] > as.numeric(min_rt) &
69+
comp[, "rt"] < as.numeric(max_rt)), , drop = FALSE]))
7070
att <- attributes(peak_list)
71-
structure(result,
72-
chrom_list = att$chrom_list,
73-
lambdas = att$lambdas, fit=att$fit, sd.max=att$sd.max,
74-
max.iter=att$max.iter,
75-
class="peak_list")
71+
transfer_metadata(result, peak_list, c('names','row.names','dim','dimnames'))
7672
}
7773

7874
#' Filter peak table

R/get_peaktable.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,9 @@ get_peaktable <- function(peak_list, chrom_list, response = c("area", "height"),
152152
pkcenters.cl[sing] <- max(pkcenters.cl) + seq_along(sing)
153153
}
154154
vars <- c("rt", "start", "end", "sd", "tau", "FWHM", "r.squared", "purity")
155-
cl.centers <- aggregate(xx[,vars], by = list(pkcenters.cl), FUN = "mean",
156-
na.rm = TRUE, na.action = "na.pass")[,-1]
155+
vars.idx <- which(colnames(xx) %in% vars)
156+
cl.centers <- aggregate(xx[,vars.idx], by = list(pkcenters.cl), FUN = "mean",
157+
na.action = "na.pass")[,-1]
157158
ncl <- length(cl.centers$rt)
158159

159160
## re-order clusters from small to large rt

R/plot.peak_list.R

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@
3232
#' @rdname plot.peak_list
3333
#' @export
3434

35-
plot.peak_list <- function(x, ..., chrom_list, index=1, lambda=NULL,
36-
points=FALSE, ticks=FALSE, a=0.5, color=NULL,
37-
cex.points=0.5, numbers = FALSE, cex.font = 0.5,
35+
plot.peak_list <- function(x, ..., chrom_list, index = 1, lambda = NULL,
36+
points = FALSE, ticks = FALSE, a = 0.5, color = NULL,
37+
cex.points = 0.5, numbers = FALSE, cex.font = 0.5,
3838
y.offset = 25, plot_purity = FALSE, res){
3939
time.units <- attributes(x)$time.units
40-
tfac <- switch(time.units, "min" = 1, "s" = 1/60, "ms" = 1/60000)
40+
time.units <- ifelse(is.null(time.units), "", time.units)
41+
tfac <- switch(time.units, "min" = 1, "s" = 1/60, "ms" = 1/60000, 1)
4142
if (missing(chrom_list)){
4243
chrom_list <- get_chrom_list(x)
4344
}
@@ -50,28 +51,28 @@ plot.peak_list <- function(x, ..., chrom_list, index=1, lambda=NULL,
5051
if (is.numeric(lambda)){
5152
lambda <- as.character(lambda)
5253
}
53-
new.ts <- get_times(x=chrom_list, index=index)
54+
new.ts <- get_times(x = chrom_list, index = index)
5455
y <- chrom_list[[index]][,lambda]
5556
pks <- data.frame(x[[index]][[lambda]])
5657
if ("r.squared" %in% colnames(pks)){
5758
fit <- ifelse("tau" %in% colnames(pks), "egh", "gaussian")
5859
} else{
5960
fit <- "raw"
6061
}
61-
plot(new.ts, y, type='l', xlab='', ylab='', xaxt='n', yaxt='n', ...)
62+
plot(new.ts, y, type = 'l', xlab = '', ylab = '', xaxt = 'n', yaxt = 'n', ...)
6263
if (points){
63-
points(pks$rt, pks$height, pch=20, cex=cex.points, col='red')
64+
points(pks$rt, pks$height, pch = 20, cex=cex.points, col = 'red')
6465
}
6566
if (ticks){
66-
arrows(pks$start, y[which(new.ts %in% pks$start)]-5,
67-
pks$start, y[which(new.ts %in% pks$start)]+5,
68-
col="blue", length=0)
69-
arrows(pks$end, y[which(new.ts %in% pks$end)]-5,
70-
pks$end,y[which(new.ts %in% pks$end)]+5,
71-
col="blue", length=0)
67+
arrows(pks$start, y[which(new.ts %in% pks$start)] - 5,
68+
pks$start, y[which(new.ts %in% pks$start)] + 5,
69+
col="blue", length = 0)
70+
arrows(pks$end, y[which(new.ts %in% pks$end)] - 5,
71+
pks$end,y[which(new.ts %in% pks$end)] + 5,
72+
col="blue", length = 0)
7273
}
7374
if (numbers){
74-
text(pks$rt, y[pks$rt] + y.offset, labels=seq_len(nrow(pks)), cex=cex.font)
75+
text(pks$rt, y[pks$rt] + y.offset, labels=seq_len(nrow(pks)), cex = cex.font)
7576
}
7677
if (missing(res))
7778
res <- get_time_resolution(chrom_list)
@@ -87,7 +88,7 @@ plot.peak_list <- function(x, ..., chrom_list, index=1, lambda=NULL,
8788
else if (fit == "egh"){
8889
yvals <- egh(x = peak.loc, center = pks$rt[i],
8990
width=pks$sd[i]*tfac, height = pks$height[i],
90-
tau=pks$tau[i]*tfac)
91+
tau = pks$tau[i]*tfac)
9192
if (is.null(color))
9293
color <- "purple"
9394
}
@@ -97,7 +98,7 @@ plot.peak_list <- function(x, ..., chrom_list, index=1, lambda=NULL,
9798
color <- "hotpink"
9899
}
99100
draw_trapezoid(peak.loc, yvals, color, a)
100-
}, silent=TRUE)
101+
}, silent = TRUE)
101102
}
102103
if (plot_purity){
103104
try({
@@ -113,10 +114,10 @@ plot.peak_list <- function(x, ..., chrom_list, index=1, lambda=NULL,
113114
p <- get_purity_values(chrom_list[[index]], pos)
114115
# lines(as.numeric(new.ts[idx]), -scales::rescale(p, c(0,20)), col = "darkgray", lty=3, lwd=1.5)
115116
lim=-20
116-
draw_trapezoid(new.ts[idx], scales::rescale(p, c(0,lim)), color="black", a=0.6)
117-
abline(h=lim, lty=3, col="darkgray")
117+
draw_trapezoid(new.ts[idx], scales::rescale(p, c(0,lim)), color="black", a = 0.6)
118+
abline(h = lim, lty = 3, col = "darkgray")
118119
})
119-
}, silent=TRUE)
120+
}, silent = TRUE)
120121
}
121122
}
122123

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ Also see the [contributing.md](https://github.com/ethanbass/chromatographR/blob/
5757

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

60-
Bass, E. (2023). chromatographR: chromatographic data analysis toolset (version 0.5.0).
60+
Bass, E. (2023). chromatographR: chromatographic data analysis toolset (version 0.5.1).
6161
http://doi.org/10.5281/zenodo.6944334

inst/CITATION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ citEntry(
55
title = "chromatographR: chromatographic data analysis toolset",
66
author = "Ethan Bass",
77
year = "2023",
8-
note = "version 0.5.0",
8+
note = "version 0.5.1",
99
url = "https://ethanbass.github.io/chromatographR/",
1010
doi = "10.5281/zenodo.6944334",
1111
textVersion = paste("Bass, E. (2023).",
12-
"chromatographR: chromatographic data analysis toolset (version 0.5.0).",
12+
"chromatographR: chromatographic data analysis toolset (version 0.5.1).",
1313
"http://doi.org/10.5281/zenodo.6944334"
1414
)
1515
)

vignettes/chromatographR.Rmd

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ vignette: >
1616
library("knitr", quietly=TRUE)
1717
library(chromatographR)
1818
library(parallel)
19-
opts_chunk$set(prompt = TRUE, highlight = FALSE, comment=NA,
20-
dpi=200, fig.width=5, out.width="600px")
19+
opts_chunk$set(prompt = TRUE, highlight = FALSE, comment = NA,
20+
dpi = 200, fig.width = 5, out.width = "600px")
2121
suppressMessages(require(chromatographR, quiet=TRUE))
2222
```
2323

@@ -66,8 +66,8 @@ lambda='200.00000'
6666
6767
matplot(x=tpoints, y=Sa[[i]][,lambda],
6868
type='l', ylab='Abs (mAU)', xlab='Time (min)')
69-
matplot(x=tpoints, y = ptw::baseline.corr(Sa[[i]][,lambda],p=.001,lambda=1e5),
70-
type='l', add = T, col='blue', lty = 3)
69+
matplot(x=tpoints, y = ptw::baseline.corr(Sa[[i]][,lambda],p = .001,lambda = 1e5),
70+
type='l', add = TRUE, col='blue', lty = 3)
7171
```
7272

7373
```{r, preprocessing, eval=T}
@@ -88,7 +88,7 @@ In many cases, liquid chromatography can suffer from retention time shifts (e.g.
8888
The `ptw` option can take a single wavelength or a list of wavelengths provided by the user using the `lambdas` argument. For each chromatogram, `ptw` then produces a "global" warping function across all the wavelengths supplied by the user. The code block below creates warping models for the samples in the provided list of data matrices. The same function is then used to warp each chromatogram according to the corresponding model, by setting the `models` parameter. Depending on the variety of your samples and the severity of the retention time shifts, it may take some experimentation with the warping parameters to get satisfactory results. Sometimes less can actually be more here -- for example, wavelengths with fewer peaks may sometimes yield better warping models. (Also see the documentation for [ptw](https://CRAN.R-project.org/package=ptw) for more guidance on warp function optimization).
8989

9090
```{r, warp models}
91-
warping.models <- correct_rt(dat.pr, what = "models", lambdas=c("210"), scale = TRUE)
91+
warping.models <- correct_rt(dat.pr, what = "models", lambdas = c("210"), scale = TRUE)
9292
warp <- correct_rt(chrom_list = dat.pr, models = warping.models, what = "corrected.values")
9393
```
9494

@@ -121,10 +121,10 @@ oldpar <- par(no.readonly = TRUE)
121121
122122
par(mfrow=c(2,1))
123123
plot_chroms(warp, lambdas = c("210","260"))
124-
legend("topleft", legend="vpdtw", bty = "n")
124+
legend("topleft", legend = "vpdtw", bty = "n")
125125
126126
plot_chroms(dat.pr, lambdas = c("210","260"))
127-
legend("topleft", legend="raw", bty = "n")
127+
legend("topleft", legend = "raw", bty = "n")
128128
129129
par(oldpar)
130130
```
@@ -154,9 +154,9 @@ The `plot.peak_list` function allows you to visually assess the peak integration
154154
```{r, plot_peaks, warning=FALSE, fig.height=6}
155155
oldpar <- par(no.readonly = TRUE)
156156
par(mfrow=c(3,1))
157-
plot(pks_gauss, index=1, lambda='210')
158-
plot(pks_egh, index=1, lambda='210')
159-
plot(pks_raw, index=1, lambda='210')
157+
plot(pks_gauss, index = 1, lambda = '210')
158+
plot(pks_egh, index = 1, lambda = '210')
159+
plot(pks_raw, index = 1, lambda = '210')
160160
par(oldpar)
161161
```
162162

@@ -189,7 +189,7 @@ pk_tab <- normalize_data(peak_table = pk_tab, column="mass")
189189
The `mirror_plot` function provides a quick way to visually compare results across treatment groups.
190190

191191
```{r}
192-
mirror_plot(pk_tab, lambdas = c("210","260"), var = "trt", legend_size=2)
192+
mirror_plot(pk_tab, lambdas = c("210","260"), var = "trt", legend_size = 2)
193193
```
194194

195195
##### Plotting spectra
@@ -198,9 +198,9 @@ The `plot_spectrum` function allows you to easily plot or record the spectra ass
198198

199199
```{r, plot spectra, fig.height=6}
200200
oldpar <- par(no.readonly = TRUE)
201-
par(mfrow=c(2,1))
202-
peak="V7"
203-
plot_spectrum(peak, peak_table = pk_tab, chrom_list=warp, verbose=FALSE)
201+
par(mfrow = c(2,1))
202+
peak = "V7"
203+
plot_spectrum(peak, peak_table = pk_tab, chrom_list = warp, verbose = FALSE)
204204
par(oldpar)
205205
```
206206

vignettes/references.bib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ @article{birkett2006
2323
urldate = {2022-11-12},
2424
abstract = {The stemborers Chilo partellus and Busseola fusca are major pests of subsistence cereal farming in Africa. Volatiles released by two cultivated hosts, sorghum and maize (Sorghum bicolor and Zea mays), and two wild grass hosts, Pennisetum purpureum and Hyparrhenia tamba, were collected by air entrainment. Electrophysiologically active components in these samples were detected by coupled gas chromatography-electroantennography (GC-EAG), and the active peaks identified by gas chromatography-mass spectrometry. A total of 41 compounds were identified from the four plant species, all of which, as well as two unidentified compounds, elicited an electrophysiological response from one or both of the stemborers. The compounds included a number of green leaf volatiles and other aliphatic aldehydes, ketones, and esters, mono- and sesquiterpenoids, and some aromatic compounds. EAG studies with authentic samples, conducted at two discriminating doses for all compounds, and dose\textendash response curves for 14 of the most highly EAG-active compounds, showed significant differences in relative responses between species. The compounds that elicited large responses in both species of moths included linalool, acetophenone, and 4-allylanisole, while a number of compounds such as the aliphatic aldehydes octanal, nonanal, and decanal elicited a large response in B. fusca, but a significantly smaller response in C. partellus. Furthermore, the wild hosts produced higher levels of physiologically active compounds compared with either of the cultivated hosts. These differences are discussed in relation to the differential attraction/oviposition of the two stemborers observed in the field and, particularly for eastern African small-scale farming systems, in the context of using a push\textendash pull strategy for their control.},
2525
langid = {english},
26-
keywords = {Electrophysiology,GC-MS,Host location,Maize,Pushpull,Sorghum,Stemborer,Volatiles},
26+
keywords = {Electrophysiology,GC-MS,Host location,Maize,Push\textendash pull,Sorghum,Stemborer,Volatiles},
2727
file = {/Users/ethanbass/Zotero/storage/VVDS3TTN/Birkett et al. - 2006 - Electrophysiological Responses of the Lepidopterou.pdf}
2828
}
2929

0 commit comments

Comments
 (0)