Search in sources :

Example 21 with PeakIdentity

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

the class ScatterPlotChart method actionPerformed.

public void actionPerformed(ActionEvent event) {
    super.actionPerformed(event);
    String command = event.getActionCommand();
    if (command.equals("SETUP_AXES")) {
        AxesSetupDialog dialog = new AxesSetupDialog(window, plot);
        dialog.setVisible(true);
        return;
    }
    if (command.equals("TIC")) {
        double valueX = plot.getDomainCrosshairValue();
        double valueY = plot.getRangeCrosshairValue();
        PeakListRow selectedRow = mainDataSet.getRow(valueX, valueY);
        if (selectedRow == null) {
            MZmineCore.getDesktop().displayErrorMessage(window, "No peak is selected");
            return;
        }
        Feature[] peaks = selectedRow.getPeaks();
        Range<Double> rtRange = peakList.getRowsRTRange();
        Range<Double> mzRange = PeakUtils.findMZRange(peaks);
        // Label best peak with preferred identity.
        final Feature bestPeak = selectedRow.getBestPeak();
        final PeakIdentity peakIdentity = selectedRow.getPreferredPeakIdentity();
        final Map<Feature, String> labelMap = new HashMap<Feature, String>(1);
        if (bestPeak != null && peakIdentity != null) {
            labelMap.put(bestPeak, peakIdentity.getName());
        }
        ScanSelection scanSelection = new ScanSelection(rtRange, 1);
        TICVisualizerModule.showNewTICVisualizerWindow(peakList.getRawDataFiles(), peaks, labelMap, scanSelection, TICPlotType.BASEPEAK, mzRange);
    }
    if ("SAVE_EMF".equals(command)) {
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("EMF Image", "EMF");
        chooser.setFileFilter(filter);
        int returnVal = chooser.showSaveDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            String file = chooser.getSelectedFile().getPath();
            if (!file.toLowerCase().endsWith(".emf"))
                file += ".emf";
            int width = (int) this.getSize().getWidth();
            int height = (int) this.getSize().getHeight();
            // Save image
            SaveImage SI = new SaveImage(getChart(), file, width, height, FileType.EMF);
            new Thread(SI).start();
        }
    }
    if ("SAVE_EPS".equals(command)) {
        JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter("EPS Image", "EPS");
        chooser.setFileFilter(filter);
        int returnVal = chooser.showSaveDialog(null);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            String file = chooser.getSelectedFile().getPath();
            if (!file.toLowerCase().endsWith(".eps"))
                file += ".eps";
            int width = (int) this.getSize().getWidth();
            int height = (int) this.getSize().getHeight();
            // Save image
            SaveImage SI = new SaveImage(getChart(), file, width, height, FileType.EPS);
            new Thread(SI).start();
        }
    }
}
Also used : ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) HashMap(java.util.HashMap) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) SaveImage(net.sf.mzmine.util.SaveImage) Feature(net.sf.mzmine.datamodel.Feature) AxesSetupDialog(net.sf.mzmine.util.dialogs.AxesSetupDialog) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) JFileChooser(javax.swing.JFileChooser)

Example 22 with PeakIdentity

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

the class ScatterPlotTopPanel method updateItemNameText.

public void updateItemNameText(PeakListRow selectedRow) {
    if (selectedRow == null) {
        itemNameLabel.setText("");
        return;
    }
    PeakIdentity identity = selectedRow.getPreferredPeakIdentity();
    String itemName;
    if (identity != null) {
        itemName = identity.getName();
    } else {
        itemName = selectedRow.toString();
    }
    itemNameLabel.setText(itemName);
}
Also used : PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity)

Example 23 with PeakIdentity

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

the class PeakSummaryComponent method actionPerformed.

