%% Information about the application
% A MATLAB application from the field of systems biology was chosen for
% experimental runs. The application was created using SimBiology which
% extends MATLAB with functionality for modeling, simulating, and
% analyzing biochemical pathways.
%
% The application allows a user to model and simulate the dynamics of a
% simple gene regulation network, and understand the effect of
% stochasticity on the final state of the system. A ensemble of stochastic
% runs were performed on a gene-regulation model, and the distribution of
% state was studied at any given time point. Several hundred thousand
% simulations might need to be performed to obtain a smooth probability
% distribution function, requiring several days of computation on one
% MATLAB.
% The model used in this script was adpated from the following publication :
% Kepler TB, Elston TC. Stochasticity in transcriptional regulation:
% Origins, consequences and % mathematical representations. Biophys J.
% 2001;81:31163136.
%% Serial version of the code
clear all
%% Define simulation settings
% Total number of runs
numberOfRuns = 20;
% Load SimBiology model
sbioloadproject GeneRegulation m1
% Pre-allocate memory
data = zeros(numberOfRuns, numel(m1.Species));
%% Running an ensemble of stochastic simulations
tic
for i = 1:numberOfRuns
data(i, :) = simulation;
end
elapsedTimeSerial = toc;
display(elapsedTimeSerial)
%% Running SimBiology with parfor
% Open matlabpool using default configuration
if matlabpool('size') == 0
matlabpool open 2
else
warning('MATLAB:poolOpen', 'matlabpool already open')
end
%% Define simulation settings
% Pre-allocate memory
dataParfor = zeros(numberOfRuns, numel(m1.Species));
%% Running an ensemble of stochastic simulations
tic
% change the for loop to a parfor to run in parallel
parfor i = 1:numberOfRuns
dataParfor(i, :) = simulation;
end
elapsedTimeParallel = toc;
display(elapsedTimeParallel)
%% Collect and plot results from parfor
hist(dataParfor(:,1))
title('Histogram of protein state at t = 1000 s')
xlabel('Protein State')
ylabel('Frequency')
%% Calculating speedup
speedUp = elapsedTimeSerial/elapsedTimeParallel;
display(speedUp);
%% Closing the matlabpool
if matlabpool('size') ~= 0
matlabpool close
else
warning('MATLAB:poolClose', 'matlabpool already closed')
end