Skip to content

Commit

Permalink
fix problems surfaced by CRAN reviews, push version 2.1-14
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbass committed Jul 10, 2022
1 parent b19db7d commit cbabb1b
Show file tree
Hide file tree
Showing 9 changed files with 78 additions and 398 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
^\.gitignore$
^\.github$
^\.git$
^CRAN-SUBMISSION$
13 changes: 8 additions & 5 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
Package: VPdtw
Type: Package
Title: Variable Penalty Dynamic Time Warping
Version: 2.1-13
Version: 2.1-14
Date: 2022-07-03
Author: David Clifford, Glenn Stone
Maintainer: Ethan Bass <[email protected]>
Description: Variable Penalty Dynamic Time Warping for aligning GC-MS chromatograms to a master signal and more. With the appropriate penalty this method performs good alignment without altering the shape of peaks in GC-MS data.
License: GPL-2 | file LICENSE
Authors@R: c(person("David", "Clifford", , email="[email protected]", role = c("aut")),
person("Glenn", "Stone", role = c("aut")),
person("Ethan", "Bass", email = "[email protected]", role = c("ctb", "cre"), comment = c(ORCID = "0000-0002-6175-6739"))
)
Description: Variable Penalty Dynamic Time Warping (VPdtw) for aligning chromatographic signals. With an appropriate penalty this method performs good alignment of chromatographic data without deforming the peaks (Clifford, D., Stone, G., Montoliu, I., Rezzi S., Martin F., Guy P., Bruce S., and Kochhar S.(2009) <doi:10.1021/ac802041e>; Clifford, D. and Stone, G. (2012) <doi:10.18637/jss.v047.i08>).
License: GPL-2
URL: https://github.com/ethanbass/VPdtw/
BugReports: https://github.com/ethanbass/VPdtw/issues

339 changes: 0 additions & 339 deletions LICENSE

This file was deleted.

5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# VPdtw 2.1-14

* Changed messages so they can be suppressed more easily by the user.
* Fixed examples and plot.VPdtw function so they no longer change user's par settings.

# VPdtw 2.1-13

