@Override
public void run() {
try {
// set up the identification parameters
SearchParameters prideSearchParameters = new SearchParameters();
// set the database
prideSearchParameters.setFastaFile(new File(database));
// default settings to be used, set the enzyme to trypsin
if (searchSettingsProjectFile == null) {
prideSearchParameters.setEnzyme(EnzymeFactory.getUtilitiesEnzyme("Trypsin"));
}
String prideSearchParametersReport = null;
ArrayList<File> mgfFiles = new ArrayList<File>();
boolean mgfConversionOk = true;
Boolean useLocalFiles = null;
for (int i = 0; i < allFiles.size() && mgfConversionOk; i++) {
String currentFile = allFiles.get(i);
String currentFileName = currentFile.substring(currentFile.lastIndexOf("/")).toLowerCase();
boolean unzipped = true;
if (currentFileName.lastIndexOf(".gz") != -1) {
currentFileName = currentFileName.substring(0, currentFileName.lastIndexOf(".gz"));
unzipped = false;
}
if (progressDialog.isRunCanceled()) {
progressDialog.setRunFinished();
PrideReshakeGUI.this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")));
return;
}
progressDialog.setTitle("Downloading Files (" + (i + 1) + "/" + allFiles.size() + "). Please Wait...");
try {
currentPrideDataFileUrl = new URL(currentFile);
currentZippedPrideDataFile = new File(outputFolder, currentFile.substring(currentFile.lastIndexOf("/")));
if (unzipped) {
currentPrideDataFile = new File(outputFolder, currentFile.substring(currentFile.lastIndexOf("/")));
if (i < selectedSpectrumFiles.size()) {
if (currentFile.toLowerCase().endsWith(".mgf")) {
currentMgfFile = new File(outputFolder, currentFile.substring(currentFile.lastIndexOf("/")));
} else {
currentMgfFile = new File(outputFolder, currentFile.substring(currentFile.lastIndexOf("/"), currentFile.lastIndexOf(".xml")) + ".mgf");
}
}
} else {
currentPrideDataFile = new File(outputFolder, currentFile.substring(currentFile.lastIndexOf("/"), currentFile.lastIndexOf(".gz")));
if (i < selectedSpectrumFiles.size()) {
if (currentFile.toLowerCase().endsWith(".mgf.gz")) {
currentMgfFile = new File(outputFolder, currentFile.substring(currentFile.lastIndexOf("/"), currentFile.lastIndexOf(".mgf.gz")) + ".mgf");
} else {
currentMgfFile = new File(outputFolder, currentFile.substring(currentFile.lastIndexOf("/"), currentFile.lastIndexOf(".xml.gz")) + ".mgf");
}
}
}
if (i < selectedSpectrumFiles.size()) {
mgfFiles.add(currentMgfFile);
}
} catch (MalformedURLException ex) {
JOptionPane.showMessageDialog(PrideReshakeGUI.this, JOptionEditorPane.getJOptionEditorPane("The file could not be downloaded:<br>"
+ ex.getMessage() + ".<br>"
+ "Please <a href=\"http://code.google.com/p/peptide-shaker/issues/list\">contact the developers</a>."),
"Download Error", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
currentPrideDataFileUrl = null;
} catch (IOException ex) {
JOptionPane.showMessageDialog(PrideReshakeGUI.this, JOptionEditorPane.getJOptionEditorPane("The file could not be downloaded:<br>"
+ ex.getMessage() + ".<br>"
+ "Please <a href=\"http://code.google.com/p/peptide-shaker/issues/list\">contact the developers</a>."),
"Download Error", JOptionPane.ERROR_MESSAGE);
ex.printStackTrace();
currentPrideDataFileUrl = null;
}
if (progressDialog.isRunCanceled()) {
progressDialog.setRunFinished();
PrideReshakeGUI.this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")));
return;
}
if (currentPrideDataFileUrl != null) {
if (!new File(peptideShakerGUI.getUtilitiesUserPreferences().getLocalPrideFolder(), currentFileName).exists()) {
boolean downloadFile = true;
if (currentPrideDataFile.exists()) {
if (useLocalFiles == null) {
int option = JOptionPane.showConfirmDialog(PrideReshakeGUI.this,
"The file \'" + currentPrideDataFile.getName() + "\' already exists locally.\nUse local copy?",
"Use Local File?", JOptionPane.YES_NO_OPTION);
if (allFiles.size() > 1) {
int option2 = JOptionPane.showConfirmDialog(PrideReshakeGUI.this,
"Do this for all following files?",
"Use Local Files?", JOptionPane.YES_NO_OPTION);
if (option2 == JOptionPane.YES_OPTION) {
useLocalFiles = (option == JOptionPane.YES_OPTION);
}
}
downloadFile = (option == JOptionPane.NO_OPTION);
} else {
downloadFile = !useLocalFiles;
}
}
if (downloadFile) {
// download the pride data file
saveUrl(currentZippedPrideDataFile, currentFile, fileSizes.get(i), progressDialog);
// file downloaded, unzip file
progressDialog.setTitle("Unzipping Files (" + (i + 1) + "/" + allFiles.size() + "). Please Wait...");
progressDialog.setPrimaryProgressCounterIndeterminate(true);
if (!unzipped) {
unzipProject();
}
}
} else {
currentPrideDataFile = new File(peptideShakerGUI.getUtilitiesUserPreferences().getLocalPrideFolder(), currentFileName);
}
if (progressDialog.isRunCanceled()) {
progressDialog.setRunFinished();
PrideReshakeGUI.this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")));
return;
}
// file unzipped, time to start the conversion to mgf
if (i < selectedSpectrumFiles.size()) {
if (currentFile.toLowerCase().endsWith(".mgf")
|| currentFile.toLowerCase().endsWith(".mgf.gz")) {
// already mgf, no conversion needed
} else {
progressDialog.setTitle("Converting Spectrum Data (" + (i + 1) + "/" + allFiles.size() + "). Please Wait...");
mgfConversionOk = convertPrideXmlToMgf();
}
}
if (progressDialog.isRunCanceled()) {
progressDialog.setRunFinished();
PrideReshakeGUI.this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")));
return;
}
// get the search params from the pride xml or mzid file
if (mgfConversionOk) {
if (searchSettingsProjectFile != null
&& currentFile.equalsIgnoreCase(searchSettingsProjectFile)) {
progressDialog.setTitle("Extracting Search Settings. Please Wait...");
if (currentFile.toLowerCase().endsWith(".xml")
|| currentFile.toLowerCase().endsWith(".xml.gz")) {
prideSearchParametersReport = getSearchParams(prideSearchParameters);
} else { // mzid
progressDialog.setPrimaryProgressCounterIndeterminate(true); // @TODO: better display of progress
// convert the parameters from the assay
prideSearchParametersReport = MzIdentMLIdfileSearchParametersConverter.getSearchParameters(currentPrideDataFile, prideSearchParameters, currentSpecies, progressDialog);
// add the ptms from the project/assay
String allPtms;
if (assaysTable.getSelectedRow() != -1) {
allPtms = (String) assaysTable.getValueAt(assaysTable.getSelectedRow(), assaysTable.getColumn("PTMs").getModelIndex());
} else {
allPtms = (String) projectsTable.getValueAt(projectsTable.getSelectedRow(), projectsTable.getColumn("PTMs").getModelIndex());
}
prideSearchParametersReport += convertPtms(allPtms, prideSearchParameters.getModificationProfile());
// save the report to disk
File searchSettingsReportFile = new File(outputFolder, "search_settings_report.html");
String tempReport = "<html>" + prideSearchParametersReport;
tempReport += "<br></html>";
FileWriter fw = new FileWriter(searchSettingsReportFile);
BufferedWriter bw = new BufferedWriter(fw);
bw.write(tempReport);
bw.close();
fw.close();
prideSearchParametersReport += "<br><br>Report saved to <a href=\"" + searchSettingsReportFile.getAbsolutePath() + "\">" + searchSettingsReportFile.getAbsolutePath() + "</a><br>";
prideSearchParametersReport += "<br></html>";
prideSearchParametersReport = "<html>" + prideSearchParametersReport;
}
}
}
} else {
mgfConversionOk = false;
}
}
if (mgfConversionOk) {
// save the search params
prideSearchParameters.setParametersFile(new File(outputFolder, "pride.parameters"));
SearchParameters.saveIdentificationParameters(prideSearchParameters, new File(outputFolder, "pride.parameters"));
}
progressDialog.setRunFinished();
PrideReshakeGUI.this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")));