use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class DeconvolutionModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull final ParameterSet parameters, @Nonnull final Collection<Task> tasks) {
PeakList[] peakLists = parameters.getParameter(DeconvolutionParameters.PEAK_LISTS).getValue().getMatchingPeakLists();
// function to calculate center mz
CenterFunction mzCenterFunction = parameters.getParameter(DeconvolutionParameters.MZ_CENTER_FUNCTION).getValue();
// use a LOG weighted, noise corrected, maximum weight capped function
if (mzCenterFunction.getMeasure().equals(CenterMeasure.AUTO)) {
// data point with lowest intensity
// weight = LOG(value) - LOG(noise) (maxed to maxWeight)
double noise = Arrays.stream(peakLists).flatMap(pkl -> Arrays.stream(pkl.getRows())).map(r -> r.getPeaks()[0]).mapToDouble(peak -> peak.getRawDataPointsIntensityRange().lowerEndpoint()).filter(v -> v != 0).min().orElse(0);
// maxWeight 4 corresponds to a linear range of 4 orders of magnitude
// everything higher than this will be capped to this weight
// do not overestimate influence of very high data points on mass accuracy
double maxWeight = 4;
// use a LOG weighted, noise corrected, maximum weight capped function
mzCenterFunction = new CenterFunction(CenterMeasure.AVG, Weighting.LOG10, noise, maxWeight);
}
for (final PeakList peakList : peakLists) {
tasks.add(new DeconvolutionTask(project, peakList, parameters, mzCenterFunction));
}
return ExitCode.OK;
}
use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class PeakExtenderModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
PeakList[] peakLists = parameters.getParameter(PeakExtenderParameters.peakLists).getValue().getMatchingPeakLists();
for (final PeakList peakList : peakLists) {
Task newTask = new PeakExtenderTask(project, peakList, parameters);
tasks.add(newTask);
}
return ExitCode.OK;
}
use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class RawDataExportModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull final MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
RawDataFileType type = parameters.getParameter(RawDataExportParameters.type).getValue();
String extension = "";
switch(type) {
case MZML:
extension = "mzML";
break;
case NETCDF:
extension = "cdf";
break;
default:
throw new MSDKRuntimeException("This format is not covered in the export module");
}
File folder = parameters.getParameter(RawDataExportParameters.fileName).getValue();
if (!folder.isDirectory())
folder = folder.getParentFile();
RawDataFile[] dataFile = parameters.getParameter(RawDataExportParameters.dataFiles).getValue().getMatchingRawDataFiles();
for (RawDataFile r : dataFile) {
File fullName = FileAndPathUtil.getRealFilePath(folder, r.getName(), extension);
Task newTask = new RawDataExportTask(r, fullName);
tasks.add(newTask);
}
return ExitCode.OK;
}
use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class RawDataImportModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull final MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
File[] fileNames = parameters.getParameter(RawDataImportParameters.fileNames).getValue();
// Find common prefix in raw file names if in GUI mode
String commonPrefix = null;
if (MZmineCore.getDesktop().getMainWindow() != null && fileNames.length > 1) {
String fileName = fileNames[0].getName();
outerloop: for (int x = 0; x < fileName.length(); x++) {
for (int i = 0; i < fileNames.length; i++) {
if (!fileName.substring(0, x).equals(fileNames[i].getName().substring(0, x))) {
commonPrefix = fileName.substring(0, x - 1);
break outerloop;
}
}
}
if (!Strings.isNullOrEmpty(commonPrefix)) {
// Show a dialog to allow user to remove common prefix
Object[] options1 = { "Remove", "Do not remove", "Cancel" };
JPanel panel = new JPanel();
panel.add(new JLabel("The files you have chosen have a common prefix."));
panel.add(new JLabel("Would you like to remove some or all of this prefix to shorten the names?"));
panel.add(new JLabel(" "));
panel.add(new JLabel("Prefix to remove:"));
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JTextField textField = new JTextField(6);
textField.setText(commonPrefix);
panel.add(textField);
int result = JOptionPane.showOptionDialog(null, panel, "Common prefix", JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options1, null);
// Cancel import if user clicked cancel
if (result == 2) {
return ExitCode.ERROR;
}
// Only remove if user selected to do so
if (result == 0) {
commonPrefix = textField.getText();
} else {
commonPrefix = null;
}
}
}
for (int i = 0; i < fileNames.length; i++) {
if (fileNames[i] == null) {
return ExitCode.OK;
}
if ((!fileNames[i].exists()) || (!fileNames[i].canRead())) {
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Cannot read file " + fileNames[i]);
logger.warning("Cannot read file " + fileNames[i]);
return ExitCode.ERROR;
}
// Set the new name by removing the common prefix
String newName;
if (!Strings.isNullOrEmpty(commonPrefix)) {
final String regex = "^" + Pattern.quote(commonPrefix);
newName = fileNames[i].getName().replaceFirst(regex, "");
} else {
newName = fileNames[i].getName();
}
RawDataFileWriter newMZmineFile;
try {
newMZmineFile = MZmineCore.createNewFile(newName);
} catch (IOException e) {
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Could not create a new temporary file " + e);
logger.log(Level.SEVERE, "Could not create a new temporary file ", e);
return ExitCode.ERROR;
}
RawDataFileType fileType = RawDataFileTypeDetector.detectDataFileType(fileNames[i]);
logger.finest("File " + fileNames[i] + " type detected as " + fileType);
if (fileType == null) {
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Could not determine the file type of file " + fileNames[i]);
continue;
}
Task newTask = createOpeningTask(fileType, project, fileNames[i], newMZmineFile);
if (newTask == null) {
logger.warning("File type " + fileType + " of file " + fileNames[i] + " is not supported.");
return ExitCode.ERROR;
}
tasks.add(newTask);
}
return ExitCode.OK;
}
use of net.sf.mzmine.taskcontrol.Task in project mzmine2 by mzmine.
the class TargetedPeakDetectionModule method runModule.
@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
RawDataFile[] dataFiles = parameters.getParameter(TargetedPeakDetectionParameters.rawDataFile).getValue().getMatchingRawDataFiles();
for (RawDataFile dataFile : dataFiles) {
Task newTask = new TargetedPeakDetectionModuleTask(project, parameters, dataFile);
tasks.add(newTask);
}
return ExitCode.OK;
}
Aggregations