use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class RoiForErrorDescriptor method preNextProcess.
public ArrayList<AsynchClientTask> preNextProcess() {
ArrayList<AsynchClientTask> tasks = new ArrayList<AsynchClientTask>();
AsynchClientTask aTask1 = new AsynchClientTask("Saving selected ROIs...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
boolean[] selectedROIs = ((RoiForErrorPanel) getPanelComponent()).getSelectedROIs();
boolean isOneSelected = false;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i]) {
isOneSelected = true;
break;
}
}
if (isOneSelected) {
bathRunWorkspace.getWorkingFrapStudy().setSelectedROIsForErrorCalculation(selectedROIs);
} else {
throw new Exception("At least one ROI has to be selected.");
}
}
};
tasks.add(aTask1);
return tasks;
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class SingleFileDescriptor method preNextProcess.
// load the data before the panel disappears
public ArrayList<AsynchClientTask> preNextProcess() {
// create AsynchClientTask arraylist
ArrayList<AsynchClientTask> taskArrayList = new ArrayList<AsynchClientTask>();
if (singleFilePanel.getFileName().length() > 0) {
final String fileStr = singleFilePanel.getFileName();
final String LOADING_MESSAGE = "Loading " + fileStr + "...";
AsynchClientTask updateUIBeforeLoadTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
VirtualFrapBatchRunFrame.updateStatus(LOADING_MESSAGE);
}
};
AsynchClientTask loadTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy newFRAPStudy = null;
File inFile = new File(fileStr);
if (// .log (vcell log file)
inFile.getName().endsWith(SimDataConstants.LOGFILE_EXTENSION)) {
DataIdentifier[] dataIdentifiers = FrapDataUtils.getDataIdentiferListFromVCellSimulationData(inFile, 0);
String[][] rowData = new String[dataIdentifiers.length][1];
for (int i = 0; i < dataIdentifiers.length; i++) {
if (dataIdentifiers[i].getVariableType().equals(VariableType.VOLUME)) {
rowData[i][0] = dataIdentifiers[i].getName();
}
}
int[] selectedIndexArr = DialogUtils.showComponentOKCancelTableList(SingleFileDescriptor.this.getPanelComponent(), "Select Volume Variable", new String[] { "Volume Variable Name" }, rowData, ListSelectionModel.SINGLE_SELECTION);
if (selectedIndexArr != null && selectedIndexArr.length > 0) {
// newFRAPStudy = getFrapWorkspace().loadFRAPDataFromVcellLogFile(inFile, dataIdentifiers[selectedIndexArr[0]].getName(), this.getClientTaskStatusSupport());
isFileLoaded = true;
} else {
throw UserCancelException.CANCEL_GENERIC;
}
} else if (// .vfrap
inFile.getName().endsWith(VirtualFrapLoader.VFRAP_EXTENSION)) {
String xmlString = XmlUtil.getXMLString(inFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
newFRAPStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), this.getClientTaskStatusSupport());
newFRAPStudy.setXmlFilename(inFile.getAbsolutePath());
if (!FRAPWorkspace.areExternalDataOK(localWorkspace, newFRAPStudy.getFrapDataExternalDataInfo(), newFRAPStudy.getRoiExternalDataInfo())) {
newFRAPStudy.setFrapDataExternalDataInfo(null);
newFRAPStudy.setRoiExternalDataInfo(null);
}
} else // .lsm or other image formatss
{
newFRAPStudy = FRAPWorkspace.loadFRAPDataFromImageFile(inFile, this.getClientTaskStatusSupport());
isFileLoaded = true;
}
// otherwise, popup a dialog saying the result will be invalid.
if (!batchRunWorkspace.isBatchRunResultsAvailable()) {
hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
} else if ((batchRunWorkspace.isBatchRunResultsAvailable() && inFile.getName().endsWith(VirtualFrapLoader.VFRAP_EXTENSION)) && ((newFRAPStudy.getFrapModel(batchRunWorkspace.getSelectedModel()) != null) && (newFRAPStudy.getFrapModel(batchRunWorkspace.getSelectedModel()).getModelParameters() != null))) {
// put newfrapstudy into hashtable to be used for next task
hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
} else {
String continueStr = "Remove results and continue";
String cancelStr = "Cancel loading data";
String msg = "Loading a new data file,\n or a vfrap file with no model data,\n or a vfrap file with different selected model type, \n will INVALID the existing resuls.";
String choice = DialogUtils.showWarningDialog(singleFilePanel, msg, new String[] { continueStr, cancelStr }, continueStr);
if (choice == continueStr) {
hashTable.put(CLEAR_RESULT_KEY, new Boolean(true));
hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
} else // cancel
{
throw UserCancelException.CANCEL_GENERIC;
}
}
}
};
AsynchClientTask afterLoadingSwingTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// check to see if results need to be cleared
Boolean needClear = (Boolean) hashTable.get(CLEAR_RESULT_KEY);
if (needClear != null && needClear.booleanValue()) {
double[][] oldAnalysisData = batchRunWorkspace.getAnalysisMSESummaryData();
double[][] newAnalysisData = null;
batchRunWorkspace.firePropertyChange(FRAPBatchRunWorkspace.PROPERTY_CHANGE_BATCHRUN_CLEAR_RESULTS, oldAnalysisData, newAnalysisData);
}
FRAPStudy newFRAPStudy = (FRAPStudy) hashTable.get(FRAPStudyPanel.NEW_FRAPSTUDY_KEY);
// setFrapStudy fires property change, so we have to put it in Swing thread.
getBatchRunWorkspace().getWorkingSingleWorkspace().setFrapStudy(newFRAPStudy, true);
VirtualFrapBatchRunFrame.updateProgress(0);
if (isFileLoaded) {
VirtualFrapBatchRunFrame.updateStatus("Loaded " + fileStr);
} else {
VirtualFrapBatchRunFrame.updateStatus("Failed loading " + fileStr + ".");
}
}
};
taskArrayList.add(updateUIBeforeLoadTask);
taskArrayList.add(loadTask);
taskArrayList.add(afterLoadingSwingTask);
} else {
DialogUtils.showErrorDialog(singleFilePanel, "Load File name is empty. Please input a file name to continue.");
throw new RuntimeException("Load File name is empty. Please input a file name to continue.");
}
return taskArrayList;
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class FRAPStudyPanel method showEstimateParamWizard.
private void showEstimateParamWizard() {
// check if frapOpt data is null? if yes, run ref simulation.
// check if parameters of each selected models are there, if not, run analytic solution, get best parameters and store parameters
AsynchClientTask saveTask = new AsynchClientTask("Preparing for parameter estimation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
if (fStudy.hasDiffusionOnlyModel()) {
// create optdata
if (fStudy.getFrapOptData() == null) {
if (fStudy.getStoredRefData() != null) {
getFrapWorkspace().getWorkingFrapStudy().setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, getLocalWorkspace(), fStudy.getStoredRefData()));
} else {
// check external data info
if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo())) {
// if external files are missing/currupt or ROIs are changed, create keys and save them
fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME));
fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME));
fStudy.saveROIsAsExternalData(localWorkspace, fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
fStudy.saveImageDatasetAsExternalData(localWorkspace, fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
}
// run ref sim
fStudy.setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, this.getClientTaskStatusSupport()));
fStudy.setSaveNeeded(true);
}
}
}
if (fStudy.hasReactionOnlyOffRateModel()) {
if (fStudy.getFrapOptFunc() == null) {
fStudy.setFrapOptFunc(new FRAPOptFunctions(fStudy));
}
}
}
};
AsynchClientTask runOptTask = new AsynchClientTask("Running optimization ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
if (fStudy.getSelectedModels() != null && fStudy.getSelectedModels().size() > 0) {
ArrayList<Integer> models = fStudy.getSelectedModels();
for (int i = 0; i < models.size(); i++) {
if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() == null) {
fStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF);
Parameter[] initialParams = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], fStudy.getStartingIndexForRecovery());
Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setModelParameters(bestParameters);
fStudy.setSaveNeeded(true);
}
} else if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() == null) {
fStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF);
Parameter[] initialParams = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], fStudy.getStartingIndexForRecovery());
Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setModelParameters(bestParameters);
fStudy.setSaveNeeded(true);
}
} else if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() == null) {
Parameter[] bestParameters = fStudy.getFrapOptFunc().getBestParamters(fStudy.getFrapData(), null, true);
fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].setModelParameters(bestParameters);
fStudy.setSaveNeeded(true);
}
}
}
}
}
};
AsynchClientTask evaulateCITask = new AsynchClientTask("Evaluating confidence intervals for model parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
if (fStudy.getSelectedModels() != null && fStudy.getSelectedModels().size() > 0) {
ArrayList<Integer> models = fStudy.getSelectedModels();
for (int i = 0; i < models.size(); i++) {
if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null && fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters().length > 0) {
Parameter[] currentParams = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters();
fStudy.getFrapOptData().setNumEstimatedParams(currentParams.length);
ProfileData[] profileData = null;
if (fStudy.getProfileData_oneDiffComponent() != null) {
profileData = fStudy.getProfileData_oneDiffComponent();
} else {
profileData = fStudy.getFrapOptData().evaluateParameters(currentParams, this.getClientTaskStatusSupport());
fStudy.setProfileData_oneDiffComponent(profileData);
fStudy.setSaveNeeded(true);
}
}
} else if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() != null && fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters().length > 0) {
Parameter[] currentParams = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters();
fStudy.getFrapOptData().setNumEstimatedParams(currentParams.length);
ProfileData[] profileData = null;
if (fStudy.getProfileData_twoDiffComponents() != null) {
profileData = fStudy.getProfileData_twoDiffComponents();
} else {
profileData = fStudy.getFrapOptData().evaluateParameters(currentParams, this.getClientTaskStatusSupport());
fStudy.setProfileData_twoDiffComponents(profileData);
fStudy.setSaveNeeded(true);
}
}
} else if ((models.get(i)).intValue() == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() != null && fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters().length > 0) {
Parameter[] currentParams = fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters();
ProfileData[] profileData = null;
if (fStudy.getProfileData_reactionOffRate() != null) {
profileData = fStudy.getProfileData_reactionOffRate();
} else {
profileData = fStudy.getFrapOptFunc().evaluateParameters(currentParams, this.getClientTaskStatusSupport());
fStudy.setProfileData_reactionOffRate(profileData);
fStudy.setSaveNeeded(true);
}
}
}
}
}
hashTable.put(FRAPSTUDY_KEY, fStudy);
}
};
AsynchClientTask showDialogTask = new AsynchClientTask("Showing estimation results ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// get frap models before the wizard
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
FRAPModel[] oldFrapModels = new FRAPModel[FRAPModel.NUM_MODEL_TYPES];
for (int i = 0; i < fStudy.getModels().length; i++) {
if (fStudy.getModels()[i] != null) {
FRAPModel model = fStudy.getModels()[i];
oldFrapModels[i] = new FRAPModel(new String(model.getModelIdentifer()), model.duplicateParameters(), null, model.duplicateTimePoints());
}
}
// get best model index before the wizard
Integer oldBestModelIndex = null;
if (fStudy.getBestModelIndex() != null) {
oldBestModelIndex = new Integer(fStudy.getBestModelIndex().intValue());
// put old best model index into hashtable
hashTable.put(BEST_MODEL_KEY, oldBestModelIndex);
}
// put old frapmodels in hashtable
hashTable.put(FRAPMODELS_KEY, oldFrapModels);
// show wizard
final Wizard estParamWizard = getEstimateParametersWizard();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
estParamWizard.showModalDialog(new Dimension(1000, 750));
}
});
// put wizard in hashtable in order to check return code in next task
hashTable.put(EST_PARAM_WIZARD_KEY, estParamWizard);
}
};
AsynchClientTask updateSaveStatusTask = new AsynchClientTask("...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
Wizard estParamWizard = (Wizard) hashTable.get(EST_PARAM_WIZARD_KEY);
// get old values from hashtable
FRAPModel[] oldFrapModels = (FRAPModel[]) hashTable.get(FRAPMODELS_KEY);
Integer oldBestModelIndex = (Integer) hashTable.get(BEST_MODEL_KEY);
// get new values
Integer newBestModelIndex = getFrapWorkspace().getWorkingFrapStudy().getBestModelIndex();
if (estParamWizard.getReturnCode() == Wizard.FINISH_RETURN_CODE) {
if (!getFrapWorkspace().getWorkingFrapStudy().areFRAPModelsEqual(oldFrapModels) || (oldBestModelIndex == null && newBestModelIndex != null) || (oldBestModelIndex != null && newBestModelIndex == null) || (oldBestModelIndex != null && newBestModelIndex != null && oldBestModelIndex.intValue() != newBestModelIndex.intValue())) {
getFrapWorkspace().getWorkingFrapStudy().setSaveNeeded(true);
}
}
}
};
// dispatch
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { saveTask, runOptTask, evaulateCITask, showDialogTask, updateSaveStatusTask }, true, true, true, null, true);
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class FRAPStudyPanel method saveAs.
public AsynchClientTask[] saveAs() {
AsynchClientTask beforeSaveTask = new AsynchClientTask("Saving file ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
if (getFrapWorkspace().getWorkingFrapStudy() == null || getFrapWorkspace().getWorkingFrapStudy().getFrapData() == null) {
throw new Exception("No FRAP Data exists to save");
} else {
File outputFile = null;
String saveFileName = null;
int choice = VirtualFrapLoader.saveFileChooser.showSaveDialog(FRAPStudyPanel.this);
if (choice != JFileChooser.APPROVE_OPTION) {
throw UserCancelException.CANCEL_FILE_SELECTION;
}
saveFileName = VirtualFrapLoader.saveFileChooser.getSelectedFile().getPath();
if (saveFileName != null) {
File tempOutputFile = new File(saveFileName);
if (!VirtualFrapLoader.filter_vfrap.accept(tempOutputFile)) {
if (tempOutputFile.getName().indexOf(".") == -1) {
tempOutputFile = new File(tempOutputFile.getParentFile(), tempOutputFile.getName() + "." + VirtualFrapLoader.VFRAP_EXTENSION);
} else {
// return?
throw new Exception("Virtual FRAP document names must have an extension of ." + VirtualFrapLoader.VFRAP_EXTENSION);
}
}
if (tempOutputFile.exists()) {
String overwriteChoice = DialogUtils.showWarningDialog(FRAPStudyPanel.this, "OverWrite file\n" + tempOutputFile.getAbsolutePath(), new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CANCEL);
if (overwriteChoice.equals(UserMessage.OPTION_CANCEL)) {
throw UserCancelException.CANCEL_GENERIC;
} else {
// Remove overwritten vfrap document external and simulation files
try {
MicroscopyXmlReader.ExternalDataAndSimulationInfo externalDataAndSimulationInfo = MicroscopyXmlReader.getExternalDataAndSimulationInfo(tempOutputFile);
FRAPStudy.removeExternalDataAndSimulationFiles(externalDataAndSimulationInfo.simulationKey, (externalDataAndSimulationInfo.frapDataExtDataInfo != null ? externalDataAndSimulationInfo.frapDataExtDataInfo.getExternalDataIdentifier() : null), (externalDataAndSimulationInfo.roiExtDataInfo != null ? externalDataAndSimulationInfo.roiExtDataInfo.getExternalDataIdentifier() : null), getLocalWorkspace());
} catch (Exception e) {
System.out.println("Error deleting externalData and simulation files for overwritten vfrap document " + tempOutputFile.getAbsolutePath() + " " + e.getMessage());
e.printStackTrace();
}
}
}
outputFile = tempOutputFile;
}
if (outputFile != null) {
VirtualFrapMainFrame.updateStatus("Saving file " + outputFile.getAbsolutePath() + " ...");
hashTable.put(FRAPStudyPanel.SAVE_FILE_NAME_KEY, outputFile);
}
}
}
};
AsynchClientTask saveTask = new AsynchClientTask("Saving file ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
File outFile = (File) hashTable.get(FRAPStudyPanel.SAVE_FILE_NAME_KEY);
saveProcedure(outFile, true, this.getClientTaskStatusSupport());
}
};
AsynchClientTask afterSaveAsTask = new AsynchClientTask("Saving file ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// disable simulation result button if it was enabled, because we don't copy simulation files over
getAnalysisResultsPanel().setResultsButtonEnabled(false);
// update mainframe title and progress
File outFile = (File) hashTable.get(FRAPStudyPanel.SAVE_FILE_NAME_KEY);
VirtualFrapMainFrame.updateStatus("File " + outFile.getAbsolutePath() + " has been saved.");
VirtualFrapLoader.mf.setMainFrameTitle(outFile.getName());
VirtualFrapMainFrame.updateProgress(0);
}
};
return new AsynchClientTask[] { beforeSaveTask, saveTask, afterSaveAsTask };
}
use of cbit.vcell.client.task.AsynchClientTask in project vcell by virtualcell.
the class FRAPStudyPanel method runSimulationForSelectedModel.
private void runSimulationForSelectedModel() {
AsynchClientTask prepareRunBindingReactionTask = new AsynchClientTask("Preparing to run simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
boolean bExtDataOK = FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo());
if (!bExtDataOK) {
// refresh rois
refreshROIs();
// if external files are missing/currupt or ROIs are changed, create keys and save them
fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.IMAGE_EXTDATA_NAME));
fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.ROI_EXTDATA_NAME));
try {
fStudy.saveROIsAsExternalData(getLocalWorkspace(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
fStudy.saveImageDatasetAsExternalData(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
} catch (Exception e) {
e.printStackTrace(System.out);
(getAnalysisResultsPanel()).setResultsButtonEnabled(false);
throw e;
}
}
}
};
// -------------------------------------------------------------------------
AsynchClientTask runReactionBindingTask = new AsynchClientTask("Running simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
Parameter[] bestParams = fStudy.getModels()[fStudy.getBestModelIndex().intValue()].getModelParameters();
if (bestParams.length < 3) {
return;
} else {
if (fStudy != null && fStudy.getBioModel() != null && fStudy.getBioModel().getSimulations() != null && fStudy.getBioModel().getSimulations().length > 0 && fStudy.getBioModel().getSimulations()[0].getVersion() != null && fStudy.getBioModel().getSimulations()[0].getVersion().getVersionKey() != null) {
fStudy.getBioModel().getSimulations()[0].getVersion().getVersionKey();
}
BioModel bioModel = null;
try {
bioModel = FRAPStudy.createNewSimBioModel(fStudy, bestParams, null, LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), fStudy.getStartingIndexForRecovery());
// run simulation
FRAPStudy.runFVSolverStandalone(new File(getLocalWorkspace().getDefaultSimDataDirectory()), bioModel.getSimulation(0), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), this.getClientTaskStatusSupport(), false);
fStudy.setBioModel(bioModel);
} catch (Exception e) {
if (bioModel != null && bioModel.getSimulations() != null) {
FRAPStudy.removeExternalDataAndSimulationFiles(bioModel.getSimulations()[0].getVersion().getVersionKey(), null, null, getLocalWorkspace());
(getAnalysisResultsPanel()).setResultsButtonEnabled(false);
}
throw e;
}
}
}
};
AsynchClientTask updateUITask = new AsynchClientTask("Simulation Done.", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
VirtualFrapMainFrame.updateStatus("Simulation Done. Click on \'View Spatial Results\' to see simulation results.");
(getAnalysisResultsPanel()).setResultsButtonEnabled(true);
}
};
// dispatch
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { prepareRunBindingReactionTask, runReactionBindingTask, updateUITask }, true, true, true, null, true);
}
Aggregations