private static int insertPeptideHitsIntoCompiler( PIACompiler compiler, List<PeptideHit> peptideHits, ProteinMap proteinMap, SearchDatabase searchDatabase, int charge, Double precursorMZ, Double retentionTime, String sourceId, String spectrumTitle, PIAInputFile file, SpectrumIdentification spectrumID, boolean isDecoy) { String sourceIdStr = sourceId; if (peptideHits == null) { return 0; } int nrPepHits = 0; Matcher matcher = MzIdentMLTools.patternScanInTitle.matcher(spectrumTitle); if (matcher.matches()) { sourceIdStr = "index=" + matcher.group(1); } // the peptideHits are the SpectrumPeptideMatches for (PeptideHit peptideHit : peptideHits) { PeptideSpectrumMatch psm; psm = compiler.createNewPeptideSpectrumMatch( charge, precursorMZ, peptideHit.getDeltaMass(), retentionTime, peptideHit.getSequence(), peptideHit.getMissedCleavages(), sourceIdStr, spectrumTitle, file, spectrumID); psm.setIsDecoy(isDecoy); // get the peptide from the compiler or, if need be, add it Peptide peptide; peptide = compiler.getPeptide(peptideHit.getSequence()); if (peptide == null) { peptide = compiler.insertNewPeptide(peptideHit.getSequence()); } // add the spectrum to the peptide peptide.addSpectrum(psm); // go through the protein hits @SuppressWarnings("unchecked") List<ProteinHit> proteins = peptideHit.getProteinHits(); for (ProteinHit proteinHit : proteins) { FastaHeaderInfos fastaInfo = FastaHeaderInfos.parseHeaderInfos(proteinHit.getAccession()); if (fastaInfo == null) { fastaInfo = new FastaHeaderInfos( null, proteinHit.getAccession(), proteinMap.getProteinID(proteinHit.getAccession()).getDescription()); } else { // if there was a protein description different to the now parsed one, take the original // from mascot String proteinDescription = proteinMap.getProteinID(proteinHit.getAccession()).getDescription(); if ((proteinDescription != null) && (proteinDescription.trim().length() > 0) && !proteinDescription.equals(fastaInfo.getDescription())) { fastaInfo = new FastaHeaderInfos(null, fastaInfo.getAccession(), proteinDescription); } } // add the Accession to the compiler (if it is not already there) Accession acc = compiler.getAccession(fastaInfo.getAccession()); if (acc == null) { // unfortunately, the sequence is not stored in the dat file acc = compiler.insertNewAccession(fastaInfo.getAccession(), null); } acc.addFile(file.getID()); if ((fastaInfo.getDescription() != null) && (fastaInfo.getDescription().length() > 0)) { acc.addDescription(file.getID(), fastaInfo.getDescription()); } acc.addSearchDatabaseRef(searchDatabase.getId()); // add the accession occurrence to the peptide peptide.addAccessionOccurrence(acc, proteinHit.getStart(), proteinHit.getStop()); // now insert the connection between peptide and accession into the compiler compiler.addAccessionPeptideConnection(acc, peptide); } // add the scores ScoreModel score; score = new ScoreModel(peptideHit.getIonsScore(), ScoreModelEnum.MASCOT_SCORE); psm.addScore(score); score = new ScoreModel(peptideHit.getExpectancy(), ScoreModelEnum.MASCOT_EXPECT); psm.addScore(score); // add the modifications com.compomics.mascotdatfile.util.interfaces.Modification[] mods = peptideHit.getModifications(); for (int loc = 0; loc < mods.length; loc++) { if (mods[loc] != null) { Modification modification; Character residue; if ((loc == 0) || (loc > psm.getSequence().length())) { residue = '.'; } else { residue = psm.getSequence().charAt(loc - 1); } modification = new Modification(residue, mods[loc].getMass(), mods[loc].getType(), null); psm.addModification(loc, modification); } } compiler.insertCompletePeptideSpectrumMatch(psm); nrPepHits++; } return nrPepHits; }