use of cbit.vcell.microscopy.FRAPOptData 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.microscopy.FRAPOptData in project vcell by virtualcell.
the class BatchRunDetailsPanel method actionPerformed.
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
if (source == addButton) {
// check file before loading into batch run, if the file has .vfrap extension
// check if it has the model that is required by the batch run, if no, run the reference simulation and get the parameters
final Wizard loadWizard = getAddFRAPDataWizard();
if (loadWizard != null) {
loadWizard.showModalDialog(new Dimension(550, 640));
// code return
if (loadWizard.getReturnCode() == Wizard.FINISH_RETURN_CODE) {
// get newly added frapstudy
FRAPStudy fStudy = getBatchRunWorkspace().getWorkingFrapStudy();
// check if the batch run has results already and the newly loaded data should have same model ready
int batchRunSelectedModel = getBatchRunWorkspace().getSelectedModel();
if (getBatchRunWorkspace().isBatchRunResultsAvailable() && fStudy.getModels()[batchRunSelectedModel] != null && fStudy.getFrapModel(batchRunSelectedModel).getModelParameters() != null) {
Parameter[] parameters = fStudy.getFrapModel(batchRunSelectedModel).getModelParameters();
double[][] fitData = null;
if (batchRunSelectedModel == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT || batchRunSelectedModel == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
FRAPOptData optData = fStudy.getFrapOptData();
// newly loaded frapstudy doesn't have estimation data ready, generate the data
if (optData == null) {
try {
optData = new FRAPOptData(fStudy, parameters.length, getLocalWorkspace(), fStudy.getStoredRefData());
fStudy.setFrapOptData(optData);
fitData = optData.getFitData(parameters);
} catch (Exception ex) {
ex.printStackTrace(System.out);
DialogUtils.showErrorDialog(BatchRunDetailsPanel.this, ex.getMessage());
}
}
} else if (batchRunSelectedModel == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
FRAPOptFunctions optFunc = fStudy.getFrapOptFunc();
if (optFunc == null) {
try {
optFunc = new FRAPOptFunctions(fStudy);
fStudy.setFrapOptFunc(optFunc);
fitData = optFunc.getFitData(parameters);
} catch (Exception ex2) {
ex2.printStackTrace();
DialogUtils.showErrorDialog(BatchRunDetailsPanel.this, ex2.getMessage());
}
}
}
fStudy.getModels()[batchRunSelectedModel].setData(fitData);
// add new data into the frapStudy list in batch run.
getBatchRunWorkspace().addFrapStudy(fStudy);
// refresh the results
getBatchRunWorkspace().refreshBatchRunResults();
} else // batch run has no results, simply add the frapStudy into
{
getBatchRunWorkspace().addFrapStudy(fStudy);
}
// set save flag true when a doc has been added successfully
getBatchRunWorkspace().setSaveNeeded(true);
// update tree
DefaultMutableTreeNode newNode = frapBatchRunViewTree.addBatchRunDocNode(new File(getBatchRunWorkspace().getWorkingFrapStudy().getXmlFilename()));
// get the new tree node after sorting
newNode = frapBatchRunViewTree.orderFRAPDocChildren(newNode);
frapBatchRunViewTree.setSelectionPath(new TreePath(newNode.getPath()));
} else {
// load data unsuccessfully, remove the displayed image
getBatchRunWorkspace().clearWorkingSingleWorkspace();
// clear tree selection
frapBatchRunViewTree.clearSelection();
// clear stored tree selection
batchRunWorkspace.clearStoredTreeSelection();
}
}
} else if (source == deleteButton) {
AsynchClientTask deleteFromWorkspaceTask = new AsynchClientTask("deleting file ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// remove tree node(doc node removable only)
DefaultMutableTreeNode parent = frapBatchRunViewTree.removeCurrentNode();
// handle differently for doc node and results node
if (// doc node
parent.equals(BatchRunTree.FRAP_BATCHRUN_DOC_NODE)) {
// remove the data & displayed image
getBatchRunWorkspace().removeFrapStudy(getBatchRunWorkspace().getWorkingFrapStudy());
} else if (// results node
parent.equals(BatchRunTree.FRAP_BATCHRUN_RESULT_NODE)) {
getBatchRunWorkspace().clearResultData();
}
getBatchRunWorkspace().clearWorkingSingleWorkspace();
}
};
AsynchClientTask deleteFromUITask = new AsynchClientTask("deleting file ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// clear tree selection
frapBatchRunViewTree.clearSelection();
if (batchRunWorkspace.getFrapStudies() == null || batchRunWorkspace.getFrapStudies().size() < 1) {
frapBatchRunViewTree.clearAll();
} else // if doc has been deleted successfully and frapStudyList still has doc, set save flag true.
{
batchRunWorkspace.setSaveNeeded(true);
}
batchRunWorkspace.clearStoredTreeSelection();
// clear parameter display
clearParameterDisplay();
}
};
ClientTaskDispatcher.dispatch(BatchRunDetailsPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { deleteFromWorkspaceTask, deleteFromUITask }, false, false, false, null, true);
} else if (source == delAllButton) {
deleteAllBatchrunDocs();
}
}
use of cbit.vcell.microscopy.FRAPOptData in project vcell by virtualcell.
the class VirtualFrapBatchRunFrame method getBatchRunTasks.
private ArrayList<AsynchClientTask> getBatchRunTasks() {
// to run batch files
ArrayList<AsynchClientTask> batchRunTaskList = new ArrayList<AsynchClientTask>();
for (int i = 0; i < batchRunWorkspace.getFrapStudies().size(); i++) {
final int finalIdx = i;
AsynchClientTask message1Task = new AsynchClientTask("Preparing for parameter estimation ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
appendJobStatus("<html><br>Running " + (batchRunWorkspace.getFrapStudies().get(finalIdx)).getXmlFilename() + "</html>", false);
}
};
AsynchClientTask saveTask = new AsynchClientTask("Preparing for parameter estimation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
if (fStudy.hasDiffusionOnlyModel()) {
// check external data info. If not existing, we have to run ref simulation.
if (!FRAPWorkspace.areExternalDataOK(localWorkspace, 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());
}
}
}
};
AsynchClientTask message2Task = new AsynchClientTask("Running reference simulation ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
if (fStudy.hasDiffusionOnlyModel()) {
MessagePanel msgPanel = appendJobStatus("Running reference simulation ...", true);
hashTable.put("runRefStatus", msgPanel);
} else if (fStudy.hasReactionOnlyOffRateModel()) {
// MessagePanel msgPanel = appendJobStatus("...", true);
// hashTable.put("runRefStatus", msgPanel);
}
}
};
AsynchClientTask runRefSimTask = new AsynchClientTask("Running reference simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
if (fStudy.hasDiffusionOnlyModel()) {
MessagePanel msgPanel = (MessagePanel) hashTable.get("runRefStatus");
// run ref sim
if (// if ref data is stored ,we don't have to re-run
fStudy.getStoredRefData() != null) {
fStudy.setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, fStudy.getStoredRefData()));
} else {
fStudy.setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, msgPanel));
}
} else if (fStudy.hasReactionOnlyOffRateModel()) {
if (fStudy.getFrapOptFunc() == null) {
fStudy.setFrapOptFunc(new FRAPOptFunctions(fStudy));
}
}
}
};
AsynchClientTask message3Task = new AsynchClientTask("Running optimization ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
if (fStudy.hasDiffusionOnlyModel()) {
MessagePanel msgPanel = (MessagePanel) hashTable.get("runRefStatus");
msgPanel.setProgressCompleted();
}
MessagePanel msgPanel1 = appendJobStatus("Running optimization ...", true);
hashTable.put("optimizationStatus", msgPanel1);
}
};
AsynchClientTask runOptTask = new AsynchClientTask("Running optimization ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
ArrayList<Integer> models = fStudy.getSelectedModels();
if (models.size() == 1) {
for (int i = 0; i < models.size(); i++) {
int model = (models.get(i)).intValue();
if (model == batchRunWorkspace.getSelectedModel()) {
if (model == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
// if(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() == null)
// {//always run
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());
// set model parameters and data
Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
double[][] fitData = fStudy.getFrapOptData().getFitData(bestParameters);
fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setModelParameters(bestParameters);
fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setData(fitData);
// }
} else if (model == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
// if(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() == null)
// {//always run
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());
// set model parameters and data
Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
double[][] fitData = fStudy.getFrapOptData().getFitData(bestParameters);
fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setModelParameters(bestParameters);
fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setData(fitData);
// }
} else if (model == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
Parameter[] bestParameters = fStudy.getFrapOptFunc().getBestParamters(fStudy.getFrapData(), null, true);
double[][] fitData = fStudy.getFrapOptFunc().getFitData(bestParameters);
fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].setModelParameters(bestParameters);
fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].setData(fitData);
}
} else {
throw new Exception("Selected model for batch run is not the same as selected model in FRAP doc " + fStudy.getXmlFilename());
}
}
} else {
throw new Exception("Selected model size exceed 1");
}
}
};
AsynchClientTask message4Task = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
MessagePanel msgPanel = (MessagePanel) hashTable.get("optimizationStatus");
msgPanel.setProgressCompleted();
MessagePanel msgPanel2 = appendJobStatus("Evaluating confidence intervals for parameters ...", true);
hashTable.put("evaluateCI", msgPanel2);
}
};
AsynchClientTask evaluateCITask = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
MessagePanel msgPanel = (MessagePanel) hashTable.get("evaluateCI");
// evaluate confidence intervals
ArrayList<Integer> models = fStudy.getSelectedModels();
if (models.size() == 1) {
for (int i = 0; i < models.size(); i++) {
int model = (models.get(i)).intValue();
if (model == batchRunWorkspace.getSelectedModel()) {
if (model == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null) {
ProfileData[] profileData = fStudy.getFrapOptData().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters(), msgPanel);
fStudy.setProfileData_oneDiffComponent(profileData);
}
} else if (model == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() != null) {
ProfileData[] profileData = fStudy.getFrapOptData().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters(), msgPanel);
fStudy.setProfileData_twoDiffComponents(profileData);
}
} else if (model == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
if (fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() != null) {
ProfileData[] profileData = fStudy.getFrapOptFunc().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters(), msgPanel);
fStudy.setProfileData_reactionOffRate(profileData);
}
}
} else {
throw new Exception("Selected model for batch run is not the same as selected model in FRAP doc " + fStudy.getXmlFilename());
}
}
} else {
throw new Exception("Selected model size exceed 1");
}
}
};
AsynchClientTask message5Task = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
MessagePanel msgPanel = (MessagePanel) hashTable.get("evaluateCI");
msgPanel.setProgressCompleted();
}
};
batchRunTaskList.add(message1Task);
batchRunTaskList.add(saveTask);
batchRunTaskList.add(message2Task);
batchRunTaskList.add(runRefSimTask);
batchRunTaskList.add(message3Task);
batchRunTaskList.add(runOptTask);
batchRunTaskList.add(message4Task);
batchRunTaskList.add(evaluateCITask);
batchRunTaskList.add(message5Task);
}
return batchRunTaskList;
}
use of cbit.vcell.microscopy.FRAPOptData in project vcell by virtualcell.
the class FRAPBatchRunWorkspace method getLoadSingleFilesTask.
// get client task for loading each single vfrap files in a batch run
public AsynchClientTask getLoadSingleFilesTask(LocalWorkspace arg_localWorkspace) {
final LocalWorkspace localWorkspace = arg_localWorkspace;
AsynchClientTask openSingleFilesTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPBatchRunWorkspace tempBatchRunWorkspace = (FRAPBatchRunWorkspace) hashTable.get(BATCH_RUN_WORKSPACE_KEY);
if (tempBatchRunWorkspace != null) {
ArrayList<FRAPStudy> fStudyList = tempBatchRunWorkspace.getFrapStudies();
int size = fStudyList.size();
for (int i = 0; i < size; i++) {
String fileName = fStudyList.get(i).getXmlFilename();
File fStudyFile = new File(fileName);
if (// .vfrap
fileName.endsWith("." + VirtualFrapLoader.VFRAP_EXTENSION) || fileName.endsWith(".xml")) {
this.getClientTaskStatusSupport().setMessage("Loading(.vfrap) " + (i + 1) + " of " + size + " : " + fileName);
FRAPStudy newFRAPStudy = null;
String xmlString = XmlUtil.getXMLString(fStudyFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
newFRAPStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), this.getClientTaskStatusSupport());
// if((newFRAPStudy.getFrapDataExternalDataInfo() != null || newFRAPStudy.getRoiExternalDataInfo() != null) &&
// !FRAPWorkspace.areExternalDataOK(localWorkspace,newFRAPStudy.getFrapDataExternalDataInfo(),newFRAPStudy.getRoiExternalDataInfo()))
// {
// throw new Exception("External Files of Frap Document " + fStudyFile.getAbsolutePath() + " are corrupted");
// }
newFRAPStudy.setXmlFilename(fileName);
// get dimentsion reduced experimental data
newFRAPStudy.getDimensionReducedExpData();
// restore the dimension reduced fitting data(2 dimensional array).
int selectedModelIdx = tempBatchRunWorkspace.getSelectedModel();
FRAPModel frapModel = newFRAPStudy.getFrapModel(selectedModelIdx);
// optimization was done but data wasn't save with file, need to restore data
if (frapModel != null && frapModel.getModelParameters() != null && frapModel.getModelParameters().length > 0 && frapModel.getData() == null) {
if (frapModel.getModelIdentifer().equals(FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_REACTION_OFF_RATE])) {
FRAPOptFunctions frapOptFunc = new FRAPOptFunctions(newFRAPStudy);
newFRAPStudy.setFrapOptFunc(frapOptFunc);
frapModel.setData(frapOptFunc.getFitData(frapModel.getModelParameters()));
} else {
FRAPOptData optData = new FRAPOptData(newFRAPStudy, frapModel.getModelParameters().length, localWorkspace, newFRAPStudy.getStoredRefData());
newFRAPStudy.setFrapOptData(optData);
frapModel.setData(optData.getFitData(frapModel.getModelParameters()));
}
}
tempBatchRunWorkspace.getFrapStudies().remove(i);
tempBatchRunWorkspace.getFrapStudies().add(i, newFRAPStudy);
}
}
// save loaded tempBatchRunWorkspace to hashtable
hashTable.put(BATCH_RUN_WORKSPACE_KEY, tempBatchRunWorkspace);
}
}
};
return openSingleFilesTask;
}
Aggregations