Search in sources :

Example 1 with RawDataTreeModel

use of net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel in project mzmine2 by mzmine.

the class StorableScan method removeMassList.

@Override
public synchronized void removeMassList(@Nonnull final MassList massList) {
    // Remove the mass list
    massLists.remove(massList);
    if (massList instanceof StorableMassList) {
        StorableMassList storableMassList = (StorableMassList) massList;
        storableMassList.removeStoredData();
    }
    // Remove from the tree model
    MZmineProjectImpl project = (MZmineProjectImpl) MZmineCore.getProjectManager().getCurrentProject();
    // Check if we are using the current project
    if (Arrays.asList(project.getDataFiles()).contains(rawDataFile)) {
        final RawDataTreeModel treeModel = project.getRawDataTreeModel();
        Runnable swingCode = new Runnable() {

            @Override
            public void run() {
                treeModel.removeObject(massList);
            }
        };
        SwingUtilities.invokeLater(swingCode);
    }
}
Also used : RawDataTreeModel(net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel)

Example 2 with RawDataTreeModel

use of net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel in project mzmine2 by mzmine.

the class MassDetectionTask method run.

/**
 * @see Runnable#run()
 */
public void run() {
    // make arrays to contain everything you need
    ArrayList<Integer> pointsInScans = new ArrayList<>();
    ArrayList<Double> allMZ = new ArrayList<>();
    ArrayList<Double> allIntensities = new ArrayList<>();
    // idecies of full mass list where scan starts?
    ArrayList<Integer> startIndex = new ArrayList<>();
    ArrayList<Double> scanAcquisitionTime = new ArrayList<>();
    // XCMS needs this one
    ArrayList<Double> totalIntensity = new ArrayList<>();
    double curTotalIntensity;
    int lastPointCount = 0;
    startIndex.add(0);
    try {
        setStatus(TaskStatus.PROCESSING);
        logger.info("Started mass detector on " + dataFile);
        final Scan[] scans = scanSelection.getMatchingScans(dataFile);
        totalScans = scans.length;
        // Process scans one by one
        for (Scan scan : scans) {
            if (isCanceled())
                return;
            MassDetector detector = massDetector.getModule();
            DataPoint[] mzPeaks = detector.getMassValues(scan, massDetector.getParameterSet());
            SimpleMassList newMassList = new SimpleMassList(name, scan, mzPeaks);
            // Add new mass list to the scan
            scan.addMassList(newMassList);
            if (this.saveToCDF) {
                curTotalIntensity = 0;
                for (int a = 0; a < mzPeaks.length; a++) {
                    DataPoint curMzPeak = mzPeaks[a];
                    allMZ.add(curMzPeak.getMZ());
                    allIntensities.add(curMzPeak.getIntensity());
                    curTotalIntensity += curMzPeak.getIntensity();
                }
                scanAcquisitionTime.add(scan.getRetentionTime());
                pointsInScans.add(0);
                startIndex.add(mzPeaks.length + lastPointCount);
                totalIntensity.add(curTotalIntensity);
                lastPointCount = mzPeaks.length + lastPointCount;
            }
            processedScans++;
        }
        // Update the GUI with all new mass lists
        MZmineProjectImpl project = (MZmineProjectImpl) MZmineCore.getProjectManager().getCurrentProject();
        final RawDataTreeModel treeModel = project.getRawDataTreeModel();
        treeModel.updateGUIWithNewObjects();
        ;
        if (this.saveToCDF) {
            // ************** write mass list *******************************
            final String outFileNamePath = outFilename.getPath();
            logger.info("Saving mass detector results to netCDF file " + outFileNamePath);
            NetcdfFileWriter writer = NetcdfFileWriter.createNew(NetcdfFileWriter.Version.netcdf3, outFileNamePath, null);
            Dimension dim_massValues = writer.addDimension(null, "mass_values", allMZ.size());
            Dimension dim_intensityValues = writer.addDimension(null, "intensity_values", allIntensities.size());
            Dimension dim_scanIndex = writer.addDimension(null, "scan_index", startIndex.size() - 1);
            Dimension dim_scanAcquisitionTime = writer.addDimension(null, "scan_acquisition_time", scanAcquisitionTime.size());
            Dimension dim_totalIntensity = writer.addDimension(null, "total_intensity", totalIntensity.size());
            Dimension dim_pointsInScans = writer.addDimension(null, "point_count", pointsInScans.size());
            // add dimensions to list
            List<Dimension> dims = new ArrayList<>();
            dims.add(dim_massValues);
            dims.add(dim_intensityValues);
            dims.add(dim_scanIndex);
            dims.add(dim_scanAcquisitionTime);
            dims.add(dim_totalIntensity);
            dims.add(dim_pointsInScans);
            // make the variables that contain the actual data I think.
            Variable var_massValues = writer.addVariable(null, "mass_values", DataType.DOUBLE, "mass_values");
            Variable var_intensityValues = writer.addVariable(null, "intensity_values", DataType.DOUBLE, "intensity_values");
            Variable var_scanIndex = writer.addVariable(null, "scan_index", DataType.INT, "scan_index");
            Variable var_scanAcquisitionTime = writer.addVariable(null, "scan_acquisition_time", DataType.DOUBLE, "scan_acquisition_time");
            Variable var_totalIntensity = writer.addVariable(null, "total_intensity", DataType.DOUBLE, "total_intensity");
            Variable var_pointsInScans = writer.addVariable(null, "point_count", DataType.INT, "point_count");
            var_massValues.addAttribute(new Attribute("units", "M/Z"));
            var_intensityValues.addAttribute(new Attribute("units", "Arbitrary Intensity Units"));
            var_scanIndex.addAttribute(new Attribute("units", "index"));
            var_scanAcquisitionTime.addAttribute(new Attribute("units", "seconds"));
            var_totalIntensity.addAttribute(new Attribute("units", "Arbitrary Intensity Units"));
            var_pointsInScans.addAttribute(new Attribute("units", "count"));
            var_massValues.addAttribute(new Attribute("scale_factor", 1.0));
            var_intensityValues.addAttribute(new Attribute("scale_factor", 1.0));
            var_scanIndex.addAttribute(new Attribute("scale_factor", 1.0));
            var_scanAcquisitionTime.addAttribute(new Attribute("scale_factor", 1.0));
            var_totalIntensity.addAttribute(new Attribute("scale_factor", 1.0));
            var_pointsInScans.addAttribute(new Attribute("scale_factor", 1.0));
            // create file
            writer.create();
            ArrayDouble.D1 arr_massValues = new ArrayDouble.D1(dim_massValues.getLength());
            ArrayDouble.D1 arr_intensityValues = new ArrayDouble.D1(dim_intensityValues.getLength());
            ArrayDouble.D1 arr_scanIndex = new ArrayDouble.D1(dim_scanIndex.getLength());
            ArrayDouble.D1 arr_scanAcquisitionTime = new ArrayDouble.D1(dim_scanAcquisitionTime.getLength());
            ArrayDouble.D1 arr_totalIntensity = new ArrayDouble.D1(dim_totalIntensity.getLength());
            ArrayDouble.D1 arr_pointsInScans = new ArrayDouble.D1(dim_pointsInScans.getLength());
            for (int i = 0; i < allMZ.size(); i++) {
                arr_massValues.set(i, allMZ.get(i));
                arr_intensityValues.set(i, allIntensities.get(i));
            }
            int i = 0;
            for (; i < scanAcquisitionTime.size(); i++) {
                arr_scanAcquisitionTime.set(i, scanAcquisitionTime.get(i) * 60);
                arr_pointsInScans.set(i, pointsInScans.get(i));
                arr_scanIndex.set(i, startIndex.get(i));
                arr_totalIntensity.set(i, totalIntensity.get(i));
            }
            // arr_scanIndex.set(i,startIndex.get(i));
            // For tiny test file
            // arr_intensityValues .set(0,200);
            // arr_scanIndex .set(0,0);
            // arr_scanAcquisitionTime .set(0,10);
            // arr_totalIntensity .set(0,200);
            // arr_pointsInScans .set(0,0);
            // arr_intensityValues .set(1,300);
            // arr_scanIndex .set(1,1);
            // arr_scanAcquisitionTime .set(1,20);
            // arr_totalIntensity .set(1,300);
            // arr_pointsInScans .set(1,0);
            writer.write(var_massValues, arr_massValues);
            writer.write(var_intensityValues, arr_intensityValues);
            writer.write(var_scanIndex, arr_scanIndex);
            writer.write(var_scanAcquisitionTime, arr_scanAcquisitionTime);
            writer.write(var_totalIntensity, arr_totalIntensity);
            writer.write(var_pointsInScans, arr_pointsInScans);
            writer.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
        setErrorMessage(e.getMessage());
        setStatus(TaskStatus.ERROR);
    }
    setStatus(TaskStatus.FINISHED);
    logger.info("Finished mass detector on " + dataFile);
}
Also used : Variable(ucar.nc2.Variable) Attribute(ucar.nc2.Attribute) ArrayList(java.util.ArrayList) DataPoint(net.sf.mzmine.datamodel.DataPoint) ArrayDouble(ucar.ma2.ArrayDouble) RawDataTreeModel(net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel) SimpleMassList(net.sf.mzmine.datamodel.impl.SimpleMassList) Dimension(ucar.nc2.Dimension) ArrayDouble(ucar.ma2.ArrayDouble) DataPoint(net.sf.mzmine.datamodel.DataPoint) NetcdfFileWriter(ucar.nc2.NetcdfFileWriter) Scan(net.sf.mzmine.datamodel.Scan) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl)

