use of com.compomics.util.experiment.identification.spectrum_annotation.SpectrumAnnotator in project peptide-shaker by compomics.
the class OverviewPanel method updateSpectrum.
/**
* Update the spectrum to the currently selected PSM.
*
* @param row the row index of the PSM
* @param resetMzRange if true the mz range is reset, if false the current
* zoom range is kept
*/
private void updateSpectrum(int row, boolean resetMzRange) {
if (row != -1) {
this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
SelfUpdatingTableModel tableModel = (SelfUpdatingTableModel) psmTable.getModel();
int psmIndex = tableModel.getViewIndex(row);
long spectrumMatchKey = psmKeys[psmIndex];
if (displaySpectrum) {
SpectrumProvider spectrumProvider = peptideShakerGUI.getSpectrumProvider();
SpectrumMatch spectrumMatch = peptideShakerGUI.getIdentification().getSpectrumMatch(spectrumMatchKey);
String spectrumFile = spectrumMatch.getSpectrumFile();
String spectrumTitle = spectrumMatch.getSpectrumTitle();
Spectrum currentSpectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
if (currentSpectrum != null && currentSpectrum.getNPeaks() > 0) {
boolean newMax = false;
if (resetMzRange) {
lastMzMaximum = 0;
}
if (peptideShakerGUI.getSelectedPeptideKey() != NO_KEY) {
double newMaximum = currentSpectrum.getMaxMz();
if (lastMzMaximum < newMaximum) {
lastMzMaximum = newMaximum;
newMax = true;
}
}
double lowerMzZoomRange = 0;
double upperMzZoomRange = lastMzMaximum;
if (spectrumPanel != null && spectrumPanel.getXAxisZoomRangeLowerValue() != 0 && !newMax) {
// @TODO: sometimes the range is reset when is should not be...
lowerMzZoomRange = spectrumPanel.getXAxisZoomRangeLowerValue();
upperMzZoomRange = spectrumPanel.getXAxisZoomRangeUpperValue();
}
// add the data to the spectrum panel
Precursor precursor = currentSpectrum.getPrecursor();
spectrumPanel = new SpectrumPanel(currentSpectrum.mz, currentSpectrum.intensity, precursor.mz, Charge.toString(spectrumMatch.getBestPeptideAssumption().getIdentificationCharge()), "", 40, false, false, false, 2, false);
spectrumPanel.setKnownMassDeltas(peptideShakerGUI.getCurrentMassDeltas());
spectrumPanel.setDeltaMassWindow(peptideShakerGUI.getIdentificationParameters().getAnnotationParameters().getFragmentIonAccuracy());
spectrumPanel.setBorder(null);
spectrumPanel.setDataPointAndLineColor(peptideShakerGUI.getUtilitiesUserParameters().getSpectrumAnnotatedPeakColor(), 0);
spectrumPanel.setPeakWaterMarkColor(peptideShakerGUI.getUtilitiesUserParameters().getSpectrumBackgroundPeakColor());
spectrumPanel.setPeakWidth(peptideShakerGUI.getUtilitiesUserParameters().getSpectrumAnnotatedPeakWidth());
spectrumPanel.setBackgroundPeakWidth(peptideShakerGUI.getUtilitiesUserParameters().getSpectrumBackgroundPeakWidth());
// get the spectrum annotations
PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();
Peptide currentPeptide = peptideAssumption.getPeptide();
PeptideSpectrumAnnotator spectrumAnnotator = new PeptideSpectrumAnnotator();
AnnotationParameters annotationParameters = peptideShakerGUI.getIdentificationParameters().getAnnotationParameters();
SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
SpecificAnnotationParameters specificAnnotationParameters = peptideShakerGUI.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption);
IonMatch[] annotations = spectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, currentSpectrum, currentPeptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
// @TODO: the selection of the peak to annotate should be done outside the spectrum panel
spectrumPanel.setAnnotations(SpectrumAnnotator.getSpectrumAnnotation(annotations), annotationParameters.getTiesResolution() == SpectrumAnnotator.TiesResolution.mostIntense);
spectrumPanel.rescale(lowerMzZoomRange, upperMzZoomRange);
// show all or just the annotated peaks
spectrumPanel.showAnnotatedPeaksOnly(!annotationParameters.showAllPeaks());
spectrumPanel.setYAxisZoomExcludesBackgroundPeaks(annotationParameters.yAxisZoomExcludesBackgroundPeaks());
Integer forwardIon = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getForwardIons().get(0);
Integer rewindIon = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getRewindIons().get(0);
// add de novo sequencing
spectrumPanel.addAutomaticDeNovoSequencing(currentPeptide, annotations, forwardIon, rewindIon, annotationParameters.getDeNovoCharge(), annotationParameters.showForwardIonDeNovoTags(), annotationParameters.showRewindIonDeNovoTags(), false, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
// add the spectrum panel to the frame
spectrumJPanel.removeAll();
spectrumJPanel.add(spectrumPanel);
spectrumJPanel.revalidate();
spectrumJPanel.repaint();
// create and display the fragment ion table
ArrayList<IonMatch[]> allAnnotations = getAnnotationsForAllSelectedSpectra();
DisplayParameters displayParameters = peptideShakerGUI.getDisplayParameters();
if (!displayParameters.useIntensityIonTable()) {
fragmentIonsJScrollPane.setViewportView(new FragmentIonTable(currentPeptide, allAnnotations, specificAnnotationParameters.getFragmentIonTypes(), specificAnnotationParameters.getNeutralLossesMap(), specificAnnotationParameters.getSelectedCharges().contains(1), specificAnnotationParameters.getSelectedCharges().contains(2), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters));
} else {
ArrayList<Spectrum> spectra = Arrays.stream(getSelectedPsmKeys()).mapToObj(key -> peptideShakerGUI.getIdentification().getSpectrumMatch(key)).map(selectedMatch -> spectrumProvider.getSpectrum(selectedMatch.getSpectrumFile(), selectedMatch.getSpectrumTitle())).collect(Collectors.toCollection(ArrayList::new));
fragmentIonsJScrollPane.setViewportView(new FragmentIonTable(currentPeptide, allAnnotations, spectra, specificAnnotationParameters.getFragmentIonTypes(), specificAnnotationParameters.getNeutralLossesMap(), specificAnnotationParameters.getSelectedCharges().contains(1), specificAnnotationParameters.getSelectedCharges().contains(2), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters));
}
// create the sequence fragment ion view
secondarySpectrumPlotsJPanel.removeAll();
sequenceFragmentationPanel = new SequenceFragmentationPanel(peptideShakerGUI.getDisplayFeaturesGenerator().getTaggedPeptideSequence(spectrumMatch, false, false, true), annotations, true, peptideShakerGUI.getIdentificationParameters().getSearchParameters().getModificationParameters(), forwardIon, rewindIon);
sequenceFragmentationPanel.setMinimumSize(new Dimension(sequenceFragmentationPanel.getPreferredSize().width, sequenceFragmentationPanel.getHeight()));
sequenceFragmentationPanel.setOpaque(true);
sequenceFragmentationPanel.setBackground(Color.WHITE);
secondarySpectrumPlotsJPanel.add(sequenceFragmentationPanel);
// create the intensity histograms
intensityHistogram = new IntensityHistogram(annotations, currentSpectrum, annotationParameters.getAnnotationIntensityLimit());
secondarySpectrumPlotsJPanel.add(intensityHistogram);
// create the miniature mass error plot
massErrorPlot = new MassErrorPlot(annotations, currentSpectrum, specificAnnotationParameters.getFragmentIonAccuracy(), peptideShakerGUI.getIdentificationParameters().getSearchParameters().getFragmentAccuracyType() == SearchParameters.MassAccuracyType.PPM);
if (massErrorPlot.getNumberOfDataPointsInPlot() > 0) {
secondarySpectrumPlotsJPanel.add(massErrorPlot);
}
// update the UI
secondarySpectrumPlotsJPanel.revalidate();
secondarySpectrumPlotsJPanel.repaint();
// update the bubble plot
updateBubblePlot();
// disable the spectrum tab if more than two psms are selected
spectrumJTabbedPane.setEnabledAt(2, psmTable.getSelectedRowCount() <= 2);
peptideShakerGUI.enableSpectrumExport(psmTable.getSelectedRowCount() <= 2);
// move to the bubble plot tab if more than two psms are selected and the spectrum tab was selected
if (psmTable.getSelectedRowCount() > 2 && spectrumJTabbedPane.getSelectedIndex() == 2) {
spectrumJTabbedPane.setSelectedIndex(1);
}
if (psmTable.getSelectedRowCount() > 2) {
spectrumJTabbedPane.setToolTipTextAt(2, "Available for single or double spectrum selection only");
} else {
spectrumJTabbedPane.setToolTipTextAt(2, null);
}
// update the panel border title
updateSpectrumPanelBorderTitle(currentSpectrum);
spectrumMainPanel.revalidate();
spectrumMainPanel.repaint();
}
}
this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
} else {
// nothing to display, empty previous results
spectrumJPanel.removeAll();
spectrumJPanel.revalidate();
spectrumJPanel.repaint();
secondarySpectrumPlotsJPanel.removeAll();
secondarySpectrumPlotsJPanel.revalidate();
secondarySpectrumPlotsJPanel.repaint();
fragmentIonsJScrollPane.setViewportView(null);
fragmentIonsJScrollPane.revalidate();
fragmentIonsJScrollPane.repaint();
bubbleJPanel.removeAll();
bubbleJPanel.revalidate();
bubbleJPanel.repaint();
((TitledBorder) spectrumMainPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Spectrum & Fragment Ions" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
spectrumMainPanel.repaint();
}
}
Aggregations