Hi,
I have some comments and suggestions on (sample) fresh weight correction.
To my understanding, a fresh weight correction must be done either before the initial peak detection with xcmsSet() (i.e. on the raw data) or after fillPeaks(). If it is done inbetween, a weight correction will be applied only to the originally picked peaks, and not on the ones that are added by fillPeaks(), which would be wrong.
I could not figure out how to do this on the raw data; also, I would prefer to do it later.
The weight-correction code in the Cookbook at
viewtopic.php?f=26&t=143
appears not to be working properly on an xcmsSet object after fillPeaks(), because it does not take into account the order in which peaks are organized in a fillPeaks()ed xcmsSet object (detected peaks first, filled peaks later).
Below is a modified piece of code that should do a weight-correction after fillPeaks(). ( Sorry for the lack of elegance, I am learning R at the same time as I am learning XCMS.)
xset14<-fillPeaks(xset13)
#samples: 20 21 22 23 … example sample names
fw <- c(99.0, 94.3, 101.3, 83.4, …) #example fresh weights (mg)
#first part of factors, for detected peaks
factors1 <- rep(100/fw, times=table(peaks(xset13)[,"sample"]))
#second part of factors, for filled peaks
nrorigpeaks<-nrow(xset13@peaks)+1
nrtotalpeaks<-nrow(xset14@peaks)
factors2<-rep(100/fw, times=table(peaks(xset14)[nrorigpeaks:nrtotalpeaks,"sample"]))
#combine factors
factors<-c(factors1, factors2)
#weight correct
intensitycolumns <- c("into", "intb", "maxo")
xset14@peaks[,intensitycolumns] <- xset14@peaks[,intensitycolumns] * factors
Talking about elegance, it would of course be much nicer with a more “integrated” way of fresh weight correction (or other correction, for that matter). The way of explicit fresh-weight assignment as in the code below will cause trouble in case samples are removed or rearranged upstream. For example, fresh weight could be specified in a table where one column carries the sample names and the other one carries the weights. Does anyone know of a simple way of doing this?
By the way, thanks to the developers for a great xcms!
/Axel