Search in sources :

Example 1 with PeakInformation

use of net.sf.mzmine.datamodel.PeakInformation in project mzmine2 by mzmine.

the class PeakListOpenHandler_2_5 method endElement.

/**
 * @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String,
 *      java.lang.String)
 */
@Override
public void endElement(String namespaceURI, String sName, String qName) throws SAXException {
    if (canceled)
        throw new SAXException("Parsing canceled");
    // <NAME>
    if (qName.equals(PeakListElementName_2_5.PEAKLIST_NAME.getElementName())) {
        name = getTextOfElement();
        logger.info("Loading feature list: " + name);
        peakListName = name;
    }
    // <PEAKLIST_DATE>
    if (qName.equals(PeakListElementName_2_5.PEAKLIST_DATE.getElementName())) {
        dateCreated = getTextOfElement();
    }
    // <QUANTITY>
    if (qName.equals(PeakListElementName_2_5.QUANTITY.getElementName())) {
        String text = getTextOfElement();
        totalRows = Integer.parseInt(text);
    }
    // <RAW_FILE>
    if (qName.equals(PeakListElementName_2_5.RAWFILE.getElementName())) {
        rawDataFileID = getTextOfElement();
        RawDataFile dataFile = dataFilesIDMap.get(rawDataFileID);
        if (dataFile == null) {
            throw new SAXException("Cannot open feature list, because raw data file " + rawDataFileID + " is missing.");
        }
        currentPeakListDataFiles.add(dataFile);
    }
    // <SCAN_ID>
    if (qName.equals(PeakListElementName_2_5.SCAN_ID.getElementName())) {
        byte[] bytes = Base64.decodeToBytes(getTextOfElement());
        // make a data input stream
        DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
        scanNumbers = new int[numOfMZpeaks];
        for (int i = 0; i < numOfMZpeaks; i++) {
            try {
                scanNumbers[i] = dataInputStream.readInt();
            } catch (IOException ex) {
                throw new SAXException(ex);
            }
        }
    }
    // <REPRESENTATIVE_SCAN>
    if (qName.equals(PeakListElementName_2_5.REPRESENTATIVE_SCAN.getElementName())) {
        representativeScan = Integer.valueOf(getTextOfElement());
    }
    // <FRAGMENT_SCAN>
    if (qName.equals(PeakListElementName_2_5.FRAGMENT_SCAN.getElementName())) {
        fragmentScan = Integer.valueOf(getTextOfElement());
    }
    // <All_MS2_FRAGMENT_SCANS>
    if (qName.equals(PeakListElementName_2_5.ALL_MS2_FRAGMENT_SCANS.getElementName())) {
        Integer fragmentNumber = Integer.valueOf(getTextOfElement());
        currentAllMS2FragmentScans.add(fragmentNumber);
    }
    // <MASS>
    if (qName.equals(PeakListElementName_2_5.MZ.getElementName())) {
        byte[] bytes = Base64.decodeToBytes(getTextOfElement());
        // make a data input stream
        DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
        masses = new double[numOfMZpeaks];
        for (int i = 0; i < numOfMZpeaks; i++) {
            try {
                masses[i] = dataInputStream.readFloat();
            } catch (IOException ex) {
                throw new SAXException(ex);
            }
        }
    }
    // <HEIGHT>
    if (qName.equals(PeakListElementName_2_5.HEIGHT.getElementName())) {
        byte[] bytes = Base64.decodeToBytes(getTextOfElement());
        // make a data input stream
        DataInputStream dataInputStream = new DataInputStream(new ByteArrayInputStream(bytes));
        intensities = new double[numOfMZpeaks];
        for (int i = 0; i < numOfMZpeaks; i++) {
            try {
                intensities[i] = dataInputStream.readFloat();
            } catch (IOException ex) {
                throw new SAXException(ex);
            }
        }
    }
    // <PEAK>
    if (qName.equals(PeakListElementName_2_5.PEAK.getElementName())) {
        DataPoint[] mzPeaks = new DataPoint[numOfMZpeaks];
        Range<Double> peakRTRange = null, peakMZRange = null, peakIntensityRange = null;
        RawDataFile dataFile = dataFilesIDMap.get(peakColumnID);
        if (dataFile == null)
            throw new SAXException("Error in project: data file " + peakColumnID + " not found");
        for (int i = 0; i < numOfMZpeaks; i++) {
            Scan sc = dataFile.getScan(scanNumbers[i]);
            double retentionTime = sc.getRetentionTime();
            double mz = masses[i];
            double intensity = intensities[i];
            if (peakIntensityRange == null) {
                peakIntensityRange = Range.singleton(intensity);
            } else {
                peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
            }
            if (intensity > 0) {
                if (peakRTRange == null) {
                    peakRTRange = Range.singleton(retentionTime);
                } else {
                    peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
                }
            }
            if (mz > 0.0) {
                mzPeaks[i] = new SimpleDataPoint(mz, intensity);
                if (peakMZRange == null)
                    peakMZRange = Range.singleton(mz);
                else
                    peakMZRange = peakMZRange.span(Range.singleton(mz));
            }
        }
        FeatureStatus status = FeatureStatus.valueOf(peakStatus);
        // convert vector of allMS2FragmentScans to array
        allMS2FragmentScanNumbers = new int[currentAllMS2FragmentScans.size()];
        for (int i = 0; i < allMS2FragmentScanNumbers.length; i++) {
            allMS2FragmentScanNumbers[i] = currentAllMS2FragmentScans.get(i);
        }
        // clear all MS2 fragment scan numbers list for next peak
        currentAllMS2FragmentScans.clear();
        SimpleFeature peak = new SimpleFeature(dataFile, mass, rt, height, area, scanNumbers, mzPeaks, status, representativeScan, fragmentScan, allMS2FragmentScanNumbers, peakRTRange, peakMZRange, peakIntensityRange);
        peak.setCharge(currentPeakCharge);
        if (currentIsotopes.size() > 0) {
            SimpleIsotopePattern newPattern = new SimpleIsotopePattern(currentIsotopes.toArray(new DataPoint[0]), currentIsotopePatternStatus, currentIsotopePatternDescription);
            peak.setIsotopePattern(newPattern);
            currentIsotopes.clear();
        }
        peak.setParentChromatogramRowID(parentChromatogramRowID);
        buildingRow.addPeak(dataFile, peak);
    }
    // <IDENTITY_PROPERTY>
    if (qName.equals(PeakListElementName_2_5.IDPROPERTY.getElementName())) {
        identityProperties.put(identityPropertyName, getTextOfElement());
    }
    // <INFO_PROPERTY>
    if (qName.equals(PeakListElementName_2_5.INFO_PROPERTY.getElementName())) {
        informationProperties.put(infoPropertyName, getTextOfElement());
    }
    // <PEAK_IDENTITY>
    if (qName.equals(PeakListElementName_2_5.PEAK_IDENTITY.getElementName())) {
        SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
        buildingRow.addPeakIdentity(identity, preferred);
    }
    if (qName.equals(PeakListElementName_2_5.PEAK_INFORMATION.getElementName())) {
        PeakInformation information = new SimplePeakInformation(informationProperties);
        buildingRow.setPeakInformation(information);
    }
    // <ROW>
    if (qName.equals(PeakListElementName_2_5.ROW.getElementName())) {
        buildingPeakList.addRow(buildingRow);
        buildingRow = null;
        parsedRows++;
    }
    // <ISOTOPE>
    if (qName.equals(PeakListElementName_2_5.ISOTOPE.getElementName())) {
        String text = getTextOfElement();
        String[] items = text.split(":");
        double mz = Double.valueOf(items[0]);
        double intensity = Double.valueOf(items[1]);
        DataPoint isotope = new SimpleDataPoint(mz, intensity);
        currentIsotopes.add(isotope);
    }
    if (qName.equals(PeakListElementName_2_5.METHOD_NAME.getElementName())) {
        String appliedMethod = getTextOfElement();
        appliedMethods.add(appliedMethod);
    }
    if (qName.equals(PeakListElementName_2_5.METHOD_PARAMETERS.getElementName())) {
        String appliedMethodParam = getTextOfElement();
        appliedMethodParameters.add(appliedMethodParam);
    }
}
Also used : FeatureStatus(net.sf.mzmine.datamodel.Feature.FeatureStatus) IOException(java.io.IOException) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) DataInputStream(java.io.DataInputStream) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SAXException(org.xml.sax.SAXException) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ByteArrayInputStream(java.io.ByteArrayInputStream) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Scan(net.sf.mzmine.datamodel.Scan) SimplePeakInformation(net.sf.mzmine.datamodel.impl.SimplePeakInformation) PeakInformation(net.sf.mzmine.datamodel.PeakInformation) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakInformation(net.sf.mzmine.datamodel.impl.SimplePeakInformation)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 DataPoint (net.sf.mzmine.datamodel.DataPoint)1 FeatureStatus (net.sf.mzmine.datamodel.Feature.FeatureStatus)1 PeakInformation (net.sf.mzmine.datamodel.PeakInformation)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 Scan (net.sf.mzmine.datamodel.Scan)1 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)1 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)1 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)1 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)1 SimplePeakInformation (net.sf.mzmine.datamodel.impl.SimplePeakInformation)1 SAXException (org.xml.sax.SAXException)1