Package com.compomics.util.experiment.biology

Examples of com.compomics.util.experiment.biology.Peptide


        PSPtmScores peptideScores = new PSPtmScores();
        PSParameter psParameter = new PSParameter();
        HashMap<Double, Integer> variableModifications = new HashMap<Double, Integer>();

        Peptide peptide = peptideMatch.getTheoreticPeptide();
        ArrayList<ModificationMatch> originalMatches = peptide.getModificationMatches();
        ArrayList<ModificationMatch> newModificationMatches = new ArrayList<ModificationMatch>(originalMatches.size());
        HashMap<Double, ArrayList<Integer>> inferredSites = new HashMap<Double, ArrayList<Integer>>();

        String originalKey = peptide.getMatchingKey(sequenceMatchingPreferences);

        for (ModificationMatch modificationMatch : originalMatches) {
            if (modificationMatch.isVariable()) {
                PTM ptm = ptmFactory.getPTM(modificationMatch.getTheoreticPtm());
                if (ptm.getType() == PTM.MODAA) {
                    Double ptmMass = ptm.getMass();
                    Integer nPtm = variableModifications.get(ptmMass);
                    if (nPtm == null) {
                        variableModifications.put(ptmMass, 1);
                    } else {
                        variableModifications.put(ptmMass, nPtm + 1);
                    }
                    if (modificationMatch.isInferred()) {
                        Integer modificationSite = modificationMatch.getModificationSite();
                        ArrayList<Integer> ptmInferredSites = inferredSites.get(ptmMass);
                        if (ptmInferredSites == null) {
                            ptmInferredSites = new ArrayList<Integer>();
                            inferredSites.put(ptmMass, ptmInferredSites);
                            ptmInferredSites.add(modificationSite);
                        } else if (!ptmInferredSites.contains(modificationSite)) {
                            ptmInferredSites.add(modificationSite);
                        }
                    }
                } else {
                    newModificationMatches.add(modificationMatch);
                }
            } else {
                newModificationMatches.add(modificationMatch);
            }
        }

        HashMap<Double, ArrayList<ModificationMatch>> newMatches = new HashMap<Double, ArrayList<ModificationMatch>>(variableModifications.size());

        if (variableModifications.size() > 0) {

            ArrayList<String> bestKeys = new ArrayList<String>();

            identification.loadSpectrumMatches(peptideMatch.getSpectrumMatches(), null);
            identification.loadSpectrumMatchParameters(peptideMatch.getSpectrumMatches(), psParameter, null);

            boolean validated = false;
            for (String spectrumKey : peptideMatch.getSpectrumMatches()) {
                psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
                MatchValidationLevel matchValidationLevel = psParameter.getMatchValidationLevel();
                if (matchValidationLevel.isValidated() && !validated) {
                    bestKeys.clear();
                    validated = true;
                }
                bestKeys.add(spectrumKey);
            }

            identification.loadSpectrumMatches(bestKeys, null);
            identification.loadSpectrumMatchParameters(bestKeys, psParameter, null);

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

            // Map confident sites
            for (String spectrumKey : bestKeys) {
                psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
                SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                PSPtmScores psmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());

                for (String ptmName : psmScores.getScoredPTMs()) {
                    PtmScoring psmScoring = psmScores.getPtmScoring(ptmName);
                    PtmScoring peptideScoring = peptideScores.getPtmScoring(ptmName);
                    if (peptideScoring == null) {
                        peptideScoring = new PtmScoring(ptmName);
                        peptideScores.addPtmScoring(ptmName, peptideScoring);
                    }
                    for (int site : psmScoring.getAllPtmLocations()) {
                        double psmDScore = psmScoring.getDeltaScore(site);
                        double peptideDScore = peptideScoring.getDeltaScore(site);
                        if (peptideDScore < psmDScore) {
                            peptideScoring.setDeltaScore(site, psmDScore);
                        }
                        double psmPScore = psmScoring.getProbabilisticScore(site);
                        double peptidePScore = peptideScoring.getProbabilisticScore(site);
                        if (peptidePScore < psmPScore) {
                            peptideScoring.setProbabilisticScore(site, psmPScore);
                        }
                        int psmValidationLevel = psmScoring.getLocalizationConfidence(site);
                        int peptideValidationLevel = peptideScoring.getLocalizationConfidence(site);
                        if (peptideValidationLevel < psmValidationLevel) {
                            peptideScoring.setSiteConfidence(site, psmValidationLevel);
                        }
                    }
                }

                for (Integer confidentSite : psmScores.getConfidentSites()) {
                    for (String ptmName : psmScores.getConfidentModificationsAt(confidentSite)) {
                        PTM ptm = ptmFactory.getPTM(ptmName);
                        Double ptmMass = ptm.getMass();
                        ArrayList<Integer> ptmConfidentSites = confidentSites.get(ptmMass);
                        if (ptmConfidentSites == null) {
                            ptmConfidentSites = new ArrayList<Integer>();
                            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);
                            }
                            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 + ".");
                            }
                        }
                    }
                }
            }

            for (ArrayList<ModificationMatch> modificationMatches : newMatches.values()) {
                newModificationMatches.addAll(modificationMatches);
            }
            peptide.setModificationMatches(newModificationMatches);

            peptideMatch.addUrParam(peptideScores);

            String newKey = peptide.getMatchingKey(sequenceMatchingPreferences);
            if (!newKey.equals(originalKey)) {
                if (identification.getPeptideIdentification().contains(newKey)) {
                    throw new IllegalArgumentException("Attempting to create duplicate peptide key: " + newKey + ".");
                }
                identification.updatePeptideMatch(originalKey, newKey, peptideMatch);
View Full Code Here


                identification.loadSpectrumMatches(spectrumKeys, null);

                for (String spectrumKey : spectrumKeys) {

                    SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                    Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
                    String sequence = peptide.getSequence();
                    String notConfidentKey = peptide.getMatchingKey(sequenceMatchingPreferences);
                    int nMod = Peptide.getModificationCount(notConfidentKey, ptmMass);
                    ArrayList<Integer> tempLocalizations, oldLocalizations = Peptide.getNModificationLocalized(notConfidentKey, ptmMass);
                    ArrayList<Integer> newLocalizationCandidates = new ArrayList<Integer>();

                    HashMap<String, ArrayList<String>> ptmConfidentPeptides = confidentPeptideInference.get(ptmMass);

                    if (ptmConfidentPeptides != null) {

                        // See if we can explain this peptide by another already identified peptide with the same number of modifications (the two peptides will be merged)
                        ArrayList<String> keys = ptmConfidentPeptides.get(sequence);

                        if (keys != null) {
                            for (String tempKey : keys) {
                                SpectrumMatch secondaryMatch = identification.getSpectrumMatch(tempKey);
                                String secondaryKey = secondaryMatch.getBestPeptideAssumption().getPeptide().getMatchingKey(sequenceMatchingPreferences);
                                if (Peptide.getModificationCount(secondaryKey, ptmMass) == nMod) {
                                    tempLocalizations = Peptide.getNModificationLocalized(secondaryKey, ptmMass);
                                    for (int localization : tempLocalizations) {
                                        if (!oldLocalizations.contains(localization) && !newLocalizationCandidates.contains(localization)) {
                                            newLocalizationCandidates.add(localization);
                                        }
                                    }
                                }
                            }
                            if (oldLocalizations.size() + newLocalizationCandidates.size() < nMod) {
                                // we cannot merge this peptide, see whether we can explain the remaining modifications using peptides with the same sequence but other modification profile
                                for (String tempKey : keys) {
                                    SpectrumMatch secondaryMatch = identification.getSpectrumMatch(tempKey);
                                    String secondaryKey = secondaryMatch.getBestPeptideAssumption().getPeptide().getMatchingKey(sequenceMatchingPreferences);
                                    tempLocalizations = Peptide.getNModificationLocalized(secondaryKey, ptmMass);
                                    for (int localization : tempLocalizations) {
                                        if (!oldLocalizations.contains(localization) && !newLocalizationCandidates.contains(localization)) {
                                            newLocalizationCandidates.add(localization);
                                        }
                                    }
                                }
                            }
                        }
                        if (oldLocalizations.size() + newLocalizationCandidates.size() < nMod) {
                            // There are still unexplained sites, let's see if we find a related peptide which can help.
                            HashMap<String, ArrayList<String>> confidentAtMass = confidentPeptideInference.get(ptmMass);
                            for (String otherSequence : confidentAtMass.keySet()) {
                                if (!sequence.equals(otherSequence) && sequence.contains(otherSequence)) {
                                    for (String tempKey : confidentAtMass.get(otherSequence)) {
                                        SpectrumMatch secondaryMatch = identification.getSpectrumMatch(tempKey);
                                        String secondaryKey = secondaryMatch.getBestPeptideAssumption().getPeptide().getMatchingKey(sequenceMatchingPreferences);
                                        tempLocalizations = Peptide.getNModificationLocalized(secondaryKey, ptmMass);
                                        int tempIndex, ref = 0;
                                        String tempSequence = sequence;
                                        while ((tempIndex = tempSequence.indexOf(otherSequence)) >= 0) {
                                            ref += tempIndex;
                                            for (int localization : tempLocalizations) {
                                                int shiftedLocalization = ref + localization;
                                                if (!oldLocalizations.contains(shiftedLocalization) && !newLocalizationCandidates.contains(shiftedLocalization)) {
                                                    boolean candidatePtm = false;
                                                    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(shiftedLocalization)) {
                                                            candidatePtm = true;
                                                            break;
                                                        }
                                                    }
                                                    if (candidatePtm) {
                                                        newLocalizationCandidates.add(shiftedLocalization);
                                                    }
                                                }
                                            }
                                            tempSequence = tempSequence.substring(tempIndex + 1);
                                            ref++;
                                        }
                                    }
                                } else if (!sequence.equals(otherSequence) && otherSequence.contains(sequence)) {
                                    for (String tempKey : confidentAtMass.get(otherSequence)) {
                                        SpectrumMatch secondaryMatch = identification.getSpectrumMatch(tempKey);
                                        String secondaryKey = secondaryMatch.getBestPeptideAssumption().getPeptide().getMatchingKey(sequenceMatchingPreferences);
                                        tempLocalizations = Peptide.getNModificationLocalized(secondaryKey, ptmMass);
                                        int tempIndex, ref = 0;
                                        String tempSequence = otherSequence;
                                        while ((tempIndex = tempSequence.indexOf(sequence)) >= 0) {
                                            ref += tempIndex;
                                            for (int localization : tempLocalizations) {
                                                int shiftedLocalization = localization - ref;
                                                if (shiftedLocalization > 0 && shiftedLocalization <= sequence.length()
                                                        && !oldLocalizations.contains(shiftedLocalization) && !newLocalizationCandidates.contains(shiftedLocalization)) {
                                                    boolean candidatePtm = false;
                                                    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(shiftedLocalization)) {
                                                            candidatePtm = true;
                                                            break;
                                                        }
                                                    }
                                                    if (candidatePtm) {
                                                        newLocalizationCandidates.add(shiftedLocalization);
                                                    }
                                                }
                                            }
                                            tempSequence = tempSequence.substring(tempIndex + 1);
                                            ref++;
                                        }
                                    }
                                }
                            }
                        }
                        // Map the most likely inferred sites
                        if (!newLocalizationCandidates.isEmpty()) {
                            HashMap<Integer, ModificationMatch> nonConfidentMatches = new HashMap<Integer, ModificationMatch>();
                            for (ModificationMatch modificationMatch : peptide.getModificationMatches()) {
                                String ptmName = modificationMatch.getTheoreticPtm();
                                PTM ptm = ptmFactory.getPTM(ptmName);
                                if (ptm.getMass() == ptmMass && !modificationMatch.isConfident()) {
                                    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);
                                    }
View Full Code Here

     * while reading a protein sequence
     */
    private void ptmSiteInference(SpectrumMatch spectrumMatch, PTMScoringPreferences ptmScoringPreferences, SearchParameters searchParameters, SequenceMatchingPreferences sequenceMatchingPreferences)
            throws IOException, IllegalArgumentException, InterruptedException, FileNotFoundException, ClassNotFoundException, SQLException {

        Peptide psPeptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
        ModificationProfile modificationProfile = searchParameters.getModificationProfile();
        PSPtmScores ptmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
        HashMap<Double, ArrayList<ModificationMatch>> modMatchesMap = new HashMap<Double, ArrayList<ModificationMatch>>();
        HashMap<Double, HashMap<Integer, String>> possiblePositions = new HashMap<Double, HashMap<Integer, String>>();
        for (ModificationMatch modificationMatch : psPeptide.getModificationMatches()) {
            if (modificationMatch.isVariable()) {
                String modName = modificationMatch.getTheoreticPtm();
                PTM ptm = ptmFactory.getPTM(modName);
                if (ptm.getType() == PTM.MODAA) {
                    double ptmMass = ptm.getMass();
                    ArrayList<ModificationMatch> ptmOccurence = modMatchesMap.get(ptmMass);
                    if (ptmOccurence == null) {
                        ptmOccurence = new ArrayList<ModificationMatch>();
                        modMatchesMap.put(ptmMass, ptmOccurence);
                    }
                    ptmOccurence.add(modificationMatch);

                    HashMap<Integer, String> ptmPossibleSites = possiblePositions.get(ptmMass);
                    if (ptmPossibleSites == null) {
                        ptmPossibleSites = new HashMap<Integer, String>();
                        possiblePositions.put(ptmMass, ptmPossibleSites);
                    }
                    for (String similarPtmName : modificationProfile.getSimilarNotFixedModifications(ptmMass)) {
                        PTM similarPtm = ptmFactory.getPTM(similarPtmName);
                        for (int pos : psPeptide.getPotentialModificationSites(similarPtm, sequenceMatchingPreferences)) {
                            ptmPossibleSites.put(pos, similarPtmName);
                        }
                    }
                } else {
                    PtmScoring ptmScoring = ptmScores.getPtmScoring(modName);
                    ptmScoring.setSiteConfidence(modificationMatch.getModificationSite(), PtmScoring.VERY_CONFIDENT);
                    modificationMatch.setConfident(true);
                }
            }
        }

        Set<Double> ptmMasses = modMatchesMap.keySet();
        HashMap<Double, HashMap<Double, HashMap<Double, HashMap<Integer, ArrayList<String>>>>> ambiguousScoreToSiteMap = new HashMap<Double, HashMap<Double, HashMap<Double, HashMap<Integer, ArrayList<String>>>>>(ptmMasses.size()); // p score -> d-score -> Map PTM mass -> site -> list of modifications
        HashMap<Double, Integer> nRepresentativesMap = new HashMap<Double, Integer>();
        for (double ptmMass : ptmMasses) {
            ArrayList<ModificationMatch> ptmMatches = modMatchesMap.get(ptmMass);
            HashMap<Integer, String> ptmPotentialSites = possiblePositions.get(ptmMass);
            HashMap<Integer, String> confidentSites = new HashMap<Integer, String>();
            int nPTMs = ptmMatches.size(), nPotentialSites = ptmPotentialSites.size();
            if (nPotentialSites < nPTMs) {
                throw new IllegalArgumentException("The occurence of modification of mass " + ptmMass + " (" + ptmMatches.size()
                        + ") is higher than the number of possible sites (" + ptmPotentialSites.size() + ") on sequence " + psPeptide.getSequence()
                        + " in spectrum " + spectrumMatch.getKey() + ".");
            } else if (ptmPotentialSites.size() == ptmMatches.size()) {
                for (ModificationMatch modMatch : ptmMatches) {
                    String modName = modMatch.getTheoreticPtm();
                    int site = modMatch.getModificationSite();
View Full Code Here

     * @param spectrumMatch the spectrum match
     * @return a string with the HTML tooltip for the peptide
     */
    public String getPeptideModificationTooltipAsHtml(SpectrumMatch spectrumMatch) {
        try {
            Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
            PSPtmScores ptmScores = new PSPtmScores();
            ptmScores = (PSPtmScores) spectrumMatch.getUrParam(ptmScores);
            return getPeptideModificationTooltipAsHtml(peptide, ptmScores);
        } catch (Exception e) {
            exceptionHandler.catchException(e);
View Full Code Here

     * @param peptideMatch the peptide match
     * @return a string with the HTML tooltip for the peptide
     */
    public String getPeptideModificationTooltipAsHtml(PeptideMatch peptideMatch) {
        try {
            Peptide peptide = peptideMatch.getTheoreticPeptide();
            PSPtmScores ptmScores = new PSPtmScores();
            ptmScores = (PSPtmScores) peptideMatch.getUrParam(ptmScores);
            return getPeptideModificationTooltipAsHtml(peptide, ptmScores);
        } catch (Exception e) {
            exceptionHandler.catchException(e);
View Full Code Here

     *
     * @return the tagged peptide sequence
     */
    public String getTaggedPeptideSequence(PeptideMatch peptideMatch, boolean useHtmlColorCoding, boolean includeHtmlStartEndTags, boolean useShortName) {
        try {
            Peptide peptide = peptideMatch.getTheoreticPeptide();
            PSPtmScores ptmScores = new PSPtmScores();
            ptmScores = (PSPtmScores) peptideMatch.getUrParam(ptmScores);
            return getTaggedPeptideSequence(peptide, ptmScores, useHtmlColorCoding, includeHtmlStartEndTags, useShortName);
        } catch (Exception e) {
            exceptionHandler.catchException(e);
View Full Code Here

     * @param useShortName if true the short names are used in the tags
     * @return the tagged peptide sequence
     */
    public String getTaggedPeptideSequence(SpectrumMatch spectrumMatch, boolean useHtmlColorCoding, boolean includeHtmlStartEndTags, boolean useShortName) {
        try {
            Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
            PSPtmScores ptmScores = new PSPtmScores();
            ptmScores = (PSPtmScores) spectrumMatch.getUrParam(ptmScores);
            return getTaggedPeptideSequence(peptide, ptmScores, useHtmlColorCoding, includeHtmlStartEndTags, useShortName);
        } catch (Exception e) {
            exceptionHandler.catchException(e);
View Full Code Here

        if (assumptionFilter.getSequenceCoverage() != null) {

            SpectrumFactory spectrumFactory = SpectrumFactory.getInstance();
            MSnSpectrum spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumKey);
            Peptide peptide = peptideAssumption.getPeptide();
            if (peptideSpectrumAnnotator == null) {
                peptideSpectrumAnnotator = new PeptideSpectrumAnnotator();
            }
            HashMap<Integer, ArrayList<IonMatch>> ionMatches = peptideSpectrumAnnotator.getCoveredAminoAcids(annotationPreferences.getIonTypes(),
                    annotationPreferences.getNeutralLosses(), annotationPreferences.getValidatedCharges(),
                    peptideAssumption.getIdentificationCharge().value, spectrum, peptide, spectrum.getIntensityLimit(annotationPreferences.getAnnotationIntensityLimit()),
                    searchParameters.getFragmentIonAccuracy(), false, annotationPreferences.isHighResolutionAnnotation());

            double nCovered = 0;
            int nAA = peptide.getSequence().length();
            for (int i = 0; i <= nAA; i++) {
                ArrayList<IonMatch> matchesAtAa = ionMatches.get(i);
                if (matchesAtAa != null && !matchesAtAa.isEmpty()) {
                    nCovered++;
                }
View Full Code Here

                            if (psParameter.getMatchValidationLevel().isValidated()) {

                                SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                                if (spectrumMatch.getBestPeptideAssumption() != null) {
                                    Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();

                                    if (exportType != ExportType.confident_ptms || isTargetedPeptide(peptide, targetedPTMs)) {

                                        boolean decoy = false;
                                        for (String protein : peptide.getParentProteins(sequenceMatchingPreferences)) {
                                            if (SequenceFactory.getInstance().isDecoyAccession(protein)) {
                                                decoy = true;
                                                break;
                                            }
                                        }
                                        if (!decoy) {
                                            if (exportType == ExportType.validated_psms) {
                                                writePsm(writer, spectrumKey, identification, sequenceMatchingPreferences);
                                            } else {
                                                String peptideKey = peptide.getMatchingKey(sequenceMatchingPreferences);
                                                psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
                                                if (psParameter.getMatchValidationLevel().isValidated()) {
                                                    if (exportType == ExportType.validated_psms_peptides) {
                                                        writePsm(writer, spectrumKey, identification, sequenceMatchingPreferences);
                                                    } else {
                                                        ArrayList<String> accessions = new ArrayList<String>();
                                                        for (String accession : peptide.getParentProteins(sequenceMatchingPreferences)) {
                                                            ArrayList<String> groups = identification.getProteinMap().get(accession);
                                                            if (groups != null) {
                                                                for (String group : groups) {
                                                                    psParameter = (PSParameter) identification.getProteinMatchParameter(group, psParameter);
                                                                    if (psParameter.getMatchValidationLevel().isValidated()) {
View Full Code Here

                            psmMap.addDoubtfulMatchesFilter(charge, spectrumFileName, psmFilter);
                        }

                        if (inputMap != null) {

                            Peptide bestPeptide = peptideAssumption.getPeptide();
                            ArrayList<Integer> agreementAdvocates = new ArrayList<Integer>();

                            for (int advocateId : spectrumMatch.getAdvocates()) {
                                for (SpectrumIdentificationAssumption spectrumIdentificationAssumption : spectrumMatch.getFirstHits(advocateId)) {
                                    if (spectrumIdentificationAssumption instanceof PeptideAssumption) {
                                        Peptide advocatePeptide = ((PeptideAssumption) spectrumIdentificationAssumption).getPeptide();
                                        if (bestPeptide.isSameSequenceAndModificationStatus(advocatePeptide, sequenceMatchingPreferences)) {
                                            agreementAdvocates.add(advocateId);
                                            break;
                                        }
                                    }
                                }
                            }

                            boolean unique = agreementAdvocates.size() == 1;

                            for (int advocateId : agreementAdvocates) {
                                inputMap.addAdvocateContribution(advocateId, spectrumFileName, unique);
                            }

                            inputMap.addAdvocateContribution(Advocate.peptideShaker.getIndex(), spectrumFileName, agreementAdvocates.isEmpty());
                        }
                    }
                }

                // go through the peptide assumptions
                if (inputMap != null) { //backward compatibility check
                    SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);

                    for (Integer advocateId : spectrumMatch.getAdvocates()) {

                        HashMap<Double, ArrayList<SpectrumIdentificationAssumption>> assumptions = spectrumMatch.getAllAssumptions(advocateId);

                        for (double eValue : assumptions.keySet()) {
                            for (SpectrumIdentificationAssumption spectrumIdAssumption : assumptions.get(eValue)) {
                                if (spectrumIdAssumption instanceof PeptideAssumption) {
                                    PeptideAssumption peptideAssumption = (PeptideAssumption) spectrumIdAssumption;
                                    updatePeptideAssumptionValidationLevel(identificationFeaturesGenerator, searchParameters, annotationPreferences, inputMap, spectrumKey, peptideAssumption, peptideSpectrumAnnotator);
                                } else if (spectrumIdAssumption instanceof TagAssumption) {
                                    TagAssumption tagAssumption = (TagAssumption) spectrumIdAssumption;
                                    updateTagAssumptionValidationLevel(identificationFeaturesGenerator, searchParameters, annotationPreferences, inputMap, spectrumKey, tagAssumption);
                                }
                            }
                        }
                    }
                }

                if (waitingHandler != null) {
                    waitingHandler.increaseSecondaryProgressCounter();
                    if (waitingHandler.isRunCanceled()) {
                        return;
                    }
                }
            }

            // check if we should narrow the mass accuracy window, if yes, do a second pass validation
            if (!precursorMzDeviations.isEmpty()) {

                NonSymmetricalNormalDistribution precDeviationDistribution = NonSymmetricalNormalDistribution.getRobustNonSymmetricalNormalDistribution(precursorMzDeviations);
                Double minDeviation = precDeviationDistribution.getMinValueForProbability(0.0001);
                Double maxDeviation = precDeviationDistribution.getMaxValueForProbability(0.0001);
                boolean needSecondPass = false;

                if (minDeviation < maxDeviation) {
                    String unit = "ppm";
                    if (!searchParameters.isPrecursorAccuracyTypePpm()) {
                        unit = "Da";
                    }
                    if (minDeviation != Double.NaN && minDeviation > -searchParameters.getPrecursorAccuracy()) {
                        needSecondPass = true;
                        PsmFilter psmFilter = new PsmFilter("Precursor m/z deviation > " + Util.roundDouble(minDeviation, 2) + " " + unit);
                        psmFilter.setDescription("Precursor m/z deviation < " + Util.roundDouble(minDeviation, 2) + " " + unit);
                        psmFilter.setMinPrecursorMzError(minDeviation);
                        psmFilter.setPrecursorMinMzErrorComparison(RowFilter.ComparisonType.AFTER);
                        for (int charge : charges) {
                            psmMap.addDoubtfulMatchesFilter(charge, spectrumFileName, psmFilter);
                        }
                    }
                    if (minDeviation != Double.NaN && maxDeviation < searchParameters.getPrecursorAccuracy()) {
                        needSecondPass = true;
                        PsmFilter psmFilter = new PsmFilter("Precursor m/z deviation < " + Util.roundDouble(maxDeviation, 2) + " " + unit);
                        psmFilter.setDescription("Precursor m/z deviation > " + Util.roundDouble(maxDeviation, 2) + " " + unit);
                        psmFilter.setMaxPrecursorMzError(maxDeviation);
                        psmFilter.setPrecursorMaxMzErrorComparison(RowFilter.ComparisonType.BEFORE);
                        for (int charge : charges) {
                            psmMap.addDoubtfulMatchesFilter(charge, spectrumFileName, psmFilter);
                        }
                    }
                }

                if (needSecondPass) {

                    if (inputMap != null) {
                        inputMap.resetAdvocateContributions(spectrumFileName);
                    }

                    for (String spectrumKey : identification.getSpectrumIdentification(spectrumFileName)) {

                        updateSpectrumMatchValidationLevel(identification, identificationFeaturesGenerator, searchParameters, sequenceMatchingPreferences, annotationPreferences, peptideSpectrumAnnotator, psmMap, spectrumKey);
                        psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);

                        if (psParameter.getMatchValidationLevel().isValidated()) {

                            SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
                            PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();

                            if (peptideAssumption != null) {
                                if (inputMap != null) {
                                    Peptide bestPeptide = peptideAssumption.getPeptide();
                                    ArrayList<Integer> agreementAdvocates = new ArrayList<Integer>();
                                    for (int advocateId : spectrumMatch.getAdvocates()) {
                                        for (SpectrumIdentificationAssumption spectrumIdentificationAssumption : spectrumMatch.getFirstHits(advocateId)) {
                                            if (spectrumIdentificationAssumption instanceof PeptideAssumption) {
                                                Peptide advocatePeptide = ((PeptideAssumption) spectrumIdentificationAssumption).getPeptide();
                                                if (bestPeptide.isSameSequenceAndModificationStatus(advocatePeptide, sequenceMatchingPreferences)) {
                                                    agreementAdvocates.add(advocateId);
                                                    break;
                                                }
                                            }
View Full Code Here

TOP

Related Classes of com.compomics.util.experiment.biology.Peptide

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.