Example 3 with RawDataTreeModel

use of net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel in project mzmine2 by mzmine.

the class SortDataFilesModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    List<RawDataFile> dataFiles = Arrays.asList(parameters.getParameter(SortDataFilesParameters.dataFiles).getValue().getMatchingRawDataFiles());
    RawDataTreeModel model = null;
    if (project instanceof MZmineProjectImpl) {
        model = ((MZmineProjectImpl) project).getRawDataTreeModel();
    } else if (MZmineCore.getDesktop() instanceof MainWindow) {
        ProjectTree tree = ((MainWindow) MZmineCore.getDesktop()).getMainPanel().getRawDataTree();
        model = (RawDataTreeModel) tree.getModel();
    }
    if (model == null)
        throw new MSDKRuntimeException("Cannot find raw data file tree model for sorting. Different MZmine project impl?");
    final DefaultMutableTreeNode rootNode = model.getRoot();
    // Get all tree nodes that represent selected data files, 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 (dataFiles.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 data files 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) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MainWindow(net.sf.mzmine.desktop.impl.MainWindow) MSDKRuntimeException(io.github.msdk.MSDKRuntimeException) RawDataTreeModel(net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel) MZmineProjectImpl(net.sf.mzmine.project.impl.MZmineProjectImpl) Nonnull(javax.annotation.Nonnull)

