sneumann / xcms

This is the git repository matching the Bioconductor package xcms: LC/MS and GC/MS Data Analysis
Other
183 stars 80 forks source link

msp file output #179

Open yufree opened 7 years ago

yufree commented 7 years ago

Hi, I wonder if xcms 3 or MSnbase could add support for msp file as output for ms/ms search.

msp is a mass spectrum file format for MS/MS spectrum. It need precursor mz, fragmental mz, intensity and metadata to write such files.

The main advantage of this file is that user could use msp file to search MS/MS libraries from NIST or structure prediction. Also, user could use msp file for ms-finder to search MassBank, LipidBlast, GNPS and in silica structure prediction.

As for LC-MS data, I am using xMSannotator package to annotate the xcmsSet object. Msp output support could enable the LC-MS/MS data identification.

Actually in my enviGCMS package, I have written a very simple function(without metadata) to output msp file :

#' Write MSP files for NIST search
#' @param mz a intensity vector, who name is the mass in m/z
#' @param outfilename the name of the MSP file, default is 'unknown'
#' @return none a MSP file will be created at the subfolder working dictionary with name 'MSP'
#' @export
writeMSP<-function(mz, outfilename="unknown"){
        mz <- paste(names(mz),round(mz))
        dir.create('MSP')
        zz <- file(file.path('MSP',paste(outfilename,".msp",sep="")), "w")
        nPeaks <- length(mz)
        cat("Name: unknown", paste("Num Peaks: ",nPeaks),  file = zz, sep = "\n")
        while (length(mz) >=5 ){
                cat(paste(mz[1:5]),"", file = zz, sep="; ")
                cat(paste("\n"), file = zz)
                mz<-mz[6:length(mz)]
        }
        if(!is.na(mz[1])){
                cat(paste(mz),"", file = zz, sep="; ")
                cat(paste("\n"), file = zz)
        }
        close(zz)
        print(paste("A data file",outfilename,".MSP has been generated in the folder:", 'MSP', cat("\n")))
}

Also, in OrgMassSpecR package, author also implemented such function WriteMspFile in a text format from dataframe.

I wonder if new object in xcms 3 could add method for this function. I am a starter for MSnbase and might not understand details for this class.

Hope this help and thanks,

Miao

sneumann commented 7 years ago

Hi, I am always supporting a wide range of possible formats. Since the above code example does not contain any xcms specifics, one could use it right away with a spectrum from xcms. Maybe also add the precursor from xcmsRaw@msnPrecursorMz.

In the coming months @jamesrco aims to contribute some work on MS/MS to xcms, maybe then there is a chance to support formats like MSP (and/or MGF). Thanks, Steffen

jorainer commented 7 years ago

Just one note: I would not add I/O code into xcms but rather into mzR instead. Also, I suggest to use the new objects in xcms for new code and implementations, i.e. the XCMSnExp object and the OnDiskMSnExp (or MSnExp) from the MSnbase package. These objects do already have linking between MSMS spectra etc implemented properly. In the long run the xcmsSet and xcmsRaw might be deprecated and eventually removed.

jamesrco commented 7 years ago

Understood from this angle. We were planning to adapt whatever product we end up with to operate on the XCMSnExp and/or OnDiskMSnExp objects, so that's no problem. If mzR ends up being a better place for the functions, that's fine too. More to come, will push some code here soon in the next few months!

tantrev commented 6 years ago

I'd also like to see this feature, especially since MS-FINDER and a number of other structure-prediction programs require .MSP input.