use of com.compomics.util.experiment.personalization.ExperimentObject.NO_KEY in project peptide-shaker by compomics.
the class ProteinStructurePanel method updateSelection.
/**
* Update the selected protein and peptide.
*
* @param scrollToVisible if true the table also scrolls to make the
* selected row visible
*/
public void updateSelection(boolean scrollToVisible) {
int proteinRow = 0;
long proteinKey = peptideShakerGUI.getSelectedProteinKey();
long peptideKey = peptideShakerGUI.getSelectedPeptideKey();
String spectrumFile = peptideShakerGUI.getSelectedSpectrumFile();
String spectrumTitle = peptideShakerGUI.getSelectedSpectrumTitle();
Identification identification = peptideShakerGUI.getIdentification();
if (proteinKey == NO_KEY && peptideKey == NO_KEY && spectrumFile != null && spectrumTitle != null) {
long psmKey = SpectrumMatch.getKey(spectrumFile, spectrumTitle);
SpectrumMatch spectrumMatch = identification.getSpectrumMatch(psmKey);
if (spectrumMatch != null && spectrumMatch.getBestPeptideAssumption() != null) {
Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
peptideKey = peptide.getMatchingKey(peptideShakerGUI.getIdentificationParameters().getSequenceMatchingParameters());
}
}
if (proteinKey == NO_KEY && peptideKey != NO_KEY) {
final long peptideKeyFinal = peptideKey;
ProteinMatch tempProteinMatch = identification.getProteinIdentification().parallelStream().map(key -> identification.getProteinMatch(key)).filter(proteinMatch -> Arrays.stream(proteinMatch.getPeptideMatchesKeys()).anyMatch(key -> key == peptideKeyFinal)).findAny().orElse(null);
if (tempProteinMatch != null) {
proteinKey = tempProteinMatch.getKey();
peptideShakerGUI.setSelectedItems(proteinKey, peptideKey, spectrumFile, spectrumTitle);
}
if (proteinKey != NO_KEY) {
proteinRow = getProteinRow(proteinKey);
}
if (proteinKeys.length == 0) {
clearData();
return;
}
if (proteinRow == -1) {
peptideShakerGUI.resetSelectedItems();
proteinTableMouseReleased(null);
} else if (proteinTable.getSelectedRow() != proteinRow) {
proteinTable.setRowSelectionInterval(proteinRow, proteinRow);
if (scrollToVisible) {
proteinTable.scrollRectToVisible(proteinTable.getCellRect(proteinRow, 0, false));
}
proteinTableMouseReleased(null);
}
int peptideRow = 0;
if (peptideKey != NO_KEY) {
peptideRow = getPeptideRow(peptideKey);
}
if (peptideTable.getSelectedRow() != peptideRow && peptideRow != -1) {
peptideTable.setRowSelectionInterval(peptideRow, peptideRow);
if (scrollToVisible) {
peptideTable.scrollRectToVisible(peptideTable.getCellRect(peptideRow, 0, false));
}
peptideTableMouseReleased(null);
}
if (spectrumFile != null && spectrumTitle != null) {
peptideShakerGUI.setSelectedItems(peptideShakerGUI.getSelectedProteinKey(), peptideShakerGUI.getSelectedPeptideKey(), spectrumFile, spectrumTitle);
}
}
}
use of com.compomics.util.experiment.personalization.ExperimentObject.NO_KEY 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();
}
}
use of com.compomics.util.experiment.personalization.ExperimentObject.NO_KEY in project peptide-shaker by compomics.
the class JumpToPanel method inputTxtKeyReleased.
// </editor-fold>//GEN-END:initComponents
/**
* Update the jump to filter.
*
* @param evt the key event
*/
private void inputTxtKeyReleased(java.awt.event.KeyEvent evt) {
// GEN-FIRST:event_inputTxtKeyReleased
indexLabel.setText("Typing...");
final KeyEvent event = evt;
newInput = true;
new Thread("FindThread") {
@Override
public synchronized void run() {
try {
searchMutex.acquire();
newInput = false;
try {
wait(500);
} catch (InterruptedException e) {
// Ignore
}
Identification identification = peptideShakerGUI.getIdentification();
if (identification != null && !newInput) {
indexLabel.setText("Searching...");
if (!inputTxt.getText().equalsIgnoreCase(welcomeText.get(selectedJumpType))) {
inputTxt.setForeground(Color.black);
} else {
inputTxt.setForeground(new Color(204, 204, 204));
}
if (event.getKeyCode() == KeyEvent.VK_UP && previousButton.isEnabled()) {
previousButtonActionPerformed(null);
} else if (event.getKeyCode() == KeyEvent.VK_DOWN && nextButton.isEnabled()) {
nextButtonActionPerformed(null);
} else {
possibilities.get(selectedJumpType).clear();
currentSelection.put(selectedJumpType, 0);
EnumMap<JumpType, Boolean> reinitializedMap = new EnumMap<>(JumpType.class);
for (JumpType jumpType : JumpType.values()) {
reinitializedMap.put(jumpType, jumpType == selectedJumpType);
}
String doubleString, inputLowerCase = inputTxt.getText().trim().toLowerCase(), inputUpperCase = inputLowerCase.toUpperCase();
if (!inputLowerCase.equals("")) {
peptideShakerGUI.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
inputTxt.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
boolean proteinFound = false;
boolean peptidefound = false;
if (selectedJumpType == JumpType.protein || selectedJumpType == JumpType.peptide) {
// See if the input is contained by a protein accession or description
TreeSet<Long> proteinKeysFound = new TreeSet<>();
TreeSet<Long> peptideKeysFound = new TreeSet<>();
for (long proteinKey : peptideShakerGUI.getIdentificationFeaturesGenerator().getProcessedProteinKeys(null, peptideShakerGUI.getFilterParameters())) {
if (newInput) {
peptideShakerGUI.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
inputTxt.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
inputTxt.requestFocus();
return;
}
ProteinMatch proteinMatch = identification.getProteinMatch(proteinKey);
if (!proteinMatch.isDecoy()) {
if (Arrays.stream(proteinMatch.getAccessions()).map(accession -> accession.toLowerCase()).anyMatch(accession -> accession.contains(inputLowerCase)) || Arrays.stream(proteinMatch.getAccessions()).map(accession -> peptideShakerGUI.getProteinDetailsProvider().getDescription(accession)).map(description -> description.toLowerCase()).anyMatch(description -> description.contains(inputLowerCase))) {
proteinFound = true;
proteinKeysFound.add(proteinKey);
for (long peptideKey : proteinMatch.getPeptideMatchesKeys()) {
peptideKeysFound.add(peptideKey);
}
}
}
}
if (proteinFound) {
lastInput.put(JumpType.protein, inputLowerCase);
if (!reinitializedMap.get(JumpType.protein)) {
possibilities.get(JumpType.protein).clear();
currentSelection.put(JumpType.protein, 0);
}
for (long proteinKey : proteinKeysFound) {
Object[] keys = new Object[3];
Arrays.fill(keys, NO_KEY);
keys[0] = proteinKey;
possibilities.get(JumpType.protein).add(keys);
}
lastInput.put(JumpType.peptide, inputLowerCase);
if (!reinitializedMap.get(JumpType.peptide)) {
possibilities.get(JumpType.peptide).clear();
currentSelection.put(JumpType.peptide, 0);
}
for (long peptideKey : peptideKeysFound) {
Object[] keys = new Object[3];
Arrays.fill(keys, NO_KEY);
keys[1] = peptideKey;
possibilities.get(JumpType.peptide).add(keys);
}
} else {
// See if the input is contained by a peptide sequence or is a modification
boolean validPeptideSequence = inputUpperCase.chars().allMatch(aa -> AminoAcid.isAa(aa));
boolean possibleMod = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getModificationParameters().getAllModifications().stream().anyMatch(modName -> modName.toLowerCase().contains(inputLowerCase));
if (validPeptideSequence || possibleMod) {
String matchingInput = AminoAcid.getMatchingSequence(inputUpperCase, peptideShakerGUI.getIdentificationParameters().getSequenceMatchingParameters());
TreeMap<Long, TreeSet<Long>> sequencesMatchesMap = new TreeMap<>();
TreeMap<Long, TreeSet<Long>> modificationsMatchesMap = new TreeMap<>();
for (long peptideKey : identification.getPeptideIdentification()) {
if (newInput) {
peptideShakerGUI.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
inputTxt.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
inputTxt.requestFocus();
return;
}
PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
if (!psParameter.getHidden()) {
Peptide peptide = peptideMatch.getPeptide();
String matchingSequence = AminoAcid.getMatchingSequence(peptide.getSequence(), peptideShakerGUI.getIdentificationParameters().getSequenceMatchingParameters());
boolean sequenceMatch = validPeptideSequence && matchingSequence.contains(matchingInput);
boolean modMatch = possibleMod && Arrays.stream(peptideMatch.getPeptide().getVariableModifications()).map(ModificationMatch::getModification).anyMatch(modName -> modName.contains(matchingInput));
if (sequenceMatch || modMatch) {
peptidefound = true;
TreeSet<Long> proteinKeys = identification.getProteinMatches(peptideKey);
for (long proteinKey : proteinKeys) {
ProteinMatch proteinMatch = identification.getProteinMatch(proteinKey);
if (!proteinMatch.isDecoy()) {
if (sequenceMatch) {
TreeSet<Long> peptideKeys = sequencesMatchesMap.get(proteinKey);
if (peptideKeys == null) {
peptideKeys = new TreeSet<>();
sequencesMatchesMap.put(proteinKey, peptideKeys);
}
peptideKeys.add(peptideKey);
}
if (modMatch) {
TreeSet<Long> peptideKeys = modificationsMatchesMap.get(proteinKey);
if (peptideKeys == null) {
peptideKeys = new TreeSet<>();
modificationsMatchesMap.put(proteinKey, peptideKeys);
}
peptideKeys.add(peptideKey);
}
}
}
}
}
}
TreeMap<Long, TreeSet<Long>> itemsMap = !modificationsMatchesMap.isEmpty() ? modificationsMatchesMap : sequencesMatchesMap;
lastInput.put(JumpType.protein, inputLowerCase);
if (!reinitializedMap.get(JumpType.protein)) {
possibilities.get(JumpType.protein).clear();
currentSelection.put(JumpType.protein, 0);
}
for (Entry<Long, TreeSet<Long>> entry : itemsMap.entrySet()) {
long proteinKey = entry.getKey();
for (long peptideKey : entry.getValue()) {
Object[] keys = new Object[3];
Arrays.fill(keys, NO_KEY);
keys[0] = proteinKey;
keys[1] = peptideKey;
possibilities.get(JumpType.protein).add(keys);
}
}
lastInput.put(JumpType.peptide, inputLowerCase);
if (!reinitializedMap.get(JumpType.peptide)) {
possibilities.get(JumpType.peptide).clear();
currentSelection.put(JumpType.peptide, 0);
}
itemsMap.values().stream().flatMapToLong(set -> set.stream().mapToLong(a -> a)).distinct().sorted().forEach(peptideKey -> {
Object[] keys = new Object[3];
Arrays.fill(keys, NO_KEY);
keys[1] = peptideKey;
possibilities.get(JumpType.peptide).add(keys);
});
}
}
}
if (selectedJumpType == JumpType.psm || !proteinFound && !peptidefound) {
// See if the input is contained by a spectrum title or corresponds to a precursor mass or RT
TreeSet<String> spectrumTitles = new TreeSet<>();
SpectrumProvider spectrumProvider = peptideShakerGUI.getSpectrumProvider();
String[] spectrumFiles = spectrumfile == null ? spectrumProvider.getOrderedFileNamesWithoutExtensions() : new String[] { spectrumfile };
for (String fileNameWithoutExtension : spectrumFiles) {
for (String spectrumTitle : spectrumProvider.getSpectrumTitles(fileNameWithoutExtension)) {
if (newInput) {
peptideShakerGUI.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
inputTxt.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
inputTxt.requestFocus();
return;
}
if (spectrumTitle.toLowerCase().contains(inputLowerCase) || fileNameWithoutExtension.toLowerCase().contains(inputLowerCase)) {
spectrumTitles.add(fileNameWithoutExtension + SPECTRUM_FILENAME_SPLITTER + spectrumTitle);
} else {
double precusorMz = spectrumProvider.getPrecursorMz(fileNameWithoutExtension, spectrumTitle);
doubleString = Double.toString(precusorMz);
if (doubleString.startsWith(inputLowerCase)) {
spectrumTitles.add(fileNameWithoutExtension + SPECTRUM_FILENAME_SPLITTER + spectrumTitle);
} else {
double precusorRt = spectrumProvider.getPrecursorRt(fileNameWithoutExtension, spectrumTitle);
doubleString = Double.toString(precusorRt);
if (doubleString.startsWith(inputLowerCase)) {
spectrumTitles.add(fileNameWithoutExtension + SPECTRUM_FILENAME_SPLITTER + spectrumTitle);
}
}
}
}
if (!spectrumTitles.isEmpty()) {
for (JumpType jumpType : JumpType.values()) {
ArrayList<Object[]> currentPossibilities = possibilities.get(jumpType);
Object[] sample = currentPossibilities.isEmpty() ? new Object[] { NO_KEY, NO_KEY, NO_KEY } : currentPossibilities.get(0);
if (jumpType == JumpType.psm || ((Long) sample[0] == NO_KEY && (Long) sample[1] == NO_KEY)) {
if (!reinitializedMap.get(jumpType)) {
possibilities.get(jumpType).clear();
currentSelection.put(jumpType, 0);
}
for (String spectrumTitle : spectrumTitles) {
Object[] keys = new Object[3];
Arrays.fill(keys, NO_KEY);
keys[2] = spectrumTitle;
possibilities.get(jumpType).add(keys);
}
}
}
}
}
}
if (possibilities.get(selectedJumpType).size() > 0) {
if (possibilities.get(selectedJumpType).size() > 1) {
previousButton.setEnabled(true);
nextButton.setEnabled(true);
} else {
// possibilities.size() == 1
previousButton.setEnabled(false);
nextButton.setEnabled(false);
}
updateSelectionInTab();
} else {
previousButton.setEnabled(false);
nextButton.setEnabled(false);
if (!inputLowerCase.equalsIgnoreCase(welcomeText.get(selectedJumpType))) {
indexLabel.setText("(no matches)");
} else {
indexLabel.setText("");
}
}
peptideShakerGUI.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
inputTxt.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
inputTxt.requestFocus();
} else {
indexLabel.setText("");
previousButton.setEnabled(false);
nextButton.setEnabled(false);
inputTxt.setText(welcomeText.get(selectedJumpType));
inputTxt.selectAll();
inputTxt.requestFocus();
}
}
lastLabel.put(selectedJumpType, indexLabel.getText());
}
} catch (Exception e) {
peptideShakerGUI.catchException(e);
} finally {
searchMutex.release();
}
}
}.start();
}
use of com.compomics.util.experiment.personalization.ExperimentObject.NO_KEY in project peptide-shaker by compomics.
the class OverviewPanel method updateSelection.
/**
* Update the selected protein and peptide.
*
* @param scrollToVisible if true the table also scrolls to make the
* selected row visible
*/
public void updateSelection(boolean scrollToVisible) {
int proteinRow = 0;
Identification identification = peptideShakerGUI.getIdentification();
long proteinKey = peptideShakerGUI.getSelectedProteinKey();
long peptideKey = peptideShakerGUI.getSelectedPeptideKey();
String spectrumFile = peptideShakerGUI.getSelectedSpectrumFile();
String spectrumTitle = peptideShakerGUI.getSelectedSpectrumTitle();
if (proteinKey == NO_KEY && peptideKey == NO_KEY && spectrumFile != null && spectrumTitle != null) {
long psmKey = SpectrumMatch.getKey(spectrumFile, spectrumTitle);
SpectrumMatch spectrumMatch = identification.getSpectrumMatch(psmKey);
if (spectrumMatch != null && spectrumMatch.getBestPeptideAssumption() != null) {
Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
peptideKey = peptide.getMatchingKey(peptideShakerGUI.getIdentificationParameters().getSequenceMatchingParameters());
}
}
if (proteinKey == NO_KEY && peptideKey != NO_KEY) {
final long peptideKeyFinal = peptideKey;
ProteinMatch tempProteinMatch = identification.getProteinIdentification().parallelStream().map(key -> identification.getProteinMatch(key)).filter(proteinMatch -> Arrays.stream(proteinMatch.getPeptideMatchesKeys()).anyMatch(key -> key == peptideKeyFinal)).findAny().orElse(null);
if (tempProteinMatch != null) {
proteinKey = tempProteinMatch.getKey();
peptideShakerGUI.setSelectedItems(proteinKey, peptideKey, spectrumFile, spectrumTitle);
}
}
if (proteinKey != NO_KEY) {
proteinRow = getProteinRow(proteinKey);
}
if (proteinKeys.length == 0) {
clearData();
return;
}
if (proteinRow == -1) {
peptideShakerGUI.resetSelectedItems();
proteinTableMouseReleased(null);
} else if (proteinTable.getSelectedRow() != proteinRow) {
proteinTable.setRowSelectionInterval(proteinRow, proteinRow);
if (scrollToVisible) {
proteinTable.scrollRectToVisible(proteinTable.getCellRect(proteinRow, 0, false));
}
proteinTableMouseReleased(null);
}
int peptideRow = 0;
if (peptideKey != NO_KEY) {
peptideRow = getPeptideRow(peptideKey);
}
if (peptideTable.getSelectedRow() != peptideRow && peptideRow != -1) {
peptideTable.setRowSelectionInterval(peptideRow, peptideRow);
if (scrollToVisible) {
peptideTable.scrollRectToVisible(peptideTable.getCellRect(peptideRow, 0, false));
}
peptideTableMouseReleased(null);
}
int psmRow = 0;
if (spectrumFile != null && spectrumTitle != null) {
long psmKey = SpectrumMatch.getKey(spectrumFile, spectrumTitle);
psmRow = getPsmRow(psmKey);
}
if (psmTable.getSelectedRow() != psmRow && psmRow != -1 && psmRow < psmTable.getRowCount()) {
psmTable.setRowSelectionInterval(psmRow, psmRow);
if (scrollToVisible) {
psmTable.scrollRectToVisible(psmTable.getCellRect(psmRow, 0, false));
}
psmTableMouseReleased(null);
}
}
use of com.compomics.util.experiment.personalization.ExperimentObject.NO_KEY in project peptide-shaker by compomics.
the class ProteinFractionsPanel method updateSelection.
/**
* Update the selected protein and peptide.
*/
public void updateSelection() {
int proteinRow = 0;
long proteinKey = peptideShakerGUI.getSelectedProteinKey();
long peptideKey = peptideShakerGUI.getSelectedPeptideKey();
String spectrumFile = peptideShakerGUI.getSelectedSpectrumFile();
String spectrumTitle = peptideShakerGUI.getSelectedSpectrumTitle();
Identification identification = peptideShakerGUI.getIdentification();
if (proteinKey == NO_KEY && peptideKey == NO_KEY && spectrumFile != null && spectrumTitle != null) {
long psmKey = SpectrumMatch.getKey(spectrumFile, spectrumTitle);
SpectrumMatch spectrumMatch = (SpectrumMatch) peptideShakerGUI.getIdentification().retrieveObject(psmKey);
if (spectrumMatch != null && spectrumMatch.getBestPeptideAssumption() != null) {
Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
peptideKey = peptide.getMatchingKey(peptideShakerGUI.getIdentificationParameters().getSequenceMatchingParameters());
}
}
if (proteinKey == NO_KEY && peptideKey != NO_KEY) {
final long peptideKeyFinal = peptideKey;
ProteinMatch tempProteinMatch = identification.getProteinIdentification().parallelStream().map(key -> identification.getProteinMatch(key)).filter(proteinMatch -> Arrays.stream(proteinMatch.getPeptideMatchesKeys()).anyMatch(key -> key == peptideKeyFinal)).findAny().orElse(null);
if (tempProteinMatch != null) {
peptideShakerGUI.setSelectedItems(tempProteinMatch.getKey(), peptideKey, spectrumFile, spectrumTitle);
}
}
if (proteinKey != NO_KEY) {
proteinRow = getProteinRow(proteinKey);
}
if (proteinKeys.length == 0) {
clearData();
return;
}
if (proteinRow == -1) {
peptideShakerGUI.resetSelectedItems();
} else if (proteinTable.getSelectedRow() != proteinRow) {
proteinTable.setRowSelectionInterval(proteinRow, proteinRow);
proteinTable.scrollRectToVisible(proteinTable.getCellRect(proteinRow, 0, false));
proteinTableKeyReleased(null);
}
}
Aggregations