Example 4 with RawDataTreeModel

use of net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel in project mzmine2 by mzmine.

the class StorableScan method addMassList.

@Override
public synchronized void addMassList(@Nonnull final MassList massList) {
    // Remove all mass lists with same name, if there are any
    MassList[] currentMassLists = massLists.toArray(new MassList[0]);
    for (MassList ml : currentMassLists) {
        if (ml.getName().equals(massList.getName()))
            removeMassList(ml);
    }
    StorableMassList storedMassList;
    if (massList instanceof StorableMassList) {
        storedMassList = (StorableMassList) massList;
    } else {
        DataPoint[] massListDataPoints = massList.getDataPoints();
        try {
            int mlStorageID = rawDataFile.storeDataPoints(massListDataPoints);
            storedMassList = new StorableMassList(rawDataFile, mlStorageID, massList.getName(), this);
        } catch (IOException e) {
            logger.severe("Could not write data to temporary file " + e.toString());
            return;
        }
    }
    // Add the new mass list
    massLists.add(storedMassList);
    // Add the mass list to the tree model
    MZmineProjectImpl project = (MZmineProjectImpl) MZmineCore.getProjectManager().getCurrentProject();
    // Check if we are adding to the current project
    if (Arrays.asList(project.getDataFiles()).contains(rawDataFile)) {
        final RawDataTreeModel treeModel = project.getRawDataTreeModel();
        treeModel.addObjectWithoutGUIUpdate(storedMassList);
    }
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) RawDataTreeModel(net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel) IOException(java.io.IOException) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Aggregations

RawDataTreeModel (net.sf.mzmine.desktop.impl.projecttree.RawDataTreeModel)4 ArrayList (java.util.ArrayList)2 DataPoint (net.sf.mzmine.datamodel.DataPoint)2 MZmineProjectImpl (net.sf.mzmine.project.impl.MZmineProjectImpl)2 MSDKRuntimeException (io.github.msdk.MSDKRuntimeException)1 IOException (java.io.IOException)1 Nonnull (javax.annotation.Nonnull)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 MassList (net.sf.mzmine.datamodel.MassList)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 Scan (net.sf.mzmine.datamodel.Scan)1 SimpleMassList (net.sf.mzmine.datamodel.impl.SimpleMassList)1 MainWindow (net.sf.mzmine.desktop.impl.MainWindow)1 ProjectTree (net.sf.mzmine.desktop.impl.projecttree.ProjectTree)1 ArrayDouble (ucar.ma2.ArrayDouble)1 Attribute (ucar.nc2.Attribute)1 Dimension (ucar.nc2.Dimension)1 NetcdfFileWriter (ucar.nc2.NetcdfFileWriter)1 Variable (ucar.nc2.Variable)1