Examples of Peptide


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

            HashSet<String> keys = new HashSet<String>(peptideMap.keySet());
            for (String key : keys) {
                LinkedList<Peptide> peptides = peptideMap.get(key);
                Iterator<Peptide> peptideIterator = peptides.iterator();
                while (peptideIterator.hasNext()) {
                    Peptide peptide = peptideIterator.next();
                    mapPeptide(peptide, !peptideIterator.hasNext());
                }
                peptideMap.remove(key);
            }
        }
View Full Code Here

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

            ExecutorService pool = Executors.newFixedThreadPool(nThreads);
            for (String key : keys) {
                LinkedList<Peptide> peptides = peptideMap.get(key);
                Iterator<Peptide> peptideIterator = peptides.iterator();
                while (peptideIterator.hasNext()) {
                    Peptide peptide = peptideIterator.next();
                    PeptideMapperRunnable peptideMapperRunnable = new PeptideMapperRunnable(peptide, !peptideIterator.hasNext());
                    pool.submit(peptideMapperRunnable);
                    if (canceled || waitingHandler.isRunCanceled()) {
                        pool.shutdownNow();
                        return;
View Full Code Here

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

        public void run() {

            try {
                Iterator<Peptide> peptideIterator = peptideList.iterator();
                while (peptideIterator.hasNext()) {
                    Peptide peptide = peptideIterator.next();
                    if (!canceled && !waitingHandler.isRunCanceled()) {
                        mapPeptide(peptide, !peptideIterator.hasNext());
                    }
                }
            } catch (Exception e) {
View Full Code Here

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

                        for (SpectrumIdentificationAssumption assumption : tempAssumptions) {

                            if (assumption instanceof PeptideAssumption) {

                                PeptideAssumption peptideAssumption = (PeptideAssumption) assumption;
                                Peptide peptide = peptideAssumption.getPeptide();
                                String peptideSequence = peptide.getSequence();

                                // map the algorithm specific modifications on utilities modifications
                                // If there are not enough sites to put them all on the sequence, add an unknown modifcation
                                // Note: this needs to be done for tag based assumptions as well since the protein mapping can return erroneous modifications for some pattern based PTMs
                                ModificationProfile modificationProfile = searchParameters.getModificationProfile();

                                boolean fixedPtmIssue = false;
                                try {
                                    ptmFactory.checkFixedModifications(modificationProfile, peptide, sequenceMatchingPreferences);
                                } catch (IllegalArgumentException e) {
                                    if (idFilter.removeUnknownPTMs()) {
                                        // Exclude peptides with aberrant PTM mapping
                                        System.out.println(e.getMessage());
                                        spectrumMatch.removeAssumption(assumption);
                                        ptmIssue++;
                                        fixedPtmIssue = true;
                                    } else {
                                        throw e;
                                    }
                                }

                                if (!fixedPtmIssue) {

                                    HashMap<Integer, ArrayList<String>> expectedNames = new HashMap<Integer, ArrayList<String>>();
                                    HashMap<ModificationMatch, ArrayList<String>> modNames = new HashMap<ModificationMatch, ArrayList<String>>();

                                    for (ModificationMatch modMatch : peptide.getModificationMatches()) {
                                        HashMap<Integer, ArrayList<String>> tempNames = new HashMap<Integer, ArrayList<String>>();
                                        if (modMatch.isVariable()) {
                                            String sePTM = modMatch.getTheoreticPtm();
                                            if (fileReader instanceof OMSSAIdfileReader) {
                                                Integer omssaIndex = null;
                                                try {
                                                    omssaIndex = new Integer(sePTM);
                                                } catch (Exception e) {
                                                    waitingHandler.appendReport("Impossible to parse OMSSA modification " + sePTM + ".", true, true);
                                                }
                                                if (omssaIndex != null) {
                                                    String omssaName = modificationProfile.getModification(omssaIndex);
                                                    if (omssaName == null) {
                                                        if (!ignoredOMSSAModifications.contains(omssaIndex)) {
                                                            waitingHandler.appendReport("Impossible to find OMSSA modification of index "
                                                                    + omssaIndex + ". The corresponding peptides will be ignored.", true, true);
                                                            ignoredOMSSAModifications.add(omssaIndex);
                                                        }
                                                        omssaName = PTMFactory.unknownPTM.getName();
                                                    }
                                                    tempNames = ptmFactory.getExpectedPTMs(modificationProfile, peptide, omssaName, ptmMassTolerance, sequenceMatchingPreferences);
                                                }
                                            } else if (fileReader instanceof MascotIdfileReader
                                                    || fileReader instanceof XTandemIdfileReader
                                                    || fileReader instanceof MsAmandaIdfileReader
                                                    || fileReader instanceof MzIdentMLIdfileReader
                                                    || fileReader instanceof PepxmlIdfileReader) {
                                                String[] parsedName = sePTM.split("@");
                                                double seMass = 0;
                                                try {
                                                    seMass = new Double(parsedName[0]);
                                                } catch (Exception e) {
                                                    throw new IllegalArgumentException("Impossible to parse \'" + sePTM + "\' as a tagged modification.\n"
                                                            + "Error encountered in peptide " + peptideSequence + " spectrum " + spectrumTitle + " in spectrum file " + fileName + ".\n"
                                                            + "Identification file: " + idFile.getName());
                                                }
                                                tempNames = ptmFactory.getExpectedPTMs(modificationProfile, peptide, seMass, ptmMassTolerance, sequenceMatchingPreferences);
                                            } else if (fileReader instanceof DirecTagIdfileReader) {
                                                PTM ptm = ptmFactory.getPTM(sePTM);
                                                if (ptm == PTMFactory.unknownPTM) {
                                                    throw new IllegalArgumentException("PTM not recognized spectrum " + spectrumTitle + " of file " + fileName + ".");
                                                }
                                                tempNames = ptmFactory.getExpectedPTMs(modificationProfile, peptide, ptm.getMass(), ptmMassTolerance, sequenceMatchingPreferences);
                                            } else {
                                                throw new IllegalArgumentException("PTM mapping not implemented for the parsing of " + idFile.getName() + ".");
                                            }

                                            ArrayList<String> allNames = new ArrayList<String>();
                                            for (ArrayList<String> namesAtAA : tempNames.values()) {
                                                for (String name : namesAtAA) {
                                                    if (!allNames.contains(name)) {
                                                        allNames.add(name);
                                                    }
                                                }
                                            }
                                            modNames.put(modMatch, allNames);
                                            for (int pos : tempNames.keySet()) {
                                                ArrayList<String> namesAtPosition = expectedNames.get(pos);
                                                if (namesAtPosition == null) {
                                                    namesAtPosition = new ArrayList<String>(2);
                                                    expectedNames.put(pos, namesAtPosition);
                                                }
                                                for (String ptmName : tempNames.get(pos)) {
                                                    if (!namesAtPosition.contains(ptmName)) {
                                                        namesAtPosition.add(ptmName);
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // 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()) {
                                                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.isCTerm()) {
                                                            boolean otherPossibleMod = false;
                                                            for (String tempName : modificationProfile.getAllNotFixedModifications()) {
                                                                if (!tempName.equals(modName)) {
                                                                    PTM tempPTM = ptmFactory.getPTM(tempName);
                                                                    if (tempPTM.getMass() == ptm.getMass() && !tempPTM.isCTerm()) {
                                                                        otherPossibleMod = true;
                                                                        break;
                                                                    }
                                                                }
                                                            }
                                                            if (!otherPossibleMod) {
                                                                cTermModification = modMatch;
                                                                modMatch.setTheoreticPtm(modName);
                                                                break;
                                                            }
                                                        }
                                                    }
                                                    if (cTermModification != null) {
                                                        break;
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    // Map the modifications according to search engine localization
                                    HashMap<Integer, ArrayList<String>> siteToPtmMap = new HashMap<Integer, ArrayList<String>>(); // Site to ptm name including termini
                                    HashMap<Integer, ModificationMatch> siteToMatchMap = new HashMap<Integer, ModificationMatch>(); // Site to Modification match excluding termini
                                    HashMap<ModificationMatch, Integer> matchToSiteMap = new HashMap<ModificationMatch, Integer>(); // Modification match to site excluding termini
                                    boolean allMapped = true;

                                    for (ModificationMatch modMatch : peptide.getModificationMatches()) {
                                        boolean mapped = false;
                                        if (modMatch.isVariable() && modMatch != nTermModification && modMatch != cTermModification && !modMatch.getTheoreticPtm().equals(PTMFactory.unknownPTM.getName())) {
                                            double refMass = getRefMass(modMatch.getTheoreticPtm(), modificationProfile);
                                            int modSite = modMatch.getModificationSite();
                                            boolean terminal = false;
                                            ArrayList<String> expectedNamesAtSite = expectedNames.get(modSite);
                                            if (expectedNamesAtSite != null) {
                                                ArrayList<String> filteredNamesAtSite = new ArrayList<String>(expectedNamesAtSite.size());
                                                ArrayList<String> modificationAtSite = siteToPtmMap.get(modSite);
                                                for (String ptmName : expectedNamesAtSite) {
                                                    PTM ptm = ptmFactory.getPTM(ptmName);
                                                    if (Math.abs(ptm.getMass() - refMass) < searchParameters.getFragmentIonAccuracy()
                                                            && (modificationAtSite == null || !modificationAtSite.contains(ptmName))) {
                                                        filteredNamesAtSite.add(ptmName);
                                                    }
                                                }
                                                if (filteredNamesAtSite.size() == 1) {
                                                    String ptmName = filteredNamesAtSite.get(0);
                                                    PTM ptm = ptmFactory.getPTM(ptmName);
                                                    if (ptm.isNTerm() && nTermModification == null) {
                                                        nTermModification = modMatch;
                                                        mapped = true;
                                                    } else if (ptm.isCTerm() && cTermModification == null) {
                                                        cTermModification = modMatch;
                                                        mapped = true;
                                                    } else if (!ptm.isNTerm() && !ptm.isCTerm()) {
                                                        matchToSiteMap.put(modMatch, modSite);
                                                        siteToMatchMap.put(modSite, modMatch);
                                                        mapped = true;
                                                    }
                                                    if (mapped) {
                                                        modMatch.setTheoreticPtm(ptmName);
                                                        if (modificationAtSite == null) {
                                                            modificationAtSite = new ArrayList<String>(2);
                                                            siteToPtmMap.put(modSite, modificationAtSite);
                                                        }
                                                        modificationAtSite.add(ptmName);
                                                    }
                                                }
                                                if (!mapped) {
                                                    if (filteredNamesAtSite.isEmpty()) {
                                                        filteredNamesAtSite = expectedNamesAtSite;
                                                    }
                                                    if (modSite == 1) {
                                                        Double minDiff = null;
                                                        String bestPtmName = null;
                                                        for (String modName : filteredNamesAtSite) {
                                                            PTM ptm = ptmFactory.getPTM(modName);
                                                            if (ptm.isNTerm() && nTermModification == null) {
                                                                double massError = Math.abs(refMass - ptm.getMass());
                                                                if (massError <= searchParameters.getFragmentIonAccuracy()
                                                                        && (minDiff == null || massError < minDiff)) {
                                                                    bestPtmName = modName;
                                                                    minDiff = massError;
                                                                }
                                                            }
                                                        }
                                                        if (bestPtmName != null) {
                                                            nTermModification = modMatch;
                                                            modMatch.setTheoreticPtm(bestPtmName);
                                                            terminal = true;
                                                            if (modificationAtSite == null) {
                                                                modificationAtSite = new ArrayList<String>(2);
                                                                siteToPtmMap.put(modSite, modificationAtSite);
                                                            }
                                                            modificationAtSite.add(bestPtmName);
                                                            mapped = true;
                                                        }
                                                    } else if (modSite == peptideSequence.length()) {
                                                        Double minDiff = null;
                                                        String bestPtmName = null;
                                                        for (String modName : filteredNamesAtSite) {
                                                            PTM ptm = ptmFactory.getPTM(modName);
                                                            if (ptm.isCTerm() && cTermModification == null) {
                                                                double massError = Math.abs(refMass - ptm.getMass());
                                                                if (massError <= searchParameters.getFragmentIonAccuracy()
                                                                        && (minDiff == null || massError < minDiff)) {
                                                                    bestPtmName = modName;
                                                                    minDiff = massError;
                                                                }
                                                            }
                                                        }
                                                        if (bestPtmName != null) {
                                                            cTermModification = modMatch;
                                                            modMatch.setTheoreticPtm(bestPtmName);
                                                            terminal = true;
                                                            if (modificationAtSite == null) {
                                                                modificationAtSite = new ArrayList<String>(2);
                                                                siteToPtmMap.put(modSite, modificationAtSite);
                                                            }
                                                            modificationAtSite.add(bestPtmName);
                                                            mapped = true;
                                                        }
                                                    }
                                                    if (!terminal) {
                                                        Double minDiff = null;
                                                        String bestPtmName = null;
                                                        for (String modName : filteredNamesAtSite) {
                                                            PTM ptm = ptmFactory.getPTM(modName);
                                                            if (!ptm.isCTerm() && !ptm.isNTerm() && modNames.get(modMatch).contains(modName) && !siteToMatchMap.containsKey(modSite)) {
                                                                double massError = Math.abs(refMass - ptm.getMass());
                                                                if (massError <= searchParameters.getFragmentIonAccuracy()
                                                                        && (minDiff == null || massError < minDiff)) {
                                                                    bestPtmName = modName;
                                                                    minDiff = massError;
                                                                }
                                                            }
                                                        }
                                                        if (bestPtmName != null) {
                                                            modMatch.setTheoreticPtm(bestPtmName);
                                                            if (modificationAtSite == null) {
                                                                modificationAtSite = new ArrayList<String>(2);
                                                                siteToPtmMap.put(modSite, modificationAtSite);
                                                            }
                                                            modificationAtSite.add(bestPtmName);
                                                            matchToSiteMap.put(modMatch, modSite);
                                                            siteToMatchMap.put(modSite, modMatch);
                                                            mapped = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                        if (!mapped) {
                                            allMapped = false;
                                        }
                                    }

                                    if (!allMapped) {

                                        // Try to correct incompatible localizations
                                        HashMap<Integer, ArrayList<Integer>> remap = new HashMap<Integer, ArrayList<Integer>>();

                                        for (ModificationMatch modMatch : peptide.getModificationMatches()) {
                                            if (modMatch.isVariable() && modMatch != nTermModification && modMatch != cTermModification && !matchToSiteMap.containsKey(modMatch) && !modMatch.getTheoreticPtm().equals(PTMFactory.unknownPTM.getName())) {
                                                int modSite = modMatch.getModificationSite();
                                                for (int candidateSite : expectedNames.keySet()) {
                                                    if (!siteToMatchMap.containsKey(candidateSite)) {
                                                        for (String modName : expectedNames.get(candidateSite)) {
                                                            if (modNames.get(modMatch).contains(modName)) {
                                                                PTM ptm = ptmFactory.getPTM(modName);
                                                                if ((!ptm.isCTerm() || cTermModification == null)
                                                                        && (!ptm.isNTerm() || nTermModification == null)) {
                                                                    ArrayList<Integer> ptmSites = remap.get(modSite);
                                                                    if (ptmSites == null) {
                                                                        ptmSites = new ArrayList<Integer>(4);
                                                                        remap.put(modSite, ptmSites);
                                                                    }
                                                                    if (!ptmSites.contains(candidateSite)) {
                                                                        ptmSites.add(candidateSite);
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }

                                        HashMap<Integer, Integer> correctedIndexes = PtmSiteMapping.alignAll(remap);

                                        for (ModificationMatch modMatch : peptide.getModificationMatches()) {
                                            if (modMatch.isVariable() && modMatch != nTermModification && modMatch != cTermModification && !matchToSiteMap.containsKey(modMatch) && !modMatch.getTheoreticPtm().equals(PTMFactory.unknownPTM.getName())) {
                                                Integer modSite = correctedIndexes.get(modMatch.getModificationSite());
                                                if (modSite != null) {
                                                    if (expectedNames.containsKey(modSite)) {
                                                        for (String modName : expectedNames.get(modSite)) {
                                                            if (modNames.get(modMatch).contains(modName)) {
                                                                ArrayList<String> taken = siteToPtmMap.get(modSite);
                                                                if (taken == null || !taken.contains(modName)) {
                                                                    matchToSiteMap.put(modMatch, modSite);
                                                                    modMatch.setTheoreticPtm(modName);
                                                                    modMatch.setModificationSite(modSite);
                                                                    if (taken == null) {
                                                                        taken = new ArrayList<String>(2);
                                                                        siteToPtmMap.put(modSite, taken);
                                                                    }
                                                                    taken.add(modName);
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                    }
                                                } else {
                                                    matchToSiteMap.put(modMatch, modSite);
                                                    modMatch.setTheoreticPtm(PTMFactory.unknownPTM.getName());
                                                }
                                                if (!matchToSiteMap.containsKey(modMatch)) {
                                                    modMatch.setTheoreticPtm(PTMFactory.unknownPTM.getName());
                                                }
                                            }
                                        }
                                    }

                                    if (idFilter.validateModifications(peptide, sequenceMatchingPreferences, searchParameters.getModificationProfile())) {
                                        // Estimate the theoretic mass with the new modifications
                                        peptide.estimateTheoreticMass();
                                        if (!idFilter.validatePrecursor(peptideAssumption, spectrumKey, spectrumFactory)) {
                                            spectrumMatch.removeAssumption(assumption);
                                            precursorIssue++;
                                        } else if (!idFilter.validateProteins(peptideAssumption.getPeptide(), sequenceMatchingPreferences)) {
                                            // Check whether there is a potential first hit which does not belong to both the target and the decoy database
View Full Code Here

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

        // iterate all the peptides
        for (String peptideKey : identification.getPeptideIdentification()) {

            PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
            Peptide peptide = peptideMatch.getTheoreticPeptide();
            String peptideSequence = peptide.getSequence();

            br.write(getCurrentTabSpace() + "<Peptide id=\"" + peptideKey + "\" >" + System.getProperty("line.separator"));
            tabCounter++;
            br.write(getCurrentTabSpace() + "<PeptideSequence>" + peptideSequence + "</PeptideSequence>" + System.getProperty("line.separator"));

            int modMatchIndex = 0;

            for (ModificationMatch modMatch : peptide.getModificationMatches()) {

                PTM currentPtm = ptmFactory.getPTM(modMatch.getTheoreticPtm());
                int ptmLocation = modMatch.getModificationSite();

                if (currentPtm.isNTerm()) {
                    ptmLocation = 0;
                } else if (currentPtm.isCTerm()) {
                    ptmLocation = peptideSequence.length() + 1;
                }

                br.write(getCurrentTabSpace() + "<Modification monoisotopicMassDelta=\"" + currentPtm.getMass() + "\" "
                        + "residues=\"" + peptideSequence.charAt(modMatch.getModificationSite() - 1) + "\" "
                        + "location=\"" + ptmLocation + "\" >" + System.getProperty("line.separator"));

                CvTerm ptmCvTerm = PtmToPrideMap.getDefaultCVTerm(currentPtm.getName());
                if (ptmCvTerm != null) {
                    tabCounter++;
                    writeCvTerm(ptmCvTerm);
                    if (mzidVersion1_2) {
                        writeCvTerm(new CvTerm("PSI-MS", "MS:100XXX", "order", modMatchIndex + "")); // @TODO: add correct cv term!
                        modMatchIndex++;
                    }
                    tabCounter--;
                }

                // add cv/user params
                // @TODO: ptm validation
                // @TODO: ptm localization scores across possible sites: PhosphoRS, A-score, d-score, ms-score
                br.write(getCurrentTabSpace() + "</Modification>" + System.getProperty("line.separator"));
            }

            modMatchIndex = 0;
            for (ModificationMatch modMatch : peptideMatch.getTheoreticPeptide().getModificationMatches()) {
                CvTerm ptmCvTerm = PtmToPrideMap.getDefaultCVTerm(modMatch.getTheoreticPtm());
                if (ptmCvTerm != null) {
                    writeCvTerm(ptmCvTerm);
                    writeCvTerm(new CvTerm("PSI-MS", "MS:100XXX", "peptide: order", modMatchIndex + ""));
                    modMatchIndex++;
                }
            }

            tabCounter--;
            br.write(getCurrentTabSpace() + "</Peptide>" + System.getProperty("line.separator"));

            waitingHandler.increasePrimaryProgressCounter();

            if (waitingHandler.isRunCanceled()) {
                break;
            }
        }

        int peptideEvidenceCounter = 0;

        // iterate the spectrum files
        for (String spectrumFileName : identification.getSpectrumFiles()) {

            identification.loadSpectrumMatches(spectrumFileName, null);
            identification.loadSpectrumMatchParameters(spectrumFileName, new PSParameter(), null);

            // iterate the psms
            for (String psmKey : identification.getSpectrumIdentification(spectrumFileName)) {

                SpectrumMatch spectrumMatch = identification.getSpectrumMatch(psmKey);
                PeptideAssumption bestPeptideAssumption = spectrumMatch.getBestPeptideAssumption();

                if (bestPeptideAssumption != null) {

                    Peptide peptide = bestPeptideAssumption.getPeptide();

                    // get all the possible parent proteins
                    ArrayList<String> possibleProteins = peptide.getParentProteins(sequenceMatchingPreferences);

                    // iterate all the possible protein parents for each peptide
                    for (String tempProtein : possibleProteins) {

                        // get the start indexes and the surrounding
                        HashMap<Integer, String[]> aaSurrounding = sequenceFactory.getProtein(tempProtein).getSurroundingAA(
                                peptide.getSequence(), 1, sequenceMatchingPreferences);

                        ArrayList<Integer> indexes = new ArrayList<Integer>();
                        ArrayList<String> before = new ArrayList<String>();
                        ArrayList<String> after = new ArrayList<String>();

                        if (aaSurrounding.size() == 1) {
                            for (int index : aaSurrounding.keySet()) {
                                indexes.add(index);
                                before.add(aaSurrounding.get(index)[0]);
                                after.add(aaSurrounding.get(index)[1]);
                            }
                        } else {
                            ArrayList<Integer> tempIndexes = new ArrayList<Integer>(aaSurrounding.keySet());
                            Collections.sort(tempIndexes);
                            for (int index : tempIndexes) {
                                indexes.add(index);
                                before.add(aaSurrounding.get(index)[0]);
                                after.add(aaSurrounding.get(index)[1]);
                            }
                        }

                        for (int i = 0; i < indexes.size(); i++) {
                            String aaBefore = "-";
                            String aaAfter = "-";

                            if (!before.get(i).isEmpty()) {
                                aaBefore = before.get(i);
                            }
                            if (!after.get(i).isEmpty()) {
                                aaAfter = after.get(i);
                            }

                            int peptideStart = indexes.get(i);
                            int peptideEnd = (indexes.get(i) + peptide.getSequence().length() - 1);

                            String peptideKey = peptide.getMatchingKey(sequenceMatchingPreferences);
                            String pepEvidenceKey = tempProtein + "_" + peptideStart + "_" + peptideKey;
                            pepEvidenceIds.put(pepEvidenceKey, "PepEv_" + ++peptideEvidenceCounter);
                            String matchingPeptideKey = peptide.getMatchingKey(sequenceMatchingPreferences);

                            br.write(getCurrentTabSpace() + "<PeptideEvidence isDecoy=\"" + peptide.isDecoy(sequenceMatchingPreferences) + "\" "
                                    + "pre=\"" + aaBefore + "\" "
                                    + "post=\"" + aaAfter + "\" "
                                    + "start=\"" + peptideStart + "\" "
                                    + "end=\"" + peptideEnd + "\" "
                                    + "peptide_ref=\"" + matchingPeptideKey + "\" "
View Full Code Here

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

                            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, annotationPreferences);
                                            } 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, annotationPreferences);
                                                    } 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

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

    private static void writePsm(BufferedWriter writer, String spectrumKey, ArrayList<String> accessions, Identification identification, SequenceMatchingPreferences sequenceMatchingPreferences, AnnotationPreferences annotationPreferences)
            throws IllegalArgumentException, SQLException, IOException, ClassNotFoundException, InterruptedException, MzMLUnmarshallerException {

        SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
        PeptideAssumption bestAssumption = spectrumMatch.getBestPeptideAssumption();
        Peptide peptide = bestAssumption.getPeptide();
        MSnSpectrum spectrum = (MSnSpectrum) SpectrumFactory.getInstance().getSpectrum(spectrumKey);

        if (accessions == null) {
            accessions = peptide.getParentProteins(sequenceMatchingPreferences);
        }
        PTMFactory ptmFactory = PTMFactory.getInstance();
        PtmToPrideMap ptmToPrideMap = null;
        // get the psi-mod mappings
        try {
            PrideObjectsFactory prideObjectsFactory = PrideObjectsFactory.getInstance();
            ptmToPrideMap = prideObjectsFactory.getPtmToPrideMap();
        } catch (Exception e) {
            e.printStackTrace();
        }

        for (String accession : accessions) {

            PeptideSpectrumAnnotator spectrumAnnotator = new PeptideSpectrumAnnotator();

            ArrayList<IonMatch> annotations = spectrumAnnotator.getSpectrumAnnotation(
                    annotationPreferences.getIonTypes(),
                    annotationPreferences.getNeutralLosses(),
                    annotationPreferences.getValidatedCharges(),
                    spectrumMatch.getBestPeptideAssumption().getIdentificationCharge().value,
                    spectrum,
                    spectrumMatch.getBestPeptideAssumption().getPeptide(),
                    spectrum.getIntensityLimit(annotationPreferences.getAnnotationIntensityLimit()),
                    annotationPreferences.getFragmentIonAccuracy(), false,
                    annotationPreferences.isHighResolutionAnnotation());

            for (IonMatch ionMatch : annotations) {

                if (ionMatch.ion.getType() == Ion.IonType.PEPTIDE_FRAGMENT_ION) {

                    PeptideFragmentIon peptideFragmentIon = (PeptideFragmentIon) ionMatch.ion;

                    if (peptideFragmentIon.getNeutralLosses().isEmpty()) {

                        //Q1
                        Charge charge = bestAssumption.getIdentificationCharge();
                        double theoreticPrecMz = (peptide.getMass() + charge.value * ElementaryIon.proton.getTheoreticMass()) / charge.value;
                        writer.write(theoreticPrecMz + SEPARATOR);

                        //Q3
                        double theoreticFragMz = ionMatch.ion.getTheoreticMz(charge.value);
                        writer.write(theoreticFragMz + SEPARATOR);

                        // RT_detected
                        double rt = spectrum.getPrecursor().getRt();
                        writer.write(rt + SEPARATOR);

                        // isotope
                        writer.write("Light" + SEPARATOR);

                        // uniprot_id
                        writer.write(accession + SEPARATOR);

                        // relative intensity
                        double intensity = ionMatch.peak.intensity; //@TODO: normalize in some way?
                        writer.write(intensity + SEPARATOR);

                        // sequence
                        String sequence = peptide.getSequence();
                        writer.write(sequence + SEPARATOR);

                        // modified sequence
                        String modifiedSequence = "";
                        for (int aa = 0; aa < sequence.length(); aa++) {
                            modifiedSequence += sequence.charAt(aa);
                            for (ModificationMatch modificationMatch : peptide.getModificationMatches()) {
                                if (modificationMatch.getModificationSite() == aa + 1) {
                                    String ptmName = modificationMatch.getTheoreticPtm();
                                    PTM ptm = ptmFactory.getPTM(ptmName);
                                    CvTerm cvTerm = null;
                                    if (ptmToPrideMap != null) {
View Full Code Here

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

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

        PSParameter psParameter = new PSParameter();
        double p1 = 1;
        Peptide psPeptide = spectrumMatch.getBestPeptideAssumption().getPeptide();
        for (SpectrumIdentificationAssumption assumption : spectrumMatch.getAllAssumptions()) {
            if (assumption instanceof PeptideAssumption) {
                PeptideAssumption peptideAssumption = (PeptideAssumption) assumption;
                Peptide sePeptide = peptideAssumption.getPeptide();
                if (psPeptide.isSameSequence(sePeptide, sequenceMatchingPreferences) && psPeptide.sameModificationsAs(sePeptide)) {
                    psParameter = (PSParameter) peptideAssumption.getUrParam(psParameter);
                    double ptemp = psParameter.getSearchEngineProbability();
                    if (ptemp < p1) {
                        p1 = ptemp;
View Full Code Here

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

        }

        HashMap<Double, ArrayList<PTM>> modifications = new HashMap<Double, ArrayList<PTM>>();
        HashMap<Double, Integer> nMod = new HashMap<Double, Integer>();
        HashMap<Double, ModificationMatch> modificationMatches = new HashMap<Double, ModificationMatch>();
        Peptide peptide = spectrumMatch.getBestPeptideAssumption().getPeptide();

        for (ModificationMatch modificationMatch : peptide.getModificationMatches()) {
            if (modificationMatch.isVariable()) {
                PTM refPTM = ptmFactory.getPTM(modificationMatch.getTheoreticPtm());
                double ptmMass = refPTM.getMass();
                if (!modifications.containsKey(ptmMass)) {
                    ArrayList<PTM> ptms = new ArrayList<PTM>();
                    for (String ptm : ptmProfile.getSimilarNotFixedModifications(ptmMass)) {
                        ptms.add(ptmFactory.getPTM(ptm));
                    }
                    modifications.put(ptmMass, ptms);
                    nMod.put(ptmMass, 1);
                } else {
                    nMod.put(ptmMass, nMod.get(ptmMass) + 1);
                }
                modificationMatches.put(ptmMass, modificationMatch);
            }
        }

        if (!modifications.isEmpty()) {

            MSnSpectrum spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumMatch.getKey());
            annotationPreferences.setCurrentSettings(spectrumMatch.getBestPeptideAssumption(), true, sequenceMatchingPreferences);

            for (Double ptmMass : modifications.keySet()) {
                HashMap<Integer, Double> scores = null;
                if (scoringPreferences.getSelectedProbabilisticScore() == PtmScore.AScore && nMod.get(ptmMass) == 1) {
                    scores = AScore.getAScore(peptide, modifications.get(ptmMass), spectrum, annotationPreferences.getIonTypes(),
                            annotationPreferences.getNeutralLosses(), annotationPreferences.getValidatedCharges(),
                            spectrumMatch.getBestPeptideAssumption().getIdentificationCharge().value,
                            searchParameters.getFragmentIonAccuracy(), scoringPreferences.isProbabilisticScoreNeutralLosses(), sequenceMatchingPreferences, peptideSpectrumAnnotator, roundingDecimal);
                } else if (scoringPreferences.getSelectedProbabilisticScore() == PtmScore.PhosphoRS) {
                    scores = PhosphoRS.getSequenceProbabilities(peptide, modifications.get(ptmMass), spectrum, annotationPreferences.getIonTypes(),
                            annotationPreferences.getNeutralLosses(), annotationPreferences.getValidatedCharges(),
                            spectrumMatch.getBestPeptideAssumption().getIdentificationCharge().value,
                            searchParameters.getFragmentIonAccuracy(), scoringPreferences.isProbabilisticScoreNeutralLosses(),
                            sequenceMatchingPreferences, peptideSpectrumAnnotator, roundingDecimal);
                }
                if (scores != null) {
                    // remap to searched PTMs
                    PTM mappedModification = null;
                    String peptideSequence = peptide.getSequence();
                    for (int site : scores.keySet()) {
                        if (site == 0) {
                            // N-term ptm
                            for (PTM ptm : modifications.get(ptmMass)) {
                                if (ptm.isNTerm() && peptide.getPotentialModificationSites(ptm, sequenceMatchingPreferences).contains(1)) {
                                    mappedModification = ptm;
                                    break;
                                }
                            }
                            if (mappedModification == null) {
                                throw new IllegalArgumentException("Could not map the PTM of mass " + ptmMass + " on the N-terminus of the peptide " + peptideSequence + ".");
                            }
                        } else if (site == peptideSequence.length() + 1) {
                            // C-term ptm
                            for (PTM ptm : modifications.get(ptmMass)) {
                                if (ptm.isCTerm() && peptide.getPotentialModificationSites(ptm, sequenceMatchingPreferences).contains(peptideSequence.length())) {
                                    mappedModification = ptm;
                                    break;
                                }
                            }
                            if (mappedModification == null) {
                                throw new IllegalArgumentException("Could not map the PTM of mass " + ptmMass + " on the C-terminus of the peptide " + peptideSequence + ".");
                            }
                        } else {
                            for (PTM ptm : modifications.get(ptmMass)) {
                                if (peptide.getPotentialModificationSites(ptm, sequenceMatchingPreferences).contains(site)) {
                                    mappedModification = ptm;
                                    break;
                                }
                            }
                            if (mappedModification == null) {
                                throw new IllegalArgumentException("Could not map the PTM of mass " + ptmMass + " at site " + site + " in peptide " + peptide.getSequence() + ".");
                            }
                        }

                        String ptmName = mappedModification.getName();
View Full Code Here

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

        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);

                            if (sites == null) {
                                sites = new ArrayList<Integer>();
                                dSitesMap.put(score, sites);
                            }

                            sites.add(site);
                        }

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

                            double score = ptmScoring.getProbabilisticScore(site);
                            ArrayList<Integer> sites = pSitesMap.get(score);

                            if (sites == null) {
                                sites = new ArrayList<Integer>();
                                pSitesMap.put(score, sites);
                            }

                            sites.add(site);

                            if (!pScores.containsKey(site)) {
                                pScores.put(site, score);
                            } else {
                                throw new IllegalArgumentException("Duplicate PTM score found at site " + site
                                        + " for peptide " + peptide.getSequence() + " in spectrum " + spectrumMatch.getKey() + ".");
                            }
                        }
                    }
                }

                ArrayList<Integer> dSites = new ArrayList<Integer>(nPtm);
                ArrayList<Double> scores = new ArrayList<Double>(dSitesMap.keySet());
                Collections.sort(scores, Collections.reverseOrder());
                int cpt = 0;

                for (double score : scores) {

                    ArrayList<Integer> sites = dSitesMap.get(score);

                    if (sites.size() >= nPtm - cpt) {
                        dSites.addAll(sites);
                        cpt += sites.size();
                    } else {
                        Collections.shuffle(sites);
                        for (Integer site : sites) {
                            if (cpt == nPtm) {
                                break;
                            }
                            dSites.add(site);
                        }
                    }

                    if (cpt == nPtm) {
                        break;
                    }
                }

                ArrayList<Integer> pSites = new ArrayList<Integer>(nPtm);
                scores = new ArrayList<Double>(pSitesMap.keySet());
                Collections.sort(scores, Collections.reverseOrder());
                cpt = 0;

                for (double score : scores) {

                    ArrayList<Integer> sites = pSitesMap.get(score);

                    if (sites.size() >= nPtm - cpt) {
                        pSites.addAll(sites);
                        cpt += sites.size();
                    } else {
                        Collections.shuffle(sites);
                        for (Integer site : sites) {
                            if (cpt == nPtm) {
                                break;
                            }
                            pSites.add(site);
                        }
                    }
                    if (cpt == nPtm) {
                        break;
                    }
                }

                if (dSites.size() < nPtm) {
                    throw new IllegalArgumentException("found less D-scores than PTMs for modification of mass "
                            + ptmMass + " in peptide " + peptide.getSequence() + " in spectrum " + spectrumMatch.getKey() + ".");
                }

                for (Integer site : pSites) {
                    boolean conflict = !dSites.contains(site);
                    psmPTMMap.addPoint(ptmMass, -pScores.get(site), spectrumMatch, conflict);
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.