Search in sources :

Example 11 with SimpleIsotopePattern

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

Example 12 with SimpleIsotopePattern

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

the class PeakListOpenHandler_2_0 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_0.PEAKLIST_NAME.getElementName())) {
        name = getTextOfElement();
        logger.info("Loading feature list: " + name);
        peakListName = name;
    }
    // <PEAKLIST_DATE>
    if (qName.equals(PeakListElementName_2_0.PEAKLIST_DATE.getElementName())) {
        dateCreated = getTextOfElement();
    }
    // <QUANTITY>
    if (qName.equals(PeakListElementName_2_0.QUANTITY.getElementName())) {
        String text = getTextOfElement();
        totalRows = Integer.parseInt(text);
    }
    // <RAW_FILE>
    if (qName.equals(PeakListElementName_2_0.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_0.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_0.REPRESENTATIVE_SCAN.getElementName())) {
        representativeScan = Integer.valueOf(getTextOfElement());
    }
    if (qName.equals(PeakListElementName_2_0.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_0.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_0.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_0.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 ((peakRTRange == null) || (peakIntensityRange == null)) {
                peakRTRange = Range.singleton(retentionTime);
                peakIntensityRange = Range.singleton(intensity);
            } else {
                peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
                peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
            }
            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();
        }
        buildingRow.addPeak(dataFile, peak);
    }
    // <IDENTITY_PROPERTY>
    if (qName.equals(PeakListElementName_2_0.IDPROPERTY.getElementName())) {
        identityProperties.put(identityPropertyName, getTextOfElement());
    }
    // <PEAK_IDENTITY>
    if (qName.equals(PeakListElementName_2_0.PEAK_IDENTITY.getElementName())) {
        String content = getTextOfElement();
        if (identityProperties.get(PeakIdentity.PROPERTY_NAME) == null)
            identityProperties.put(PeakIdentity.PROPERTY_NAME, content);
        SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
        buildingRow.addPeakIdentity(identity, preferred);
    }
    // <ROW>
    if (qName.equals(PeakListElementName_2_0.ROW.getElementName())) {
        buildingPeakList.addRow(buildingRow);
        buildingRow = null;
        parsedRows++;
    }
    // <ISOTOPE>
    if (qName.equals(PeakListElementName_2_0.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_0.METHOD_NAME.getElementName())) {
        String appliedMethod = getTextOfElement();
        appliedMethods.add(appliedMethod);
    }
    if (qName.equals(PeakListElementName_2_0.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) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)

Example 13 with SimpleIsotopePattern

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

the class PeakListOpenHandler_2_3 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_3.PEAKLIST_NAME.getElementName())) {
        name = getTextOfElement();
        logger.info("Loading feature list: " + name);
        peakListName = name;
    }
    // <PEAKLIST_DATE>
    if (qName.equals(PeakListElementName_2_3.PEAKLIST_DATE.getElementName())) {
        dateCreated = getTextOfElement();
    }
    // <QUANTITY>
    if (qName.equals(PeakListElementName_2_3.QUANTITY.getElementName())) {
        String text = getTextOfElement();
        totalRows = Integer.parseInt(text);
    }
    // <RAW_FILE>
    if (qName.equals(PeakListElementName_2_3.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_3.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_3.REPRESENTATIVE_SCAN.getElementName())) {
        representativeScan = Integer.valueOf(getTextOfElement());
    }
    if (qName.equals(PeakListElementName_2_3.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_3.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_3.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_3.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 ((peakRTRange == null) || (peakIntensityRange == null)) {
                peakRTRange = Range.singleton(retentionTime);
                peakIntensityRange = Range.singleton(intensity);
            } else {
                peakRTRange = peakRTRange.span(Range.singleton(retentionTime));
                peakIntensityRange = peakIntensityRange.span(Range.singleton(intensity));
            }
            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();
        }
        buildingRow.addPeak(dataFile, peak);
    }
    // <IDENTITY_PROPERTY>
    if (qName.equals(PeakListElementName_2_3.IDPROPERTY.getElementName())) {
        identityProperties.put(identityPropertyName, getTextOfElement());
    }
    // <PEAK_IDENTITY>
    if (qName.equals(PeakListElementName_2_3.PEAK_IDENTITY.getElementName())) {
        SimplePeakIdentity identity = new SimplePeakIdentity(identityProperties);
        buildingRow.addPeakIdentity(identity, preferred);
    }
    // <ROW>
    if (qName.equals(PeakListElementName_2_3.ROW.getElementName())) {
        buildingPeakList.addRow(buildingRow);
        buildingRow = null;
        parsedRows++;
    }
    // <ISOTOPE>
    if (qName.equals(PeakListElementName_2_3.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_3.METHOD_NAME.getElementName())) {
        String appliedMethod = getTextOfElement();
        appliedMethods.add(appliedMethod);
    }
    if (qName.equals(PeakListElementName_2_3.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) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)

