Search in sources :

Example 1 with AnnotationParameters

use of com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters 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();
}
Also used : MassErrorBubblePlot(com.compomics.util.gui.spectrum.MassErrorBubblePlot) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) DisplayParameters(eu.isas.peptideshaker.preferences.DisplayParameters) ArrayList(java.util.ArrayList) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) TitledBorder(javax.swing.border.TitledBorder) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) TagAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption) IonMatch(com.compomics.util.experiment.identification.matches.IonMatch) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) TagSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.TagSpectrumAnnotator) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) HashSet(java.util.HashSet) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) SpectrumPanel(com.compomics.util.gui.spectrum.SpectrumPanel) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator)

Example 2 with AnnotationParameters

use of com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters 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 3 with AnnotationParameters

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

the class PsmScorer method estimateIntermediateScores.

/**
 * Scores the PSMs contained in an identification object.
 *
 * @param identification the object containing the identification matches
 * @param inputMap the input map scores
 * @param processingParameters the processing preferences
 * @param identificationParameters identification parameters used
 * @param waitingHandler the handler displaying feedback to the user
 * @param exceptionHandler a handler for exceptions
 *
 * @throws java.lang.InterruptedException exception thrown if a thread is
 * interrupted
 * @throws java.util.concurrent.TimeoutException exception thrown if the
 * process times out
 */
public void estimateIntermediateScores(Identification identification, InputMap inputMap, ProcessingParameters processingParameters, IdentificationParameters identificationParameters, WaitingHandler waitingHandler, ExceptionHandler exceptionHandler) throws InterruptedException, TimeoutException {
    // Remove the intensity filter during scoring
    AnnotationParameters annotationSettings = identificationParameters.getAnnotationParameters();
    double intensityThreshold = annotationSettings.getAnnotationIntensityLimit();
    annotationSettings.setIntensityLimit(0);
    waitingHandler.setWaitingText("Scoring PSMs. Please Wait...");
    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
    waitingHandler.setMaxSecondaryProgressCounter(identification.getSpectrumIdentificationSize());
    ExecutorService pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
    SpectrumMatchesIterator psmIterator = identification.getSpectrumMatchesIterator(null);
    ArrayList<PsmScorerRunnable> psmScorerRunnables = new ArrayList<>(processingParameters.getnThreads());
    for (int i = 1; i <= processingParameters.getnThreads() && !waitingHandler.isRunCanceled(); i++) {
        PsmScorerRunnable runnable = new PsmScorerRunnable(psmIterator, identification, inputMap, identificationParameters, waitingHandler, exceptionHandler);
        psmScorerRunnables.add(runnable);
        pool.submit(runnable);
    }
    if (waitingHandler.isRunCanceled()) {
        pool.shutdownNow();
        return;
    }
    pool.shutdown();
    if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
        throw new TimeoutException("PSM scoring timed out. Please contact the developers.");
    }
    ArrayList<HashMap<Double, Integer>> aHistograms = new ArrayList<>(processingParameters.getnThreads());
    ArrayList<HashMap<Double, Integer>> bHistograms = new ArrayList<>(processingParameters.getnThreads());
    HashMap<Long, ArrayList<Integer>> missingValuesMap = new HashMap<>();
    for (PsmScorerRunnable runnable : psmScorerRunnables) {
        HashMap<Long, ArrayList<Integer>> currentMissingValuesMap = runnable.getMissingEValues();
        missingValuesMap.putAll(currentMissingValuesMap);
        HyperScore hyperScore = runnable.getHyperScore();
        aHistograms.add(hyperScore.getAs());
        bHistograms.add(hyperScore.getBs());
    }
    if (!missingValuesMap.isEmpty()) {
        HashMap<Double, Integer> aHistogram = HistogramUtils.mergeHistograms(aHistograms);
        HashMap<Double, Integer> bHistogram = HistogramUtils.mergeHistograms(bHistograms);
        double defaultA = aHistogram.isEmpty() ? Double.NaN : HistogramUtils.getMedianValue(aHistogram);
        double defaultB = bHistogram.isEmpty() ? Double.NaN : HistogramUtils.getMedianValue(bHistogram);
        long[] spectrumKeys = missingValuesMap.keySet().stream().mapToLong(Long::longValue).toArray();
        psmIterator = identification.getSpectrumMatchesIterator(spectrumKeys, null);
        pool = Executors.newFixedThreadPool(processingParameters.getnThreads());
        for (int i = 1; i <= processingParameters.getnThreads() && !waitingHandler.isRunCanceled(); i++) {
            MissingEValueEstimatorRunnable runnable = new MissingEValueEstimatorRunnable(missingValuesMap, defaultA, defaultB, psmIterator, inputMap, identificationParameters, waitingHandler, exceptionHandler);
            pool.submit(runnable);
        }
        if (waitingHandler.isRunCanceled()) {
            pool.shutdownNow();
            return;
        }
        pool.shutdown();
        if (!pool.awaitTermination(identification.getSpectrumIdentificationSize(), TimeUnit.MINUTES)) {
            throw new TimeoutException("PSM scoring timed out. Please contact the developers.");
        }
    }
    waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    // Restaure intensity threshold
    annotationSettings.setIntensityLimit(intensityThreshold);
}
Also used : HyperScore(com.compomics.util.experiment.identification.psm_scoring.psm_scores.HyperScore) 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) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) ExecutorService(java.util.concurrent.ExecutorService) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with AnnotationParameters

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

