forked from CovertLab/WholeCell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loadSimulation.m
91 lines (82 loc) · 2.91 KB
/
loadSimulation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
% Load whole cell simulation from disk/database.
%
% Author: Jonathan Karr, jkarr@stanford.edu
% Affilitation: Covert Lab, Department of Bioengineering, Stanford University
% Last updated: 1/12/2011
function [simulation, states, options, parameters, fittedConstants, metadata] = loadSimulation(directoryOrWID, timeInit, timeFin, downsampleStepSec, downsampleType)
%initialize
setWarnings();
setPath();
setPreferences();
%import
import edu.stanford.covert.cell.sim.Simulation;
import edu.stanford.covert.cell.sim.util.DatabaseLogger;
import edu.stanford.covert.cell.sim.util.DiskLogger;
import edu.stanford.covert.cell.sim.util.CachedSimulationObjectUtil;
import edu.stanford.covert.cell.sim.util.SimulationDiskUtil;
import edu.stanford.covert.db.MySQLDatabase;
%load metadata
if ischar(directoryOrWID)
directoryOrWID = SimulationDiskUtil.getSimulation(directoryOrWID);
metadata = DiskLogger.loadMetadata(directoryOrWID);
else
if ~exist('database', 'var')
database = MySQLDatabase(getConfig());
end
metadata = DatabaseLogger.loadMetadata(database, directoryOrWID);
end
%construct simulation object
simulation = CachedSimulationObjectUtil.load(metadata.revision);
%load options, parameters, fitted constants based on data stored in disk/database
if ischar(directoryOrWID)
if nargin < 2
timeInit = [];
end
if nargin < 3
timeFin = [];
end
if nargin < 4
downsampleStepSec = [];
end
if nargin < 5
downsampleType = [];
end
[states, metadata, options, parameters, fittedConstants, randStreamStates] = ...
DiskLogger.load(directoryOrWID, '-independent', timeInit, timeFin, downsampleStepSec, downsampleType);
else
if ~exist('database', 'var')
database = MySQLDatabase(getConfig());
end
if nargin > 1
warning('WholeCell:warning', 'Additional options ignored');
end
[states, metadata, options, parameters, fittedConstants, randStreamStates] = ...
DatabaseLogger.load(simulation, database, directoryOrWID);
end
%apply options, parameters, constants, time courses to simulation
simulation.applyOptions(options);
simulation.applyParameters(parameters);
simulation.applyFittedConstants(fittedConstants);
simulation.applyRandStreamStates(randStreamStates);
simulation.allocateMemoryForState(numel(states.Time.values));
for i = 1:numel(simulation.states)
state = simulation.states{i};
stateID = state.wholeCellModelID(7:end);
for j = 1:numel(state.stateNames)
name = state.stateNames{j};
try
state.(name) = states.(stateID).(name);
catch %#ok<CTCH>
warning('WholeCell:warning', 'Data not provided for %s %s state', state.name, name);
end
end
end
for i = 1:numel(simulation.processes)
process = simulation.processes{i};
process.copyFromState();
end
simulation.applyPerturbationsToConstants();
%cleanup
if exist('database', 'var')
database.close();
end