TreeSet<ExactMzDataPoint> candidatePeaks, double noiseLevel) {
DataPoint[] scanDataPoints = scan.getDataPoints();
if (scanDataPoints.length == 0)
return;
DataPoint localMaximum = scanDataPoints[0];
ArrayList<DataPoint> rangeDataPoints = new ArrayList<DataPoint>();
boolean ascending = true;
// Iterate through all data points
for (int i = 0; i < scanDataPoints.length - 1; i++) {
boolean nextIsBigger = scanDataPoints[i + 1].getIntensity() > scanDataPoints[i]
.getIntensity();
boolean nextIsZero = scanDataPoints[i + 1].getIntensity() == 0;
boolean currentIsZero = scanDataPoints[i].getIntensity() == 0;
// Ignore zero intensity regions
if (currentIsZero) {
continue;
}
// Add current (non-zero) data point to the current m/z peak
rangeDataPoints.add(scanDataPoints[i]);
// Check for local maximum
if (ascending && (!nextIsBigger)) {
localMaximum = scanDataPoints[i];
ascending = false;
continue;
}
// Check for the end of the peak
if ((!ascending) && (nextIsBigger || nextIsZero)) {
// Add the m/z peak if it is above the noise level
if (localMaximum.getIntensity() > noiseLevel) {
DataPoint[] rawDataPoints = rangeDataPoints
.toArray(new DataPoint[0]);
candidatePeaks.add(new ExactMzDataPoint(localMaximum,
rawDataPoints));