Search in sources :

Example 6 with Modification

use of com.compomics.util.experiment.biology.modifications.Modification in project peptide-shaker by compomics.

the class QCPanel method getPeptideModificationEfficiencyDataset.

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

Example 7 with Modification

use of com.compomics.util.experiment.biology.modifications.Modification in project peptide-shaker by compomics.

the class StirRunnable method scoreModificationLocalization.

/**
 * Scores the modification localization for the given peptide in the given
 * spectrum match. The scores are returned in a map: modification mass to
 * modification site to modification score.
 *
 * @param spectrumMatch The spectrum match.
 * @param peptideAssumption The peptide assumption.
 *
 * @return The modification localization scores in a map.
 */
private TreeMap<Double, HashMap<Integer, Double>> scoreModificationLocalization(SpectrumMatch spectrumMatch, PeptideAssumption peptideAssumption) {
    SearchParameters searchParameters = identificationParameters.getSearchParameters();
    AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
    SequenceMatchingParameters sequenceMatchingParameters = identificationParameters.getSequenceMatchingParameters();
    ModificationParameters modificationParameters = identificationParameters.getSearchParameters().getModificationParameters();
    ModificationLocalizationParameters modificationLocalizationParameters = identificationParameters.getModificationLocalizationParameters();
    SequenceMatchingParameters modificationSequenceMatchingParameters = modificationLocalizationParameters.getSequenceMatchingParameters();
    Peptide peptide = peptideAssumption.getPeptide();
    String spectrumFile = spectrumMatch.getSpectrumFile();
    String spectrumTitle = spectrumMatch.getSpectrumTitle();
    Spectrum spectrum = spectrumProvider.getSpectrum(spectrumFile, spectrumTitle);
    HashMap<Double, ArrayList<Modification>> modificationsMap = new HashMap<>(1);
    for (ModificationMatch modificationMatch : peptide.getVariableModifications()) {
        Modification refMod = modificationFactory.getModification(modificationMatch.getModification());
        double modMass = refMod.getMass();
        if (!modificationsMap.containsKey(modMass)) {
            ArrayList<Modification> modifications = modificationFactory.getSameMassNotFixedModifications(modMass, searchParameters).stream().map(modification -> modificationFactory.getModification(modification)).collect(Collectors.toCollection(ArrayList::new));
            modificationsMap.put(modMass, modifications);
        }
    }
    SpecificAnnotationParameters specificAnnotationParameters = annotationParameters.getSpecificAnnotationParameters(spectrumFile, spectrumTitle, peptideAssumption, modificationParameters, sequenceProvider, modificationSequenceMatchingParameters, peptideSpectrumAnnotator);
    return modificationsMap.entrySet().stream().collect(Collectors.toMap(entry -> entry.getKey(), entry -> PhosphoRS.getSequenceProbabilities(peptide, entry.getValue(), modificationParameters, spectrum, sequenceProvider, annotationParameters, specificAnnotationParameters, modificationLocalizationParameters.isProbabilisticScoreNeutralLosses(), sequenceMatchingParameters, modificationSequenceMatchingParameters, peptideSpectrumAnnotator), (a, b) -> a, TreeMap::new));
}
Also used : ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) IntStream(java.util.stream.IntStream) PeptideVariantMatches(com.compomics.util.experiment.identification.matches.PeptideVariantMatches) ModificationFactory(com.compomics.util.experiment.biology.modifications.ModificationFactory) Arrays(java.util.Arrays) FastaMapper(com.compomics.util.experiment.identification.protein_inference.FastaMapper) IdfileReader(com.compomics.util.experiment.io.identification.IdfileReader) HashMap(java.util.HashMap) SpectrumMatch(com.compomics.util.experiment.identification.matches.SpectrumMatch) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Modification(com.compomics.util.experiment.biology.modifications.Modification) WaitingHandler(com.compomics.util.waiting.WaitingHandler) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) Map(java.util.Map) SpectrumProvider(com.compomics.util.experiment.mass_spectrometry.SpectrumProvider) PhosphoRS(com.compomics.util.experiment.identification.modification.scores.PhosphoRS) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) 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) SimpleMzIdentMLExporter(com.compomics.util.experiment.io.identification.writers.SimpleMzIdentMLExporter) SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) 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) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) PeptideProteinMapping(com.compomics.util.experiment.identification.protein_inference.PeptideProteinMapping) TreeMap(java.util.TreeMap) ModificationLocalizationMapper(com.compomics.util.experiment.identification.modification.mapping.ModificationLocalizationMapper) CliLogger(com.compomics.software.log.CliLogger) ModificationNameMapper(com.compomics.util.experiment.identification.modification.mapping.ModificationNameMapper) ModificationLocalizationParameters(com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Modification(com.compomics.util.experiment.biology.modifications.Modification) ModificationMatch(com.compomics.util.experiment.identification.matches.ModificationMatch) HashMap(java.util.HashMap) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) AnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.AnnotationParameters) ArrayList(java.util.ArrayList) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters) SpecificAnnotationParameters(com.compomics.util.experiment.identification.spectrum_annotation.SpecificAnnotationParameters) Spectrum(com.compomics.util.experiment.mass_spectrometry.spectra.Spectrum) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) ModificationLocalizationParameters(com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters) SequenceMatchingParameters(com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters) Peptide(com.compomics.util.experiment.biology.proteins.Peptide)

