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;
}
}
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();
}
Aggregations