MSnbase extracting individual spectrum based on precursor ion m/z
1
0
Entering edit mode
garfield320 ▴ 30
@garfield320-18805
Last seen 4.0 years ago

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 • 1.1k views
ADD COMMENT
2
Entering edit mode
@laurent-gatto-5645
Last seen 5 weeks ago
Belgium

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 COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 723 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6