use of cbit.vcell.math.FunctionColumnDescription in project vcell by virtualcell.
the class EstParams_ReactionOffRatePanel method displayResults.
private void displayResults(FRAPData frapData, int startIndexRecovery) throws ExpressionException, DivideByZeroException {
Parameter[] currentParams = offRateParamPanel.getCurrentParameters();
if (frapData == null || currentParams == null) {
multisourcePlotPane.setDataSources(null);
} else {
double[] frapDataTimeStamps = frapData.getImageDataset().getImageTimeStamps();
// Experiment - Cell ROI Average
double[] temp_background = frapData.getAvgBackGroundIntensity();
double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(frapData, startIndexRecovery);
/*double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()),preBleachAvgXYZ,temp_background);
ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { ReservedSymbol.TIME.getName(), "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] {frapDataTimeStamps, cellRegionData });
DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("exp", expCellAvgData);
//Analytic - Cell ROI Average with Bleach while monitor
ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedSymbol.TIME.getName()));
Expression cellAvgExp = new Expression(FRAPOptFunctions.FUNC_CELL_INTENSITY);
// substitute parameter values
cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_I_inicell), new Expression(cellRegionData[startIndexRecovery]));
cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_BWM_RATE), new Expression(currentParams[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getInitialGuess()));
// time shift
cellAvgExp.substituteInPlace(new Expression(ReservedSymbol.TIME.getName()), new Expression(ReservedSymbol.TIME.getName()+"-"+frapDataTimeStamps[startIndexRecovery]));
try {
bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(
new FunctionColumnDescription(
cellAvgExp,
"CellROIAvg",
null,"bleachWhileMonitorFit",true));
} catch (ExpressionException e) {
e.printStackTrace();
}
for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++)
{
bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
}
DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceOdeSolverResultSet("fit", bleachWhileMonitorOdeSolverResultSet);*/
// experimental bleach region average intensity curve
double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
;
ReferenceData expRefData = new SimpleReferenceData(new String[] { ReservedVariable.TIME.getName(), "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
DataSource expBleachDataSource = new DataSource.DataSourceReferenceData("exp", expRefData);
// Analytic - bleach region average intensity with bleach while monitoring rate
ODESolverResultSet koffFitOdeSolverResultSet = new ODESolverResultSet();
koffFitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedVariable.TIME.getName()));
Expression bleachedAvgExp = frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().getRecoveryExpressionWithCurrentParameters(currentParams);
try {
koffFitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(bleachedAvgExp, "BleachROIAvg", null, "recoveryFit", true));
} catch (ExpressionException e) {
e.printStackTrace();
}
double[] truncatedTimes = new double[frapDataTimeStamps.length - startIndexRecovery];
for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++) {
koffFitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
truncatedTimes[i - startIndexRecovery] = frapDataTimeStamps[i];
}
setCurrentEstimationResults(frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().createData(bleachedAvgExp.flatten(), truncatedTimes));
DataSource koffFitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", koffFitOdeSolverResultSet);
multisourcePlotPane.setDataSources(new DataSource[] { expBleachDataSource, koffFitDataSource /*, expCellAvgDataSource , bleachWhileMonitorDataSource*/
});
multisourcePlotPane.selectAll();
}
}
use of cbit.vcell.math.FunctionColumnDescription in project vcell by virtualcell.
the class CopasiOptimizationSolver method getOdeSolverResultSet.
private static ODESolverResultSet getOdeSolverResultSet(RowColumnResultSet rcResultSet, SimulationSymbolTable simSymbolTable, String[] parameterNames, double[] parameterValues) {
//
// get simulation results - copy from RowColumnResultSet into OdeSolverResultSet
//
ODESolverResultSet odeSolverResultSet = new ODESolverResultSet();
for (int i = 0; i < rcResultSet.getDataColumnCount(); i++) {
odeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(rcResultSet.getColumnDescriptions(i).getName()));
}
for (int i = 0; i < rcResultSet.getRowCount(); i++) {
odeSolverResultSet.addRow(rcResultSet.getRow(i));
}
//
// add appropriate Function columns to result set
//
Function[] functions = simSymbolTable.getFunctions();
for (int i = 0; i < functions.length; i++) {
if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
Expression exp1 = new Expression(functions[i].getExpression());
try {
exp1 = simSymbolTable.substituteFunctions(exp1).flatten();
//
for (int j = 0; parameterNames != null && j < parameterNames.length; j++) {
exp1.substituteInPlace(new Expression(parameterNames[j]), new Expression(parameterValues[j]));
}
} catch (MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
}
try {
FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
odeSolverResultSet.addFunctionColumn(cd);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
return odeSolverResultSet;
}
use of cbit.vcell.math.FunctionColumnDescription in project vcell by virtualcell.
the class GibsonSolver method getStochSolverResultSet.
/**
* Get data columns and function columns to be ready for plot.
* Creation date: (8/15/2006 11:36:43 AM)
* @return cbit.vcell.solver.stoch.StochSolverResultSet
*/
public ODESolverResultSet getStochSolverResultSet() {
// read .stoch file, this funciton here equals to getODESolverRestultSet()+getStateVariableResultSet() in ODE.
ODESolverResultSet stSolverResultSet = new ODESolverResultSet();
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(getBaseName() + IDA_DATA_EXTENSION);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
// Read header
String line = bufferedReader.readLine();
if (line == null) {
// throw exception
System.out.println("There is no data in output file!");
return null;
}
while (line.indexOf(':') > 0) {
String name = line.substring(0, line.indexOf(':'));
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
line = line.substring(line.indexOf(':') + 1);
}
// Read data
while ((line = bufferedReader.readLine()) != null) {
line = line + "\t";
double[] values = new double[stSolverResultSet.getDataColumnCount()];
boolean bCompleteRow = true;
for (int i = 0; i < stSolverResultSet.getDataColumnCount(); i++) {
if (line.indexOf('\t') == -1) {
bCompleteRow = false;
break;
} else {
String value = line.substring(0, line.indexOf('\t')).trim();
values[i] = Double.valueOf(value).doubleValue();
line = line.substring(line.indexOf('\t') + 1);
}
}
if (bCompleteRow) {
stSolverResultSet.addRow(values);
} else {
break;
}
}
//
} catch (Exception e) {
e.printStackTrace(System.out);
return null;
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (Exception ex) {
lg.error(ex.getMessage(), ex);
}
}
/*
Add appropriate Function columns to result set if the stochastic simulation is to display the trajectory.
No function columns for the results of multiple stochastic trials
*/
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
if (simSymbolTable.getSimulation().getSolverTaskDescription().getStochOpt().getNumOfTrials() == 1) {
Function[] functions = simSymbolTable.getFunctions();
for (int i = 0; i < functions.length; i++) {
if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
Expression exp1 = new Expression(functions[i].getExpression());
try {
exp1 = simSymbolTable.substituteFunctions(exp1);
} catch (MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
}
try {
FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
stSolverResultSet.addFunctionColumn(cd);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
}
return stSolverResultSet;
}
use of cbit.vcell.math.FunctionColumnDescription in project vcell by virtualcell.
the class HybridSolver method getHybridSolverResultSet.
/**
* Get data columns and function columns to be ready for plot.
* Creation date: (8/15/2006 11:36:43 AM)
* @return cbit.vcell.solver.stoch.StochSolverResultSet
*/
private ODESolverResultSet getHybridSolverResultSet() {
// read .stoch file, this funciton here equals to getODESolverRestultSet()+getStateVariableResultSet() in ODE.
ODESolverResultSet stSolverResultSet = new ODESolverResultSet();
try {
String filename = getBaseName() + NETCDF_DATA_EXTENSION;
NetCDFEvaluator ncEva = new NetCDFEvaluator();
NetCDFReader ncReader = null;
try {
ncEva.setNetCDFTarget(filename);
ncReader = ncEva.getNetCDFReader();
} catch (Exception e) {
e.printStackTrace(System.err);
throw new RuntimeException("Cannot open simulation result file: " + filename + "!");
}
// Read result according to trial number
if (ncReader.getNumTrials() == 1) {
// Read header
String[] varNames = ncReader.getSpeciesNames_val();
// first column will be time t.
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
// following columns are stoch variables
for (int i = 0; i < varNames.length; i++) {
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(varNames[i]));
}
// Read data
// data only, no time points
ArrayDouble data = (ArrayDouble) ncEva.getTimeSeriesData(1);
double[] timePoints = ncReader.getTimePoints();
System.out.println("time points length is " + timePoints.length);
// shape[0]:num of timepoints, shape[1]: num of species
int[] shape = data.getShape();
if (// one species
shape.length == 1) {
ArrayDouble.D1 temData = (ArrayDouble.D1) data;
System.out.println("one species in time series data and size is " + temData.getSize());
for (// rows
int k = 0; // rows
k < timePoints.length; // rows
k++) {
double[] values = new double[stSolverResultSet.getDataColumnCount()];
values[0] = timePoints[k];
for (int i = 1; i < stSolverResultSet.getDataColumnCount(); i++) {
values[i] = temData.get(k);
}
stSolverResultSet.addRow(values);
}
}
if (// more than one species
shape.length == 2) {
ArrayDouble.D2 temData = (ArrayDouble.D2) data;
System.out.println("multiple species in time series, the length of time series is :" + data.getShape()[0] + ", and the total number of speceis is: " + data.getShape()[1]);
for (// rows
int k = 0; // rows
k < timePoints.length; // rows
k++) {
double[] values = new double[stSolverResultSet.getDataColumnCount()];
values[0] = timePoints[k];
for (int i = 1; i < stSolverResultSet.getDataColumnCount(); i++) {
values[i] = temData.get(k, i - 1);
}
stSolverResultSet.addRow(values);
}
}
} else if (ncReader.getNumTrials() > 1) {
// Read header
String[] varNames = ncReader.getSpeciesNames_val();
// first column will be time t.
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("TrialNo"));
// following columns are stoch variables
for (int i = 0; i < varNames.length; i++) {
stSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(varNames[i]));
}
// Read data
// data only, no trial numbers
ArrayDouble data = (ArrayDouble) ncEva.getDataOverTrials(ncReader.getTimePoints().length - 1);
int[] trialNum = ncEva.getNetCDFReader().getTrialNumbers();
// System.out.println("total trials are "+trialNum.length);
// shape[0]:number of trials, shape[1]: num of species
int[] shape = data.getShape();
if (// one species
shape.length == 1) {
ArrayDouble.D1 temData = (ArrayDouble.D1) data;
// System.out.println("one species over trials, size is: "+temData.getSize());
for (// rows
int k = 0; // rows
k < trialNum.length; // rows
k++) {
double[] values = new double[stSolverResultSet.getDataColumnCount()];
values[0] = trialNum[k];
for (int i = 1; i < stSolverResultSet.getDataColumnCount(); i++) {
values[i] = temData.get(k);
}
stSolverResultSet.addRow(values);
}
}
if (// more than one species
shape.length == 2) {
ArrayDouble.D2 temData = (ArrayDouble.D2) data;
// System.out.println("multiple species in multiple trials, the length of trials is :"+data.getShape()[0]+", and the total number of speceis is: "+data.getShape()[1]);
for (// rows
int k = 0; // rows
k < trialNum.length; // rows
k++) {
double[] values = new double[stSolverResultSet.getDataColumnCount()];
values[0] = trialNum[k];
for (int i = 1; i < stSolverResultSet.getDataColumnCount(); i++) {
values[i] = temData.get(k, i - 1);
}
stSolverResultSet.addRow(values);
}
}
} else {
throw new RuntimeException("Number of trials should be a countable positive value, from 1 to N.");
}
} catch (Exception e) {
e.printStackTrace(System.err);
throw new RuntimeException("Problem encountered in parsing hybrid simulation results.\n" + e.getMessage());
}
/*
*Add appropriate Function columns to result set if the stochastic simulation is to display the trajectory.
*No function columns for the results of multiple stochastic trials.
*In stochastic simulation the functions include probability functions and clamped variable.
*/
SimulationSymbolTable simSymbolTable = simTask.getSimulationJob().getSimulationSymbolTable();
if (simSymbolTable.getSimulation().getSolverTaskDescription().getStochOpt().getNumOfTrials() == 1) {
Function[] functions = simSymbolTable.getFunctions();
for (int i = 0; i < functions.length; i++) {
if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
Expression exp1 = new Expression(functions[i].getExpression());
try {
exp1 = simSymbolTable.substituteFunctions(exp1);
} catch (MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
}
try {
FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
stSolverResultSet.addFunctionColumn(cd);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
}
return stSolverResultSet;
}
use of cbit.vcell.math.FunctionColumnDescription in project vcell by virtualcell.
the class VCellSBMLSolver method getODESolverResultSet.
public static ODESolverResultSet getODESolverResultSet(SimulationJob argSimJob, String idaFileName) {
// read .ida file
ODESolverResultSet odeSolverResultSet = new ODESolverResultSet();
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(idaFileName);
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
// Read header
String line = bufferedReader.readLine();
if (line == null) {
// throw exception
}
while (line.indexOf(':') > 0) {
String name = line.substring(0, line.indexOf(':'));
odeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
line = line.substring(line.indexOf(':') + 1);
}
// Read data
while ((line = bufferedReader.readLine()) != null) {
line = line + "\t";
double[] values = new double[odeSolverResultSet.getDataColumnCount()];
boolean bCompleteRow = true;
for (int i = 0; i < odeSolverResultSet.getDataColumnCount(); i++) {
if (line.indexOf('\t') == -1) {
bCompleteRow = false;
break;
} else {
String value = line.substring(0, line.indexOf('\t')).trim();
values[i] = Double.valueOf(value).doubleValue();
line = line.substring(line.indexOf('\t') + 1);
}
}
if (bCompleteRow) {
odeSolverResultSet.addRow(values);
} else {
break;
}
}
//
} catch (Exception e) {
e.printStackTrace(System.out);
} finally {
try {
if (inputStream != null) {
inputStream.close();
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
}
// add appropriate Function columns to result set
cbit.vcell.math.Function[] functions = argSimJob.getSimulationSymbolTable().getFunctions();
for (int i = 0; i < functions.length; i++) {
if (SimulationSymbolTable.isFunctionSaved(functions[i])) {
Expression exp1 = new Expression(functions[i].getExpression());
try {
exp1 = argSimJob.getSimulationSymbolTable().substituteFunctions(exp1);
} catch (cbit.vcell.math.MathException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
} catch (cbit.vcell.parser.ExpressionException e) {
e.printStackTrace(System.out);
throw new RuntimeException("Substitute function failed on function " + functions[i].getName() + " " + e.getMessage());
}
try {
FunctionColumnDescription cd = new FunctionColumnDescription(exp1.flatten(), functions[i].getName(), null, functions[i].getName(), false);
odeSolverResultSet.addFunctionColumn(cd);
} catch (cbit.vcell.parser.ExpressionException e) {
e.printStackTrace(System.out);
}
}
}
return odeSolverResultSet;
}
Aggregations