Search in sources :

Example 36 with SimpleDataPoint

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

the class SmoothingTask method run.

@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    try {
        // Get filter weights.
        final double[] filterWeights = SavitzkyGolayFilter.getNormalizedWeights(filterWidth);
        // Create new feature list
        newPeakList = new SimplePeakList(origPeakList + " " + suffix, origPeakList.getRawDataFiles());
        // Process each row.
        for (final PeakListRow row : origPeakList.getRows()) {
            if (!isCanceled()) {
                // Create a new peak-list row.
                final int originalID = row.getID();
                final PeakListRow newRow = new SimplePeakListRow(originalID);
                // Process each peak.
                for (final Feature peak : row.getPeaks()) {
                    if (!isCanceled()) {
                        // Copy original peak intensities.
                        final int[] scanNumbers = peak.getScanNumbers();
                        final int numScans = scanNumbers.length;
                        final double[] intensities = new double[numScans];
                        for (int i = 0; i < numScans; i++) {
                            final DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);
                            intensities[i] = dataPoint == null ? 0.0 : dataPoint.getIntensity();
                        }
                        // Smooth peak.
                        final double[] smoothed = convolve(intensities, filterWeights);
                        // Measure peak (max, ranges, area etc.)
                        final RawDataFile dataFile = peak.getDataFile();
                        final DataPoint[] newDataPoints = new DataPoint[numScans];
                        double maxIntensity = 0.0;
                        int maxScanNumber = -1;
                        DataPoint maxDataPoint = null;
                        Range<Double> intensityRange = null;
                        double area = 0.0;
                        for (int i = 0; i < numScans; i++) {
                            final int scanNumber = scanNumbers[i];
                            final DataPoint dataPoint = peak.getDataPoint(scanNumber);
                            final double intensity = smoothed[i];
                            if (dataPoint != null && intensity > 0.0) {
                                // Create a new data point.
                                final double mz = dataPoint.getMZ();
                                final double rt = dataFile.getScan(scanNumber).getRetentionTime();
                                final DataPoint newDataPoint = new SimpleDataPoint(mz, intensity);
                                newDataPoints[i] = newDataPoint;
                                // Track maximum intensity data point.
                                if (intensity > maxIntensity) {
                                    maxIntensity = intensity;
                                    maxScanNumber = scanNumber;
                                    maxDataPoint = newDataPoint;
                                }
                                // Update ranges.
                                if (intensityRange == null) {
                                    intensityRange = Range.singleton(intensity);
                                } else {
                                    intensityRange = intensityRange.span(Range.singleton(intensity));
                                }
                                // Accumulate peak area.
                                if (i != 0) {
                                    final DataPoint lastDP = newDataPoints[i - 1];
                                    final double lastIntensity = lastDP == null ? 0.0 : lastDP.getIntensity();
                                    final double lastRT = dataFile.getScan(scanNumbers[i - 1]).getRetentionTime();
                                    area += (rt - lastRT) * 60d * (intensity + lastIntensity) / 2.0;
                                }
                            }
                        }
                        assert maxDataPoint != null;
                        if (!isCanceled() && maxScanNumber >= 0) {
                            // Create a new peak.
                            newRow.addPeak(dataFile, new SimpleFeature(dataFile, maxDataPoint.getMZ(), peak.getRT(), maxIntensity, area, scanNumbers, newDataPoints, peak.getFeatureStatus(), maxScanNumber, peak.getMostIntenseFragmentScanNumber(), peak.getAllMS2FragmentScanNumbers(), peak.getRawDataPointsRTRange(), peak.getRawDataPointsMZRange(), intensityRange));
                        }
                    }
                }
                newPeakList.addRow(newRow);
                progress++;
            }
        }
        // Finish up.
        if (!isCanceled()) {
            // Add new peak-list to the project.
            project.addPeakList(newPeakList);
            // Add quality parameters to peaks
            QualityParameters.calculateQualityParameters(newPeakList);
            // Remove the original peak-list if requested.
            if (removeOriginal) {
                project.removePeakList(origPeakList);
            }
            // Copy previously applied methods
            for (final PeakListAppliedMethod method : origPeakList.getAppliedMethods()) {
                newPeakList.addDescriptionOfAppliedTask(method);
            }
            // Add task description to peak-list.
            newPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peaks smoothed by Savitzky-Golay filter", parameters));
            LOG.finest("Finished peak smoothing: " + progress + " rows processed");
            setStatus(TaskStatus.FINISHED);
        }
    } catch (Throwable t) {
        LOG.log(Level.SEVERE, "Smoothing error", t);
        setErrorMessage(t.getMessage());
        setStatus(TaskStatus.ERROR);
    }
}
Also used : SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList)

Example 37 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint 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 38 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint 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 39 with SimpleDataPoint

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

the class ExtendedPeak method finishExtendedPeak.

