use of com.compomics.util.gui.spectrum.MassErrorBubblePlot in project peptide-shaker by compomics.
the class SpectrumIdentificationPanel method updateSpectrum.
/**
* Update the spectrum based on the currently selected PSM.
*/
public void updateSpectrum() {
if (spectrumTable.getSelectedRow() != -1) {
spectrumChartPanel.removeAll();
String spectrumTitle = getSelectedSpectrumTitle();
Spectrum currentSpectrum = peptideShakerGUI.getSpectrumProvider().getSpectrum(fileSelected, spectrumTitle);
AnnotationParameters annotationParameters = peptideShakerGUI.getIdentificationParameters().getAnnotationParameters();
long spectrumMatchKey = SpectrumMatch.getKey(fileSelected, spectrumTitle);
SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumMatchKey);
// get the selected spectrum
if (currentSpectrum != null && currentSpectrum.getNPeaks() > 0) {
Precursor precursor = currentSpectrum.getPrecursor();
String chargeAsString = "";
if (spectrumMatch != null) {
if (spectrumMatch.getBestPeptideAssumption() != null) {
chargeAsString = Charge.toString(spectrumMatch.getBestPeptideAssumption().getIdentificationCharge());
} else if (spectrumMatch.getBestTagAssumption() != null) {
chargeAsString = Charge.toString(spectrumMatch.getBestTagAssumption().getIdentificationCharge());
}
} else {
chargeAsString = precursor.getPossibleChargesAsString();
}
double[] intensitiesAsArray = searchResultsTable.getSelectedRowCount() == 1 ? currentSpectrum.intensity : ArrayUtil.scaleToMax(currentSpectrum.intensity);
spectrumPanel = new SpectrumPanel(currentSpectrum.mz, intensitiesAsArray, precursor.mz, chargeAsString, "", 40, false, false, false, 2, false);
spectrumPanel.setKnownMassDeltas(peptideShakerGUI.getCurrentMassDeltas());
spectrumPanel.setDeltaMassWindow(annotationParameters.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());
// add the mirrored spectrum
if (searchResultsTable.getSelectedRowCount() == 2) {
spectrumPanel.addMirroredSpectrum(currentSpectrum.mz, ArrayUtil.scaleToMax(currentSpectrum.intensity), precursor.mz, chargeAsString, "", false, peptideShakerGUI.getUtilitiesUserParameters().getSpectrumAnnotatedMirroredPeakColor(), peptideShakerGUI.getUtilitiesUserParameters().getSpectrumAnnotatedMirroredPeakColor());
}
}
// add spectrum annotations
if (spectrumMatch != null) {
SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
SearchParameters searchParameters = identificationParameters.getSearchParameters();
DisplayParameters displayParameters = peptideShakerGUI.getDisplayParameters();
int forwardIon = searchParameters.getForwardIons().get(0);
int rewindIon = searchParameters.getRewindIons().get(0);
if (currentSpectrum != null && spectrumPanel != null) {
if (currentSpectrum.getNPeaks() > 0) {
int maxPrecursorCharge = 1;
String modifiedSequence = "";
HashSet<String> allModifications = new HashSet<>();
ArrayList<IonMatch[]> allAnnotations = new ArrayList<>();
ArrayList<Spectrum> allSpectra = new ArrayList<>();
ArrayList<String> selectedIndexes = new ArrayList<>();
SpecificAnnotationParameters specificAnnotationParameters = null;
for (int i = 0; i < searchResultsTable.getSelectedRowCount(); i++) {
SpectrumIdentificationAssumption currentAssumption = currentAssumptionsList.get(searchResultsTable.getSelectedRows()[i]);
if (currentAssumption != null) {
selectedIndexes.add((i + 1) + " " + Charge.toString(currentAssumption.getIdentificationCharge()));
if (currentAssumption instanceof PeptideAssumption) {
PeptideAssumption currentPeptideAssumption = (PeptideAssumption) currentAssumption;
Peptide peptide = currentPeptideAssumption.getPeptide();
PeptideSpectrumAnnotator peptideSpectrumAnnotator = new PeptideSpectrumAnnotator();
specificAnnotationParameters = peptideShakerGUI.getSpecificAnnotationParameters(fileSelected, spectrumTitle, currentPeptideAssumption);
IonMatch[] annotations = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, fileSelected, spectrumTitle, currentSpectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
allAnnotations.add(annotations);
allSpectra.add(currentSpectrum);
// add the spectrum annotations
if (i == 0) {
// @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);
// add de novo sequencing
spectrumPanel.addAutomaticDeNovoSequencing(peptide, annotations, forwardIon, rewindIon, annotationParameters.getDeNovoCharge(), annotationParameters.showForwardIonDeNovoTags(), annotationParameters.showRewindIonDeNovoTags(), false, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
} else {
spectrumPanel.setAnnotationsMirrored(SpectrumAnnotator.getSpectrumAnnotation(annotations));
// add de novo sequencing
spectrumPanel.addAutomaticDeNovoSequencing(peptide, annotations, forwardIon, rewindIon, annotationParameters.getDeNovoCharge(), annotationParameters.showForwardIonDeNovoTags(), annotationParameters.showRewindIonDeNovoTags(), true, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
}
if (currentPeptideAssumption.getIdentificationCharge() > maxPrecursorCharge) {
maxPrecursorCharge = currentPeptideAssumption.getIdentificationCharge();
}
if (!modifiedSequence.isEmpty()) {
modifiedSequence += " vs. ";
}
modifiedSequence += peptide.getTaggedModifiedSequence(modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, false, false, true, displayParameters.getDisplayedModifications());
allModifications.addAll(ModificationUtils.getAllModifications(peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters));
} else if (currentAssumption instanceof TagAssumption) {
TagAssumption tagAssumption = (TagAssumption) currentAssumption;
TagSpectrumAnnotator spectrumAnnotator = new TagSpectrumAnnotator();
specificAnnotationParameters = peptideShakerGUI.getSpecificAnnotationParameters(fileSelected, spectrumTitle, tagAssumption);
IonMatch[] annotations = spectrumAnnotator.getSpectrumAnnotation(annotationParameters, modificationParameters, modificationSequenceMatchingParameters, specificAnnotationParameters, fileSelected, spectrumTitle, currentSpectrum, tagAssumption.getTag());
// add the spectrum annotations
// @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);
// add de novo sequencing
spectrumPanel.addAutomaticDeNovoSequencing(tagAssumption.getTag(), annotations, forwardIon, rewindIon, annotationParameters.getDeNovoCharge(), annotationParameters.showForwardIonDeNovoTags(), annotationParameters.showRewindIonDeNovoTags(), false);
// get the modifications for the tag
allModifications.addAll(ModificationUtils.getAllModifications(tagAssumption.getTag(), modificationParameters, modificationSequenceMatchingParameters));
if (tagAssumption.getIdentificationCharge() > maxPrecursorCharge) {
maxPrecursorCharge = tagAssumption.getIdentificationCharge();
}
if (!modifiedSequence.isEmpty()) {
modifiedSequence += " vs. ";
}
modifiedSequence += tagAssumption.getTag().getTaggedModifiedSequence(modificationParameters, false, false, true, false, modificationSequenceMatchingParameters, displayParameters.getDisplayedModifications());
} else {
throw new UnsupportedOperationException("Spectrum annotation not implemented for identification assumption of type " + currentAssumption.getClass() + ".");
}
}
}
spectrumPanel.showAnnotatedPeaksOnly(!annotationParameters.showAllPeaks());
spectrumPanel.setYAxisZoomExcludesBackgroundPeaks(annotationParameters.yAxisZoomExcludesBackgroundPeaks());
peptideShakerGUI.updateAnnotationMenus(specificAnnotationParameters, maxPrecursorCharge, allModifications);
// update the spectrum title
if (searchResultsTable.getSelectedRowCount() == 1) {
((TitledBorder) spectrumPanelPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Spectrum & Fragment Ions (" + modifiedSequence + " " + maxPrecursorCharge + " " + Util.roundDouble(currentSpectrum.getPrecursor().mz, 2) + " m/z)" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
} else if (searchResultsTable.getSelectedRowCount() == 2) {
((TitledBorder) spectrumPanelPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Spectrum & Fragment Ions (" + modifiedSequence + ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
} else if (searchResultsTable.getSelectedRowCount() > 2) {
((TitledBorder) spectrumPanelPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Spectrum & Fragment Ions (" + searchResultsTable.getSelectedRowCount() + " PSMs)" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
}
spectrumPanelPanel.repaint();
if (searchResultsTable.getSelectedRowCount() > 2) {
SearchParameters.MassAccuracyType fragmentAccuracyType = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getFragmentAccuracyType();
double bubbleScale = annotationParameters.getFragmentIonAccuracy() * 10 * peptideShakerGUI.getBubbleScale();
DisplayParameters displayPreferences = peptideShakerGUI.getDisplayParameters();
MassErrorBubblePlot massErrorBubblePlot = new MassErrorBubblePlot(selectedIndexes, allAnnotations, allSpectra, annotationParameters.getFragmentIonAccuracy(), bubbleScale, selectedIndexes.size() == 1, displayPreferences.showBars(), fragmentAccuracyType == SearchParameters.MassAccuracyType.PPM);
// hide the legend if selecting more than 20 spectra // @TODO: 20 should not be hardcoded here..
if (selectedIndexes.size() > 20) {
massErrorBubblePlot.getChartPanel().getChart().getLegend().setVisible(false);
}
// hide the outline
massErrorBubblePlot.getChartPanel().getChart().getPlot().setOutlineVisible(false);
spectrumChartPanel.add(massErrorBubblePlot);
}
}
}
if (searchResultsTable.getSelectedRowCount() <= 2) {
spectrumChartPanel.add(spectrumPanel);
}
} else {
// update the spectrum title
((TitledBorder) spectrumPanelPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Spectrum & Fragment Ions (" + Util.roundDouble(currentSpectrum.getPrecursor().mz, 2) + " m/z)" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
if (currentSpectrum.getNPeaks() > 0) {
spectrumChartPanel.add(spectrumPanel);
}
spectrumPanelPanel.repaint();
}
}
spectrumChartPanel.revalidate();
spectrumChartPanel.repaint();
}
Aggregations