Search in sources :

Example 16 with SimpleScan

use of net.sf.mzmine.datamodel.impl.SimpleScan 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)

Example 17 with SimpleScan

use of net.sf.mzmine.datamodel.impl.SimpleScan in project mzmine2 by mzmine.

the class AgilentCsvReadTask method run.

/**
 * Reads the file.
 */
public void run() {
    setStatus(TaskStatus.PROCESSING);
    Scanner scanner;
    try {
        scanner = new Scanner(this.file);
        this.dataSource = this.getMetaData(scanner, "file name");
        String[] range = this.getMetaData(scanner, "mass range").split(",");
        newMZmineFile.setMZRange(1, Range.closed(Double.parseDouble(range[0]), Double.parseDouble(range[1])));
        range = this.getMetaData(scanner, "time range").split(",");
        newMZmineFile.setRTRange(1, Range.closed(Double.parseDouble(range[0]), Double.parseDouble(range[1])));
        totalScans = Integer.parseInt(this.getMetaData(scanner, "number of spectra"));
        // advance to the spectrum data...
        while (!scanner.nextLine().trim().equals("[spectra]")) {
        }
        scanner.useDelimiter(",");
        for (parsedScans = 0; parsedScans < totalScans; parsedScans++) {
            if (isCanceled()) {
                return;
            }
            // if the task is canceled.
            double retentionTime = scanner.nextDouble();
            // not sure about this value
            int msLevel = scanner.nextInt();
            scanner.next();
            scanner.next();
            int charge = (scanner.next().equals("+") ? 1 : -1);
            scanner.next();
            int spectrumSize = scanner.nextInt();
            DataPoint[] dataPoints = new DataPoint[spectrumSize];
            for (int j = 0; j < spectrumSize; j++) {
                dataPoints[j] = new SimpleDataPoint(scanner.nextDouble(), scanner.nextDouble());
            }
            newMZmineFile.addScan(new SimpleScan(null, parsedScans + 1, msLevel, retentionTime, 0.0, charge, null, dataPoints, ScanUtils.detectSpectrumType(dataPoints), PolarityType.UNKNOWN, "", null));
            scanner.nextLine();
        }
        finalRawDataFile = newMZmineFile.finishWriting();
        project.addFile(finalRawDataFile);
    } catch (Exception e) {
        setErrorMessage(e.getMessage());
        this.setStatus(TaskStatus.ERROR);
        return;
    }
    this.setStatus(TaskStatus.FINISHED);
}
Also used : Scanner(java.util.Scanner) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Aggregations

SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)17 DataPoint (net.sf.mzmine.datamodel.DataPoint)16 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)15 Scan (net.sf.mzmine.datamodel.Scan)10 IOException (java.io.IOException)5 RawDataFileWriter (net.sf.mzmine.datamodel.RawDataFileWriter)4 ArrayList (java.util.ArrayList)3 MassSpectrumType (net.sf.mzmine.datamodel.MassSpectrumType)3 Scanner (java.util.Scanner)2 PolarityType (net.sf.mzmine.datamodel.PolarityType)2 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)2 MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)1 ByteBuffer (java.nio.ByteBuffer)1 Vector (java.util.Vector)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Array (ucar.ma2.Array)1 Index (ucar.ma2.Index)1 Spectrum (uk.ac.ebi.jmzml.model.mzml.Spectrum)1 MzMLUnmarshaller (uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller)1