Search in sources :

Example 1 with PeptideShakerParameters

use of eu.isas.peptideshaker.parameters.PeptideShakerParameters in project peptide-shaker by compomics.

the class PsdbExporter method saveAs.

/**
 * Saves the given data in a psdb file.
 *
 * @param destinationFile the destination psdb file
 * @param waitingHandler a waiting handler used to cancel the saving
 * @param identification the identification to save
 * @param sequenceProvider the sequence provider
 * @param identificationParameters the identification parameters
 * @param proteinDetailsProvider the protein details providers
 * @param spectrumCountingParameters the spectrum counting preferences
 * @param projectDetails the project details
 * @param filterParameters the filtering preferences
 * @param displayParameters the display preferences
 * @param metrics the dataset
 * @param projectType the project type
 * @param geneMaps the gene maps
 * @param identificationFeaturesCache the identification features cache
 * @param emptyCache a boolean indicating whether the object cache should be
 * emptied
 * @param dbFolder the path to the folder where the database is located
 *
 * @throws IOException thrown whenever an error occurred while reading or
 * writing a file
 */
public static void saveAs(File destinationFile, WaitingHandler waitingHandler, Identification identification, IdentificationParameters identificationParameters, SequenceProvider sequenceProvider, ProteinDetailsProvider proteinDetailsProvider, SpectrumCountingParameters spectrumCountingParameters, ProjectDetails projectDetails, FilterParameters filterParameters, Metrics metrics, GeneMaps geneMaps, ProjectType projectType, IdentificationFeaturesCache identificationFeaturesCache, boolean emptyCache, DisplayParameters displayParameters, File dbFolder) throws IOException {
    identificationFeaturesCache.setReadOnly(true);
    try {
        // save the user advocates
        projectDetails.setUserAdvocateMapping(Advocate.getUserAdvocates());
        // add all necessary data and parameters into the db for export
        if (!identification.contains(PeptideShakerParameters.KEY)) {
            PeptideShakerParameters peptideShakerParameters = new PeptideShakerParameters(identificationParameters, spectrumCountingParameters, projectDetails, filterParameters, displayParameters, metrics, sequenceProvider, proteinDetailsProvider, geneMaps, projectType, identificationFeaturesCache);
            identification.addObject(PeptideShakerParameters.KEY, peptideShakerParameters);
        }
        // add the identification keys
        if (!identification.contains(IdentificationKeys.KEY)) {
            identification.addObject(IdentificationKeys.KEY, identification.getIdentificationKeys());
        }
        PSMaps psMaps = new PSMaps();
        long psMapsIdentKey = psMaps.getParameterKey();
        if (!identification.contains(psMapsIdentKey)) {
            identification.addObject(psMapsIdentKey, identification.getUrParam(psMaps));
        }
        // save the cache and the database
        if (waitingHandler == null || !waitingHandler.isRunCanceled()) {
            // remove the FM index temporaly from the parameters set
            PeptideShakerParameters peptideShakerParameters = (PeptideShakerParameters) identification.retrieveObject(PeptideShakerParameters.KEY);
            SequenceProvider tmpSequenceProvider = peptideShakerParameters.getSequenceProvider();
            ProteinDetailsProvider tmpProteinDetailsProvider = peptideShakerParameters.getProteinDetailsProvider();
            peptideShakerParameters.cleanProviders();
            identification.updateObject(PeptideShakerParameters.KEY, peptideShakerParameters);
            identification.getObjectsDB().lock(waitingHandler);
            IoUtil.copyFile(identification.getObjectsDB().getDbFile(), destinationFile);
            // @TODO: re-add when the zipping works
            // GzUtils.gzFile(
            // identification.getObjectsDB().getDbFile(),
            // destinationFile,
            // false
            // );
            identification.getObjectsDB().unlock();
            peptideShakerParameters.setSequenceProvider(tmpSequenceProvider);
            peptideShakerParameters.setProteinDetailsProvider(tmpProteinDetailsProvider);
            identification.updateObject(PeptideShakerParameters.KEY, peptideShakerParameters);
        }
    } finally {
        // restore the project navigability
        identificationFeaturesCache.setReadOnly(false);
    }
}
Also used : SequenceProvider(com.compomics.util.experiment.io.biology.protein.SequenceProvider) PSMaps(eu.isas.peptideshaker.scoring.PSMaps) ProteinDetailsProvider(com.compomics.util.experiment.io.biology.protein.ProteinDetailsProvider) PeptideShakerParameters(eu.isas.peptideshaker.parameters.PeptideShakerParameters)

Example 2 with PeptideShakerParameters

use of eu.isas.peptideshaker.parameters.PeptideShakerParameters 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

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