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;
}
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));
}
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();
}
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();
}
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;
}
Aggregations