Question: MSnbase extracting individual spectrum based on precursor ion m/z
0
gravatar for garfield320
4 months ago by
garfield32020
garfield32020 wrote:

Hi,

I'm having trouble with extracting individual MS spectrum from my metadata based on precursor ion m/z.

rawdata <- readMSData("file.mzXML", msLevel = 2,  mode = "onDisk")

I'm aware that I can assess individual MS spectrum objects by using index, like rawdata[[1]] . But I was trying to get the index I want based on retention time or m/z of precursor ion. For example, my rawdata[[1]] looks like this:

> rawdata[[1]]
Object of class "Spectrum2"
Precursor: 808.5253 
Retention time: 0:8 
Charge: 2 
MSn level: 2 
Peaks count: 462 
Total ion count: 1423873

For retention time, this worked:

head(rtime(rawdata))   #got exact retention time
> which(rtime(rawdata)==7.81947)
F1.S00029 
     1

But when I do the same for precursor ion m/z, I don't get an index as an answer.

> which(precursorMz(rawdata)==808.5253)
named integer(0)

Why doesn't this work for precursor ion m/z? Is there any way to extract the index (and eventually the corresponding MS spectrum) based on precursor ion m/z?

msnbase • 92 views
ADD COMMENTlink modified 4 months ago by Laurent Gatto1.2k • written 4 months ago by garfield32020
Answer: MSnbase extracting individual spectrum based on precursor ion m/z
2
gravatar for Laurent Gatto
4 months ago by
Laurent Gatto1.2k
Belgium
Laurent Gatto1.2k wrote:

This is most likely due to the fact that the precursor M/Z isn't exactly 808.5253. 808.5253 is probably a rounded up value that is shown as part of showing the spectrum object, and == returns TRUE when the two values are exactly identical. You would need to check the exact value of the M/Z value - for example, the following should return what you are looking for

mz1 <- precursorMz(rawdata)[1]
which(precursorMz(rawdata) == mz1)

Alternatively, you could also use all.equal rather than ==:

> all.equal(808.5253, 808.52532355)
[1] "Mean relative difference: 2.91271e-08"
> all.equal(808.5253, 808.52532355, tolerance = 0.0001)
[1] TRUE

or round the M/Z value before doing the comparisons:

> all.equal(808.5253, round(808.52532355, 4))
[1] TRUE
> 808.5253 == round(808.52532355, 4)
[1] TRUE
ADD COMMENTlink written 4 months ago by Laurent Gatto1.2k

Yes that was the problem, which(round(precursorMz(rawdata),4)==808.5253) gave me the index I wanted, thanks!

ADD REPLYlink written 4 months ago by garfield32020

Yes that was the problem, which(round(precursorMz(rawdata),4)==808.5253) gave me the index I wanted, thanks!

ADD REPLYlink written 4 months ago by garfield32020
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 16.09
Traffic: 298 users visited in the last hour