Search in sources :

Example 1 with PeakDataSet

use of net.sf.mzmine.modules.visualization.tic.PeakDataSet in project mzmine2 by mzmine.

the class ShapeModelerSetupDialog method loadPreviewPeak.

private void loadPreviewPeak() {
    PeakListRow previewRow = (PeakListRow) comboPeak.getSelectedItem();
    if (previewRow == null)
        return;
    logger.finest("Loading new preview peak " + previewRow);
    Feature previewPeak = previewRow.getPeaks()[0];
    ticPlot.removeAllTICDataSets();
    // Load the intensities into array
    RawDataFile dataFile = previewPeak.getDataFile();
    int[] scanNumbers = previewPeak.getScanNumbers();
    double[] retentionTimes = new double[scanNumbers.length];
    for (int i = 0; i < scanNumbers.length; i++) retentionTimes[i] = dataFile.getScan(scanNumbers[i]).getRetentionTime();
    double[] intensities = new double[scanNumbers.length];
    for (int i = 0; i < scanNumbers.length; i++) {
        DataPoint dp = previewPeak.getDataPoint(scanNumbers[i]);
        if (dp != null)
            intensities[i] = dp.getIntensity();
        else
            intensities[i] = 0;
    }
    // Create shape model
    updateParameterSetFromComponents();
    JComboBox<?> component = (JComboBox<?>) getComponentForParameter(ShapeModelerParameters.shapeModelerType);
    ShapeModel model = (ShapeModel) component.getSelectedItem();
    JFormattedTextField resolutionField = (JFormattedTextField) getComponentForParameter(ShapeModelerParameters.massResolution);
    double resolution = ((Number) resolutionField.getValue()).doubleValue();
    try {
        Class<?> shapeModelClass = model.getModelClass();
        Constructor<?> shapeModelConstruct = shapeModelClass.getConstructors()[0];
        // shapePeakModel(ChromatographicPeak originalDetectedShape, int[]
        // scanNumbers,
        // double[] intensities, double[] retentionTimes, double resolution)
        Feature shapePeak = (Feature) shapeModelConstruct.newInstance(previewPeak, scanNumbers, intensities, retentionTimes, resolution);
        PeakDataSet peakDataSet = new PeakDataSet(shapePeak);
        ticPlot.addPeakDataset(peakDataSet);
        ticDataset = new ChromatogramTICDataSet(previewRow.getPeaks()[0]);
        ticPlot.addTICDataset(ticDataset);
        // Set auto range to axes
        ticPlot.getXYPlot().getDomainAxis().setAutoRange(true);
        ticPlot.getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
        ticPlot.getXYPlot().getRangeAxis().setAutoRange(true);
        ticPlot.getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
    } catch (Exception e) {
        String message = "Error trying to make an instance of Peak Builder " + model;
        MZmineCore.getDesktop().displayErrorMessage(this, message);
        logger.severe(message);
        e.printStackTrace();
        return;
    }
}
Also used : PeakDataSet(net.sf.mzmine.modules.visualization.tic.PeakDataSet) JComboBox(javax.swing.JComboBox) JFormattedTextField(javax.swing.JFormattedTextField) ChromatogramTICDataSet(net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ChromatogramTICDataSet) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 2 with PeakDataSet

use of net.sf.mzmine.modules.visualization.tic.PeakDataSet in project mzmine2 by mzmine.

the class PeakResolverSetupDialog method parametersChanged.

