lgatto / MSnbase

Base Classes and Functions for Mass Spectrometry and Proteomics
http://lgatto.github.io/MSnbase/
127 stars 46 forks source link

chromatogram() automatically adjusts mz range & rt range #581

Closed pablovgd closed 2 years ago

pablovgd commented 2 years ago

Dear

I have found out some weird behavior of the chromatogram() function. It seems to adjust the mzRange when displaying the chromatogram instead of the input mzRange. Example:

> raw_data <- readMSData(file, msLevel. = 1,mode = "onDisk")
> raw_data_low <- filterRt(raw_data,c(67,1000))
> chr_raw <- chromatogram(raw_data_low, mz = c(290.1555, 290.1642), rt = c(56.4,80.4))
> chr_raw[1,]
  Object of class: Chromatogram
  Intensity values aggregated using: sum 
  length of object: 21
  from file: 1
  mz range: [290.1593, 290.1595]
  rt range: [56.9376, 80.35369]
  MS level: NA, 1

and

> chr_raw <- chromatogram(raw_data_low, mz = c(290.15,290.17), rt = c(56.4,80.4))
> chr_raw[1,]
Object of class: Chromatogram
Intensity values aggregated using: sum 
length of object: 21
from file: 1
mz range: [290.1593, 290.1667]
rt range: [56.9376, 80.35369]
MS level: NA, 1

This causes it to miss peaks that would otherwise be picked up in the original mzrange. Now I have to start from a very broad range to pick up some data:

chr_raw <- chromatogram(raw_data_low, mz = c(290.1,290.19), rt = c(56.4,80.4))
plot(chr_raw)
chr_raw[1,]
Object of class: Chromatogram
Intensity values aggregated using: sum 
length of object: 21
from file: 1
mz range: [290.101, 290.1708]
rt range: [56.9376, 80.35369]
MS level: NA, 1

Any idea how to fix this? Thanks a lot for the help!

Kind regards, Pablo

File can be found here for those that want to have a go: https://filesender.belnet.be/?s=download&token=60b80d2c-0d73-4b26-9a6d-1c64b826fbe0

jorainer commented 2 years ago

The m/z range that is displayed by the show method for Chromatogram is not the original m/z range that was provided by the user, but the m/z range of all peaks that were found in the data after filtering by (the user defined) m/z and RT ranges.

To explain, what chromatograms does is:

The function does not change the m/z and rt ranges (provided by the user) for the filtering. They are used as they were provided, only the m/z range is adjusted afterwards to represent the real m/z range of the data subset.

Hope this could clarify the differences you see.

pablovgd commented 2 years ago

Dear Johannes,

Alright, I get it! Thanks for the elaborate explanation, much appreciated.

Cheers, Pablo