Search in sources :

Example 1 with SpectrumIdentificationAssumption

use of com.compomics.util.experiment.identification.SpectrumIdentificationAssumption 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 SpectrumIdentificationAssumption

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

the class PsmScorer method scorePsms.

/**
 * Attaches a score to the PSMs.
 *
 * @param identification the object containing the identification matches
 * @param inputMap the input map scores
 * @param processingPreferences the processing preferences
 * @param identificationParameters the identification parameters
 * @param waitingHandler the handler displaying feedback to the user
 */
public void scorePsms(Identification identification, InputMap inputMap, ProcessingParameters processingPreferences, IdentificationParameters identificationParameters, WaitingHandler waitingHandler) {
    waitingHandler.setSecondaryProgressCounterIndeterminate(false);
    waitingHandler.setMaxSecondaryProgressCounter(identification.getSpectrumIdentificationSize());
    PsmScoringParameters psmScoringPreferences = identificationParameters.getPsmScoringParameters();
    PSParameter psParameter = new PSParameter();
    SpectrumMatchesIterator psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
    SpectrumMatch spectrumMatch;
    while ((spectrumMatch = psmIterator.next()) != null) {
        String spectrumFile = spectrumMatch.getSpectrumFile();
        HashMap<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> assumptions = spectrumMatch.getPeptideAssumptionsMap();
        for (Entry<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> entry1 : assumptions.entrySet()) {
            int advocateIndex = entry1.getKey();
            if (psmScoringPreferences.isScoringNeeded(advocateIndex)) {
                HashSet<Integer> scoresForAdvocate = psmScoringPreferences.getScoreForAlgorithm(advocateIndex);
                if (!scoresForAdvocate.isEmpty()) {
                    TreeMap<Double, ArrayList<PeptideAssumption>> advocateAssumptions = entry1.getValue();
                    for (double eValue : advocateAssumptions.keySet()) {
                        for (SpectrumIdentificationAssumption assumption : advocateAssumptions.get(eValue)) {
                            if (assumption instanceof PeptideAssumption) {
                                psParameter = (PSParameter) assumption.getUrParam(psParameter);
                                double score = 1.0;
                                if (scoresForAdvocate.size() == 1 || !fastaParameters.isTargetDecoy()) {
                                    score = psParameter.getIntermediateScore(scoresForAdvocate.iterator().next());
                                } else {
                                    for (int scoreIndex : scoresForAdvocate) {
                                        TargetDecoyMap targetDecoyMap = inputMap.getIntermediateScoreMap(spectrumFile, advocateIndex, scoreIndex);
                                        Double intermediateScore = psParameter.getIntermediateScore(scoreIndex);
                                        if (intermediateScore != null) {
                                            double p = targetDecoyMap.getProbability(intermediateScore);
                                            score *= (1.0 - p);
                                        }
                                    }
                                    score = 1 - score;
                                }
                                assumption.setScore(score);
                                PeptideAssumption peptideAssumption = (PeptideAssumption) assumption;
                                Peptide peptide = peptideAssumption.getPeptide();
                                boolean decoy = PeptideUtils.isDecoy(peptide, sequenceProvider);
                                inputMap.addEntry(advocateIndex, spectrumFile, assumption.getScore(), decoy);
                            }
                        }
                    }
                }
            }
        }
        if (waitingHandler.isRunCanceled()) {
            return;
        }
        waitingHandler.increaseSecondaryProgressCounter();
        identification.updateObject(spectrumMatch.getKey(), spectrumMatch);
    }
    waitingHandler.setSecondaryProgressCounterIndeterminate(true);
}
Also used : ArrayList(java.util.ArrayList) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) TreeMap(java.util.TreeMap) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) TargetDecoyMap(eu.isas.peptideshaker.scoring.targetdecoy.TargetDecoyMap) PsmScoringParameters(com.compomics.util.parameters.identification.advanced.PsmScoringParameters) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 3 with SpectrumIdentificationAssumption

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

the class ModificationsPanel method getSelectedIdentificationAssumptions.

/**
 * Returns a map of the selected spectrum identification assumptions as a
 * map: spectrum key | assumption
 *
 * @return an ArrayList of the keys of the selected spectra in the PSM table
 */
