Examples of PSPtmScores


Examples of eu.isas.peptideshaker.myparameters.PSPtmScores

     * @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);
            return "Error";
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSPtmScores

     * @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);
            return "Error";
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSPtmScores

        if (scoringPreferences.isProbabilitsticScoreCalculation()) {
            attachProbabilisticScore(identification, spectrumMatch, searchParameters, annotationPreferences, scoringPreferences, sequenceMatchingPreferences);
        }

        PSPtmScores ptmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());

        if (ptmScores != null) {

            Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();

            ArrayList<Double> modificationMasses = new ArrayList<Double>();
            for (ModificationMatch modificationMatch : peptide.getModificationMatches()) {
                PTM ptm = ptmFactory.getPTM(modificationMatch.getTheoreticPtm());
                if (!modificationMasses.contains(ptm.getMass())) {
                    modificationMasses.add(ptm.getMass());
                }
            }

            for (double ptmMass : modificationMasses) {

                int nPtm = peptide.getNVariableModifications(ptmMass);
                HashMap<Double, ArrayList<Integer>> dSitesMap = new HashMap<Double, ArrayList<Integer>>();
                HashMap<Double, ArrayList<Integer>> pSitesMap = new HashMap<Double, ArrayList<Integer>>();
                HashMap<Integer, Double> pScores = new HashMap<Integer, Double>();

                for (String modification : ptmScores.getScoredPTMs()) {

                    PTM ptm = ptmFactory.getPTM(modification);

                    if (ptm.getMass() == ptmMass) {

                        PtmScoring ptmScoring = ptmScores.getPtmScoring(modification);

                        for (int site : ptmScoring.getDSites()) {

                            double score = ptmScoring.getDeltaScore(site);
                            ArrayList<Integer> sites = dSitesMap.get(score);
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSPtmScores

     * deserializing a match
     */
    public void scorePTMs(Identification identification, PeptideMatch peptideMatch, SearchParameters searchParameters,
            AnnotationPreferences annotationPreferences, PTMScoringPreferences scoringPreferences, SequenceMatchingPreferences sequenceMatchingPreferences) throws Exception {

        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);
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSPtmScores

        for (String peptideKey : peptideKeys) {
            psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
            if (psParameter.getMatchValidationLevel().isValidated() && Peptide.isModified(peptideKey)) {
                PeptideMatch peptideMath = identification.getPeptideMatch(peptideKey);
                String peptideSequence = Peptide.getSequence(peptideKey);
                if (peptideMath.getUrParam(new PSPtmScores()) == null || scorePeptides) {
                    scorePTMs(identification, peptideMath, searchParameters, annotationPreferences, ptmScoringPreferences, sequenceMatchingPreferences);
                }
                PSPtmScores peptideScores = (PSPtmScores) peptideMath.getUrParam(new PSPtmScores());
                if (peptideScores != null) {

                    if (protein == null) {
                        protein = sequenceFactory.getProtein(proteinMatch.getMainMatch());
                    }
                    ArrayList<Integer> peptideStart = protein.getPeptideStart(peptideSequence,
                            sequenceMatchingPreferences);
                    for (int confidentSite : peptideScores.getConfidentSites()) {
                        for (int peptideTempStart : peptideStart) {
                            int siteOnProtein = peptideTempStart + confidentSite - 2;
                            ArrayList<String> modificationsAtSite = confidentSites.get(siteOnProtein);
                            if (modificationsAtSite == null) {
                                modificationsAtSite = new ArrayList<String>();
                                confidentSites.put(siteOnProtein, modificationsAtSite);
                            }
                            for (String ptmName : peptideScores.getConfidentModificationsAt(confidentSite)) {
                                if (!modificationsAtSite.contains(ptmName)) {
                                    modificationsAtSite.add(ptmName);
                                }
                            }
                        }
                    }
                    for (int representativeSite : peptideScores.getRepresentativeSites()) {
                        HashMap<Integer, ArrayList<String>> peptideAmbiguousSites = peptideScores.getAmbiguousPtmsAtRepresentativeSite(representativeSite);
                        for (int peptideTempStart : peptideStart) {
                            int proteinRepresentativeSite = peptideTempStart + representativeSite - 2;
                            HashMap<Integer, ArrayList<String>> proteinAmbiguousSites = ambiguousSites.get(proteinRepresentativeSite);
                            if (proteinAmbiguousSites == null) {
                                proteinAmbiguousSites = new HashMap<Integer, ArrayList<String>>(peptideAmbiguousSites.size());
                                ambiguousSites.put(proteinRepresentativeSite, proteinAmbiguousSites);
                            }
                            for (int peptideSite : peptideAmbiguousSites.keySet()) {
                                int siteOnProtein = peptideTempStart + peptideSite - 2;
                                proteinAmbiguousSites.put(siteOnProtein, peptideAmbiguousSites.get(peptideSite));
                            }
                        }
                    }
                }
            }
        }

        // remove ambiguous sites where a confident was found and merge overlapping groups
        PSPtmScores proteinScores = new PSPtmScores();
        ArrayList<Integer> representativeSites = new ArrayList<Integer>(ambiguousSites.keySet());
        Collections.sort(representativeSites);

        for (Integer representativeSite : representativeSites) {
            HashMap<Integer, ArrayList<String>> secondarySitesMap = ambiguousSites.get(representativeSite);
            ArrayList<Integer> secondarySites = new ArrayList<Integer>(secondarySitesMap.keySet());
            for (int secondarySite : secondarySites) {
                ArrayList<String> confidentPtms = confidentSites.get(secondarySite);
                if (confidentPtms != null) {
                    boolean samePtm = false;
                    for (String modification : confidentPtms) {
                        PTM confidentPtm = ptmFactory.getPTM(modification);
                        for (String secondaryModification : secondarySitesMap.get(secondarySite)) {
                            PTM secondaryPtm = ptmFactory.getPTM(secondaryModification);
                            if (secondaryPtm.getMass() == confidentPtm.getMass()) {
                                samePtm = true;
                                break;
                            }
                        }
                        if (samePtm) {
                            break;
                        }
                    }
                    if (samePtm) {
                        ambiguousSites.remove(representativeSite);
                        break;
                    }
                }
                if (secondarySite != representativeSite) {
                    ArrayList<Integer> tempRepresentativeSites = new ArrayList<Integer>(ambiguousSites.keySet());
                    Collections.sort(tempRepresentativeSites);
                    for (Integer previousSite : tempRepresentativeSites) {
                        if (previousSite >= representativeSite) {
                            break;
                        }
                        if (previousSite == secondarySite) {
                            HashMap<Integer, ArrayList<String>> previousSites = ambiguousSites.get(previousSite);
                            ArrayList<String> previousPtms = previousSites.get(previousSite);
                            boolean samePtm = false;
                            for (String modification : previousPtms) {
                                PTM previousPtm = ptmFactory.getPTM(modification);
                                for (String secondaryModification : secondarySitesMap.get(secondarySite)) {
                                    PTM secondaryPtm = ptmFactory.getPTM(secondaryModification);
                                    if (secondaryPtm.getMass() == previousPtm.getMass()) {
                                        samePtm = true;
                                        break;
                                    }
                                }
                                if (samePtm) {
                                    break;
                                }
                            }
                            if (samePtm) {
                                for (int tempSecondarySite : secondarySitesMap.keySet()) {
                                    if (!previousSites.containsKey(secondarySite)) {
                                        previousSites.put(tempSecondarySite, secondarySitesMap.get(tempSecondarySite));
                                    }
                                }
                                ambiguousSites.remove(representativeSite);
                            }
                        }
                    }
                }
            }
        }

        for (int confidentSite : confidentSites.keySet()) {
            for (String modificationName : confidentSites.get(confidentSite)) {
                proteinScores.addConfidentModificationSite(modificationName, confidentSite);
            }
        }

        for (int representativeSite : ambiguousSites.keySet()) {
            proteinScores.addAmbiguousModificationSites(representativeSite, ambiguousSites.get(representativeSite));
        }

        proteinMatch.addUrParam(proteinScores);
        identification.updateProteinMatch(proteinMatch);
    }
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSPtmScores

                                        }
                                        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);
                                }
                            }
                        }
