// Update the status of this task
setStatus(TaskStatus.PROCESSING);
try {
// Create a new file
final RawDataFileWriter rawDataFileWriter = MZmineCore
.createNewFile(origDataFile.getName() + ' ' + suffix);
// Determine number of bins.
final int numBins = useBins ? (int) Math.ceil(origDataFile
.getDataMZRange().getSize() / binWidth) : 1;
// Get MS levels.
final int[] levels = origDataFile.getMSLevels();
// Measure progress and find MS-level.
boolean foundLevel = msLevel == 0;
progressMax = 0;
for (final int level : levels) {
final boolean isMSLevel = msLevel == level;
final int numScans = origDataFile.getScanNumbers(level).length;
foundLevel |= isMSLevel;
progressMax += isMSLevel || msLevel == 0 ? 2 * numScans
+ numBins : numScans;
}
// Is the specified MS-level present?
if (!foundLevel) {
throw new IllegalArgumentException(
"The data file doesn't contain data for MS-level "
+ msLevel + '.');
}
// Which chromatogram type.
final boolean useTIC = chromatogramType == ChromatogramType.TIC;
// Process each MS level.
for (final int level : levels) {
if (!isCanceled()) {
if (level == msLevel || msLevel == 0) {
// Correct baseline for this MS-level.
if (useTIC) {
correctTICBaselines(rawDataFileWriter, level,
numBins);
} else {
correctBasePeakBaselines(rawDataFileWriter, level,
numBins);
}
} else {
// Copy scans for this MS-level.
copyScansToWriter(rawDataFileWriter, level);
}
}
}
// If this task was canceled, stop processing
if (!isCanceled()) {
// Finalize writing
correctedDataFile = rawDataFileWriter.finishWriting();
// Add the newly created file to the project
final MZmineProject project = MZmineCore.getCurrentProject();
project.addFile(correctedDataFile);