Search in sources :

Example 1 with CenterFunction

use of net.sf.mzmine.util.maths.CenterFunction in project mzmine2 by mzmine.

the class CenterMeasureComponent method getSelectedFunction.

public CenterFunction getSelectedFunction() {
    CenterMeasure measure = (CenterMeasure) comboCenterMeasure.getSelectedItem();
    Weighting trans = Weighting.NONE;
    if (comboTransform != null && comboTransform.isVisible())
        trans = (Weighting) comboTransform.getSelectedItem();
    return new CenterFunction(measure, trans);
}
Also used : CenterMeasure(net.sf.mzmine.util.maths.CenterMeasure) Weighting(net.sf.mzmine.util.maths.Weighting) CenterFunction(net.sf.mzmine.util.maths.CenterFunction)

Example 2 with CenterFunction

use of net.sf.mzmine.util.maths.CenterFunction in project mzmine2 by mzmine.

the class CenterMeasureParameter method loadValueFromXML.

@Override
public void loadValueFromXML(Element xmlElement) {
    try {
        CenterMeasure measure = CenterMeasure.valueOf(xmlElement.getAttribute("measure"));
        Weighting weighting = Weighting.valueOf(xmlElement.getAttribute("weighting"));
        value = new CenterFunction(measure, weighting);
    } catch (Exception e) {
        logger.log(Level.WARNING, "center measure cannot be loaded from xml", e);
    }
}
Also used : CenterMeasure(net.sf.mzmine.util.maths.CenterMeasure) Weighting(net.sf.mzmine.util.maths.Weighting) CenterFunction(net.sf.mzmine.util.maths.CenterFunction)

Example 3 with CenterFunction

use of net.sf.mzmine.util.maths.CenterFunction 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)

Example 4 with CenterFunction

use of net.sf.mzmine.util.maths.CenterFunction 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

CenterFunction (net.sf.mzmine.util.maths.CenterFunction)4 CenterMeasure (net.sf.mzmine.util.maths.CenterMeasure)3 Weighting (net.sf.mzmine.util.maths.Weighting)3 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Nonnull (javax.annotation.Nonnull)1 Feature (net.sf.mzmine.datamodel.Feature)1 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)1 PeakList (net.sf.mzmine.datamodel.PeakList)1 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)1 MZmineModuleCategory (net.sf.mzmine.modules.MZmineModuleCategory)1 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)1 PeakDataSet (net.sf.mzmine.modules.visualization.tic.PeakDataSet)1 ParameterSet (net.sf.mzmine.parameters.ParameterSet)1 Task (net.sf.mzmine.taskcontrol.Task)1 ExitCode (net.sf.mzmine.util.ExitCode)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