use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.
the class NetworkConstraintsPanel method runBioNetGen.
private void runBioNetGen() {
EditConstraintsPanel panel = new EditConstraintsPanel(this);
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(this);
ChildWindow childWindow = childWindowManager.addChildWindow(panel, panel, "Edit / Test Constraints");
Dimension dim = new Dimension(360, 160);
childWindow.pack();
panel.setChildWindow(childWindow);
childWindow.setPreferredSize(dim);
childWindow.showModal();
int maxIterations;
int maxMolecules;
if (panel.getButtonPushed() == ActionButtons.Run) {
maxIterations = new Integer(panel.maxIterationTextField.getText());
maxMolecules = new Integer(panel.maxMolTextField.getText());
fieldSimulationContext.getNetworkConstraints().setTestConstraints(maxIterations, maxMolecules);
} else if (panel.getButtonPushed() == ActionButtons.Apply) {
activateConsole();
maxIterations = new Integer(panel.maxIterationTextField.getText());
maxMolecules = new Integer(panel.maxMolTextField.getText());
fieldSimulationContext.getNetworkConstraints().setTestConstraints(maxIterations, maxMolecules);
fieldSimulationContext.getNetworkConstraints().updateConstraintsFromTest();
// apply will invalidate everything: generated species, reactions, console, cache, etc
updateBioNetGenOutput(null);
refreshInterface();
TaskCallbackMessage tcm = new TaskCallbackMessage(TaskCallbackStatus.Clean, "");
fieldSimulationContext.appendToConsole(tcm);
String message = "Warning: The current Constraints are not tested / validated.";
tcm = new TaskCallbackMessage(TaskCallbackStatus.Warning, message);
fieldSimulationContext.appendToConsole(tcm);
message = "The Network generation may take a very long time or the generated network may be incomplete. " + "We recommend testing this set of constraints.";
tcm = new TaskCallbackMessage(TaskCallbackStatus.Notification, message);
fieldSimulationContext.appendToConsole(tcm);
return;
} else {
return;
}
// TODO: do not delete the commented code below
// uncomment the next 6 lines to keep the data in the dialogs synchronized with the most recent reaction network
// if(viewSpeciesDialog != null) {
// viewSpeciesDialog.dispose();
// }
// if(viewReactionsDialog != null) {
// viewReactionsDialog.dispose();
// }
activateConsole();
// previousIterationSpecies = 0;
synchronized (this) {
fieldSimulationContext.setMd5hash(null);
fieldSimulationContext.setMostRecentlyCreatedOutputSpec(null);
}
refreshInterface();
if (!checkBnglRequirements()) {
return;
}
NetworkTransformer transformer = new NetworkTransformer();
MathMappingCallback dummyCallback = new MathMappingCallback() {
public void setProgressFraction(float percentDone) {
}
public void setMessage(String message) {
}
public boolean isInterrupted() {
return false;
}
};
// we alter the input string to use the test values for max iterations and max molecules per species
String input = transformer.convertToBngl(fieldSimulationContext, true, dummyCallback, NetworkGenerationRequirements.ComputeFullNoTimeout);
// get rid of the default generate network command...
input = input.substring(0, input.indexOf("generate_network({"));
// ... and replace it with the "fake" one
StringWriter bnglStringWriter = new StringWriter();
PrintWriter pw = new PrintWriter(bnglStringWriter);
RbmNetworkGenerator.generateNetworkEx(maxIterations, maxMolecules, pw, fieldSimulationContext.getModel().getRbmModelContainer(), fieldSimulationContext, NetworkGenerationRequirements.ComputeFullNoTimeout);
String genNetStr = bnglStringWriter.toString();
pw.close();
input += genNetStr;
BNGInput bngInput = new BNGInput(input);
final BNGExecutorService bngService = BNGExecutorService.getInstance(bngInput, NetworkGenerationRequirements.NoTimeoutMS);
bngService.registerBngUpdaterCallback(this);
Hashtable<String, Object> hash = new Hashtable<String, Object>();
AsynchClientTask[] tasksArray = new AsynchClientTask[3];
TaskCallbackMessage message = new TaskCallbackMessage(TaskCallbackStatus.Clean, "");
fieldSimulationContext.appendToConsole(message);
tasksArray[0] = new RunBioNetGen(bngService);
tasksArray[1] = new CreateBNGOutputSpec(bngService);
tasksArray[2] = new ReturnBNGOutput(bngService, fieldSimulationContext, this);
ClientTaskDispatcher.dispatch(this, hash, tasksArray, false, true, new ProgressDialogListener() {
@Override
public void cancelButton_actionPerformed(EventObject newEvent) {
try {
bngService.stopBNG();
String s = "...user cancelled.";
TaskCallbackMessage tcm = new TaskCallbackMessage(TaskCallbackStatus.TaskStopped, s);
// message will be processed in TaskCallbackProcessor::case TaskStopped
setNewCallbackMessage(tcm);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.
the class ViewJobsPanel method refreshInterface.
private void refreshInterface() {
Hashtable<String, Object> hash = new Hashtable<String, Object>();
AsynchClientTask[] tasksArray = new AsynchClientTask[2];
tasksArray[0] = new RunQuery();
tasksArray[1] = new DisplayResults();
ClientTaskDispatcher.dispatch(this, hash, tasksArray, false, true, new ProgressDialogListener() {
@Override
public void cancelButton_actionPerformed(EventObject newEvent) {
try {
System.out.println("...user cancelled.");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.
the class FRAPOptData method main.
public static void main(String[] args) {
String workingDir = "C:\\";
LocalWorkspace localWorkspace = new LocalWorkspace(new File(workingDir));
String xmlString;
try {
// read original data from file
System.out.println("start loading original data....");
String expFileName = "C:/VirtualMicroscopy/testFastD_4_fastFrac_0p5_slowD_1_slowFrac_0p3_ImmobileFrac_0p2_mwb_0p0015_new.vfrap";
xmlString = XmlUtil.getXMLString(expFileName);
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
FRAPStudy expFrapStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
expFrapStudy.setXmlFilename(expFileName);
System.out.println("experimental data time points" + expFrapStudy.getFrapData().getImageDataset().getSizeT());
System.out.println("finish loading original data....");
// create reference data
System.out.println("creating rederence data....");
FRAPOptData optData = new FRAPOptData(expFrapStudy, 5, localWorkspace, new ClientTaskStatusSupport() {
public void setProgress(int progress) {
// TODO Auto-generated method stub
}
public void setMessage(String message) {
// TODO Auto-generated method stub
}
public boolean isInterrupted() {
// TODO Auto-generated method stub
return false;
}
public int getProgress() {
// TODO Auto-generated method stub
return 0;
}
public void addProgressDialogListener(ProgressDialogListener progressDialogListener) {
throw new RuntimeException("not yet implemented");
}
});
// trying 3 parameters
// Parameter diff = new cbit.vcell.opt.Parameter(FRAPOptData.PARAMETER_NAMES[FRAPOptData.DIFFUSION_RATE_INDEX], 0, 100, 1.0, Double.parseDouble(expFrapStudy.getFrapModelParameters().diffusionRate));
// Parameter mobileFrac = new cbit.vcell.opt.Parameter(FRAPOptData.PARAMETER_NAMES[FRAPOptData.MOBILE_FRACTION_INDEX], 0, 1, 1.0, 1/*Double.parseDouble(expFrapStudy.getFrapModelParameters().mobileFraction)*/);
// Parameter bleachWhileMonitoringRate = new cbit.vcell.opt.Parameter(FRAPOptData.PARAMETER_NAMES[FRAPOptData.BLEACH_WHILE_MONITOR_INDEX], 0, 10, 1.0, 0/*Double.parseDouble(expFrapStudy.getFrapModelParameters().monitorBleachRate)*/);
// trying 5 parameters
Parameter diffFastOffset = new cbit.vcell.opt.Parameter("fastDiffOffset", 0, 50, 1.0, 10);
Parameter mFracFast = new cbit.vcell.opt.Parameter("fastMobileFrac", 0, 1, 1.0, 0.5);
Parameter diffSlow = new cbit.vcell.opt.Parameter("slowDiffRate", 0, 10, 1.0, 0.1);
Parameter mFracSlow = new cbit.vcell.opt.Parameter("slowMobileFrac", 0, 1, 1.0, 0.5);
Parameter bleachWhileMonitoringRate = new cbit.vcell.opt.Parameter("bleachWhileMonitoringRate", 0, 20, 1.0, 0.1);
Parameter[] inParams = new Parameter[] { diffFastOffset, mFracFast, diffSlow, mFracSlow, bleachWhileMonitoringRate };
// Parameter diffFast = new cbit.vcell.opt.Parameter("fast_diff_rate", 0, 100, 1.0, 5);
// Parameter mFracFast = new cbit.vcell.opt.Parameter("fast_mobile_fraction", 0, 1, 1.0, 0.5);
// Parameter diffSlowFactor = new cbit.vcell.opt.Parameter("slow_diff_factor", 0, 1, 1.0, 0.2);
// Parameter mFracSlow = new cbit.vcell.opt.Parameter("slow_mobile_fraction", 0, 1, 1.0, 0.5);
// Parameter bleachWhileMonitoringRate = new cbit.vcell.opt.Parameter("bleach_while_monitoring_rate", 0, 1, 1.0, 0.1);
// Parameter[] inParams = new Parameter[]{diffFast, mFracFast, diffSlowFactor, mFracSlow, bleachWhileMonitoringRate};
// add some constraints, like fast mobile fraction + slow mobile fraction should smaller than 1.
// slower rate should be 5 times smaller than fast rate.....??? 5*slowDiffRate < fastDiffRate
// Expression exp1 = new Expression("("+mFracFast.getName()+" + "+mFracSlow.getName()+" - 1)");
// Constraint con1 = new Constraint(ConstraintType.LinearInequality, exp1);
// Expression exp2 = new Expression("( 4 * "+diffSlow.getName()+" - "+ diffFastOffset.getName() +")");
// Constraint con2 = new Constraint(ConstraintType.LinearInequality, exp2);
// Constraint[] cons = new Constraint[2];
// cons[0] = con1;
// cons[1] = con2;
ROI[] rois = expFrapStudy.getFrapData().getRois();
boolean[] errorOfInterest = new boolean[rois.length];
for (int i = 0; i < rois.length; i++) {
if (/*!rois[i].getROIType().equals(RoiType.ROI_BLEACHED)*/
rois[i].getROIName().equals(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()) || rois[i].getROIName().equals(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name())) {
errorOfInterest[i] = false;
} else {
errorOfInterest[i] = true;
}
}
optData.getBestParamters(inParams, errorOfInterest);
// double[][] result = optData.getFitData(inParams, errorOfInterest); // double[roiLen][timePoints]
// int indexROI = -1;
// for(int j = 0; j < expFrapStudy.getFrapData().getRois().length; j++)
// {
// if(expFrapStudy.getFrapData().getRois()[j].getROIType().equals(RoiType.ROI_BLEACHED))
// {
// indexROI = j;
// break;
// }
// }
// int index = Integer.parseInt(expFrapStudy.getFrapModelParameters().startIndexForRecovery);
// for(int i = 0; i < (expFrapStudy.getFrapData().getImageDataset().getImageTimeStamps().length - index); i++)
// {
// System.out.println(expFrapStudy.getFrapData().getImageDataset().getImageTimeStamps()[i+index]+"\t"+result[indexROI][i]);
// }
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.
the class FRAPParamTest method runProfileLikelihood.
public void runProfileLikelihood() {
String errorMsg = checkFrapStudyValidity();
if (!errorMsg.equals("")) {
System.out.println("Application terminated due to " + errorMsg);
System.exit(1);
} else {
try {
ClientTaskStatusSupport ctss = new ClientTaskStatusSupport() {
public void setProgress(int progress) {
System.out.println(progress);
}
public void setMessage(String message) {
System.out.println(message);
}
public boolean isInterrupted() {
// TODO Auto-generated method stub
return false;
}
public int getProgress() {
// TODO Auto-generated method stub
return 0;
}
public void addProgressDialogListener(ProgressDialogListener progressDialogListener) {
throw new RuntimeException("not yet implemented");
}
};
// get startign index
if (frapStudy.getStartingIndexForRecovery() == null) {
int index = FRAPDataAnalysis.calculateRecoveryIndex(frapStudy.getFrapData());
frapStudy.setStartingIndexForRecovery(index);
}
// get dependent rois
if (frapStudy.getFrapData().getRois().length < 4) {
frapStudy.refreshDependentROIs();
}
// get selected ROIs
if (frapStudy.getSelectedROIsForErrorCalculation() == null) {
boolean[] selectedROIs = new boolean[FRAPData.VFRAP_ROI_ENUM.values().length];
int counter = 0;
for (FRAPData.VFRAP_ROI_ENUM roiEnum : FRAPData.VFRAP_ROI_ENUM.values()) {
if (roiEnum.name().equals(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()) || roiEnum.name().equals(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name())) {
counter++;
continue;
}
if (frapStudy.getFrapData().getRoi(roiEnum.name()).getNonzeroPixelsCount() > 0) {
selectedROIs[counter] = true;
counter++;
}
}
frapStudy.setSelectedROIsForErrorCalculation(selectedROIs);
}
// get frap opt data
if (frapStudy.getFrapOptData() == null) {
if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), frapStudy.getFrapDataExternalDataInfo(), frapStudy.getRoiExternalDataInfo())) {
// if external files are missing/currupt or ROIs are changed, create keys and save them
frapStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME));
frapStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME));
frapStudy.saveROIsAsExternalData(localWorkspace, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
frapStudy.saveImageDatasetAsExternalData(localWorkspace, frapStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
}
// run ref sim
frapStudy.setFrapOptData(new FRAPOptData(frapStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, ctss));
}
FRAPOptData optData = frapStudy.getFrapOptData();
// create frapModels
if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] == null) {
frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] = new FRAPModel(FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], null, null, null);
if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() == null) {
frapStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF);
Parameter[] initialParams = FRAPModel.getInitialParameters(frapStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], frapStudy.getStartingIndexForRecovery());
Parameter[] bestParameters = frapStudy.getFrapOptData().getBestParamters(initialParams, frapStudy.getSelectedROIsForErrorCalculation());
frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setModelParameters(bestParameters);
}
}
if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] == null) {
frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] = new FRAPModel(FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], null, null, null);
if (frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() == null) {
frapStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF);
Parameter[] initialParams = FRAPModel.getInitialParameters(frapStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], frapStudy.getStartingIndexForRecovery());
Parameter[] bestParameters = frapStudy.getFrapOptData().getBestParamters(initialParams, frapStudy.getSelectedROIsForErrorCalculation());
frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setModelParameters(bestParameters);
}
}
// try diffusion with one diffusing component model
System.out.println("Evaluating parameters in diffusion with one diffusing compoent model...");
Parameter[] bestParameters = frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters();
ProfileData[] profileData = optData.evaluateParameters(bestParameters, ctss);
// output profile likelihood
File outputDir_oneComponent = new File(getLocalWorkspace().getDefaultWorkspaceDirectory() + SUB_DIRECTORY + "OneComponent_SAVED_AT_" + BeanUtils.generateDateTimeString() + System.getProperty("file.separator"));
if (!outputDir_oneComponent.exists()) {
outputDir_oneComponent.mkdirs();
}
for (int i = 0; i < profileData.length; i++) {
ProfileDataElement profileDataElement = profileData[i].getProfileDataElements().get(0);
outputProfileLikelihood(profileData[i].getProfileDataElements(), profileDataElement.getParamName(), outputDir_oneComponent);
}
// try diffusion with two diffusing components model
System.out.println("Evaluating parameters in diffusion with two diffusing compoents model...");
bestParameters = frapStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters();
profileData = optData.evaluateParameters(bestParameters, ctss);
// output profile likelihood
File outputDir_twoComponents = new File(getLocalWorkspace().getDefaultWorkspaceDirectory() + SUB_DIRECTORY + "TwoComponents_SAVED_AT_" + BeanUtils.generateDateTimeString() + System.getProperty("file.separator"));
if (!outputDir_twoComponents.exists()) {
outputDir_twoComponents.mkdirs();
}
for (int i = 0; i < profileData.length; i++) {
ProfileDataElement profileDataElement = profileData[i].getProfileDataElements().get(0);
outputProfileLikelihood(profileData[i].getProfileDataElements(), profileDataElement.getParamName(), outputDir_twoComponents);
}
} catch (Exception e) {
e.printStackTrace(System.out);
System.exit(1);
}
}
}
use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.
the class KenworthyWorkflowTest method main.
public static void main(String[] args) {
try {
File baseDir = new File(".");
// File baseDir = new File("/Users/schaff/Documents/workspace/VCell_5.4");
// initialize computing environment
//
File workingDirectory = new File(baseDir, "workingDir");
LocalWorkspace localWorkspace = new LocalWorkspace(workingDirectory);
//
// import raw image time series data from VFRAP file format (can have noise, background, etc ... can be actual microscopy data)
//
ClientTaskStatusSupport progressListener = new ClientTaskStatusSupport() {
String message = "";
int progress = 0;
@Override
public void setProgress(int progress) {
this.progress = progress;
}
@Override
public void setMessage(String message) {
this.message = message;
}
@Override
public boolean isInterrupted() {
return false;
}
@Override
public int getProgress() {
return progress;
}
@Override
public void addProgressDialogListener(ProgressDialogListener progressDialogListener) {
}
};
//
// generate fake data (and save?)
//
// ImageTimeSeries<UShortImage> simulatedFluorescence = generateFakeData(localWorkspace, progressListener);
// new ExportRawTimeSeriesToVFrapOp().exportToVFRAP(vfrapFile, simulatedFluorescence, null);
//
// analyze raw data (from file?) using Keyworthy method.
//
File vfrapFile = new File(baseDir, "vfrapPaper/rawData/sim3/workflow.txt.save");
// File vfrapFile = new File(baseDir, "tryit.vfrap");
ImageTimeSeries<UShortImage> fluorTimeSeriesImages = new ImportRawTimeSeriesFromVFrapOp().importRawTimeSeriesFromVFrap(vfrapFile);
analyzeKeyworthy(fluorTimeSeriesImages, localWorkspace);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
Aggregations