Search in sources :

Example 1 with MZmineProject

use of net.sf.mzmine.datamodel.MZmineProject in project mzmine2 by mzmine.

the class ProjectParametersSetupDialog method copyParameterValuesToRawDataFiles.

private void copyParameterValuesToRawDataFiles() {
    MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
    // Remove all previous parameters from project
    UserParameter<?, ?>[] parameters = currentProject.getParameters();
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.removeParameter(parameter);
    }
    // Add new parameters
    parameters = parameterValues.keySet().toArray(new UserParameter[0]);
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.addParameter(parameter);
    }
    // Set values for new parameters
    for (int columnIndex = 0; columnIndex < parameterValues.keySet().size(); columnIndex++) {
        UserParameter<?, ?> parameter = tablemodelParameterValues.getParameter(columnIndex + 1);
        for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
            RawDataFile file = dataFiles[dataFileIndex];
            Object value = tablemodelParameterValues.getValueAt(dataFileIndex, columnIndex + 1);
            if (parameter instanceof DoubleParameter) {
                Double doubleValue = null;
                if (value instanceof Double)
                    doubleValue = (Double) value;
                if (value instanceof String)
                    doubleValue = Double.parseDouble((String) value);
                currentProject.setParameterValue(parameter, file, doubleValue);
            }
            if (parameter instanceof StringParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
            if (parameter instanceof ComboParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
        }
    }
}
Also used : UserParameter(net.sf.mzmine.parameters.UserParameter) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 2 with MZmineProject

use of net.sf.mzmine.datamodel.MZmineProject in project mzmine2 by mzmine.

the class ProjectParametersSetupDialog method copyParameterValuesFromRawDataFiles.

private void copyParameterValuesFromRawDataFiles() {
    MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
    for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
        RawDataFile file = dataFiles[dataFileIndex];
        UserParameter<?, ?>[] parameters = currentProject.getParameters();
        // Loop through all parameters defined for this file
        for (UserParameter<?, ?> p : parameters) {
            // Check if this parameter has been seen before?
            Object[] values;
            if (!(parameterValues.containsKey(p))) {
                // No, initialize a new array of values for this parameter
                values = new Object[dataFiles.length];
                for (int i = 0; i < values.length; i++) values[i] = p.getValue();
                parameterValues.put(p, values);
            } else {
                values = parameterValues.get(p);
            }
            // Set value of this parameter for the current raw data file
            values[dataFileIndex] = currentProject.getParameterValue(p, file);
        }
    }
}
Also used : UserParameter(net.sf.mzmine.parameters.UserParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject)

Example 3 with MZmineProject

use of net.sf.mzmine.datamodel.MZmineProject in project mzmine2 by mzmine.

the class ProjectCloseModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    int selectedValue = JOptionPane.showInternalConfirmDialog(MZmineCore.getDesktop().getMainWindow().getContentPane(), "Are you sure you want to close the current project?", "Close project", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
    if (selectedValue != JOptionPane.YES_OPTION)
        return ExitCode.CANCEL;
    // Close all windows related to previous project
    GUIUtils.closeAllWindows();
    // Create a new, empty project
    MZmineProject newProject = new MZmineProjectImpl();
    // Replace the current project with the new one
    ProjectManager projectManager = MZmineCore.getProjectManager();
    projectManager.setCurrentProject(newProject);
    // Ask the garbage collector to free the previously used memory
    System.gc();
    logger.info("Project closed.");
    return ExitCode.OK;
}
Also used : MZmineProject(net.sf.mzmine.datamodel.MZmineProject) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl) ProjectManager(net.sf.mzmine.project.ProjectManager) Nonnull(javax.annotation.Nonnull)

Example 4 with MZmineProject

use of net.sf.mzmine.datamodel.MZmineProject in project mzmine2 by mzmine.

the class HeatMapParameters method showSetupDialog.

