Search in sources :

Example 1 with Precursor

use of com.compomics.util.experiment.mass_spectrometry.spectra.Precursor 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 Precursor

use of com.compomics.util.experiment.mass_spectrometry.spectra.Precursor in project peptide-shaker by compomics.

the class OverviewPanel method updateSpectrum.

/**
 * Update the spectrum to the currently selected PSM.
 *
 * @param row the row index of the PSM
 * @param resetMzRange if true the mz range is reset, if false the current
 * zoom range is kept
 */
private void updateSpectrum(int row, boolean resetMzRange) {
    if (row != -1) {
        this.setCursor(new java.awt.Cursor(java.awt.Cursor.WAIT_CURSOR));
        SelfUpdatingTableModel tableModel = (SelfUpdatingTableModel) psmTable.getModel();
        int psmIndex = tableModel.getViewIndex(row);
        long spectrumMatchKey = psmKeys[psmIndex];
        if (displaySpectrum) {
            SpectrumProvider spectrumProvider = peptideShakerGUI.getSpectrumProvider();
            SpectrumMatch spectrumMatch = peptideShakerGUI.getIdentification().getSpectrumMatch(spectrumMatchKey);
            String spectrumFile = spectrumMatch.getSpectrumFile();
            String spectrumTitle = spectrumMatch.getSpectrumTitle();
            Spectrum currentSpectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            if (currentSpectrum != null && currentSpectrum.getNPeaks() > 0) {
                boolean newMax = false;
                if (resetMzRange) {
                    lastMzMaximum = 0;
                }
                if (peptideShakerGUI.getSelectedPeptideKey() != NO_KEY) {
                    double newMaximum = currentSpectrum.getMaxMz();
                    if (lastMzMaximum < newMaximum) {
                        lastMzMaximum = newMaximum;
                        newMax = true;
                    }
                }
                double lowerMzZoomRange = 0;
                double upperMzZoomRange = lastMzMaximum;
                if (spectrumPanel != null && spectrumPanel.getXAxisZoomRangeLowerValue() != 0 && !newMax) {
                    // @TODO: sometimes the range is reset when is should not be...
                    lowerMzZoomRange = spectrumPanel.getXAxisZoomRangeLowerValue();
                    upperMzZoomRange = spectrumPanel.getXAxisZoomRangeUpperValue();
                }
                // add the data to the spectrum panel
                Precursor precursor = currentSpectrum.getPrecursor();
                spectrumPanel = new SpectrumPanel(currentSpectrum.mz, currentSpectrum.intensity, precursor.mz, Charge.toString(spectrumMatch.getBestPeptideAssumption().getIdentificationCharge()), "", 40, false, false, false, 2, false);
                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());
                // get the spectrum annotations
                PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();
                Peptide currentPeptide = peptideAssumption.getPeptide();
                PeptideSpectrumAnnotator spectrumAnnotator = new PeptideSpectrumAnnotator();
                AnnotationParameters annotationParameters = peptideShakerGUI.getIdentificationParameters().getAnnotationParameters();
                SequenceProvider sequenceProvider = peptideShakerGUI.getSequenceProvider();
                IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
                ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
                SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
                SpecificAnnotationParameters specificAnnotationParameters = peptideShakerGUI.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption);
                IonMatch[] annotations = spectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, currentSpectrum, currentPeptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
                // @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);
                spectrumPanel.rescale(lowerMzZoomRange, upperMzZoomRange);
                // show all or just the annotated peaks
                spectrumPanel.showAnnotatedPeaksOnly(!annotationParameters.showAllPeaks());
                spectrumPanel.setYAxisZoomExcludesBackgroundPeaks(annotationParameters.yAxisZoomExcludesBackgroundPeaks());
                Integer forwardIon = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getForwardIons().get(0);
                Integer rewindIon = peptideShakerGUI.getIdentificationParameters().getSearchParameters().getRewindIons().get(0);
                // add de novo sequencing
                spectrumPanel.addAutomaticDeNovoSequencing(currentPeptide, annotations, forwardIon, rewindIon, annotationParameters.getDeNovoCharge(), annotationParameters.showForwardIonDeNovoTags(), annotationParameters.showRewindIonDeNovoTags(), false, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
                // add the spectrum panel to the frame
                spectrumJPanel.removeAll();
                spectrumJPanel.add(spectrumPanel);
                spectrumJPanel.revalidate();
                spectrumJPanel.repaint();
                // create and display the fragment ion table
                ArrayList<IonMatch[]> allAnnotations = getAnnotationsForAllSelectedSpectra();
                DisplayParameters displayParameters = peptideShakerGUI.getDisplayParameters();
                if (!displayParameters.useIntensityIonTable()) {
                    fragmentIonsJScrollPane.setViewportView(new FragmentIonTable(currentPeptide, allAnnotations, specificAnnotationParameters.getFragmentIonTypes(), specificAnnotationParameters.getNeutralLossesMap(), specificAnnotationParameters.getSelectedCharges().contains(1), specificAnnotationParameters.getSelectedCharges().contains(2), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters));
                } else {
                    ArrayList<Spectrum> spectra = Arrays.stream(getSelectedPsmKeys()).mapToObj(key -> peptideShakerGUI.getIdentification().getSpectrumMatch(key)).map(selectedMatch -> spectrumProvider.getSpectrum(selectedMatch.getSpectrumFile(), selectedMatch.getSpectrumTitle())).collect(Collectors.toCollection(ArrayList::new));
                    fragmentIonsJScrollPane.setViewportView(new FragmentIonTable(currentPeptide, allAnnotations, spectra, specificAnnotationParameters.getFragmentIonTypes(), specificAnnotationParameters.getNeutralLossesMap(), specificAnnotationParameters.getSelectedCharges().contains(1), specificAnnotationParameters.getSelectedCharges().contains(2), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters));
                }
                // create the sequence fragment ion view
                secondarySpectrumPlotsJPanel.removeAll();
                sequenceFragmentationPanel = new SequenceFragmentationPanel(peptideShakerGUI.getDisplayFeaturesGenerator().getTaggedPeptideSequence(spectrumMatch, false, false, true), annotations, true, peptideShakerGUI.getIdentificationParameters().getSearchParameters().getModificationParameters(), forwardIon, rewindIon);
                sequenceFragmentationPanel.setMinimumSize(new Dimension(sequenceFragmentationPanel.getPreferredSize().width, sequenceFragmentationPanel.getHeight()));
                sequenceFragmentationPanel.setOpaque(true);
                sequenceFragmentationPanel.setBackground(Color.WHITE);
                secondarySpectrumPlotsJPanel.add(sequenceFragmentationPanel);
                // create the intensity histograms
                intensityHistogram = new IntensityHistogram(annotations, currentSpectrum, annotationParameters.getAnnotationIntensityLimit());
                secondarySpectrumPlotsJPanel.add(intensityHistogram);
                // create the miniature mass error plot
                massErrorPlot = new MassErrorPlot(annotations, currentSpectrum, specificAnnotationParameters.getFragmentIonAccuracy(), peptideShakerGUI.getIdentificationParameters().getSearchParameters().getFragmentAccuracyType() == SearchParameters.MassAccuracyType.PPM);
                if (massErrorPlot.getNumberOfDataPointsInPlot() > 0) {
                    secondarySpectrumPlotsJPanel.add(massErrorPlot);
                }
                // update the UI
                secondarySpectrumPlotsJPanel.revalidate();
                secondarySpectrumPlotsJPanel.repaint();
                // update the bubble plot
                updateBubblePlot();
                // disable the spectrum tab if more than two psms are selected
                spectrumJTabbedPane.setEnabledAt(2, psmTable.getSelectedRowCount() <= 2);
                peptideShakerGUI.enableSpectrumExport(psmTable.getSelectedRowCount() <= 2);
                // move to the bubble plot tab if more than two psms are selected and the spectrum tab was selected
                if (psmTable.getSelectedRowCount() > 2 && spectrumJTabbedPane.getSelectedIndex() == 2) {
                    spectrumJTabbedPane.setSelectedIndex(1);
                }
                if (psmTable.getSelectedRowCount() > 2) {
                    spectrumJTabbedPane.setToolTipTextAt(2, "Available for single or double spectrum selection only");
                } else {
                    spectrumJTabbedPane.setToolTipTextAt(2, null);
                }
                // update the panel border title
                updateSpectrumPanelBorderTitle(currentSpectrum);
                spectrumMainPanel.revalidate();
                spectrumMainPanel.repaint();
            }
        }
        this.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
    } else {
        // nothing to display, empty previous results
        spectrumJPanel.removeAll();
        spectrumJPanel.revalidate();
        spectrumJPanel.repaint();
        secondarySpectrumPlotsJPanel.removeAll();
        secondarySpectrumPlotsJPanel.revalidate();
        secondarySpectrumPlotsJPanel.repaint();
        fragmentIonsJScrollPane.setViewportView(null);
        fragmentIonsJScrollPane.revalidate();
        fragmentIonsJScrollPane.repaint();
        bubbleJPanel.removeAll();
        bubbleJPanel.revalidate();
        bubbleJPanel.repaint();
        ((TitledBorder) spectrumMainPanel.getBorder()).setTitle(PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING + "Spectrum & Fragment Ions" + PeptideShakerGUI.TITLED_BORDER_HORIZONTAL_PADDING);
        spectrumMainPanel.repaint();
    }
}
Also used : MatchType(eu.isas.peptideshaker.gui.MatchValidationDialog.MatchType) PsPeptideFeature(com.compomics.util.io.export.features.peptideshaker.PsPeptideFeature) PsProteinFeature(com.compomics.util.io.export.features.peptideshaker.PsProteinFeature) NO_KEY(com.compomics.util.experiment.personalization.ExperimentObject.NO_KEY) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) JSparklinesDataSeries(no.uib.jsparklines.data.JSparklinesDataSeries) FileAndFileFilter(com.compomics.util.gui.file_handling.FileAndFileFilter) BareBonesBrowserLaunch(com.compomics.util.examples.BareBonesBrowserLaunch) 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) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) SpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.SpectrumAnnotator) MouseAdapter(java.awt.event.MouseAdapter) TitledBorder(javax.swing.border.TitledBorder) JSparklinesDataset(no.uib.jsparklines.data.JSparklinesDataset) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) PeptideTableModel(eu.isas.peptideshaker.gui.tablemodels.PeptideTableModel) Variant(com.compomics.util.experiment.biology.variants.Variant) TableProperties(com.compomics.util.gui.TableProperties) SpectrumCountingMethod(com.compomics.util.experiment.quantification.spectrumcounting.SpectrumCountingMethod) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) ProteinSequencePanelParent(eu.isas.peptideshaker.gui.protein_sequence.ProteinSequencePanelParent) PSModificationScores(com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores) Clipboard(java.awt.datatransfer.Clipboard) TableModelEvent(javax.swing.event.TableModelEvent) ExportScheme(com.compomics.util.io.export.ExportScheme) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) 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) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) com.compomics.util.experiment.identification.matches(com.compomics.util.experiment.identification.matches) GuiUtilities(com.compomics.util.gui.GuiUtilities) DisplayParameters(eu.isas.peptideshaker.preferences.DisplayParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) ProteinSequencePanel(eu.isas.peptideshaker.gui.protein_sequence.ProteinSequencePanel) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) CategoryPlot(org.jfree.chart.plot.CategoryPlot) ArrayUtil(com.compomics.util.ArrayUtil) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) MatchValidationDialog(eu.isas.peptideshaker.gui.MatchValidationDialog) IntStream(java.util.stream.IntStream) java.util(java.util) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) HelpDialog(com.compomics.util.gui.error_handlers.HelpDialog) ChromosomeTableCellRenderer(no.uib.jsparklines.extra.ChromosomeTableCellRenderer) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) NonSymmetricalNormalDistribution(com.compomics.util.math.statistics.distributions.NonSymmetricalNormalDistribution) PlotOrientation(org.jfree.chart.plot.PlotOrientation) TableModelListener(javax.swing.event.TableModelListener) XYPlottingDialog(com.compomics.util.gui.XYPlottingDialog) ModificationUtils(com.compomics.util.experiment.identification.utils.ModificationUtils) ProteinTableModel(eu.isas.peptideshaker.gui.tablemodels.ProteinTableModel) StringSelection(java.awt.datatransfer.StringSelection) PsmTableModel(eu.isas.peptideshaker.gui.tablemodels.PsmTableModel) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) ProteinInferenceDialog(eu.isas.peptideshaker.gui.protein_inference.ProteinInferenceDialog) MatchValidationLevel(com.compomics.util.experiment.identification.validation.MatchValidationLevel) BufferedWriter(java.io.BufferedWriter) FileWriter(java.io.FileWriter) DecimalFormat(java.text.DecimalFormat) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) ExportFeature(com.compomics.util.io.export.ExportFeature) Identification(com.compomics.util.experiment.identification.Identification) ResidueAnnotation(eu.isas.peptideshaker.gui.protein_sequence.ResidueAnnotation) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ExportGraphicsDialog(com.compomics.util.gui.export.graphics.ExportGraphicsDialog) PSMaps(eu.isas.peptideshaker.scoring.PSMaps) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) MouseEvent(java.awt.event.MouseEvent) File(java.io.File) ChartChangeEvent(org.jfree.chart.event.ChartChangeEvent) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator) ExportFormat(com.compomics.util.io.export.ExportFormat) java.awt(java.awt) Charge(com.compomics.util.experiment.biology.ions.Charge) HtmlLinksRenderer(no.uib.jsparklines.extra.HtmlLinksRenderer) com.compomics.util.gui.spectrum(com.compomics.util.gui.spectrum) GeneDetailsDialog(com.compomics.util.gui.genes.GeneDetailsDialog) no.uib.jsparklines.renderers(no.uib.jsparklines.renderers) Range(org.jfree.data.Range) org.jfree.chart(org.jfree.chart) ChartChangeListener(org.jfree.chart.event.ChartChangeListener) ProgressDialogX(com.compomics.util.gui.waiting.waitinghandlers.ProgressDialogX) javax.swing(javax.swing) 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) 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) 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) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) java.awt(java.awt) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator)

