Identification identification = experiment.getAnalysisSet(sample).getProteomicAnalysis(replicateNumber).getIdentification(IdentificationMethod.MS2_IDENTIFICATION);
waitingHandler.setSecondaryProgressCounterIndeterminate(false);
waitingHandler.setMaxSecondaryProgressCounter(identification.getSpectrumIdentificationSize());
PeptideSpectrumAnnotator spectrumAnnotator = new PeptideSpectrumAnnotator();
boolean multiSE = inputMap.isMultipleAlgorithms();
// Keep a map of the spectrum keys grouped by peptide
HashMap<String, ArrayList<String>> orderedPsmMap = null;
if (MemoryConsumptionStatus.memoryUsed() < 0.8) {
orderedPsmMap = new HashMap<String, ArrayList<String>>(identification.getSpectrumIdentificationMap().size());
}
for (String spectrumFileName : identification.getSpectrumFiles()) {
HashMap<String, ArrayList<String>> keysMap = null;
if (orderedPsmMap != null) {
keysMap = new HashMap<String, ArrayList<String>>();
}
// batch load the spectrum matches
identification.loadSpectrumMatches(spectrumFileName, null);
for (String spectrumKey : identification.getSpectrumIdentification(spectrumFileName)) {
// map of the peptide first hits for this spectrum: score -> max protein count -> max search engine votes -> sequence coverage annotated -> min mass deviation (unless you have a better idea?)
HashMap<Double, HashMap<Integer, HashMap<Integer, HashMap<Double, HashMap<Double, ArrayList<PeptideAssumption>>>>>> peptideAssumptions
= new HashMap<Double, HashMap<Integer, HashMap<Integer, HashMap<Double, HashMap<Double, ArrayList<PeptideAssumption>>>>>>();
// map of the tag first hits: score -> assumptions
HashMap<Double, ArrayList<TagAssumption>> tagAssumptions = new HashMap<Double, ArrayList<TagAssumption>>();
PSParameter psParameter = new PSParameter();
ArrayList<String> identifications = new ArrayList<String>();
SpectrumMatch spectrumMatch = identification.getSpectrumMatch(spectrumKey);
for (int searchEngine1 : spectrumMatch.getAdvocates()) {
double bestEvalue = Collections.min(spectrumMatch.getAllAssumptions(searchEngine1).keySet());
for (SpectrumIdentificationAssumption assumption1 : spectrumMatch.getAllAssumptions(searchEngine1).get(bestEvalue)) {
if (assumption1 instanceof PeptideAssumption) {
PeptideAssumption peptideAssumption1 = (PeptideAssumption) assumption1;
String id = peptideAssumption1.getPeptide().getKey();
if (!identifications.contains(id)) {
psParameter = (PSParameter) peptideAssumption1.getUrParam(psParameter);
double p;
if (multiSE && sequenceFactory.concatenatedTargetDecoy()) {
p = psParameter.getSearchEngineProbability();
} else {
p = peptideAssumption1.getScore();
}
int nSE = 1;
int proteinMax = 1;
for (String protein : peptideAssumption1.getPeptide().getParentProteins(sequenceMatchingPreferences)) {
Integer tempCount = proteinCount.get(protein);
if (tempCount != null && tempCount > proteinMax) {
proteinMax = tempCount;
}
}
for (int searchEngine2 : spectrumMatch.getAdvocates()) {
if (searchEngine1 != searchEngine2) {
boolean found = false;
ArrayList<Double> eValues2 = new ArrayList<Double>(spectrumMatch.getAllAssumptions(searchEngine2).keySet());
Collections.sort(eValues2);
for (double eValue2 : eValues2) {
for (SpectrumIdentificationAssumption assumption2 : spectrumMatch.getAllAssumptions(searchEngine2).get(eValue2)) {
if (assumption2 instanceof PeptideAssumption) {
PeptideAssumption peptideAssumption2 = (PeptideAssumption) assumption2;
if (peptideAssumption1.getPeptide().isSameSequenceAndModificationStatus(peptideAssumption2.getPeptide(),
sequenceMatchingPreferences)) {
PSParameter psParameter2 = (PSParameter) peptideAssumption2.getUrParam(psParameter);
p = p * psParameter2.getSearchEngineProbability();
nSE++;
found = true;
break;
}
}
}
if (found) {
break;
}
}
}
}
identifications.add(id);
if (!peptideAssumptions.containsKey(p)) {
peptideAssumptions.put(p, new HashMap<Integer, HashMap<Integer, HashMap<Double, HashMap<Double, ArrayList<PeptideAssumption>>>>>());
}
if (!peptideAssumptions.get(p).containsKey(proteinMax)) {
peptideAssumptions.get(p).put(proteinMax, new HashMap<Integer, HashMap<Double, HashMap<Double, ArrayList<PeptideAssumption>>>>());
}
if (!peptideAssumptions.get(p).get(proteinMax).containsKey(nSE)) {
ArrayList<PeptideAssumption> assumptions = new ArrayList<PeptideAssumption>();
assumptions.add(peptideAssumption1);
peptideAssumptions.get(p).get(proteinMax).put(nSE, new HashMap<Double, HashMap<Double, ArrayList<PeptideAssumption>>>());
peptideAssumptions.get(p).get(proteinMax).get(nSE).put(-1.0, new HashMap<Double, ArrayList<PeptideAssumption>>());
peptideAssumptions.get(p).get(proteinMax).get(nSE).get(-1.0).put(-1.0, assumptions);
} else {
HashMap<Ion.IonType, HashSet<Integer>> iontypes = annotationPreferences.getIonTypes();
NeutralLossesMap neutralLosses = annotationPreferences.getNeutralLosses();
ArrayList<Integer> charges = annotationPreferences.getValidatedCharges();
MSnSpectrum spectrum = (MSnSpectrum) spectrumFactory.getSpectrum(spectrumKey);
double mzTolerance = searchParameters.getFragmentIonAccuracy();
boolean isPpm = false; //@TODO change this as soon as search engine support fragment ion tolerance in ppm
if (peptideAssumptions.get(p).get(proteinMax).get(nSE).containsKey(-1.0)) {
ArrayList<PeptideAssumption> assumptions = peptideAssumptions.get(p).get(proteinMax).get(nSE).get(-1.0).get(-1.0);
PeptideAssumption tempAssumption = assumptions.get(0);
Peptide peptide = tempAssumption.getPeptide();
int precursorCharge = tempAssumption.getIdentificationCharge().value;
annotationPreferences.setCurrentSettings(tempAssumption, true, sequenceMatchingPreferences);
double nIons = spectrumAnnotator.getCoveredAminoAcids(iontypes, neutralLosses, charges, precursorCharge,
spectrum, peptide, 0, mzTolerance, isPpm, annotationPreferences.isHighResolutionAnnotation()).keySet().size();
double coverage = nIons / peptide.getSequence().length();
peptideAssumptions.get(p).get(proteinMax).get(nSE).put(coverage, new HashMap<Double, ArrayList<PeptideAssumption>>());
peptideAssumptions.get(p).get(proteinMax).get(nSE).get(coverage).put(-1.0, assumptions);
peptideAssumptions.get(p).get(proteinMax).get(nSE).remove(-1.0);
}
Peptide peptide = peptideAssumption1.getPeptide();
int precursorCharge = peptideAssumption1.getIdentificationCharge().value;
annotationPreferences.setCurrentSettings(peptideAssumption1, true, sequenceMatchingPreferences);
double nIons = spectrumAnnotator.getCoveredAminoAcids(iontypes, neutralLosses, charges, precursorCharge,
spectrum, peptide, 0, mzTolerance, isPpm, annotationPreferences.isHighResolutionAnnotation()).keySet().size();
double coverage = nIons / peptide.getSequence().length();
HashMap<Double, ArrayList<PeptideAssumption>> coverageMap = peptideAssumptions.get(p).get(proteinMax).get(nSE).get(coverage);
if (coverageMap == null) {