use of de.ipbhalle.metfraglib.exceptions.RetentionTimeNotFoundException in project MetFragRelaunched by ipb-halle.
the class BeanSettingsContainer method preprocessRetentionTimeTrainingFile.
public void preprocessRetentionTimeTrainingFile() throws Exception {
if (this.retentionTimeScoreTrainingFilePath == null || this.retentionTimeScoreTrainingFilePath.trim().length() == 0)
return;
if (this.availableCandidatePartitioningCoefficients == null || this.availableCandidatePartitioningCoefficients.size() == 0)
return;
java.io.File retentionTimeTrainingFile = new java.io.File(this.retentionTimeScoreTrainingFilePath);
if (retentionTimeTrainingFile != null && retentionTimeTrainingFile.exists() && retentionTimeTrainingFile.canRead()) {
MetFragGlobalSettings settings = new MetFragGlobalSettings();
settings.set(VariableNames.LOG_LEVEL_NAME, Level.DEBUG);
settings.set(VariableNames.METFRAG_DATABASE_TYPE_NAME, "LocalProperty");
settings.set(VariableNames.LOCAL_DATABASE_PATH_NAME, this.retentionTimeScoreTrainingFilePath);
CombinedMetFragProcess combinedMetFragProcess = new CombinedMetFragProcess(settings);
boolean entriesRetrieved = combinedMetFragProcess.retrieveCompounds();
if (entriesRetrieved) {
CandidateList candidates = combinedMetFragProcess.getCandidateList();
if (candidates == null || candidates.getNumberElements() <= 1)
throw new TooFewCandidatesException();
if (!candidates.getElement(0).getProperties().containsKey(VariableNames.RETENTION_TIME_NAME))
throw new RetentionTimeNotFoundException();
this.availablePartitioningCoefficients = new java.util.ArrayList<SelectItem>();
java.util.Enumeration<String> keys = candidates.getElement(0).getProperties().keys();
while (keys.hasMoreElements()) {
String currentKey = keys.nextElement().trim();
if (currentKey.equals(VariableNames.INCHI_NAME)) {
currentKey = "CDK";
}
for (int k = 0; k < this.availableCandidatePartitioningCoefficients.size(); k++) {
if (this.availableCandidatePartitioningCoefficients.get(k).getLabel().equals(currentKey)) {
if (currentKey.equals("CDK"))
this.availablePartitioningCoefficients.add(new SelectItem(currentKey));
else {
if (this.isValidLogValueProperty(currentKey, candidates))
this.availablePartitioningCoefficients.add(new SelectItem(currentKey));
}
}
}
}
}
Collections.sort(this.availablePartitioningCoefficients, new java.util.Comparator<SelectItem>() {
@Override
public int compare(SelectItem left, SelectItem right) {
return ((String) left.getValue()).compareTo((String) right.getValue());
}
});
} else
this.availablePartitioningCoefficients = null;
}
use of de.ipbhalle.metfraglib.exceptions.RetentionTimeNotFoundException in project MetFragRelaunched by ipb-halle.
the class UserInputDataHandler method handleRetentionTimeTrainingFile.
/**
* @param retentionTimeTrainingFile
* @param infoMessages
* @param errorMessages
* @return
*/
public void handleRetentionTimeTrainingFile(UploadedFile retentionTimeTrainingFile, Messages infoMessages, Messages errorMessages, BeanSettingsContainer beanSettingsContainer) {
if (retentionTimeTrainingFile == null) {
errorMessages.setMessage("retentionTimeTrainingFileError", "Error: Retention time training file was not saved.");
return;
}
// create upload folder
File uploadFolder = this.fileStorer.prepareFolder(beanSettingsContainer.getRootSessionFolder() + Constants.OS_SPECIFIC_FILE_SEPARATOR + "retentiontimescore", errorMessages);
if (uploadFolder == null)
return;
// store the file
File storedFile = null;
try {
storedFile = this.fileStorer.saveUploadedFile(retentionTimeTrainingFile, uploadFolder);
beanSettingsContainer.setRetentionTimeScoreTrainingFilePath(storedFile.getAbsolutePath());
} catch (Exception e) {
errorMessages.setMessage("retentionTimeTrainingFileError", "Error: Retention time training file was not saved.");
beanSettingsContainer.setRetentionTimeScoreTrainingFilePath("");
return;
}
// preprocess
try {
beanSettingsContainer.preprocessRetentionTimeTrainingFile();
if (beanSettingsContainer.getAvailablePartitioningCoefficients() == null || beanSettingsContainer.getAvailablePartitioningCoefficients().size() == 0) {
errorMessages.setMessage("retentionTimeTrainingFileError", "No proper value for a partitioning coefficient found. Check candidate and retention time file.");
beanSettingsContainer.setScoreValid(false, "retentionTimeTrainingFile");
beanSettingsContainer.setRetentionTimeScoreTrainingFilePath("");
return;
}
} catch (TooFewCandidatesException e1) {
beanSettingsContainer.setScoreValid(false, "retentionTimeTrainingFile");
beanSettingsContainer.setRetentionTimeScoreTrainingFilePath("");
beanSettingsContainer.setAvailablePartitioningCoefficients(null);
errorMessages.setMessage("retentionTimeTrainingFileError", "Error: Uploaded file contains too few values.");
} catch (RetentionTimeNotFoundException e2) {
beanSettingsContainer.setScoreValid(false, "retentionTimeTrainingFile");
beanSettingsContainer.setRetentionTimeScoreTrainingFilePath("");
beanSettingsContainer.setAvailablePartitioningCoefficients(null);
errorMessages.setMessage("retentionTimeTrainingFileError", "Error: Uploaded file does not contain a RetentionTime field.");
} catch (Exception e3) {
e3.printStackTrace();
beanSettingsContainer.setScoreValid(false, "retentionTimeTrainingFile");
beanSettingsContainer.setRetentionTimeScoreTrainingFilePath("");
beanSettingsContainer.setAvailablePartitioningCoefficients(null);
errorMessages.setMessage("retentionTimeTrainingFileError", "Error: Could not read file. Missing/Wrong header?");
}
}
Aggregations