Example 3 with Precursor

use of com.compomics.util.experiment.mass_spectrometry.spectra.Precursor in project peptide-shaker by compomics.

the class PsIdentificationAlgorithmMatchesSection method getTagAssumptionFeature.

/**
 * Writes the feature associated to the match of the given tag assumption.
 *
 * @param identification The identification of the project.
 * @param identificationFeaturesGenerator The identification features
 * generator of the project.
 * @param spectrumProvider the spectrum provider
 * @param identificationParameters The identification parameters.
 * @param linePrefix The line prefix.
 * @param spectrumFile The name of the file of the spectrum.
 * @param spectrumTitle The title of the spectrum.
 * @param tagAssumption The assumption for the match to inspect.
 * @param psParameter The PeptideShaker parameter of the match.
 * @param exportFeature The feature to export.
 * @param waitingHandler The waiting handler.
 *
 * @return The content corresponding to the given feature of the current
 * section.
 */
public static String getTagAssumptionFeature(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, String linePrefix, TagAssumption tagAssumption, String spectrumFile, String spectrumTitle, PSParameter psParameter, PsIdentificationAlgorithmMatchesFeature exportFeature, WaitingHandler waitingHandler) {
    switch(exportFeature) {
        case rank:
            return Integer.toString(tagAssumption.getRank());
        case variable_ptms:
            return Tag.getTagModificationsAsString(tagAssumption.getTag());
        case fixed_ptms:
            // @TODO: impplement
            return "";
        case accessions:
            return "";
        case protein_description:
            return "";
        case algorithm_confidence:
            return Double.toString(psParameter.getConfidence());
        case decoy:
            return "";
        case hidden:
            return psParameter.getHidden() ? "1" : "0";
        case identification_charge:
            return Integer.toString(tagAssumption.getIdentificationCharge());
        case isotope:
            double precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(tagAssumption.getIsotopeNumber(precursorMz, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection()));
        case mz:
            precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(precursorMz);
        case total_spectrum_intensity:
            Spectrum spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return Double.toString(spectrum.getTotalIntensity());
        case max_intensity:
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return Double.toString(spectrum.getMaxIntensity());
        case mz_error_ppm:
            precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(tagAssumption.getDeltaMz(precursorMz, true, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection()));
        case rt:
            double precursorRt = spectrumProvider.getPrecursorRt(spectrumFile, spectrumTitle);
            return Double.toString(precursorRt);
        case algorithm_raw_score:
            int id = tagAssumption.getAdvocate();
            double score = tagAssumption.getRawScore();
            return String.join("", Advocate.getAdvocate(id).getName(), " (", Double.toString(score), ")");
        case algorithm_score:
            id = tagAssumption.getAdvocate();
            score = tagAssumption.getScore();
            return String.join("", Advocate.getAdvocate(id).getName(), " (", Double.toString(score), ")");
        case sequence:
            return tagAssumption.getTag().asSequence();
        case missed_cleavages:
            return "";
        case modified_sequence:
            ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            HashSet<String> modToExport = new HashSet(modificationParameters.getVariableModifications());
            return tagAssumption.getTag().getTaggedModifiedSequence(modificationParameters, false, false, true, false, modificationSequenceMatchingParameters, modToExport);
        case spectrum_charge:
            Precursor precursor = spectrumProvider.getPrecursor(spectrumFile, spectrumTitle);
            return precursor.getPossibleChargesAsString();
        case precursor_intensity:
            precursor = spectrumProvider.getPrecursor(spectrumFile, spectrumTitle);
            return Double.toString(precursor.intensity);
        case spectrum_file:
            return spectrumFile;
        case spectrum_array_list:
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return spectrum.getPeakListAsString();
        case spectrum_title:
            return spectrumTitle;
        case spectrum_scan_number:
            // TODO: To get scan numbers from cms when source mgf files have that info
            return "";
        case starred:
            return psParameter.getStarred() ? "1" : "0";
        case theoretical_mass:
            return Double.toString(tagAssumption.getTag().getMass());
        case validated:
            if (psParameter.getMatchValidationLevel() != null) {
                return psParameter.getMatchValidationLevel().toString();
            } else {
                return "";
            }
        case fragment_mz_accuracy_score:
        case intensity_score:
        case sequence_coverage:
        case longest_amino_acid_sequence_annotated:
        case amino_acids_annotated:
        case position:
            return "";
        default:
            return "Not implemented";
    }
}
Also used : ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) HashSet(java.util.HashSet)