View Full Code Here

Examples of eu.isas.peptideshaker.myparameters.PSPtmScores

    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();
                    PtmScoring ptmScoring = ptmScores.getPtmScoring(modName);
                    ptmScoring.setSiteConfidence(site, PtmScoring.VERY_CONFIDENT);
                    modMatch.setConfident(true);
                    confidentSites.put(site, modName);
                }
            } else if (!ptmScoringPreferences.isProbabilitsticScoreCalculation()
                    || ptmScoringPreferences.getSelectedProbabilisticScore() == PtmScore.AScore && ptmMatches.size() > 1) {
                double pScore = 0; // no probabilistic score in that case
                for (ModificationMatch modificationMatch : ptmMatches) {
                    String modName = modificationMatch.getTheoreticPtm();
                    PtmScoring ptmScoring = ptmScores.getPtmScoring(modName);
                    ArrayList<Integer> orderedDSites = new ArrayList<Integer>(ptmScoring.getDSites());
                    Collections.sort(orderedDSites);
                    for (int site : orderedDSites) {
                        if (site == modificationMatch.getModificationSite()) {
                            double dScore = ptmScoring.getDeltaScore(site);
                            if (dScore == 0) {
                                ptmScoring.setSiteConfidence(site, PtmScoring.RANDOM);
                                modificationMatch.setConfident(false);
                            } else if (dScore <= 95) {
                                ptmScoring.setSiteConfidence(site, PtmScoring.DOUBTFUL);
                                modificationMatch.setConfident(false);
                            } else {
                                ptmScoring.setSiteConfidence(site, PtmScoring.CONFIDENT);
                                modificationMatch.setConfident(true);
                                confidentSites.put(site, modName);
                            }
                            if (!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>>>>(1);
                                    ambiguousScoreToSiteMap.put(pScore, pScoreAmbiguousMap);
                                }
                                HashMap<Double, HashMap<Integer, ArrayList<String>>> dScoreAmbiguousMap = pScoreAmbiguousMap.get(dScore);
                                if (dScoreAmbiguousMap == null) {
                                    dScoreAmbiguousMap = new HashMap<Double, HashMap<Integer, ArrayList<String>>>(nPotentialSites);
                                    pScoreAmbiguousMap.put(dScore, dScoreAmbiguousMap);
                                }
                                HashMap<Integer, ArrayList<String>> massAmbiguousMap = dScoreAmbiguousMap.get(ptmMass);
                                if (massAmbiguousMap == null) {
                                    massAmbiguousMap = new HashMap<Integer, ArrayList<String>>(nPotentialSites);
                                    dScoreAmbiguousMap.put(ptmMass, massAmbiguousMap);
                                }
                                ArrayList<String> modifications = massAmbiguousMap.get(site);
                                if (modifications == null) {
                                    modifications = new ArrayList<String>(1);
                                    massAmbiguousMap.put(site, modifications);
                                }
                                modifications.add(modName);
                            }
                        }
                    }
                }
            } else {
                HashMap<Double, HashMap<Double, ArrayList<Integer>>> scoreToSiteMap = new HashMap<Double, HashMap<Double, ArrayList<Integer>>>(nPotentialSites);
                for (int site : ptmPotentialSites.keySet()) {
                    String modName = ptmPotentialSites.get(site);
                    PtmScoring ptmScoring = ptmScores.getPtmScoring(modName);
                    double pScore = 0;
                    double dScore = 0;
                    if (ptmScoring != null) {
                        pScore = ptmScoring.getProbabilisticScore(site);
                        dScore = ptmScoring.getDeltaScore(site);
                    }
                    HashMap<Double, ArrayList<Integer>> pScoreMap = scoreToSiteMap.get(pScore);
                    if (pScoreMap == null) {
                        pScoreMap = new HashMap<Double, ArrayList<Integer>>(1);
                        scoreToSiteMap.put(pScore, pScoreMap);
                    }
                    ArrayList<Integer> dScoreSites = pScoreMap.get(dScore);
                    if (dScoreSites == null) {
                        dScoreSites = new ArrayList<Integer>(1);
                        pScoreMap.put(dScore, dScoreSites);
                    }
                    dScoreSites.add(site);
                }
                ArrayList<Double> pScores = new ArrayList<Double>(scoreToSiteMap.keySet());
                Collections.sort(pScores, Collections.reverseOrder());
                int key = spectrumMatch.getBestPeptideAssumption().getIdentificationCharge().value;
                TargetDecoyMap currentMap = psmPTMMap.getTargetDecoyMap(ptmMass, key);
                if (currentMap == null) {
                    throw new IllegalArgumentException("No FLR map found for PTM of mass " + ptmMass + " in PSMs of charge " + key + ".");
                }
                int cpt = 0;
                double doubtfulThreshold;
                if (ptmScoringPreferences.isEstimateFlr()) {
                    doubtfulThreshold = -currentMap.getTargetDecoyResults().getScoreLimit();
                } else {
                    doubtfulThreshold = ptmScoringPreferences.getProbabilisticScoreThreshold();
                }
                double randomThreshold = 0;
                if (ptmScoringPreferences.getSelectedProbabilisticScore() == PtmScore.PhosphoRS) {
                    randomThreshold = (100.0 * nPTMs) / ptmPotentialSites.size();
                }
                for (Double pScore : pScores) {
                    HashMap<Double, ArrayList<Integer>> pScoreMap = scoreToSiteMap.get(pScore);
                    ArrayList<Double> dScores = new ArrayList<Double>(pScoreMap.keySet());
                    Collections.sort(dScores, Collections.reverseOrder());
                    for (Double dScore : dScores) {
                        ArrayList<Integer> sites = pScoreMap.get(dScore);
                        Collections.sort(sites);
                        boolean enoughPtms = nPTMs - cpt >= sites.size();
                        for (int site : sites) {
                            String modName = ptmPotentialSites.get(site);
                            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);
                                }
                                HashMap<Double, HashMap<Integer, ArrayList<String>>> dScoreAmbiguousMap = pScoreAmbiguousMap.get(dScore);
                                if (dScoreAmbiguousMap == null) {
                                    dScoreAmbiguousMap = new HashMap<Double, HashMap<Integer, ArrayList<String>>>(1);
                                    pScoreAmbiguousMap.put(dScore, dScoreAmbiguousMap);
                                }
                                HashMap<Integer, ArrayList<String>> massAmbiguousMap = dScoreAmbiguousMap.get(ptmMass);
                                if (massAmbiguousMap == null) {
                                    massAmbiguousMap = new HashMap<Integer, ArrayList<String>>(nPotentialSites);
                                    dScoreAmbiguousMap.put(ptmMass, massAmbiguousMap);
                                }
                                ArrayList<String> modifications = massAmbiguousMap.get(site);
                                if (modifications == null) {
                                    modifications = new ArrayList<String>(1);
                                    massAmbiguousMap.put(site, modifications);
                                }
                                modifications.add(modName);

                            }
                            cpt++;
                        }
                    }
                }
            }
            // Select the best scoring ambiguous sites as representative PTM sites
            ArrayList<Integer> ptmConfidentSites = new ArrayList<Integer>(confidentSites.keySet());
            for (int site : ptmConfidentSites) {
                ptmScores.addConfidentModificationSite(confidentSites.get(site), site);
            }
            int nConfident = ptmConfidentSites.size();
            if (nConfident < nPTMs) {
                int nRepresentatives = nPTMs - nConfident;
                if (nRepresentatives > 0) {
                    nRepresentativesMap.put(ptmMass, nRepresentatives);
                }
            }
        }
        if (!nRepresentativesMap.isEmpty()) {
            HashMap<Double, HashMap<Integer, HashMap<Integer, ArrayList<String>>>> representativeToSecondaryMap = getRepresentativeToSecondaryMap(ambiguousScoreToSiteMap, nRepresentativesMap);
            for (Double ptmMass : representativeToSecondaryMap.keySet()) {
                HashMap<Integer, HashMap<Integer, ArrayList<String>>> massMap = representativeToSecondaryMap.get(ptmMass);
                for (int representativeSite : massMap.keySet()) {
                    ptmScores.addAmbiguousModificationSites(representativeSite, massMap.get(representativeSite));
                }
            }
        }
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.