Search in sources :

Example 1 with Identification

use of com.compomics.util.experiment.identification.Identification 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);
        }
    }
}
Also used : Color(java.awt.Color) PsPeptideFeature(com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature) PsProteinFeature(com.compomics.util.io.export.features.peptideshaker.PsProteinFeature) Arrays(java.util.Arrays) JSparklinesArrayListBarChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesArrayListBarChartTableCellRenderer) NO_KEY(com.compomics.util.experiment.personalization.ExperimentObject.NO_KEY) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) FileAndFileFilter(com.compomics.util.gui.file_handling.FileAndFileFilter) BareBonesBrowserLaunch(com.compomics.util.examples.BareBonesBrowserLaunch) JSparklinesBarChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesBarChartTableCellRenderer) FileChooserUtil(com.compomics.util.gui.file_handling.FileChooserUtil) JTableHeader(javax.swing.table.JTableHeader) ProteinInferencePeptideLevelDialog(eu.isas.peptideshaker.gui.protein_inference.ProteinInferencePeptideLevelDialog) PeptideShakerGUI(eu.isas.peptideshaker.gui.PeptideShakerGUI) MouseAdapter(java.awt.event.MouseAdapter) TitledBorder(javax.swing.border.TitledBorder) JSparklinesIntegerIconTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesIntegerIconTableCellRenderer) TableProperties(com.compomics.util.gui.TableProperties) SpectrumCountingMethod(com.compomics.util.experiment.quantification.spectrumcounting.SpectrumCountingMethod) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) TableModelEvent(javax.swing.event.TableModelEvent) ExportScheme(com.compomics.util.io.export.ExportScheme) DefaultTableModel(javax.swing.table.DefaultTableModel) TrueFalseIconRenderer(no.uib.jsparklines.extra.TrueFalseIconRenderer) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) PSExportFactory(eu.isas.peptideshaker.export.PSExportFactory) SelfUpdatingTableModel(com.compomics.util.gui.tablemodels.SelfUpdatingTableModel) Util(com.compomics.util.Util) KeyEvent(java.awt.event.KeyEvent) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) GuiUtilities(com.compomics.util.gui.GuiUtilities) DisplayParameters(eu.isas.peptideshaker.preferences.DisplayParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) Dimension(java.awt.Dimension) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) Graphics(java.awt.Graphics) Toolkit(java.awt.Toolkit) IntStream(java.util.stream.IntStream) Rectangle(java.awt.Rectangle) FindPdbForUniprotAccessions(com.compomics.util.pdbfinder.FindPdbForUniprotAccessions) HelpDialog(com.compomics.util.gui.error_handlers.HelpDialog) PdbParameter(com.compomics.util.pdbfinder.pdb.PdbParameter) HashMap(java.util.HashMap) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) PlotOrientation(org.jfree.chart.plot.PlotOrientation) TableModelListener(javax.swing.event.TableModelListener) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) JSparklinesIntervalChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesIntervalChartTableCellRenderer) JSparklinesMultiIntervalChartTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesMultiIntervalChartTableCellRenderer) JSparklinesIntegerColorTableCellRenderer(no.uib.jsparklines.renderers.JSparklinesIntegerColorTableCellRenderer) XYPlottingDialog(com.compomics.util.gui.XYPlottingDialog) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ProteinTableModel(eu.isas.peptideshaker.gui.tablemodels.ProteinTableModel) JmolAdapter(org.jmol.api.JmolAdapter) XYDataPoint(no.uib.jsparklines.data.XYDataPoint) ProteinInferenceDialog(eu.isas.peptideshaker.gui.protein_inference.ProteinInferenceDialog) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) ExportFeature(com.compomics.util.io.export.ExportFeature) Identification(com.compomics.util.experiment.identification.Identification) IOException(java.io.IOException) JmolViewer(org.jmol.api.JmolViewer) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ExportGraphicsDialog(com.compomics.util.gui.export.graphics.ExportGraphicsDialog) PdbBlock(com.compomics.util.pdbfinder.pdb.PdbBlock) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) ExportFormat(com.compomics.util.io.export.ExportFormat) HtmlLinksRenderer(no.uib.jsparklines.extra.HtmlLinksRenderer) SmarterJmolAdapter(org.jmol.adapter.smarter.SmarterJmolAdapter) GeneDetailsDialog(com.compomics.util.gui.genes.GeneDetailsDialog) StartIndexes(no.uib.jsparklines.data.StartIndexes) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) javax.swing(javax.swing) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) Identification(com.compomics.util.experiment.identification.Identification) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) XYDataPoint(no.uib.jsparklines.data.XYDataPoint)