Example 4 with Precursor

use of com.compomics.util.experiment.mass_spectrometry.spectra.Precursor in project peptide-shaker by compomics.

the class DeepLcExport method deepLcExport.

/**
 * Exports a DeepLC training file for the given spectrum file.
 *
 * @param destinationFile The file where to write the export.
 * @param confidentHitsDestinationFile The file where to write the export
 * for confident hits.
 * @param keys The keys of the spectrum matches.
 * @param identification The identification object containing the matches.
 * @param modificationParameters The modification parameters.
 * @param sequenceMatchingParameters The sequence matching parameters.
 * @param sequenceProvider The sequence provider.
 * @param spectrumProvider The spectrum provider.
 * @param waitingHandler The waiting handler.
 */
public static void deepLcExport(File destinationFile, File confidentHitsDestinationFile, HashSet<Long> keys, Identification identification, ModificationParameters modificationParameters, SequenceMatchingParameters sequenceMatchingParameters, SequenceProvider sequenceProvider, SpectrumProvider spectrumProvider, WaitingHandler waitingHandler) {
    ModificationFactory modificationFactory = ModificationFactory.getInstance();
    HashSet<Long> processedPeptideKeys = new HashSet<>();
    SimpleSemaphore writingSemaphore = new SimpleSemaphore(1);
    try (SimpleFileWriter writer = new SimpleFileWriter(destinationFile, true)) {
        writer.writeLine("seq,modifications,tr");
        try (SimpleFileWriter writerConfident = new SimpleFileWriter(confidentHitsDestinationFile, true)) {
            writerConfident.writeLine("seq,modifications,tr");
            long[] spectrumKeys = keys.stream().mapToLong(a -> a).toArray();
            SpectrumMatchesIterator spectrumMatchesIterator = identification.getSpectrumMatchesIterator(spectrumKeys, waitingHandler);
            SpectrumMatch spectrumMatch;
            while ((spectrumMatch = spectrumMatchesIterator.next()) != null) {
                // Display progress
                if (waitingHandler != null) {
                    waitingHandler.increaseSecondaryProgressCounter();
                    if (waitingHandler.isRunCanceled()) {
                        return;
                    }
                }
                // Measured retention time
                String spectrumFile = spectrumMatch.getSpectrumFile();
                String spectrumTitle = spectrumMatch.getSpectrumTitle();
                Precursor precursor = spectrumProvider.getPrecursor(spectrumFile, spectrumTitle);
                double retentionTime = precursor.rt;
                // Export all candidate peptides
                spectrumMatch.getAllPeptideAssumptions().parallel().forEach(peptideAssumption -> writePeptideCandidate(peptideAssumption, retentionTime, modificationParameters, sequenceProvider, sequenceMatchingParameters, modificationFactory, processedPeptideKeys, writingSemaphore, writer));
                // Check whether the spectrum yielded a confident peptide
                if (spectrumMatch.getBestPeptideAssumption() != null && ((PSParameter) spectrumMatch.getUrParam(PSParameter.dummy)).getMatchValidationLevel().isValidated()) {
                    // Export the confident peptide to the confident peptides file
                    writePeptideCandidate(spectrumMatch.getBestPeptideAssumption(), retentionTime, modificationParameters, sequenceProvider, sequenceMatchingParameters, modificationFactory, processedPeptideKeys, writingSemaphore, writerConfident);
                }
            }
        }
    }
}
Also used : ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) DeepLcUtils(eu.isas.peptideshaker.utils.DeepLcUtils) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) HashMap(java.util.HashMap) SimpleSemaphore(com.compomics.util.threading.SimpleSemaphore) Collectors(java.util.stream.Collectors) File(java.io.File) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WaitingHandler(com.compomics.util.waiting.WaitingHandler) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) SimpleSemaphore(com.compomics.util.threading.SimpleSemaphore) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) SimpleFileWriter(com.compomics.util.io.flat.SimpleFileWriter) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) HashSet(java.util.HashSet)