public void finishExtendedPeak() {
    int[] allScanNumbers = Ints.toArray(dataPointsMap.keySet());
    Arrays.sort(allScanNumbers);
    scanNumbers = allScanNumbers;
    // Calculate median m/z
    double[] allMzValues = new double[allScanNumbers.length];
    for (int i = 0; i < allScanNumbers.length; i++) {
        allMzValues[i] = dataPointsMap.get(allScanNumbers[i]).getMZ();
    }
    mz = MathUtils.calcQuantile(allMzValues, 0.5f);
    // Update raw data point ranges, height, rt and representative scan
    height = Double.MIN_VALUE;
    for (int i = 0; i < allScanNumbers.length; i++) {
        DataPoint mzPeak = dataPointsMap.get(allScanNumbers[i]);
        Scan aScan = dataFile.getScan(allScanNumbers[i]);
        // Replace the MzPeak instance with an instance of SimpleDataPoint,
        // to reduce the memory usage. After we finish this extended peak,
        // we don't need the additional data provided by the MzPeak
        SimpleDataPoint newDataPoint = new SimpleDataPoint(mzPeak);
        dataPointsMap.put(allScanNumbers[i], newDataPoint);
        if (i == 0) {
            rawDataPointsIntensityRange = Range.singleton(mzPeak.getIntensity());
            rawDataPointsMZRange = Range.singleton(mzPeak.getMZ());
            rawDataPointsRTRange = Range.singleton(aScan.getRetentionTime());
        } else {
            rawDataPointsIntensityRange = rawDataPointsIntensityRange.span(Range.singleton(mzPeak.getIntensity()));
            rawDataPointsMZRange = rawDataPointsMZRange.span(Range.singleton(mzPeak.getMZ()));
            rawDataPointsRTRange = rawDataPointsRTRange.span(Range.singleton(aScan.getRetentionTime()));
        }
        if (height < mzPeak.getIntensity()) {
            height = mzPeak.getIntensity();
            rt = aScan.getRetentionTime();
            representativeScan = allScanNumbers[i];
        }
    }
    // Update area
    area = 0;
    for (int i = 1; i < allScanNumbers.length; i++) {
        // For area calculation, we use retention time in seconds
        double previousRT = dataFile.getScan(allScanNumbers[i - 1]).getRetentionTime() * 60d;
        double currentRT = dataFile.getScan(allScanNumbers[i]).getRetentionTime() * 60d;
        double previousHeight = dataPointsMap.get(allScanNumbers[i - 1]).getIntensity();
        double currentHeight = dataPointsMap.get(allScanNumbers[i]).getIntensity();
        area += (currentRT - previousRT) * (currentHeight + previousHeight) / 2;
    }
    // Update fragment scan
    fragmentScan = ScanUtils.findBestFragmentScan(dataFile, dataFile.getDataRTRange(1), rawDataPointsMZRange);
    allMS2FragmentScanNumbers = ScanUtils.findAllMS2FragmentScans(dataFile, dataFile.getDataRTRange(1), rawDataPointsMZRange);
    if (fragmentScan > 0) {
        Scan fragmentScanObject = dataFile.getScan(fragmentScan);
        int precursorCharge = fragmentScanObject.getPrecursorCharge();
        if ((precursorCharge > 0) && (this.charge == 0))
            this.charge = precursorCharge;
    }
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Scan(net.sf.mzmine.datamodel.Scan) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 40 with SimpleDataPoint

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

the class MzMLReadTask method extractDataPoints.

private DataPoint[] extractDataPoints(Spectrum spectrum) {
    BinaryDataArrayList dataList = spectrum.getBinaryDataArrayList();
    if ((dataList == null) || (dataList.getCount().equals(0)))
        return new DataPoint[0];
    BinaryDataArray mzArray = dataList.getBinaryDataArray().get(0);
    BinaryDataArray intensityArray = dataList.getBinaryDataArray().get(1);
    Number[] mzValues = mzArray.getBinaryDataAsNumberArray();
    Number[] intensityValues = intensityArray.getBinaryDataAsNumberArray();
    DataPoint[] dataPoints = new DataPoint[mzValues.length];
    for (int i = 0; i < dataPoints.length; i++) {
        double mz = mzValues[i].doubleValue();
        double intensity = intensityValues[i].doubleValue();
        dataPoints[i] = new SimpleDataPoint(mz, intensity);
    }
    return dataPoints;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) BinaryDataArray(uk.ac.ebi.jmzml.model.mzml.BinaryDataArray) BinaryDataArrayList(uk.ac.ebi.jmzml.model.mzml.BinaryDataArrayList) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Aggregations

SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)58 DataPoint (net.sf.mzmine.datamodel.DataPoint)56 Scan (net.sf.mzmine.datamodel.Scan)15 ArrayList (java.util.ArrayList)13 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)13 SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)12 IOException (java.io.IOException)11 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)10 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)10 Feature (net.sf.mzmine.datamodel.Feature)8 HashMap (java.util.HashMap)7 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)7 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)6 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)6 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)5 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)5 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 Vector (java.util.Vector)4