Package com.compomics.util.experiment.identification.matches

Examples of com.compomics.util.experiment.identification.matches.ModificationMatch


                                            }
                                        }
                                    }

                                    // If a terminal modification cannot be elsewhere lock the terminus
                                    ModificationMatch nTermModification = null;
                                    for (ModificationMatch modMatch : peptide.getModificationMatches()) {
                                        if (modMatch.isVariable() && !modMatch.getTheoreticPtm().equals(PTMFactory.unknownPTM.getName())) {
                                            double refMass = getRefMass(modMatch.getTheoreticPtm(), modificationProfile);
                                            int modSite = modMatch.getModificationSite();
                                            if (modSite == 1) {
                                                ArrayList<String> expectedNamesAtSite = expectedNames.get(modSite);
                                                if (expectedNamesAtSite != null) {
                                                    ArrayList<String> filteredNamesAtSite = new ArrayList<String>(expectedNamesAtSite.size());
                                                    for (String ptmName : expectedNamesAtSite) {
                                                        PTM ptm = ptmFactory.getPTM(ptmName);
                                                        if (Math.abs(ptm.getMass() - refMass) < searchParameters.getFragmentIonAccuracy()) {
                                                            filteredNamesAtSite.add(ptmName);
                                                        }
                                                    }
                                                    for (String modName : filteredNamesAtSite) {
                                                        PTM ptm = ptmFactory.getPTM(modName);
                                                        if (ptm.isNTerm()) {
                                                            boolean otherPossibleMod = false;
                                                            for (String tempName : modificationProfile.getAllNotFixedModifications()) {
                                                                if (!tempName.equals(modName)) {
                                                                    PTM tempPTM = ptmFactory.getPTM(tempName);
                                                                    if (tempPTM.getMass() == ptm.getMass() && !tempPTM.isNTerm()) {
                                                                        otherPossibleMod = true;
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                            if (!otherPossibleMod) {
                                                                nTermModification = modMatch;
                                                                modMatch.setTheoreticPtm(modName);
                                                                break;
                                                            }
                                                        }
                                                    }
                                                    if (nTermModification != null) {
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    ModificationMatch cTermModification = null;
                                    for (ModificationMatch modMatch : peptide.getModificationMatches()) {
                                        if (modMatch.isVariable() && !modMatch.getTheoreticPtm().equals(PTMFactory.unknownPTM.getName()) && modMatch != nTermModification) {
                                            double refMass = getRefMass(modMatch.getTheoreticPtm(), modificationProfile);
                                            int modSite = modMatch.getModificationSite();
                                            if (modSite == peptideSequence.length()) {
View Full Code Here


                        Peptide sePeptide = bestPeptideAssumption.getPeptide();
                        ArrayList<String> psProteins = new ArrayList<String>(sePeptide.getParentProteins(sequenceMatchingPreferences));
                        ArrayList<ModificationMatch> psModificationMatches = new ArrayList<ModificationMatch>();

                        for (ModificationMatch seModMatch : sePeptide.getModificationMatches()) {
                            psModificationMatches.add(new ModificationMatch(seModMatch.getTheoreticPtm(), seModMatch.isVariable(), seModMatch.getModificationSite()));
                        }

                        Peptide psPeptide = new Peptide(sePeptide.getSequence(), psModificationMatches);
                        psPeptide.setParentProteins(psProteins);
                        PeptideAssumption psAssumption = new PeptideAssumption(psPeptide, 1, Advocate.peptideShaker.getIndex(), bestPeptideAssumption.getIdentificationCharge(), retainedP);
View Full Code Here

                            confidentSites.put(ptmMass, ptmConfidentSites);
                        }
                        if (!ptmConfidentSites.contains(confidentSite)) {
                            ptmConfidentSites.add(confidentSite);
                            peptideScores.addConfidentModificationSite(ptmName, confidentSite);
                            ModificationMatch newMatch = new ModificationMatch(ptmName, true, confidentSite);
                            newMatch.setConfident(true);
                            ArrayList<ModificationMatch> newPtmMatches = newMatches.get(ptmMass);
                            if (newPtmMatches == null) {
                                newPtmMatches = new ArrayList<ModificationMatch>();
                                newMatches.put(ptmMass, newPtmMatches);
                            }
                            newPtmMatches.add(newMatch);
                            if (newPtmMatches.size() > variableModifications.get(ptmMass)) {
                                throw new IllegalArgumentException("More sites than PTMs on peptide " + peptideMatch.getKey() + " for PTM of mass " + ptmMass + ".");
                            }
                            ArrayList<Integer> ptmInferredSites = inferredSites.get(ptmMass);
                            if (ptmInferredSites != null) {
                                ptmInferredSites.remove(confidentSite);
                                if (ptmInferredSites.isEmpty()) {
                                    inferredSites.remove(ptmMass);
                                }
                            }
                        }
                    }
                }
            }

            boolean enoughSites = true;
            for (double ptmMass : variableModifications.keySet()) {
                int nPtms = variableModifications.get(ptmMass);
                int nConfident = 0;
                ArrayList<Integer> ptmConfidentSites = confidentSites.get(ptmMass);
                if (ptmConfidentSites != null) {
                    nConfident = ptmConfidentSites.size();
                }
                if (nConfident < nPtms) {
                    enoughSites = false;
                    break;
                }
            }
            if (!enoughSites) {

                HashMap<Double, HashMap<Double, HashMap<Double, HashMap<Integer, ArrayList<String>>>>> ambiguousSites = new HashMap<Double, HashMap<Double, HashMap<Double, HashMap<Integer, ArrayList<String>>>>>();

                for (String spectrumKey : bestKeys) {

                    psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
                    SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                    PSPtmScores psmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());

                    for (int representativeSite : psmScores.getRepresentativeSites()) {
                        HashMap<Integer, ArrayList<String>> ambiguousMappingAtSite = psmScores.getAmbiguousPtmsAtRepresentativeSite(representativeSite);
                        int mappingSize = ambiguousMappingAtSite.size();
                        for (int site : ambiguousMappingAtSite.keySet()) {
                            for (String ptmName : ambiguousMappingAtSite.get(site)) {
                                PTM ptm = ptmFactory.getPTM(ptmName);
                                Double ptmMass = ptm.getMass();
                                ArrayList<Integer> ptmConfidentSites = confidentSites.get(ptmMass);
                                if (ptmConfidentSites == null || !ptmConfidentSites.contains(site)) {
                                    double probabilisticScore = 0.0;
                                    double dScore = 0.0;
                                    PtmScoring ptmScoring = psmScores.getPtmScoring(ptmName);
                                    if (ptmScoring != null) {
                                        probabilisticScore = ptmScoring.getProbabilisticScore(site);
                                        dScore = ptmScoring.getDeltaScore(site);
                                    }
                                    HashMap<Double, HashMap<Double, HashMap<Integer, ArrayList<String>>>> pScoreMap = ambiguousSites.get(probabilisticScore);
                                    if (pScoreMap == null) {
                                        pScoreMap = new HashMap<Double, HashMap<Double, HashMap<Integer, ArrayList<String>>>>(mappingSize);
                                        ambiguousSites.put(probabilisticScore, pScoreMap);
                                    }
                                    HashMap<Double, HashMap<Integer, ArrayList<String>>> dScoreMap = pScoreMap.get(dScore);
                                    if (dScoreMap == null) {
                                        dScoreMap = new HashMap<Double, HashMap<Integer, ArrayList<String>>>(mappingSize);
                                        pScoreMap.put(dScore, dScoreMap);
                                    }
                                    HashMap<Integer, ArrayList<String>> ptmMap = dScoreMap.get(ptmMass);
                                    if (ptmMap == null) {
                                        ptmMap = new HashMap<Integer, ArrayList<String>>(1);
                                        dScoreMap.put(ptmMass, ptmMap);
                                    }
                                    ArrayList<String> modifications = ptmMap.get(site);
                                    if (modifications == null) {
                                        modifications = new ArrayList<String>(1);
                                        ptmMap.put(site, modifications);
                                    }
                                    if (!modifications.contains(ptmName)) {
                                        modifications.add(ptmName);
                                    }
                                }
                            }
                        }
                    }
                }

                HashMap<Double, Integer> nRepresentativesMap = new HashMap<Double, Integer>();
                for (double ptmMass : variableModifications.keySet()) {
                    int nPtm = variableModifications.get(ptmMass);
                    int nConfident = 0;
                    ArrayList<Integer> ptmConfidentSites = confidentSites.get(ptmMass);
                    if (ptmConfidentSites != null) {
                        nConfident = ptmConfidentSites.size();
                    }
                    if (nConfident < nPtm) {
                        int nRepresentatives = nPtm - nConfident;
                        if (nRepresentatives > 0) {
                            nRepresentativesMap.put(ptmMass, nRepresentatives);
                        }
                    }
                }

                HashMap<Double, HashMap<Integer, HashMap<Integer, ArrayList<String>>>> representativeToSecondaryMap = getRepresentativeToSecondaryMap(ambiguousSites, nRepresentativesMap, inferredSites);

                for (Double ptmMass : representativeToSecondaryMap.keySet()) {
                    HashMap<Integer, HashMap<Integer, ArrayList<String>>> representativesAtMass = representativeToSecondaryMap.get(ptmMass);
                    ArrayList<Integer> ptmInferredSites = inferredSites.get(ptmMass);
                    for (int representativeSite : representativesAtMass.keySet()) {
                        HashMap<Integer, ArrayList<String>> siteToPtmMap = representativesAtMass.get(representativeSite);
                        peptideScores.addAmbiguousModificationSites(representativeSite, siteToPtmMap);
                        for (String ptmName : siteToPtmMap.get(representativeSite)) {
                            ModificationMatch newMatch = new ModificationMatch(ptmName, true, representativeSite);
                            newMatch.setConfident(false);
                            if (ptmInferredSites != null && ptmInferredSites.contains(representativeSite)) {
                                newMatch.setInferred(true);
                            }
                            ArrayList<ModificationMatch> newPtmMatches = newMatches.get(ptmMass);
                            if (newPtmMatches == null) {
                                newPtmMatches = new ArrayList<ModificationMatch>();
                                newMatches.put(ptmMass, newPtmMatches);
View Full Code Here

                                    nonConfidentMatches.put(modificationMatch.getModificationSite(), modificationMatch);
                                }
                            }
                            HashMap<Integer, Integer> mapping = PtmSiteMapping.align(nonConfidentMatches.keySet(), newLocalizationCandidates);
                            for (Integer oldLocalization : mapping.keySet()) {
                                ModificationMatch modificationMatch = nonConfidentMatches.get(oldLocalization);
                                Integer newLocalization = mapping.get(oldLocalization);
                                if (modificationMatch == null) {
                                    throw new IllegalArgumentException("No modification match found at site " + oldLocalization + " in spectrum " + spectrumKey + ".");
                                }
                                if (newLocalization != null) {
                                    if (newLocalization != oldLocalization) {
                                        PTM ptmCandidate = null;
                                        for (String ptmName : searchParameters.getModificationProfile().getAllNotFixedModifications()) {
                                            PTM ptm = ptmFactory.getPTM(ptmName);
                                            if (ptm.getType() == PTM.MODAA && ptm.getMass() == ptm.getMass() && peptide.getPotentialModificationSites(ptm, sequenceMatchingPreferences).contains(newLocalization)) {
                                                ptmCandidate = ptm;
                                                break;
                                            }
                                        }
                                        if (ptmCandidate == null) {
                                            throw new IllegalArgumentException("No PTM found for site " + newLocalization + " on  peptide " + peptide.getSequence() + " in spectrum " + spectrumKey + ".");
                                        }
                                        modificationMatch.setModificationSite(newLocalization);
                                        PSPtmScores psmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
                                        psmScores.changeRepresentativeSite(ptmCandidate.getName(), oldLocalization, newLocalization);
                                    }
                                    modificationMatch.setInferred(true);
                                }
                            }
                        }
                        identification.updateSpectrumMatch(spectrumMatch);
                    }
View Full Code Here

                            PtmScoring ptmScoring = ptmScores.getPtmScoring(modName);
                            if (ptmScoring == null) {
                                ptmScoring = new PtmScoring(modName);
                                ptmScores.addPtmScoring(modName, ptmScoring);
                            }
                            ModificationMatch modificationMatch = null;
                            if (cpt < nPTMs) {
                                modificationMatch = ptmMatches.get(cpt);
                                modificationMatch.setModificationSite(site);
                                modificationMatch.setTheoreticPtm(modName);
                            }
                            if (pScore <= randomThreshold || !enoughPtms) {
                                ptmScoring.setSiteConfidence(site, PtmScoring.RANDOM);
                                if (modificationMatch != null) {
                                    modificationMatch.setConfident(false);
                                }
                            } else if (pScore <= doubtfulThreshold) {
                                ptmScoring.setSiteConfidence(site, PtmScoring.DOUBTFUL);
                                if (modificationMatch != null) {
                                    modificationMatch.setConfident(false);
                                }
                            } else {
                                ptmScoring.setSiteConfidence(site, PtmScoring.VERY_CONFIDENT);
                                if (modificationMatch != null) {
                                    modificationMatch.setConfident(true);
                                }
                                confidentSites.put(site, modName);
                            }
                            if (modificationMatch == null || !modificationMatch.isConfident()) {
                                HashMap<Double, HashMap<Double, HashMap<Integer, ArrayList<String>>>> pScoreAmbiguousMap = ambiguousScoreToSiteMap.get(pScore);
                                if (pScoreAmbiguousMap == null) {
                                    pScoreAmbiguousMap = new HashMap<Double, HashMap<Double, HashMap<Integer, ArrayList<String>>>>(nPotentialSites);
                                    ambiguousScoreToSiteMap.put(pScore, pScoreAmbiguousMap);
                                }
View Full Code Here

TOP

Related Classes of com.compomics.util.experiment.identification.matches.ModificationMatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.