rformassspectrometry / Spectra

Low level infrastructure to handle MS spectra
https://rformassspectrometry.github.io/Spectra/
34 stars 24 forks source link

Problem with MGF import - object: mz values have to be sorted increasingly #311

Closed felipe-mansoldo closed 4 months ago

felipe-mansoldo commented 4 months ago

Dear all,

I'm not able to import the GNPS .mgf obtained from: https://gnps-external.ucsd.edu/gnpslibrary download link: https://gnps-external.ucsd.edu/gnpslibrary/GNPS-LIBRARY.mgf


> mbank.gnps <- Spectra("GNPS-LIBRARY.mgf", source = MsBackendMgf() )
Start data import from 1 files ... done
Error in validObject(object) : 
  invalid class “MsBackendMgf” object: mz values have to be sorted increasingly

However, it is possible to import using MSnbase::readMgfData:


> mbank <- MSnbase::readMgfData("GNPS-LIBRARY.mgf", pdata = NULL, centroided = TRUE, smoothed = FALSE,
+                               verbose = TRUE, cache = 1)
Scanning GNPS-LIBRARY.mgf ...
  |===================================================================================================================| 100%
> length(mbank)
[1] 14190

I would like to import through Spectra to be able to use the package's functions. Is it possible to fix this? or convert MSnExp to Spectra?

Ideally it would be better to import through Spectra so we can keep the MGF information like SMILES, INCHI, NAME etc.

thanks

jorainer commented 4 months ago

Which version of Spectra and MsBackendMgf are you using?

jorainer commented 4 months ago

I can read the file without problems using the current stable version (for R 4.3, Bioconductor release 3.18). According to the NEWS a version > 1.7.4 would be needed.

felipe-mansoldo commented 4 months ago

Dear @jorainer It's true, it's an old version problem. I updated and everything is working perfectly, thanks!