Search in sources :

Example 6 with MSDKRuntimeException

use of io.github.msdk.MSDKRuntimeException in project mzmine2 by mzmine.

the class RawFileMergeTask method run.

@Override
public void run() {
    try {
        setStatus(TaskStatus.PROCESSING);
        // total number of scans
        StringBuilder s = new StringBuilder();
        s.append("Merge files: ");
        for (RawDataFile r : raw) {
            s.append(r.getName());
            s.append(", ");
        }
        LOG.info(s.toString());
        // put all in a list and sort by rt
        List<Scan> scans = new ArrayList<>();
        for (RawDataFile r : raw) {
            // some files are only for MS2
            boolean isMS2Only = useMS2Marker && r.getName().contains(ms2Marker);
            int[] snarray = r.getScanNumbers();
            for (int sn : snarray) {
                if (isCanceled())
                    return;
                Scan scan = r.getScan(sn);
                if (!isMS2Only || scan.getMSLevel() > 1) {
                    scans.add(scan);
                }
            }
        }
        // sort by rt
        scans.sort(new Comparator<Scan>() {

            @Override
            public int compare(Scan a, Scan b) {
                return Double.compare(a.getRetentionTime(), b.getRetentionTime());
            }
        });
        // create new file
        RawDataFileWriter rawDataFileWriter = MZmineCore.createNewFile(raw[0].getName() + " " + suffix);
        int i = 0;
        for (Scan scan : scans) {
            if (isCanceled())
                return;
            // copy, reset scan number
            SimpleScan scanCopy = new SimpleScan(scan);
            scanCopy.setScanNumber(i);
            rawDataFileWriter.addScan(scanCopy);
            i++;
        }
        RawDataFile filteredRawDataFile = rawDataFileWriter.finishWriting();
        project.addFile(filteredRawDataFile);
        if (getStatus() == TaskStatus.PROCESSING)
            setStatus(TaskStatus.FINISHED);
    } catch (IOException e) {
        throw new MSDKRuntimeException(e);
    }
}
Also used : ArrayList(java.util.ArrayList) RawDataFileWriter(net.sf.mzmine.datamodel.RawDataFileWriter) IOException(java.io.IOException) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) Scan(net.sf.mzmine.datamodel.Scan) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan)

Example 7 with MSDKRuntimeException

use of io.github.msdk.MSDKRuntimeException in project mzmine2 by mzmine.

the class GnpsFbmnExportAndSubmitTask method run.

@Override
public void run() {
    final AbstractTask thistask = this;
    setStatus(TaskStatus.PROCESSING);
    boolean openFolder = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.OPEN_FOLDER).getValue();
    boolean submit = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.SUBMIT).getValue();
    File file = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.FILENAME).getValue();
    file = FileAndPathUtil.eraseFormat(file);
    parameters.getParameter(GnpsFbmnExportAndSubmitParameters.FILENAME).setValue(file);
    List<AbstractTask> list = new ArrayList<>(3);
    GnpsFbmnMgfExportTask task = new GnpsFbmnMgfExportTask(parameters);
    list.add(task);
    // add csv quant table
    list.add(addQuantTableTask(parameters, null));
    // finish listener to submit
    final File fileName = file;
    final File folder = file.getParentFile();
    new AllTasksFinishedListener(list, true, // succeed
    l -> {
        try {
            LOG.info("succeed" + thistask.getStatus().toString());
            if (submit) {
                GnpsFbmnSubmitParameters param = parameters.getParameter(GnpsFbmnExportAndSubmitParameters.SUBMIT).getEmbeddedParameters();
                submit(fileName, param);
            }
            // open folder
            try {
                if (openFolder && Desktop.isDesktopSupported()) {
                    Desktop.getDesktop().open(folder);
                }
            } catch (Exception ex) {
            }
        } finally {
            // finish task
            if (thistask.getStatus() == TaskStatus.PROCESSING)
                thistask.setStatus(TaskStatus.FINISHED);
        }
    }, lerror -> {
        setErrorMessage("GNPS submit was not started due too errors while file export");
        thistask.setStatus(TaskStatus.ERROR);
        throw new MSDKRuntimeException("GNPS submit was not started due too errors while file export");
    }, // cancel if one was cancelled
    listCancelled -> cancel()) {

        @Override
        public void taskStatusChanged(Task task, TaskStatus newStatus, TaskStatus oldStatus) {
            super.taskStatusChanged(task, newStatus, oldStatus);
            // show progress
            progress.getAndSet(getProgress());
        }
    };
    MZmineCore.getTaskController().addTasks(list.toArray(new AbstractTask[list.size()]));
    // wait till finish
    while (!(isCanceled() || isFinished())) {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            LOG.log(Level.SEVERE, "Error in GNPS export/submit task", e);
        }
    }
}
Also used : CSVExportTask(net.sf.mzmine.modules.peaklistmethods.io.csvexport.CSVExportTask) Task(net.sf.mzmine.taskcontrol.Task) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) ArrayList(java.util.ArrayList) AllTasksFinishedListener(net.sf.mzmine.taskcontrol.AllTasksFinishedListener) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) File(java.io.File)

