Skip to content

Commit d051b26

Browse files
Huy VoHuy Vo
Huy Vo
authored and
Huy Vo
committed
Files upload
1 parent 775a190 commit d051b26

38 files changed

+3663
-1
lines changed

DataSynthesizer/data_gen.m

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
function datcell = data_gen( stoich_mat, propensity, x0, t_array, n_sample, unobservable)
2+
% datcell = data_gen( stoich_mat, propensity, x0, t_array, n_sample,
3+
% unobservable) synthesizes smFISH data at specific measurement time points
4+
% (for numerical testing purpose).
5+
datcell = cell( length(t_array ), 1 );
6+
n_species = length(x0);
7+
8+
for it = 1:length( t_array )
9+
10+
t_ssa = t_array(it);
11+
12+
13+
ssa_samples = zeros(n_sample, n_species);
14+
for i = 1:n_sample
15+
ssa_samples(i, :) = ssa(t_ssa, x0, stoich_mat, propensity);
16+
end
17+
18+
ssa_samples = ssa_samples(:, setdiff((1:n_species), unobservable));
19+
20+
[observed_states, ~, i_observed] = unique(ssa_samples, 'rows');
21+
n_observed = size(observed_states, 1);
22+
23+
[wbin, jbin] = hist(i_observed, unique(i_observed));
24+
25+
observed_freq = zeros(n_observed, 1);
26+
observed_freq(jbin) = wbin;
27+
28+
datcell{it} = [observed_states observed_freq];
29+
end
30+
31+
end

DataSynthesizer/ssa.m

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function end_state = ssa(t_f, x0, stoich_mat, propensity)
2+
% SSA stochastic simulation algorithm.
3+
%
4+
% t_f(in): final time.
5+
%
6+
% x0 (in): starting intial vector.
7+
%
8+
% stoich_mat (in): stoichiometry matrix of size (n.o.reactions) x
9+
% (n.o.species).
10+
%
11+
% propensity (in): function handle, propensity(x) = [a_1(x) a_2(x) .. a_M(x)]
12+
% where a_k(x) is the k-th propensity function evaluated at x.
13+
%
14+
% Reference:
15+
% =========
16+
% ?Gillespie, D. T. (1977). Exact Stochastic Simulation of Coupled Chemical Reactions. J. Phys. Chem., 81(25), 2340?2361.
17+
%
18+
x = x0;
19+
t = 0;
20+
while (t < t_f)
21+
a = propensity(x);
22+
a0 = sum(a);
23+
24+
u1 = rand();
25+
u2 = rand();
26+
27+
% Update time
28+
tau = min(log(1/u1)/a0, t_f - t);
29+
t = t + tau;
30+
31+
% Update state
32+
r = find(cumsum(a) > u2*a0, 1, 'first');
33+
x = x + stoich_mat(r, :);
34+
end
35+
end_state = x;
36+
end

DataSynthesizer/test.m

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
% Test the data generation on a toggle swtich model
2+
%% Define the model
3+
nmax = [50 50];
4+
5+
x0 = [31 5];
6+
Pfull0 = zeros(prod(nmax+1),1); i0 = sub2ind(nmax+1, x0(1)+1, x0(2)+1); Pfull0(i0) = 1;
7+
8+
S = [1 0;1 0;-1 0; 0 1; 0 1; 0 -1]'; % stoichiometry matrix
9+
10+
ayx = 6.1e-3; axy = 2.6e-3; nyx = 2.1; nxy = 3; % we assume these parameters are known
11+
12+
ind_prop = @(x,y) [ones(length(x),1), 1./(1+ayx*(y.^nyx)), x, ones(length(y),1), 1./(1+axy*(x.^nxy)), y]; % the parameter-independent part of the propensities
13+
14+
params0 = [5e-5, 1e-2, 5e-4, 2e-3, 1e-2, 3e-4];
15+
16+
t_array = linspace( 1, 10000, 4 );
17+
18+
prop = @(x) params0.*ind_prop(x(1), x(2));
19+
datcell = data_gen( S', prop, x0, t_array, 1000, [] );
20+
%% Solve the FSP to compare with the generated data
21+
Acell = fsp_get_matrices( S, ind_prop, nmax );
22+
Pcell = fsp_solve( params0, t_array, Acell, Pfull0 );
23+
24+
%% plot and compare results
25+
26+
figure();
27+
for it = 1:length(t_array)
28+
subplot( length(t_array), 2, 2*(it-1)+1);
29+
contourf( reshape(Pcell{it}, nmax(1)+1, nmax(2)+1 ) );
30+
subplot( length(t_array), 2, 2*(it-1)+2);
31+
xdat = datcell{it}(:, 1:end-1);
32+
wdat = datcell{it}(:,end);
33+
contourf( full( sparse( xdat(:,1)+1, xdat(:,2)+1, wdat ) ) );
34+
xlim ([0 nmax(2)+1] );
35+
ylim ( [0 nmax(1)+1] );
36+
end

0 commit comments

Comments
 (0)