// @TODO: iterate all assumptions and not just the best one?
PeptideAssumption bestPeptideAssumption = spectrumMatch.getBestPeptideAssumption();
if (bestPeptideAssumption != null) {
PSParameter psmParameter = (PSParameter) identification.getSpectrumMatchParameter(psmKey, new PSParameter());
int rank = 1; // @TODO: should not be hardcoded?
String spectrumIdentificationItemKey = "SII_" + psmIndex + "_" + rank;
spectrumIds.put(psmKey, spectrumIdentificationItemKey);
String bestPeptideKey = bestPeptideAssumption.getPeptide().getMatchingKey(sequenceMatchingPreferences);
br.write(getCurrentTabSpace() + "<SpectrumIdentificationItem "
+ "passThreshold=\"" + psmParameter.getMatchValidationLevel().isValidated() + "\" "
+ "rank=\"" + rank + "\" "
+ "peptide_ref=\"" + bestPeptideKey + "\" "
+ "calculatedMassToCharge=\"" + bestPeptideAssumption.getTheoreticMz() + "\" "
+ "experimentalMassToCharge=\"" + spectrumFactory.getPrecursor(psmKey).getMz() + "\" "
+ "chargeState=\"" + bestPeptideAssumption.getIdentificationCharge().value + "\" "
+ "id=\"" + spectrumIdentificationItemKey + "\">" + System.getProperty("line.separator"));
tabCounter++;
// @TODO: add peptide level annotation
// MS:1002462: distinct peptide-level global FNR
// MS:1002463: distinct peptide-level global confidence
// MS:1001364: distinct peptide-level global FDR
//
// add the peptide evidence references
// get all the possible parent proteins
ArrayList<String> possibleProteins = bestPeptideAssumption.getPeptide().getParentProteins(sequenceMatchingPreferences);
String peptideSequence = bestPeptideAssumption.getPeptide().getSequence();
// iterate all the possible protein parents for each peptide
for (String tempProtein : possibleProteins) {
// get the start indexes and the surrounding amino acids
ArrayList<Integer> peptideStarts = sequenceFactory.getProtein(tempProtein).getPeptideStart(
peptideSequence, sequenceMatchingPreferences);
for (int start : peptideStarts) {
String pepEvidenceKey = tempProtein + "_" + start + "_" + bestPeptideKey;
String peptideEvidenceId = pepEvidenceIds.get(pepEvidenceKey);
br.write(getCurrentTabSpace() + "<PeptideEvidenceRef peptideEvidence_ref=\"" + peptideEvidenceId + "\"/>" + System.getProperty("line.separator"));
}
}
// add the fragment ion annotation
int identificationCharge = bestPeptideAssumption.getIdentificationCharge().value;
annotationPreferences.setCurrentSettings(bestPeptideAssumption, true, sequenceMatchingPreferences);
MSnSpectrum spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumFileName, spectrumTitle);
// get all the fragment ion annotations
ArrayList<IonMatch> annotations = peptideSpectrumAnnotator.getSpectrumAnnotation(annotationPreferences.getIonTypes(),
annotationPreferences.getNeutralLosses(),
annotationPreferences.getValidatedCharges(),
identificationCharge,
spectrum, bestPeptideAssumption.getPeptide(),
spectrum.getIntensityLimit(annotationPreferences.getAnnotationIntensityLimit()),
annotationPreferences.getFragmentIonAccuracy(), false,
annotationPreferences.isHighResolutionAnnotation());
// organize the fragment ions by ion type
HashMap<String, HashMap<Integer, ArrayList<IonMatch>>> allFragmentIons = new HashMap<String, HashMap<Integer, ArrayList<IonMatch>>>();
for (IonMatch ionMatch : annotations) {
if (ionMatch.ion.getType() == IonType.PEPTIDE_FRAGMENT_ION
|| ionMatch.ion.getType() == IonType.IMMONIUM_ION) { // @TODO: add PRECURSOR_ION and REPORTER_ION
// || ionMatch.ion.getType() == IonType.PRECURSOR_ION
// || ionMatch.ion.getType() == IonType.REPORTER_ION) {
CvTerm fragmentIonTerm = ionMatch.ion.getPrideCvTerm(); // @TODO: replace by PSI-MS mappings...
Integer charge = ionMatch.charge.value;
if (fragmentIonTerm != null) {
if (!allFragmentIons.containsKey(fragmentIonTerm.getName())) {
allFragmentIons.put(fragmentIonTerm.getName(), new HashMap<Integer, ArrayList<IonMatch>>());
}
if (!allFragmentIons.get(fragmentIonTerm.getName()).containsKey(charge)) {
allFragmentIons.get(fragmentIonTerm.getName()).put(charge, new ArrayList<IonMatch>());
}
allFragmentIons.get(fragmentIonTerm.getName()).get(charge).add(ionMatch);
}
}
}
if (!allFragmentIons.isEmpty()) {
br.write(getCurrentTabSpace() + "<Fragmentation>" + System.getProperty("line.separator"));
tabCounter++;
// add the fragment ions
Iterator<String> fragmentTypeIterator = allFragmentIons.keySet().iterator();
while (fragmentTypeIterator.hasNext()) {
String fragmentType = fragmentTypeIterator.next();
Iterator<Integer> chargeTypeIterator = allFragmentIons.get(fragmentType).keySet().iterator();
while (chargeTypeIterator.hasNext()) {
Integer fragmentCharge = chargeTypeIterator.next();
ArrayList<IonMatch> ionMatches = allFragmentIons.get(fragmentType).get(fragmentCharge);
CvTerm fragmentIonTerm = ionMatches.get(0).ion.getPrideCvTerm();
String indexes = "";
String mzValues = "";
String intensityValues = "";
String errorValues = "";
// get the fragment ion details
for (IonMatch ionMatch : ionMatches) {
if (ionMatch.ion instanceof PeptideFragmentIon) {
indexes += ((PeptideFragmentIon) ionMatch.ion).getNumber() + " ";
} else if (ionMatch.ion instanceof ImmoniumIon) {
char residue = ImmoniumIon.getResidue(((ImmoniumIon) ionMatch.ion).getSubType());
char[] peptideAsArray = peptideSequence.toCharArray();
for (int i = 0; i < peptideAsArray.length; i++) {
if (peptideAsArray[i] == residue) {
indexes += (i + 1) + " ";
}
}
} else {
// not yet implemented...
}
mzValues += ionMatch.peak.mz + " ";
intensityValues += ionMatch.peak.intensity + " ";
errorValues += ionMatch.getAbsoluteError() + " ";
}
br.write(getCurrentTabSpace() + "<IonType charge=\"" + fragmentCharge + "\" index=\"" + indexes.trim() + "\">" + System.getProperty("line.separator"));
tabCounter++;
br.write(getCurrentTabSpace() + "<FragmentArray measure_ref=\"Measure_MZ\" values=\"" + mzValues.trim() + "\"/>" + System.getProperty("line.separator"));
br.write(getCurrentTabSpace() + "<FragmentArray measure_ref=\"Measure_Int\" values=\"" + intensityValues.trim() + "\"/>" + System.getProperty("line.separator"));
br.write(getCurrentTabSpace() + "<FragmentArray measure_ref=\"Measure_Error\" values=\"" + errorValues.trim() + "\"/>" + System.getProperty("line.separator"));
writeCvTerm(new CvTerm(fragmentIonTerm.getOntology(), fragmentIonTerm.getAccession(), fragmentIonTerm.getName(), null));
tabCounter--;
br.write(getCurrentTabSpace() + "</IonType>" + System.getProperty("line.separator"));
}
}
tabCounter--;
br.write(getCurrentTabSpace() + "</Fragmentation>" + System.getProperty("line.separator"));
}
// add peptide shaker score and confidence
writeCvTerm(new CvTerm("PSI-MS", "MS:1002466", "PeptideShaker: PSM score", Double.toString(Util.roundDouble(psmParameter.getPsmScore(), CONFIDENCE_DECIMALS))));
writeCvTerm(new CvTerm("PSI-MS", "MS:1002467", "PeptideShaker PSM confidence", Double.toString(Util.roundDouble(psmParameter.getPsmConfidence(), CONFIDENCE_DECIMALS))));
if (mzidVersion1_2) {
PeptideMatch peptideMatch = identification.getPeptideMatch(bestPeptideKey);
PSPtmScores psPtmScores = (PSPtmScores) spectrumMatch.getUrParam(new PSPtmScores());
if (psPtmScores != null) {
int modMatchIndex = 0;
for (ModificationMatch modMatch : bestPeptideAssumption.getPeptide().getModificationMatches()) {
PtmScoring ptmScoring = psPtmScores.getPtmScoring(modMatch.getTheoreticPtm());
if (ptmScoring != null) {
int site = modMatch.getModificationSite();
if (ptmScoringPreferences.isProbabilitsticScoreCalculation()) {
double score = ptmScoring.getProbabilisticScore(site);
String valid = "true";
if (score < ptmScoringPreferences.getProbabilisticScoreThreshold()) {
valid = "false";
}
writeCvTerm(new CvTerm("PSI-MS", "MS:100XXX",
ptmScoringPreferences.getSelectedProbabilisticScore().getName(),
modMatchIndex + ":" + score + ":" + site + ":" + valid)); // @TODO: add correct cv term!
}
double score = ptmScoring.getDeltaScore(site);
String valid = "true";
if (score < 95) { //@TODO: avoid this hard coded value
valid = "false";
}
writeCvTerm(new CvTerm("PSI-MS", "MS:100XXX", "D-score",
modMatchIndex + ":" + score + ":" + site + ":" + valid)); // @TODO: add correct cv term!
}
modMatchIndex++;
}
}
PSParameter peptideParameter = (PSParameter) identification.getPeptideMatchParameter(bestPeptideKey, psmParameter);
writeCvTerm(new CvTerm("PSI-MS", "MS:100XXX", "peptide: Confidence", peptideParameter.getPeptideConfidence() + "")); // @TODO: add correct cv term!
writeCvTerm(new CvTerm("PSI-MS", "MS:1002489", "peptide: Score", peptideParameter.getPeptideScore() + ""));
writeCvTerm(new CvTerm("PSI-MS", "MS:1002500", "peptide passes threshold", peptideParameter.getMatchValidationLevel().isValidated() + ""));
psPtmScores = (PSPtmScores) peptideMatch.getUrParam(new PSPtmScores());
if (psPtmScores != null) {
int modMatchIndex = 0;
for (ModificationMatch modMatch : peptideMatch.getTheoreticPeptide().getModificationMatches()) {