the class OverviewPanel method updateBubblePlot.

/**
 * Updated the bubble plot with the current PSMs.
 */
public void updateBubblePlot() {
    if (peptideTable.getSelectedRow() != -1 && displaySpectrum) {
        ArrayList<String> selectedIndexes = new ArrayList<>();
        // get the currenly selected rows in the psm table
        int[] selectedPsmRows = psmTable.getSelectedRows();
        SelfUpdatingTableModel psmTableModel = (SelfUpdatingTableModel) psmTable.getModel();
        ArrayList<IonMatch[]> allAnnotations = new ArrayList<>();
        ArrayList<Spectrum> allSpectra = new ArrayList<>();
        SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
        IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
        ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
        SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
        AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
        DisplayParameters displayParameters = peptideShakerGUI.getDisplayParameters();
        ArrayList<Peptide> peptides = new ArrayList<>();
        SpectrumProvider spectrumProvider = peptideShakerGUI.getSpectrumProvider();
        PeptideSpectrumAnnotator spectrumAnnotator = new PeptideSpectrumAnnotator();
        SpecificAnnotationParameters specificAnnotationParameters = null;
        int maxCharge = 1;
        HashSet<String> allModifications = new HashSet<>();
        // iterate the selected psms rows
        for (int row : selectedPsmRows) {
            int psmIndex = psmTableModel.getViewIndex(row);
            long spectrumMatchKey = psmKeys[psmIndex];
            SpectrumMatch spectrumMatch = peptideShakerGUI.getIdentification().getSpectrumMatch(spectrumMatchKey);
            selectedIndexes.add((psmIndex + 1) + " " + Charge.toString(spectrumMatch.getBestPeptideAssumption().getIdentificationCharge()));
            String spectrumFile = spectrumMatch.getSpectrumFile();
            String spectrumTitle = spectrumMatch.getSpectrumTitle();
            Spectrum currentSpectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            if (currentSpectrum != null) {
                PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();
                Peptide peptide = peptideAssumption.getPeptide();
                specificAnnotationParameters = peptideShakerGUI.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption);
                peptides.add(peptide);
                IonMatch[] annotations = spectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, currentSpectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
                allAnnotations.add(annotations);
                allSpectra.add(currentSpectrum);
                int currentCharge = spectrumMatch.getBestPeptideAssumption().getIdentificationCharge();
                if (currentCharge > maxCharge) {
                    maxCharge = currentCharge;
                }
                allModifications.addAll(ModificationUtils.getAllModifications(peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters));
                currentSpectrumMatchKey = spectrumMatch.getKey();
            }
        }
        double bubbleScale = annotationParameters.getFragmentIonAccuracy() * 10 * peptideShakerGUI.getBubbleScale();
        massErrorBubblePlot = new MassErrorBubblePlot(selectedIndexes, allAnnotations, allSpectra, annotationParameters.getFragmentIonAccuracy(), bubbleScale, selectedIndexes.size() == 1, displayParameters.showBars(), identificationParameters.getSearchParameters().getFragmentAccuracyType() == 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);
        bubbleJPanel.removeAll();
        bubbleJPanel.add(massErrorBubblePlot);
        bubbleJPanel.revalidate();
        bubbleJPanel.repaint();
        if (allSpectra.size() == 2) {
            for (int i = 0; i < allSpectra.size(); i++) {
                if (i == 0) {
                    Spectrum spectrum = allSpectra.get(i);
                    spectrumPanel = new SpectrumPanel(spectrum.mz, ArrayUtil.scaleToMax(spectrum.intensity), 500, "2", "", 40, false, false, false, 2, false);
                    // @TODO: implement ties resolution in the spectrum panel
                    spectrumPanel.setAnnotateHighestPeak(annotationParameters.getTiesResolution() == SpectrumAnnotator.TiesResolution.mostIntense);
                    // @TODO: the selection of the peak to annotate should be done outside the spectrum panel
                    spectrumPanel.setAnnotations(SpectrumAnnotator.getSpectrumAnnotation(allAnnotations.get(i)), annotationParameters.getTiesResolution() == SpectrumAnnotator.TiesResolution.mostIntense);
                    SpectrumPanel.setKnownMassDeltas(peptideShakerGUI.getCurrentMassDeltas());
                    spectrumPanel.setDeltaMassWindow(peptideShakerGUI.getIdentificationParameters().getAnnotationParameters().getFragmentIonAccuracy());
                    spectrumPanel.setBorder(null);
                    spectrumPanel.setDataPointAndLineColor(peptideShakerGUI.getUtilitiesUserParameters().getSpectrumAnnotatedPeakColor(), 0);
                    spectrumPanel.setPeakWaterMarkColor(peptideShakerGUI.getUtilitiesUserParameters().getSpectrumBackgroundPeakColor());
                    spectrumPanel.setPeakWidth(peptideShakerGUI.getUtilitiesUserParameters().getSpectrumAnnotatedPeakWidth());
                    spectrumPanel.setBackgroundPeakWidth(peptideShakerGUI.getUtilitiesUserParameters().getSpectrumBackgroundPeakWidth());
                    spectrumPanel.showAnnotatedPeaksOnly(!annotationParameters.showAllPeaks());
                    spectrumPanel.setYAxisZoomExcludesBackgroundPeaks(annotationParameters.yAxisZoomExcludesBackgroundPeaks());
                    Integer forwardIon = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getForwardIons().get(0);
                    Integer rewindIon = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getRewindIons().get(0);
                    spectrumPanel.addAutomaticDeNovoSequencing(peptides.get(i), allAnnotations.get(i), forwardIon, rewindIon, annotationParameters.getDeNovoCharge(), annotationParameters.showForwardIonDeNovoTags(), annotationParameters.showRewindIonDeNovoTags(), false, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
                } else {
                    Spectrum spectrum = allSpectra.get(i);
                    spectrumPanel.addMirroredSpectrum(spectrum.mz, ArrayUtil.scaleToMax(spectrum.intensity), 500, "2", "", false, peptideShakerGUI.getUtilitiesUserParameters().getSpectrumAnnotatedMirroredPeakColor(), peptideShakerGUI.getUtilitiesUserParameters().getSpectrumAnnotatedMirroredPeakColor());
                    // @TODO: implement ties resolution in the spectrum panel
                    spectrumPanel.setAnnotateHighestPeak(annotationParameters.getTiesResolution() == SpectrumAnnotator.TiesResolution.mostIntense);
                    spectrumPanel.setAnnotationsMirrored(SpectrumAnnotator.getSpectrumAnnotation(allAnnotations.get(i)));
                    Integer forwardIon = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getForwardIons().get(0);
                    Integer rewindIon = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getRewindIons().get(0);
                    spectrumPanel.addAutomaticDeNovoSequencing(peptides.get(i), allAnnotations.get(i), forwardIon, rewindIon, annotationParameters.getDeNovoCharge(), annotationParameters.showForwardIonDeNovoTags(), annotationParameters.showRewindIonDeNovoTags(), true, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
                }
            }
            spectrumPanel.rescale(0.0, spectrumPanel.getMaxXAxisValue());
            spectrumSplitPane.setDividerLocation(0);
            spectrumContainerJPanel.revalidate();
            spectrumContainerJPanel.repaint();
            spectrumJPanel.removeAll();
            spectrumJPanel.add(spectrumPanel);
            spectrumJPanel.revalidate();
            spectrumJPanel.repaint();
        } else {
            spectrumSplitPane.setDividerLocation(spectrumSubPlotDividerLocation);
            spectrumContainerJPanel.revalidate();
            spectrumContainerJPanel.repaint();
        }
        peptideShakerGUI.updateAnnotationMenus(specificAnnotationParameters, maxCharge, allModifications);
    }
}
Also used : SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) DisplayParameters(eu.isas.peptideshaker.preferences.DisplayParameters) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) SelfUpdatingTableModel(com.compomics.util.gui.tablemodels.SelfUpdatingTableModel) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator)

