if (progressDialog.isRunCanceled()) {
break;
}
boolean shared = false;
PeptideMatch peptideMatch = identification.getPeptideMatch(peptideKey);
peptidePSParameter = (PSParameter) identification.getPeptideMatchParameter(peptideKey, peptidePSParameter);
if (!peptideMatch.getTheoreticPeptide().isDecoy(peptideShakerGUI.getSequenceMatchingPreferences()) || !onlyValidated) {
if ((onlyValidated && peptidePSParameter.getMatchValidationLevel().isValidated()) || !onlyValidated) {
if ((!includeHidden && !peptidePSParameter.isHidden()) || includeHidden) {
if ((onlyStarred && peptidePSParameter.isStarred()) || !onlyStarred) {
Peptide peptide = peptideMatch.getTheoreticPeptide();
ArrayList<String> possibleProteins = new ArrayList<String>();
ArrayList<String> orderedProteinsKeys = new ArrayList<String>(); // @TODO: could be merged with one of the other maps perhaps?
if (accession || proteinDescription || surroundings || location || uniqueOnly) {
if (proteinKey == null) {
for (String parentProtein : peptide.getParentProteins(peptideShakerGUI.getSequenceMatchingPreferences())) {
ArrayList<String> parentProteins = identification.getProteinMap().get(parentProtein);
if (parentProteins != null) {
for (String proteinKey : parentProteins) {
if (!possibleProteins.contains(proteinKey)) {
try {
proteinMatch = identification.getProteinMatch(proteinKey);
if (proteinMatch.getPeptideMatchesKeys().contains(peptideKey)) {
possibleProteins.add(proteinKey);
}
} catch (Exception e) {
// protein deleted due to protein inference issue and not deleted from the map in versions earlier than 0.14.6
System.out.println("Non-existing protein key in protein map: " + proteinKey);
e.printStackTrace();
}
}
}
}
}
shared = possibleProteins.size() > 1;
proteinMatch = identification.getProteinMatch(possibleProteins.get(0));
} else {
proteinMatch = identification.getProteinMatch(proteinKey);
}
}
if (shared && uniqueOnly) {
// these will be ignored as the user requested unique only
} else {
if (indexes) {
writer.write(++peptideCounter + SEPARATOR);
}
if (accession || proteinDescription) {
String mainMatch, secondaryProteins = "", peptideProteins = "";
String mainMatchDescription, secondaryProteinsDescriptions = "", peptideProteinDescriptions = "";
ArrayList<String> accessions = new ArrayList<String>();
mainMatch = proteinMatch.getMainMatch();
mainMatchDescription = sequenceFactory.getHeader(mainMatch).getSimpleProteinDescription();
boolean first = true;
if (!shared) {
orderedProteinsKeys.add(mainMatch);
}
accessions.addAll(proteinMatch.getTheoreticProteinsAccessions());
Collections.sort(accessions);
for (String key : accessions) {
if (!key.equals(mainMatch)) {
if (first) {
first = false;
} else {
secondaryProteins += "; ";
secondaryProteinsDescriptions += "; ";
}
secondaryProteins += key;
secondaryProteinsDescriptions += sequenceFactory.getHeader(key).getSimpleProteinDescription();
orderedProteinsKeys.add(key);
}
}
if (shared) {
mainMatch = "shared peptide";
mainMatchDescription = "shared peptide";
}
first = true;
ArrayList<String> peptideAccessions = new ArrayList<String>(peptide.getParentProteins(peptideShakerGUI.getSequenceMatchingPreferences()));
Collections.sort(peptideAccessions);
for (String key : peptideAccessions) {
if (shared || !accessions.contains(key)) {
if (first) {
first = false;
} else {
peptideProteins += "; ";
peptideProteinDescriptions += "; ";
}
peptideProteins += key;
peptideProteinDescriptions += sequenceFactory.getHeader(key).getSimpleProteinDescription();
orderedProteinsKeys.add(key);
}
}
if (accession) {
writer.write(mainMatch + SEPARATOR);
writer.write(secondaryProteins + SEPARATOR);
writer.write(peptideProteins + SEPARATOR);
}
if (proteinDescription) {
writer.write(mainMatchDescription + SEPARATOR);
writer.write(secondaryProteinsDescriptions + SEPARATOR);
writer.write(peptideProteinDescriptions + SEPARATOR);
}
}
if (proteinInferenceType) {
writer.write(peptidePSParameter.getProteinInferenceClassAsString() + SEPARATOR);
}
if (location || surroundings) {
for (String proteinAccession : orderedProteinsKeys) {
surroundingAAs.put(proteinAccession,
sequenceFactory.getProtein(proteinAccession).getSurroundingAA(peptide.getSequence(),
peptideShakerGUI.getDisplayPreferences().getnAASurroundingPeptides(),
peptideShakerGUI.getSequenceMatchingPreferences()));
}
}
if (surroundings) {
String subSequence = "";
for (String proteinAccession : orderedProteinsKeys) {
ArrayList<Integer> starts = new ArrayList<Integer>(surroundingAAs.get(proteinAccession).keySet());
Collections.sort(starts);
boolean first = true;
for (int start : starts) {
if (first) {
first = false;
} else {
subSequence += ", ";
}
subSequence += surroundingAAs.get(proteinAccession).get(start)[0];
}
subSequence += "; ";
}
subSequence = subSequence.substring(0, subSequence.length() - 1);
writer.write(subSequence + SEPARATOR);
}
if (sequence) {
writer.write(peptide.getSequence() + SEPARATOR);
writer.write(peptide.getTaggedModifiedSequence(peptideShakerGUI.getSearchParameters().getModificationProfile(),
false, false, true) + SEPARATOR);
}
if (surroundings) {
String subSequence = "";
for (String proteinAccession : orderedProteinsKeys) {
ArrayList<Integer> starts = new ArrayList<Integer>(surroundingAAs.get(proteinAccession).keySet());
Collections.sort(starts);
boolean first = true;
for (int start : starts) {
if (first) {
first = false;
} else {
subSequence += ", ";
}
subSequence += surroundingAAs.get(proteinAccession).get(start)[1];
}
subSequence += "; ";
}
subSequence = subSequence.substring(0, subSequence.length() - 1);
writer.write(subSequence + SEPARATOR);
}
if (enzymatic) {
boolean isEnzymatic = sequenceFactory.getProtein(proteinMatch.getMainMatch()).isEnzymaticPeptide(peptide.getSequence(),
peptideShakerGUI.getSearchParameters().getEnzyme(), peptideShakerGUI.getSequenceMatchingPreferences());
writer.write(isEnzymatic + SEPARATOR);
}
if (location) {
String start = "";
String end = "";
for (String proteinAccession : orderedProteinsKeys) {
int endAA;
String sequence = peptide.getSequence();
ArrayList<Integer> starts = new ArrayList<Integer>(surroundingAAs.get(proteinAccession).keySet());
Collections.sort(starts);
boolean first = true;
for (int startAa : starts) {
if (first) {
first = false;
} else {
start += ", ";
end += ", ";
}
start += startAa;
endAA = startAa + sequence.length();
end += endAA;
}
start += "; ";
end += "; ";
}
start = start.substring(0, start.length() - 2);
end = end.substring(0, end.length() - 2);
writer.write(start + SEPARATOR + end + SEPARATOR);
}
if (modifications) {
writer.write(getPeptideModificationsAsString(peptide, false));
writer.write(SEPARATOR);
}
if (modifications) {
writer.write(getPeptideModificationsAsString(peptide, true));
writer.write(SEPARATOR);
}
if (ptmLocations) {
writer.write(getPeptideModificationLocations(peptide, peptideMatch, ptmProfile));
writer.write(SEPARATOR);
}
if (charges) {
writer.write(getPeptidePrecursorChargesAsString(peptideMatch));
writer.write(SEPARATOR);
}
if (nSpectra) {
int cpt = 0;
// @TODO: replace with: peptideShakerGUI.getIdentificationFeaturesGenerator().getNValidatedSpectraForPeptide(peptideKey);?
identification.loadSpectrumMatchParameters(peptideMatch.getSpectrumMatches(), secondaryPSParameter, null);
for (String spectrumKey : peptideMatch.getSpectrumMatches()) {
secondaryPSParameter = (PSParameter) identification.getSpectrumMatchParameter(spectrumKey, secondaryPSParameter);
if (secondaryPSParameter.getMatchValidationLevel().isValidated()) {
cpt++;
}
}
writer.write(cpt + SEPARATOR);
}
if (peptidePdbArray != null) {
writer.write(peptidePdbArray.contains(peptideKey) + SEPARATOR);
}
if (score) {
writer.write(peptidePSParameter.getPeptideScore() + SEPARATOR);
}
if (confidence) {
writer.write(peptidePSParameter.getPeptideConfidence() + SEPARATOR);
}
if (!onlyValidated) {
MatchValidationLevel matchValidationLevel = peptidePSParameter.getMatchValidationLevel();
writer.write(matchValidationLevel.toString());
if (matchValidationLevel == MatchValidationLevel.doubtful && !peptidePSParameter.getReasonDoubtful().equals("")) {
writer.write(" (" + peptidePSParameter.getReasonDoubtful() + ")");
}
writer.write(SEPARATOR);
if (peptideMatch.getTheoreticPeptide().isDecoy(peptideShakerGUI.getSequenceMatchingPreferences())) {
writer.write(1 + SEPARATOR);
} else {
writer.write(0 + SEPARATOR);
}
}