use of com.compomics.util.experiment.biology.proteins.Peptide in project peptide-shaker by compomics.
the class SpectrumIdentificationPanel method populateIdResultsTable.
/**
* Populates the assumptions table with assumptions from the selected
* spectrum match.
*
* @param spectrumMatchKey the key of the selected spectrum match
*/
private void populateIdResultsTable(long spectrumMatchKey) {
currentAssumptionsList = new ArrayList<>(8);
searchResultsTablePeptideTooltips = new ArrayList<>(8);
SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumMatchKey);
if (spectrumMatch != null) {
// sort peptides by pep, tool, and sequence
HashMap<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> peptideAssumptions = spectrumMatch.getPeptideAssumptionsMap();
TreeMap<Double, TreeMap<Integer, TreeMap<String, ArrayList<PeptideAssumption>>>> peptideAssumptionsByPep = new TreeMap<>();
for (Entry<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> entry1 : peptideAssumptions.entrySet()) {
int tool = entry1.getKey();
for (Entry<Double, ArrayList<PeptideAssumption>> entry2 : entry1.getValue().entrySet()) {
ArrayList<PeptideAssumption> assumptions = entry2.getValue();
for (PeptideAssumption peptideAssumption : assumptions) {
PSParameter psParameter = (PSParameter) peptideAssumption.getUrParam(PSParameter.dummy);
double pep = psParameter.getProbability();
TreeMap<Integer, TreeMap<String, ArrayList<PeptideAssumption>>> mapAtPep = peptideAssumptionsByPep.get(pep);
if (mapAtPep == null) {
mapAtPep = new TreeMap<>();
peptideAssumptionsByPep.put(pep, mapAtPep);
}
TreeMap<String, ArrayList<PeptideAssumption>> toolMap = mapAtPep.get(tool);
if (toolMap == null) {
toolMap = new TreeMap<>();
mapAtPep.put(tool, toolMap);
}
String sequence = peptideAssumption.getPeptide().getSequence();
ArrayList<PeptideAssumption> sequenceAssumptions = toolMap.get(sequence);
if (sequenceAssumptions == null) {
sequenceAssumptions = new ArrayList<>(1);
toolMap.put(sequence, sequenceAssumptions);
}
sequenceAssumptions.add(peptideAssumption);
}
}
}
// Add peptides to the list to display
peptideAssumptionsByPep.values().stream().flatMap(subMap -> subMap.values().stream()).flatMap(subMap -> subMap.values().stream()).flatMap(assumptionList -> assumptionList.stream()).forEach(peptideAssumption -> {
Peptide peptide = peptideAssumption.getPeptide();
if (peptideShakerGUI.getIdentificationParameters().getPeptideAssumptionFilter().validatePeptide(peptide, peptideShakerGUI.getIdentificationParameters().getSequenceMatchingParameters(), peptideShakerGUI.getIdentificationParameters().getSearchParameters().getDigestionParameters())) {
if (vallidatedPsmsCheckBox.isSelected()) {
PSParameter psParameter = (PSParameter) peptideAssumption.getUrParam(PSParameter.dummy);
if (psParameter.getMatchValidationLevel().isValidated()) {
currentAssumptionsList.add(peptideAssumption);
searchResultsTablePeptideTooltips.add(peptideShakerGUI.getDisplayFeaturesGenerator().getPeptideModificationTooltipAsHtml(peptide));
}
} else {
currentAssumptionsList.add(peptideAssumption);
searchResultsTablePeptideTooltips.add(peptideShakerGUI.getDisplayFeaturesGenerator().getPeptideModificationTooltipAsHtml(peptide));
}
}
});
// Add tags to the list to display. Scores cannot be compared between algorithms so keep sorting by tool.
spectrumMatch.getTagAssumptionsMap().values().stream().flatMap(subMap -> subMap.values().stream()).flatMap(array -> array.stream()).forEach(tagAssumption -> {
// @TODO: filter the tags as well? and respect the vallidatedPsmsCheckBox value!
currentAssumptionsList.add(tagAssumption);
String toolTip = peptideShakerGUI.getDisplayFeaturesGenerator().getTagModificationTooltipAsHtml(tagAssumption.getTag());
searchResultsTablePeptideTooltips.add(toolTip);
});
}
}
use of com.compomics.util.experiment.biology.proteins.Peptide 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();
}
use of com.compomics.util.experiment.biology.proteins.Peptide 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.biology.proteins.Peptide in project peptide-shaker by compomics.
the class ModificationLocalizationScorer method attachDeltaScore.
/**
* Scores the modification locations using the delta score.
*
* @param identification Identification object containing the matches.
* @param spectrumMatch The spectrum match of interest.
* @param sequenceMatchingParameters The sequence matching preferences.
* @param modificationProvider The modification provider to use.
*/
public void attachDeltaScore(Identification identification, SpectrumMatch spectrumMatch, SequenceMatchingParameters sequenceMatchingParameters, ModificationProvider modificationProvider) {
PSModificationScores modificationScores = (PSModificationScores) spectrumMatch.getUrParam(PSModificationScores.dummy);
if (modificationScores == null) {
modificationScores = new PSModificationScores();
spectrumMatch.addUrParam(modificationScores);
}
Peptide psPeptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
HashMap<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> assumptions = spectrumMatch.getPeptideAssumptionsMap();
String mainSequence = psPeptide.getSequence();
HashMap<String, List<Integer>> modificationParameters = Arrays.stream(psPeptide.getVariableModifications()).collect(Collectors.groupingBy(ModificationMatch::getModification, HashMap::new, Collectors.mapping(ModificationMatch::getSite, Collectors.toList())));
for (Entry<String, List<Integer>> entry : modificationParameters.entrySet()) {
String modName = entry.getKey();
List<Integer> sites = entry.getValue();
Modification modification1 = modificationProvider.getModification(modName);
for (int modSite : sites) {
double refP = 1, secondaryP = 1;
for (TreeMap<Double, ArrayList<PeptideAssumption>> algorithmAssumptions : assumptions.values()) {
for (ArrayList<PeptideAssumption> assumptionsAtScore : algorithmAssumptions.values()) {
for (PeptideAssumption peptideAssumption : assumptionsAtScore) {
if (peptideAssumption.getPeptide().getSequence().equals(mainSequence)) {
boolean modificationAtSite = false, modificationFound = false;
Peptide peptide = peptideAssumption.getPeptide();
for (ModificationMatch modMatch : peptide.getVariableModifications()) {
Modification modification2 = modificationProvider.getModification(modMatch.getModification());
if (modification1.getMass() == modification2.getMass()) {
modificationFound = true;
PSParameter psParameter = (PSParameter) peptideAssumption.getUrParam(PSParameter.dummy);
double p = psParameter.getProbability();
if (modMatch.getSite() == modSite) {
modificationAtSite = true;
if (p < refP) {
refP = p;
}
}
}
}
if (!modificationAtSite && modificationFound) {
PSParameter psParameter = (PSParameter) peptideAssumption.getUrParam(PSParameter.dummy);
double p = psParameter.getProbability();
if (p < secondaryP) {
secondaryP = p;
}
}
}
}
}
}
ModificationScoring modificationScoring = modificationScores.getModificationScoring(modName);
if (modificationScoring == null) {
modificationScoring = new ModificationScoring(modName);
modificationScores.addModificationScoring(modName, modificationScoring);
}
if (secondaryP < refP) {
secondaryP = refP;
}
double deltaScore = (secondaryP - refP) * 100;
modificationScoring.setDeltaScore(modSite, deltaScore);
}
identification.updateObject(spectrumMatch.getKey(), spectrumMatch);
}
}
use of com.compomics.util.experiment.biology.proteins.Peptide 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);
}
Aggregations