public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command.equals("SHOW")) {
        String visualizerType = (String) comboShow.getSelectedItem();
        int[] indexesRow = peaksInfoList.getSelectedRows();
        Feature[] selectedPeaks = new Feature[indexesRow.length];
        RawDataFile[] dataFiles = new RawDataFile[indexesRow.length];
        Range<Double> rtRange = null, mzRange = null;
        for (int i = 0; i < indexesRow.length; i++) {
            selectedPeaks[i] = listElementModel.getElementAt(indexesRow[i]);
            dataFiles[i] = selectedPeaks[i].getDataFile();
            if ((rtRange == null) || (mzRange == null)) {
                rtRange = dataFiles[i].getDataRTRange(1);
                mzRange = selectedPeaks[i].getRawDataPointsMZRange();
            } else {
                rtRange = rtRange.span(dataFiles[i].getDataRTRange(1));
                mzRange = mzRange.span(selectedPeaks[i].getRawDataPointsMZRange());
            }
        }
        if (dataFiles.length == 0) {
            return;
        }
        if (visualizerType.equals("Chromatogram")) {
            // Label best peak with preferred identity.
            final Feature bestPeak = row.getBestPeak();
            final PeakIdentity peakIdentity = row.getPreferredPeakIdentity();
            final Map<Feature, String> labelMap = new HashMap<Feature, String>(1);
            if (bestPeak != null && peakIdentity != null) {
                labelMap.put(bestPeak, peakIdentity.getName());
            }
            ScanSelection scanSelection = new ScanSelection(rtRange, 1);
            TICVisualizerModule.showNewTICVisualizerWindow(dataFiles, selectedPeaks, labelMap, scanSelection, TICPlotType.BASEPEAK, mzRange);
            return;
        } else if (visualizerType.equals("Mass spectrum")) {
            for (int i = 0; i < selectedPeaks.length; ++i) {
                final Feature peak = selectedPeaks[i];
                final IsotopePattern ip = peak.getIsotopePattern();
                if (ip != null) {
                    // ------------------------------
                    // Multiply isotope pattern by -1
                    // ------------------------------
                    DataPoint[] newDataPoints = Arrays.stream(ip.getDataPoints()).map(p -> new SimpleDataPoint(p.getMZ(), -p.getIntensity())).toArray(DataPoint[]::new);
                    // ---------------------------
                    // Construct identity spectrum
                    // ---------------------------
                    List<DataPoint> identityDataPoints = new ArrayList<>();
                    PeakIdentity identity = row.getPreferredPeakIdentity();
                    if (identity != null) {
                        String spectrum = identity.getPropertyValue(PeakIdentity.PROPERTY_SPECTRUM);
                        if (spectrum != null && spectrum.length() > 2) {
                            spectrum = spectrum.substring(1, spectrum.length() - 1);
                            for (String strPair : spectrum.split(",")) {
                                String[] pair = strPair.split("=", 2);
                                if (pair.length == 2)
                                    identityDataPoints.add(new SimpleDataPoint(Double.parseDouble(pair[0]), Double.parseDouble(pair[1])));
                            }
                        }
                    }
                    if (// Plot raw spectrum and isotope pattern
                    identityDataPoints.isEmpty())
                        SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber(), null, null, null, new SimpleIsotopePattern(newDataPoints, ip.getStatus(), ip.getDescription()));
                    else
                        // Plot raw spectrum, isotope pattern, and identity spectrum
                        SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber(), null, new SimpleIsotopePattern(identityDataPoints.toArray(new DataPoint[identityDataPoints.size()]), IsotopePatternStatus.DETECTED, identity.getPropertyValue(PeakIdentity.PROPERTY_FORMULA)), null, new SimpleIsotopePattern(newDataPoints, ip.getStatus(), ip.getDescription()));
                } else
                    // Plot raw spectrum without isotope pattern
                    SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], peak.getRepresentativeScanNumber());
            }
        } else if (visualizerType.equals("Peak in 2D")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                Range<Double> peakRTRange = selectedPeaks[i].getRawDataPointsRTRange();
                Range<Double> peakMZRange = selectedPeaks[i].getRawDataPointsMZRange();
                final double rtLen = peakRTRange.upperEndpoint() - peakRTRange.lowerEndpoint();
                Range<Double> localRTRange = Range.closed(Math.max(0, peakRTRange.lowerEndpoint() - rtLen), peakRTRange.upperEndpoint() + rtLen);
                final double mzLen = peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint();
                Range<Double> localMZRange = Range.closed(Math.max(0, peakMZRange.lowerEndpoint() - mzLen), peakMZRange.upperEndpoint() + mzLen);
                TwoDVisualizerModule.show2DVisualizerSetupDialog(dataFiles[i], localMZRange, localRTRange);
            }
        } else if (visualizerType.equals("Peak in 3D")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                Range<Double> peakRTRange = selectedPeaks[i].getRawDataPointsRTRange();
                Range<Double> peakMZRange = selectedPeaks[i].getRawDataPointsMZRange();
                final double rtLen = peakRTRange.upperEndpoint() - peakRTRange.lowerEndpoint();
                Range<Double> localRTRange = Range.closed(Math.max(0, peakRTRange.lowerEndpoint() - rtLen), peakRTRange.upperEndpoint() + rtLen);
                final double mzLen = peakMZRange.upperEndpoint() - peakMZRange.lowerEndpoint();
                Range<Double> localMZRange = Range.closed(Math.max(0, peakMZRange.lowerEndpoint() - mzLen), peakMZRange.upperEndpoint() + mzLen);
                Fx3DVisualizerModule.setupNew3DVisualizer(dataFiles[i], localMZRange, localRTRange);
            }
        } else if (visualizerType.equals("MS/MS")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                int scanNumber = selectedPeaks[i].getMostIntenseFragmentScanNumber();
                if (scanNumber > 0) {
                    SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], scanNumber);
                } else {
                    JFrame frame = (JFrame) SwingUtilities.getAncestorOfClass(JFrame.class, this);
                    MZmineCore.getDesktop().displayMessage(frame, "There is no fragment for the mass " + MZmineCore.getConfiguration().getMZFormat().format(selectedPeaks[i].getMZ()) + "m/z in the current raw data.");
                    return;
                }
            }
        } else if (visualizerType.equals("Isotope pattern")) {
            for (int i = 0; i < selectedPeaks.length; i++) {
                IsotopePattern ip = selectedPeaks[i].getIsotopePattern();
                if (ip == null) {
                    return;
                }
                SpectraVisualizerModule.showNewSpectrumWindow(dataFiles[i], selectedPeaks[i].getMostIntenseFragmentScanNumber(), ip);
            }
        }
        return;
    }
    if (command.equals("CHANGE")) {
        int indexRow = peaksInfoList.getSelectedRow();
        if (indexRow == -1) {
            return;
        }
        Feature selectedPeak = listElementModel.getElementAt(indexRow);
        ManualPeakPickerModule.runManualDetection(selectedPeak.getDataFile(), row, null, null);
        return;
    }
}
Also used : ScanSelection(net.sf.mzmine.parameters.parametertypes.selectors.ScanSelection) HashMap(java.util.HashMap) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) Range(com.google.common.collect.Range) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) JFrame(javax.swing.JFrame) List(java.util.List) ArrayList(java.util.ArrayList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)

