Search in sources :

Example 41 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class DeconvolutionTask method resolvePeaks.

/**
 * Deconvolve a chromatogram into separate peaks.
 *
 * @param peakList holds the chromatogram to deconvolve.
 * @param mzCenterFunction2
 * @return a new feature list holding the resolved peaks.
 * @throws RSessionWrapperException
 */
private PeakList resolvePeaks(final PeakList peakList, RSessionWrapper rSession) throws RSessionWrapperException {
    // Get data file information.
    final RawDataFile dataFile = peakList.getRawDataFile(0);
    // Peak resolver.
    final MZmineProcessingStep<PeakResolver> resolver = parameters.getParameter(PEAK_RESOLVER).getValue();
    // set msms pairing range
    this.setMSMSRange = parameters.getParameter(mzRangeMSMS).getValue();
    if (setMSMSRange)
        this.msmsRange = parameters.getParameter(mzRangeMSMS).getEmbeddedParameter().getValue();
    else
        this.msmsRange = 0;
    this.setMSMSRT = parameters.getParameter(RetentionTimeMSMS).getValue();
    if (setMSMSRT)
        this.RTRangeMSMS = parameters.getParameter(RetentionTimeMSMS).getEmbeddedParameter().getValue();
    else
        this.RTRangeMSMS = 0;
    // Create new feature list.
    final PeakList resolvedPeaks = new SimplePeakList(peakList + " " + parameters.getParameter(SUFFIX).getValue(), dataFile);
    // Load previous applied methods.
    for (final PeakListAppliedMethod method : peakList.getAppliedMethods()) {
        resolvedPeaks.addDescriptionOfAppliedTask(method);
    }
    // Add task description to feature list.
    resolvedPeaks.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Peak deconvolution by " + resolver, resolver.getParameterSet()));
    // Initialise counters.
    processedRows = 0;
    totalRows = peakList.getNumberOfRows();
    int peakId = 1;
    // Process each chromatogram.
    final PeakListRow[] peakListRows = peakList.getRows();
    final int chromatogramCount = peakListRows.length;
    for (int index = 0; !isCanceled() && index < chromatogramCount; index++) {
        final PeakListRow currentRow = peakListRows[index];
        final Feature chromatogram = currentRow.getPeak(dataFile);
        // Resolve peaks.
        final PeakResolver resolverModule = resolver.getModule();
        final ParameterSet resolverParams = resolver.getParameterSet();
        final ResolvedPeak[] peaks = resolverModule.resolvePeaks(chromatogram, resolverParams, rSession, mzCenterFunction, msmsRange, RTRangeMSMS);
        // Add peaks to the new feature list.
        for (final ResolvedPeak peak : peaks) {
            peak.setParentChromatogramRowID(currentRow.getID());
            final PeakListRow newRow = new SimplePeakListRow(peakId++);
            newRow.addPeak(dataFile, peak);
            newRow.setPeakInformation(peak.getPeakInformation());
            resolvedPeaks.addRow(newRow);
        }
        processedRows++;
    }
    return resolvedPeaks;
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) PeakListAppliedMethod(net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) Feature(net.sf.mzmine.datamodel.Feature) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 42 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class MsMsSpectraMergeModule method mergeAcrossFragmentSpectra.

/**
 * Internal method that merges a list of spectra into one.
 *
 * @param fragmentMergedSpectra list of spectra with meta information
 * @return merged spectrum
 */
