Skip to main content
Topic: sample weight/fresh weight correction (Read 7787 times) previous topic - next topic

sample weight/fresh weight correction

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.)
Code: [Select]
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

Re: sample weight/fresh weight correction

Reply #1
Axel,

You are quite right! I mistakenly copied over the cookbooks from the old help wiki and didn't take the time to check all of them made sense. I guess the example code is assuming that you are not doing any further processing.
I'll update the cookbook after this.

In response to your question the best way to do this would be to put it into the phenoData slot of the xcmsSet object. However, this would cause problems in processing of the data when the method sampClass is called, see below.

Code: [Select]
sampclass(faahko)
 [1] KO KO KO KO KO KO WT WT WT WT WT WT
Levels: KO WT

> faahko@phenoData[,2]<-rnorm(12)
> colnames(faahko@phenoData)<-c("class","correction")
> faahko@phenoData
        class    correction
ko15    KO -0.31316541
ko16    KO -0.98863015
ko18    KO  1.30310404
ko19    KO -2.44810310
ko21    KO  0.08792664
ko22    KO -1.25398753
wt15    WT  0.42322176
wt16    WT -0.63370173
wt18    WT -0.64810154
wt19    WT  1.09348362
wt21    WT -0.12389553
wt22    WT -0.81885280

> sampclass(faahko)
 [1] KO.-0.313165406925513 KO.-0.988630153757617 KO.1.30310403967609  KO.-2.4481030999142  KO.0.0879266365046826
 [6] KO.-1.25398752921148  WT.0.423221757485947  WT.-0.633701734089758 WT.-0.64810154477207  WT.1.09348362162584 
[11] WT.-0.123895528530453 WT.-0.818852797444424
24 Levels: KO.-2.4481030999142 WT.-2.4481030999142 KO.-1.25398752921148 ... WT.1.30310403967609

The sampclass method should probably be changed to allow for multiple 'classes'. I'll have a look at this update.

Cheers,

Paul
~~
H. Paul Benton
Scripps Research Institute
If you have an error with XCMS Online please send me the JOBID and submit an error via the XCMS Online contact page

Re: sample weight/fresh weight correction

Reply #2
Although it is technically possibly, I would be extremely careful with this type of "normalization".

Mass spec signals are not linear ! Only within a very limited range ... and then we also have matrix effects, signal suppression, saturation, etc ...
 If you inject 2x the sample amount, you cannot rely on getting 2x the signal !

There was a lot of discussion on exactly this topic in the Metabolomics workshop at ASMS (Vancouver, Monday night, two weeks ago).
It was my impression that most people agreed that sample normalization should happen before  the measurement,
 i.e. normalization based on fresh weight, dry weight, cell count, etc.