Example 24 with PeakIdentity

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

the class CameraSearchTask method groupPeaksByPCGroup.

/**
 * Uses PCGroup-field in PeakIdentity to group peaks and build spectrum
 *
 * @param peakList a PeakList object
 * @return a new PeakList object
 */
private PeakList groupPeaksByPCGroup(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 PCGroups
    // --------------------
    Set<String> pcGroups = new HashSet<>();
    for (PeakListRow row : peakList.getRows()) {
        PeakIdentity identity = row.getPreferredPeakIdentity();
        if (identity == null)
            continue;
        String groupName = identity.getName();
        if (groupName == null || groupName.length() == 0)
            continue;
        pcGroups.add(groupName);
    }
    List<PeakListRow> groupRows = new ArrayList<>();
    // Set <String> groupNames = new HashSet <> ();
    Map<Double, Double> spectrum = new HashMap<>();
    List<PeakListRow> newPeakListRows = new ArrayList<>();
    for (String groupName : pcGroups) {
        // -----------------------------------------
        // Find all peaks belonging to isotopeGroups
        // -----------------------------------------
        groupRows.clear();
        // groupNames.clear();
        spectrum.clear();
        double maxIntensity = 0.0;
        PeakListRow groupRow = null;
        for (PeakListRow row : peakList.getRows()) {
            PeakIdentity identity = row.getPreferredPeakIdentity();
            if (identity == null)
                continue;
            String name = identity.getName();
            if (name.equals(groupName)) {
                double intensity = row.getAverageHeight();
                groupRows.add(row);
                // groupNames.add(name);
                spectrum.put(row.getAverageMZ(), intensity);
                if (intensity > maxIntensity) {
                    maxIntensity = intensity;
                    groupRow = row;
                }
            }
        }
        if (groupRow == null || spectrum.size() <= 1)
            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);
    }
    // ------------------------------------
    // 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 25 with PeakIdentity

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

the class NistMsSearchTask method checkSameIds.

/**
 * Check whether peak row identities are the same.
 *
 * @param row1 first row to compare.
 * @param row2 second row to compare.
 * @return true if the rows have identities with the same name or both have no identity.
 */
private static boolean checkSameIds(final PeakListRow row1, final PeakListRow row2) {
    final PeakIdentity id1 = row1.getPreferredPeakIdentity();
    final PeakIdentity id2 = row2.getPreferredPeakIdentity();
    return // Use == rather than .equals() to handle nulls.
    id1 == id2 || id1 != null && id2 != null && id1.getName().equalsIgnoreCase(id2.getName());
}
Also used : SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity)

Aggregations

PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)32 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)19 Feature (net.sf.mzmine.datamodel.Feature)14 ArrayList (java.util.ArrayList)9 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)9 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)9 PeakList (net.sf.mzmine.datamodel.PeakList)8 HashMap (java.util.HashMap)7 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)7 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)7 DataPoint (net.sf.mzmine.datamodel.DataPoint)6 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)6 IOException (java.io.IOException)5 List (java.util.List)5 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)5 File (java.io.File)4 HashSet (java.util.HashSet)4 Scan (net.sf.mzmine.datamodel.Scan)4 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 Range (com.google.common.collect.Range)3