Question: MSnbase annotate m/z values on mass spectrum plots
2
5 weeks ago by
garfield32020
garfield32020 wrote:

Hi,

I'm new to MSnbase package and am trying to plot MS2 spectra with each peaks annotated with their m/z values.

I followed the examples from the MSnbase document as below.

rawdata <- readMSData("filename", msLevel = 2)
sp <- rawdata[which.max(peaksCount(rawdata))]
plot(sp, full = TRUE)

This gives me a plot of intensity vs. M/Z. I read in the documentation that plot function can annotate fragment ions by matching it to a peptide sequence, but I'm wondering if I can annotate each of these peaks with their M/Z values instead of their IDs, to make sure all peaks that weren't matched to some reference still show their M/Z values. In addition, it would also be useful if I can annotate M/Z values of ten peaks that have highest intensities. I'm aware that I can use mz(rawdata) to get a list of M/Zs but just wondering if there are ways to plot them using functions supported in the MSnbase package. Any advice would be greatly appreciated!

msnbase • 71 views
modified 5 weeks ago by Laurent Gatto1.1k • written 5 weeks ago by garfield32020
Answer: MSnbase annotate m/z values on mass spectrum plots
1
5 weeks ago by
Laurent Gatto1.1k
United Kingdom
Laurent Gatto1.1k wrote:

You can add a sequence (as a character) to plot to automatically annotate the plot. Below I have sp, an object of class Spectrum, and its sequence s:

> sp
Object of class "Spectrum2"
Precursor: 641.3205
Retention time: 30:2
Charge: 2
MSn level: 2
Peaks count: 121
Total ion count: 58841315
> s
[1] "SIGFEGDSIGR"
> plot(sp, s, main = s)


See http://lgatto.github.io/MSnbase/reference/plot-methods.html for an example plot.

It is them possible to add annotations manually with

## get the spectrum as a data.frame
> spdf <- as(sp, 'data.frame')
## hand-annotate the 13th peak with
> text(spdf[13, "mz"], spdf[13 ,"i"], "hello")


I initially asked this question because I don't have any sequence information that can be matched to the spectrum, and the code you put as an example (plot(sp, s, main = s)) seemed like it specifically required a sequence-like object for it to work. However, your getting the spectrum into a data frame inspired me to come up with what I wanted, so thank you for pointing that out! I'm posting the code I used in case anyone in the future needs this.

> sp
Object of class "Spectrum2"
Precursor: 452.2279
Retention time: 11:8
Charge: 1
MSn level: 2
Peaks count: 234
Total ion count: 17796.33

> spdf <- as(sp, 'data.frame')
> plot(spdf$mz, spdf$i, type = 'h')
> spdf.order <- spdf[order(-spdf$i), ] > max <- spdf.order[1:10,] > with(spdf, plot(spdf$mz, spdf$i, type='h')) > text(max$mz, max$i, labels = round(max$mz, 3))