* filtering.
*/
private PeakList filterPeakListRows(final PeakList peakList) {
// Create new peak list.
final PeakList newPeakList = new SimplePeakList(peakList.getName()
+ ' ' + parameters.getParameter(SUFFIX).getValue(),
peakList.getRawDataFiles());
// Copy previous applied methods.
for (final PeakListAppliedMethod method : peakList.getAppliedMethods()) {
newPeakList.addDescriptionOfAppliedTask(method);
}
// Add task description to peakList.
newPeakList
.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod(
getTaskDescription(), parameters));
// Get parameters.
final boolean identified = parameters.getParameter(HAS_IDENTITIES)
.getValue();
final String groupingParameter = (String) parameters.getParameter(
GROUPSPARAMETER).getValue();
final int minPresent = parameters.getParameter(MIN_PEAK_COUNT)
.getValue();
final int minIsotopePatternSize = parameters.getParameter(
MIN_ISOTOPE_PATTERN_COUNT).getValue();
final Range mzRange = parameters.getParameter(MZ_RANGE).getValue();
final Range rtRange = parameters.getParameter(RT_RANGE).getValue();
final Range durationRange = parameters.getParameter(PEAK_DURATION)
.getValue();
// Filter rows.
final PeakListRow[] rows = peakList.getRows();
totalRows = rows.length;
for (processedRows = 0; !isCanceled() && processedRows < totalRows; processedRows++) {
final PeakListRow row = rows[processedRows];
boolean rowIsGood = true;
// Check number of peaks.
final int peakCount = getPeakCount(row, groupingParameter);
if (peakCount < minPresent) {
rowIsGood = false;
}
// Check identities.
if (identified && row.getPreferredPeakIdentity() == null) {
rowIsGood = false;
}
// Check average m/z.
if (!mzRange.contains(row.getAverageMZ())) {
rowIsGood = false;
}
// Check average RT.
if (!rtRange.contains(row.getAverageRT())) {
rowIsGood = false;
}
// Calculate average duration and isotope pattern count.
int maxIsotopePatternSizeOnRow = 1;
double avgDuration = 0.0;
final ChromatographicPeak[] peaks = row.getPeaks();
for (final ChromatographicPeak p : peaks) {
final IsotopePattern pattern = p.getIsotopePattern();
if (pattern != null
&& maxIsotopePatternSizeOnRow < pattern
.getNumberOfIsotopes()) {
maxIsotopePatternSizeOnRow = pattern.getNumberOfIsotopes();
}
avgDuration += p.getRawDataPointsRTRange().getSize();
}
// Check isotope pattern count.
if (maxIsotopePatternSizeOnRow < minIsotopePatternSize) {
rowIsGood = false;
}
// Check average duration.
avgDuration /= (double) peakCount;
if (!durationRange.contains(avgDuration)) {
rowIsGood = false;
}
// Good row?
if (rowIsGood) {
newPeakList.addRow(copyPeakRow(row));
}
}
return newPeakList;
}