Examples of PeptideAssumption


Examples of com.compomics.util.experiment.identification.PeptideAssumption

                if (!validatedOnly || psParameter.getMatchValidationLevel().isValidated()) {

                    spectrumMatch = identification.getSpectrumMatch(spectrumKey);

                    PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();

                    if (decoys || peptideAssumption == null || !peptideAssumption.getPeptide().isDecoy(sequenceMatchingPreferences)) {

                        boolean first = true;

                        if (indexes) {
                            if (linePrefix != null) {
View Full Code Here

Examples of com.compomics.util.experiment.identification.PeptideAssumption

            case algorithm_score:
                HashMap<Integer, Double> scoreMap = new HashMap<Integer, Double>();
                if (spectrumMatch.getBestPeptideAssumption() != null) {
                    for (SpectrumIdentificationAssumption spectrumIdentificationAssumption : spectrumMatch.getAllAssumptions()) {
                        if (spectrumIdentificationAssumption instanceof PeptideAssumption) {
                            PeptideAssumption peptideAssumption = (PeptideAssumption) spectrumIdentificationAssumption;
                            if (peptideAssumption.getPeptide().isSameSequenceAndModificationStatus(spectrumMatch.getBestPeptideAssumption().getPeptide(), sequenceMatchingPreferences)) {
                                int id = peptideAssumption.getAdvocate();
                                double score = peptideAssumption.getScore();
                                Double currentScore = scoreMap.get(id);
                                if (currentScore == null || score < currentScore) {
                                    scoreMap.put(id, score);
                                }
                            }
View Full Code Here

Examples of com.compomics.util.experiment.identification.PeptideAssumption

                            }
                            HashMap<Peptide, HashMap<String, ArrayList<Integer>>> proteinMapping = proteinTree.getProteinMapping(extendedAssumption.getTag(), tagMatcher, sequenceMatchingPreferences, searchParameters.getFragmentIonAccuracy());
                            for (Peptide peptide : proteinMapping.keySet()) {
                                String peptideKey = peptide.getKey();
                                if (!peptidesFound.contains(peptideKey)) {
                                    PeptideAssumption peptideAssumption = new PeptideAssumption(peptide, extendedAssumption.getRank(), advocateId, tagAssumption.getIdentificationCharge(), tagAssumption.getScore(), tagAssumption.getIdentificationFile());
                                    peptideAssumption.addUrParam(tagAssumption);
                                    spectrumMatch.addHit(advocateId, peptideAssumption, true);
                                    peptidesFound.add(peptideKey);
                                }
                            }
                            String extendedSequence = extendedAssumption.getTag().asSequence();
View Full Code Here

Examples of com.compomics.util.experiment.identification.PeptideAssumption

            psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
            SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);

            if (spectrumMatch.getBestPeptideAssumption() != null) { // Should always be the case

                PeptideAssumption peptideAssumption = spectrumMatch.getBestPeptideAssumption();
                peptide = peptideAssumption.getPeptide();

                int column = 1;
                HSSFRow rowHead = sheet.createRow(++currentRow);
                rowHead.setHeightInPoints(12.75f);

                Cell cell = rowHead.createCell(column++);
                MatchValidationLevel matchValidationLevel = psParameter.getMatchValidationLevel();
                // High, Medium or Low - refers to the confidence in the peptide
                if (matchValidationLevel == MatchValidationLevel.confident) {
                    cell.setCellValue("High");
                } else if (matchValidationLevel == MatchValidationLevel.doubtful) {
                    cell.setCellValue("Medium");
                } else {
                    cell.setCellValue("Low");
                }
                cell.setCellStyle(a2CellStyle);

                cell = rowHead.createCell(column++);
                cell.setCellValue(peptide.getSequenceWithLowerCasePtms()); // peptide sequence, modified residues in lower case
                cell.setCellStyle(peptideRowCellStyle);

                cell = rowHead.createCell(column++);
                cell.setCellValue(1); // number of PSMs
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                cell = rowHead.createCell(column++);
                cell.setCellValue(proteinAccessions.size()); // number of proteins
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                cell = rowHead.createCell(column++);
                cell.setCellValue(proteinGroups.size()); // number of protein groups
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                cell = rowHead.createCell(column++);
                cell.setCellValue(proteinAccessionsAsString.toString()); // protein accessions, separated by semi colon
                cell.setCellStyle(peptideRowCellStyle);

                cell = rowHead.createCell(column++);
                cell.setCellValue(getPeptideModificationsAsString(peptide)); // the modifications, separated by semi colon _and_ space // @TODO: reformat
                cell.setCellStyle(peptideRowCellStyle);

                cell = rowHead.createCell(column++);
                Double delta = psParameter.getDeltaPEP(); // PeptideShaker closest equivalent to a delta Cn
                if (delta == null) {
                    cell.setCellValue(Double.NaN);
                    // @TODO: set another type?
                } else {
                    cell.setCellValue(delta);
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                }
                cell.setCellStyle(peptideRowCellStyle);

                cell = rowHead.createCell(column++);
                cell.setCellValue(0); // PeptideShaker q-value // @TODO: insert real value
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                cell = rowHead.createCell(column++);
                cell.setCellValue(psParameter.getPsmProbability()); // pep value
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                cell = rowHead.createCell(column++);
                double score = psParameter.getPsmScore(); // PeptideShaker closest equivalent to an ion score
                cell.setCellValue(score);
                cell.setCellStyle(peptideRowCellStyle);
                if (score != Double.POSITIVE_INFINITY) {
                    cell.setCellType(Cell.CELL_TYPE_NUMERIC);
                }

                cell = rowHead.createCell(column++);
                cell.setCellValue(psParameter.getPsmProbabilityScore()); // PeptideShaker closest equivalent to an e-value
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                cell = rowHead.createCell(column++);
                cell.setCellValue(peptideAssumption.getIdentificationCharge().value); // charge
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                cell = rowHead.createCell(column++);
                cell.setCellValue(identification.getPeptideMatch(peptideKey).getTheoreticPeptide().getMass()
                        + ElementaryIon.proton.getTheoreticMass()); // theoretical mass for single charge: MH+ [Da]
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                Precursor precursor = spectrumFactory.getPrecursor(spectrumKey);

                cell = rowHead.createCell(column++);
                cell.setCellValue(peptideAssumption.getDeltaMass(precursor.getMz(), true)); // mass error in ppm
                cell.setCellStyle(peptideRowCellStyle);
                cell.setCellType(Cell.CELL_TYPE_NUMERIC);

                cell = rowHead.createCell(column++);
                Double rt = precursor.getRt();
View Full Code Here

Examples of com.compomics.util.experiment.identification.PeptideAssumption

            String fileName = Spectrum.getSpectrumFile(spectrumKey);
            String spectrumTitle = Spectrum.getSpectrumTitle(spectrumKey);

            for (SpectrumIdentificationAssumption assumption : spectrumMatch.getAllAssumptions()) {
                if (assumption instanceof PeptideAssumption) {
                    PeptideAssumption peptideAssumption = (PeptideAssumption) assumption;
                    if (!idFilter.validatePeptide(peptideAssumption.getPeptide(), sequenceMatchingPreferences)) {
                        spectrumMatch.removeAssumption(assumption);
                        peptideIssue++;
                    }
                }
            }

            if (!spectrumMatch.hasAssumption(advocateId)) {
                psmsRejected++;
            } else {

                if (spectrumMatch.hasAssumption(advocateId)) {

                    // Check whether there is a potential first hit which does not belong to the target and the decoy database
                    ArrayList<Double> eValues = new ArrayList<Double>(spectrumMatch.getAllAssumptions(advocateId).keySet());
                    Collections.sort(eValues);

                    for (Double eValue : eValues) {

                        ArrayList<SpectrumIdentificationAssumption> tempAssumptions
                                = new ArrayList<SpectrumIdentificationAssumption>(spectrumMatch.getAllAssumptions(advocateId).get(eValue));

                        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
                                            spectrumMatch.removeAssumption(assumption);
                                            proteinIssue++;
                                        }
                                    } else {
                                        spectrumMatch.removeAssumption(assumption);
                                        ptmIssue++;
                                    }
                                }
                            }
                        }
                    }
                }

                if (spectrumMatch.hasAssumption(advocateId)) {
                    // try to find the best peptide hit
                    PeptideAssumption firstPeptideHit = null;
                    ArrayList<Double> eValues = new ArrayList<Double>(spectrumMatch.getAllAssumptions(advocateId).keySet());
                    Collections.sort(eValues);

                    for (Double eValue : eValues) {
                        for (SpectrumIdentificationAssumption assumption : spectrumMatch.getAllAssumptions(advocateId).get(eValue)) {
                            if (assumption instanceof PeptideAssumption) {
                                PeptideAssumption peptideAssumption = (PeptideAssumption) assumption;
                                firstPeptideHit = peptideAssumption;
                                spectrumMatch.setFirstHit(advocateId, assumption);
                                checkPeptidesMassErrorsAndCharges(spectrumKey, peptideAssumption);
                                if (!processingPreferences.isScoringNeeded(advocateId)) {
                                    inputMap.addEntry(advocateId, fileName, firstPeptideHit.getScore(), firstPeptideHit.getPeptide().isDecoy(sequenceMatchingPreferences));
View Full Code Here

Examples of com.compomics.util.experiment.identification.PeptideAssumption

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

Examples of com.compomics.util.experiment.identification.PeptideAssumption

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

        String mainSequence = psPeptide.getSequence();
        ArrayList<String> modifications = new ArrayList<String>();

        for (ModificationMatch modificationMatch : psPeptide.getModificationMatches()) {
            if (modificationMatch.isVariable()) {
                String modificationName = modificationMatch.getTheoreticPtm();
                if (!modifications.contains(modificationName)) {
                    modifications.add(modificationName);
                    modificationProfiles.put(modificationName, new ArrayList<Integer>());
                }
                modificationProfiles.get(modificationName).add(modificationMatch.getModificationSite());
            }
        }

        if (!modifications.isEmpty()) {

            for (String modName : modifications) {

                PTM ptm1 = ptmFactory.getPTM(modName);

                for (int modSite : modificationProfiles.get(modName)) {

                    double refP = 1, secondaryP = 1;

                    for (SpectrumIdentificationAssumption assumption : spectrumMatch.getAllAssumptions()) {

                        if (assumption instanceof PeptideAssumption) {

                            PeptideAssumption peptideAssumption = (PeptideAssumption) assumption;

                            if (peptideAssumption.getPeptide().getSequence().equals(mainSequence)) {

                                boolean modificationAtSite = false, modificationFound = false;

                                for (ModificationMatch modMatch : peptideAssumption.getPeptide().getModificationMatches()) {

                                    PTM ptm2 = ptmFactory.getPTM(modMatch.getTheoreticPtm());

                                    if (ptm1.getMass() == ptm2.getMass()) {

                                        modificationFound = true;
                                        psParameter = (PSParameter) peptideAssumption.getUrParam(psParameter);
                                        double p = psParameter.getSearchEngineProbability();

                                        if (modMatch.getModificationSite() == modSite) {

                                            modificationAtSite = true;

                                            if (p < refP) {
                                                refP = p;
                                            }
                                        }
                                    }
                                }

                                if (!modificationAtSite && modificationFound) {
                                    psParameter = (PSParameter) peptideAssumption.getUrParam(psParameter);
                                    double p = psParameter.getSearchEngineProbability();
                                    if (p < secondaryP) {
                                        secondaryP = p;
                                    }
                                }
View Full Code Here

Examples of com.compomics.util.experiment.identification.PeptideAssumption

            throws IllegalArgumentException, SQLException, IOException, ClassNotFoundException, InterruptedException {

        SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
        PSParameter psParameter = new PSParameter();
        psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);
        PeptideAssumption bestAssumption = spectrumMatch.getBestPeptideAssumption();

        if (accessions == null) {
            accessions = bestAssumption.getPeptide().getParentProteins(sequenceMatchingPreferences);
        }

        for (String protein : accessions) {

            // peptide sequence
            writer.write(bestAssumption.getPeptide().getSequence() + SEPARATOR);

            // modifications
            HashMap<String, ArrayList<Integer>> modMap = new HashMap<String, ArrayList<Integer>>();
            for (ModificationMatch modificationMatch : bestAssumption.getPeptide().getModificationMatches()) {

                if (modificationMatch.isVariable()) {
                    if (!modMap.containsKey(modificationMatch.getTheoreticPtm())) {
                        modMap.put(modificationMatch.getTheoreticPtm(), new ArrayList<Integer>());
                    }
                    modMap.get(modificationMatch.getTheoreticPtm()).add(modificationMatch.getModificationSite());
                }
            }

            ArrayList<String> mods = new ArrayList<String>(modMap.keySet());

            for (int i = 0; i < bestAssumption.getPeptide().getSequence().length() + 1; i++) {

                String allMods = "";

                for (int k = 0; k < mods.size(); k++) {
View Full Code Here

Examples of com.compomics.util.experiment.identification.PeptideAssumption

                psParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, psParameter);

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

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

                    if (peptideAssumption != null) {

                        Precursor precursor = spectrumFactory.getPrecursor(spectrumKey);
                        double precursorMzError = peptideAssumption.getDeltaMass(precursor.getMz(), searchParameters.isPrecursorAccuracyTypePpm());
                        precursorMzDeviations.add(precursorMzError);
                        Integer charge = peptideAssumption.getIdentificationCharge().value;

                        if (!charges.contains(charge)) {
                            charges.add(charge);
                            PsmFilter psmFilter = new PsmFilter(">30% Fragment Ion Sequence Coverage");
                            psmFilter.setDescription("<30% sequence coverage by fragment ions");
                            psmFilter.setSequenceCoverage(30.0); // @TODO: make the doubtfulThreshold editable by the user!
                            psmFilter.setSequenceCoverageComparison(RowFilter.ComparisonType.AFTER);
                            psmMap.addDoubtfulMatchesFilter(charge, spectrumFileName, psmFilter);
                        }

                        if (inputMap != null) {

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

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

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

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

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

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

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

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

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

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

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

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

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

                if (needSecondPass) {

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

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

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

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

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

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

Examples of com.compomics.util.experiment.identification.PeptideAssumption

                                    break;
                                }

                                SpectrumMatch spectrumMatch = identification.getSpectrumMatch(psmKey);
                                psParameter = (PSParameter) identification.getSpectrumMatchParameter(psmKey, psParameter);
                                PeptideAssumption bestAssumption = spectrumMatch.getBestPeptideAssumption();

                                if (!bestAssumption.getPeptide().isDecoy(peptideShakerGUI.getSequenceMatchingPreferences()) || !onlyValidated) {
                                    if ((onlyValidated && psParameter.getMatchValidationLevel().isValidated()) || !onlyValidated) {
                                        if ((!includeHidden && !psParameter.isHidden()) || includeHidden) {
                                            if ((onlyStarred && psParameter.isStarred()) || !onlyStarred) {

                                                if (indexes) {
                                                    writer.write(++psmCounter + SEPARATOR);
                                                }

                                                if (accessions || proteinDescription) {

                                                    String proteinAccessions = "";
                                                    String proteinDescriptions = "";

                                                    boolean first = true;
                                                    for (String protein : bestAssumption.getPeptide().getParentProteins(peptideShakerGUI.getSequenceMatchingPreferences())) {
                                                        if (first) {
                                                            first = false;
                                                        } else {
                                                            if (accessions) {
                                                                proteinAccessions += ", ";
                                                            }
                                                            if (proteinDescription) {
                                                                proteinDescriptions += "; ";
                                                            }
                                                        }
                                                        if (accessions) {
                                                            proteinAccessions += protein;
                                                        }
                                                        if (proteinDescription) {
                                                            proteinDescriptions += sequenceFactory.getHeader(protein).getSimpleProteinDescription();
                                                        }
                                                    }
                                                    if (accessions) {
                                                        writer.write(proteinAccessions + SEPARATOR);
                                                    }
                                                    if (proteinDescription) {
                                                        writer.write(proteinDescriptions + SEPARATOR);
                                                    }
                                                }
                                                if (sequence) {
                                                    writer.write(bestAssumption.getPeptide().getSequence() + SEPARATOR);
                                                }
                                                if (modification) {
                                                    HashMap<String, ArrayList<Integer>> modMap = new HashMap<String, ArrayList<Integer>>();
                                                    for (ModificationMatch modificationMatch : bestAssumption.getPeptide().getModificationMatches()) {
                                                        if (modificationMatch.isVariable()) {
                                                            if (!modMap.containsKey(modificationMatch.getTheoreticPtm())) {
                                                                modMap.put(modificationMatch.getTheoreticPtm(), new ArrayList<Integer>());
                                                            }
                                                            modMap.get(modificationMatch.getTheoreticPtm()).add(modificationMatch.getModificationSite());
                                                        }
                                                    }
                                                    boolean first = true, first2;
                                                    ArrayList<String> mods = new ArrayList<String>(modMap.keySet());
                                                    Collections.sort(mods);
                                                    for (String mod : mods) {
                                                        if (first) {
                                                            first = false;
                                                        } else {
                                                            writer.write(", ");
                                                        }
                                                        first2 = true;
                                                        writer.write(mod + "(");
                                                        for (int aa : modMap.get(mod)) {
                                                            if (first2) {
                                                                first2 = false;
                                                            } else {
                                                                writer.write(", ");
                                                            }
                                                            writer.write(aa + "");
                                                        }
                                                        writer.write(")");
                                                    }
                                                    writer.write(SEPARATOR);
                                                }
                                                if (location) {
                                                    ArrayList<String> modList = new ArrayList<String>();
                                                    for (ModificationMatch modificationMatch : bestAssumption.getPeptide().getModificationMatches()) {
                                                        if (modificationMatch.isVariable()) {
                                                            PTM refPtm = ptmFactory.getPTM(modificationMatch.getTheoreticPtm());
                                                            for (String equivalentPtm : ptmProfile.getSimilarNotFixedModifications(refPtm.getMass())) {
                                                                if (!modList.contains(equivalentPtm)) {
                                                                    modList.add(equivalentPtm);
                                                                }
                                                            }
                                                        }
                                                    }
                                                    Collections.sort(modList);
                                                    PSPtmScores ptmScores = new PSPtmScores();
                                                    boolean first = true;
                                                    for (String mod : modList) {
                                                        if (spectrumMatch.getUrParam(ptmScores) != null) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                writer.write(", ");
                                                            }
                                                            ptmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
                                                            writer.write(mod + " (");
                                                            if (ptmScores != null && ptmScores.getPtmScoring(mod) != null) {
                                                                PtmScoring ptmScoring = ptmScores.getPtmScoring(mod);
                                                                boolean firstSite = true;
                                                                for (int site : ptmScoring.getOrderedPtmLocations()) {
                                                                    if (firstSite) {
                                                                        firstSite = false;
                                                                    } else {
                                                                        writer.write(", ");
                                                                    }
                                                                    int ptmConfidence = ptmScoring.getLocalizationConfidence(site);
                                                                    if (ptmConfidence == PtmScoring.NOT_FOUND) {
                                                                        writer.write(site + ": Not Scored"); // Well this should not happen
                                                                    } else if (ptmConfidence == PtmScoring.RANDOM) {
                                                                        writer.write(site + ": Random");
                                                                    } else if (ptmConfidence == PtmScoring.DOUBTFUL) {
                                                                        writer.write(site + ": Doubtfull");
                                                                    } else if (ptmConfidence == PtmScoring.CONFIDENT) {
                                                                        writer.write(site + ": Confident");
                                                                    } else if (ptmConfidence == PtmScoring.VERY_CONFIDENT) {
                                                                        writer.write(site + ": Very Confident");
                                                                    }
                                                                }
                                                            } else {
                                                                writer.write("Not Scored");
                                                            }
                                                            writer.write(")");
                                                        }
                                                    }
                                                    writer.write(SEPARATOR);
                                                    if (ptmScoringPreferences.isProbabilitsticScoreCalculation()) {
                                                        first = true;
                                                        for (String mod : modList) {
                                                            if (spectrumMatch.getUrParam(ptmScores) != null) {
                                                                if (first) {
                                                                    first = false;
                                                                } else {
                                                                    writer.write(", ");
                                                                }
                                                                ptmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
                                                                writer.write(mod + " (");
                                                                if (ptmScores != null && ptmScores.getPtmScoring(mod) != null) {
                                                                    PtmScoring ptmScoring = ptmScores.getPtmScoring(mod);
                                                                    boolean firstSite = true;
                                                                    ArrayList<Integer> sites = new ArrayList<Integer>(ptmScoring.getProbabilisticSites());
                                                                    Collections.sort(sites);
                                                                    for (int site : sites) {
                                                                        if (firstSite) {
                                                                            firstSite = false;
                                                                        } else {
                                                                            writer.write(", ");
                                                                        }
                                                                        writer.write(site + ": " + ptmScoring.getProbabilisticScore(site));
                                                                    }
                                                                } else {
                                                                    writer.write("Not Scored");
                                                                }
                                                                writer.write(")");
                                                            }
                                                        }
                                                    }
                                                    writer.write(SEPARATOR);
                                                    first = true;
                                                    for (String mod : modList) {
                                                        if (spectrumMatch.getUrParam(ptmScores) != null) {
                                                            if (first) {
                                                                first = false;
                                                            } else {
                                                                writer.write(", ");
                                                            }
                                                            ptmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
                                                            writer.write(mod + " (");
                                                            if (ptmScores != null && ptmScores.getPtmScoring(mod) != null) {
                                                                PtmScoring ptmScoring = ptmScores.getPtmScoring(mod);
                                                                boolean firstSite = true;
                                                                ArrayList<Integer> sites = new ArrayList<Integer>(ptmScoring.getDSites());
                                                                Collections.sort(sites);
                                                                for (int site : sites) {
                                                                    if (firstSite) {
                                                                        firstSite = false;
                                                                    } else {
                                                                        writer.write(", ");
                                                                    }
                                                                    writer.write(site + ": " + ptmScoring.getDeltaScore(site));
                                                                }
                                                            } else {
                                                                writer.write("Not Scored");
                                                            }
                                                            writer.write(")");
                                                        }
                                                    }
                                                    writer.write(SEPARATOR);
                                                }
                                                if (file) {
                                                    writer.write(spectrumFile + SEPARATOR);
                                                }
                                                if (title) {
                                                    writer.write(Spectrum.getSpectrumTitle(spectrumMatch.getKey()) + SEPARATOR);
                                                }
                                                if (precursor) {
                                                    Precursor prec = spectrumFactory.getPrecursor(spectrumMatch.getKey());
                                                    writer.write(prec.getMz() + SEPARATOR);
                                                    writer.write(prec.getPossibleChargesAsString() + SEPARATOR);
                                                    writer.write(bestAssumption.getIdentificationCharge().value + SEPARATOR);
                                                    writer.write(prec.getRt() + SEPARATOR);
                                                    writer.write(bestAssumption.getPeptide().getMass() + SEPARATOR);
                                                    writer.write(bestAssumption.getDeltaMass(prec.getMz(), peptideShakerGUI.getSearchParameters().isPrecursorAccuracyTypePpm()) + SEPARATOR);
                                                    writer.write(bestAssumption.getIsotopeNumber(prec.getMz()) + SEPARATOR);
                                                }
                                                if (score) {
                                                    writer.write(psParameter.getPsmScore() + SEPARATOR);
                                                }
                                                if (confidence) {
                                                    writer.write(psParameter.getPsmConfidence() + SEPARATOR);
                                                }
                                                if (!onlyValidated) {
                                                    MatchValidationLevel matchValidationLevel = psParameter.getMatchValidationLevel();
                                                    writer.write(matchValidationLevel.toString());
                                                    if (matchValidationLevel == MatchValidationLevel.doubtful && !psParameter.getReasonDoubtful().equals("")) {
                                                        writer.write(" (" + psParameter.getReasonDoubtful() + ")");
                                                    }
                                                    writer.write(SEPARATOR);

                                                    if (bestAssumption.getPeptide().isDecoy(peptideShakerGUI.getSequenceMatchingPreferences())) {
                                                        writer.write(1 + SEPARATOR);
                                                    } else {
                                                        writer.write(0 + SEPARATOR);
                                                    }
                                                }
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.