Example 14 with SimpleIsotopePattern

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

the class PeakSummaryComponent method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("SHOW")) {
        String visualizerType = (String) comboShow.getSelectedItem();
        int[] indexesRow = peaksInfoList.getSelectedRows();
        Feature[] selectedPeaks = new Feature[indexesRow.length];
        RawDataFile[] dataFiles = new RawDataFile[indexesRow.length];
        Range<Double> rtRange = null, mzRange = null;
        for (int i = 0; i < indexesRow.length; i++) {
            selectedPeaks[i] = listElementModel.getElementAt(indexesRow[i]);
            dataFiles[i] = selectedPeaks[i].getDataFile();
            if ((rtRange == null) || (mzRange == null)) {
                rtRange = dataFiles[i].getDataRTRange(1);
                mzRange = selectedPeaks[i].getRawDataPointsMZRange();
            } else {
                rtRange = rtRange.span(dataFiles[i].getDataRTRange(1));
                mzRange = mzRange.span(selectedPeaks[i].getRawDataPointsMZRange());
            }
        }
        if (dataFiles.length == 0) {
            return;
        }
        if (visualizerType.equals("Chromatogram")) {
            // Label best peak with preferred identity.
            final Feature bestPeak = row.getBestPeak();
            final PeakIdentity peakIdentity = row.getPreferredPeakIdentity();
            final Map<Feature, String> labelMap = new HashMap<Feature, String>(1);
            if (bestPeak != null && peakIdentity != null) {
                labelMap.put(bestPeak, peakIdentity.getName());
            }
            ScanSelection scanSelection = new ScanSelection(rtRange, 1);
            TICVisualizerModule.showNewTICVisualizerWindow(dataFiles, selectedPeaks, labelMap, scanSelection, TICPlotType.BASEPEAK, mzRange);
            return;
        } else if (visualizerType.equals("Mass spectrum")) {
            for (int i = 0; i < selectedPeaks.length; ++i) {
                final Feature peak = selectedPeaks[i];
                final IsotopePattern ip = peak.getIsotopePattern();
                if (ip != null) {
                    // ------------------------------
                    // Multiply isotope pattern by -1
                    // ------------------------------
                    DataPoint[] newDataPoints = Arrays.stream(ip.getDataPoints()).map(p -> new SimpleDataPoint(p.getMZ(), -p.getIntensity())).toArray(DataPoint[]::new);
                    // ---------------------------
                    // Construct identity spectrum
                    // ---------------------------
                    List<DataPoint> identityDataPoints = new ArrayList<>();
                    PeakIdentity identity = row.getPreferredPeakIdentity();
                    if (identity != null) {
                        String spectrum = identity.getPropertyValue(PeakIdentity.PROPERTY_SPECTRUM);
                        if (spectrum != null && spectrum.length() > 2) {
                            spectrum = spectrum.substring(1, spectrum.length() - 1);
                            for (String strPair : spectrum.split(",")) {
                                String[] pair = strPair.split("=", 2);
                                if (pair.length == 2)
                                    identityDataPoints.add(new SimpleDataPoint(Double.parseDouble(pair[0]), Double.parseDouble(pair[1])));
                            }
                        }
                    }
                    if (// Plot raw spectrum and isotope pattern
                    identityDataPoints.isEmpty())
                        SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber(), null, null, null, new SimpleIsotopePattern(newDataPoints, ip.getStatus(), ip.getDescription()));
                    else
                        // Plot raw spectrum, isotope pattern, and identity spectrum
                        SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber(), null, new SimpleIsotopePattern(identityDataPoints.toArray(new DataPoint[identityDataPoints.size()]), IsotopePatternStatus.DETECTED, identity.getPropertyValue(PeakIdentity.PROPERTY_FORMULA)), null, new SimpleIsotopePattern(newDataPoints, ip.getStatus(), ip.getDescription()));
                } else
                    // Plot raw spectrum without isotope pattern
                    SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber());
            }
        } else if (visualizerType.equals("Peak in 2D")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                Range<Double> peakRTRange = selectedPeaks[i].getRawDataPointsRTRange();
                Range<Double> peakMZRange = selectedPeaks[i].getRawDataPointsMZRange();
                final double rtLen = peakRTRange.upperEndpoint() - peakRTRange.lowerEndpoint();
                Range<Double> localRTRange = Range.closed(Math.max(0, peakRTRange.lowerEndpoint() - rtLen), peakRTRange.upperEndpoint() + rtLen);
                final double mzLen = peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint();
                Range<Double> localMZRange = Range.closed(Math.max(0, peakMZRange.lowerEndpoint() - mzLen), peakMZRange.upperEndpoint() + mzLen);
                TwoDVisualizerModule.show2DVisualizerSetupDialog(dataFiles[i], localMZRange, localRTRange);
            }
        } else if (visualizerType.equals("Peak in 3D")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                Range<Double> peakRTRange = selectedPeaks[i].getRawDataPointsRTRange();
                Range<Double> peakMZRange = selectedPeaks[i].getRawDataPointsMZRange();
                final double rtLen = peakRTRange.upperEndpoint() - peakRTRange.lowerEndpoint();
                Range<Double> localRTRange = Range.closed(Math.max(0, peakRTRange.lowerEndpoint() - rtLen), peakRTRange.upperEndpoint() + rtLen);
                final double mzLen = peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint();
                Range<Double> localMZRange = Range.closed(Math.max(0, peakMZRange.lowerEndpoint() - mzLen), peakMZRange.upperEndpoint() + mzLen);
                Fx3DVisualizerModule.setupNew3DVisualizer(dataFiles[i], localMZRange, localRTRange);
            }
        } else if (visualizerType.equals("MS/MS")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                int scanNumber = selectedPeaks[i].getMostIntenseFragmentScanNumber();
                if (scanNumber > 0) {
                    SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], scanNumber);
                } else {
                    JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, this);
                    MZmineCore.getDesktop().displayMessage(frame, "There is no fragment for the mass " + MZmineCore.getConfiguration().getMZFormat().format(selectedPeaks[i].getMZ()) + "m/z in the current raw data.");
                    return;
                }
            }
        } else if (visualizerType.equals("Isotope pattern")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                IsotopePattern ip = selectedPeaks[i].getIsotopePattern();
                if (ip == null) {
                    return;
                }
                SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], selectedPeaks[i].getMostIntenseFragmentScanNumber(), ip);
            }
        }
        return;
    }
    if (command.equals("CHANGE")) {
        int indexRow = peaksInfoList.getSelectedRow();
        if (indexRow == -1) {
            return;
        }
        Feature selectedPeak = listElementModel.getElementAt(indexRow);
        ManualPeakPickerModule.runManualDetection(selectedPeak.getDataFile(), row, null, null);
        return;
    }
}
Also used : ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) HashMap(java.util.HashMap) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) Range(com.google.common.collect.Range) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) JFrame(javax.swing.JFrame) List(java.util.List) ArrayList(java.util.ArrayList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)

