Search in sources :

Example 1 with MsFileHandler

use of com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler in project peptide-shaker by compomics.

the class NewDialog method clearSpectraActionPerformed.

// GEN-LAST:event_browseDbButtonActionPerformed
/**
 * Clear the spectra selection.
 *
 * @param evt
 */
private void clearSpectraActionPerformed(java.awt.event.ActionEvent evt) {
    // GEN-FIRST:event_clearSpectraActionPerformed
    spectrumFiles = new ArrayList<>();
    spectrumFilesTxt.setText(spectrumFiles.size() + " file(s) selected");
    msFileHandler = new MsFileHandler();
    validateInput();
}
Also used : MsFileHandler(com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler)

Example 2 with MsFileHandler

use of com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler 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 3 with MsFileHandler

use of com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler in project peptide-shaker by compomics.

the class Stirred method run.

/**
 * Runs the stirred process.
 *
 * @throws InterruptedException Exception thrown if a thread is interrupted.
 * @throws TimeoutException Exception thrown if the process times out.
 * @throws IOException Exception thrown if an error occurred while reading
 * or writing a file.
 */
public void run() throws InterruptedException, TimeoutException, IOException {
    // Start
    cliLogger.logMessage("Stirred process start");
    totalDuration.start();
    WaitingHandler waitingHandler = new WaitingHandlerCLIImpl();
    String inputFileName = inputFile.getName();
    if (inputFileName.toLowerCase().endsWith(".zip")) {
        // SearchGUI zip file
        File unzipFolder = new File(tempFolder, PsZipUtils.getUnzipSubFolder());
        unzipFolder.mkdir();
        TempFilesManager.registerTempFolder(unzipFolder);
        ZipUtils.unzip(inputFile, unzipFolder, waitingHandler);
        // Get the files
        File dataFasta = fastaFile;
        File dataIdentificationParametersFile = identificationParametersFile;
        ArrayList<File> spectrumFiles = new ArrayList<>();
        ArrayList<File> searchEngineResultsFiles = new ArrayList<>();
        if (spectrumFile != null) {
            spectrumFiles.add(spectrumFile);
        }
        // List the files to inspect
        ArrayList<File> files = Arrays.stream(unzipFolder.listFiles()).collect(Collectors.toCollection(ArrayList::new));
        File sguiInputFile = new File(unzipFolder, "searchGUI_input.txt");
        if (sguiInputFile.exists()) {
            SimpleFileReader reader = SimpleFileReader.getFileReader(sguiInputFile);
            String line;
            while ((line = reader.readLine()) != null) {
                if (line.charAt(0) != '#') {
                    files.add(new File(line));
                }
            }
        }
        File dataFolder = new File(unzipFolder, PeptideShaker.DATA_DIRECTORY);
        if (dataFolder.exists() && dataFolder.isDirectory()) {
            files.addAll(Arrays.stream(dataFolder.listFiles()).collect(Collectors.toCollection(ArrayList::new)));
        }
        // Inspect all files
        for (File file : files) {
            String fileNameLowerCase = file.getName().toLowerCase();
            if (fastaFile == null) {
                if (fileNameLowerCase.endsWith(".fasta")) {
                    if (dataFasta != null) {
                        throw new IllegalArgumentException("More than one fasta file provided in the data folder, please specify the file to use via the command line option.");
                    }
                    dataFasta = file;
                }
            }
            if (identificationParametersFile == null) {
                if (fileNameLowerCase.endsWith(".par")) {
                    if (dataIdentificationParametersFile != null) {
                        throw new IllegalArgumentException("More than one identification parameters file provided in the data folder, please specify the file to use via the command line option.");
                    }
                    dataIdentificationParametersFile = file;
                }
            }
            if (spectrumFile == null) {
                if (fileNameLowerCase.endsWith(".mzml") || fileNameLowerCase.endsWith(".mgf")) {
                    spectrumFiles.add(file);
                }
            }
            if (fileNameLowerCase.endsWith(".omx") || fileNameLowerCase.endsWith(".t.xml") || fileNameLowerCase.endsWith(".pep.xml") || fileNameLowerCase.endsWith(".dat") || fileNameLowerCase.endsWith(".mzid") || fileNameLowerCase.endsWith(".ms-amanda.csv") || fileNameLowerCase.endsWith(".res") || fileNameLowerCase.endsWith(".tide-search.target.txt") || fileNameLowerCase.endsWith(".tags") || fileNameLowerCase.endsWith(".pnovo.txt") || fileNameLowerCase.endsWith(".novor.csv") || fileNameLowerCase.endsWith(".psm") || fileNameLowerCase.endsWith(".omx.gz") || fileNameLowerCase.endsWith(".t.xml.gz") || fileNameLowerCase.endsWith(".pep.xml.gz") || fileNameLowerCase.endsWith(".mzid.gz") || fileNameLowerCase.endsWith(".ms-amanda.csv.gz") || fileNameLowerCase.endsWith(".res.gz") || fileNameLowerCase.endsWith(".tide-search.target.txt.gz") || // || fileNameLowerCase.endsWith(".novor.csv.gz")
            fileNameLowerCase.endsWith(".psm.gz")) {
                searchEngineResultsFiles.add(file);
            }
        }
        // Sanity check
        if (searchEngineResultsFiles.isEmpty()) {
            throw new FileNotFoundException("No identification results found in " + inputFile + ".");
        }
        if (spectrumFiles.isEmpty()) {
            throw new FileNotFoundException("No spectrum file found in " + inputFile + ".");
        }
        if (dataFasta == null) {
            throw new FileNotFoundException("No fasta file found in " + inputFile + ".");
        }
        if (dataIdentificationParametersFile == null) {
            throw new FileNotFoundException("No identification parameters file found in " + inputFile + ".");
        }
        // Import identification parameters
        cliLogger.logMessage("    Importing identification parameters file from " + dataIdentificationParametersFile);
        IdentificationParameters identificationParameters = IdentificationParameters.getIdentificationParameters(dataIdentificationParametersFile);
        // Import fasta file
        cliLogger.logMessage("    Importing protein sequences from " + dataFasta);
        FMIndex fmIndex = new FMIndex(dataFasta, identificationParameters.getFastaParameters(), waitingHandler, true, identificationParameters.getPeptideVariantsParameters(), identificationParameters.getSearchParameters());
        FastaSummary fastaSummary = FastaSummary.getSummary(dataFasta.getAbsolutePath(), identificationParameters.getFastaParameters(), waitingHandler);
        // Import spectrum files
        MsFileHandler msFileHandler = new MsFileHandler();
        for (File spectrumFile : spectrumFiles) {
            cliLogger.logMessage("    Importing spectra from " + spectrumFile);
            msFileHandler.register(spectrumFile, tempFolder, waitingHandler);
        }
        File finalFasta = dataFasta;
        // Process search engine results in parallel
        searchEngineResultsFiles.stream().parallel().forEach(searchEngineResultsFile -> {
            try {
                // Create output file
                File outputFile = new File(ouputFolder, IoUtil.removeExtension(searchEngineResultsFile.getName()) + ".stirred.mzid.gz");
                // Run on the provided files
                process(searchEngineResultsFile, finalFasta, outputFile, fmIndex, fastaSummary, msFileHandler, identificationParameters, waitingHandler);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
    } else {
        // Sanity check
        if (spectrumFile == null || !spectrumFile.exists()) {
            throw new FileNotFoundException("Spectrum file '" + spectrumFile + "' not found.");
        }
        if (fastaFile == null || !fastaFile.exists()) {
            throw new FileNotFoundException("Fasta file '" + fastaFile + "' not found.");
        }
        if (identificationParametersFile == null || !identificationParametersFile.exists()) {
            throw new FileNotFoundException("Fasta file '" + identificationParametersFile + "' not found.");
        }
        // Import identification parameters
        cliLogger.logMessage("    Importing identification parameters file from " + identificationParametersFile);
        IdentificationParameters identificationParameters = IdentificationParameters.getIdentificationParameters(identificationParametersFile);
        // Import fasta file
        cliLogger.logMessage("    Importing protein sequences from " + fastaFile);
        FMIndex fmIndex = new FMIndex(fastaFile, identificationParameters.getFastaParameters(), waitingHandler, true, identificationParameters.getPeptideVariantsParameters(), identificationParameters.getSearchParameters());
        FastaSummary fastaSummary = FastaSummary.getSummary(fastaFile.getAbsolutePath(), identificationParameters.getFastaParameters(), waitingHandler);
        // Import spectrum file
        cliLogger.logMessage("    Importing spectra from " + spectrumFile);
        MsFileHandler msFileHandler = new MsFileHandler();
        msFileHandler.register(spectrumFile, tempFolder, waitingHandler);
        // Create output file
        File outputFile = new File(ouputFolder, IoUtil.removeExtension(inputFileName) + ".stirred.mzid.gz");
        // Run on the provided files
        process(inputFile, fastaFile, outputFile, fmIndex, fastaSummary, msFileHandler, identificationParameters, waitingHandler);
    }
    // Done
    totalDuration.end();
    cliLogger.logMessage("Stirred process completed (" + totalDuration.toString() + ")");
}
Also used : ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) SimpleFileReader(com.compomics.util.io.flat.SimpleFileReader) FastaSummary(com.compomics.util.experiment.io.biology.protein.FastaSummary) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) WaitingHandlerCLIImpl(com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl) IdentificationParameters(com.compomics.util.parameters.identification.IdentificationParameters) FMIndex(com.compomics.util.experiment.identification.protein_inference.fm_index.FMIndex) WaitingHandler(com.compomics.util.waiting.WaitingHandler) File(java.io.File) MsFileHandler(com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler)

Example 4 with MsFileHandler

use of com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler in project peptide-shaker by compomics.

the class PsdbParent method loadPsdbFile.

/**
 * Loads the information from a psdb file.
 *
 * @param dbFolder the folder where to untar the project
 * @param waitingHandler a waiting handler displaying feedback to the user.
 * Ignored if null
 * @param openFromZip flag determining if pdsb file was opened from a zip
 * file
 *
 * @throws IOException thrown of IOException occurs exception thrown
 * whenever an error occurred while reading or writing a file
 */
public void loadPsdbFile(File dbFolder, WaitingHandler waitingHandler, boolean openFromZip) throws IOException {
    // close any open connection to an identification database
    if (identification != null) {
        identification.close(false);
    }
    // create the matches folder if it does not exist
    if (!dbFolder.exists()) {
        if (!dbFolder.mkdirs()) {
            throw new IOException("Impossible to create folder " + dbFolder.getAbsolutePath() + ".");
        }
    }
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
    String dbName = "tempDB-" + df.format(new Date()) + ".psdb";
    File destinationFile = new File(dbFolder.getAbsolutePath(), dbName);
    IoUtil.copyFile(psdbFile, destinationFile);
    // GzUtils.gunzipFile(psdbFile, destinationFile, false); // @TODO: re-add when the zipping works
    ObjectsDB objectsDB = new ObjectsDB(dbFolder.getAbsolutePath(), destinationFile.getName(), false);
    // get the PeptideShaker parameters
    PeptideShakerParameters psParameters = (PeptideShakerParameters) objectsDB.retrieveObject(PeptideShakerParameters.KEY);
    identificationParameters = psParameters.getIdentificationParameters();
    spectrumCountingParameters = psParameters.getSpectrumCountingPreferences();
    projectDetails = psParameters.getProjectDetails();
    metrics = psParameters.getMetrics();
    geneMaps = psParameters.getGeneMaps();
    filterParameters = psParameters.getFilterParameters();
    displayParameters = psParameters.getDisplayParameters();
    sequenceProvider = psParameters.getSequenceProvider();
    proteinDetailsProvider = psParameters.getProteinDetailsProvider();
    projectType = psParameters.getProjectType();
    // find or create the fm index
    FMIndex fmIndex = null;
    if (openFromZip) {
        File fmPath = new File(Paths.get(psdbFile.getParentFile().getAbsolutePath(), "data").toString());
        for (File file : fmPath.listFiles()) {
            if (file.getAbsoluteFile().toString().toLowerCase().endsWith(".fasta")) {
                fmIndex = new FMIndex(file, psParameters.getIdentificationParameters().getFastaParameters(), waitingHandler, true, psParameters.getIdentificationParameters().getPeptideVariantsParameters(), psParameters.getIdentificationParameters().getSearchParameters());
                break;
            }
        }
    } else {
        boolean fastaFileFound = false;
        try {
            FastaSummary fastaSummary = loadFastaFile(waitingHandler);
            if (fastaSummary != null) {
                fastaFileFound = true;
            }
        } catch (IOException e) {
            fastaFileFound = false;
        }
        if (fastaFileFound) {
            File fastaFile = new File(psParameters.getProjectDetails().getFastaFile());
            fmIndex = new FMIndex(fastaFile, psParameters.getIdentificationParameters().getFastaParameters(), waitingHandler, true, psParameters.getIdentificationParameters().getPeptideVariantsParameters(), psParameters.getIdentificationParameters().getSearchParameters());
        } else {
            throw new IOException("FASTA file not found " + psParameters.getProjectDetails().getFastaFile() + ".");
        }
    }
    psParameters.setSequenceProvider(fmIndex);
    psParameters.setProteinDetailsProvider(fmIndex);
    sequenceProvider = fmIndex;
    proteinDetailsProvider = fmIndex;
    objectsDB.updateObject(PeptideShakerParameters.KEY, psParameters);
    projectParameters = (ProjectParameters) objectsDB.retrieveObject(ProjectParameters.key);
    identification = new Identification(objectsDB);
    // load identification attributes
    IdentificationKeys identificationKeys = (IdentificationKeys) objectsDB.retrieveObject(IdentificationKeys.KEY);
    identification.setIdentificationKeys(identificationKeys);
    PSMaps psMaps = new PSMaps();
    psMaps = (PSMaps) objectsDB.retrieveObject(psMaps.getParameterKey());
    identification.addUrParam(psMaps);
    // set up the spectrum provider
    msFileHandler = new MsFileHandler();
    // set up caches
    identificationFeaturesGenerator = new IdentificationFeaturesGenerator(identification, identificationParameters, sequenceProvider, msFileHandler, metrics, spectrumCountingParameters);
    IdentificationFeaturesCache identificationFeaturesCache = psParameters.getIdentificationFeaturesCache();
    if (identificationFeaturesCache != null) {
        identificationFeaturesGenerator.setIdentificationFeaturesCache(psParameters.getIdentificationFeaturesCache());
        identificationFeaturesCache.setReadOnly(false);
    }
    if (waitingHandler != null && waitingHandler.isRunCanceled()) {
        waitingHandler.setRunFinished();
        return;
    }
    loadUserParameters();
    userPreferences.addRecentProject(psdbFile);
    saveUserParameters();
}
Also used : IdentificationFeaturesGenerator(com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator) IdentificationKeys(com.compomics.util.experiment.identification.IdentificationKeys) PSMaps(eu.isas.peptideshaker.scoring.PSMaps) IdentificationFeaturesCache(com.compomics.util.experiment.identification.features.IdentificationFeaturesCache) Identification(com.compomics.util.experiment.identification.Identification) IOException(java.io.IOException) FastaSummary(com.compomics.util.experiment.io.biology.protein.FastaSummary) Date(java.util.Date) ObjectsDB(com.compomics.util.db.object.ObjectsDB) FMIndex(com.compomics.util.experiment.identification.protein_inference.fm_index.FMIndex) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) PeptideShakerParameters(eu.isas.peptideshaker.parameters.PeptideShakerParameters) MsFileHandler(com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler)

