// Set total number of scans to process
totalScans = dataFile.getNumOfScans();
try {
// Create a new file
final RawDataFileImpl rawDataFileWriter = (RawDataFileImpl) MZmineCore
.createNewFile(dataFile.getName() + ' ' + suffix);
// Process each deconvoluted spectrum
for (int scanNumber : dataFile.getScanNumbers(1)) {
// Canceled?
if (isCanceled())
return;
// Duplicate current spectrum
Scan spectrum = dataFile.getScan(scanNumber);
// Exclude the entire spectrum if its base peak intensity is
// less than the given threshold
if (spectrum.getBasePeak().getIntensity() < basePeakThreshold)
continue;
// Exclude the entire spectrum if its unique mass intensity is
// less than the given threshold
if (spectrum instanceof CorrectedSpectrum) {
CorrectedSpectrum s = ((CorrectedSpectrum) spectrum);
if (s.getUniqueMass() != null
&& s.getUniqueMass().getIntensity() < uniqueMassThreshold)
continue;
}
// Get the data points from the spectrum and sort by m/z
List<DataPoint> dataPoints = Lists.newArrayList(spectrum
.getDataPoints());
Collections.sort(dataPoints, new Comparator<DataPoint>() {
@Override
public int compare(DataPoint a, DataPoint b) {
return a.getMZ() < b.getMZ() ? -1 : a.getMZ() > b
.getMZ() ? 1 : 0;
}
});
// Create a list for the filtered points
List<DataPoint> filteredDataPoints = new ArrayList<DataPoint>();
// Filter the data points given pre-defined conditions
for (int i = dataPoints.size() - 1; i >= 0; i--) {
// Step #1: Remove C13 Isotope ions
if (i > 0
&& dataPoints.get(i).getMZ()
- dataPoints.get(i - 1).getMZ() < 1 + EPSILON
&& dataPoints.get(i - 1).getIntensity() >= (1 + c13IsotopeCut)
* dataPoints.get(i).getIntensity())
continue;
// Step #2: Remove all ions < 100 counts
else if (dataPoints.get(i).getIntensity() < intensityThreshold)
continue;
// Step #3: Remove all ions < 1% of base peak
else if (dataPoints.get(i).getIntensity() < intensityPercentageThreshold
* spectrum.getBasePeak().getIntensity())
continue;
// If the data point passes all filters, keep it.
else
filteredDataPoints.add(0, dataPoints.get(i));
}
// Add scan to new data file
int storageID = rawDataFileWriter
.storeDataPoints(filteredDataPoints
.toArray(new DataPoint[filteredDataPoints
.size()]));
CorrectedSpectrum newSpectrum = new CorrectedSpectrum(spectrum,
rawDataFileWriter, filteredDataPoints.size(), storageID);
rawDataFileWriter.addScan(newSpectrum);
processedScans++;
}
// If this task was canceled, stop processing
if (!isCanceled()) {
// Finalize writing
filteredDataFile = rawDataFileWriter.finishWriting();
// Add the newly created file to the project
final MZmineProject project = MZmineCore.getCurrentProject();
project.addFile(filteredDataFile);