* Added a `NEWS.md` file to track changes to the package.
Expand Down
40 changes: 15 additions & 25 deletions R/VPdtw.R
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
VPdtw <- function(reference,query,penalty=0,maxshift=50,Reference.type=c("random","median","mean","trimmed")) {
VPdtw <- function(reference, query, penalty=0, maxshift=50,
Reference.type=c("random", "median", "mean", "trimmed")) {

## We assume Sakoe Chiba DTW to allow for faster computation times
if(!is.numeric(maxshift)) {
return("Please specify maxshift as an integer value\n")
}
if(!is.numeric(maxshift))
stop("Please specify maxshift as an integer value")

## Figure out what kind of alignment we are doing -

## a reference vector to a query vector?
## no reference and a matrix of query vectors?
## something else = no implementation here

if(is.null(reference) & !is.matrix(query)) {
cat("Please specify a reference when passing a non-matrix query\n")
return("Exiting....\n")
}
if(is.null(reference) & !is.matrix(query))
stop("Please specify a reference when passing a non-matrix query")

if(is.null(reference) & is.matrix(query)) {

## If no reference is specified, we choose one randomly, using
## median, mean or trimmed mean of the query matrix depending on
## the value of type as specified by the user.

type <- match.arg(Reference.type,c("random","median","mean","trimmed"))
type <- match.arg(Reference.type,c("random", "median", "mean", "trimmed"))
ss <- sample(1:ncol(query),1)
reference <- switch(type,
random = query[,ss],
Expand All @@ -32,12 +30,12 @@ VPdtw <- function(reference,query,penalty=0,maxshift=50,Reference.type=c("random
reference <- na.omit(reference)

## if penalty is a number, then this means a constant penalty vector, create that vector
if(length(penalty)==1) penalty <- rep(penalty,length(reference))
if(length(penalty) ==1 )
penalty <- rep(penalty,length(reference))

## Check penalty vector length
if(length(penalty)<length(reference)) {
warning("Penalty vector should be at least of length ",length(reference)," but it has length ",length(penalty),"\n")
return("Exiting...\n")
if(length(penalty) < length(reference)) {
stop("Penalty vector should be at least of length ", length(reference)," but it has length ",length(penalty))
}

## information used in summary at end - what kind of reference do
Expand Down Expand Up @@ -84,7 +82,8 @@ VPdtw <- function(reference,query,penalty=0,maxshift=50,Reference.type=c("random
information <- paste(information,"Max allowed shift is ",maxshift,".\n",sep="")
reference <- na.omit(reference)

if(length(penalty)==1) penalty <- rep(penalty,length(reference))
if(length(penalty)==1)
penalty <- rep(penalty,length(reference))

result <- DoAlignment(query,reference,penalty,maxshift)

Expand Down Expand Up @@ -174,10 +173,6 @@ VPdtw <- function(reference,query,penalty=0,maxshift=50,Reference.type=c("random
output$shift[seq(str,end,by=1),colName] <- result[[ii]][,4]
}

## matplot(output$xVals,output$warpedQuery,type="n",lty=1,col=c(2,3))
## lines(output$xVals,output$reference,lwd=2,col=1)
## matplot(output$xVals,output$warpedQuery,type="l",lty=1,col=c(2,3),add=TRUE)

class(output) <- "VPdtw"

## Summary Statistics for each query separately
Expand Down Expand Up @@ -262,10 +257,6 @@ VPdtw <- function(reference,query,penalty=0,maxshift=50,Reference.type=c("random
colName <- paste("shift penalty",ii)
output$shift[seq(str,end,by=1),colName] <- result[[ii]][,4]
}

## matplot(output$xVals,output$warpedQuery,type="n",lty=1,col=c(2,3))
## lines(output$xVals,output$reference,lwd=2,col=1)
## matplot(output$xVals,output$warpedQuery,type="l",lty=1,col=c(2,3),add=TRUE)
class(output) <- "VPdtw"

## Summary Statistics for each query separately
Expand All @@ -292,9 +283,8 @@ VPdtw <- function(reference,query,penalty=0,maxshift=50,Reference.type=c("random
}

if(is.matrix(query) & is.matrix(penalty)) {
cat("Multiple queries and multiple penalties not yet implemented\n")
cat("Please create loops and call VPdtw as required\n")
return("Exiting....\n")
stop("Multiple queries and multiple penalties not yet implemented.
Please create loops and call VPdtw as needed.")
}

## finished
Expand Down
46 changes: 22 additions & 24 deletions R/plot.VPdtw.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

plot.VPdtw <- function(x,type=c("All","Before","After","Shift"),xlim=NULL,...)
plot.VPdtw <- function(x, type=c("All", "Before", "After", "Shift"), xlim=NULL,
...)
{
bgcol <- grey(0.9)
type <- match.arg(type,c("All","Before","After","Shift"))


oldpar <- par(no.readonly = TRUE)
on.exit(par(oldpar))
pp <- switch(type,
All=par(mfrow=c(3,1)),
Before=par(mfrow=c(1,1)),
Expand All @@ -14,7 +17,6 @@ plot.VPdtw <- function(x,type=c("All","Before","After","Shift"),xlim=NULL,...)
xlim <- c(x$xVals[1],x$xVals[length(x$xVals)])
ylim <- range(x$query,x$reference,na.rm=TRUE)
} else {

ind <- 1:length(x$reference)
ylim <- range(x$reference[which(ind>=xlim[1] & ind <= xlim[2])],na.rm=TRUE)
ind <- 1:length(x$query)
Expand All @@ -28,7 +30,6 @@ plot.VPdtw <- function(x,type=c("All","Before","After","Shift"),xlim=NULL,...)
}

if(type=="All" | type=="Before") {

if(is.matrix(x$query)) {
plot(c(1,nrow(x$query)),c(1,ncol(x$query)),type="n",
xlab="Index",ylab="Sample",
Expand All @@ -39,12 +40,10 @@ plot.VPdtw <- function(x,type=c("All","Before","After","Shift"),xlim=NULL,...)
}

if(is.vector(x$query)) {

plot(xlim,ylim,type="n",xlab="Index",ylab="Intensity",
main="Query and Reference before Alignment")
lines(x$xVals,x$reference,lwd=2,col=1)
lines(x$query,col=2)

}
}

Expand All @@ -53,13 +52,15 @@ plot.VPdtw <- function(x,type=c("All","Before","After","Shift"),xlim=NULL,...)
plot(c(min(x$xVals),max(x$xVals)),c(1,ncol(x$warpedQuery)),type="n",
xlab="Index",ylab="Sample",
main="Queries after Alignment")
rect(min(x$xVals)-1000,-1000,max(x$xVals)+1000,ncol(x$warpedQuery)+1000,col=bgcol)
rect(min(x$xVals)-1000, -1000,
max(x$xVals)+1000, ncol(x$warpedQuery)+1000,
col=bgcol)
image(x$xVals,1:ncol(x$warpedQuery),x$warpedQuery,add=TRUE)
box()
}
if(is.vector(x$query) & is.vector(x$penalty)) {

plot(xlim,ylim,type="n",xlab="Index",ylab="Intensity",main="Query and Reference after Alignment")
plot(xlim,ylim,type="n",xlab="Index",ylab="Intensity",
main="Query and Reference after Alignment")
lines(x$xVals,x$reference,lwd=2,col=1)
lines(x$xVals,x$warpedQuery,col=2)

Expand All @@ -69,36 +70,33 @@ plot.VPdtw <- function(x,type=c("All","Before","After","Shift"),xlim=NULL,...)
return("Error, exiting...\n")
}
if(is.vector(x$query) & is.matrix(x$penalty)) {
##
ncols <- ncol(x$warpedQuery)
plot(xlim,ylim,type="n",xlab="Index",ylab="Intensity",main="Query and Reference after Alignment")
plot(xlim,ylim,type="n",xlab="Index",ylab="Intensity",
main="Query and Reference after Alignment")
lines(x$xVals,x$reference,lwd=2,col=1)
matplot(x$xVals,x$warpedQuery,type="l",lty=1,add=TRUE,col=2:(ncols+1))
legend("topright",legend=c("Reference",paste("penalty #",1:ncols,sep="")),col=1:(ncols+1),lty=rep(1,ncols+1),lwd=c(2,rep(1,ncols)))
legend("topright",legend=c("Reference",paste("penalty #",1:ncols,sep="")),
col=1:(ncols+1),lty=rep(1,ncols+1),lwd=c(2,rep(1,ncols)))
}
}

if(type=="All" | type=="Shift") {
if(type == "All" | type == "Shift") {
if(is.matrix(x$shift)) {
## Image isn't very useful here, matplot is better, though crowded
##image(x$xVals,1:ncol(x$shift),x$shift,xlab="Index",ylab="Sample",main="Shifts after Alignment")
##box()
ncols <- ncol(x$shift)
##xlim <- range(0,x$shift,na.rm=TRUE)

matplot(x$xVals,x$shift,type="l",lty=1,xlab="Index",ylab="Shift",main="Shifts required for Alignment",col=2:(ncols+1),xlim=xlim)
if(is.matrix(x$penalty)) legend("topleft",legend=paste("penalty #",1:ncols,sep=""),col=2:(ncols+1),lty=rep(1,ncols))
if(is.matrix(x$query)) legend("topleft",legend=paste("query #",1:ncols,sep=""),col=2:(ncols+1),lty=rep(1,ncols))

matplot(x$xVals, x$shift, type="l", lty=1, xlab="Index", ylab="Shift",
main="Shifts required for Alignment", col=2:(ncols+1), xlim=xlim)
if (is.matrix(x$penalty))
legend("topleft",legend=paste("penalty #",1:ncols,sep=""),col=2:(ncols+1),lty=rep(1,ncols))
if (is.matrix(x$query))
legend("topleft",legend=paste("query #",1:ncols,sep=""),col=2:(ncols+1),lty=rep(1,ncols))
abline(h=0,lty=2,col=grey(0.75))
}
if(is.vector(x$shift)) {
plot(x$xVals,x$shift,ylim=range(c(0,x$shift),na.rm=TRUE),xlab="Index",ylab="Shift",main="Shifts required for Alignment",type="n",xlim=xlim)
abline(h=0,lty=2,col=grey(0.75))
lines(x$xVals,x$shift)


}
}

par(pp)
}
5 changes: 2 additions & 3 deletions R/signalMatchABand.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ signalMatchABand <- function(reference,query, lambda=rep(0.0,length(reference)),

## Should we warn when we get close to maxshift?
shift <- xVals - xIndices
if(max(abs(shift),na.rm=TRUE)>(3*maxshift/4)) cat("Warning: Observed shift more than three quarters of maxshift\n")
if (max(abs(shift), na.rm=TRUE) > (3*maxshift/4))
warning("Observed shift more than three quarters of maxshift")

## Come up with a nice summary
output <- matrix(NA,length(xVals),4)
Expand All @@ -68,8 +69,6 @@ signalMatchABand <- function(reference,query, lambda=rep(0.0,length(reference)),
output[,"warped query"] <- query[xIndices]
output[,"shift"] <- shift


##cat(range(pp$path - 1:length(pp$path)),"\n")
zz <- output
return(invisible(zz))
}
Expand Down
25 changes: 23 additions & 2 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## Response to reviews

- Have [the] issues [that caused the original package to be archived] been solved?
Yes, as far as I know the package was archived because the native routines were not properly registered. This issue has been remedied as of version 2.1-13.

- As requested, the Description was modified to use the Authors@R field and acronyms were removed from the package description. I also added two references to the package description.

- The LICENSE file was removed since it was redundant with the license stated in the package description.

- Functions no longer use the `cat` command to write messages to the console; `message`, `warning` or `stop` (as appropriate) are now used instead.

- Examples were corrected so that they reset the user's par settings after running.

## R CMD check results

0 errors | 0 warnings | 1 note
Expand All @@ -7,5 +20,13 @@
- While this is marked as a new submission, it was in fact [published on CRAN previously](https://cran.r-project.org/web/packages/VPdtw/index.html).
VPdtw was removed from CRAN on 2017-03-13 -- apparently, because the
"native routines" were not properly registered. This issue has been remedied with
this new version. I am taking over from David Clifford as maintainer with his
permission.
this new version. I am taking over from David Clifford as maintainer with his
permission.

- Found the following (possibly) invalid DOIs:
DOI: 10.1021/ac802041e
From: DESCRIPTION
Status: Service Unavailable
Message: 503

^ This is a valid doi.
2 changes: 2 additions & 0 deletions man/dilation.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ lines(dref,col=2)
BIN <- (volcano>177)
dBIN <- t(apply(BIN,1,dilation,span=5))
dBIN <- apply(dBIN,2,dilation,span=5)
oldpar <- par(no.readonly = TRUE)
par(mfrow=c(2,2))
image(volcano)
image(BIN)
image(dBIN)
par(oldpar)
}

\keyword{methods}

0 comments on commit cbabb1b

Please sign in to comment.