for (String accession : ProteinMatch.getAccessions(proteinSharedKey)) {
for (String proteinUniqueKey : identification.getProteinMap().get(accession)) {
if (ProteinMatch.contains(proteinSharedKey, proteinUniqueKey)) {
psParameter = (PSParameter) identification.getProteinMatchParameter(proteinUniqueKey, psParameter);
double uniqueProteinProbabilityScore = psParameter.getProteinProbabilityScore();
ProteinMatch proteinUnique = identification.getProteinMatch(proteinUniqueKey);
ProteinMatch proteinShared = identification.getProteinMatch(proteinSharedKey);
for (String sharedPeptideKey : proteinShared.getPeptideMatchesKeys()) {
proteinUnique.addPeptideMatchKey(sharedPeptideKey);
}
identification.updateProteinMatch(proteinUnique);
if (uniqueProteinProbabilityScore <= sharedProteinProbabilityScore) {
better = true;
}
}
}
}
if (better) {
toRemove.add(proteinSharedKey);
} else {
waitingHandler.increaseSecondaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
}
}
}
for (String proteinKey : toRemove) {
psParameter = (PSParameter) identification.getProteinMatchParameter(proteinKey, psParameter);
proteinMap.removePoint(psParameter.getProteinProbabilityScore(), ProteinMatch.isDecoy(proteinKey));
identification.removeProteinMatch(proteinKey);
waitingHandler.increaseSecondaryProgressCounter();
}
int nSolved = toRemove.size();
int nGroups = 0;
int nLeft = 0;
// As we go through all protein ids, keep the sorted list of proteins and maxima in the instance of the Metrics class to pass them to the GUI afterwards
// proteins are sorted 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>>>>();
PSParameter probabilities = new PSParameter();
double maxMW = 0;
identification.loadProteinMatches(null);
for (String proteinKey : identification.getProteinIdentification()) {
ProteinMatch proteinMatch = identification.getProteinMatch(proteinKey);
if (!ProteinMatch.isDecoy(proteinKey)) {
probabilities = (PSParameter) identification.getProteinMatchParameter(proteinKey, probabilities);
double score = probabilities.getProteinProbabilityScore();
int nPeptides = -proteinMatch.getPeptideMatchesKeys().size();
int nSpectra = 0;
Protein currentProtein = sequenceFactory.getProtein(proteinMatch.getMainMatch());
if (currentProtein != null) {
double mw = sequenceFactory.computeMolecularWeight(proteinMatch.getMainMatch());
if (mw > maxMW) {
maxMW = mw;
}
}
identification.loadPeptideMatches(proteinMatch.getPeptideMatchesKeys(), null);
for (String peptideKey : proteinMatch.getPeptideMatchesKeys()) {
PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
nSpectra -= peptideMatch.getSpectrumCount();
}
if (!orderMap.containsKey(score)) {
orderMap.put(score, new HashMap<Integer, HashMap<Integer, ArrayList<String>>>());
}
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);
// save the lenght of the longest protein accession number
if (proteinMatch.getMainMatch().length() > maxProteinKeyLength) {
maxProteinKeyLength = proteinMatch.getMainMatch().length();
}
}
ArrayList<String> accessions = new ArrayList<String>(Arrays.asList(ProteinMatch.getAccessions(proteinKey)));
Collections.sort(accessions);
String mainKey = accessions.get(0);
if (accessions.size() > 1) {
boolean similarityFound = false;
boolean allSimilar = false;
psParameter = (PSParameter) identification.getProteinMatchParameter(proteinKey, psParameter);
for (String accession : accessions) {
if (compareMainProtein(proteinMatch, mainKey, proteinMatch, accession, searchParameters, sequenceMatchingPreferences) > 0) {
mainKey = accession;
}
}
for (int i = 0; i < accessions.size() - 1; i++) {
for (int j = i + 1; j < accessions.size(); j++) {
if (getSimilarity(accessions.get(i), accessions.get(j))) {
similarityFound = true;
if (compareMainProtein(proteinMatch, mainKey, proteinMatch, accessions.get(j), searchParameters, sequenceMatchingPreferences) > 0) {
mainKey = accessions.get(i);
}
break;
}
}
if (similarityFound) {
break;
}
}
if (similarityFound) {
allSimilar = true;
for (String key : accessions) {
if (!mainKey.equals(key)) {
if (!getSimilarity(mainKey, key)) {
allSimilar = false;
break;
}
}
}
}
if (!similarityFound) {
psParameter.setProteinInferenceClass(PSParameter.UNRELATED);
nGroups++;
nLeft++;
identification.updateProteinMatchParameter(proteinKey, psParameter);
identification.loadPeptideMatchParameters(proteinMatch.getPeptideMatchesKeys(), psParameter, null);
for (String peptideKey : proteinMatch.getPeptideMatchesKeys()) {
psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
psParameter.setProteinInferenceClass(PSParameter.UNRELATED);
identification.updatePeptideMatchParameter(peptideKey, psParameter);
}
} else if (!allSimilar) {
psParameter.setProteinInferenceClass(PSParameter.RELATED_AND_UNRELATED);
nGroups++;
nSolved++;
identification.updateProteinMatchParameter(proteinKey, psParameter);
identification.loadPeptideMatchParameters(proteinMatch.getPeptideMatchesKeys(), psParameter, null);
for (String peptideKey : proteinMatch.getPeptideMatchesKeys()) {
psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
psParameter.setProteinInferenceClass(PSParameter.RELATED_AND_UNRELATED);
identification.updatePeptideMatchParameter(peptideKey, psParameter);
}
} else {
psParameter.setProteinInferenceClass(PSParameter.RELATED);
nGroups++;
nSolved++;
identification.updateProteinMatchParameter(proteinKey, psParameter);
String mainMatch = proteinMatch.getMainMatch();
identification.loadPeptideMatches(proteinMatch.getPeptideMatchesKeys(), null);
identification.loadPeptideMatchParameters(proteinMatch.getPeptideMatchesKeys(), psParameter, null);
for (String peptideKey : proteinMatch.getPeptideMatchesKeys()) {
psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
boolean unrelated = false;
for (String proteinAccession : peptideMatch.getTheoreticPeptide().getParentProteins(sequenceMatchingPreferences)) {
if (!proteinKey.contains(proteinAccession)) {
if (!getSimilarity(mainMatch, proteinAccession)) {
unrelated = true;
break;
}
}
}
if (unrelated) {
psParameter.setProteinInferenceClass(PSParameter.RELATED_AND_UNRELATED);
} else {
psParameter.setProteinInferenceClass(PSParameter.RELATED);
}
identification.updatePeptideMatchParameter(peptideKey, psParameter);
}
}
} else {
String mainMatch = proteinMatch.getMainMatch();
identification.loadPeptideMatches(proteinMatch.getPeptideMatchesKeys(), null);
identification.loadPeptideMatchParameters(proteinMatch.getPeptideMatchesKeys(), psParameter, null);
for (String peptideKey : proteinMatch.getPeptideMatchesKeys()) {
psParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, psParameter);
PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
boolean unrelated = false;
boolean otherProtein = false;
for (String protein : peptideMatch.getTheoreticPeptide().getParentProteins(sequenceMatchingPreferences)) {
if (!proteinKey.contains(protein)) {
otherProtein = true;
if (!getSimilarity(mainMatch, protein)) {
unrelated = true;
break;
}
}
}
if (otherProtein) {
psParameter.setProteinInferenceClass(PSParameter.RELATED);
}
if (unrelated) {
psParameter.setProteinInferenceClass(PSParameter.UNRELATED);
}
identification.updatePeptideMatchParameter(peptideKey, psParameter);
}
}
if (ProteinMatch.getNProteins(proteinKey) > 1) {
if (!proteinMatch.getMainMatch().equals(mainKey)) {
proteinMatch.setMainMatch(mainKey);
identification.updateProteinMatch(proteinMatch);
}
}
waitingHandler.increaseSecondaryProgressCounter();