@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
    // Update the parameter choices
    MZmineProject project = MZmineCore.getProjectManager().getCurrentProject();
    UserParameter<?, ?>[] newChoices = project.getParameters();
    getParameter(HeatMapParameters.selectionData).setChoices(newChoices);
    if (newChoices.length > 0) {
        ArrayList<Object> values = new ArrayList<Object>();
        for (RawDataFile dataFile : project.getDataFiles()) {
            Object paramValue = project.getParameterValue(newChoices[0], dataFile);
            if (paramValue == null) {
                continue;
            }
            if (!values.contains(paramValue)) {
                values.add(paramValue);
            }
        }
        Object[] newValues = values.toArray();
        getParameter(HeatMapParameters.referenceGroup).setChoices(newValues);
    }
    HeatmapSetupDialog dialog = new HeatmapSetupDialog(parent, valueCheckRequired, this);
    dialog.setVisible(true);
    return dialog.getExitCode();
}
Also used : UserParameter(net.sf.mzmine.parameters.UserParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayList(java.util.ArrayList) MZmineProject(net.sf.mzmine.datamodel.MZmineProject)

Example 5 with MZmineProject

use of net.sf.mzmine.datamodel.MZmineProject in project mzmine2 by mzmine.

the class ProjectTreeDnDHandler method importData.

public boolean importData(TransferSupport info) {
    if (!info.isDrop()) {
        return false;
    }
    ProjectTree projectTree = (ProjectTree) info.getComponent();
    DefaultTreeModel treeModel = (DefaultTreeModel) projectTree.getModel();
    MZmineProject project = MZmineCore.getProjectManager().getCurrentProject();
    JTree.DropLocation dl = (JTree.DropLocation) info.getDropLocation();
    TreePath dropPath = dl.getPath();
    DefaultMutableTreeNode droppedLocationNode = (DefaultMutableTreeNode) dropPath.getLastPathComponent();
    Object droppedLocationObject = droppedLocationNode.getUserObject();
    int childIndex = dl.getChildIndex();
    TreePath[] transferedPaths = projectTree.getSelectionPaths();
    // Check if the drop target is among the project data files
    if (droppedLocationObject == RawDataTreeModel.dataFilesNodeName) {
        for (TreePath path : transferedPaths) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            int currentIndex = node.getParent().getIndex(node);
            Object transferObject = node.getUserObject();
            if (transferObject instanceof RawDataFile) {
                treeModel.removeNodeFromParent(node);
                if (childIndex > currentIndex)
                    childIndex--;
                treeModel.insertNodeInto(node, droppedLocationNode, childIndex);
                childIndex++;
            }
        }
    }
    // Check if the drop target is AFTER the data files (last position)
    if ((droppedLocationObject == project) && (childIndex == 1)) {
        int numOfFiles = project.getDataFiles().length;
        DefaultMutableTreeNode filesNode = (DefaultMutableTreeNode) droppedLocationNode.getChildAt(0);
        for (TreePath path : transferedPaths) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            Object transferObject = node.getUserObject();
            if (transferObject instanceof RawDataFile) {
                treeModel.removeNodeFromParent(node);
                treeModel.insertNodeInto(node, filesNode, numOfFiles - 1);
            }
        }
    }
    // Check if the drop target is among the project feature lists
    if (droppedLocationObject == PeakListTreeModel.peakListsNodeName) {
        for (TreePath path : transferedPaths) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            int currentIndex = node.getParent().getIndex(node);
            Object transferObject = node.getUserObject();
            if (childIndex > currentIndex)
                childIndex--;
            if (transferObject instanceof PeakList) {
                treeModel.removeNodeFromParent(node);
                treeModel.insertNodeInto(node, droppedLocationNode, childIndex);
                childIndex++;
            }
        }
    }
    // Check if the drop target is AFTER the feature lists (last position)
    if ((droppedLocationObject == project) && (childIndex == 2)) {
        DefaultMutableTreeNode peakListsNode = (DefaultMutableTreeNode) droppedLocationNode.getChildAt(1);
        int numOfPeakLists = project.getPeakLists().length;
        for (TreePath path : transferedPaths) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent();
            Object transferObject = node.getUserObject();
            if (transferObject instanceof PeakList) {
                treeModel.removeNodeFromParent(node);
                treeModel.insertNodeInto(node, peakListsNode, numOfPeakLists - 1);
            }
        }
    }
    return true;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) PeakList(net.sf.mzmine.datamodel.PeakList)

Aggregations

MZmineProject (net.sf.mzmine.datamodel.MZmineProject)11 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)8 PeakList (net.sf.mzmine.datamodel.PeakList)5 UserParameter (net.sf.mzmine.parameters.UserParameter)4 ArrayList (java.util.ArrayList)3 ParameterSet (net.sf.mzmine.parameters.ParameterSet)3 Task (net.sf.mzmine.taskcontrol.Task)3 ExitCode (net.sf.mzmine.util.ExitCode)3 Nonnull (javax.annotation.Nonnull)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 TreePath (javax.swing.tree.TreePath)2 MassList (net.sf.mzmine.datamodel.MassList)2 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)2 Scan (net.sf.mzmine.datamodel.Scan)2 File (java.io.File)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 JFileChooser (javax.swing.JFileChooser)1