Example 8 with MSDKRuntimeException

use of io.github.msdk.MSDKRuntimeException in project mzmine2 by mzmine.

the class SortPeakListsModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    List<PeakList> peakLists = Arrays.asList(parameters.getParameter(SortPeakListsParameters.peakLists).getValue().getMatchingPeakLists());
    PeakListTreeModel model = null;
    if (project instanceof MZmineProjectImpl) {
        model = ((MZmineProjectImpl) project).getPeakListTreeModel();
    } else if (MZmineCore.getDesktop() instanceof MainWindow) {
        ProjectTree tree = ((MainWindow) MZmineCore.getDesktop()).getMainPanel().getPeakListTree();
        model = (PeakListTreeModel) tree.getModel();
    }
    if (model == null)
        throw new MSDKRuntimeException("Cannot find feature list tree model for sorting. Different MZmine project impl?");
    final DefaultMutableTreeNode rootNode = model.getRoot();
    // Get all tree nodes that represent selected feature lists, and remove
    // them from
    final ArrayList<DefaultMutableTreeNode> selectedNodes = new ArrayList<DefaultMutableTreeNode>();
    for (int row = 0; row < rootNode.getChildCount(); row++) {
        DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) rootNode.getChildAt(row);
        Object selectedObject = selectedNode.getUserObject();
        if (peakLists.contains(selectedObject)) {
            selectedNodes.add(selectedNode);
        }
    }
    // Get the index of the first selected item
    final ArrayList<Integer> positions = new ArrayList<Integer>();
    for (DefaultMutableTreeNode node : selectedNodes) {
        int nodeIndex = rootNode.getIndex(node);
        if (nodeIndex != -1)
            positions.add(nodeIndex);
    }
    if (positions.isEmpty())
        return ExitCode.ERROR;
    int insertPosition = Collections.min(positions);
    // Sort the feature lists by name
    Collections.sort(selectedNodes, new Comparator<DefaultMutableTreeNode>() {

        @Override
        public int compare(DefaultMutableTreeNode o1, DefaultMutableTreeNode o2) {
            return o1.getUserObject().toString().compareTo(o2.getUserObject().toString());
        }
    });
    // Reorder the nodes in the tree model
    for (DefaultMutableTreeNode node : selectedNodes) {
        model.removeNodeFromParent(node);
        model.insertNodeInto(node, rootNode, insertPosition);
        insertPosition++;
    }
    return ExitCode.OK;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ArrayList(java.util.ArrayList) ProjectTree(net.sf.mzmine.desktop.impl.projecttree.ProjectTree) PeakListTreeModel(net.sf.mzmine.desktop.impl.projecttree.PeakListTreeModel) MainWindow(net.sf.mzmine.desktop.impl.MainWindow) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) PeakList(net.sf.mzmine.datamodel.PeakList) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl) Nonnull(javax.annotation.Nonnull)

Example 9 with MSDKRuntimeException

use of io.github.msdk.MSDKRuntimeException 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)

Aggregations

MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)9 ArrayList (java.util.ArrayList)5 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)4 File (java.io.File)3 Nonnull (javax.annotation.Nonnull)3 AbstractTask (net.sf.mzmine.taskcontrol.AbstractTask)3 Task (net.sf.mzmine.taskcontrol.Task)3 TaskStatus (net.sf.mzmine.taskcontrol.TaskStatus)3 IOException (java.io.IOException)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DataPoint (net.sf.mzmine.datamodel.DataPoint)2 Scan (net.sf.mzmine.datamodel.Scan)2 MainWindow (net.sf.mzmine.desktop.impl.MainWindow)2 ProjectTree (net.sf.mzmine.desktop.impl.projecttree.ProjectTree)2 CSVExportTask (net.sf.mzmine.modules.peaklistmethods.io.csvexport.CSVExportTask)2 MZmineProjectImpl (net.sf.mzmine.project.impl.MZmineProjectImpl)2 AllTasksFinishedListener (net.sf.mzmine.taskcontrol.AllTasksFinishedListener)2 Range (com.google.common.collect.Range)1 DoubleArrayList (it.unimi.dsi.fastutil.doubles.DoubleArrayList)1 Arrays (java.util.Arrays)1