Search in sources :

Example 1 with DataPointSorter

use of net.sf.mzmine.util.DataPointSorter in project mzmine2 by mzmine.

the class SpectralDBPeakIdentity method getQueryDataPoints.

public DataPoint[] getQueryDataPoints(DataPointsTag tag) {
    switch(tag) {
        case ORIGINAL:
            DataPoint[] dp = getQueryDataPoints();
            if (dp == null)
                return new DataPoint[0];
            Arrays.sort(dp, new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending));
            return dp;
        case FILTERED:
            return similarity.getQuery();
        case ALIGNED:
            return similarity.getAlignedDataPoints()[1];
        case MERGED:
            return new DataPoint[0];
    }
    return new DataPoint[0];
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPointSorter(net.sf.mzmine.util.DataPointSorter)

Example 2 with DataPointSorter

use of net.sf.mzmine.util.DataPointSorter in project mzmine2 by mzmine.

the class HighestDataPointConnector method addScan.

public void addScan(int scanNumber, DataPoint[] mzValues) {
    // Sort m/z peaks by descending intensity
    Arrays.sort(mzValues, new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending));
    // Set of already connected chromatograms in each iteration
    Set<Chromatogram> connectedChromatograms = new LinkedHashSet<Chromatogram>();
    // TODO: these two nested cycles should be optimized for speed
    for (DataPoint mzPeak : mzValues) {
        // Search for best chromatogram, which has highest last data point
        Chromatogram bestChromatogram = null;
        for (Chromatogram testChrom : buildingChromatograms) {
            DataPoint lastMzPeak = testChrom.getLastMzPeak();
            Range<Double> toleranceRange = mzTolerance.getToleranceRange(lastMzPeak.getMZ());
            if (toleranceRange.contains(mzPeak.getMZ())) {
                if ((bestChromatogram == null) || (testChrom.getLastMzPeak().getIntensity() > bestChromatogram.getLastMzPeak().getIntensity())) {
                    bestChromatogram = testChrom;
                }
            }
        }
        // haven't found a chromatogram, we may create a new one.
        if (bestChromatogram != null) {
            if (connectedChromatograms.contains(bestChromatogram)) {
                continue;
            }
        } else {
            bestChromatogram = new Chromatogram(dataFile, allScanNumbers);
        }
        // Add this mzPeak to the chromatogram
        bestChromatogram.addMzPeak(scanNumber, mzPeak);
        // Move the chromatogram to the set of connected chromatograms
        connectedChromatograms.add(bestChromatogram);
    }
    // Process those chromatograms which were not connected to any m/z peak
    for (Chromatogram testChrom : buildingChromatograms) {
        // Skip those which were connected
        if (connectedChromatograms.contains(testChrom)) {
            continue;
        }
        // Check if we just finished a long-enough segment
        if (testChrom.getBuildingSegmentLength() >= minimumTimeSpan) {
            testChrom.commitBuildingSegment();
            // Move the chromatogram to the set of connected chromatograms
            connectedChromatograms.add(testChrom);
            continue;
        }
        // Check if we have any committed segments in the chromatogram
        if (testChrom.getNumberOfCommittedSegments() > 0) {
            testChrom.removeBuildingSegment();
            // Move the chromatogram to the set of connected chromatograms
            connectedChromatograms.add(testChrom);
            continue;
        }
    }
    // All remaining chromatograms in buildingChromatograms are discarded
    // and buildingChromatograms is replaced with connectedChromatograms
    buildingChromatograms = connectedChromatograms;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPointSorter(net.sf.mzmine.util.DataPointSorter)

Example 3 with DataPointSorter

use of net.sf.mzmine.util.DataPointSorter in project mzmine2 by mzmine.

the class ShoulderPeaksFilter method filterMassValues.

public static DataPoint[] filterMassValues(DataPoint[] mzPeaks, ParameterSet parameters) {
    double resolution = parameters.getParameter(ShoulderPeaksFilterParameters.resolution).getValue();
    PeakModel peakModel = null;
    // Try to create an instance of the peak model
    try {
        PeakModelType type = parameters.getParameter(ShoulderPeaksFilterParameters.peakModel).getValue();
        if (type == null)
            type = PeakModelType.GAUSS;
        Class<?> modelClass = type.getModelClass();
        peakModel = (PeakModel) modelClass.newInstance();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // If peakModel is null, just don't do any filtering
    if (peakModel == null)
        return mzPeaks;
    // Create a tree set of detected mzPeaks sorted by MZ in ascending order
    TreeSet<DataPoint> finalMZPeaks = new TreeSet<DataPoint>(new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending));
    // Create a tree set of candidate mzPeaks sorted by intensity in
    // descending order.
    TreeSet<DataPoint> candidatePeaks = new TreeSet<DataPoint>(new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending));
    candidatePeaks.addAll(Arrays.asList(mzPeaks));
    while (candidatePeaks.size() > 0) {
        // Always take the biggest (intensity) peak
        DataPoint currentCandidate = candidatePeaks.first();
        // Add this candidate to the final tree set sorted by MZ and remove
        // from tree set sorted by intensity
        finalMZPeaks.add(currentCandidate);
        candidatePeaks.remove(currentCandidate);
        // Remove from tree set sorted by intensity all FTMS shoulder peaks,
        // taking as a main peak the current candidate
        removeLateralPeaks(currentCandidate, candidatePeaks, peakModel, resolution);
    }
    return finalMZPeaks.toArray(new DataPoint[0]);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) TreeSet(java.util.TreeSet) DataPointSorter(net.sf.mzmine.util.DataPointSorter)

