Skip to content

Sample files and examples

Yasset Perez-Riverol edited this page May 28, 2015 · 2 revisions

#Test Files

The jmzReader contains a collection of example files of the various file formats.

#Example

The following example shows how the jmzReader library can be used in conjunction with the jmzIdentML API.

This example is based on the 55merge_omssa.mzid file and its peak list file 55merge.mgf. Both files can be found in the download section.

More detailed code examples can be found in the jmzReader interface page.

/**
 * This example ignores any exception and error handling.
 * Furthermore, this example assumes that the corresponding
 * peak list file for the given mzIdentML file is already 
 * known.
 */

JMzReader jmzreader = new MgfFile(new File("/path/to/55merge.mgf"));
MzIdentMLUnmarshaller unmarshaller = new MzIdentMLUnmarshaller(new URL("/path/to/55merge_omssa.mzid"));

List<SpectrumIdentificationList> sil = ad.getSpectrumIdentificationList();

for (SpectrumIdentificationList sIdentList : sil) {
    for (SpectrumIdentificationResult spectrumIdentResult 
                : sIdentList.getSpectrumIdentificationResult()) {

        // get the spectrum's id in the referenced file
        String spectrumID =  spectrumIdentResult.getSpectrumID(); // this returns a value like "index=246"
        // this is the actual reference to the spectrum file
        // but as in this example the spectrum file is already
        // known it is not needed. In real world examples this
        // reference would be used to identify the source spectrum
        // file
        String spectrumFileRef = spectrumIdentResult.getSpectraDataRef();
 
        // as MGF files are index based the "index=" portion of the spectrumId needs to be removed
        String spectrumIndex = spectrumID.substring(6);

        //  and since the index in mzid files is 0 based and the index in jmzReader is 1 based, this has to be addressed as well
        int index = Integer.parseInt(spectrumIndex);
        index = index + 1;

        // using the index the spectrum can now be retrieved from the
        // MGF file.
        Spectrum spectrum = jmzreader.getSpectrumByIndex(index);
    } // end spectrum identification results
}
Clone this wiki locally