Search in sources :

Example 36 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class AddAdductsAction method actionPerformed.

@Override
public void actionPerformed(final ActionEvent e) {
    // Parent component.
    final AdductsComponent parent = (AdductsComponent) SwingUtilities.getAncestorOfClass(AdductsComponent.class, (Component) e.getSource());
    if (parent != null) {
        // Show dialog.
        final ParameterSet parameters = new AddAdductParameters();
        if (parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true) == ExitCode.OK) {
            // Create new adduct.
            final AdductType adduct = new AdductType(parameters.getParameter(AddAdductParameters.NAME).getValue(), parameters.getParameter(AddAdductParameters.MASS_DIFFERENCE).getValue());
            // Add to list of choices (if not already present).
            final Collection<AdductType> choices = new ArrayList<AdductType>(Arrays.asList((AdductType[]) parent.getChoices()));
            if (!choices.contains(adduct)) {
                choices.add(adduct);
                parent.setChoices(choices.toArray(new AdductType[choices.size()]));
            }
        }
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) ArrayList(java.util.ArrayList) AdductsComponent(net.sf.mzmine.parameters.parametertypes.AdductsComponent) AdductsComponent(net.sf.mzmine.parameters.parametertypes.AdductsComponent) Component(java.awt.Component)

Example 37 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class MzTabImportTask method importRawDataFiles.

private SortedMap<Integer, RawDataFile> importRawDataFiles(MZTabFile mzTabFile) throws Exception {
    SortedMap<Integer, MsRun> msrun = mzTabFile.getMetadata().getMsRunMap();
    SortedMap<Integer, RawDataFile> rawDataFiles = new TreeMap<>();
    // If we are importing files, let's run RawDataImportModule
    if (importRawFiles) {
        List<File> filesToImport = new ArrayList<>();
        for (Entry<Integer, MsRun> entry : msrun.entrySet()) {
            File fileToImport = new File(entry.getValue().getLocation().getPath());
            if (fileToImport.exists() && fileToImport.canRead())
                filesToImport.add(fileToImport);
            else {
                // Check if the raw file exists in the same folder as the mzTab file
                File checkFile = new File(inputFile.getParentFile(), fileToImport.getName());
                if (checkFile.exists() && checkFile.canRead())
                    filesToImport.add(checkFile);
                else {
                    // Append .gz & check again if file exists as a workaround to .gz not getting preserved
                    // when .mzML.gz importing
                    checkFile = new File(inputFile.getParentFile(), fileToImport.getName() + ".gz");
                    if (checkFile.exists() && checkFile.canRead())
                        filesToImport.add(checkFile);
                    else {
                        // One more level of checking, appending .zip & checking as a workaround
                        checkFile = new File(inputFile.getParentFile(), fileToImport.getName() + ".zip");
                        if (checkFile.exists() && checkFile.canRead())
                            filesToImport.add(checkFile);
                    }
                }
            }
        }
        RawDataImportModule RDI = MZmineCore.getModuleInstance(RawDataImportModule.class);
        ParameterSet rdiParameters = RDI.getParameterSetClass().newInstance();
        rdiParameters.getParameter(RawDataImportParameters.fileNames).setValue(filesToImport.toArray(new File[0]));
        synchronized (underlyingTasks) {
            RDI.runModule(project, rdiParameters, underlyingTasks);
        }
        if (underlyingTasks.size() > 0) {
            MZmineCore.getTaskController().addTasks(underlyingTasks.toArray(new Task[0]));
        }
        // Wait until all raw data file imports have completed
        while (true) {
            if (isCanceled())
                return null;
            boolean tasksFinished = true;
            for (Task task : underlyingTasks) {
                if ((task.getStatus() == TaskStatus.WAITING) || (task.getStatus() == TaskStatus.PROCESSING))
                    tasksFinished = false;
            }
            if (tasksFinished)
                break;
            Thread.sleep(1000);
        }
    /*
       * // Sort raw data files based on order in mzTab file MainWindow mainWindow = (MainWindow)
       * MZmineCore.getDesktop(); ProjectTree rawDataTree = mainWindow.getMainPanel()
       * .getRawDataTree(); final RawDataTreeModel treeModel = ((MZmineProjectImpl)
       * project).getRawDataTreeModel(); final DefaultMutableTreeNode rootNode =
       * treeModel.getRoot(); int[] selectedRows = new int[rootNode.getChildCount()]; for (int i =
       * 1; i < rootNode.getChildCount() + 1; i++) { selectedRows[i - 1] = i; } final
       * ArrayList<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
       * for (int row : selectedRows) { TreePath path = rawDataTree.getPathForRow(row);
       * DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) path
       * .getLastPathComponent(); selectedNodes.add(selectedNode); }
       * 
       * // Reorder the nodes in the tree model based on order in mzTab // file int fileCounter = 0;
       * for (Entry<Integer, MsRun> entry : msrun.entrySet()) { fileCounter++; File f = new
       * File(entry.getValue().getLocation().getPath()); for (DefaultMutableTreeNode node :
       * selectedNodes) { if (node.toString().equals(f.getName())) {
       * treeModel.removeNodeFromParent(node); treeModel.insertNodeInto(node, rootNode, fileCounter
       * - 1); } } }
       */
    } else {
        finishedPercentage = 0.5;
    }
    // Find a matching RawDataFile for each MsRun entry
    for (Entry<Integer, MsRun> entry : msrun.entrySet()) {
        String rawFileName = new File(entry.getValue().getLocation().getPath()).getName();
        RawDataFile rawDataFile = null;
        // Check if we already have a RawDataFile of that name
        for (RawDataFile f : project.getDataFiles()) {
            if (f.getName().equals(rawFileName)) {
                rawDataFile = f;
                break;
            }
        }
        // If no data file of that name exists, create a dummy one
        if (rawDataFile == null) {
            RawDataFileWriter writer = MZmineCore.createNewFile(rawFileName);
            rawDataFile = writer.finishWriting();
            project.addFile(rawDataFile);
        }
        // Save a reference to the new raw data file
        rawDataFiles.put(entry.getKey(), rawDataFile);
    }
    return rawDataFiles;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) Task(net.sf.mzmine.taskcontrol.Task) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) ArrayList(java.util.ArrayList) RawDataFileWriter(net.sf.mzmine.datamodel.RawDataFileWriter) TreeMap(java.util.TreeMap) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) RawDataImportModule(net.sf.mzmine.modules.rawdatamethods.rawdataimport.RawDataImportModule) MsRun(uk.ac.ebi.pride.jmztab.model.MsRun) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File) MZTabFile(uk.ac.ebi.pride.jmztab.model.MZTabFile)