Example 4 with DataPointSorter

use of net.sf.mzmine.util.DataPointSorter in project mzmine2 by mzmine.

the class RecursiveMassDetector method getMassValues.

public DataPoint[] getMassValues(DataPoint[] dataPoints, ParameterSet parameters) {
    double noiseLevel = parameters.getParameter(RecursiveMassDetectorParameters.noiseLevel).getValue();
    double minimumMZPeakWidth = parameters.getParameter(RecursiveMassDetectorParameters.minimumMZPeakWidth).getValue();
    double maximumMZPeakWidth = parameters.getParameter(RecursiveMassDetectorParameters.maximumMZPeakWidth).getValue();
    TreeSet<DataPoint> mzPeaks = new TreeSet<DataPoint>(new DataPointSorter(SortingProperty.MZ, SortingDirection.Ascending));
    // Find MzPeaks
    recursiveThreshold(mzPeaks, dataPoints, 1, dataPoints.length - 1, noiseLevel, minimumMZPeakWidth, maximumMZPeakWidth, 0);
    return mzPeaks.toArray(new DataPoint[0]);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) TreeSet(java.util.TreeSet) DataPointSorter(net.sf.mzmine.util.DataPointSorter)

Example 5 with DataPointSorter

use of net.sf.mzmine.util.DataPointSorter in project mzmine2 by mzmine.

the class ADAPHighestDataPointConnector method addScan.

public void addScan(int scanNumber, DataPoint[] mzValues) {
    // Sort m/z peaks by descending intensity
    Arrays.sort(mzValues, new DataPointSorter(SortingProperty.Intensity, SortingDirection.Descending));
    // Set of already connected chromatograms in each iteration
    Set<ADAPChromatogram> connectedChromatograms = new LinkedHashSet<ADAPChromatogram>();
    // TODO: these two nested cycles should be optimized for speed
    for (DataPoint mzPeak : mzValues) {
        // Search for best chromatogram, which has highest last data point
        ADAPChromatogram bestChromatogram = null;
        for (ADAPChromatogram testChrom : buildingChromatograms) {
            DataPoint lastMzPeak = testChrom.getLastMzPeak();
            Range<Double> toleranceRange = mzTolerance.getToleranceRange(lastMzPeak.getMZ());
            if (toleranceRange.contains(mzPeak.getMZ())) {
                if ((bestChromatogram == null) || (testChrom.getLastMzPeak().getIntensity() > bestChromatogram.getLastMzPeak().getIntensity())) {
                    bestChromatogram = testChrom;
                }
            }
        }
        // haven't found a chromatogram, we may create a new one.
        if (bestChromatogram != null) {
            if (connectedChromatograms.contains(bestChromatogram)) {
                continue;
            }
        } else {
            bestChromatogram = new ADAPChromatogram(dataFile, allScanNumbers);
        }
        // Add this mzPeak to the chromatogram
        bestChromatogram.addMzPeak(scanNumber, mzPeak);
        // Move the chromatogram to the set of connected chromatograms
        connectedChromatograms.add(bestChromatogram);
    }
    // Process those chromatograms which were not connected to any m/z peak
    for (ADAPChromatogram testChrom : buildingChromatograms) {
        // Skip those which were connected
        if (connectedChromatograms.contains(testChrom)) {
            continue;
        }
        // Check if we just finished a long-enough segment
        if (testChrom.getBuildingSegmentLength() >= minimumTimeSpan) {
            testChrom.commitBuildingSegment();
            // Move the chromatogram to the set of connected chromatograms
            connectedChromatograms.add(testChrom);
            continue;
        }
        // Check if we have any committed segments in the chromatogram
        if (testChrom.getNumberOfCommittedSegments() > 0) {
            testChrom.removeBuildingSegment();
            // Move the chromatogram to the set of connected chromatograms
            connectedChromatograms.add(testChrom);
            continue;
        }
    }
    // All remaining chromatograms in buildingChromatograms are discarded
    // and buildingChromatograms is replaced with connectedChromatograms
    buildingChromatograms = connectedChromatograms;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPointSorter(net.sf.mzmine.util.DataPointSorter)

Aggregations

DataPointSorter (net.sf.mzmine.util.DataPointSorter)12 DataPoint (net.sf.mzmine.datamodel.DataPoint)11 TreeSet (java.util.TreeSet)4 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 ArrayList (java.util.ArrayList)3 LinkedHashSet (java.util.LinkedHashSet)2 MZTolerance (net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance)2 Range (com.google.common.collect.Range)1 Vector (java.util.Vector)1 Feature (net.sf.mzmine.datamodel.Feature)1 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)1 MassList (net.sf.mzmine.datamodel.MassList)1 Scan (net.sf.mzmine.datamodel.Scan)1 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)1 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)1 PeakSorter (net.sf.mzmine.util.PeakSorter)1