lgatto / MSnbase

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

readMSData to read additional data #527

Closed Adafede closed 3 years ago

Adafede commented 3 years ago

Hi,

Thank you for your wonderful package.

I was wondering if it would be easily implementable for your readMSData function to read not only MS data encoded in the mzML but also data coming from other detectors which is encoded almost in the same way? I know your package is MS oriented but it would be really great to access PDA spectra in the same way we access MS spectra now, or even simple chromatograms also encoded in the file.

I think this would be really great since no tool (as far as I know) does it.

stanstrup commented 3 years ago

With the more low level mzR it is possible to read the PDA data: https://gitlab.com/stanstrup-work/read_waters_pda/-/blob/master/funs.R

Adafede commented 3 years ago

Wonderful! Exactly what I was looking for. Do you also read the chromatograms and not spectra which are listed as chromatogram id = ...?

stanstrup commented 3 years ago

I have not worked with chromatograms so dunno. But it seems to be possible now. Some hints here https://github.com/sneumann/mzR/issues/172 and https://github.com/sneumann/mzR/issues/163.

More on the status of non-MS data in MSnbase: https://github.com/lgatto/MSnbase/issues/452

lgatto commented 3 years ago

You can extract chromatograms from the MSnExp object (see ?Chromatogram and ?Chromatograms). There's also a readSRMData data.

Adafede commented 3 years ago

Hi again,

Sorry to insist but this time it might be clearer since I think I am missing something...

First of all, thank you @stanstrup , your trick works perfetcly for accessing PDA scans! :)

Here is my file:

https://we.tl/t-Oep8oWPl79 (sorry it's big)

It contains MS1 data, MS2 data, PDA data and an additional 1D analog signal. 3 chromatograms are encoded in the file, but I am sadly able only to access the ones linked to the MS data. What I would like is to also access the other ones. (see chromatogramList count="3" in file)

How could I do?

What I am doing is:

msnexp <-
  readMSData(
    files = file,
    verbose = TRUE,
    centroided. = TRUE,
    smoothed. = FALSE,
    mode = "onDisk"
  )

Then,

bpi_ms1 <- chromatogram(object = msnexp, msLevel = 1)
# works

bpi_ms2 <- chromatogram(object = msnexp, msLevel = 2)
# works

test <- chromatograms(object = msnexp)
# Error in (function (classes, fdef, mtable)  : 
# unable to find an inherited method for function ‘chromatograms’ for signature ‘"OnDiskMSnExp"’

Many thanks

jorainer commented 3 years ago

I guess the error comes because you misspelled the function (chromatograms and not chromatogram).

Note that AFAIK it will not be possible to extract MS1 and MS2 chromatograms at the same time, thus chromatogram(msnexp) will extract MS1 chromatograms (the default).

Adafede commented 3 years ago

It is not a misspell... I checked both functions and chromatogram works on MS chromatograms (MS1, and MS2 separately) but chromatogramS does not work (as written

Error in (function (classes, fdef, mtable)  : 
unable to find an inherited method for function ‘chromatograms’ for signature ‘"OnDiskMSnExp"
lgatto commented 3 years ago

Indeed, there is not chromatograms function for [OnDisk]MSnExp objects. chromatograms() and chromatogram() are different functions altogether. The former only works for mzR objects.

Adafede commented 3 years ago

Marvelous! I got it now...

So what I did:

object <- mzR::openMSfile(file)

chromatograms <- chromatograms(object)

and got all of them 👍🏼