use of com.compomics.util.experiment.io.biology.protein.FastaSummary 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 com.compomics.util.experiment.io.biology.protein.FastaSummary 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 com.compomics.util.experiment.io.biology.protein.FastaSummary in project peptide-shaker by compomics.
the class PeptideShaker method createProject.
/**
* Creates a PeptideShaker project.
*
* @param waitingHandler the handler displaying feedback to the user
* @param exceptionHandler handler for exceptions
* @param identificationParameters the identification parameters
* @param processingParameters the processing parameters
* @param projectType the project type
* @param spectrumCountingParameters the spectrum counting parameters
* @param spectrumProvider the spectrum provider
* @param setWaitingHandlerFinshedWhenDone if true, the waiting handler is
* set to finished when the project is created
* @param projectDetails the project details
*
* @throws java.lang.InterruptedException exception thrown if a thread gets
* interrupted
* @throws java.util.concurrent.TimeoutException exception thrown if a
* process times out
* @throws java.io.IOException if an exception occurs when parsing files
*/
public void createProject(IdentificationParameters identificationParameters, ProcessingParameters processingParameters, SpectrumCountingParameters spectrumCountingParameters, SpectrumProvider spectrumProvider, ProjectDetails projectDetails, ProjectType projectType, WaitingHandler waitingHandler, boolean setWaitingHandlerFinshedWhenDone, ExceptionHandler exceptionHandler) throws InterruptedException, TimeoutException, IOException {
identification.getObjectsDB().commit();
identificationFeaturesGenerator = new IdentificationFeaturesGenerator(identification, identificationParameters, sequenceProvider, spectrumProvider, metrics, spectrumCountingParameters);
matchesValidator = new MatchesValidator(new TargetDecoyMap(), new TargetDecoyMap(), new TargetDecoyMap());
if (waitingHandler.isRunCanceled()) {
return;
}
PsmScoringParameters psmScoringPreferences = identificationParameters.getPsmScoringParameters();
FastaParameters fastaParameters = identificationParameters.getFastaParameters();
FastaSummary fastaSummary = FastaSummary.getSummary(projectDetails.getFastaFile(), fastaParameters, waitingHandler);
// set the background species
identificationParameters.getGeneParameters().setBackgroundSpeciesFromFastaSummary(fastaSummary);
ArrayList<Integer> usedAlgorithms = projectDetails.getIdentificationAlgorithms();
if (psmScoringPreferences.isScoringNeeded(usedAlgorithms)) {
waitingHandler.appendReport("Estimating PSM scores.", true, true);
PsmScorer psmScorer = new PsmScorer(fastaParameters, sequenceProvider, spectrumProvider);
psmScorer.estimateIntermediateScores(identification, inputMap, processingParameters, identificationParameters, waitingHandler, exceptionHandler);
if (psmScoringPreferences.isTargetDecoyNeededForPsmScoring(usedAlgorithms)) {
if (fastaParameters.isTargetDecoy()) {
waitingHandler.appendReport("Estimating intermediate scores probabilities.", true, true);
psmScorer.estimateIntermediateScoreProbabilities(identification, inputMap, processingParameters, waitingHandler);
} else {
waitingHandler.appendReport("No decoy sequences found. Impossible to " + "estimate intermediate scores probabilities.", true, true);
}
}
waitingHandler.appendReport("Scoring PSMs.", true, true);
psmScorer.scorePsms(identification, inputMap, processingParameters, identificationParameters, waitingHandler);
}
identification.getObjectsDB().commit();
System.gc();
if (fastaParameters.isTargetDecoy()) {
waitingHandler.appendReport("Computing assumptions probabilities.", true, true);
} else {
waitingHandler.appendReport("Importing assumptions scores.", true, true);
}
inputMap.estimateProbabilities(waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Saving assumptions probabilities, selecting best match, scoring modification localization.", true, true);
PsmProcessor psmProcessor = new PsmProcessor(identification);
psmProcessor.processPsms(inputMap, identificationParameters, matchesValidator, modificationLocalizationScorer, sequenceProvider, spectrumProvider, modificationFactory, proteinCount, processingParameters.getnThreads(), waitingHandler, exceptionHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Computing PSM probabilities.", true, true);
matchesValidator.getPsmMap().estimateProbabilities(waitingHandler);
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
PeptideInference peptideInference = new PeptideInference();
ModificationLocalizationParameters modificationScoringPreferences = identificationParameters.getModificationLocalizationParameters();
if (modificationScoringPreferences.getAlignNonConfidentModifications()) {
waitingHandler.appendReport("Resolving peptide inference issues.", true, true);
peptideInference.peptideInference(identification, identificationParameters, sequenceProvider, modificationFactory, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
}
identification.getObjectsDB().commit();
System.gc();
}
String reportTxt = "Saving probabilities";
String waitingTitle = "Saving Probabilities.";
;
switch(projectType) {
case psm:
reportTxt += ".";
break;
case peptide:
reportTxt += ", building peptides.";
waitingTitle += " Building Peptides.";
break;
default:
reportTxt += ", building peptides and proteins.";
waitingTitle += " Building Peptides and Proteins.";
}
waitingHandler.appendReport(reportTxt, true, true);
waitingHandler.setWaitingText(waitingTitle + " Please Wait...");
attachSpectrumProbabilitiesAndBuildPeptidesAndProteins(sequenceProvider, identificationParameters.getSequenceMatchingParameters(), projectType, fastaParameters, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
waitingHandler.appendReport("Generating peptide map.", true, true);
matchesValidator.fillPeptideMaps(identification, metrics, waitingHandler, identificationParameters, sequenceProvider, spectrumProvider);
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Computing peptide probabilities.", true, true);
matchesValidator.getPeptideMap().estimateProbabilities(waitingHandler);
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Saving peptide probabilities.", true, true);
matchesValidator.attachPeptideProbabilities(identification, fastaParameters, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.protein) {
if (identificationParameters.getProteinInferenceParameters().getSimplifyGroups()) {
waitingHandler.appendReport("Simplifying protein groups.", true, true);
GroupSimplification groupSimplification = new GroupSimplification();
groupSimplification.removeRedundantGroups(identification, identificationParameters, sequenceProvider, proteinDetailsProvider, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
}
identification.getObjectsDB().commit();
System.gc();
ProteinInference proteinInference = new ProteinInference();
waitingHandler.appendReport("Mapping shared peptides.", true, true);
proteinInference.distributeSharedPeptides(identification, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Generating protein map.", true, true);
matchesValidator.fillProteinMap(identification, spectrumProvider, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Selecting leading proteins, inferring peptide and protein inference status.", true, true);
proteinInference.inferPiStatus(identification, metrics, matchesValidator.getProteinMap(), identificationParameters, sequenceProvider, proteinDetailsProvider, waitingHandler);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Computing protein probabilities.", true, true);
matchesValidator.getProteinMap().estimateProbabilities(waitingHandler);
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Saving protein probabilities.", true, true);
matchesValidator.attachProteinProbabilities(identification, sequenceProvider, fastaParameters, metrics, waitingHandler, identificationParameters.getFractionParameters());
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
}
}
if (fastaParameters.isTargetDecoy()) {
IdMatchValidationParameters idMatchValidationParameters = identificationParameters.getIdValidationParameters();
if (idMatchValidationParameters.getDefaultPsmFDR() == 1 && idMatchValidationParameters.getDefaultPeptideFDR() == 1 && idMatchValidationParameters.getDefaultProteinFDR() == 1) {
waitingHandler.appendReport("Validating identifications at 1% FDR, quality control of matches.", true, true);
} else {
waitingHandler.appendReport("Validating identifications, quality control of matches.", true, true);
}
} else {
waitingHandler.appendReport("Quality control of matches.", true, true);
}
matchesValidator.validateIdentifications(identification, metrics, inputMap, waitingHandler, exceptionHandler, identificationFeaturesGenerator, sequenceProvider, proteinDetailsProvider, spectrumProvider, geneMaps, identificationParameters, projectType, processingParameters);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.peptide || projectType == ProjectType.protein) {
waitingHandler.appendReport("Scoring PTMs in peptides.", true, true);
modificationLocalizationScorer.scorePeptidePtms(identification, modificationFactory, waitingHandler, identificationParameters);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
if (projectType == ProjectType.protein) {
waitingHandler.appendReport("Estimating spectrum counting scaling values.", true, true);
ScalingFactorsEstimators scalingFactors = new ScalingFactorsEstimators(spectrumCountingParameters);
scalingFactors.estimateScalingFactors(identification, metrics, sequenceProvider, identificationFeaturesGenerator, waitingHandler, exceptionHandler, processingParameters);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
waitingHandler.appendReport("Scoring PTMs in proteins, gathering summary metrics.", true, true);
ProteinProcessor proteinProcessor = new ProteinProcessor(identification, identificationParameters, identificationFeaturesGenerator, sequenceProvider);
proteinProcessor.processProteins(modificationLocalizationScorer, metrics, modificationFactory, waitingHandler, exceptionHandler, processingParameters);
waitingHandler.increasePrimaryProgressCounter();
if (waitingHandler.isRunCanceled()) {
return;
}
identification.getObjectsDB().commit();
System.gc();
}
}
projectCreationDuration.end();
String report = "Identification processing completed (" + projectCreationDuration.toString() + ").";
waitingHandler.appendReport(report, true, true);
waitingHandler.appendReportEndLine();
waitingHandler.appendReportEndLine();
identification.addUrParam(new PSMaps(inputMap, matchesValidator.getPsmMap(), matchesValidator.getPeptideMap(), matchesValidator.getProteinMap()));
if (setWaitingHandlerFinshedWhenDone) {
waitingHandler.setRunFinished();
}
}
use of com.compomics.util.experiment.io.biology.protein.FastaSummary 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 com.compomics.util.experiment.io.biology.protein.FastaSummary in project peptide-shaker by compomics.
the class PeptideShakerCLI method createProject.
/**
* Creates the PeptideShaker project based on the identification files
* provided in the command line input
*
* @throws java.io.IOException exception thrown if an error occurs while
* reading or writing a file
* @throws java.lang.InterruptedException exception thrown if a thread is
* interrupted
* @throws java.util.concurrent.TimeoutException exception thrown if a
* process times out
*/
public void createProject() throws IOException, InterruptedException, TimeoutException {
// define new project reference
projectParameters = new ProjectParameters(cliInputBean.getExperimentID());
// set the project details
projectDetails = new ProjectDetails();
projectDetails.setCreationDate(new Date());
projectDetails.setPeptideShakerVersion(new Properties().getVersion());
// set up spectrum provider
msFileHandler = new MsFileHandler();
// get the input files
ArrayList<File> identificationFilesInput = cliInputBean.getIdFiles();
ArrayList<File> dataFolders = new ArrayList<>();
ArrayList<File> spectrumFiles = cliInputBean.getSpectrumFiles();
File fastaFile = null;
// Extract data from zip files, try to find the search parameter and spectrum files
ArrayList<File> identificationFiles = new ArrayList<>();
IdentificationParameters tempIdentificationParameters = null;
for (File inputFile : identificationFilesInput) {
File parentFile = inputFile.getParentFile();
if (!dataFolders.contains(parentFile)) {
dataFolders.add(parentFile);
}
File dataFolder = new File(parentFile, "mgf");
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
dataFolder = new File(parentFile, "mzml");
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
dataFolder = new File(parentFile, "cms");
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
dataFolder = new File(parentFile, "fasta");
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
dataFolder = new File(parentFile, PeptideShaker.DATA_DIRECTORY);
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
String fileName = inputFile.getName();
if (fileName.toLowerCase().endsWith(".zip")) {
waitingHandler.appendReport("Unzipping " + fileName + ".", true, true);
String newName = PsZipUtils.getTempFolderName(fileName);
String parentFolder = PsZipUtils.getUnzipParentFolder();
if (parentFolder == null) {
parentFolder = parentFile.getAbsolutePath();
}
File parentFolderFile = new File(parentFolder, PsZipUtils.getUnzipSubFolder());
File destinationFolder = new File(parentFolderFile, newName);
destinationFolder.mkdir();
TempFilesManager.registerTempFolder(parentFolderFile);
ZipUtils.unzip(inputFile, destinationFolder, waitingHandler);
if (waitingHandler instanceof WaitingHandlerCLIImpl) {
waitingHandler.appendReportEndLine();
}
dataFolder = new File(destinationFolder, PeptideShaker.DATA_DIRECTORY);
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
dataFolder = new File(destinationFolder, ".mgf");
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
dataFolder = new File(parentFile, "mzml");
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
dataFolder = new File(destinationFolder, ".cms");
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
dataFolder = new File(destinationFolder, ".fasta");
if (dataFolder.exists() && !dataFolders.contains(dataFolder)) {
dataFolders.add(dataFolder);
}
for (File unzippedFile : destinationFolder.listFiles()) {
String nameLowerCase = unzippedFile.getName().toLowerCase();
if (nameLowerCase.endsWith(".omx") || nameLowerCase.endsWith(".t.xml") || nameLowerCase.endsWith(".pep.xml") || nameLowerCase.endsWith(".dat") || nameLowerCase.endsWith(".mzid") || nameLowerCase.endsWith(".ms-amanda.csv") || nameLowerCase.endsWith(".res") || nameLowerCase.endsWith(".tide-search.target.txt") || nameLowerCase.endsWith(".tags") || nameLowerCase.endsWith(".pnovo.txt") || nameLowerCase.endsWith(".novor.csv") || nameLowerCase.endsWith(".psm") || nameLowerCase.endsWith(".omx.gz") || nameLowerCase.endsWith(".t.xml.gz") || nameLowerCase.endsWith(".pep.xml.gz") || nameLowerCase.endsWith(".mzid.gz") || nameLowerCase.endsWith(".ms-amanda.csv.gz") || nameLowerCase.endsWith(".res.gz") || nameLowerCase.endsWith(".tide-search.target.txt.gz") || nameLowerCase.endsWith(".tags.gz") || nameLowerCase.endsWith(".pnovo.txt.gz") || nameLowerCase.endsWith(".novor.csv.gz") || nameLowerCase.endsWith(".psm.gz")) {
identificationFiles.add(unzippedFile);
} else if (nameLowerCase.endsWith(".par")) {
try {
tempIdentificationParameters = IdentificationParameters.getIdentificationParameters(unzippedFile);
ValidationQcParameters validationQCParameters = tempIdentificationParameters.getIdValidationParameters().getValidationQCParameters();
if (validationQCParameters == null || validationQCParameters.getPsmFilters() == null || validationQCParameters.getPeptideFilters() == null || validationQCParameters.getProteinFilters() == null || validationQCParameters.getPsmFilters().isEmpty() && validationQCParameters.getPeptideFilters().isEmpty() && validationQCParameters.getProteinFilters().isEmpty()) {
MatchesValidator.setDefaultMatchesQCFilters(validationQCParameters);
}
} catch (Exception e) {
e.printStackTrace();
waitingHandler.appendReport("An error occurred while parsing the parameters file " + unzippedFile.getName() + ". " + getLogFileMessage(), true, true);
waitingHandler.setRunCanceled();
}
}
}
} else {
identificationFiles.add(inputFile);
}
}
// list the spectrum files found
HashSet<String> dataFileNamesRequired = new HashSet<>();
for (File spectrumFile : spectrumFiles) {
dataFileNamesRequired.add(IoUtil.getFileName(spectrumFile));
}
for (File dataFolder : dataFolders) {
for (File file : dataFolder.listFiles()) {
String name = file.getName();
if (name.endsWith(".mgf") || name.endsWith(".mgf.gz") || name.endsWith(".mzml") || name.endsWith(".mzml.gz") || name.endsWith(".cms")) {
if (!dataFileNamesRequired.contains(name)) {
spectrumFiles.add(file);
dataFileNamesRequired.add(name);
}
} else if (name.endsWith(".fasta")) {
if (!dataFileNamesRequired.contains(name)) {
fastaFile = file;
dataFileNamesRequired.add(name);
}
}
}
}
// Load the spectrum files
for (File spectrumFile : spectrumFiles) {
File folder = CmsFolder.getParentFolder() == null ? spectrumFile.getParentFile() : new File(CmsFolder.getParentFolder());
msFileHandler.register(spectrumFile, folder, waitingHandler);
}
// If there is a specific fasta file chosen, it is used insted of the one included in the searchgui zip
if (cliInputBean.getFastaFile() != null) {
fastaFile = cliInputBean.getFastaFile();
}
// get the identification parameters
IdentificationParametersInputBean identificationParametersInputBean = cliInputBean.getIdentificationParametersInputBean();
if (tempIdentificationParameters != null && identificationParametersInputBean.getInputFile() == null) {
identificationParametersInputBean.setIdentificationParameters(tempIdentificationParameters);
identificationParametersInputBean.updateIdentificationParameters();
}
identificationParameters = identificationParametersInputBean.getIdentificationParameters();
ValidationQcParameters validationQCParameters = identificationParameters.getIdValidationParameters().getValidationQCParameters();
if (validationQCParameters == null || validationQCParameters.getPsmFilters() == null || validationQCParameters.getPeptideFilters() == null || validationQCParameters.getProteinFilters() == null || validationQCParameters.getPsmFilters().isEmpty() && validationQCParameters.getPeptideFilters().isEmpty() && validationQCParameters.getProteinFilters().isEmpty()) {
MatchesValidator.setDefaultMatchesQCFilters(validationQCParameters);
}
if (identificationParameters == null) {
waitingHandler.appendReport("Identification parameters not found!", true, true);
waitingHandler.setRunCanceled();
}
SearchParameters searchParameters = identificationParameters.getSearchParameters();
String error = PeptideShaker.loadModifications(searchParameters);
if (error != null) {
System.out.println(error);
}
// try to locate the fasta file
if (fastaFile == null) {
waitingHandler.appendReport("FASTA file not set (or not in zip file)!", true, true);
waitingHandler.setRunCanceled();
} else if (!fastaFile.exists()) {
boolean found = false;
// look in the database folder
try {
File tempDbFolder = utilitiesUserParameters.getDbFolder();
File newFile = new File(tempDbFolder, fastaFile.getName());
if (newFile.exists()) {
fastaFile = newFile;
projectDetails.setFastaFile(fastaFile);
found = true;
}
} catch (Exception e) {
e.printStackTrace();
}
if (!found) {
// look in the data folders
for (File dataFolder : dataFolders) {
File newFile = new File(dataFolder, fastaFile.getName());
if (newFile.exists()) {
fastaFile = newFile;
projectDetails.setFastaFile(fastaFile);
found = true;
break;
}
}
if (!found) {
waitingHandler.appendReport("FASTA file \'" + fastaFile.getName() + "\' not found.", true, true);
waitingHandler.setRunCanceled();
}
}
} else {
projectDetails.setFastaFile(fastaFile);
}
// get the summary information for the FASTA file
try {
// get the FASTA summary
FastaSummary fastaSummary = loadFastaFile(waitingHandler);
// set the background species
identificationParameters.getGeneParameters().setBackgroundSpeciesFromFastaSummary(fastaSummary);
} catch (IOException e) {
e.printStackTrace();
waitingHandler.appendReport("An error occurred while parsing the FASTA file.", true, true);
waitingHandler.setRunCanceled();
}
// set the processing settings
ProcessingParameters processingParameters = new ProcessingParameters();
Integer nThreads = cliInputBean.getnThreads();
if (nThreads != null) {
processingParameters.setnThreads(nThreads);
}
// set the spectrum counting prefrences
spectrumCountingParameters = new SpectrumCountingParameters();
// set the project type
projectType = cliInputBean.getProjectType();
// check the project reference
for (String forbiddenChar : Util.FORBIDDEN_CHARACTERS) {
if (cliInputBean.getExperimentID().contains(forbiddenChar)) {
waitingHandler.appendReport("The project name cannot not contain " + forbiddenChar + ".", true, true);
waitingHandler.setRunCanceled();
}
}
// incrementing the counter for a new PeptideShaker start run via CLI
if (utilitiesUserParameters.isAutoUpdate()) {
Util.sendGAUpdate("UA-36198780-1", "startrun-cl", "peptide-shaker-" + PeptideShaker.getVersion());
}
// create a shaker which will perform the analysis
PeptideShaker peptideShaker = new PeptideShaker(projectParameters);
// import the files
int outcome = peptideShaker.importFiles(waitingHandler, identificationFiles, msFileHandler, identificationParameters, projectDetails, processingParameters, exceptionHandler);
if (outcome == 0) {
peptideShaker.createProject(identificationParameters, processingParameters, spectrumCountingParameters, msFileHandler, projectDetails, projectType, waitingHandler, false, exceptionHandler);
}
if (!waitingHandler.isRunCanceled()) {
// identification as created by PeptideShaker
identification = peptideShaker.getIdentification();
// metrics saved while processing the data
metrics = peptideShaker.getMetrics();
// fene maps
geneMaps = peptideShaker.getGeneMaps();
// the identification feature generator
identificationFeaturesGenerator = peptideShaker.getIdentificationFeaturesGenerator();
// the sequence provider
sequenceProvider = peptideShaker.getSequenceProvider();
// the protein details provider
proteinDetailsProvider = peptideShaker.getProteinDetailsProvider();
if (waitingHandler instanceof WaitingDialog) {
projectDetails.setReport(((WaitingDialog) waitingHandler).getReport(null));
((WaitingDialog) waitingHandler).setRunNotFinished();
((WaitingDialog) waitingHandler).setCloseDialogWhenImportCompletes(true, false);
}
} else {
if (waitingHandler instanceof WaitingDialog) {
saveReport();
}
TempFilesManager.deleteTempFolders();
waitingHandler.setWaitingText("PeptideShaker Processing Canceled.");
System.out.println("<CompomicsError>PeptideShaker processing canceled. " + getLogFileMessage() + "</CompomicsError>");
}
}
Aggregations