Example 2 with Identification

use of com.compomics.util.experiment.identification.Identification 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);
}
Also used : ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) Arrays(java.util.Arrays) ModificationType(com.compomics.util.experiment.biology.modifications.ModificationType) HashMap(java.util.HashMap) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) ModificationScoring(com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring) TreeSet(java.util.TreeSet) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Modification(com.compomics.util.experiment.biology.modifications.Modification) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ModificationUtils(com.compomics.util.experiment.identification.utils.ModificationUtils) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) PhosphoRS(com.compomics.util.experiment.identification.modification.scores.PhosphoRS) ModificationProvider(com.compomics.util.experiment.biology.modifications.ModificationProvider) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) ExperimentObject(com.compomics.util.experiment.personalization.ExperimentObject) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Set(java.util.Set) Identification(com.compomics.util.experiment.identification.Identification) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ModificationLocalizationScore(com.compomics.util.experiment.identification.modification.ModificationLocalizationScore) Collectors(java.util.stream.Collectors) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) List(java.util.List) Stream(java.util.stream.Stream) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) Collections(java.util.Collections) ModificationLocalizationParameters(com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) HashSet(java.util.HashSet)

Example 3 with Identification

use of com.compomics.util.experiment.identification.Identification in project peptide-shaker by compomics.

the class ModificationLocalizationScorer method attachProbabilisticScore.

/**
 * Attaches the selected probabilistic modification score.
 *
 * @param spectrumMatch The spectrum match studied, the score will be
 * calculated for the best assumption only.
 * @param sequenceProvider The protein sequence provider to use.
 * @param spectrumProvider The spectrum provider to use.
 * @param modificationProvider The modification provider to use.
 * @param identificationParameters The identification parameters.
 * @param peptideSpectrumAnnotator The peptide spectrum annotator to use.
 * @param identification The identification object containing the matches.
 */
