Search in sources :

Example 56 with Task

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;
}
Also used : Arrays(java.util.Arrays) Collection(java.util.Collection) CenterFunction(net.sf.mzmine.util.maths.CenterFunction) MZmineModuleCategory(net.sf.mzmine.modules.MZmineModuleCategory) PeakList(net.sf.mzmine.datamodel.PeakList) CenterMeasure(net.sf.mzmine.util.maths.CenterMeasure) Task(net.sf.mzmine.taskcontrol.Task) MZmineProcessingModule(net.sf.mzmine.modules.MZmineProcessingModule) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Weighting(net.sf.mzmine.util.maths.Weighting) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) ExitCode(net.sf.mzmine.util.ExitCode) Nonnull(javax.annotation.Nonnull) PeakList(net.sf.mzmine.datamodel.PeakList) CenterFunction(net.sf.mzmine.util.maths.CenterFunction) Nonnull(javax.annotation.Nonnull)

Example 57 with Task

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;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) PeakList(net.sf.mzmine.datamodel.PeakList) Nonnull(javax.annotation.Nonnull)

Example 58 with Task

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;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File) Nonnull(javax.annotation.Nonnull)

Example 59 with Task

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;
}
Also used : JPanel(javax.swing.JPanel) MzMLReadTask(net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.MzMLReadTask) MzDataReadTask(net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.MzDataReadTask) CsvReadTask(net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.CsvReadTask) AgilentCsvReadTask(net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.AgilentCsvReadTask) MzXMLReadTask(net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.MzXMLReadTask) ZipReadTask(net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.ZipReadTask) Task(net.sf.mzmine.taskcontrol.Task) NativeFileReadTask(net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.NativeFileReadTask) NetCDFReadTask(net.sf.mzmine.modules.rawdatamethods.rawdataimport.fileformats.NetCDFReadTask) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) RawDataFileWriter(net.sf.mzmine.datamodel.RawDataFileWriter) IOException(java.io.IOException) JTextField(javax.swing.JTextField) File(java.io.File) Nonnull(javax.annotation.Nonnull)

Example 60 with Task

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;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Nonnull(javax.annotation.Nonnull)

Aggregations

Task (net.sf.mzmine.taskcontrol.Task)75 Nonnull (javax.annotation.Nonnull)57 PeakList (net.sf.mzmine.datamodel.PeakList)37 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)20 ParameterSet (net.sf.mzmine.parameters.ParameterSet)8 ArrayList (java.util.ArrayList)7 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)7 TaskStatus (net.sf.mzmine.taskcontrol.TaskStatus)7 File (java.io.File)6 RawDataFilesParameter (net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesParameter)6 ExitCode (net.sf.mzmine.util.ExitCode)4 MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)3 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)3 RawDataFileWriter (net.sf.mzmine.datamodel.RawDataFileWriter)2 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)2 CSVExportTask (net.sf.mzmine.modules.peaklistmethods.io.csvexport.CSVExportTask)2 PeakListsParameter (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter)2 TaskStatusListener (net.sf.mzmine.taskcontrol.TaskStatusListener)2 IOException (java.io.IOException)1 Arrays (java.util.Arrays)1