Search in sources :

Example 31 with IsotopePattern

use of net.sf.mzmine.datamodel.IsotopePattern 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)

Aggregations

IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)31 DataPoint (net.sf.mzmine.datamodel.DataPoint)19 Feature (net.sf.mzmine.datamodel.Feature)14 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)9 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)9 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)8 ArrayList (java.util.ArrayList)7 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)7 PeakList (net.sf.mzmine.datamodel.PeakList)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)5 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)5 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)4 ParameterSet (net.sf.mzmine.parameters.ParameterSet)4 HashMap (java.util.HashMap)3 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)3 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)3 ExitCode (net.sf.mzmine.util.ExitCode)3 Component (dulab.adap.datamodel.Component)2 Peak (dulab.adap.datamodel.Peak)2 PeakInfo (dulab.adap.datamodel.PeakInfo)2