Search in sources :

Example 1 with ProjectParameters

use of com.compomics.util.experiment.ProjectParameters 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>");
    }
}
Also used : ArrayList(java.util.ArrayList) WaitingDialog(com.compomics.util.gui.waiting.waitinghandlers.WaitingDialog) Properties(eu.isas.peptideshaker.utils.Properties) FastaSummary(com.compomics.util.experiment.io.biology.protein.FastaSummary) SearchParameters(com.compomics.util.parameters.identification.search.SearchParameters) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) ValidationQcParameters(com.compomics.util.parameters.identification.advanced.ValidationQcParameters) ProcessingParameters(com.compomics.util.parameters.tools.ProcessingParameters) MsFileHandler(com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler) HashSet(java.util.HashSet) ProjectDetails(eu.isas.peptideshaker.preferences.ProjectDetails) IdentificationParametersInputBean(com.compomics.cli.identification_parameters.IdentificationParametersInputBean) SpectrumCountingParameters(com.compomics.util.parameters.quantification.spectrum_counting.SpectrumCountingParameters) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) SQLException(java.sql.SQLException) Point(java.awt.Point) ProjectParameters(com.compomics.util.experiment.ProjectParameters) WaitingHandlerCLIImpl(com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl) PeptideShaker(eu.isas.peptideshaker.PeptideShaker)

Example 2 with ProjectParameters

use of com.compomics.util.experiment.ProjectParameters in project peptide-shaker by compomics.

the class NewDialog method loadButtonActionPerformed.

// </editor-fold>//GEN-END:initComponents
/**
 * Tries to process the identification files, closes the dialog and then
 * opens the results in the main frame.
 *
 * @param evt
 */