Example 5 with AnnotationParameters

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

the class OverviewPanel method intensitySliderStateChanged.

// GEN-LAST:event_spectrumJTabbedPaneMouseWheelMoved
/**
 * Updates the intensity annotation limit.
 *
 * @param evt
 */
private void intensitySliderStateChanged(javax.swing.event.ChangeEvent evt) {
    // GEN-FIRST:event_intensitySliderStateChanged
    AnnotationParameters annotationParameters = peptideShakerGUI.getIdentificationParameters().getAnnotationParameters();
    annotationParameters.setIntensityLimit(intensitySlider.getValue() / 100.0);
    peptideShakerGUI.updateSpectrumAnnotations();
    peptideShakerGUI.setDataSaved(false);
    intensitySlider.setToolTipText("Annotation Level: " + intensitySlider.getValue() + "%");
    updateSpectrumSliderToolTip();
}
Also used : SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters)

Aggregations

AnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters)26 SpecificAnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters)23 PeptideAssumption (com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption)16 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)16 SequenceMatchingParameters (com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters)16 ModificationParameters (com.compomics.util.parameters.identification.search.ModificationParameters)16 ArrayList (java.util.ArrayList)16 Spectrum (com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum)15 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)14 PeptideSpectrumAnnotator (com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator)14 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)14 SpectrumProvider (com.compomics.util.experiment.mass_spectrometry.SpectrumProvider)12 SearchParameters (com.compomics.util.parameters.identification.search.SearchParameters)12 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)9 HashMap (java.util.HashMap)9 IonMatch (com.compomics.util.experiment.identification.matches.IonMatch)8 HashSet (java.util.HashSet)8 TreeMap (java.util.TreeMap)8 Collectors (java.util.stream.Collectors)8 PeptideFragmentIon (com.compomics.util.experiment.biology.ions.impl.PeptideFragmentIon)5