Search in sources :

Example 1 with ObjectsDB

use of com.compomics.util.db.object.ObjectsDB in project peptide-shaker by compomics.

the class PeptideShaker method importFiles.

/**
 * Imports identification results from result files.
 *
 * @param waitingHandler the handler displaying feedback to the user
 * @param idFiles the files to import
 * @param spectrumProvider the spectrum provider
 * @param identificationParameters identification parameters
 * @param projectDetails the project details
 * @param processingPreferences the initial processing preferences
 * @param exceptionHandler the exception handler
 *
 * @return 0 if the import went fine, 1 otherwise
 */
public int importFiles(WaitingHandler waitingHandler, ArrayList<File> idFiles, SpectrumProvider spectrumProvider, IdentificationParameters identificationParameters, ProjectDetails projectDetails, ProcessingParameters processingPreferences, ExceptionHandler exceptionHandler) {
    projectCreationDuration = new Duration();
    projectCreationDuration.start();
    waitingHandler.appendReport("Import process for " + projectParameters.getProjectUniqueName(), true, true);
    waitingHandler.appendReportEndLine();
    SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
    String dbName = projectParameters.getProjectUniqueName() + df.format(projectParameters.getCreationTime()) + ".psdb";
    objectsDB = new ObjectsDB(PeptideShaker.getMatchesFolder().getAbsolutePath(), dbName);
    identification = new Identification(objectsDB);
    identification.addObject(ProjectParameters.key, projectParameters);
    fileImporter = new FileImporter(identification, identificationParameters, processingPreferences, metrics, projectDetails, spectrumProvider, waitingHandler, exceptionHandler);
    int outcome = fileImporter.importFiles(idFiles);
    if (outcome == 0) {
        geneMaps = fileImporter.getGeneMaps();
        sequenceProvider = fileImporter.getSequenceProvider();
        proteinDetailsProvider = fileImporter.getProteinDetailsProvider();
        inputMap = fileImporter.getInputMap();
        proteinCount = fileImporter.getProteinCount();
        return 0;
    } else {
        return 1;
    }
}
Also used : FileImporter(eu.isas.peptideshaker.fileimport.FileImporter) Duration(com.compomics.util.waiting.Duration) ObjectsDB(com.compomics.util.db.object.ObjectsDB) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with ObjectsDB

use of com.compomics.util.db.object.ObjectsDB 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

ObjectsDB (com.compomics.util.db.object.ObjectsDB)2 SimpleDateFormat (java.text.SimpleDateFormat)2 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 FMIndex (com.compomics.util.experiment.identification.protein_inference.fm_index.FMIndex)1 FastaSummary (com.compomics.util.experiment.io.biology.protein.FastaSummary)1 MsFileHandler (com.compomics.util.experiment.io.mass_spectrometry.MsFileHandler)1 Duration (com.compomics.util.waiting.Duration)1 FileImporter (eu.isas.peptideshaker.fileimport.FileImporter)1 PeptideShakerParameters (eu.isas.peptideshaker.parameters.PeptideShakerParameters)1 PSMaps (eu.isas.peptideshaker.scoring.PSMaps)1 File (java.io.File)1 IOException (java.io.IOException)1 Date (java.util.Date)1