use of org.vcell.vmicro.workflow.data.OptContext in project vcell by virtualcell.
the class Generate2DOptContext method compute0.
@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws ExpressionException {
// get inputs
RowColumnResultSet normExpDataset = context.getData(normExpData);
RowColumnResultSet measurementErrorDataset = context.getData(normalizedMeasurementErrors);
OptModel optmodel = context.getData(optModel);
// do op
Generate2DOptContextOp op = new Generate2DOptContextOp();
ErrorFunction errorFunction = context.getData(this.errorFunction);
OptContext optcontext = op.generate2DOptContext(optmodel, normExpDataset, measurementErrorDataset, errorFunction);
// set output
context.setData(optContext, optcontext);
}
use of org.vcell.vmicro.workflow.data.OptContext in project vcell by virtualcell.
the class OptModelParamPanel method computeProfileLikelihood.
public void computeProfileLikelihood() {
final Repository repository = new MemoryRepository();
Workflow workflow = new Workflow("profileLikelihoodWorkflow");
final TaskContext context = new TaskContext(workflow, repository, localWorkspace);
System.err.println("OptModelParamPanel.showParameterEvaluation(): how do we pass in the initial guess to ProfileLikelihood code??? should be an independent input to ProfileLikelihood so that it is explicit ... and OptContext is immutable.????");
final RunProfileLikelihoodGeneral runProfileLikelihoodGeneral = new RunProfileLikelihoodGeneral("internal");
WorkflowParameter<OptContext> optContextParam = workflow.addParameter(OptContext.class, "optContext", repository, optContext);
workflow.connectParameter(optContextParam, runProfileLikelihoodGeneral.optContext);
workflow.addTask(runProfileLikelihoodGeneral);
final DisplayProfileLikelihoodPlots displayProfileLikelihoodPlots = new DisplayProfileLikelihoodPlots("displayProfileLikihood");
workflow.connect2(runProfileLikelihoodGeneral.profileData, displayProfileLikelihoodPlots.profileData);
WorkflowParameter<String> titleParam = workflow.addParameter(String.class, "title", repository, "profile likelihood");
workflow.connectParameter(titleParam, displayProfileLikelihoodPlots.title);
workflow.addTask(displayProfileLikelihoodPlots);
AsynchClientTask evaluateTask = new AsynchClientTask("Prepare to evaluate parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
runProfileLikelihoodGeneral.compute(context, getClientTaskStatusSupport());
}
};
AsynchClientTask showResultTask = new AsynchClientTask("Showing profile likelihood and confidence intervals ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
displayProfileLikelihoodPlots.compute(context, getClientTaskStatusSupport());
}
};
// dispatch
ClientTaskDispatcher.dispatch(OptModelParamPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { evaluateTask, showResultTask }, false, true, null, true);
}
use of org.vcell.vmicro.workflow.data.OptContext in project vcell by virtualcell.
the class PhotoactivationExperimentTest method analyzePhotoactivation.
/**
* Fits raw image time series data to uniform disk models (with Guassian or Uniform fluorescence).
*
* @param rawTimeSeriesImages
* @param localWorkspace
* @throws Exception
*/
private static void analyzePhotoactivation(ImageTimeSeries<UShortImage> rawTimeSeriesImages, LocalWorkspace localWorkspace) throws Exception {
//
// correct the timestamps (1 per second).
//
double[] timeStamps = rawTimeSeriesImages.getImageTimeStamps();
for (int i = 0; i < timeStamps.length; i++) {
timeStamps[i] = i;
}
new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeriesImages, "raw images", (WindowListener) null);
ImageTimeSeries<UShortImage> blurredRaw = blurTimeSeries(rawTimeSeriesImages);
new DisplayTimeSeriesOp().displayImageTimeSeries(blurredRaw, "blurred raw images", (WindowListener) null);
double cellThreshold = 0.4;
GeometryRoisAndActivationTiming cellROIresults = new GenerateCellROIsFromRawPhotoactivationTimeSeriesOp().generate(blurredRaw, cellThreshold);
ROI backgroundROI = cellROIresults.backgroundROI_2D;
ROI cellROI = cellROIresults.cellROI_2D;
int indexOfFirstPostactivation = cellROIresults.indexOfFirstPostactivation;
boolean backgroundSubtract = false;
boolean normalizeByPreActivation = false;
NormalizedPhotoactivationDataResults normResults = new GenerateNormalizedPhotoactivationDataOp().generate(rawTimeSeriesImages, backgroundROI, indexOfFirstPostactivation, backgroundSubtract, normalizeByPreActivation);
ImageTimeSeries<FloatImage> normalizedTimeSeries = normResults.normalizedPhotoactivationData;
FloatImage preactivationAvg = normResults.preactivationAverageImage;
FloatImage normalizedPostactivation = normalizedTimeSeries.getAllImages()[0];
new DisplayTimeSeriesOp().displayImageTimeSeries(normalizedTimeSeries, "normalized images", (WindowListener) null);
//
// create a single bleach ROI by thresholding
//
double activatedThreshold = 1000;
ROI activatedROI = new GenerateActivationRoiOp().generateActivatedRoi(blurredRaw.getAllImages()[indexOfFirstPostactivation], cellROI, activatedThreshold);
new DisplayImageOp().displayImage(activatedROI.getRoiImages()[0], "activated roi", null);
new DisplayImageOp().displayImage(cellROI.getRoiImages()[0], "cell roi", null);
new DisplayImageOp().displayImage(backgroundROI.getRoiImages()[0], "background roi", null);
{
//
// only use bleach ROI for fitting etc.
//
NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI) };
//
// get reduced data and errors for each ROI
//
RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
DisplayPlotOp displayReducedData = new DisplayPlotOp();
displayReducedData.displayPlot(reducedData, "reduced data", null);
DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
displayMeasurementError.displayPlot(measurementErrors, "measurement error", null);
//
// 2 parameter uniform disk model
//
Parameter tau = new Parameter("tau", 0.001, 200.0, 1.0, 0.1);
Parameter f_init = new Parameter("f_init", 0.5, 4000, 1.0, 1.0);
Parameter f_final = new Parameter("f_final", 0.01, 4000, 1.0, 0.5);
Parameter[] parameters = new Parameter[] { tau, f_init, f_final };
OptModel optModel = new OptModel("photoactivation (activated roi)", parameters) {
@Override
public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
double tau = newParams[0];
double max = newParams[1];
double offset = newParams[2];
double[][] solution = new double[1][solutionTimePoints.length];
for (int i = 0; i < solution[0].length; i++) {
double t = solutionTimePoints[i];
solution[0][i] = offset + (max - offset) * Math.exp(-t / tau);
}
return solution;
}
@Override
public double getPenalty(double[] parameters2) {
return 0;
}
};
ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated ROI only", null);
}
{
//
// only activation ROI for chemistry, cellROI for bleaching
//
NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI), NormalizedSampleFunction.fromROI(cellROI) };
//
// get reduced data and errors for each ROI
//
RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
DisplayPlotOp displayReducedData = new DisplayPlotOp();
displayReducedData.displayPlot(reducedData, "reduced data (2)", null);
DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
displayMeasurementError.displayPlot(measurementErrors, "measurement error (2)", null);
//
// 2 parameter uniform disk model
//
Parameter tau_active = new Parameter("tau_active", 0.001, 200.0, 1.0, 0.1);
Parameter f_active_init = new Parameter("f_active_init", 0.5, 4000, 1.0, 1.0);
Parameter f_active_amplitude = new Parameter("f_active_amplitude", 0.01, 4000, 1.0, 0.5);
Parameter f_cell_init = new Parameter("f_cell_init", 0.01, 4000, 1.0, 0.1);
Parameter f_cell_amplitude = new Parameter("f_cell_amplitude", 0.01, 4000, 1.0, 0.1);
Parameter tau_cell = new Parameter("tau_cell", 0.00001, 200, 1.0, 1);
Parameter[] parameters = new Parameter[] { tau_active, f_active_init, f_active_amplitude, tau_cell, f_cell_init, f_cell_amplitude };
OptModel optModel = new OptModel("photoactivation (activated and cell rois)", parameters) {
@Override
public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
double tau_active = newParams[0];
double max_active = newParams[1];
double amplitude_active = newParams[2];
double tau_cell = newParams[3];
double max_cell = newParams[4];
double amplitude_cell = newParams[5];
final int ACTIVE_ROI = 0;
final int CELL_ROI = 1;
final int NUM_ROIS = 2;
double[][] solution = new double[NUM_ROIS][solutionTimePoints.length];
for (int i = 0; i < solution[0].length; i++) {
double t = solutionTimePoints[i];
solution[ACTIVE_ROI][i] = (max_active - amplitude_active) + (amplitude_active) * Math.exp(-t / tau_active) * Math.exp(-t / tau_cell);
solution[CELL_ROI][i] = (max_cell - amplitude_cell) + (amplitude_cell) * Math.exp(-t / tau_cell);
}
return solution;
}
@Override
public double getPenalty(double[] parameters2) {
return 0;
}
};
ErrorFunctionNoiseWeightedL2 errorFunction = new ErrorFunctionNoiseWeightedL2();
OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated and cell ROIs", null);
}
}
use of org.vcell.vmicro.workflow.data.OptContext in project vcell by virtualcell.
the class VFrapProcess method compute.
public static VFrapProcessResults compute(ImageTimeSeries rawTimeSeriesImages, double bleachThreshold, double cellThreshold, LocalWorkspace localWorkspace, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
GenerateCellROIsFromRawFrapTimeSeriesOp generateCellROIs = new GenerateCellROIsFromRawFrapTimeSeriesOp();
GeometryRoisAndBleachTiming geometryAndTiming = generateCellROIs.generate(rawTimeSeriesImages, cellThreshold);
GenerateNormalizedFrapDataOp generateNormalizedFrapData = new GenerateNormalizedFrapDataOp();
NormalizedFrapDataResults normalizedFrapResults = generateNormalizedFrapData.generate(rawTimeSeriesImages, geometryAndTiming.backgroundROI_2D, geometryAndTiming.indexOfFirstPostbleach);
GenerateBleachRoiOp generateROIs = new GenerateBleachRoiOp();
ROI bleachROI = generateROIs.generateBleachRoi(normalizedFrapResults.normalizedFrapData.getAllImages()[0], geometryAndTiming.cellROI_2D, bleachThreshold);
GenerateDependentImageROIsOp generateDependentROIs = new GenerateDependentImageROIsOp();
ROI[] dataROIs = generateDependentROIs.generate(geometryAndTiming.cellROI_2D, bleachROI);
NormalizedSampleFunction[] roiSampleFunctions = new NormalizedSampleFunction[dataROIs.length];
for (int i = 0; i < dataROIs.length; i++) {
roiSampleFunctions[i] = NormalizedSampleFunction.fromROI(dataROIs[i]);
}
GenerateReducedDataOp generateReducedNormalizedData = new GenerateReducedDataOp();
RowColumnResultSet reducedData = generateReducedNormalizedData.generateReducedData(normalizedFrapResults.normalizedFrapData, roiSampleFunctions);
ComputeMeasurementErrorOp computeMeasurementError = new ComputeMeasurementErrorOp();
RowColumnResultSet measurementError = computeMeasurementError.computeNormalizedMeasurementError(roiSampleFunctions, geometryAndTiming.indexOfFirstPostbleach, rawTimeSeriesImages, normalizedFrapResults.prebleachAverage, clientTaskStatusSupport);
GenerateTrivial2DPsfOp psf_2D = new GenerateTrivial2DPsfOp();
UShortImage psf = psf_2D.generateTrivial2D_Psf();
// RunRefSimulationOp runRefSimulationFull = new RunRefSimulationOp();
// GenerateReducedROIDataOp generateReducedRefSimData = new GenerateReducedROIDataOp();
RunRefSimulationFastOp runRefSimulationFast = new RunRefSimulationFastOp();
RowColumnResultSet refData = runRefSimulationFast.runRefSimFast(geometryAndTiming.cellROI_2D, normalizedFrapResults.normalizedFrapData, dataROIs, psf, localWorkspace, clientTaskStatusSupport);
final double refDiffusionRate = 1.0;
double[] refSimTimePoints = refData.extractColumn(0);
int numRois = refData.getDataColumnCount() - 1;
int numRefSimTimes = refData.getRowCount();
double[][] refSimData = new double[numRois][numRefSimTimes];
for (int roi = 0; roi < numRois; roi++) {
double[] roiData = refData.extractColumn(roi + 1);
for (int t = 0; t < numRefSimTimes; t++) {
refSimData[roi][t] = roiData[t];
}
}
ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
OptModelOneDiff optModelOneDiff = new OptModelOneDiff(refSimData, refSimTimePoints, refDiffusionRate);
Generate2DOptContextOp generate2DOptContextOne = new Generate2DOptContextOp();
OptContext optContextOneDiff = generate2DOptContextOne.generate2DOptContext(optModelOneDiff, reducedData, measurementError, errorFunction);
RunProfileLikelihoodGeneralOp runProfileLikelihoodOne = new RunProfileLikelihoodGeneralOp();
ProfileData[] profileDataOne = runProfileLikelihoodOne.runProfileLikihood(optContextOneDiff, clientTaskStatusSupport);
// OptModelTwoDiffWithoutPenalty optModelTwoDiffWithoutPenalty = new OptModelTwoDiffWithoutPenalty(refSimData, refSimTimePoints, refDiffusionRate);
// Generate2DOptContextOp generate2DOptContextTwoWithoutPenalty = new Generate2DOptContextOp();
// OptContext optContextTwoDiffWithoutPenalty = generate2DOptContextTwoWithoutPenalty.generate2DOptContext(optModelTwoDiffWithoutPenalty, reducedData, measurementError);
// RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithoutPenalty = new RunProfileLikelihoodGeneralOp();
// ProfileData[] profileDataTwoWithoutPenalty = runProfileLikelihoodTwoWithoutPenalty.runProfileLikihood(optContextTwoDiffWithoutPenalty, clientTaskStatusSupport);
OptModelTwoDiffWithPenalty optModelTwoDiffWithPenalty = new OptModelTwoDiffWithPenalty(refSimData, refSimTimePoints, refDiffusionRate);
Generate2DOptContextOp generate2DOptContextTwoWithPenalty = new Generate2DOptContextOp();
OptContext optContextTwoDiffWithPenalty = generate2DOptContextTwoWithPenalty.generate2DOptContext(optModelTwoDiffWithPenalty, reducedData, measurementError, errorFunction);
RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithPenalty = new RunProfileLikelihoodGeneralOp();
ProfileData[] profileDataTwoWithPenalty = runProfileLikelihoodTwoWithPenalty.runProfileLikihood(optContextTwoDiffWithPenalty, clientTaskStatusSupport);
//
// SLOW WAY
//
// runRefSimulationFull.cellROI_2D,generateCellROIs.cellROI_2D);
// runRefSimulationFull.normalizedTimeSeries,generateNormalizedFrapData.normalizedFrapData);
// workflow.addTask(runRefSimulationFull);
// generateReducedRefSimData.imageTimeSeries,runRefSimulationFull.refSimTimeSeries);
// generateReducedRefSimData.imageDataROIs,generateDependentROIs.imageDataROIs);
// workflow.addTask(generateReducedRefSimData);
// DataHolder<RowColumnResultSet> reducedROIData = generateReducedRefSimData.reducedROIData;
// DataHolder<Double> refSimDiffusionRate = runRefSimulationFull.refSimDiffusionRate;
VFrapProcessResults results = new VFrapProcessResults(dataROIs, geometryAndTiming.cellROI_2D, bleachROI, normalizedFrapResults.normalizedFrapData, reducedData, profileDataOne, profileDataTwoWithPenalty);
return results;
}
use of org.vcell.vmicro.workflow.data.OptContext in project vcell by virtualcell.
the class RunProfileLikelihoodGeneral method compute0.
@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
// get input
OptContext optContext = context.getData(this.optContext);
// do op
RunProfileLikelihoodGeneralOp op = new RunProfileLikelihoodGeneralOp();
ProfileData[] profileData = op.runProfileLikihood(optContext, clientTaskStatusSupport);
// set output
context.setData(this.profileData, profileData);
}
Aggregations