Example 5 with Precursor

use of com.compomics.util.experiment.mass_spectrometry.spectra.Precursor in project peptide-shaker by compomics.

the class PsIdentificationAlgorithmMatchesSection method getPeptideAssumptionFeature.

/**
 * Writes the feature associated to the match of the given peptide
 * assumption.
 *
 * @param identification The identification of the project.
 * @param identificationFeaturesGenerator The identification features
 * generator of the project.
 * @param sequenceProvider The provider for the protein sequences.
 * @param proteinDetailsProvider The provider for protein details.
 * @param spectrumProvider The spectrum provider.
 * @param identificationParameters The identification parameters.
 * @param linePrefix The line prefix.
 * @param nSurroundingAA The number of surrounding amino acids to export.
 * @param peptideAssumption The assumption for the match to inspect.
 * @param spectrumFile The name of the file of the spectrum.
 * @param spectrumTitle The title of the spectrum.
 * @param psParameter The PeptideShaker parameter of the match.
 * @param exportFeature The feature to export.
 * @param waitingHandler The waiting handler.
 *
 * @return The content corresponding to the given feature of the current
 * section.
 */
public static String getPeptideAssumptionFeature(Identification identification, IdentificationFeaturesGenerator identificationFeaturesGenerator, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, String linePrefix, int nSurroundingAA, PeptideAssumption peptideAssumption, String spectrumFile, String spectrumTitle, PSParameter psParameter, PsIdentificationAlgorithmMatchesFeature exportFeature, WaitingHandler waitingHandler) {
    switch(exportFeature) {
        case rank:
            return Integer.toString(peptideAssumption.getRank());
        case variable_ptms:
            ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            SequenceMatchingParameters modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            TreeMap<String, TreeSet<Integer>> modMap = getModMap(peptideAssumption.getPeptide(), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, true);
            return modMap.entrySet().stream().map(entry -> getModificationAsString(entry.getKey(), entry.getValue())).collect(Collectors.joining(";"));
        case fixed_ptms:
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            modMap = getModMap(peptideAssumption.getPeptide(), modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, false);
            return modMap.entrySet().stream().map(entry -> getModificationAsString(entry.getKey(), entry.getValue())).collect(Collectors.joining(";"));
        case accessions:
            TreeMap<String, int[]> proteinMapping = peptideAssumption.getPeptide().getProteinMapping();
            return proteinMapping.navigableKeySet().stream().collect(Collectors.joining(","));
        case protein_description:
            proteinMapping = peptideAssumption.getPeptide().getProteinMapping();
            return proteinMapping.navigableKeySet().stream().map(accession -> proteinDetailsProvider.getDescription(accession)).collect(Collectors.joining(","));
        case algorithm_confidence:
            return Double.toString(psParameter.getConfidence());
        case algorithm_delta_confidence:
            Double delta = psParameter.getAlgorithmDeltaPEP();
            return delta == null ? "Not available" : Double.toString(100 * delta);
        case delta_confidence:
            delta = psParameter.getDeltaPEP();
            return Double.toString(100 * delta);
        case decoy:
            return PeptideUtils.isDecoy(peptideAssumption.getPeptide(), sequenceProvider) ? "1" : "0";
        case hidden:
            return psParameter.getHidden() ? "1" : "0";
        case identification_charge:
            return Integer.toString(peptideAssumption.getIdentificationCharge());
        case isotope:
            double precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Integer.toString(peptideAssumption.getIsotopeNumber(precursorMz, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection()));
        case mz:
            precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(precursorMz);
        case total_spectrum_intensity:
            Spectrum spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return Double.toString(spectrum.getTotalIntensity());
        case max_intensity:
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return Double.toString(spectrum.getMaxIntensity());
        case intensity_coverage:
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            Peptide peptide = peptideAssumption.getPeptide();
            AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            SpecificAnnotationParameters specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            IonMatch[] matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            double coveredIntensity = Arrays.stream(matches).mapToDouble(ionMatch -> ionMatch.peakIntensity).sum();
            double coverage = 100 * coveredIntensity / spectrum.getTotalIntensity();
            return Double.toString(coverage);
        case mz_error_ppm:
            precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(peptideAssumption.getDeltaMz(precursorMz, true, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection()));
        case mz_error_da:
            precursorMz = spectrumProvider.getPrecursorMz(spectrumFile, spectrumTitle);
            return Double.toString(peptideAssumption.getDeltaMz(precursorMz, false, identificationParameters.getSearchParameters().getMinIsotopicCorrection(), identificationParameters.getSearchParameters().getMaxIsotopicCorrection()));
        case rt:
            double precursorRt = spectrumProvider.getPrecursorRt(spectrumFile, spectrumTitle);
            return Double.toString(precursorRt);
        case algorithm_raw_score:
            int id = peptideAssumption.getAdvocate();
            double score = peptideAssumption.getRawScore();
            return String.join("", Advocate.getAdvocate(id).getName(), " (", Double.toString(score), ")");
        case algorithm_score:
            id = peptideAssumption.getAdvocate();
            score = peptideAssumption.getScore();
            return String.join("", Advocate.getAdvocate(id).getName(), " (", Double.toString(score), ")");
        case sequence:
            return peptideAssumption.getPeptide().getSequence();
        case aaBefore:
            TreeMap<String, String[]> aaMap = PeptideUtils.getAaBefore(peptideAssumption.getPeptide(), nSurroundingAA, sequenceProvider);
            return aaMap.values().stream().map(aas -> (Arrays.stream(aas)).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
        case aaAfter:
            aaMap = PeptideUtils.getAaAfter(peptideAssumption.getPeptide(), nSurroundingAA, sequenceProvider);
            return aaMap.values().stream().map(aas -> (Arrays.stream(aas)).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
        case position:
            proteinMapping = peptideAssumption.getPeptide().getProteinMapping();
            return proteinMapping.values().stream().map(positions -> (Arrays.stream(positions)).mapToObj(pos -> Integer.toString(pos)).collect(Collectors.joining(","))).collect(Collectors.joining(";"));
        case missed_cleavages:
            peptide = peptideAssumption.getPeptide();
            int nMissedCleavages = peptide.getNMissedCleavages(identificationParameters.getSearchParameters().getDigestionParameters());
            return Integer.toString(nMissedCleavages);
        case modified_sequence:
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            return peptideAssumption.getPeptide().getTaggedModifiedSequence(modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, false, false, true, null);
        case spectrum_charge:
            Precursor precursor = spectrumProvider.getPrecursor(spectrumFile, spectrumTitle);
            return precursor.getPossibleChargesAsString();
        case precursor_intensity:
            precursor = spectrumProvider.getPrecursor(spectrumFile, spectrumTitle);
            return Double.toString(precursor.intensity);
        case spectrum_file:
            return spectrumFile;
        case spectrum_array_list:
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            return spectrum.getPeakListAsString();
        case spectrum_title:
            return spectrumTitle;
        case spectrum_scan_number:
            // TODO: To get scan numbers from cms when source mgf files have that info
            return "";
        case starred:
            return psParameter.getStarred() ? "1" : "0";
        case theoretical_mass:
            return Double.toString(peptideAssumption.getPeptide().getMass());
        case validated:
            if (psParameter.getMatchValidationLevel() != null) {
                return psParameter.getMatchValidationLevel().toString();
            } else {
                return "";
            }
        case sequence_coverage:
            peptide = peptideAssumption.getPeptide();
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            int sequenceLength = peptide.getSequence().length();
            int[] aaCoverage = new int[sequenceLength];
            Arrays.stream(matches).filter(ionMatch -> ionMatch.ion instanceof PeptideFragmentIon).forEach(ionMatch -> aaCoverage[((PeptideFragmentIon) ionMatch.ion).getNumber() - 1] = 1);
            double nIons = Arrays.stream(aaCoverage).sum();
            coverage = 100 * nIons / sequenceLength;
            return Double.toString(coverage);
        case longest_amino_acid_sequence_annotated:
            peptide = peptideAssumption.getPeptide();
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            String sequence = peptide.getSequence();
            sequenceLength = sequence.length();
            boolean[] coverageForward = new boolean[sequenceLength];
            boolean[] coverageRewind = new boolean[sequenceLength];
            Arrays.stream(matches).filter(ionMatch -> ionMatch.ion instanceof PeptideFragmentIon).map(ionMatch -> ((PeptideFragmentIon) ionMatch.ion)).forEach(peptideFragmentIon -> {
                if (PeptideFragmentIon.isForward(peptideFragmentIon.getSubType())) {
                    coverageForward[peptideFragmentIon.getNumber() - 1] = true;
                } else {
                    coverageRewind[peptideFragmentIon.getNumber() - 1] = true;
                }
            });
            boolean[] aaCoverageB = new boolean[sequenceLength];
            boolean previous = true;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                boolean current = coverageForward[aaIndex];
                if (current && previous) {
                    aaCoverageB[aaIndex] = true;
                }
                previous = current;
            }
            previous = true;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                boolean current = coverageRewind[aaIndex];
                if (current && previous) {
                    aaCoverageB[sequenceLength - aaIndex - 1] = true;
                }
                previous = current;
            }
            StringBuilder currentTag = new StringBuilder();
            String longestTag = new String();
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                if (aaCoverageB[aaIndex]) {
                    currentTag.append(sequence.charAt(aaIndex));
                } else {
                    if (currentTag.length() > longestTag.length()) {
                        longestTag = currentTag.toString();
                    }
                    currentTag = new StringBuilder();
                }
            }
            if (currentTag.length() > longestTag.length()) {
                longestTag = currentTag.toString();
            }
            return longestTag;
        case longest_amino_acid_sequence_annotated_single_serie:
            peptide = peptideAssumption.getPeptide();
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            sequence = peptide.getSequence();
            sequenceLength = sequence.length();
            HashMap<Integer, boolean[]> ionCoverage = new HashMap<>(6);
            ionCoverage.put(PeptideFragmentIon.A_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.B_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.C_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.X_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.Y_ION, new boolean[sequenceLength]);
            ionCoverage.put(PeptideFragmentIon.Z_ION, new boolean[sequenceLength]);
            Arrays.stream(matches).filter(ionMatch -> ionMatch.charge == 1 && ionMatch.ion instanceof PeptideFragmentIon && !ionMatch.ion.hasNeutralLosses()).map(ionMatch -> ((PeptideFragmentIon) ionMatch.ion)).forEach(peptideFragmentIon -> ionCoverage.get(peptideFragmentIon.getSubType())[peptideFragmentIon.getNumber() - 1] = true);
            longestTag = new String();
            currentTag = new StringBuilder();
            previous = true;
            for (int ionType : PeptideFragmentIon.getPossibleSubtypes()) {
                for (int i = 0; i < sequenceLength; i++) {
                    int aaIndex = PeptideFragmentIon.isForward(ionType) ? i : sequence.length() - i - 1;
                    boolean current = ionCoverage.get(ionType)[i];
                    if (current && previous) {
                        currentTag.append(sequence.charAt(aaIndex));
                    } else {
                        if (currentTag.length() > longestTag.length()) {
                            if (PeptideFragmentIon.isForward(ionType)) {
                                currentTag.reverse();
                            }
                            longestTag = currentTag.toString();
                        }
                        currentTag = new StringBuilder();
                    }
                    previous = current;
                }
                if (currentTag.length() > longestTag.length()) {
                    if (PeptideFragmentIon.isForward(ionType)) {
                        currentTag.reverse();
                    }
                    longestTag = currentTag.toString();
                }
            }
            return longestTag;
        case amino_acids_annotated:
            peptide = peptideAssumption.getPeptide();
            spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
            annotationParameters = identificationParameters.getAnnotationParameters();
            modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
            modificationSequenceMatchingParameters = identificationParameters.getModificationLocalizationParameters().getSequenceMatchingParameters();
            specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
            matches = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationParameters, specificAnnotationParameters, spectrumFile, spectrumTitle, spectrum, peptide, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters);
            sequence = peptide.getSequence();
            sequenceLength = sequence.length();
            coverageForward = new boolean[sequenceLength];
            coverageRewind = new boolean[sequenceLength];
            Arrays.stream(matches).filter(ionMatch -> ionMatch.ion instanceof PeptideFragmentIon).map(ionMatch -> ((PeptideFragmentIon) ionMatch.ion)).forEach(peptideFragmentIon -> {
                if (PeptideFragmentIon.isForward(peptideFragmentIon.getSubType())) {
                    coverageForward[peptideFragmentIon.getNumber() - 1] = true;
                } else {
                    coverageRewind[peptideFragmentIon.getNumber() - 1] = true;
                }
            });
            aaCoverageB = new boolean[sequenceLength];
            previous = true;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                boolean current = coverageForward[aaIndex];
                if (current && previous) {
                    aaCoverageB[aaIndex] = true;
                }
                previous = current;
            }
            previous = true;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                boolean current = coverageRewind[aaIndex];
                if (current && previous) {
                    aaCoverageB[sequenceLength - aaIndex - 1] = true;
                }
                previous = current;
            }
            StringBuilder tag = new StringBuilder();
            double gap = 0;
            for (int aaIndex = 0; aaIndex < sequenceLength; aaIndex++) {
                if (aaCoverageB[aaIndex]) {
                    if (gap > 0) {
                        tag.append("<").append(gap).append(">");
                    }
                    tag.append(sequence.charAt(aaIndex));
                    gap = 0;
                } else {
                    gap += AminoAcid.getAminoAcid(sequence.charAt(aaIndex)).getMonoisotopicMass();
                }
            }
            if (gap > 0) {
                tag.append("<").append(gap).append(">");
            }
            return tag.toString();
        default:
            return "Not implemented";
    }
}
Also used : ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) IntStream(java.util.stream.IntStream) PsFragmentFeature(com.compomics.util.io.export.features.peptideshaker.PsFragmentFeature) Arrays(java.util.Arrays) SpectrumIdentificationAssumption(com.compomics.util.experiment.identification.SpectrumIdentificationAssumption) ExportWriter(com.compomics.util.io.export.ExportWriter) IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) SpectrumMatchesIterator(com.compomics.util.experiment.identification.matches_iterators.SpectrumMatchesIterator) PsIdentificationAlgorithmMatchesFeature(com.compomics.util.io.export.features.peptideshaker.PsIdentificationAlgorithmMatchesFeature) TagAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.TagAssumption) PeptideUtils(com.compomics.util.experiment.identification.utils.PeptideUtils) HashMap(java.util.HashMap) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) TreeSet(java.util.TreeSet) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) WaitingHandler(com.compomics.util.waiting.WaitingHandler) PeptideFragmentIon(com.compomics.util.experiment.biology.ions.impl.PeptideFragmentIon) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) Advocate(com.compomics.util.experiment.identification.Advocate) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) AminoAcid(com.compomics.util.experiment.biology.aminoacids.AminoAcid) EnumSet(java.util.EnumSet) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) IonMatch(com.compomics.util.experiment.identification.matches.IonMatch) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) PeptideAssumption(com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) ExportFeature(com.compomics.util.io.export.ExportFeature) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) Identification(com.compomics.util.experiment.identification.Identification) Tag(com.compomics.util.experiment.identification.amino_acid_tags.Tag) IOException(java.io.IOException) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) Collectors(java.util.stream.Collectors) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) PeptideSpectrumAnnotator(com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) PSParameter(com.compomics.util.experiment.identification.peptide_shaker.PSParameter) TreeMap(java.util.TreeMap) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) Collections(java.util.Collections) HashMap(java.util.HashMap) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) Precursor(com.compomics.util.experiment.mass_spectrometry.spectra.Precursor) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) IonMatch(com.compomics.util.experiment.identification.matches.IonMatch) TreeSet(java.util.TreeSet) PeptideFragmentIon(com.compomics.util.experiment.biology.ions.impl.PeptideFragmentIon) Peptide(com.compomics.util.experiment.biology.proteins.Peptide) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters)

Aggregations

Precursor (com.compomics.util.experiment.mass_spectrometry.spectra.Precursor)8 Spectrum (com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum)6 SequenceMatchingParameters (com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters)6 ModificationParameters (com.compomics.util.parameters.identification.search.ModificationParameters)6 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)5 PeptideAssumption (com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption)5 SequenceProvider (com.compomics.util.experiment.io.biology.protein.SequenceProvider)5 SpectrumProvider (com.compomics.util.experiment.mass_spectrometry.SpectrumProvider)5 HashSet (java.util.HashSet)5 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)4 AnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters)4 SpecificAnnotationParameters (com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters)4 PeptideSpectrumAnnotator (com.compomics.util.experiment.identification.spectrum_annotation.spectrum_annotators.PeptideSpectrumAnnotator)4 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)4 TitledBorder (javax.swing.border.TitledBorder)4 Identification (com.compomics.util.experiment.identification.Identification)3 SpectrumIdentificationAssumption (com.compomics.util.experiment.identification.SpectrumIdentificationAssumption)3 IonMatch (com.compomics.util.experiment.identification.matches.IonMatch)3 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)3 SearchParameters (com.compomics.util.parameters.identification.search.SearchParameters)3