Search in sources :

Example 31 with PeakList

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

the class CameraSearchTask method groupPeaksByIsotope.

/**
 * Uses Isotope-field in PeakIdentity to group isotopes and build spectrum
 *
 * @param peakList PeakList object
 * @return new PeakList object
 */
private PeakList groupPeaksByIsotope(PeakList peakList) {
    // Create new feature list.
    final PeakList combinedPeakList = new SimplePeakList(peakList + " " + parameters.getParameter(CameraSearchParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
    // Load previous applied methods.
    for (final PeakList.PeakListAppliedMethod method : peakList.getAppliedMethods()) {
        combinedPeakList.addDescriptionOfAppliedTask(method);
    }
    // Add task description to feature list.
    combinedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Bioconductor CAMERA", parameters));
    // ------------------------------------------------
    // Find unique isotopes belonging to the same group
    // ------------------------------------------------
    Set<String> isotopeGroups = new HashSet<>();
    for (PeakListRow row : peakList.getRows()) {
        PeakIdentity identity = row.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        String isotope = identity.getPropertyValue("Isotope");
        if (isotope == null)
            continue;
        String isotopeGroup = isotope.substring(1, isotope.indexOf("]"));
        if (isotopeGroup == null || isotopeGroup.length() == 0)
            continue;
        isotopeGroups.add(isotopeGroup);
    }
    List<PeakListRow> groupRows = new ArrayList<>();
    Set<String> groupNames = new HashSet<>();
    Map<Double, Double> spectrum = new HashMap<>();
    List<PeakListRow> newPeakListRows = new ArrayList<>();
    for (String isotopeGroup : isotopeGroups) {
        // -----------------------------------------
        // Find all peaks belonging to isotopeGroups
        // -----------------------------------------
        groupRows.clear();
        groupNames.clear();
        spectrum.clear();
        int minLength = Integer.MAX_VALUE;
        PeakListRow groupRow = null;
        for (PeakListRow row : peakList.getRows()) {
            PeakIdentity identity = row.getPreferredPeakIdentity();
            if (identity == null)
                continue;
            String isotope = identity.getPropertyValue("Isotope");
            if (isotope == null)
                continue;
            String isoGroup = isotope.substring(1, isotope.indexOf("]"));
            if (isoGroup == null)
                continue;
            if (isoGroup.equals(isotopeGroup)) {
                groupRows.add(row);
                groupNames.add(identity.getName());
                spectrum.put(row.getAverageMZ(), row.getAverageHeight());
                if (isoGroup.length() < minLength) {
                    minLength = isoGroup.length();
                    groupRow = row;
                }
            }
        }
        // Skip peaks that have different identity names (belong to different pcgroup)
        if (groupRow == null || groupNames.size() != 1)
            continue;
        if (groupRow == null)
            continue;
        PeakIdentity identity = groupRow.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        DataPoint[] dataPoints = new DataPoint[spectrum.size()];
        int count = 0;
        for (Entry<Double, Double> e : spectrum.entrySet()) dataPoints[count++] = new SimpleDataPoint(e.getKey(), e.getValue());
        IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
        groupRow.getBestPeak().setIsotopePattern(pattern);
        // combinedPeakList.addRow(groupRow);
        newPeakListRows.add(groupRow);
    }
    if (includeSingletons) {
        for (PeakListRow row : peakList.getRows()) {
            PeakIdentity identity = row.getPreferredPeakIdentity();
            if (identity == null)
                continue;
            String isotope = identity.getPropertyValue("Isotope");
            if (isotope == null || isotope.length() == 0) {
                DataPoint[] dataPoints = new DataPoint[1];
                dataPoints[0] = new SimpleDataPoint(row.getAverageMZ(), row.getAverageHeight());
                IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
                row.getBestPeak().setIsotopePattern(pattern);
                newPeakListRows.add(row);
            }
        }
    }
    // ------------------------------------
    // Sort new peak rows by retention time
    // ------------------------------------
    Collections.sort(newPeakListRows, new Comparator<PeakListRow>() {

        @Override
        public int compare(PeakListRow row1, PeakListRow row2) {
            double retTime1 = row1.getAverageRT();
            double retTime2 = row2.getAverageRT();
            return Double.compare(retTime1, retTime2);
        }
    });
    for (PeakListRow row : newPeakListRows) combinedPeakList.addRow(row);
    return combinedPeakList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) HashSet(java.util.HashSet)

Example 32 with PeakList

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

the class PrecursorDBSearchModule method runModule.

@Override
@Nonnull
public ExitCode runModule(@Nonnull MZmineProject project, @Nonnull ParameterSet parameters, @Nonnull Collection<Task> tasks) {
    PeakList[] peakLists = parameters.getParameter(PrecursorDBSearchParameters.peakLists).getValue().getMatchingPeakLists();
    for (PeakList peakList : peakLists) {
        Task newTask = new PrecursorDBSearchTask(peakList, parameters);
        tasks.add(newTask);
    }
    return ExitCode.OK;
}
Also used : Task(net.sf.mzmine.taskcontrol.Task) PeakList(net.sf.mzmine.datamodel.PeakList) Nonnull(javax.annotation.Nonnull)

Example 33 with PeakList

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

the class VanKrevelenDiagramParameters method showSetupDialog.

@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
    PeakList[] selectedPeakLists = getParameter(peakList).getValue().getMatchingPeakLists();
    if (selectedPeakLists.length > 0) {
        PeakListRow[] plRows = selectedPeakLists[0].getRows();
        Arrays.sort(plRows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
    }
    return super.showSetupDialog(parent, valueCheckRequired);
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) PeakList(net.sf.mzmine.datamodel.PeakList) PeakListRowSorter(net.sf.mzmine.util.PeakListRowSorter)

Example 34 with PeakList

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

the class TwoDVisualizerWindow method actionPerformed.

/**
 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
public void actionPerformed(ActionEvent event) {
    String command = event.getActionCommand();
    if (command.equals("SWITCH_PALETTE")) {
        twoDPlot.getXYPlot().switchPalette();
    }
    if (command.equals("SHOW_DATA_POINTS")) {
        twoDPlot.switchDataPointsVisible();
    }
    if (command.equals("SETUP_AXES")) {
        AxesSetupDialog dialog = new AxesSetupDialog(this, twoDPlot.getXYPlot());
        dialog.setVisible(true);
    }
    if (command.equals("SWITCH_PLOTMODE")) {
        if (twoDPlot.getPlotMode() == PlotMode.CENTROID) {
            toolBar.setCentroidButton(true);
            twoDPlot.setPlotMode(PlotMode.CONTINUOUS);
        } else {
            toolBar.setCentroidButton(false);
            twoDPlot.setPlotMode(PlotMode.CENTROID);
        }
    }
    if (command.equals("SWITCH_TOOLTIPS")) {
        if (tooltipMode) {
            twoDPlot.showPeaksTooltips(false);
            toolBar.setTooltipButton(false);
            tooltipMode = false;
        } else {
            twoDPlot.showPeaksTooltips(true);
            toolBar.setTooltipButton(true);
            tooltipMode = true;
        }
    }
    if (command.equals("SWITCH_LOG_SCALE")) {
        if (twoDPlot != null) {
            logScale = !logScale;
            twoDPlot.setLogScale(logScale);
        }
    }
    if ("PEAKLIST_CHANGE".equals(command)) {
        final PeakList selectedPeakList = bottomPanel.getSelectedPeakList();
        if (selectedPeakList != null) {
            logger.finest("Loading a feature list " + selectedPeakList + " to a 2D view of " + dataFile);
            twoDPlot.loadPeakList(selectedPeakList);
        }
    }
}
Also used : PeakList(net.sf.mzmine.datamodel.PeakList) AxesSetupDialog(net.sf.mzmine.util.dialogs.AxesSetupDialog)

Example 35 with PeakList

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

the class TwoDBottomPanel method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == thresholdCombo) {
        PeakThresholdMode mode = (PeakThresholdMode) this.thresholdCombo.getSelectedItem();
        switch(mode) {
            case ABOVE_INTENSITY_PEAKS:
                peakTextField.setText(String.valueOf(thresholdSettings.getIntensityThreshold()));
                peakTextField.setEnabled(true);
                break;
            case ALL_PEAKS:
                peakTextField.setEnabled(false);
                break;
            case TOP_PEAKS:
            case TOP_PEAKS_AREA:
                peakTextField.setText(String.valueOf(thresholdSettings.getTopPeaksThreshold()));
                peakTextField.setEnabled(true);
                break;
        }
        thresholdSettings.setMode(mode);
    }
    if (src == peakTextField) {
        PeakThresholdMode mode = (PeakThresholdMode) this.thresholdCombo.getSelectedItem();
        String value = peakTextField.getText();
        switch(mode) {
            case ABOVE_INTENSITY_PEAKS:
                double topInt = Double.parseDouble(value);
                thresholdSettings.setIntensityThreshold(topInt);
                break;
            case TOP_PEAKS:
            case TOP_PEAKS_AREA:
                int topPeaks = Integer.parseInt(value);
                thresholdSettings.setTopPeaksThreshold(topPeaks);
                break;
            default:
                break;
        }
    }
    PeakList selectedPeakList = getPeaksInThreshold();
    if (selectedPeakList != null)
        masterFrame.getPlot().loadPeakList(selectedPeakList);
}
Also used : SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList)

Aggregations

PeakList (net.sf.mzmine.datamodel.PeakList)120 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)41 Nonnull (javax.annotation.Nonnull)40 Task (net.sf.mzmine.taskcontrol.Task)37 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)36 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)26 Feature (net.sf.mzmine.datamodel.Feature)19 ArrayList (java.util.ArrayList)15 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)11 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)11 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)10 File (java.io.File)9 FileWriter (java.io.FileWriter)8 ParameterSet (net.sf.mzmine.parameters.ParameterSet)8 IOException (java.io.IOException)7 DataPoint (net.sf.mzmine.datamodel.DataPoint)7 Vector (java.util.Vector)6 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)6 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)6