use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class MicroscopyXmlReader method getPrimaryROIs.
/**
* This method is only called by DataSymbolsPanel to get the primary ROIs
*/
public ROI[] getPrimaryROIs(Element param, /*root, frapstudy element*/
ClientTaskStatusSupport progressListener) throws XmlParseException {
// get frapData element
Element frapDataElement = param.getChild(MicroscopyXMLTags.FRAPDataTag);
Namespace ns = param.getNamespace();
List<Element> roiList = frapDataElement.getChildren(MicroscopyXMLTags.ROITag);
ROI[] rois = null;
int numROIs = 3;
if (numROIs > 0) {
rois = new ROI[numROIs];
Iterator<Element> roiIter = roiList.iterator();
int index = 0;
while (roiIter.hasNext()) {
Element roiElement = roiIter.next();
if (roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_BLEACHED.name()) || roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()) || roiElement.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag).equals(AnnotatedImageDataset.VFRAP_ROI_ENUM.ROI_CELL.name())) {
rois[index++] = getROI(roiElement);
if (index == 3) {
break;
}
}
}
}
// reorder ROIs according to the order of FRAPData.VFRAP_ROI_ENUM
ROI[] reorderedROIs = AnnotatedImageDataset.reorderROIs(rois);
return reorderedROIs;
}
use of cbit.vcell.VirtualMicroscopy.ROI 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 cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class FRAPOptimizationUtils method refreshNormalizedMeasurementError.
/*
* Calculate Measurement error for data that is normalized
* and averaged at each ROI ring.
* The first dimension is ROI rings(according to the Enum in FRAPData)
* The second dimension is time points (from starting index to the end)
*/
public static double[][] refreshNormalizedMeasurementError(FRAPStudy frapStudy) throws Exception {
FRAPData fData = frapStudy.getFrapData();
ImageDataset imgDataset = fData.getImageDataset();
double[] timeStamp = imgDataset.getImageTimeStamps();
int startIndexRecovery = frapStudy.getStartingIndexForRecovery();
int roiLen = FRAPData.VFRAP_ROI_ENUM.values().length;
double[][] sigma = new double[roiLen][timeStamp.length - startIndexRecovery];
double[] prebleachAvg = FrapDataUtils.calculatePreBleachAverageXYZ(fData, startIndexRecovery);
for (int roiIdx = 0; roiIdx < roiLen; roiIdx++) {
ROI roi = fData.getRoi((FRAPData.VFRAP_ROI_ENUM.values()[roiIdx]).name());
if (roi != null) {
short[] roiData = roi.getPixelsXYZ();
for (int timeIdx = startIndexRecovery; timeIdx < timeStamp.length; timeIdx++) {
short[] rawTimeData = AnnotatedImageDataset.collectAllZAtOneTimepointIntoOneArray(imgDataset, timeIdx);
if (roiData.length != rawTimeData.length || roiData.length != prebleachAvg.length || rawTimeData.length != prebleachAvg.length) {
throw new Exception("ROI data and image data are not in the same length.");
} else {
// loop through ROI
int roiPixelCounter = 0;
double sigmaVal = 0;
for (int i = 0; i < roiData.length; i++) {
if (roiData[i] != 0) {
sigmaVal = sigmaVal + ((rawTimeData[i] & 0x0000FFFF)) / (prebleachAvg[i] * prebleachAvg[i]);
roiPixelCounter++;
}
}
if (roiPixelCounter == 0) {
sigmaVal = 0;
} else {
sigmaVal = Math.sqrt(sigmaVal) / roiPixelCounter;
}
sigma[roiIdx][timeIdx - startIndexRecovery] = sigmaVal;
}
}
}
}
// }
return sigma;
}
use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class FRAPStudy method spatialAnalysis.
public static SpatialAnalysisResults spatialAnalysis(PDEDataManager simulationDataManager, int startingIndexForRecovery, double startingForRecoveryExperimentalTime, Parameter[] modelParameters, FRAPData frapData, double[] preBleachAverageXYZ) throws Exception {
String[] varNames = new String[] { SPECIES_NAME_PREFIX_COMBINED };
AnalysisParameters analysisParameters = new AnalysisParameters(modelParameters);
//
// for each simulation time step, get the data under each ROI <indexed by ROI, then diffusion
//
// preallocate arrays for all data first
Hashtable<CurveInfo, double[]> curveHash = new Hashtable<CurveInfo, double[]>();
ArrayList<int[]> nonZeroIndicesForROI = new ArrayList<int[]>();
for (int i = 0; i < SpatialAnalysisResults.ORDERED_ROINAMES.length; i++) {
// for (int j = 0; j < diffusionRates.length; j++) {
curveHash.put(new CurveInfo(analysisParameters, SpatialAnalysisResults.ORDERED_ROINAMES[i]), new double[frapData.getImageDataset().getImageTimeStamps().length - startingIndexForRecovery]);
// }
ROI roi_2D = frapData.getRoi(SpatialAnalysisResults.ORDERED_ROINAMES[i]);
nonZeroIndicesForROI.add(roi_2D.getRoiImages()[0].getNonzeroIndices());
}
//
// collect data for experiment (over all ROIs), normalized with pre-bleach average
//
double[] avgBkIntensity = frapData.getAvgBackGroundIntensity();
for (int i = 0; i < SpatialAnalysisResults.ORDERED_ROINAMES.length; i++) {
double[] normalizedAverageFluorAtEachTimeUnderROI = new double[frapData.getImageDataset().getImageTimeStamps().length];
for (int j = 0; j < normalizedAverageFluorAtEachTimeUnderROI.length; j++) {
normalizedAverageFluorAtEachTimeUnderROI[j] = frapData.getAverageUnderROI(j, frapData.getRoi(SpatialAnalysisResults.ORDERED_ROINAMES[i]), preBleachAverageXYZ, avgBkIntensity[j]);
}
curveHash.put(new CurveInfo(null, SpatialAnalysisResults.ORDERED_ROINAMES[i]), normalizedAverageFluorAtEachTimeUnderROI);
}
//
// get times to compare experimental data with simulated results.
//
double[] shiftedSimTimes = null;
if (simulationDataManager != null) {
double[] simTimes = simulationDataManager.getDataSetTimes();
shiftedSimTimes = simTimes.clone();
for (int j = 0; j < simTimes.length; j++) {
// timeStamps[startingIndexOfRecovery];
shiftedSimTimes[j] = simTimes[j] + startingForRecoveryExperimentalTime;
}
// curveHash was intialized with exp time data length. so, we have to replace it with the real sim data length.
if (simTimes.length != (frapData.getImageDataset().getImageTimeStamps().length - startingIndexForRecovery)) {
for (int k = 0; k < SpatialAnalysisResults.ORDERED_ROINAMES.length; k++) {
CurveInfo ci = new CurveInfo(analysisParameters, SpatialAnalysisResults.ORDERED_ROINAMES[k]);
curveHash.remove(ci);
curveHash.put(ci, new double[simTimes.length]);
}
}
for (int i = 0; i < simTimes.length; i++) {
for (int j = 0; j < varNames.length; j++) {
SimDataBlock simDataBlock = simulationDataManager.getSimDataBlock(varNames[j], simTimes[i]);
double[] data = simDataBlock.getData();
for (int k = 0; k < SpatialAnalysisResults.ORDERED_ROINAMES.length; k++) {
CurveInfo ci = new CurveInfo(analysisParameters, SpatialAnalysisResults.ORDERED_ROINAMES[k]);
int[] roiIndices = nonZeroIndicesForROI.get(k);
if (roiIndices != null && roiIndices.length > 0) {
double accum = 0.0;
for (int index = 0; index < roiIndices.length; index++) {
accum += data[roiIndices[index]];
}
double[] values = curveHash.get(ci);
values[i] = accum / roiIndices.length;
}
}
}
}
}
SpatialAnalysisResults spatialAnalysisResults = new SpatialAnalysisResults(new AnalysisParameters[] { analysisParameters }, shiftedSimTimes, curveHash);
return spatialAnalysisResults;
}
use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class FRAPStudy method calculatePrebleachAvg_oneValue.
public static double calculatePrebleachAvg_oneValue(FRAPData arg_frapData, int arg_startingIndexForRecovery) {
double accum = 0;
int counter = 0;
double[] prebleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(arg_frapData, arg_startingIndexForRecovery);
ROI cellROI = arg_frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
for (int i = 0; i < prebleachAvgXYZ.length; i++) {
if (cellROI.getPixelsXYZ()[i] != 0) {
accum = accum + prebleachAvgXYZ[i];
counter++;
}
}
return (accum / counter);
}
Aggregations