Aggregations

MsFileHandler (com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler)4 FastaSummary (com.compomics.util.experiment.io.biology.protein.FastaSummary)3 FMIndex (com.compomics.util.experiment.identification.protein_inference.fm_index.FMIndex)2 WaitingHandlerCLIImpl (com.compomics.util.gui.waiting.waitinghandlers.WaitingHandlerCLIImpl)2 IdentificationParameters (com.compomics.util.parameters.identification.IdentificationParameters)2 File (java.io.File)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 TimeoutException (java.util.concurrent.TimeoutException)2 IdentificationParametersInputBean (com.compomics.cli.identification_parameters.IdentificationParametersInputBean)1 ObjectsDB (com.compomics.util.db.object.ObjectsDB)1 ProjectParameters (com.compomics.util.experiment.ProjectParameters)1 Identification (com.compomics.util.experiment.identification.Identification)1 IdentificationKeys (com.compomics.util.experiment.identification.IdentificationKeys)1 IdentificationFeaturesCache (com.compomics.util.experiment.identification.features.IdentificationFeaturesCache)1 IdentificationFeaturesGenerator (com.compomics.util.experiment.identification.features.IdentificationFeaturesGenerator)1 WaitingDialog (com.compomics.util.gui.waiting.waitinghandlers.WaitingDialog)1 SimpleFileReader (com.compomics.util.io.flat.SimpleFileReader)1 ValidationQcParameters (com.compomics.util.parameters.identification.advanced.ValidationQcParameters)1