Example 8 with Modification

use of com.compomics.util.experiment.biology.modifications.Modification in project peptide-shaker by compomics.

the class DeepLcUtils method getModifications.

/**
 * Returns the modifications of the peptides encoded as required by DeepLc.
 *
 * @param peptide The pepitde.
 * @param modificationParameters The modification parameters of the search.
 * @param sequenceMatchingParameters The sequence matching parameters.
 * @param sequenceProvider The sequence provider.
 * @param modificationFactory The factory containing the modification
 * details
 *
 * @return the modifications of the peptides encoded as required by DeepLc.
 */
public static String getModifications(Peptide peptide, ModificationParameters modificationParameters, SequenceProvider sequenceProvider, SequenceMatchingParameters sequenceMatchingParameters, ModificationFactory modificationFactory) {
    String peptideSequence = peptide.getSequence();
    // Fixed modifications
    String[] fixedModifications = peptide.getFixedModifications(modificationParameters, sequenceProvider, sequenceMatchingParameters);
    StringBuilder modificationSites = new StringBuilder();
    for (int i = 0; i < fixedModifications.length; i++) {
        if (fixedModifications[i] != null) {
            int site = i < peptideSequence.length() + 1 ? i : -1;
            String modName = fixedModifications[i];
            Modification modification = modificationFactory.getModification(modName);
            CvTerm cvTerm = modification.getUnimodCvTerm();
            if (cvTerm == null) {
                throw new IllegalArgumentException("No Unimod id found for modification " + modName + ".");
            }
            String unimodName = cvTerm.getName();
            if (modificationSites.length() > 0) {
                modificationSites.append('|');
            }
            modificationSites.append(site).append('|').append(unimodName);
        }
    }
    // Variable modifications
    String[] variableModifications = peptide.getIndexedVariableModifications();
    for (int i = 0; i < variableModifications.length; i++) {
        if (variableModifications[i] != null) {
            int site = i < peptideSequence.length() + 1 ? i : -1;
            String modName = variableModifications[i];
            Modification modification = modificationFactory.getModification(modName);
            CvTerm cvTerm = modification.getUnimodCvTerm();
            if (cvTerm == null) {
                throw new IllegalArgumentException("No Unimod id found for modification " + modName + ".");
            }
            String unimodName = cvTerm.getName();
            if (modificationSites.length() > 0) {
                modificationSites.append('|');
            }
            modificationSites.append(site).append('|').append(unimodName);
        }
    }
    return modificationSites.toString();
}
Also used : Modification(com.compomics.util.experiment.biology.modifications.Modification) CvTerm(com.compomics.util.pride.CvTerm)

Example 9 with Modification

use of com.compomics.util.experiment.biology.modifications.Modification in project peptide-shaker by compomics.

the class Ms2PipUtils method getPeptideData.

/**
 * Gets the peptide data to provide to ms2pip.
 *
 * @param peptideAssumption The peptide assumption.
 * @param modificationParameters The modification parameters of the search.
 * @param sequenceMatchingParameters The sequence matching parameters.
 * @param sequenceProvider The sequence provider.
 * @param modificationFactory The factory containing the modification details
 *
 * @return The peptide data as string.
 */
