use of com.compomics.util.gui.DummyFrame in project peptide-shaker by compomics.
the class PeptideShakerCLI method call.
@Override
public Object call() {
try {
// set up the waiting handler
if (cliInputBean.isGUI()) {
// set the look and feel
try {
UtilitiesGUIDefaults.setLookAndFeel();
} catch (Exception e) {
// ignore, use default look and feel
}
ArrayList<String> tips;
try {
tips = Tips.getTips();
} catch (Exception e) {
tips = new ArrayList<>();
// do something here?
}
waitingHandler = new WaitingDialog(new DummyFrame("PeptideShaker " + PeptideShaker.getVersion(), "/icons/peptide-shaker.gif"), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), false, tips, "Importing Data", "PeptideShaker", PeptideShaker.getVersion(), true);
((WaitingDialog) waitingHandler).setCloseDialogWhenImportCompletes(false, false);
((WaitingDialog) waitingHandler).setLocationRelativeTo(null);
Point tempLocation = ((WaitingDialog) waitingHandler).getLocation();
((WaitingDialog) waitingHandler).setLocation((int) tempLocation.getX() + 30, (int) tempLocation.getY() + 30);
new Thread(new Runnable() {
public void run() {
try {
((WaitingDialog) waitingHandler).setVisible(true);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}, "ProgressDialog").start();
} else {
waitingHandler = new WaitingHandlerCLIImpl();
}
// @TODO: improve the primary progress display?
int progressCounter = cliInputBean.getIdFiles().size() + cliInputBean.getSpectrumFiles().size();
// establishing the database connection
progressCounter++;
// the FASTA file
progressCounter++;
// the peptide to protein map
progressCounter++;
// computing probabilities etc
progressCounter += 6;
// simplify protein groups
progressCounter++;
// resolving protein inference
progressCounter++;
// correcting protein probabilities, Validating identifications at 1% FDR, Scoring PTMs in peptides, Scoring PTMs in proteins.
progressCounter += 4;
// scoring PTMs in PSMs. Estimating PTM FLR.
progressCounter += 2;
// peptide inference
progressCounter++;
// project zipping
if (cliInputBean.getZipExport() != null) {
progressCounter++;
}
// add one more just to not start at 0%
progressCounter++;
waitingHandler.setMaxPrimaryProgressCounter(progressCounter);
// just to not start at 0%
waitingHandler.increasePrimaryProgressCounter();
// turn off illegal access log messages
try {
Class loggerClass = Class.forName("jdk.internal.module.IllegalAccessLogger");
Field loggerField = loggerClass.getDeclaredField("logger");
Class unsafeClass = Class.forName("sun.misc.Unsafe");
Field unsafeField = unsafeClass.getDeclaredField("theUnsafe");
unsafeField.setAccessible(true);
Object unsafe = unsafeField.get(null);
Long offset = (Long) unsafeClass.getMethod("staticFieldOffset", Field.class).invoke(unsafe, loggerField);
//
unsafeClass.getMethod("putObjectVolatile", Object.class, long.class, Object.class).invoke(unsafe, loggerClass, offset, null);
} catch (Throwable ex) {
// ignore, i.e. simply show the warnings...
// ex.printStackTrace();
}
// turn off the zoodb logging
LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
ch.qos.logback.classic.Logger logger = loggerContext.getLogger("org.zoodb");
logger.setLevel(Level.toLevel("ERROR"));
setDbFolder(PeptideShaker.getMatchesFolder());
// Load user parameters
utilitiesUserParameters = UtilitiesUserParameters.loadUserParameters();
// Instantiate factories
PeptideShaker.instantiateFacories(utilitiesUserParameters);
modificationFactory = ModificationFactory.getInstance();
enzymeFactory = EnzymeFactory.getInstance();
// Load resources files
loadSpecies();
// Set the gene mappings
ProteinGeneDetailsProvider geneFactory = new ProteinGeneDetailsProvider();
geneFactory.initialize(PeptideShaker.getJarFilePath());
// Load the species mapping
try {
SpeciesFactory speciesFactory = SpeciesFactory.getInstance();
speciesFactory.initiate(PeptideShaker.getJarFilePath());
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while loading the " + "species mapping. Gene annotation might be impaired. " + getLogFileMessage(), true, true);
e.printStackTrace();
}
// create project
try {
createProject();
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while creating the " + "PeptideShaker project. " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
// see if the project was created or canceled
if (waitingHandler.isRunCanceled()) {
try {
closePeptideShaker(identification);
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while closing PeptideShaker. " + getLogFileMessage(), true, true);
e.printStackTrace();
}
System.exit(1);
return 1;
} else {
waitingHandler.appendReport("Project successfully created.", true, true);
waitingHandler.increasePrimaryProgressCounter();
}
// save project
if (cliInputBean.getOutput() != null) {
try {
psdbFile = cliInputBean.getOutput();
waitingHandler.appendReport("Saving results.", true, true);
saveProject(waitingHandler, true);
waitingHandler.appendReport("Results saved to " + psdbFile.getAbsolutePath() + ".", true, true);
waitingHandler.appendReportEndLine();
} catch (Exception e) {
waitingHandler.appendReport("An exception occurred while saving the project. " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
waitingHandler.increasePrimaryProgressCounter();
}
// finished
waitingHandler.setPrimaryProgressCounterIndeterminate(false);
waitingHandler.setSecondaryProgressCounterIndeterminate(false);
// follow up tasks if needed
FollowUpCLIInputBean followUpCLIInputBean = cliInputBean.getFollowUpCLIInputBean();
// array to be filled with all exported follow-up reports
ArrayList<File> followupAnalysisFiles = new ArrayList<File>();
if (followUpCLIInputBean.followUpNeeded()) {
waitingHandler.appendReport("Starting follow up tasks.", true, true);
// recalibrate spectra
if (followUpCLIInputBean.recalibrationNeeded()) {
waitingHandler.appendReport("Spectrum recalibration.", true, true);
try {
followupAnalysisFiles.addAll(CLIExportMethods.recalibrateSpectra(followUpCLIInputBean, identification, sequenceProvider, msFileHandler, identificationParameters, waitingHandler));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while recalibrating the spectra. " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
// export spectra
if (followUpCLIInputBean.spectrumExportNeeded()) {
waitingHandler.appendReport("Spectrum export.", true, true);
try {
followupAnalysisFiles.addAll(CLIExportMethods.exportSpectra(followUpCLIInputBean, identification, msFileHandler, waitingHandler, identificationParameters.getSequenceMatchingParameters()));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while exporting the spectra. " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
// export protein accessions
if (followUpCLIInputBean.accessionExportNeeded()) {
waitingHandler.appendReport("Protein accession export.", true, true);
try {
followupAnalysisFiles.add(CLIExportMethods.exportAccessions(followUpCLIInputBean, identification, sequenceProvider, waitingHandler, filterParameters));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while exporting the protein accessions. " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
// export protein details
if (followUpCLIInputBean.proteinSequencesExportNeeded()) {
waitingHandler.appendReport("Protein sequences export.", true, true);
try {
followupAnalysisFiles.add(CLIExportMethods.exportProteinSequences(followUpCLIInputBean, identification, sequenceProvider, waitingHandler, filterParameters));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while exporting the protein details. " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
// progenesis export
if (followUpCLIInputBean.progenesisExportNeeded()) {
waitingHandler.appendReport("Progenesis export.", true, true);
try {
followupAnalysisFiles.add(CLIExportMethods.exportProgenesis(followUpCLIInputBean, identification, waitingHandler, sequenceProvider, proteinDetailsProvider, identificationParameters.getSequenceMatchingParameters()));
waitingHandler.appendReport("Progenesis export completed.", true, true);
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while exporting the Progenesis file. " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
// inclusion list export
if (followUpCLIInputBean.inclusionListNeeded()) {
waitingHandler.appendReport("Inclusion list export.", true, true);
try {
followupAnalysisFiles.add(CLIExportMethods.exportInclusionList(followUpCLIInputBean, identification, identificationFeaturesGenerator, msFileHandler, identificationParameters.getSearchParameters(), waitingHandler, filterParameters));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while generating the inclusion list.", true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
// proteoforms export
if (followUpCLIInputBean.proteoformsNeeded()) {
waitingHandler.appendReport("Proteoform export.", true, true);
try {
followupAnalysisFiles.add(CLIExportMethods.exportProteoforms(followUpCLIInputBean, identification, waitingHandler));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while generating the proteoforms list.", true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
// DeepLC export
if (followUpCLIInputBean.deepLcExportNeeded()) {
waitingHandler.appendReport("DeepLC export.", true, true);
try {
followupAnalysisFiles.addAll(CLIExportMethods.exportDeepLC(followUpCLIInputBean, identification, identificationParameters.getSearchParameters().getModificationParameters(), identificationParameters.getSequenceMatchingParameters(), sequenceProvider, msFileHandler, waitingHandler));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while generating the proteoforms list.", true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
// ms2pip export
if (followUpCLIInputBean.ms2pipExportNeeded()) {
waitingHandler.appendReport("ms2pip export.", true, true);
try {
followupAnalysisFiles.addAll(CLIExportMethods.exportMs2pip(followUpCLIInputBean, identification, identificationParameters.getSearchParameters(), identificationParameters.getSequenceMatchingParameters(), sequenceProvider, msFileHandler, waitingHandler));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while generating the proteoforms list.", true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
}
// report export if needed
ReportCLIInputBean reportCLIInputBean = cliInputBean.getReportCLIInputBean();
// array to be filled with all exported reports
ArrayList<File> reportFiles = new ArrayList<File>();
if (reportCLIInputBean.exportNeeded()) {
// see if output folder is set, and if not set to the same folder as the psdb file
boolean reportOutputFolderSet = reportCLIInputBean.getReportOutputFolder() != null;
if (!reportOutputFolderSet) {
if (cliInputBean.getOutput() == null) {
// @TODO: ideally this test should be done before starting the processing of the data!
waitingHandler.appendReport("Report output folder not set. Please use -out_reports (or the more general -out option). Processing canceled.", true, true);
System.err.println("Report output folder not set. Please use -out_reports (or the more general -out option). Processing canceled.");
waitingHandler.setRunCanceled();
} else {
reportCLIInputBean.setReportOutputFolder(cliInputBean.getOutput().getParentFile());
reportOutputFolderSet = true;
}
}
if (reportOutputFolderSet) {
waitingHandler.appendReport("Exporting reports.", true, true);
// Export report(s)
if (reportCLIInputBean.exportNeeded()) {
// @TODO: this shall not be hard coded //peptideShakerGUI.getDisplayPreferences().getnAASurroundingPeptides()
int nSurroundingAAs = 2;
for (String reportType : reportCLIInputBean.getReportTypes()) {
waitingHandler.appendReport("Exporting " + reportType + ".", true, true);
try {
reportFiles.add(CLIExportMethods.exportReport(reportCLIInputBean, reportType, projectParameters.getProjectUniqueName(), projectDetails, identification, geneMaps, identificationFeaturesGenerator, identificationParameters, sequenceProvider, proteinDetailsProvider, msFileHandler, nSurroundingAAs, spectrumCountingParameters, waitingHandler));
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while exporting the " + reportType + ". " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
}
// export documentation
if (reportCLIInputBean.documentationExportNeeded()) {
waitingHandler.appendReport("Exporting report documentation.", true, true);
for (String reportType : reportCLIInputBean.getReportTypes()) {
try {
CLIExportMethods.exportDocumentation(reportCLIInputBean, reportType, waitingHandler);
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while exporting the documentation for " + reportType + ". " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
}
}
}
}
}
// export as mzid
MzidCLIInputBean mzidCLIInputBean = cliInputBean.getMzidCLIInputBean();
File mzidFile = mzidCLIInputBean.getOutputFile();
if (mzidFile != null) {
waitingHandler.appendReportEndLine();
waitingHandler.appendReport("Exporting project as mzIdentML.", true, true);
// export mzid file
// make sure that all annotations are included
double currentIntensityLimit = this.getIdentificationParameters().getAnnotationParameters().getAnnotationIntensityLimit();
this.getIdentificationParameters().getAnnotationParameters().setIntensityLimit(0.0);
try {
CLIExportMethods.exportMzId(mzidCLIInputBean, this, waitingHandler);
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while generating the mzid file. " + getLogFileMessage(), true, true);
e.printStackTrace();
waitingHandler.setRunCanceled();
} finally {
// reset the annotation level
this.getIdentificationParameters().getAnnotationParameters().setIntensityLimit(currentIntensityLimit);
}
}
// export project as zip
File zipFile = cliInputBean.getZipExport();
if (zipFile != null) {
waitingHandler.appendReportEndLine();
waitingHandler.appendReport("Zipping project.", true, true);
File parent = zipFile.getParentFile();
try {
parent.mkdirs();
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while creating folder " + parent.getAbsolutePath() + ". " + getLogFileMessage(), true, true);
waitingHandler.setRunCanceled();
}
ArrayList<File> spectrumFiles = new ArrayList<>();
for (String spectrumFileName : getIdentification().getFractions()) {
File spectrumFile = new File(msFileHandler.getFilePaths().get(spectrumFileName));
spectrumFiles.add(spectrumFile);
}
File fastaFile = new File(projectDetails.getFastaFile());
try {
ProjectExport.exportProjectAsZip(zipFile, fastaFile, msFileHandler, followupAnalysisFiles, reportFiles, mzidFile, psdbFile, true, waitingHandler);
final int NUMBER_OF_BYTES_PER_MEGABYTE = 1048576;
double sizeOfZippedFile = Util.roundDouble(((double) zipFile.length() / NUMBER_OF_BYTES_PER_MEGABYTE), 2);
waitingHandler.appendReport("Project zipped to \'" + zipFile.getAbsolutePath() + "\' (" + sizeOfZippedFile + " MB)", true, true);
// export mgf file(s) out of the zip file
boolean mgfExport = cliInputBean.getMgfExport();
if (mgfExport) {
waitingHandler.appendReportEndLine();
waitingHandler.appendReport("Writing mgf file(s) to output folder.", true, true);
int i = 0;
for (String spectrumFileName : msFileHandler.getCmsFilePaths().keySet()) {
if (waitingHandler.isRunCanceled()) {
break;
}
waitingHandler.appendReport("Writing: " + IoUtil.removeExtension(spectrumFileName) + ".mgf" + " (" + (i + 1) + "/" + getIdentification().getFractions().size() + ")", true, true);
File mgfFile = new File(parent, IoUtil.removeExtension(spectrumFileName) + ".mgf");
MsFileExporter.writeMgfFile(msFileHandler, spectrumFileName, mgfFile, waitingHandler);
// writing the index too
MgfIndex mgfIndex = IndexedMgfReader.getMgfIndex(mgfFile, waitingHandler);
File indexFile = new File(parent, IoUtil.removeExtension(mgfIndex.getFileName()) + ".cui");
SerializationUtils.writeObject(mgfIndex, indexFile);
i++;
}
waitingHandler.appendReport("Written mgf file(s) to output folder.", true, true);
}
waitingHandler.increasePrimaryProgressCounter();
} catch (IOException e) {
e.printStackTrace();
waitingHandler.appendReport("An error occurred while attempting to zip project in " + zipFile.getAbsolutePath() + ". " + getLogFileMessage(), true, true);
waitingHandler.setRunCanceled();
}
}
waitingHandler.appendReportEndLine();
try {
closePeptideShaker(identification);
} catch (Exception e) {
waitingHandler.appendReport("An error occurred while closing PeptideShaker. " + getLogFileMessage(), true, true);
e.printStackTrace();
}
saveReport();
} catch (Exception e) {
e.printStackTrace();
if (waitingHandler != null) {
waitingHandler.appendReport("PeptideShaker processing failed. " + getLogFileMessage(), true, true);
saveReport();
waitingHandler.setRunCanceled();
}
}
if (waitingHandler != null && !waitingHandler.isRunCanceled()) {
waitingHandler.appendReport("PeptideShaker process completed.", true, true);
waitingHandler.setSecondaryProgressText("Processing Completed.");
// @TODO: Find other ways of cancelling the process? If not cancelled searchgui will not stop.
System.exit(0);
// Note that if a different solution is found, the DummyFrame has to be closed similar to the setVisible method in the WelcomeDialog!!
return 0;
} else {
System.out.println("PeptideShaker process failed! " + getLogFileMessage());
// @TODO: Find other ways of cancelling the process? If not cancelled searchgui will not stop.
System.exit(1);
// Note that if a different solution is found, the DummyFrame has to be closed similar to the setVisible method in the WelcomeDialog!!
return 1;
}
}
Aggregations