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;
}
}
Aggregations