// Cancel?
if (status == TaskStatus.CANCELED)
return;
Scan scan = rawDataFile.getScan(scanNumber);
// check parent m/z
if (!totalMZRange.contains(scan.getPrecursorMZ())) {
continue;
}
// get m/z and intensity values
DataPoint scanDataPoints[] = scan.getDataPoints();
// skip empty scans
if (scan.getBasePeak() == null) {
processedScans++;
continue;
}
// topPeaks will contain indexes to mzValues peaks of top intensity
int topPeaks[] = new int[numOfFragments];
Arrays.fill(topPeaks, -1);
for (int i = 0; i < scanDataPoints.length; i++) {
fragmentsCycle : for (int j = 0; j < numOfFragments; j++) {
// Cancel?
if (status == TaskStatus.CANCELED)
return;
if ((topPeaks[j] < 0)
|| (scanDataPoints[i].getIntensity()) > scanDataPoints[topPeaks[j]]
.getIntensity()) {
// shift the top peaks array
for (int k = numOfFragments - 1; k > j; k--)
topPeaks[k] = topPeaks[k - 1];
// add the peak to the appropriate place
topPeaks[j] = i;
break fragmentsCycle;
}
}
}
// add the data points
for (int i = 0; i < topPeaks.length; i++) {
int peakIndex = topPeaks[i];
// if we have a very few peaks, the array may not be full
if (peakIndex < 0)
break;
NeutralLossDataPoint newPoint = new NeutralLossDataPoint(
scanDataPoints[peakIndex].getMZ(),
scan.getScanNumber(), scan.getParentScanNumber(),
scan.getPrecursorMZ(), scan.getPrecursorCharge(),
scan.getRetentionTime());
dataSeries.get(0).add(newPoint);
}