for (final PeakListRow row : origPeakList.getRows()) {
if (!isCanceled()) {
// Create a new peak-list row.
final PeakListRow newRow = new SimplePeakListRow(peakID++);
// Process each peak.
for (final ChromatographicPeak 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 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 = new Range(intensity);
} else {
intensityRange.extendRange(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)
* (intensity + lastIntensity)
/ 2.0;
}
}
}
assert maxDataPoint != null;
if (!isCanceled() && maxScanNumber >= 0) {
// Create a new peak.
newRow.addPeak(
dataFile,
new SimpleChromatographicPeak(
dataFile,
maxDataPoint.getMZ(),
peak.getRT(),