private void attachProbabilisticScore(SpectrumMatch spectrumMatch, SequenceProvider sequenceProvider, SpectrumProvider spectrumProvider, ModificationProvider modificationProvider, IdentificationParameters identificationParameters, PeptideSpectrumAnnotator peptideSpectrumAnnotator, Identification identification) {
    SearchParameters searchParameters = identificationParameters.getSearchParameters();
    AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
    ModificationLocalizationParameters scoringParameters = identificationParameters.getModificationLocalizationParameters();
    SequenceMatchingParameters sequenceMatchingParameters = identificationParameters.getSequenceMatchingParameters();
    SequenceMatchingParameters modificationSequenceMatchingParameters = scoringParameters.getSequenceMatchingParameters();
    ModificationParameters modificationParameters = searchParameters.getModificationParameters();
    PSModificationScores modificationScores = (PSModificationScores) spectrumMatch.getUrParam(PSModificationScores.dummy);
    if (modificationScores != null) {
        modificationScores = new PSModificationScores();
        spectrumMatch.addUrParam(modificationScores);
    }
    HashMap<Double, ArrayList<Modification>> modificationsMap = new HashMap<>(1);
    HashMap<Double, Integer> nMod = new HashMap<>(1);
    PeptideAssumption bestPeptideAssumption = spectrumMatch.getBestPeptideAssumption();
    Peptide peptide = bestPeptideAssumption.getPeptide();
    for (ModificationMatch modificationMatch : peptide.getVariableModifications()) {
        Modification refMod = modificationProvider.getModification(modificationMatch.getModification());
        double modMass = refMod.getMass();
        if (!modificationsMap.containsKey(modMass)) {
            ArrayList<Modification> modifications = modificationFactory.getSameMassNotFixedModifications(modMass, searchParameters).stream().map(modification -> modificationProvider.getModification(modification)).collect(Collectors.toCollection(ArrayList::new));
            modificationsMap.put(modMass, modifications);
            nMod.put(modMass, 1);
        } else {
            nMod.put(modMass, nMod.get(modMass) + 1);
        }
    }
    if (!modificationsMap.isEmpty()) {
        String spectrumFile = spectrumMatch.getSpectrumFile();
        String spectrumTitle = spectrumMatch.getSpectrumTitle();
        Spectrum spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
        SpecificAnnotationParameters specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, bestPeptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
        for (double modMass : modificationsMap.keySet()) {
            HashMap<Integer, Double> scores = null;
            if (scoringParameters.getSelectedProbabilisticScore() == ModificationLocalizationScore.PhosphoRS) {
                scores = PhosphoRS.getSequenceProbabilities(peptide, modificationsMap.get(modMass), modificationParameters, spectrum, sequenceProvider, annotationParameters, specificAnnotationParameters, scoringParameters.isProbabilisticScoreNeutralLosses(), sequenceMatchingParameters, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
                if (scores == null) {
                    throw new IllegalArgumentException("An error occurred while scoring spectrum " + spectrumTitle + " of file " + spectrumFile + " with PhosphoRS.");
                // Most likely a compatibility issue with utilities
                }
            }
            if (scores != null) {
                // remap to searched modifications
                Modification mappedModification = null;
                String peptideSequence = peptide.getSequence();
                for (int site : scores.keySet()) {
                    if (site == 0) {
                        // N-term mod
                        for (Modification modification : modificationsMap.get(modMass)) {
                            if (modification.getModificationType().isNTerm()) {
                                mappedModification = modification;
                                break;
                            }
                        }
                        if (mappedModification == null) {
                            throw new IllegalArgumentException("Could not map the PTM of mass " + modMass + " on the N-terminus of the peptide " + peptideSequence + ".");
                        }
                    } else if (site == peptideSequence.length() + 1) {
                        // C-term mod
                        for (Modification modification : modificationsMap.get(modMass)) {
                            if (modification.getModificationType().isCTerm()) {
                                mappedModification = modification;
                                break;
                            }
                        }
                        if (mappedModification == null) {
                            throw new IllegalArgumentException("Could not map the PTM of mass " + modMass + " on the C-terminus of the peptide " + peptideSequence + ".");
                        }
                    } else {
                        for (Modification modification : modificationsMap.get(modMass)) {
                            mappedModification = modification;
                            break;
                        }
                        if (mappedModification == null) {
                            throw new IllegalArgumentException("Could not map the PTM of mass " + modMass + " at site " + site + " in peptide " + peptide.getSequence() + ".");
                        }
                    }
                    String modName = mappedModification.getName();
                    ModificationScoring modificationScoring = modificationScores.getModificationScoring(modName);
                    if (modificationScoring == null) {
                        modificationScoring = new ModificationScoring(modName);
                        modificationScores.addModificationScoring(modName, modificationScoring);
                    }
                    modificationScoring.setProbabilisticScore(site, scores.get(site));
                }
            }
        }
        identification.updateObject(spectrumMatch.getKey(), spectrumMatch);
    }
}
Also used : ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) Arrays(java.util.Arrays) ModificationType(com.compomics.util.experiment.biology.modifications.ModificationType) HashMap(java.util.HashMap) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) ModificationScoring(com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring) TreeSet(java.util.TreeSet) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Modification(com.compomics.util.experiment.biology.modifications.Modification) WaitingHandler(com.compomics.util.waiting.WaitingHandler) ProteinMatch(com.compomics.util.experiment.identification.matches.ProteinMatch) ModificationUtils(com.compomics.util.experiment.identification.utils.ModificationUtils) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) PhosphoRS(com.compomics.util.experiment.identification.modification.scores.PhosphoRS) ModificationProvider(com.compomics.util.experiment.biology.modifications.ModificationProvider) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) ExperimentObject(com.compomics.util.experiment.personalization.ExperimentObject) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Set(java.util.Set) Identification(com.compomics.util.experiment.identification.Identification) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ModificationLocalizationScore(com.compomics.util.experiment.identification.modification.ModificationLocalizationScore) Collectors(java.util.stream.Collectors) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) List(java.util.List) Stream(java.util.stream.Stream) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) TreeMap(java.util.TreeMap) Entry(java.util.Map.Entry) Collections(java.util.Collections) ModificationLocalizationParameters(com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters) Modification(com.compomics.util.experiment.biology.modifications.Modification) ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) HashMap(java.util.HashMap) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) ArrayList(java.util.ArrayList) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) ModificationScoring(com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) ModificationLocalizationParameters(com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption)

Example 4 with Identification

use of com.compomics.util.experiment.identification.Identification in project peptide-shaker by compomics.