public static String getPeptideData(PeptideAssumption peptideAssumption, ModificationParameters modificationParameters, SequenceProvider sequenceProvider, SequenceMatchingParameters sequenceMatchingParameters, ModificationFactory modificationFactory) {
    // Peptide sequence
    Peptide peptide = peptideAssumption.getPeptide();
    String peptideSequence = peptide.getSequence();
    // Fixed modifications
    String[] fixedModifications = peptide.getFixedModifications(modificationParameters, sequenceProvider, sequenceMatchingParameters);
    StringBuilder modificationSites = new StringBuilder();
    for (int i = 0; i < fixedModifications.length; i++) {
        if (fixedModifications[i] != null) {
            int site = i < peptideSequence.length() + 1 ? i : -1;
            String modName = fixedModifications[i];
            Modification modification = modificationFactory.getModification(modName);
            CvTerm cvTerm = modification.getUnimodCvTerm();
            if (cvTerm == null) {
                throw new IllegalArgumentException("No Unimod id found for modification " + modName + ".");
            }
            String unimodName = cvTerm.getName();
            if (modificationSites.length() > 0) {
                modificationSites.append('|');
            }
            modificationSites.append(site).append('|').append(unimodName);
        }
    }
    // Variable modifications
    String[] variableModifications = peptide.getIndexedVariableModifications();
    for (int i = 0; i < variableModifications.length; i++) {
        if (variableModifications[i] != null) {
            int site = i < peptideSequence.length() + 1 ? i : -1;
            String modName = variableModifications[i];
            Modification modification = modificationFactory.getModification(modName);
            CvTerm cvTerm = modification.getUnimodCvTerm();
            if (cvTerm == null) {
                throw new IllegalArgumentException("No Unimod id found for modification " + modName + ".");
            }
            String unimodName = cvTerm.getName();
            if (modificationSites.length() > 0) {
                modificationSites.append('|');
            }
            modificationSites.append(site).append('|').append(unimodName);
        }
    }
    if (modificationSites.length() == 0) {
        modificationSites.append('-');
    }
    return new StringBuilder().append(modificationSites).append(' ').append(peptideSequence).append(' ').append(peptideAssumption.getIdentificationCharge()).toString();
}
Also used : Modification(com.compomics.util.experiment.biology.modifications.Modification) CvTerm(com.compomics.util.pride.CvTerm) Peptide(com.compomics.util.experiment.biology.proteins.Peptide)

Example 10 with Modification

use of com.compomics.util.experiment.biology.modifications.Modification in project peptide-shaker by compomics.

the class PeptideShakerGUI method getCurrentMassDeltas.

/**
 * Get the current delta masses for use when annotating the spectra.
 *
 * @return the current delta masses
 */
