use of com.compomics.util.experiment.identification.matches.ProteinMatch in project peptide-shaker by compomics.
the class ProteinStructurePanel method pdbMatchesJTableMouseReleased.
// GEN-LAST:event_peptideTableMouseReleased
/**
* Update the PDB structure shown in the Jmol panel.
*
* @param evt
*/
private void pdbMatchesJTableMouseReleased(java.awt.event.MouseEvent evt) {
// GEN-FIRST:event_pdbMatchesJTableMouseReleased
setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
boolean loadStructure = true;
if (pdbMatchesJTable.getSelectedRow() != -1 && currentlyDisplayedPdbFile != null) {
String tempPdbFile = (String) pdbMatchesJTable.getValueAt(pdbMatchesJTable.getSelectedRow(), pdbMatchesJTable.getColumn("PDB").getModelIndex());
if (currentlyDisplayedPdbFile.equalsIgnoreCase(tempPdbFile)) {
loadStructure = false;
}
}
if (loadStructure) {
// just a trick to make sure that the users cannot select
// another row until the selection has been updated
this.setEnabled(false);
DefaultTableModel dm = (DefaultTableModel) pdbChainsJTable.getModel();
dm.getDataVector().removeAllElements();
dm.fireTableDataChanged();
// clear the peptide to pdb mappings in the peptide table
for (int i = 0; i < peptideTable.getRowCount(); i++) {
peptideTable.setValueAt(false, i, peptideTable.getColumn("PDB").getModelIndex());
}
// select the peptide in the table again
int peptideRow = 0;
long peptideKey = peptideShakerGUI.getSelectedPeptideKey();
if (peptideKey != NO_KEY) {
peptideRow = getPeptideRow(peptideKey);
}
if (peptideTable.getRowCount() > 0) {
peptideTable.setRowSelectionInterval(peptideRow, peptideRow);
peptideTable.scrollRectToVisible(peptideTable.getCellRect(peptideRow, peptideRow, false));
}
// empty the jmol panel
if (jmolStructureShown) {
jmolPanel = new JmolPanel();
pdbPanel.removeAll();
pdbPanel.add(jmolPanel);
pdbPanel.revalidate();
pdbPanel.repaint();
jmolStructureShown = false;
currentlyDisplayedPdbFile = null;
((TitledBorder) pdbOuterPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "PDB Structure" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
pdbOuterPanel.repaint();
}
if (pdbMatchesJTable.getSelectedRow() != -1) {
currentlyDisplayedPdbFile = (String) pdbMatchesJTable.getValueAt(pdbMatchesJTable.getSelectedRow(), pdbMatchesJTable.getColumn("PDB").getModelIndex());
// open protein link in web browser
if (pdbMatchesJTable.getSelectedColumn() == pdbMatchesJTable.getColumn("PDB").getModelIndex() && evt.getButton() == MouseEvent.BUTTON1 && ((String) pdbMatchesJTable.getValueAt(pdbMatchesJTable.getSelectedRow(), pdbMatchesJTable.getSelectedColumn())).lastIndexOf("<a href=\"") != -1) {
String temp = currentlyDisplayedPdbFile.substring(currentlyDisplayedPdbFile.indexOf("\"") + 1);
currentlyDisplayedPdbFile = temp.substring(0, temp.indexOf("\""));
this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
BareBonesBrowserLaunch.openURL(currentlyDisplayedPdbFile);
this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
}
// get the pdb file
int selectedPdbTableIndex = (Integer) pdbMatchesJTable.getValueAt(pdbMatchesJTable.getSelectedRow(), 0);
PdbParameter lParam = uniProtPdb.getPdbs().get(selectedPdbTableIndex - 1);
chains = lParam.getBlocks();
// get the protein sequence
SelfUpdatingTableModel proteinTableModel = (SelfUpdatingTableModel) proteinTable.getModel();
int proteinIndex = proteinTableModel.getViewIndex(proteinTable.getSelectedRow());
long proteinKey = proteinKeys[proteinIndex];
ProteinMatch proteinMatch = peptideShakerGUI.getIdentification().getProteinMatch(proteinKey);
String proteinSequence = peptideShakerGUI.getSequenceProvider().getSequence(proteinMatch.getLeadingAccession());
// add the chain information to the table
for (int j = 0; j < chains.length; j++) {
XYDataPoint temp = new XYDataPoint(chains[j].getStartProtein(), chains[j].getEndProtein());
if (chains[j].getStartProtein() != chains[j].getEndProtein()) {
((DefaultTableModel) pdbChainsJTable.getModel()).addRow(new Object[] { (j + 1), chains[j].getBlock(), temp, (((double) chains[j].getEndProtein() - chains[j].getStartProtein()) / proteinSequence.length()) * 100 });
}
}
((JSparklinesIntervalChartTableCellRenderer) pdbChainsJTable.getColumn("PDB-Protein").getCellRenderer()).setMaxValue(proteinSequence.length());
if (pdbChainsJTable.getRowCount() > 0) {
((TitledBorder) pdbChainsPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "PDB Chains (" + pdbChainsJTable.getRowCount() + ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
} else {
((TitledBorder) pdbChainsPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "PDB Chains" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
}
pdbChainsPanel.repaint();
if (pdbChainsJTable.getRowCount() > 0) {
pdbChainsJTable.setRowSelectionInterval(0, 0);
pdbChainsJTable.scrollRectToVisible(pdbChainsJTable.getCellRect(0, 0, false));
pdbChainsJTableMouseReleased(null);
}
} else {
((TitledBorder) pdbChainsPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "PDB Chains" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
pdbChainsPanel.repaint();
}
// give the power back to the user ;)
this.setEnabled(true);
} else {
// open protein link in web browser
if (pdbMatchesJTable.getSelectedColumn() == pdbMatchesJTable.getColumn("PDB").getModelIndex() && evt.getButton() == MouseEvent.BUTTON1 && ((String) pdbMatchesJTable.getValueAt(pdbMatchesJTable.getSelectedRow(), pdbMatchesJTable.getSelectedColumn())).lastIndexOf("<a href=\"") != -1) {
String temp = currentlyDisplayedPdbFile.substring(currentlyDisplayedPdbFile.indexOf("\"") + 1);
currentlyDisplayedPdbFile = temp.substring(0, temp.indexOf("\""));
this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
BareBonesBrowserLaunch.openURL(currentlyDisplayedPdbFile);
this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
}
}
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
}
use of com.compomics.util.experiment.identification.matches.ProteinMatch in project peptide-shaker by compomics.
the class ProteinStructurePanel method updatePdbTable.
/**
* Update the PDB table according to the selected protein in the protein
* table.
*
* @param proteinKey the current protein key
*/
private void updatePdbTable(long aProteinKey) {
final long proteinKey = aProteinKey;
progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
progressDialog.setPrimaryProgressCounterIndeterminate(true);
new Thread(new Runnable() {
public void run() {
progressDialog.setTitle("Getting PDB Data. Please Wait...");
try {
progressDialog.setVisible(true);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}, "ProgressDialog").start();
new Thread("ExtractThread") {
@Override
public void run() {
try {
// get the accession number of the main match
ProteinMatch proteinMatch = peptideShakerGUI.getIdentification().getProteinMatch(proteinKey);
String tempAccession = proteinMatch.getLeadingAccession();
// find the pdb matches
// @TODO: make it possible to cancel this process...
uniProtPdb = new FindPdbForUniprotAccessions(tempAccession, progressDialog);
// delete the previous matches
DefaultTableModel dm = (DefaultTableModel) pdbMatchesJTable.getModel();
dm.getDataVector().removeAllElements();
dm.fireTableDataChanged();
dm = (DefaultTableModel) pdbChainsJTable.getModel();
dm.getDataVector().removeAllElements();
dm.fireTableDataChanged();
// clear the peptide to pdb mappings in the peptide table
for (int i = 0; i < peptideTable.getRowCount() && !progressDialog.isRunCanceled(); i++) {
peptideTable.setValueAt(false, i, peptideTable.getColumn("PDB").getModelIndex());
}
int maxNumberOfChains = 1;
// add the new matches to the pdb table
for (int i = 0; i < uniProtPdb.getPdbs().size() && !progressDialog.isRunCanceled(); i++) {
PdbParameter lParam = uniProtPdb.getPdbs().get(i);
((DefaultTableModel) pdbMatchesJTable.getModel()).addRow(new Object[] { i + 1, addPdbDatabaseLink(lParam.getPdbaccession()), lParam.getTitle(), lParam.getExperiment_type(), lParam.getBlocks().length });
if (lParam.getBlocks().length > maxNumberOfChains) {
maxNumberOfChains = lParam.getBlocks().length;
}
}
if (!progressDialog.isRunCanceled()) {
((JSparklinesBarChartTableCellRenderer) pdbMatchesJTable.getColumn("Chains").getCellRenderer()).setMaxValue(maxNumberOfChains);
if (!uniProtPdb.urlWasRead()) {
((TitledBorder) pdbMatchesPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "PDB Matches - Not Available Without Internet Connection!" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
} else {
((TitledBorder) pdbMatchesPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "PDB Matches (" + pdbMatchesJTable.getRowCount() + ")" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
}
pdbMatchesPanel.repaint();
((TitledBorder) pdbChainsPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "PDB Chains" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
pdbChainsPanel.repaint();
}
progressDialog.setRunFinished();
} catch (Exception e) {
progressDialog.setRunFinished();
peptideShakerGUI.catchException(e);
}
}
}.start();
}
use of com.compomics.util.experiment.identification.matches.ProteinMatch 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.identification.matches.ProteinMatch in project peptide-shaker by compomics.
the class ModificationLocalizationScorer method scorePTMs.
/**
* Scores PTMs in a protein match.
*
* @param identification The identification object containing the matches.
* @param proteinMatch The protein match.
* @param identificationParameters The identification parameters.
* @param scorePeptides If true, peptides will be scored as well.
* @param modificationProvider The modification provider to use.
* @param waitingHandler The waiting handler to sue, ignored if null.
*/
public void scorePTMs(Identification identification, ProteinMatch proteinMatch, IdentificationParameters identificationParameters, boolean scorePeptides, ModificationProvider modificationProvider, WaitingHandler waitingHandler) {
HashMap<Integer, ArrayList<String>> confidentSites = new HashMap<>();
HashMap<Integer, HashMap<Integer, HashSet<String>>> ambiguousSites = new HashMap<>();
for (long peptideKey : proteinMatch.getPeptideMatchesKeys()) {
PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
Peptide peptide = peptideMatch.getPeptide();
PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
if (psParameter.getMatchValidationLevel().isValidated() && peptide.getNVariableModifications() > 0) {
PSModificationScores peptideScores = (PSModificationScores) peptideMatch.getUrParam(PSModificationScores.dummy);
if (peptideScores == null || scorePeptides) {
scorePTMs(identification, peptideMatch, identificationParameters, modificationProvider, waitingHandler);
peptideScores = (PSModificationScores) peptideMatch.getUrParam(PSModificationScores.dummy);
}
if (peptideScores != null) {
int[] peptideStart = peptide.getProteinMapping().get(proteinMatch.getLeadingAccession());
for (int confidentSite : peptideScores.getConfidentSites()) {
for (int peptideTempStart : peptideStart) {
int siteOnProtein = peptideTempStart + confidentSite - 1;
ArrayList<String> modificationsAtSite = confidentSites.get(siteOnProtein);
if (modificationsAtSite == null) {
modificationsAtSite = new ArrayList<>();
confidentSites.put(siteOnProtein, modificationsAtSite);
}
for (String modName : peptideScores.getConfidentModificationsAt(confidentSite)) {
if (!modificationsAtSite.contains(modName)) {
modificationsAtSite.add(modName);
}
}
}
}
for (int representativeSite : peptideScores.getRepresentativeSites()) {
HashMap<Integer, HashSet<String>> peptideAmbiguousSites = peptideScores.getAmbiguousModificationsAtRepresentativeSite(representativeSite);
for (int peptideTempStart : peptideStart) {
int proteinRepresentativeSite = peptideTempStart + representativeSite - 1;
HashMap<Integer, HashSet<String>> proteinAmbiguousSites = ambiguousSites.get(proteinRepresentativeSite);
if (proteinAmbiguousSites == null) {
proteinAmbiguousSites = new HashMap<>(peptideAmbiguousSites.size());
ambiguousSites.put(proteinRepresentativeSite, proteinAmbiguousSites);
}
for (int peptideSite : peptideAmbiguousSites.keySet()) {
int siteOnProtein = peptideTempStart + peptideSite - 1;
proteinAmbiguousSites.put(siteOnProtein, peptideAmbiguousSites.get(peptideSite));
}
}
}
}
}
}
// remove ambiguous sites where a confident was found and merge overlapping groups
PSModificationScores proteinScores = new PSModificationScores();
ArrayList<Integer> representativeSites = new ArrayList<>(ambiguousSites.keySet());
Collections.sort(representativeSites);
for (Integer representativeSite : representativeSites) {
HashMap<Integer, HashSet<String>> secondarySitesMap = ambiguousSites.get(representativeSite);
ArrayList<Integer> secondarySites = new ArrayList<>(secondarySitesMap.keySet());
for (int secondarySite : secondarySites) {
ArrayList<String> confidentModifications = confidentSites.get(secondarySite);
if (confidentModifications != null) {
boolean sameModification = confidentModifications.stream().map(modName -> modificationProvider.getModification(modName)).anyMatch(confidentModification -> secondarySitesMap.get(secondarySite).stream().map(modName -> modificationProvider.getModification(modName)).anyMatch(secondaryModification -> secondaryModification.getMass() == confidentModification.getMass()));
if (sameModification) {
ambiguousSites.remove(representativeSite);
break;
}
}
if (secondarySite != representativeSite) {
ArrayList<Integer> tempRepresentativeSites = new ArrayList<>(ambiguousSites.keySet());
Collections.sort(tempRepresentativeSites);
for (Integer previousSite : tempRepresentativeSites) {
if (previousSite >= representativeSite) {
break;
}
if (previousSite == secondarySite) {
HashMap<Integer, HashSet<String>> previousSites = ambiguousSites.get(previousSite);
HashSet<String> previousModifications = previousSites.get(previousSite);
boolean sameModification = previousModifications.stream().map(modName -> modificationProvider.getModification(modName)).anyMatch(previousModification -> secondarySitesMap.get(secondarySite).stream().map(modName -> modificationProvider.getModification(modName)).anyMatch(secondaryModification -> secondaryModification.getMass() == previousModification.getMass()));
if (sameModification) {
for (int tempSecondarySite : secondarySitesMap.keySet()) {
if (!previousSites.containsKey(secondarySite)) {
previousSites.put(tempSecondarySite, secondarySitesMap.get(tempSecondarySite));
}
}
ambiguousSites.remove(representativeSite);
}
}
}
}
}
}
for (int confidentSite : confidentSites.keySet()) {
for (String modName : confidentSites.get(confidentSite)) {
proteinScores.addConfidentModificationSite(modName, confidentSite);
}
}
for (int representativeSite : ambiguousSites.keySet()) {
proteinScores.addAmbiguousModificationSites(representativeSite, ambiguousSites.get(representativeSite));
}
proteinMatch.addUrParam(proteinScores);
}
use of com.compomics.util.experiment.identification.matches.ProteinMatch in project peptide-shaker by compomics.
the class QCPanel method getProteinDataset.
/**
* Returns the dataset to use for the protein QC plot.
*/
private void getProteinDataset() {
progressDialog.setPrimaryProgressCounterIndeterminate(false);
progressDialog.setMaxPrimaryProgressCounter(peptideShakerGUI.getIdentification().getProteinIdentification().size());
progressDialog.setValue(0);
IdentificationFeaturesGenerator identificationFeaturesGenerator = peptideShakerGUI.getIdentificationFeaturesGenerator();
maxValue = Double.MIN_VALUE;
validatedValues = new ArrayList<>();
validatedDoubtfulValues = new ArrayList<>();
nonValidatedValues = new ArrayList<>();
validatedDecoyValues = new ArrayList<>();
nonValidatedDecoyValues = new ArrayList<>();
ProteinMatchesIterator proteinMatchesIterator = peptideShakerGUI.getIdentification().getProteinMatchesIterator(progressDialog);
ProteinMatch proteinMatch;
while ((proteinMatch = proteinMatchesIterator.next()) != null) {
long proteinKey = proteinMatch.getKey();
if (progressDialog.isRunCanceled()) {
break;
}
double value = 0;
if (proteinNumberValidatedPeptidesJRadioButton.isSelected()) {
value = identificationFeaturesGenerator.getNValidatedPeptides(proteinKey);
} else if (proteinSpectrumCountingScoreJRadioButton.isSelected()) {
value = identificationFeaturesGenerator.getSpectrumCounting(proteinKey);
} else if (proteinSequenceCoverageJRadioButton.isSelected()) {
HashMap<Integer, Double> sequenceCoverage = peptideShakerGUI.getIdentificationFeaturesGenerator().getSequenceCoverage(proteinKey);
Double sequenceCoverageConfident = 100 * sequenceCoverage.get(MatchValidationLevel.confident.getIndex());
Double sequenceCoverageDoubtful = 100 * sequenceCoverage.get(MatchValidationLevel.doubtful.getIndex());
value = sequenceCoverageConfident + sequenceCoverageDoubtful;
} else if (proteinSequenceLengthJRadioButton.isSelected()) {
String proteinSequence = peptideShakerGUI.getSequenceProvider().getSequence(proteinMatch.getLeadingAccession());
value = proteinSequence.length();
}
PSParameter proteinParameter = (PSParameter) proteinMatch.getUrParam(PSParameter.dummy);
if (!proteinParameter.getHidden()) {
if (value > maxValue) {
maxValue = value;
}
if (!proteinMatch.isDecoy()) {
if (proteinParameter.getMatchValidationLevel().isValidated()) {
if (proteinParameter.getMatchValidationLevel() == MatchValidationLevel.confident) {
validatedValues.add(value);
} else {
validatedDoubtfulValues.add(value);
}
} else {
nonValidatedValues.add(value);
}
}
}
progressDialog.increasePrimaryProgressCounter();
}
}
Aggregations