the class QCPanel method getPeptideModificationEnrichmentSpecificityDataset.

/**
 * Returns the dataset for the peptide modification rate QC plot.
 *
 * @return the dataset for the peptide modification rate QC plot
 */
private DefaultCategoryDataset getPeptideModificationEnrichmentSpecificityDataset() {
    ModificationFactory modificationFactory = ModificationFactory.getInstance();
    Identification identification = peptideShakerGUI.getIdentification();
    SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
    IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
    ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
    SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
    ArrayList<String> modNames = modificationParameters.getAllNotFixedModifications();
    HashMap<String, Integer> modifiedPeptidesMap = new HashMap<>(modNames.size());
    HashMap<String, Integer> possiblyModifiedPeptidesMap = new HashMap<>(modNames.size());
    progressDialog.setPrimaryProgressCounterIndeterminate(false);
    progressDialog.setMaxPrimaryProgressCounter(identification.getPeptideIdentification().size());
    progressDialog.setValue(0);
    PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(progressDialog);
    PeptideMatch peptideMatch;
    while ((peptideMatch = peptideMatchesIterator.next()) != null) {
        PSParameter psParameter = (PSParameter) peptideMatch.getUrParam(PSParameter.dummy);
        if (psParameter.getMatchValidationLevel().isValidated()) {
            Peptide peptide = peptideMatch.getPeptide();
            for (String modName : modificationParameters.getAllNotFixedModifications()) {
                Modification modification = modificationFactory.getModification(modName);
                int[] possibleSites = ModificationUtils.getPossibleModificationSites(peptide, modification, sequenceProvider, modificationSequenceMatchingParameters);
                if (possibleSites.length != 0) {
                    Integer nPossiblePeptides = possiblyModifiedPeptidesMap.get(modName);
                    if (nPossiblePeptides == null) {
                        possiblyModifiedPeptidesMap.put(modName, 1);
                    } else {
                        possiblyModifiedPeptidesMap.put(modName, nPossiblePeptides + 1);
                    }
                    boolean modified = false;
                    for (ModificationMatch modificationMatch : peptide.getVariableModifications()) {
                        if (modificationMatch.getModification().equals(modName)) {
                            modified = true;
                            break;
                        }
                    }
                    if (modified) {
                        Integer nModifiedPeptides = modifiedPeptidesMap.get(modName);
                        if (nModifiedPeptides == null) {
                            modifiedPeptidesMap.put(modName, 1);
                        } else {
                            modifiedPeptidesMap.put(modName, nModifiedPeptides + 1);
                        }
                    }
                }
            }
        }
        if (progressDialog.isRunCanceled()) {
            break;
        }
        progressDialog.increaseSecondaryProgressCounter();
    }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String modName : modificationParameters.getAllNotFixedModifications()) {
        Integer nFound = modifiedPeptidesMap.get(modName);
        if (nFound == null) {
            nFound = 0;
        }
        Integer nPossible = possiblyModifiedPeptidesMap.get(modName);
        Double rate = 0.0;
        if (nPossible != null) {
            rate = (100.0 * nFound) / nPossible;
        }
        dataset.addValue(rate, "Modified", modName);
        double rest = 0.0;
        if (nPossible != null) {
            rest = 100 - rate;
        }
        dataset.addValue(rest, "Not Modified", modName);
    }
    return dataset;
}
Also used : Modification(com.compomics.util.experiment.biology.modifications.Modification) ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) HashMap(java.util.HashMap) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) Identification(com.compomics.util.experiment.identification.Identification) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 5 with Identification

use of com.compomics.util.experiment.identification.Identification in project peptide-shaker by compomics.

the class QCPanel method getPeptideModificationEfficiencyDataset.

/**
 * Returns the dataset for the peptide modification efficiency QC plot.
 *
 * @return the dataset for the peptide modification efficiency QC plot
 */
