Search in sources :

Example 1 with Spectrum

use of uk.ac.ebi.jmzml.model.mzml.Spectrum in project mzmine2 by mzmine.

the class MzMLReadTask method run.

/**
 * @see java.lang.Runnable#run()
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Started parsing file " + file);
    MzMLUnmarshaller unmarshaller = new MzMLUnmarshaller(file);
    totalScans = unmarshaller.getObjectCountForXpath("/run/spectrumList/spectrum");
    fillScanIdTable(unmarshaller.unmarshalCollectionFromXpath("/run/spectrumList/spectrum", Spectrum.class), totalScans);
    MzMLObjectIterator<Spectrum> spectrumIterator = unmarshaller.unmarshalCollectionFromXpath("/run/spectrumList/spectrum", Spectrum.class);
    try {
        while (spectrumIterator.hasNext()) {
            if (isCanceled())
                return;
            Spectrum spectrum = spectrumIterator.next();
            // Ignore scans that are not MS, e.g. UV
            if (!isMsSpectrum(spectrum)) {
                parsedScans++;
                continue;
            }
            String scanId = spectrum.getId();
            Integer scanNumber = scanIdTable.get(scanId);
            if (scanNumber == null)
                throw new IllegalStateException("Cannot determine scan number: " + scanId);
            // Extract scan data
            int msLevel = extractMSLevel(spectrum);
            double retentionTime = extractRetentionTime(spectrum);
            PolarityType polarity = extractPolarity(spectrum);
            int parentScan = extractParentScanNumber(spectrum);
            double precursorMz = extractPrecursorMz(spectrum);
            int precursorCharge = extractPrecursorCharge(spectrum);
            String scanDefinition = extractScanDefinition(spectrum);
            DataPoint[] dataPoints = extractDataPoints(spectrum);
            // Auto-detect whether this scan is centroided
            MassSpectrumType spectrumType = ScanUtils.detectSpectrumType(dataPoints);
            SimpleScan scan = new SimpleScan(null, scanNumber, msLevel, retentionTime, precursorMz, precursorCharge, null, dataPoints, spectrumType, polarity, scanDefinition, null);
            for (SimpleScan s : parentStack) {
                if (s.getScanNumber() == parentScan) {
                    s.addFragmentScan(scanNumber);
                }
            }
            /*
         * Verify the size of parentStack. The actual size of the window to cover possible
         * candidates is defined by limitSize.
         */
            if (parentStack.size() > PARENT_STACK_SIZE) {
                SimpleScan firstScan = parentStack.removeLast();
                newMZmineFile.addScan(firstScan);
            }
            parentStack.addFirst(scan);
            parsedScans++;
        }
        while (!parentStack.isEmpty()) {
            SimpleScan scan = parentStack.removeLast();
            newMZmineFile.addScan(scan);
        }
        finalRawDataFile = newMZmineFile.finishWriting();
        project.addFile(finalRawDataFile);
    } catch (Throwable e) {
        e.printStackTrace();
        setStatus(TaskStatus.ERROR);
        setErrorMessage("Error parsing mzML: " + ExceptionUtils.exceptionToString(e));
        e.printStackTrace();
        return;
    }
    if (parsedScans == 0) {
        setStatus(TaskStatus.ERROR);
        setErrorMessage("No scans found");
        return;
    }
    logger.info("Finished parsing " + file + ", parsed " + parsedScans + " scans");
    setStatus(TaskStatus.FINISHED);
}
Also used : PolarityType(net.sf.mzmine.datamodel.PolarityType) MassSpectrumType(net.sf.mzmine.datamodel.MassSpectrumType) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Spectrum(uk.ac.ebi.jmzml.model.mzml.Spectrum) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) MzMLUnmarshaller(uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)1 MassSpectrumType (net.sf.mzmine.datamodel.MassSpectrumType)1 PolarityType (net.sf.mzmine.datamodel.PolarityType)1 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)1 SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)1 Spectrum (uk.ac.ebi.jmzml.model.mzml.Spectrum)1 MzMLUnmarshaller (uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller)1