protected MergedSpectrum mergeAcrossFragmentSpectra(ParameterSet parameters, List<MergedSpectrum> fragmentMergedSpectra) {
    if (fragmentMergedSpectra.isEmpty())
        return MergedSpectrum.empty();
    int totalNumberOfScans = 0;
    for (MergedSpectrum s : fragmentMergedSpectra) totalNumberOfScans += s.totalNumberOfScans();
    final double[] scores = new double[fragmentMergedSpectra.size()];
    for (int k = 0; k < fragmentMergedSpectra.size(); ++k) {
        scores[k] = fragmentMergedSpectra.get(k).bestFragmentScanScore;
    }
    int scansRemovedDueToLowQuality = 0;
    final double bestScore = Arrays.stream(scores).max().getAsDouble();
    // only pick fragment scans with decent quality
    final List<MergedSpectrum> selectedScans = new ArrayList<>();
    MergedSpectrum bestOne = null;
    for (int k = 0; k < fragmentMergedSpectra.size(); ++k) {
        if (scores[k] >= bestScore / 5d) {
            if (scores[k] >= bestScore)
                bestOne = fragmentMergedSpectra.get(k);
            selectedScans.add(fragmentMergedSpectra.get(k));
        } else {
            scansRemovedDueToLowQuality += fragmentMergedSpectra.get(k).totalNumberOfScans();
        }
    }
    Collections.sort(selectedScans, Comparator.comparingInt(u -> u.scanIds[0]));
    int bestIndex = 0;
    for (int k = 0; k < selectedScans.size(); ++k) {
        if (selectedScans.get(k) == bestOne)
            bestIndex = k;
    }
    final List<MergedSpectrum> toMerge = new ArrayList<>();
    toMerge.add(bestOne);
    for (int i = 1; i < selectedScans.size(); ++i) {
        int k = bestIndex - i;
        if (k >= 0)
            toMerge.add(selectedScans.get(k));
        k = bestIndex + i;
        if (k < selectedScans.size())
            toMerge.add(selectedScans.get(k));
    }
    if (toMerge.size() == 1) {
        toMerge.get(0).removedScansByLowQuality = scansRemovedDueToLowQuality;
        return toMerge.get(0);
    }
    /*
     * merge every scan if its cosine is above the cosine threshold
     */
    final double cosineThreshold = parameters.getParameter(MsMsSpectraMergeParameters.COSINE_PARAMETER).getValue();
    final MZTolerance massTolerance = parameters.getParameter(MsMsSpectraMergeParameters.MASS_ACCURACY).getValue();
    final MzMergeMode mzMergeMode = parameters.getParameter(MsMsSpectraMergeParameters.MZ_MERGE_MODE).getValue();
    final IntensityMergeMode intensityMergeMode = parameters.getParameter(MsMsSpectraMergeParameters.INTENSITY_MERGE_MODE).getValue();
    MergedSpectrum initial = bestOne;
    final double lowestMassToConsider = Math.min(50d, initial.precursorMz - 50d);
    final DataPoint[] initialMostIntense = ScanUtils.extractMostIntensePeaksAcrossMassRange(initial.data, Range.closed(lowestMassToConsider, lowestMassToConsider + 100), 6);
    final Range<Double> cosineRange = Range.closed(lowestMassToConsider, initial.precursorMz - 20);
    double lowestIntensityToConsider;
    {
        Optional<MergedDataPoint> max = Arrays.stream(initial.data).filter(x -> cosineRange.contains(x.getMZ())).max(Comparator.comparingDouble(u -> u.intensity));
        if (!max.isPresent()) {
            // no peak beside precursor ion
            return MergedSpectrum.empty(totalNumberOfScans);
        }
        MergedDataPoint basePeak = max.get();
        lowestIntensityToConsider = basePeak.sources[0].getIntensity();
        for (DataPoint p : basePeak.sources) {
            lowestIntensityToConsider = Math.max(p.getIntensity(), lowestIntensityToConsider);
        }
        lowestIntensityToConsider = lowestIntensityToConsider * 0.01;
    }
    final double initialCosine = ScanUtils.probabilityProductUnnormalized(initialMostIntense, initialMostIntense, massTolerance, lowestIntensityToConsider, cosineRange);
    for (int k = 1; k < toMerge.size(); ++k) {
        MergedSpectrum scan = toMerge.get(k);
        DataPoint[] dataPoints = scan.data;
        final DataPoint[] mostIntense = ScanUtils.extractMostIntensePeaksAcrossMassRange(dataPoints, Range.closed(50d, 150d), 6);
        final double norm = ScanUtils.probabilityProductUnnormalized(mostIntense, mostIntense, massTolerance, lowestIntensityToConsider, cosineRange);
        final double cosine = ScanUtils.probabilityProductUnnormalized(initialMostIntense, mostIntense, massTolerance, lowestIntensityToConsider, cosineRange) / Math.sqrt(norm * initialCosine);
        if (cosine >= cosineThreshold) {
            initial = merge(initial, scan, mzMergeMode, intensityMergeMode, massTolerance);
        } else {
            initial.removedScansByLowCosine += scan.totalNumberOfScans();
        }
    }
    initial.removedScansByLowQuality = scansRemovedDueToLowQuality;
    return initial;
}
Also used : Scan(net.sf.mzmine.datamodel.Scan) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Range(com.google.common.collect.Range) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Collectors(java.util.stream.Collectors) DataPoint(net.sf.mzmine.datamodel.DataPoint) ArrayList(java.util.ArrayList) MassList(net.sf.mzmine.datamodel.MassList) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) ScanUtils(net.sf.mzmine.util.scans.ScanUtils) HashSet(java.util.HashSet) List(java.util.List) Feature(net.sf.mzmine.datamodel.Feature) MZmineModule(net.sf.mzmine.modules.MZmineModule) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Optional(java.util.Optional) Comparator(java.util.Comparator) Erf(org.apache.commons.math3.special.Erf) Collections(java.util.Collections) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) Optional(java.util.Optional) ArrayList(java.util.ArrayList) DataPoint(net.sf.mzmine.datamodel.DataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 43 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class MzRangeFormulaCalculatorModule method showRangeCalculationDialog.

/**
 * Shows the calculation dialog and returns the calculated m/z range. May return null in case user
 * clicked Cancel.
 */
@Nullable
public static Range<Double> showRangeCalculationDialog() {
    ParameterSet myParameters = MZmineCore.getConfiguration().getModuleParameters(MzRangeFormulaCalculatorModule.class);
    if (myParameters == null)
        return null;
    ExitCode exitCode = myParameters.showSetupDialog(null, true);
    if (exitCode != ExitCode.OK)
        return null;
    return getMzRangeFromFormula(myParameters);
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ExitCode(net.sf.mzmine.util.ExitCode) Nullable(javax.annotation.Nullable)

Example 44 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class MsMsVisualizerWindow method actionPerformed.

/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (command.equals("SHOW_SPECTRUM")) {
        CursorPosition pos = getCursorPosition();
        if (pos != null) {
            SpectraVisualizerModule.showNewSpectrumWindow(pos.getDataFile(), pos.getScanNumber());
        }
    }
    if (command.equals("SETUP_AXES")) {
        AxesSetupDialog dialog = new AxesSetupDialog(this, IDAPlot.getXYPlot());
        dialog.setVisible(true);
    }
    if (command.equals("SHOW_DATA_POINTS")) {
        IDAPlot.switchDataPointsVisible();
    }
    if (command.equals("SWITCH_TOOLTIPS")) {
        if (tooltipMode) {
            IDAPlot.showPeaksTooltips(false);
            toolBar.setTooltipButton(false);
            tooltipMode = false;
        } else {
            IDAPlot.showPeaksTooltips(true);
            toolBar.setTooltipButton(true);
            tooltipMode = true;
        }
    }
    if (command.equals("FIND_SPECTRA")) {
        // Parameters
        final DoubleParameter inputMZ = new DoubleParameter("Ion m/z", "m/z value of ion to search for.");
        final MZToleranceParameter inputMZTolerance = new MZToleranceParameter();
        final DoubleParameter inputIntensity = new DoubleParameter("Min. ion intensity", "Only ions with intensities above this value will be searched for.");
        final BooleanParameter inputNL = new BooleanParameter("Neutral Loss", "If selected, the ion to be searched for will be a neutral loss ion.\nIn this case, only ions above the min. intensity will be examined.", false);
        final ComboParameter<Colors> inputColors = new ComboParameter<Colors>("Color", "The color which the data points will be marked with.", Colors.values());
        Parameter<?>[] parameters = new Parameter<?>[5];
        parameters[0] = inputMZ;
        parameters[1] = inputMZTolerance;
        parameters[2] = inputIntensity;
        parameters[3] = inputNL;
        parameters[4] = inputColors;
        final ParameterSet parametersSearch = new SimpleParameterSet(parameters);
        ExitCode exitCode = parametersSearch.showSetupDialog(this, true);
        if (exitCode != ExitCode.OK)
            return;
        double searchMZ = parametersSearch.getParameter(inputMZ).getValue();
        MZTolerance searchMZTolerance = parametersSearch.getParameter(inputMZTolerance).getValue();
        double minIntensity = parametersSearch.getParameter(inputIntensity).getValue();
        boolean neutralLoss = parametersSearch.getParameter(inputNL).getValue();
        Color highligtColor = Color.red;
        ;
        if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.green)) {
            highligtColor = Color.green;
        }
        if (parametersSearch.getParameter(inputColors).getValue().equals(Colors.blue)) {
            highligtColor = Color.blue;
        }
        // Find and highlight spectra with specific ion
        dataset.highlightSpectra(searchMZ, searchMZTolerance, minIntensity, neutralLoss, highligtColor);
        // Add legend entry
        LegendItemCollection chartLegend = IDAPlot.getXYPlot().getLegendItems();
        chartLegend.add(new LegendItem("Ion: " + searchMZ, "", "MS/MS spectra which contain the " + searchMZ + " ion\nTolerance: " + searchMZTolerance.toString() + "\nMin intensity: " + minIntensity, "", new Ellipse2D.Double(0, 0, 7, 7), highligtColor));
        IDAPlot.getXYPlot().setFixedLegendItems(chartLegend);
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) MZToleranceParameter(net.sf.mzmine.parameters.parametertypes.tolerances.MZToleranceParameter) SimpleParameterSet(net.sf.mzmine.parameters.impl.SimpleParameterSet) LegendItemCollection(org.jfree.chart.LegendItemCollection) ExitCode(net.sf.mzmine.util.ExitCode) Color(java.awt.Color) BooleanParameter(net.sf.mzmine.parameters.parametertypes.BooleanParameter) AxesSetupDialog(net.sf.mzmine.util.dialogs.AxesSetupDialog) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) LegendItem(org.jfree.chart.LegendItem) Parameter(net.sf.mzmine.parameters.Parameter) WindowSettingsParameter(net.sf.mzmine.parameters.parametertypes.WindowSettingsParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter) BooleanParameter(net.sf.mzmine.parameters.parametertypes.BooleanParameter) MZToleranceParameter(net.sf.mzmine.parameters.parametertypes.tolerances.MZToleranceParameter) CursorPosition(net.sf.mzmine.modules.visualization.tic.CursorPosition)

