PSParameter peptidePSParameter = new PSParameter();
PSParameter secondaryPSParameter = new PSParameter();
int peptideCounter = 0;
HashMap<String, HashMap<Integer, String[]>> surroundingAAs = new HashMap<String, HashMap<Integer, String[]>>();
ProteinMatch proteinMatch = null;
ModificationProfile ptmProfile = peptideShakerGUI.getSearchParameters().getModificationProfile();
// @TODO: try to batch load the spectra? as this would speed up the export...
progressDialog.setTitle("Loading Peptide Matches. Please Wait...");
identification.loadPeptideMatches(progressDialog);
progressDialog.setTitle("Loading Peptide Details. Please Wait...");
identification.loadPeptideMatchParameters(peptidePSParameter, progressDialog);
progressDialog.setPrimaryProgressCounterIndeterminate(false);
progressDialog.setMaxPrimaryProgressCounter(peptideKeys.size());
progressDialog.setValue(0);
progressDialog.setTitle("Copying to File. Please Wait...");
for (String peptideKey : peptideKeys) {
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);
}