public HashMap<Double, String> getCurrentMassDeltas() {
    HashMap<Double, String> knownMassDeltas = new HashMap<>();
    // add the monoisotopic amino acids masses
    knownMassDeltas.put(AminoAcid.A.getMonoisotopicMass(), "A");
    knownMassDeltas.put(AminoAcid.R.getMonoisotopicMass(), "R");
    knownMassDeltas.put(AminoAcid.N.getMonoisotopicMass(), "N");
    knownMassDeltas.put(AminoAcid.D.getMonoisotopicMass(), "D");
    knownMassDeltas.put(AminoAcid.C.getMonoisotopicMass(), "C");
    knownMassDeltas.put(AminoAcid.Q.getMonoisotopicMass(), "Q");
    knownMassDeltas.put(AminoAcid.E.getMonoisotopicMass(), "E");
    knownMassDeltas.put(AminoAcid.G.getMonoisotopicMass(), "G");
    knownMassDeltas.put(AminoAcid.H.getMonoisotopicMass(), "H");
    knownMassDeltas.put(AminoAcid.I.getMonoisotopicMass(), "I/L");
    knownMassDeltas.put(AminoAcid.K.getMonoisotopicMass(), "K");
    knownMassDeltas.put(AminoAcid.M.getMonoisotopicMass(), "M");
    knownMassDeltas.put(AminoAcid.F.getMonoisotopicMass(), "F");
    knownMassDeltas.put(AminoAcid.P.getMonoisotopicMass(), "P");
    knownMassDeltas.put(AminoAcid.S.getMonoisotopicMass(), "S");
    knownMassDeltas.put(AminoAcid.T.getMonoisotopicMass(), "T");
    knownMassDeltas.put(AminoAcid.W.getMonoisotopicMass(), "W");
    knownMassDeltas.put(AminoAcid.Y.getMonoisotopicMass(), "Y");
    knownMassDeltas.put(AminoAcid.V.getMonoisotopicMass(), "V");
    knownMassDeltas.put(AminoAcid.U.getMonoisotopicMass(), "U");
    knownMassDeltas.put(AminoAcid.O.getMonoisotopicMass(), "O");
    // add default neutral losses
    // knownMassDeltas.put(NeutralLoss.H2O.mass, "H2O");
    // knownMassDeltas.put(NeutralLoss.NH3.mass, "NH3");
    // knownMassDeltas.put(NeutralLoss.CH4OS.mass, "CH4OS");
    // knownMassDeltas.put(NeutralLoss.H3PO4.mass, "H3PO4");
    // knownMassDeltas.put(NeutralLoss.HPO3.mass, "HPO3");
    // knownMassDeltas.put(4d, "18O"); // @TODO: should this be added to neutral losses??
    // knownMassDeltas.put(44d, "PEG"); // @TODO: should this be added to neutral losses??
    // add the modifications
    SearchParameters searchParameters = getIdentificationParameters().getSearchParameters();
    ModificationParameters modificationProfile = searchParameters.getModificationParameters();
    ArrayList<String> modificationList = modificationProfile.getAllModifications();
    Collections.sort(modificationList);
    // iterate the modifications list and add the non-terminal modifications
    for (String modName : modificationList) {
        Modification modification = modificationFactory.getModification(modName);
        if (modification.getModificationType() == ModificationType.modaa) {
            for (char aa : modification.getPattern().getAminoAcidsAtTarget()) {
                AminoAcid aminoAcid = AminoAcid.getAminoAcid(aa);
                double massKey = aminoAcid.getMonoisotopicMass() + modification.getMass();
                String annotationValue = String.join("", Character.toString(aa), "<", modification.getShortName(), ">");
                knownMassDeltas.put(massKey, annotationValue);
            }
        }
    }
    return knownMassDeltas;
}
Also used : SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) Modification(com.compomics.util.experiment.biology.modifications.Modification) HashMap(java.util.HashMap) AminoAcid(com.compomics.util.experiment.biology.aminoacids.AminoAcid) ModificationParameters(com.compomics.util.parameters.identification.search.ModificationParameters)

Aggregations

Modification (com.compomics.util.experiment.biology.modifications.Modification)24 Peptide (com.compomics.util.experiment.biology.proteins.Peptide)14 ModificationMatch (com.compomics.util.experiment.identification.matches.ModificationMatch)12 HashMap (java.util.HashMap)12 ModificationParameters (com.compomics.util.parameters.identification.search.ModificationParameters)11 ModificationFactory (com.compomics.util.experiment.biology.modifications.ModificationFactory)10 ArrayList (java.util.ArrayList)10 SearchParameters (com.compomics.util.parameters.identification.search.SearchParameters)9 TreeMap (java.util.TreeMap)9 SequenceMatchingParameters (com.compomics.util.parameters.identification.advanced.SequenceMatchingParameters)8 ModificationScoring (com.compomics.util.experiment.identification.peptide_shaker.ModificationScoring)7 PSModificationScores (com.compomics.util.experiment.identification.peptide_shaker.PSModificationScores)7 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)7 ModificationLocalizationParameters (com.compomics.util.parameters.identification.advanced.ModificationLocalizationParameters)7 HashSet (java.util.HashSet)7 ModificationType (com.compomics.util.experiment.biology.modifications.ModificationType)6 PeptideMatch (com.compomics.util.experiment.identification.matches.PeptideMatch)6 SpectrumMatch (com.compomics.util.experiment.identification.matches.SpectrumMatch)6 PSParameter (com.compomics.util.experiment.identification.peptide_shaker.PSParameter)6 PeptideAssumption (com.compomics.util.experiment.identification.spectrum_assumptions.PeptideAssumption)6