public HashMap<Long, ArrayList<SpectrumIdentificationAssumption>> getSelectedIdentificationAssumptions() {
    HashMap<Long, ArrayList<SpectrumIdentificationAssumption>> result = new HashMap<>(2);
    for (Long spectrumKey : getSelectedPsmsKeys(false)) {
        SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
        ArrayList<SpectrumIdentificationAssumption> assumptions = new ArrayList<>(1);
        assumptions.add(spectrumMatch.getBestPeptideAssumption());
        result.put(spectrumKey, assumptions);
    }
    for (Long spectrumKey : getSelectedPsmsKeys(true)) {
        SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
        ArrayList<SpectrumIdentificationAssumption> assumptions = new ArrayList<>(1);
        assumptions.add(spectrumMatch.getBestPeptideAssumption());
        result.put(spectrumKey, assumptions);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption)

Example 4 with SpectrumIdentificationAssumption

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

the class PsIdentificationAlgorithmMatchesSection method writeSection.

/**
 * Writes the desired section. Exports all algorithm assumptions including
 * the decoy and non-validated matches.
 *
 * @param identification The identification of the project.
 * @param identificationFeaturesGenerator The identification features
 * generator of the project.
 * @param sequenceProvider The sequence provider.
 * @param proteinDetailsProvider The protein details provider.
 * @param spectrumProvider The spectrum provider.
 * @param identificationParameters The identification parameters.
 * @param keys The keys of the spectrum matches to output.
 * @param linePrefix The line prefix.
 * @param nSurroundingAA The number of surrounding amino acids to export.
 * @param waitingHandler The waiting handler.
 *
 * @throws IOException exception thrown whenever an error occurred while
 * interacting with a file
 */
public void writeSection(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, long[] keys, String linePrefix, int nSurroundingAA, WaitingHandler waitingHandler) throws IOException {
    if (waitingHandler != null) {
        waitingHandler.setSecondaryProgressCounterIndeterminate(true);
    }
    if (header) {
        writeHeader();
    }
    PSParameter psParameter = new PSParameter();
    int line = 1;
    int totalSize = identification.getNumber(SpectrumMatch.class);
    if (waitingHandler != null) {
        waitingHandler.setWaitingText("Exporting. Please Wait...");
        waitingHandler.resetSecondaryProgressCounter();
        waitingHandler.setMaxSecondaryProgressCounter(totalSize);
    }
    SpectrumMatchesIterator psmIterator = identification.getSpectrumMatchesIterator(waitingHandler);
    SpectrumMatch spectrumMatch;
    while ((spectrumMatch = psmIterator.next()) != null) {
        if (waitingHandler != null) {
            if (waitingHandler.isRunCanceled()) {
                return;
            }
            waitingHandler.increaseSecondaryProgressCounter();
        }
        HashMap<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> peptideAssumptions = spectrumMatch.getPeptideAssumptionsMap();
        for (int advocateId : peptideAssumptions.keySet()) {
            TreeMap<Double, ArrayList<PeptideAssumption>> advocateAssumptions = peptideAssumptions.get(advocateId);
            ArrayList<Double> scores = new ArrayList<>(advocateAssumptions.keySet());
            Collections.sort(scores);
            for (double score : scores) {
                for (SpectrumIdentificationAssumption assumption : advocateAssumptions.get(score)) {
                    boolean firstFeature = true;
                    if (indexes) {
                        if (linePrefix != null) {
                            writer.write(linePrefix);
                        }
                        writer.write(Integer.toString(line));
                        firstFeature = false;
                    }
                    for (PsIdentificationAlgorithmMatchesFeature identificationAlgorithmMatchesFeature : matchExportFeatures) {
                        if (!firstFeature) {
                            writer.addSeparator();
                        } else {
                            firstFeature = false;
                        }
                        psParameter = (PSParameter) assumption.getUrParam(psParameter);
                        PeptideAssumption peptideAssumption = (PeptideAssumption) assumption;
                        String feature = getPeptideAssumptionFeature(identification, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, identificationParameters, linePrefix, nSurroundingAA, peptideAssumption, spectrumMatch.getSpectrumFile(), spectrumMatch.getSpectrumTitle(), psParameter, identificationAlgorithmMatchesFeature, waitingHandler);
                        writer.write(feature);
                    }
                    writer.addSeparator();
                    if (fragmentSection != null) {
                        String fractionPrefix = "";
                        if (linePrefix != null) {
                            fractionPrefix += linePrefix;
                        }
                        fractionPrefix += line + ".";
                        fragmentSection.writeSection(spectrumMatch.getSpectrumFile(), spectrumMatch.getSpectrumTitle(), assumption, sequenceProvider, spectrumProvider, identificationParameters, fractionPrefix, null);
                    }
                    line++;
                    writer.newLine();
                }
            }
        }
        HashMap<Integer, TreeMap<Double, ArrayList<TagAssumption>>> tagAssumptions = spectrumMatch.getTagAssumptionsMap();
        for (int advocateId : tagAssumptions.keySet()) {
            TreeMap<Double, ArrayList<TagAssumption>> advocateAssumptions = tagAssumptions.get(advocateId);
            ArrayList<Double> scores = new ArrayList<>(advocateAssumptions.keySet());
            Collections.sort(scores);
            for (double score : scores) {
                for (SpectrumIdentificationAssumption assumption : advocateAssumptions.get(score)) {
                    boolean firstFeature = true;
                    if (indexes) {
                        if (linePrefix != null) {
                            writer.write(linePrefix);
                        }
                        writer.write(Integer.toString(line));
                        firstFeature = false;
                    }
                    for (PsIdentificationAlgorithmMatchesFeature identificationAlgorithmMatchesFeature : matchExportFeatures) {
                        if (!firstFeature) {
                            writer.addSeparator();
                        } else {
                            firstFeature = false;
                        }
                        psParameter = (PSParameter) assumption.getUrParam(psParameter);
                        TagAssumption tagAssumption = (TagAssumption) assumption;
                        String feature = getTagAssumptionFeature(identification, identificationFeaturesGenerator, spectrumProvider, identificationParameters, linePrefix, tagAssumption, spectrumMatch.getSpectrumFile(), spectrumMatch.getSpectrumTitle(), psParameter, identificationAlgorithmMatchesFeature, waitingHandler);
                        writer.write(feature);
                    }
                    writer.addSeparator();
                    if (fragmentSection != null) {
                        String fractionPrefix = "";
                        if (linePrefix != null) {
                            fractionPrefix += linePrefix;
                        }
                        fractionPrefix += line + ".";
                        fragmentSection.writeSection(spectrumMatch.getSpectrumFile(), spectrumMatch.getSpectrumTitle(), assumption, sequenceProvider, spectrumProvider, identificationParameters, fractionPrefix, null);
                    }
                    line++;
                    writer.newLine();
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) PsIdentificationAlgorithmMatchesFeature(com.compomics.util.io.export.features.peptideshaker.PsIdentificationAlgorithmMatchesFeature) TreeMap(java.util.TreeMap) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) TagAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Example 5 with SpectrumIdentificationAssumption

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

the class PepXmlExport method writeSpectrumMatch.

/**
 * Writes the content of a spectrum match.
 *
 * @param sw the XML file writer
 * @param identification the identification object containing the
 * identification results
 * @param spectrumProvider the spectrum provider
 * @param identificationParameters the identification parameters
 * @param spectrumMatch the spectrum match
 *
 * @throws IOException exception thrown whenever an error is encountered
 * while reading or writing a file
 */
private void writeSpectrumMatch(SimpleXmlWriter sw, Identification identification, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, SpectrumMatch spectrumMatch) throws IOException {
    double precursorMz = spectrumProvider.getPrecursorMz(spectrumMatch.getSpectrumFile(), spectrumMatch.getSpectrumTitle());
    PSParameter psParameter;
    sw.writeLineIncreasedIndent("<search_result>");
    sw.increaseIndent();
    // PeptideShaker hit
    PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();
    if (peptideAssumption != null) {
        psParameter = (PSParameter) spectrumMatch.getUrParam(PSParameter.dummy);
        writeSearchHit(sw, identificationParameters, peptideAssumption, precursorMz, psParameter, true);
    }
    // Search engines results
    HashMap<Integer, TreeMap<Double, ArrayList<PeptideAssumption>>> assumptions = ((SpectrumMatch) identification.retrieveObject(spectrumMatch.getKey())).getPeptideAssumptionsMap();
    for (TreeMap<Double, ArrayList<PeptideAssumption>> scoreMap : assumptions.values()) {
        for (ArrayList<PeptideAssumption> spectrumIdentificationAssumptions : scoreMap.values()) {
            for (SpectrumIdentificationAssumption spectrumIdentificationAssumption : spectrumIdentificationAssumptions) {
                peptideAssumption = (PeptideAssumption) spectrumIdentificationAssumption;
                psParameter = (PSParameter) peptideAssumption.getUrParam(PSParameter.dummy);
                writeSearchHit(sw, identificationParameters, peptideAssumption, precursorMz, psParameter, false);
            }
        }
    }
    sw.writeLineDecreasedIndent("</search_result>");
}
Also used : SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) TreeMap(java.util.TreeMap) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter)

Aggregations

SpectrumIdentificationAssumption (com.compomics.util.experiment.identification.SpectrumIdentificationAssumption)6 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)5 ArrayList (java.util.ArrayList)5 PeptideAssumption (com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption)4 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)3 TreeMap (java.util.TreeMap)3 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)2 SpectrumMatchesIterator (com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator)2 TagAssumption (com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption)2 IonMatch (com.compomics.util.experiment.identification.matches.IonMatch)1 AnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters)1 SpecificAnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters)1 PeptideSpectrumAnnotator (com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator)1 TagSpectrumAnnotator (com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.TagSpectrumAnnotator)1 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)1 Precursor (com.compomics.util.experiment.mass_spectrometry.spectra.Precursor)1 Spectrum (com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum)1 MassErrorBubblePlot (com.compomics.util.gui.spectrum.MassErrorBubblePlot)1 SpectrumPanel (com.compomics.util.gui.spectrum.SpectrumPanel)1 SelfUpdatingTableModel (com.compomics.util.gui.tablemodels.SelfUpdatingTableModel)1