use of com.compomics.util.experiment.identification.IdentificationKeys 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();
}
Aggregations