Example 45 with ParameterSet

use of net.sf.mzmine.parameters.ParameterSet in project mzmine2 by mzmine.

the class MsMsVisualizerModule method showIDAVisualizerSetupDialog.

public static void showIDAVisualizerSetupDialog(RawDataFile dataFile, Range<Double> mzRange, Range<Double> rtRange, IntensityType intensityType, NormalizationType normalizationType, Double minPeakInt) {
    ParameterSet parameters = MZmineCore.getConfiguration().getModuleParameters(MsMsVisualizerModule.class);
    parameters.getParameter(MsMsParameters.dataFiles).setValue(RawDataFilesSelectionType.SPECIFIC_FILES, new RawDataFile[] { dataFile });
    if (rtRange != null)
        parameters.getParameter(MsMsParameters.retentionTimeRange).setValue(rtRange);
    if (mzRange != null)
        parameters.getParameter(MsMsParameters.mzRange).setValue(mzRange);
    if (intensityType != null)
        parameters.getParameter(MsMsParameters.intensityType).setValue(intensityType);
    if (normalizationType != null)
        parameters.getParameter(MsMsParameters.normalizationType).setValue(normalizationType);
    if (!Double.isNaN(minPeakInt))
        parameters.getParameter(MsMsParameters.minPeakInt).setValue(minPeakInt);
    ExitCode exitCode = parameters.showSetupDialog(MZmineCore.getDesktop().getMainWindow(), true);
    if (exitCode != ExitCode.OK)
        return;
    rtRange = parameters.getParameter(MsMsParameters.retentionTimeRange).getValue();
    mzRange = parameters.getParameter(MsMsParameters.mzRange).getValue();
    intensityType = parameters.getParameter(MsMsParameters.intensityType).getValue();
    normalizationType = parameters.getParameter(MsMsParameters.normalizationType).getValue();
    minPeakInt = parameters.getParameter(MsMsParameters.minPeakInt).getValue();
    MsMsVisualizerWindow newWindow = new MsMsVisualizerWindow(dataFile, rtRange, mzRange, intensityType, normalizationType, minPeakInt, parameters);
    newWindow.setVisible(true);
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) ExitCode(net.sf.mzmine.util.ExitCode)

Aggregations

ParameterSet (net.sf.mzmine.parameters.ParameterSet)53 ExitCode (net.sf.mzmine.util.ExitCode)19 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)11 File (java.io.File)9 ArrayList (java.util.ArrayList)8 SimpleParameterSet (net.sf.mzmine.parameters.impl.SimpleParameterSet)8 Task (net.sf.mzmine.taskcontrol.Task)8 Element (org.w3c.dom.Element)8 PeakList (net.sf.mzmine.datamodel.PeakList)6 MZmineModule (net.sf.mzmine.modules.MZmineModule)6 Document (org.w3c.dom.Document)6 IOException (java.io.IOException)5 DataPoint (net.sf.mzmine.datamodel.DataPoint)5 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)5 Scan (net.sf.mzmine.datamodel.Scan)5 MZmineProcessingModule (net.sf.mzmine.modules.MZmineProcessingModule)5 Nonnull (javax.annotation.Nonnull)4 Feature (net.sf.mzmine.datamodel.Feature)4 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)4 PeakListsParameter (net.sf.mzmine.parameters.parametertypes.selectors.PeakListsParameter)4