@Override
public void parametersChanged() {
    if (preview != null && preview.isSelected()) {
        final PeakListRow previewRow = (PeakListRow) comboPeak.getSelectedItem();
        if (previewRow != null) {
            LOG.finest("Loading new preview peak " + previewRow);
            ticPlot.removeAllTICDataSets();
            ticPlot.addTICDataset(new ChromatogramTICDataSet(previewRow.getPeaks()[0]));
            // Auto-range to axes.
            ticPlot.getXYPlot().getDomainAxis().setAutoRange(true);
            ticPlot.getXYPlot().getDomainAxis().setAutoTickUnitSelection(true);
            ticPlot.getXYPlot().getRangeAxis().setAutoRange(true);
            ticPlot.getXYPlot().getRangeAxis().setAutoTickUnitSelection(true);
            updateParameterSetFromComponents();
            // If there is some illegal value, do not load the preview but
            // just exit.
            ArrayList<String> errors = new ArrayList<String>();
            if (!parameterSet.checkParameterValues(errors)) {
                LOG.fine("Illegal parameter value: " + errors);
                return;
            }
            // Load the intensities and RTs into array.
            final Feature previewPeak = previewRow.getPeaks()[0];
            // Resolve peaks.
            Feature[] resolvedPeaks = {};
            RSessionWrapper rSession;
            try {
                if (peakResolver.getRequiresR()) {
                    // Check R availability, by trying to open the
                    // connection.
                    String[] reqPackages = peakResolver.getRequiredRPackages();
                    String[] reqPackagesVersions = peakResolver.getRequiredRPackagesVersions();
                    String callerFeatureName = peakResolver.getName();
                    REngineType rEngineType = peakResolver.getREngineType(parameters);
                    rSession = new RSessionWrapper(rEngineType, callerFeatureName, reqPackages, reqPackagesVersions);
                    rSession.open();
                } else {
                    rSession = null;
                }
                CenterFunction mzCenterFunction = new CenterFunction(CenterMeasure.MEDIAN);
                // preview doesn't show msms scans
                // set it to be default searching range
                resolvedPeaks = peakResolver.resolvePeaks(previewPeak, parameters, rSession, mzCenterFunction, 0, 0);
                // Turn off R instance.
                if (rSession != null)
                    rSession.close(false);
            } catch (RSessionWrapperException e) {
                throw new IllegalStateException(e.getMessage());
            } catch (Throwable t) {
                LOG.log(Level.SEVERE, "Peak deconvolution error", t);
                MZmineCore.getDesktop().displayErrorMessage(this, t.toString());
            }
            // Add resolved peaks to TIC plot.
            final int peakCount = Math.min(MAX_PEAKS, resolvedPeaks.length);
            for (int i = 0; i < peakCount; i++) {
                final XYDataset peakDataSet = new PeakDataSet(resolvedPeaks[i]);
                ticPlot.addPeakDataset(peakDataSet);
            }
            // Check peak count.
            if (resolvedPeaks.length > MAX_PEAKS) {
                // MZmineCore.getDesktop().displayMessage(this,
                // "Too many peaks detected, please adjust parameter values");
                MZmineCore.getDesktop().displayMessage(this, "Too many peaks detected. Not all of the peaks might be displayed");
            }
        }
    }
}
Also used : PeakDataSet(net.sf.mzmine.modules.visualization.tic.PeakDataSet) RSessionWrapper(net.sf.mzmine.util.R.RSessionWrapper) REngineType(net.sf.mzmine.util.R.REngineType) ArrayList(java.util.ArrayList) Feature(net.sf.mzmine.datamodel.Feature) RSessionWrapperException(net.sf.mzmine.util.R.RSessionWrapperException) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) XYDataset(org.jfree.data.xy.XYDataset) CenterFunction(net.sf.mzmine.util.maths.CenterFunction)

Aggregations

Feature (net.sf.mzmine.datamodel.Feature)2 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)2 PeakDataSet (net.sf.mzmine.modules.visualization.tic.PeakDataSet)2 ArrayList (java.util.ArrayList)1 JComboBox (javax.swing.JComboBox)1 JFormattedTextField (javax.swing.JFormattedTextField)1 DataPoint (net.sf.mzmine.datamodel.DataPoint)1 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)1 ChromatogramTICDataSet (net.sf.mzmine.modules.peaklistmethods.peakpicking.deconvolution.ChromatogramTICDataSet)1 REngineType (net.sf.mzmine.util.R.REngineType)1 RSessionWrapper (net.sf.mzmine.util.R.RSessionWrapper)1 RSessionWrapperException (net.sf.mzmine.util.R.RSessionWrapperException)1 CenterFunction (net.sf.mzmine.util.maths.CenterFunction)1 XYDataset (org.jfree.data.xy.XYDataset)1