Skip to main content
Topic: retrieve an averaged spectrum (Read 7904 times) previous topic - next topic

retrieve an averaged spectrum

Hello XCMS gurus,

I am running some infusions of standard compounds and am trying to use the getSpec() function to collect an averaged spectrum for a range of about 30 seconds during which time my standard is eluting.

test<-xcmsRaw("120703_601.CDF", profstep=0.01)
test
spec<-getSpec(test, rtrange=c(45:90))
spec2<-spec[order(spec[,2], decreasing=TRUE),]
spec2[1:20,]

            mz intensity
 [1,] 132.10220  84482.79
 [2,] 132.10226  84476.03
 [3,] 132.10229  84468.90
 [4,] 132.10216  84434.43
 [5,] 132.10213  84392.98
 [6,] 132.10240  84370.49
 [7,] 132.10243  84337.78
 [8,] 132.10246  84293.82
 [9,] 132.10205  84216.37
[10,] 132.10262  83990.52
[11,] 132.10196  83972.10
[12,] 132.10170  83246.16
[13,]  86.09711  37450.49
[14,]  86.09715  37449.09
[15,]  86.09710  37446.60
[16,]  86.09720  37443.11
[17,]  86.09707  37436.68
[18,]  86.09725  37416.95
[19,]  86.09694  37371.84
[20,]  86.09693  37367.13

As you can see, I am not getting any averaging of the spectra unless the mass matches exactly, though the documentation for getScan suggests it can be used for averaging multiple scans.  Am I missing a parameter setting somewhere (a ppm error, for example), or am I trying to do something the function wasn't designed for?  Any advice is greatly appreciated!

Corey

ps.  as a secondary but relevent question:  any way to subtract background spectrum from a portion of the infusion before the compound elutes?

Re: retrieve an averaged spectrum

Reply #1
I have made a little progress using this code:

> xs <- xcmsSet(method="MSW", files="120703_library_test601.CDF", snthresh=1)
120703_library_test601:
> xsg<-group(xs, method="mzClust", mzppm=10, minfrac=5)
47.37  97.37  100.00 
> peaklist <- peakTable(xsg, value="into")
> mz<-vector()
> intensity<-vector()
> for (i in 1:length(xsg@groupidx)) {
+ mz<-c(mz, mean(peaklist[xsg@groupidx[], "mz"]))
+ intensity<-c(intensity, mean(peaklist[xsg@groupidx[], "into"]))
+ }
> mz
[1]  86.09696 132.10216
> intensity
[1] 33563.66 67670.72
>


However, I seem to have lost my isotopes and lower abundance peaks.  I have tried adjusting the snthresh values, to no avail.  Pointers?
Corey

Re: retrieve an averaged spectrum

Reply #2
I really haven't made any progress - any one have any tips?  I just to average a few spectra from infusion data to increase spectrum quality.  Thanks,
Corey

Re: retrieve an averaged spectrum

Reply #3
Hi,

one thing that'd come to mind is to use group.mzClust()
which is an alignment of individual spectra. Originally developed
to group() data from direct infusion spectra in an xcmSet.

Then you could do intensity-weighted averages of the grouped peaks

Check out xcms/R/mzClust.R.

yours,
Steffen
--
IPB Halle                          Mass spectrometry & Bioinformatics
Dr. Steffen Neumann         http://www.IPB-Halle.DE
Weinberg 3 06120 Halle     Tel. +49 (0) 345 5582 - 1470
sneumann(at)IPB-Halle.DE

Re: retrieve an averaged spectrum

Reply #4
I think your approach is OK, the problem is that you have to optimize MSW peak picking first, which can be a little tricky, see also here.

Alternatively, you could export the spectra in centroid mode using your vendor software/converter or try the "deprofiling" code that was posted recently.

With the centroided/picked spectra you can use mzClust to align and postprocess the aligned data to get your averaged spectrum.
Some decision making will be necessary there, e.g. do you want to weight m/z by intensity, do you  want the average for intensities or the local maxima, a noise filter based on the number of peaks aligned, etc.

Ralf

Re: retrieve an averaged spectrum

Reply #5
Ralf,