Example 15 with SimpleIsotopePattern

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

the class CameraSearchTask method groupPeaksByPCGroup.

/**
 * Uses PCGroup-field in PeakIdentity to group peaks and build spectrum
 *
 * @param peakList a PeakList object
 * @return a new PeakList object
 */
private PeakList groupPeaksByPCGroup(PeakList peakList) {
    // Create new feature list.
    final PeakList combinedPeakList = new SimplePeakList(peakList + " " + parameters.getParameter(CameraSearchParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
    // Load previous applied methods.
    for (final PeakList.PeakListAppliedMethod method : peakList.getAppliedMethods()) {
        combinedPeakList.addDescriptionOfAppliedTask(method);
    }
    // Add task description to feature list.
    combinedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Bioconductor CAMERA", parameters));
    // --------------------
    // Find unique PCGroups
    // --------------------
    Set<String> pcGroups = new HashSet<>();
    for (PeakListRow row : peakList.getRows()) {
        PeakIdentity identity = row.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        String groupName = identity.getName();
        if (groupName == null || groupName.length() == 0)
            continue;
        pcGroups.add(groupName);
    }
    List<PeakListRow> groupRows = new ArrayList<>();
    // Set <String> groupNames = new HashSet <> ();
    Map<Double, Double> spectrum = new HashMap<>();
    List<PeakListRow> newPeakListRows = new ArrayList<>();
    for (String groupName : pcGroups) {
        // -----------------------------------------
        // Find all peaks belonging to isotopeGroups
        // -----------------------------------------
        groupRows.clear();
        // groupNames.clear();
        spectrum.clear();
        double maxIntensity = 0.0;
        PeakListRow groupRow = null;
        for (PeakListRow row : peakList.getRows()) {
            PeakIdentity identity = row.getPreferredPeakIdentity();
            if (identity == null)
                continue;
            String name = identity.getName();
            if (name.equals(groupName)) {
                double intensity = row.getAverageHeight();
                groupRows.add(row);
                // groupNames.add(name);
                spectrum.put(row.getAverageMZ(), intensity);
                if (intensity > maxIntensity) {
                    maxIntensity = intensity;
                    groupRow = row;
                }
            }
        }
        if (groupRow == null || spectrum.size() <= 1)
            continue;
        PeakIdentity identity = groupRow.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        DataPoint[] dataPoints = new DataPoint[spectrum.size()];
        int count = 0;
        for (Entry<Double, Double> e : spectrum.entrySet()) dataPoints[count++] = new SimpleDataPoint(e.getKey(), e.getValue());
        IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
        groupRow.getBestPeak().setIsotopePattern(pattern);
        // combinedPeakList.addRow(groupRow);
        newPeakListRows.add(groupRow);
    }
    // ------------------------------------
    // Sort new peak rows by retention time
    // ------------------------------------
    Collections.sort(newPeakListRows, new Comparator<PeakListRow>() {

        @Override
        public int compare(PeakListRow row1, PeakListRow row2) {
            double retTime1 = row1.getAverageRT();
            double retTime2 = row2.getAverageRT();
            return Double.compare(retTime1, retTime2);
        }
    });
    for (PeakListRow row : newPeakListRows) combinedPeakList.addRow(row);
    return combinedPeakList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) HashSet(java.util.HashSet)

Aggregations

DataPoint (net.sf.mzmine.datamodel.DataPoint)17 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)17 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)15 ArrayList (java.util.ArrayList)11 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)6 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)6 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)5 ExtendedIsotopePattern (net.sf.mzmine.datamodel.impl.ExtendedIsotopePattern)5 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)5 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)5 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)5 HashMap (java.util.HashMap)4 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)4 ProcessedDataPoint (net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 DataInputStream (java.io.DataInputStream)3 IOException (java.io.IOException)3 Feature (net.sf.mzmine.datamodel.Feature)3 FeatureStatus (net.sf.mzmine.datamodel.Feature.FeatureStatus)3 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)3