[R] Chromatogram deconvolution and peak matching

Katharine Mullen kate at few.vu.nl
Tue Feb 17 17:50:45 CET 2009


Hoi Bart,

I think you're right that ALS should be applicable to this problem.
Unfortunately in writing I see that there is a bug when the spectra are
NOT constrained to nonnegative values (the package has been used to my
knowledge only in fitting multiway mass spectra thus far, where this
constraint is always applied); I'll have a patched version soon.

I'd be interested in hearing about where the manual could be improved,
too.

#2D chromatogram generation

time <- seq(0,20,by=0.05)
f <- function(x,rt) dnorm((x-rt),mean=0,sd=rt/35)
C1 <- matrix(c( f(time,6.1), f(time,5.6), f(time,15)), nrow=401,ncol=3)
C2 <- matrix(c( f(time,2.1), f(time,4), f(time,8)), nrow=401,ncol=3)

#spectrum generation
spectra <- function(x,a,b,c,d,e) a + b*(x-e) + c*((x-e)^2) + d*((x-e)^3)
x <- 220:300
s1 <- spectra(x,(-194.2),2.386,(-0.009617),(1.275e-05),0)
s2 <- spectra(x,(-1.054e02),1.3,(-5.239e-03),(6.927e-06),-20)
s3 <- spectra(x,(-194.2),2.386,(-0.009617),(1.275e-05),20)
spec <- matrix(c(s1,s2,s3), nrow=81,ncol=3)

## data matrix 1
chrom1 <- C1 %*% t(spec)

## data matrix 2
chrom2 <- C2 %*% t(spec)

require(ALS)

## you want to recover 2 (401 x 3) matrices C1 and C2 and a
## (82 x 3) matrix E such that
## chrom1 = C1 E^T, chrom2 = C2 E^T

## some starting guess for elution profiles
## these need to be pretty good
Cstart1 <- matrix(c( f(time,4), f(time,6), f(time,12)), nrow=401,ncol=3)
Cstart2 <- matrix(c( f(time,3), f(time,5), f(time,10)), nrow=401,ncol=3)

xx <- als( CList = list(Cstart1, Cstart2), PsiList = list(chrom1, chrom2),
          S=matrix(1, nrow=81, ncol=3), x=time, x2=x, uniC=TRUE,
          normS=TRUE, nonnegS=TRUE)

par(mfrow=c(3,1))

matplot(time, xx$CList[[1]], col=2, type="l",
        main="elution profiles chrom1", lty=1,
        ylab="amplitude")

matplot(time, C1, col=1, add=TRUE, type="l", lty=1)

legend(10,2,legend=c("real", "estimated"), col=1:2, lty=1)

matplot(time, xx$CList[[2]], col=2, type="l",
        main="elution profiles chrom2", lty=1,
        ylab="amplitude")

matplot(time, C2, col=1, add=TRUE, type="l", lty=1)

legend(10,6,legend=c("real", "estimated"), col=1:2, lty=1)

matplot(x, xx$S, col=2, type="l", main="spectra", lty=1,
        ylab="amplitude")

matplot(x, spec, col=1, add=TRUE, type="l", lty=1)

legend(270,.95,legend=c("real", "estimated"), col=1:2, lty=1)


On Tue, 17 Feb 2009, bartjoosen wrote:

>
> Hi,
>
> I'm trying to match peaks between chromatographic runs.
> I'm able to match peaks when they are chromatographed with the same method,
> but not when there are different methods are used and spectra comes in to
> play.
>
> While searching I found the ALS package which should be usefull for my
> application, but I couldn't figure it out.
>
> I made some dummy chroms with R, which mimic my actual datasets, to play
> with, but after looking at the manuals of ALS, I'm affraid I can't get the
> job done. Can someone put me on the right way?
>
> Here is my code to generate the dummy chroms, which also plots the 2 chroms
> and the spectra of the 3 peaks:
>
> #2D chromatogram generation
> par(mfrow=c(3,1))
> time <- seq(0,20,by=0.05)
> f <- function(x,rt) dnorm((x-rt),mean=0,sd=rt/35)
> c1 <- f(time,6.1)
> c2 <- f(time,5.6)
> c3 <- f(time,15)
> plot(c1+c2+c3~time,type="l",main="chrom1")
>
> #spectrum generation
> spectra <- function(x,a,b,c,d,e) a + b*(x-e) + c*((x-e)^2) + d*((x-e)^3)
> x <- 220:300
> s1 <- spectra(x,(-194.2),2.386,(-0.009617),(1.275e-05),0)
> s2 <- spectra(x,(-1.054e02),1.3,(-5.239e-03),(6.927e-06),-20)
> s3 <- spectra(x,(-194.2),2.386,(-0.009617),(1.275e-05),20)
>
> chrom1.tot <-
> data.frame(time,outer(c1,s1,"*")+outer(c2,s2,"*")+outer(c2,s2,"*"))
> names(chrom.tot)[-1] <- x
>
> #generation of chromatogram 2
> c1 <- f(time,2.1)
> c2 <- f(time,4)
> c3 <- f(time,8)
> plot(c1+c2+c3~time,type="l",main="chrom2")
>
> chrom2.tot <-
> data.frame(time,outer(c1,s1,"*")+outer(c2,s2,"*")+outer(c2,s2,"*"))
> names(chrom.tot)[-1] <- x
>
> plot(s1~x,type="l",main="spectra")
> lines(s2~x,col=2)
> lines(s3~x,col=3)
>
> Thanks for your time
>
> Kind Regards
>
> Bart
> --
> View this message in context: http://www.nabble.com/Chromatogram-deconvolution-and-peak-matching-tp22057592p22057592.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>




More information about the R-help mailing list