use of eu.isas.peptideshaker.preferences.ProjectDetails in project peptide-shaker by compomics.
the class PeptideShakerGUI method importPeptideShakerFile.
/**
* Imports information from a PeptideShaker file.
*
* @param psFile The PeptideShaker file to import.
* @param importFromZip flag that determines if psdb was imported from a zip
* file
*/
public void importPeptideShakerFile(File psFile, boolean importFromZip) {
psdbParent.setPsdbFile(psFile);
psdbParent.setPsdbImportFromZip(importFromZip);
// needed due to threading issues
final PeptideShakerGUI peptideShakerGUI = this;
progressDialog = new ProgressDialogX(this, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
progressDialog.setPrimaryProgressCounterIndeterminate(true);
progressDialog.setTitle("Importing Project. Please Wait...");
// reset the title
resetFrameTitle();
new Thread(new Runnable() {
public void run() {
try {
progressDialog.setVisible(true);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}, "ProgressDialog").start();
new Thread("ImportThread") {
@Override
public void run() {
try {
// reset enzymes, modifications and parameters
resetModificationFactory();
setDefaultParameters();
setCurentNotes(new ArrayList<String>(0));
updateNotesNotificationCounter();
openingExistingProject = true;
psdbParent.loadPsdbFile(PeptideShaker.getMatchesFolder(), progressDialog, psdbParent.getPsdbImportFromZip());
// load project specific PTMs
String error = PeptideShaker.loadModifications(getIdentificationParameters().getSearchParameters());
if (error != null) {
JOptionPane.showMessageDialog(peptideShakerGUI, error, "Modification Definition Changed", JOptionPane.WARNING_MESSAGE);
}
// resets the display features generator according to the new project
resetDisplayFeaturesGenerator();
if (progressDialog.isRunCanceled()) {
clearData(true, true);
clearParameters();
progressDialog.setRunFinished();
openingExistingProject = false;
return;
}
progressDialog.setTitle("Loading FASTA File. Please Wait...");
boolean fileFound = true;
try {
FastaSummary fastaSummary = psdbParent.loadFastaFile(progressDialog);
if (fastaSummary == null) {
fileFound = false;
}
} catch (IOException e) {
fileFound = false;
}
if (!fileFound && !locateFastaFileManually()) {
String fastaFilePath = getProjectDetails().getFastaFile();
JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while reading:\n" + fastaFilePath + "." + "\n\nFile not found.", "File Input Error", JOptionPane.ERROR_MESSAGE);
clearData(true, true);
clearParameters();
progressDialog.setRunFinished();
openingExistingProject = false;
return;
}
if (progressDialog.isRunCanceled()) {
clearData(true, true);
clearParameters();
progressDialog.setRunFinished();
openingExistingProject = false;
return;
}
progressDialog.setTitle("Loading Spectrum Files. Please Wait...");
progressDialog.resetPrimaryProgressCounter();
progressDialog.setMaxPrimaryProgressCounter(getIdentification().getSpectrumIdentification().size() + 1);
progressDialog.increasePrimaryProgressCounter();
ProjectDetails projectParameters = psdbParent.getProjectDetails();
Set<String> fileNames = getProjectDetails().getSpectrumFileNames();
ArrayList<File> spectrumFiles = fileNames.stream().map(projectParameters::getSpectrumFilePath).map(path -> new File(path)).collect(Collectors.toCollection(ArrayList::new));
int cpt = 0, total = fileNames.size();
for (String spectrumFileName : getIdentification().getFractions()) {
progressDialog.setTitle("Loading Spectrum Files (" + ++cpt + " of " + total + "). Please Wait...");
progressDialog.increasePrimaryProgressCounter();
boolean found;
try {
found = psdbParent.loadSpectrumFile(spectrumFileName, spectrumFiles, progressDialog);
} catch (Exception e) {
found = false;
}
if (!found) {
JOptionPane.showMessageDialog(peptideShakerGUI, "Spectrum file not found: \'" + spectrumFileName + "\'." + "\nPlease select the spectrum file or the folder containing it manually.", "File Not Found", JOptionPane.WARNING_MESSAGE);
JFileChooser fileChooser = new JFileChooser(getLastSelectedFolder().getLastSelectedFolder());
fileChooser.setDialogTitle("Open Spectrum File");
FileFilter filter = new FileFilter() {
@Override
public boolean accept(File myFile) {
return myFile.getName().toLowerCase().endsWith(".mgf") || myFile.getName().toLowerCase().endsWith(".mgf.gz") || myFile.getName().toLowerCase().endsWith(".mzml") || myFile.getName().toLowerCase().endsWith(".mzml.gz") || myFile.isDirectory();
}
@Override
public String getDescription() {
return "Supported formats: mgf or mzML (.mgf, .mg.gz, .mzml, .mzml.gz)";
}
};
fileChooser.setFileFilter(filter);
int returnVal = fileChooser.showDialog(peptideShakerGUI, "Open");
if (returnVal == JFileChooser.APPROVE_OPTION) {
File spectrumFolder = fileChooser.getSelectedFile();
if (!spectrumFolder.isDirectory()) {
spectrumFolder = spectrumFolder.getParentFile();
}
lastSelectedFolder.setLastSelectedFolder(spectrumFolder.getAbsolutePath());
found = false;
for (File file : spectrumFolder.listFiles()) {
for (String spectrumFileName2 : getIdentification().getFractions()) {
try {
String fileName = IoUtil.removeExtension(file.getName());
if (spectrumFileName2.equals(fileName)) {
psdbParent.loadSpectrumFile(file, progressDialog);
spectrumFiles.add(file);
}
if (fileName.equals(spectrumFileName2)) {
found = true;
}
} catch (Exception e) {
// ignore
}
}
}
if (found) {
try {
found = psdbParent.loadSpectrumFile(spectrumFileName, spectrumFiles, progressDialog);
} catch (Exception e) {
found = false;
}
}
if (!found) {
JOptionPane.showMessageDialog(peptideShakerGUI, spectrumFileName + " was not found in the given folder.", "File Input Error", JOptionPane.ERROR_MESSAGE);
clearData(true, true);
clearParameters();
progressDialog.setRunFinished();
openingExistingProject = false;
return;
}
}
}
if (progressDialog.isRunCanceled()) {
clearData(true, true);
clearParameters();
progressDialog.setRunFinished();
openingExistingProject = false;
return;
}
}
progressDialog.setPrimaryProgressCounterIndeterminate(true);
progressDialog.setRunFinished();
peptideShakerGUI.displayResults();
// display the overview tab data
allTabsJTabbedPaneStateChanged(null);
peptideShakerGUI.updateFrameTitle();
dataSaved = true;
SwingUtilities.invokeLater(new Runnable() {
public void run() {
openingExistingProject = false;
}
});
} catch (OutOfMemoryError error) {
System.err.println("Ran out of memory!");
System.err.println("Memory given to the Java virtual machine: " + Runtime.getRuntime().maxMemory() + ".");
System.err.println("Memory used by the Java virtual machine: " + Runtime.getRuntime().totalMemory() + ".");
System.err.println("Free memory in the Java virtual machine: " + Runtime.getRuntime().freeMemory() + ".");
Runtime.getRuntime().gc();
String message = "PeptideShaker used up all the available memory and had to be stopped.<br>" + "Memory boundaries are changed in the the Welcome Dialog (Settings<br>" + "& Help > Settings > Java Memory Settings) or in the Edit menu (Edit<br>" + "Java Options). See also <a href=\"https://compomics.github.io/projects/compomics-utilities/wiki/JavaTroubleShooting.html\">JavaTroubleShooting</a>.";
JOptionPane.showMessageDialog(PeptideShakerGUI.this, JOptionEditorPane.getJOptionEditorPane(message), "Out Of Memory", JOptionPane.ERROR_MESSAGE);
progressDialog.setRunFinished();
error.printStackTrace();
} catch (OptionalDataException e) {
progressDialog.setRunFinished();
if (e.eof) {
JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while reading:\n" + psdbParent.getPsdbFile() + ".\n\n" + "The end of the file was reached unexpectedly. The file seems to be corrupt and cannot\n" + "be opened. If the file is a copy, make sure that it is identical to the original file.", "File Input Error", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while reading:\n" + psdbParent.getPsdbFile() + ".\n\n" + "Please verify that the version used to create the file\n" + "is compatible with your version of PeptideShaker.", "File Input Error", JOptionPane.ERROR_MESSAGE);
}
e.printStackTrace();
} catch (EOFException e) {
progressDialog.setRunFinished();
JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while reading:\n" + psdbParent.getPsdbFile() + ".\n\n" + "The end of the file was reached unexpectedly. The file seems to be corrupt and cannot\n" + "be opened. If the file is a copy, make sure that it is identical to the original file.", "File Input Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
} catch (Exception e) {
progressDialog.setRunFinished();
JOptionPane.showMessageDialog(peptideShakerGUI, "An error occurred while reading:\n" + psdbParent.getPsdbFile() + ".\n\n" + "Please verify that the version used to create the file\n" + "is compatible with your version of PeptideShaker.", "File Input Error", JOptionPane.ERROR_MESSAGE);
e.printStackTrace();
}
}
}.start();
}
use of eu.isas.peptideshaker.preferences.ProjectDetails in project peptide-shaker by compomics.
the class MzIdentMLExportDialog method convertJButtonActionPerformed.
// GEN-LAST:event_contactEmailJTextFieldKeyReleased
/**
* Convert the project to an mzIdentML file.
*
* @param evt
*/
private void convertJButtonActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_convertJButtonActionPerformed
final File finalOutputFile = new File(outputFolderJTextField.getText());
progressDialog = new ProgressDialogX(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true);
progressDialog.setPrimaryProgressCounterIndeterminate(true);
progressDialog.setTitle("Exporting mzIdentML. Please Wait...");
new Thread(new Runnable() {
public void run() {
try {
progressDialog.setVisible(true);
} catch (IndexOutOfBoundsException e) {
// ignore
}
}
}, "ProgressDialog").start();
new Thread("ConvertThread") {
@Override
public void run() {
IdentificationParameters identificationParameters = peptideShakerGUI.getIdentificationParameters();
AnnotationParameters annotationParameters = identificationParameters.getAnnotationParameters();
ProjectDetails projectDetails = peptideShakerGUI.getProjectDetails();
// save the inserted mzid details with the project
projectDetails.setContactFirstName(contactFirstNameJTextField.getText().trim());
projectDetails.setContactLastName(contactLastNameJTextField.getText().trim());
projectDetails.setContactEmail(contactEmailJTextField.getText().trim());
projectDetails.setContactAddress(contactAddressJTextField.getText().trim());
if (!contactUrlJTextField.getText().trim().isEmpty()) {
projectDetails.setContactUrl(contactUrlJTextField.getText().trim());
} else {
projectDetails.setContactUrl(null);
}
projectDetails.setOrganizationName(organizationNameJTextField.getText().trim());
projectDetails.setOrganizationEmail(organizationEmailJTextField.getText().trim());
projectDetails.setOrganizationAddress(organizationAddressJTextField.getText().trim());
if (!organizationUrlJTextField.getText().trim().isEmpty()) {
projectDetails.setOrganizationUrl(organizationUrlJTextField.getText().trim());
} else {
projectDetails.setOrganizationUrl(null);
}
projectDetails.setIncludeProteinSequences(includeSequencesCheckBox.isSelected());
projectDetails.setMzIdentOutputFile(outputFolderJTextField.getText());
peptideShakerGUI.setDataSaved(false);
boolean conversionCompleted = false;
// make sure that all annotations are included
double currentIntensityLimit = annotationParameters.getAnnotationIntensityLimit();
annotationParameters.setIntensityLimit(0.0);
try {
FastaSummary fastaSummary = FastaSummary.getSummary(projectDetails.getFastaFile(), identificationParameters.getFastaParameters(), progressDialog);
MzIdentMLExport mzIdentMLExport = new MzIdentMLExport(PeptideShaker.getVersion(), peptideShakerGUI.getIdentification(), projectDetails, identificationParameters, peptideShakerGUI.getSequenceProvider(), peptideShakerGUI.getProteinDetailsProvider(), peptideShakerGUI.getSpectrumProvider(), ModificationFactory.getInstance(), fastaSummary, peptideShakerGUI.getIdentificationFeaturesGenerator(), finalOutputFile, includeSequencesCheckBox.isSelected(), progressDialog, true);
mzIdentMLExport.createMzIdentMLFile(mzIdentMLVersion);
// validate the mzidentml file
if (validateMzIdentML && !progressDialog.isRunCanceled()) {
progressDialog.setPrimaryProgressCounterIndeterminate(true);
progressDialog.setTitle("Validating mzIdentML. Please Wait...");
String errors = validateMzIdentML(finalOutputFile);
// see if any errors were found, and display them to the user
if (!errors.isEmpty()) {
JOptionPane.showMessageDialog(null, errors, "mzIdentML Errors", JOptionPane.ERROR_MESSAGE);
} else {
conversionCompleted = true;
}
} else {
conversionCompleted = true;
}
} catch (Exception e) {
peptideShakerGUI.catchException(e);
progressDialog.setRunCanceled();
progressDialog.dispose();
return;
} finally {
// reset the annotation level
annotationParameters.setIntensityLimit(currentIntensityLimit);
}
// close the progress dialog
boolean processCancelled = progressDialog.isRunCanceled();
progressDialog.setRunFinished();
// display a conversion complete message to the user
if (conversionCompleted && !processCancelled) {
JOptionPane.showMessageDialog(MzIdentMLExportDialog.this, JOptionEditorPane.getJOptionEditorPane("mzIdentML file \'" + new File(outputFolderJTextField.getText()).getAbsolutePath() + "\' created." + "<br><br>" + "Review your mzIdentML files with <a href=\"https://github.com/PRIDE-Toolsuite/pride-inspector\">PRIDE Inspector</a>.<br>" + "Publish your mzIdentML files via <a href=\"http://www.proteomexchange.org/submission\">ProteomeXchange</a>."), "File Created", JOptionPane.INFORMATION_MESSAGE);
dispose();
}
if (processCancelled) {
JOptionPane.showMessageDialog(peptideShakerGUI, "mzIdentML conversion cancelled by the user.", "mzIdentML Conversion Cancelled", JOptionPane.WARNING_MESSAGE);
}
}
}.start();
}
use of eu.isas.peptideshaker.preferences.ProjectDetails in project peptide-shaker by compomics.
the class MzIdentMLExportDialog method insertProjectData.
/**
* Insert the available project data.
*/
private void insertProjectData() {
ProjectDetails projectDetails = peptideShakerGUI.getProjectDetails();
// use the saved mzIdentML annotation, if any
contactFirstNameJTextField.setText(projectDetails.getContactFirstName());
contactLastNameJTextField.setText(projectDetails.getContactLastName());
contactEmailJTextField.setText(projectDetails.getContactEmail());
contactAddressJTextField.setText(projectDetails.getContactAddress());
contactUrlJTextField.setText(projectDetails.getContactUrl());
organizationNameJTextField.setText(projectDetails.getOrganizationName());
organizationEmailJTextField.setText(projectDetails.getOrganizationEmail());
organizationAddressJTextField.setText(projectDetails.getOrganizationAddress());
organizationUrlJTextField.setText(projectDetails.getOrganizationUrl());
includeSequencesCheckBox.setSelected(projectDetails.getIncludeProteinSequences());
if (projectDetails.getMzIdentMLOutputFile() != null && new File(projectDetails.getMzIdentMLOutputFile()).exists()) {
outputFolderJTextField.setText(projectDetails.getMzIdentMLOutputFile());
}
}
use of eu.isas.peptideshaker.preferences.ProjectDetails in project peptide-shaker by compomics.
the class CLIExportMethods method exportMzId.
/**
* Exports the project in the mzIdentML format.
*
* @param mzidCLIInputBean the user input
* @param psbdParent a psbd file parent allowing accessing the information it
* contains
* @param waitingHandler a waiting handler allowing display of progress and
* interruption of the export
*
* @throws IOException exception thrown whenever an IO exception occurred
* while reading or writing to a file
*/
public static void exportMzId(MzidCLIInputBean mzidCLIInputBean, PsdbParent psbdParent, WaitingHandler waitingHandler) throws IOException {
ProjectDetails projectDetails = psbdParent.getProjectDetails();
projectDetails.setContactFirstName(mzidCLIInputBean.getContactFirstName());
projectDetails.setContactLastName(mzidCLIInputBean.getContactLastName());
projectDetails.setContactEmail(mzidCLIInputBean.getContactEmail());
projectDetails.setContactAddress(mzidCLIInputBean.getContactAddress());
projectDetails.setContactUrl(mzidCLIInputBean.getContactUrl());
projectDetails.setOrganizationName(mzidCLIInputBean.getOrganizationName());
projectDetails.setOrganizationEmail(mzidCLIInputBean.getOrganizationMail());
projectDetails.setOrganizationAddress(mzidCLIInputBean.getOrganizationAddress());
projectDetails.setOrganizationUrl(mzidCLIInputBean.getOrganizationUrl());
projectDetails.setIncludeProteinSequences(mzidCLIInputBean.getIncludeProteinSequences());
projectDetails.setPrideOutputFolder(mzidCLIInputBean.getOutputFile().getAbsolutePath());
IdentificationParameters identificationParameters = psbdParent.getIdentificationParameters();
FastaSummary fastaSummary = FastaSummary.getSummary(projectDetails.getFastaFile(), identificationParameters.getFastaParameters(), waitingHandler);
MzIdentMLExport mzIdentMLExport = new MzIdentMLExport(PeptideShaker.getVersion(), psbdParent.getIdentification(), psbdParent.getProjectDetails(), identificationParameters, psbdParent.getSequenceProvider(), psbdParent.getProteinDetailsProvider(), psbdParent.getSpectrumProvider(), ModificationFactory.getInstance(), fastaSummary, psbdParent.getIdentificationFeaturesGenerator(), mzidCLIInputBean.getOutputFile(), mzidCLIInputBean.getIncludeProteinSequences(), waitingHandler, mzidCLIInputBean.isGzip());
mzIdentMLExport.createMzIdentMLFile(mzidCLIInputBean.getMzIdentMLVersion());
}
use of eu.isas.peptideshaker.preferences.ProjectDetails in project peptide-shaker by compomics.
the class PsSearchParametersSection method writeSection.
/**
* Writes the desired section.
*
* @param searchParameters the search parameters of this project
* @param projectDetails the project details
* @param waitingHandler the waiting handler
* @throws IOException exception thrown whenever an error occurred while
* writing the file
*/
public void writeSection(SearchParameters searchParameters, ProjectDetails projectDetails, WaitingHandler waitingHandler) throws IOException {
if (waitingHandler != null) {
waitingHandler.setSecondaryProgressCounterIndeterminate(true);
}
if (header) {
if (indexes) {
writer.writeHeaderText("");
writer.addSeparator();
}
writer.writeHeaderText("Parameter");
writer.addSeparator();
writer.writeHeaderText("Value");
writer.newLine();
}
int line = 1;
for (PsSearchFeature exportFeature : searchFeatures) {
if (indexes) {
writer.write(Integer.toString(line));
writer.addSeparator();
}
writer.write(exportFeature.getTitle());
writer.addSeparator();
switch(exportFeature) {
case database:
String fastaFileName = IoUtil.getFileName(projectDetails.getFastaFile());
writer.write(fastaFileName);
break;
case cleavage:
DigestionParameters digestionPreferences = searchParameters.getDigestionParameters();
writer.write(digestionPreferences.getCleavageParameter().toString());
break;
case enzyme:
digestionPreferences = searchParameters.getDigestionParameters();
if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
String enzymeString = digestionPreferences.getEnzymes().stream().map(enzyme -> enzyme.getName()).collect(Collectors.joining(", "));
writer.write(enzymeString);
}
break;
case mc:
digestionPreferences = searchParameters.getDigestionParameters();
if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
String nMissedCleavagesString = digestionPreferences.getEnzymes().stream().map(enzyme -> digestionPreferences.getnMissedCleavages(enzyme.getName()).toString()).collect(Collectors.joining(", "));
writer.write(nMissedCleavagesString);
}
break;
case specificity:
digestionPreferences = searchParameters.getDigestionParameters();
if (digestionPreferences.getCleavageParameter() == DigestionParameters.CleavageParameter.enzyme) {
String specificityString = digestionPreferences.getEnzymes().stream().map(enzyme -> digestionPreferences.getSpecificity(enzyme.getName()).name).collect(Collectors.joining(", "));
writer.write(specificityString);
}
break;
case fixed_modifications:
writer.write(searchParameters.getModificationParameters().getFixedModifications().stream().collect(Collectors.joining(", ")));
break;
case variable_modifications:
writer.write(searchParameters.getModificationParameters().getVariableModifications().stream().collect(Collectors.joining(", ")));
break;
case refinement_variable_modifications:
writer.write(searchParameters.getModificationParameters().getRefinementVariableModifications().stream().collect(Collectors.joining(", ")));
break;
case refinement_fixed_modifications:
writer.write(searchParameters.getModificationParameters().getRefinementFixedModifications().stream().collect(Collectors.joining(", ")));
break;
case forward_ion:
writer.write(searchParameters.getForwardIons().stream().map(ion -> ion.toString()).collect(Collectors.joining(", ")));
break;
case rewind_ion:
writer.write(searchParameters.getRewindIons().stream().map(ion -> ion.toString()).collect(Collectors.joining(", ")));
break;
case fragment_tolerance:
writer.write(Double.toString(searchParameters.getFragmentIonAccuracy()));
break;
case precursor_tolerance_unit:
writer.write(searchParameters.getPrecursorAccuracyType().toString());
break;
case fragment_tolerance_unit:
writer.write(searchParameters.getFragmentAccuracyType().toString());
break;
case precursor_tolerance:
writer.write(Double.toString(searchParameters.getPrecursorAccuracy()));
break;
default:
writer.write("Not implemented");
}
writer.newLine();
line++;
}
}
Aggregations