private DefaultCategoryDataset getPeptideModificationEfficiencyDataset() {
    ModificationFactory modificationFactory = ModificationFactory.getInstance();
    Identification identification = peptideShakerGUI.getIdentification();
    SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
    IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
    ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
    SequenceMatchingParameters modificationSequenceMatchingPreferences = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
    ArrayList<String> modNames = modificationParameters.getAllNotFixedModifications();
    HashMap<String, Integer> modifiedSitesMap = new HashMap<>(modNames.size());
    HashMap<String, Integer> possibleSitesMap = new HashMap<>(modNames.size());
    PSParameter psParameter = new PSParameter();
    progressDialog.setPrimaryProgressCounterIndeterminate(false);
    progressDialog.setMaxPrimaryProgressCounter(identification.getPeptideIdentification().size());
    progressDialog.setValue(0);
    PeptideMatchesIterator peptideMatchesIterator = identification.getPeptideMatchesIterator(progressDialog);
    PeptideMatch peptideMatch;
    while ((peptideMatch = peptideMatchesIterator.next()) != null) {
        psParameter = (PSParameter) peptideMatch.getUrParam(psParameter);
        if (psParameter.getMatchValidationLevel().isValidated()) {
            Peptide peptide = peptideMatch.getPeptide();
            HashMap<String, Integer> peptideModificationsMap = new HashMap<>(peptide.getVariableModifications().length);
            for (ModificationMatch modificationMatch : peptide.getVariableModifications()) {
                String modName = modificationMatch.getModification();
                Integer occurrence = peptideModificationsMap.get(modName);
                if (occurrence == null) {
                    peptideModificationsMap.put(modName, 1);
                } else {
                    peptideModificationsMap.put(modName, occurrence + 1);
                }
            }
            for (String modName : modificationParameters.getAllNotFixedModifications()) {
                Modification modification = modificationFactory.getModification(modName);
                int[] possibleSites = ModificationUtils.getPossibleModificationSites(peptide, modification, sequenceProvider, modificationSequenceMatchingPreferences);
                if (possibleSites.length != 0) {
                    Integer occurrencePeptide = peptideModificationsMap.get(modName);
                    if (occurrencePeptide != null) {
                        Integer occurrenceDataset = modifiedSitesMap.get(modName);
                        if (occurrenceDataset == null) {
                            modifiedSitesMap.put(modName, occurrencePeptide);
                        } else {
                            modifiedSitesMap.put(modName, occurrenceDataset + occurrencePeptide);
                        }
                    }
                    Integer possibleSitesDataset = possibleSitesMap.get(modName);
                    if (possibleSitesDataset == null) {
                        possibleSitesMap.put(modName, possibleSites.length);
                    } else {
                        possibleSitesMap.put(modName, possibleSitesDataset + possibleSites.length);
                    }
                }
            }
        }
        if (progressDialog.isRunCanceled()) {
            break;
        }
        progressDialog.increaseSecondaryProgressCounter();
    }
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (String modName : modificationParameters.getAllNotFixedModifications()) {
        Integer nFound = modifiedSitesMap.get(modName);
        if (nFound == null) {
            nFound = 0;
        }
        Integer nPossible = possibleSitesMap.get(modName);
        Double rate = 0.0;
        if (nPossible != null) {
            rate = (100.0 * nFound) / nPossible;
        }
        dataset.addValue(rate, "Modified", modName);
        double rest = 100 - rate;
        dataset.addValue(rest, "Not Modified", modName);
    }
    return dataset;
}
Also used : Modification(com.compomics.util.experiment.biology.modifications.Modification) ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) PeptideMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.PeptideMatchesIterator) PeptideMatch(com.compomics.util.experiment.identification.matches.PeptideMatch) HashMap(java.util.HashMap) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) Identification(com.compomics.util.experiment.identification.Identification) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Aggregations

Identification (com.compomics.util.experiment.identification.Identification)38 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)28 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)19 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)19 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)18 PeptideMatch (com.compomics.util.experiment.identification.matches.PeptideMatch)17 ProteinMatch (com.compomics.util.experiment.identification.matches.ProteinMatch)17 Collectors (java.util.stream.Collectors)16 WaitingHandler (com.compomics.util.waiting.WaitingHandler)15 Arrays (java.util.Arrays)15 ArrayList (java.util.ArrayList)14 HashMap (java.util.HashMap)14 ModificationParameters (com.compomics.util.parameters.identification.search.ModificationParameters)13 PeptideUtils (com.compomics.util.experiment.identification.utils.PeptideUtils)12 SequenceMatchingParameters (com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters)12 IdentificationFeaturesGenerator (com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator)11 SpectrumProvider (com.compomics.util.experiment.mass_spectrometry.SpectrumProvider)11 SelfUpdatingTableModel (com.compomics.util.gui.tablemodels.SelfUpdatingTableModel)11 HashSet (java.util.HashSet)11 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)10