I have spectra that are already centroided.  I can extract individual spectra from the file using getSpec(), and I can choose those spectra by using the xcmsRaw()@TIC slot.  I am trying to understand how to apply mzClust to to spectra.  The default output for getScan is not an xcmsSet or Raw object structure, so I don't think I can use that directly as input for mzClust.  If I could coerce a spectrum into an xcmsSet object structure, maybe this is possible. 

So I think that I either need to
1. extract individal scans from a raw data file so that they are inserted into an xcmsSet object or
2. coerce the getSpec() output into something mzClust can take. 

I am a bit stumped as to how to do this.  Any tips?  Thanks,

Corey

Re: retrieve an averaged spectrum

Reply #6
Hi,

Quote from: "cbroeckl"
how to apply mzClust to to spectra.

Check out the mzClustGeneric in xcms/R/mzClust.R,
this is the function doing the actual work.

This is called from group(method="mzClust") and takes a simple mz/sample matrix.

Code: [Select]

          groups <- mzClustGeneric(peaks[,c("mz","sample")],
                                  sampclass=classlabel,
                                  mzppm=mzppm,mzabs=mzabs,
                                  minsamp=minsamp,
                                  minfrac=minfrac)


Quote from: "cbroeckl"
So I think that I either need to
1. extract individal scans from a raw data file so that they are inserted into an xcmsSet object or

This would be a new method for findPeaks(), which would be quite welcome!

For direct infusion with several scans (as opposed to single scans, which MSW expects)
I could envision that it is not too unlike centWave,
but without the wavelets (because there are no gaussian peak shapes):

It'd take a (very narrow) scanrange, detect ROIs, but skip the wavelet analysis,
and then apply one of the mzCenterFun to get a more accurate m/z than
you can expect from a single scan. A question would be whether and how
to integrate the intensities (Max ? Avg ?). Does that make sense ?

Yours,
Steffen
--
IPB Halle                          Mass spectrometry & Bioinformatics
Dr. Steffen Neumann         http://www.IPB-Halle.DE
Weinberg 3 06120 Halle     Tel. +49 (0) 345 5582 - 1470
sneumann(at)IPB-Halle.DE

Re: retrieve an averaged spectrum

Reply #7
Thanks for the tip Steffen


Stupid questions maybe:  I have never really accessed the behind the scenes code, and for the life of me I cannot find the file you refer to.  In my xcms/R folder there are only xcms documents (three of them), and my search isn't finding any files called mzClust.R on my C: drive.  Sorry to be a pain. 

Corey

Re: retrieve an averaged spectrum

Reply #8
Hi,

Quote from: "cbroeckl"
Stupid questions
Corey
There are no stupid questions!

Quote from: "cbroeckl"
I have never really accessed the behind the scenes code, and for the life of me I cannot find the file you refer to.
Corey

For Windows (and Mac ?) the package downloads are "compiled", that's why you don't see them.
Linux will download the sources and compile on-the-fly during installation.

The source code is in the "package source" e.g. xcms_1.34.0.tar.gz at http://bioconductor.org/packages/releas ... /xcms.html
Alternatively, you cen check it out with SVN from https://hedgehog.fhcrc.org/bioconductor ... acks/xcms/
Check out http://bioconductor.org/developers/source-control/ for the password.

If you made any changes to the sources, you then will need to
R CMD INSTALL /path/to/xcmssources/
and re-load xcms into R.

Yours,
Steffen
--
IPB Halle                          Mass spectrometry & Bioinformatics
Dr. Steffen Neumann         http://www.IPB-Halle.DE
Weinberg 3 06120 Halle     Tel. +49 (0) 345 5582 - 1470
sneumann(at)IPB-Halle.DE

 

Re: retrieve an averaged spectrum

Reply #9
steffen,

THanks for the tips.  I used the links you provided, and in the mzClust.R file under R, there is code:

Code: [Select]
mzClustGeneric <- function(p,sampclass=NULL,
                          mzppm = 20,
                          mzabs = 0,
                          minsamp = 1,
                          minfrac=0.5)

I did find the code snippet you quoted in the xcmsSet.R file. 

Is it safe to assume that everything necessary to run xcmsSet() from the R console is located in the xcmsSet.R file?  If not, how do I recognize calls to other files?  Thanks again,  being able to see all the details should allow me to understand everything (including how to properly write R code) better.
Corey