// sort the proteins according to the protein score, then number of peptides (inverted), then number of spectra (inverted).
HashMap<Double, HashMap<Integer, HashMap<Integer, ArrayList<String>>>> orderMap
= new HashMap<Double, HashMap<Integer, HashMap<Integer, ArrayList<String>>>>();
ArrayList<Double> scores = new ArrayList<Double>();
PSParameter probabilities = new PSParameter();
int maxPeptides = 0, maxSpectra = 0;
double maxSpectrumCounting = 0, maxMW = 0;
int nValidatedProteins = 0;
int nConfidentProteins = 0;
for (String proteinKey : identification.getProteinIdentification()) {
if (!ProteinMatch.isDecoy(proteinKey)) {
probabilities = (PSParameter) identification.getProteinMatchParameter(proteinKey, probabilities);
if (!probabilities.isHidden()) {
ProteinMatch proteinMatch = identification.getProteinMatch(proteinKey);
double score = probabilities.getProteinProbabilityScore();
int nPeptides = -proteinMatch.getPeptideMatchesKeys().size();
int nSpectra = -getNSpectra(proteinKey);
if (needMaxValues) {
if (-nPeptides > maxPeptides) {
maxPeptides = -nPeptides;
}
if (-nSpectra > maxSpectra) {
maxSpectra = -nSpectra;
}
double tempSpectrumCounting = estimateSpectrumCounting(proteinKey);
if (tempSpectrumCounting > maxSpectrumCounting) {
maxSpectrumCounting = tempSpectrumCounting;
}
Protein currentProtein = sequenceFactory.getProtein(proteinMatch.getMainMatch());
if (currentProtein != null) {
double mw = sequenceFactory.computeMolecularWeight(proteinMatch.getMainMatch());
if (mw > maxMW) {
maxMW = mw;
}
}
if (probabilities.getMatchValidationLevel().isValidated()) {
nValidatedProteins++;
if (probabilities.getMatchValidationLevel() == MatchValidationLevel.confident) {
nConfidentProteins++;
}
}
}
if (!orderMap.containsKey(score)) {
orderMap.put(score, new HashMap<Integer, HashMap<Integer, ArrayList<String>>>());
scores.add(score);
}
if (!orderMap.get(score).containsKey(nPeptides)) {
orderMap.get(score).put(nPeptides, new HashMap<Integer, ArrayList<String>>());
}
if (!orderMap.get(score).get(nPeptides).containsKey(nSpectra)) {
orderMap.get(score).get(nPeptides).put(nSpectra, new ArrayList<String>());
}
orderMap.get(score).get(nPeptides).get(nSpectra).add(proteinKey);
}
}
if (waitingHandler != null) {
waitingHandler.increaseSecondaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return null;
}
}
}
if (needMaxValues) {
metrics.setMaxNPeptides(maxPeptides);
metrics.setMaxNSpectra(maxSpectra);
metrics.setMaxSpectrumCounting(maxSpectrumCounting);
metrics.setMaxMW(maxMW);
metrics.setnValidatedProteins(nValidatedProteins);
metrics.setnConfidentProteins(nConfidentProteins);
}
ArrayList<String> proteinList = new ArrayList<String>();
ArrayList<Double> scoreList = new ArrayList<Double>(orderMap.keySet());
Collections.sort(scoreList);
if (waitingHandler != null) {
waitingHandler.resetSecondaryProgressCounter();
waitingHandler.setWaitingText("Updating Protein Table. Please Wait...");
waitingHandler.setMaxSecondaryProgressCounter(identification.getProteinIdentification().size());
}
for (double currentScore : scoreList) {
ArrayList<Integer> nPeptideList = new ArrayList<Integer>(orderMap.get(currentScore).keySet());
Collections.sort(nPeptideList);
for (int currentNPeptides : nPeptideList) {
ArrayList<Integer> nPsmList = new ArrayList<Integer>(orderMap.get(currentScore).get(currentNPeptides).keySet());
Collections.sort(nPsmList);
for (int currentNPsms : nPsmList) {
ArrayList<String> tempList = orderMap.get(currentScore).get(currentNPeptides).get(currentNPsms);
Collections.sort(tempList);
proteinList.addAll(tempList);
if (waitingHandler != null) {
waitingHandler.setMaxSecondaryProgressCounter(tempList.size());
if (waitingHandler.isRunCanceled()) {
return null;
}
}
}
}
}
identificationFeaturesCache.setProteinList(proteinList);
if (waitingHandler != null) {
waitingHandler.setPrimaryProgressCounterIndeterminate(true);
if (waitingHandler.isRunCanceled()) {
return null;
}
}
}
if (hidingNeeded(filterPreferences) || identificationFeaturesCache.getProteinListAfterHiding() == null) {
ArrayList<String> proteinListAfterHiding = new ArrayList<String>();
ArrayList<String> validatedProteinList = new ArrayList<String>();
PSParameter psParameter = new PSParameter();
int nValidatedProteins = 0;
int nConfidentProteins = 0;
for (String proteinKey : identificationFeaturesCache.getProteinList()) {
if (!ProteinMatch.isDecoy(proteinKey)) {
psParameter = (PSParameter) identification.getProteinMatchParameter(proteinKey, psParameter);
if (!psParameter.isHidden()) {
proteinListAfterHiding.add(proteinKey);
if (psParameter.getMatchValidationLevel().isValidated()) {
nValidatedProteins++;
validatedProteinList.add(proteinKey);
if (psParameter.getMatchValidationLevel() == MatchValidationLevel.confident) {
nConfidentProteins++;
}
}
}
}