Example 38 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class SiriusExportModule method exportSinglePeakList.

public static void exportSinglePeakList(PeakListRow row) {
    try {
        ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(SiriusExportModule.class);
        ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
        if (exitCode != ExitCode.OK)
            return;
        // Open file
        final SiriusExportTask task = new SiriusExportTask(parameters);
        task.runSingleRow(row);
    } catch (Exception e) {
        e.printStackTrace();
        MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error while exporting feature to SIRIUS: " + ExceptionUtils.exceptionToString(e));
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ExitCode(net.sf.mzmine.util.ExitCode)

Example 39 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class SiriusExportModule method exportSingleRows.

public static void exportSingleRows(PeakListRow[] row) {
    try {
        ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(SiriusExportModule.class);
        ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
        if (exitCode != ExitCode.OK)
            return;
        // Open file
        final SiriusExportTask task = new SiriusExportTask(parameters);
        task.runSingleRows(row);
    } catch (Exception e) {
        e.printStackTrace();
        MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "Error while exporting feature to SIRIUS: " + ExceptionUtils.exceptionToString(e));
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ExitCode(net.sf.mzmine.util.ExitCode)

Example 40 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet 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)

Aggregations

ParameterSet (net.sf.mzmine.parameters.ParameterSet)53 ExitCode (net.sf.mzmine.util.ExitCode)19 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)11 File (java.io.File)9 ArrayList (java.util.ArrayList)8 SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)8 Task (net.sf.mzmine.taskcontrol.Task)8 Element (org.w3c.dom.Element)8 PeakList (net.sf.mzmine.datamodel.PeakList)6 MZmineModule (net.sf.mzmine.modules.MZmineModule)6 Document (org.w3c.dom.Document)6 IOException (java.io.IOException)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)5 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)5 Scan (net.sf.mzmine.datamodel.Scan)5 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)5 Nonnull (javax.annotation.Nonnull)4 Feature (net.sf.mzmine.datamodel.Feature)4 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)4 PeakListsParameter (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter)4