private void loadButtonActionPerformed(java.awt.event.ActionEvent evt) {
    if (validateUserInput()) {
        if (welcomeDialog != null) {
            welcomeDialog.setVisible(false);
        }
        this.setVisible(false);
        peptideShakerGUI.setVisible(true);
        ProjectType projectType = ProjectType.getProjectType(typeCmb.getSelectedItem().toString());
        peptideShakerGUI.setIdentificationParameters(identificationParameters);
        peptideShakerGUI.setProcessingParameters(processingParameters);
        peptideShakerGUI.setDisplayParameters(displayPreferences);
        projectDetails = new ProjectDetails();
        projectDetails.setCreationDate(new Date());
        projectDetails.setPeptideShakerVersion(new eu.isas.peptideshaker.utils.Properties().getVersion());
        projectDetails.setFastaFile(fastaFile);
        peptideShakerGUI.setProjectDetails(projectDetails);
        peptideShakerGUI.setCurentNotes(new ArrayList<>());
        peptideShakerGUI.updateNotesNotificationCounter();
        peptideShakerGUI.resetDisplayFeaturesGenerator();
        peptideShakerGUI.setSpectrumCountingParameters(spectrumCountingPreferences);
        peptideShakerGUI.setMsFileHandler(msFileHandler);
        ProjectParameters projectParameters = new ProjectParameters(projectNameIdTxt.getText().trim());
        // incrementing the counter for a new PeptideShaker start run via GUI
        if (peptideShakerGUI.getUtilitiesUserParameters().isAutoUpdate()) {
            Util.sendGAUpdate("UA-36198780-1", "startrun-gui", "peptide-shaker-" + PeptideShaker.getVersion());
        }
        peptideShaker = new PeptideShaker(projectParameters);
        ArrayList<String> tips;
        try {
            tips = Tips.getTips();
        } catch (Exception e) {
            tips = new ArrayList<>();
        // Do something here?
        }
        WaitingDialog waitingDialog = new WaitingDialog(peptideShakerGUI, Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker.gif")), Toolkit.getDefaultToolkit().getImage(getClass().getResource("/icons/peptide-shaker-orange.gif")), true, tips, "Importing Data", "PeptideShaker", PeptideShaker.getVersion(), true);
        waitingDialog.setCloseDialogWhenImportCompletes(true, true);
        int progressCounter = idFiles.size() + spectrumFiles.size();
        // establishing the database connection
        progressCounter++;
        // the FASTA file
        progressCounter++;
        // the peptide to protein map
        progressCounter++;
        // computing probabilities etc
        progressCounter += 6;
        if (identificationParameters.getProteinInferenceParameters().getSimplifyGroups()) {
            // 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;
        if (identificationParameters.getModificationLocalizationParameters().getAlignNonConfidentModifications()) {
            // Peptide inference
            progressCounter++;
        }
        // add one more just to not start at 0%
        progressCounter++;
        waitingDialog.setMaxPrimaryProgressCounter(progressCounter);
        // just to not start at 0%
        waitingDialog.increasePrimaryProgressCounter();
        boolean needDialog = false;
        // load the identification files
        if (idFiles.size() > 0) {
            needDialog = true;
            new Thread(new Runnable() {

                public void run() {
                    ExceptionHandler exceptionHandler = new WaitingDialogExceptionHandler((WaitingDialog) waitingDialog, "https://github.com/compomics/peptide-shaker/issues");
                    try {
                        int outcome = peptideShaker.importFiles(waitingDialog, idFiles, msFileHandler, identificationParameters, projectDetails, processingParameters, exceptionHandler);
                        if (outcome == 0) {
                            peptideShaker.createProject(identificationParameters, processingParameters, spectrumCountingPreferences, msFileHandler, projectDetails, projectType, waitingDialog, true, exceptionHandler);
                        } else {
                            waitingDialog.setRunCanceled();
                        }
                    } catch (Exception e) {
                        exceptionHandler.catchException(e);
                        waitingDialog.setRunCanceled();
                        waitingDialog.setWaitingText("Failed to import data or create the project!");
                    }
                }
            }, "Import data and create project").start();
        }
        if (needDialog) {
            try {
                waitingDialog.setVisible(true);
            } catch (IndexOutOfBoundsException e) {
            // ignore
            }
            this.dispose();
        }
        if (!needDialog || !waitingDialog.isRunCanceled()) {
            peptideShakerGUI.setProject(projectParameters);
            peptideShakerGUI.setIdentification(peptideShaker.getIdentification());
            peptideShakerGUI.setMetrics(peptideShaker.getMetrics());
            peptideShakerGUI.setGeneMaps(peptideShaker.getGeneMaps());
            peptideShakerGUI.setProjectType(projectType);
            peptideShakerGUI.setSequenceProvider(peptideShaker.getSequenceProvider());
            peptideShakerGUI.setProteinDetailsProvider(peptideShaker.getProteinDetailsProvider());
            peptideShakerGUI.resetDisplayFeaturesGenerator();
            peptideShakerGUI.setIdentificationFeaturesGenerator(peptideShaker.getIdentificationFeaturesGenerator());
            peptideShakerGUI.displayResults();
            // display the overview tab
            peptideShakerGUI.initiateDisplay();
            peptideShakerGUI.getProjectDetails().setReport(waitingDialog.getReport(null));
            this.dispose();
        } else if (waitingDialog.isRunCanceled()) {
            // close the database
            try {
                peptideShaker.getIdentification().close(false);
            } catch (Exception e) {
                System.out.println("Failed to close the database!");
                e.printStackTrace();
            }
        }
    }
}
Also used : ProjectDetails(eu.isas.peptideshaker.preferences.ProjectDetails) ArrayList(java.util.ArrayList) WaitingDialog(com.compomics.util.gui.waiting.waitinghandlers.WaitingDialog) WaitingDialogExceptionHandler(com.compomics.util.exceptions.exception_handlers.WaitingDialogExceptionHandler) Date(java.util.Date) WaitingDialogExceptionHandler(com.compomics.util.exceptions.exception_handlers.WaitingDialogExceptionHandler) ExceptionHandler(com.compomics.util.exceptions.ExceptionHandler) ProjectParameters(com.compomics.util.experiment.ProjectParameters) ProjectType(com.compomics.util.parameters.peptide_shaker.ProjectType) PeptideShaker(eu.isas.peptideshaker.PeptideShaker)

Aggregations

ProjectParameters (com.compomics.util.experiment.ProjectParameters)2 WaitingDialog (com.compomics.util.gui.waiting.waitinghandlers.WaitingDialog)2 PeptideShaker (eu.isas.peptideshaker.PeptideShaker)2 ProjectDetails (eu.isas.peptideshaker.preferences.ProjectDetails)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 IdentificationParametersInputBean (com.compomics.cli.identification_parameters.IdentificationParametersInputBean)1 ExceptionHandler (com.compomics.util.exceptions.ExceptionHandler)1 WaitingDialogExceptionHandler (com.compomics.util.exceptions.exception_handlers.WaitingDialogExceptionHandler)1 FastaSummary (com.compomics.util.experiment.io.biology.protein.FastaSummary)1 MsFileHandler (com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler)1 WaitingHandlerCLIImpl (com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl)1 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)1 ValidationQcParameters (com.compomics.util.parameters.identification.advanced.ValidationQcParameters)1 SearchParameters (com.compomics.util.parameters.identification.search.SearchParameters)1 ProjectType (com.compomics.util.parameters.peptide_shaker.ProjectType)1 SpectrumCountingParameters (com.compomics.util.parameters.quantification.spectrum_counting.SpectrumCountingParameters)1 ProcessingParameters (com.compomics.util.parameters.tools.ProcessingParameters)1 Properties (eu.isas.peptideshaker.utils.Properties)1 Point (java.awt.Point)1