Team:Dundee/Modeling/Appendix3

Dry Lab


Appendix 3: Chromate Biosensor Code

Chromate Model Code

Bone Incision Experimental Data

Bone Incision Experiment Code

Chromate Model Code


The figures shown in the Chromate Biosensor model were created using MATLAB. Two files were written to perform sensitivity analysis; one to set the function (chromate.m) and one to solve the function and plot the results in Figure 3, Figure 4 , Figure 5 and Figure 6 (run_chromate.m). Both files are shown below, where the green is comments to aid in understanding of the scripts.



  MATLAB code from chromate.m file
% Function to define the system of ODEs describing the modified chromate pathway.
%% Section 1: Function to define the system of ODEs describing the modified chromate pathway.
% The vector u has seven dimensions where;
% u(1) = ChrB protein concentration,
% u(2) = ChrB dimer concentration,
% u(3) = Cv, the hexavalent chromate added to the system concentration,
% u(4) = Dimer and Cv complex concentration,
% u(5) = Pc, the closed (bound and non-functioning) promoter concentration,
% u(6) = Po. the open (unbound and functioning) promoter concentration,
% u(7) = GFP output concentration.
% Parameter t is time that the simulation runs over. 
% Parameters k1..k8 represent the kinetic rates of the system.
% L represents leakiness of the system.
function f=chromate(t,u,L);
k1 = 1;
k2 = 1;
k3 = 1;
km3 = 1;
k4 = 1;
km4 = 1;
k5 = 1;
k6 = 1;
km6=1;
k7 = 1;
% k8 divided by 60 as in minutes not hours.
k8=(0.25/60);
% Set S1 and S2 at specific times which represent whether chromate is present or not
% S is the signal input.

S1=0;
S2=1;
if (t<500)% Where time is less than 500 seconds.
    S=S1;

else if (t>500) && (t<3100)% Where time is more than 500 seconds and less than 3100 seconds.
        S=S2;

    else if (t>3100)% Where time is more than 3100 seconds.
            S=S1;
        end
    end
end % If and else if loop sets the times when chromate is present or absent from the system.
% Define f as a vector where the input is the right hand side of the systems of ODEs representing the pathway with signal input incorporated.
f=[k1 - k2*u(1)+km3*u(2)-k3*u(1)*u(1);
    k3*u(1)*u(1)-km3*u(2)+(km4*u(4))-(k4*u(2)*u(3)*S)-k5*u(2)+(km6*u(5)*S)-k6*u(2)*u(6);
    -k4*u(2)*u(3)*S+km4*u(4);
     k4*u(2)*u(3)*S-km4*u(4);
     k6*u(6)*u(2)-km6*u(5)*S;
     -k6*u(6)*u(2)+km6*u(5)*S;
    L+k7*u(6)*S-k8*u(7)];
 % End function.
end
% This function can then be called using the @chromate command in run_chromate.m file.
% END OF FILE
 MATLAB code from chrom_wt.m file
%% Function to define the system of ODEs describing the original chromate pathway.
% The vector u has seven dimensions where;
% u(1) = ChrB protein concentration,
% u(2) = ChrB dimer concentration,
% u(3) = Cv, the hexavalent chromate added to the system concentration,
% u(4) = Dimer and Cv complex concentration,
% u(5) = Pc, the closed (bound and non-functioning) promoter concentration,
% u(6) = Po. the open (unbound and functioning) promoter concentration,
% u(7) = GFP output concentration.
% Parameter t is time that the simulation runs over. 
% Parameters k1..k8 represent the kinetic rates of the system.
% L represents leakiness of the system.
function f=chrom_wt(t,u,L);
k2 = 1;
k3 = 1;
km3 = 1;
k4 = 1;
km4 = 1;
k5 = 1;
k6 = 1;
km6=1;
k7 = 1;
% k8 divided by 60 as in minutes not hours.
k8=(0.25/60);
% Set S1 and S2 at specific times which represent whether chromate is present or not.
% S is the signal input.

S1=0;
S2=1;
if (t1<500)% Where time is less than 500 seconds.
    S=S1;

else if (t1>500) && (t1<3100)% Where time is more than 500 seconds and less than 3100 seconds.
        S=S2;

    else if (t1>3100)% Where time is more than 3100 seconds.
            S=S1;
        end
    end
end % If and else if loop sets the times when chromate is present or absent from the system.
% Define f as a vector where the input is the right hand side of the systems of ODEs representing the pathway with signal input incorporated.
f=[L+k7*u(6)-k2*u(1)+km3*u(2)-k3*u(1)*u(1);
    k3*u(1)*u(1)-km3*u(2)+(km4*u(4))-(k4*u(2)*u(3)*S)-k5*u(2)+(km6*u(5)*S)-k6*u(2)*u(6);
    -k4*u(2)*u(3)*S+km4*u(4);
     k4*u(2)*u(3)*S-km4*u(4);
     k6*u(6)*u(2)-km6*u(5)*S;
     -k6*u(6)*u(2)+km6*u(5)*S;
     L+k7*u(6)*S-k8*u(7)];
 % End function.
end
% This function can then be called using the @chrom_wt command in run_chromate.m file
%
%
% END OF FILE




 MATLAB code from run_chromate.m file
%% File to solve chromate functions.
%% Section 1: Solving the modified system to investigate GFP production with chromate added and removed at specific times.
% a = Initial ChrB protein concentration.
a = 1;
% b = Initial ChrB dimer concentration.
b = 1;
% c = Initial Cv, chromate, concentration.
c =1;
% d = Initial Cv and dimer complex concentration.
d = 0;
% e = Initial Pc, closed promoter, concentration.
e = 0;
% f = Initial Po, open promoter, concentration.
f = 1;
% g = Initial GFP concentration.
g = 0.01;
% T = Final time of simulation, in seconds.
T=3600;
% Solve the function using ode23 solver with set time range and defined initial conditions.
% Save time values in vector t and u(1)..u(7) values in matrix u with no leakiness, L=0.
[t,u]=ode23(@chromate,[0,T],[a,b,c,d,e,f,g],[],0);

% Call up empty figure 1 to prevent overwriting figures.
figure1=figure(1)
% Plot t vector against the 7th column of the u matrix, that is the GFP concentration, and set linewidth to 3 so that it is easily read.
plot(t,u(:,7), 'LineWidth',3);
% Ensure that axis fits the data by using axis tight command.
axis tight
% Remove the values on the x and y axis as they are not relevant.
set(gca,'YTick',[],'XTick',[]);
% Annotate the figure by adding arrows along the x and y axis to represent increasing time and Fluorescence.
annotation(figure1,'arrow',[0.133928571428571 0.914285714285714],...
    [0.0466190476190482 0.0476190476190482],'LineWidth',4);
annotation(figure1,'arrow',[0.0982142857142857 0.0982142857142857],...
    [0.103761904761905 0.919047619047619],'LineWidth',4);
% Annotate the figure by adding text arrow to highlight where the chromate is added and removed.
annotation(figure1,'textarrow',[0.3875 0.25],...
    [0.346619047619048 0.119047619047619],'Color',[1 0 0],...
    'String',{'Chromate Added'},...
    'LineWidth',4,...
    'FontWeight','bold',...
    'FontSize',12);
annotation(figure1,'textarrow',[0.682142857142857 0.789285714285714],...
    [0.779952380952381 0.919047619047619],'Color',[1 0 0],...
    'String',{'Chromate Removed'},...
    'LineWidth',4,...
    'FontWeight','bold',...
    'FontSize',12);
% Set the labels of the x and y axis to Time and Fluorescence, respectively.
xlabel ('Time', 'FontSize', 15);
ylabel ('Fluorescence','FontSize', 15);
% Add a legend for GFP Response.
legend1=legend('GFP Response');
% Make the box around legend bold and make font bigger, also position legend so that it is easily read.
set(legend1,...
    'Position',[0.468154768530456 0.149603206588803 0.360714277944395 0.0626984112082966],...
    'LineWidth',2,...
    'FontWeight','bold',...
    'FontSize',12);
% END OF SECTION
%
%

%% Section 2: Sensitivity analysis on effect of chromate added to GFP production in modified pathway.
% n = Number of different values of chromate evaluated.
n=10;
% T = Final time of simulation, in seconds.
T=3600;
% c1 = The range of values used for initial chromate concentration, with minimum at 0 and maximum at 400.
c1=linspace(0,400,n);
% Call up figure 2 to ensure no figures are overwritten.
figure2=figure(2)
% Set hold on so that multiple lines will be plotted on same figure.
hold on
% Set a for loop so that the n values for chromate are evaluated individually and the system solved for each of them.
for i=1:n
 % Solve the chromate function using ode23 solver over set time range and same initial conditions for all variables except chromate.
    % The initial concentration of chromate will depend on the value of i within the for loop.
    % The values will be stored in the t vector and u matrix with no leakiness, L=0.
    [t,u]=ode23(@chromate,[0,T],[a,b,c1(i),d,e,f,g],[],0);
    % Plot the GFP concentration over time.
    plot(t,u(:,7), 'LineWidth',2);
% End the for loop.
end
% Then switch hold off so that no more lines are plotted on figure.
hold off
% Set axis to tight so that plot fits the data.
axis tight
% Add a rectangle onto the graph to highlight the section that will be zoomed in on in figure 3.
annotation('rectangle',[0.236714285714286 0.561904761904762 0.213285714285714 0.354761904761906], 'LineStyle','--');
% Remove the values of the x and y axis as they are not necessary.
set(gca,'YTick',[],'XTick',[]);
% Annotate the figure by adding arrows along the x and y axis to represent increasing time and concentration.
annotation(figure2,'arrow',[0.133928571428571 0.914285714285714],...
    [0.0466190476190482 0.0476190476190482],'LineWidth',4);
annotation(figure2,'arrow',[0.0982142857142857 0.0982142857142857],...
    [0.103761904761905 0.919047619047619],'LineWidth',4);
% Annotate the figure by adding text arrow to highlight where the chromate is added and removed.
annotation(figure2,'textarrow',[0.3875 0.25],...
    [0.346619047619048 0.119047619047619],'Color',[1 0 0],...
    'String',{'Chromate Added'},...
    'LineWidth',4,...
    'FontWeight','bold',...
    'FontSize',12);
annotation(figure2,'textarrow',[0.682142857142857 0.789285714285714],...
    [0.779952380952381 0.919047619047619],'Color',[1 0 0],...
    'String',{'Chromate Removed'},...
    'LineWidth',4,...
    'FontWeight','bold',...
    'FontSize',12);
% Set the labels of the x and y axis to Time and Concentration, respectively.
xlabel ('Time', 'FontSize', 15);
ylabel ('Fluorescence','FontSize', 15);
%
% We will now replot figure 2 but zoom in on a specific section for clarity.
%
%
% Call up empty figure 3 to prevent overwriting figures.
figure3=figure(3)
% Set hold on so that multiple lines will be plotted on same figure.
 hold on
 % Set a for loop so that the n values for chromate are evaluated individually and the system solved for each of them.
 for i=1:n
 % Solve the chromate function using ode23 solver over set time range and same initial conditions for all variables except chromate.
   
    % The initial concentration of chromate will depend on the value of i within the for loop.
    % The values will be stored in the t vector and u matrix with no leakiness, L=0.
    [t,u]=ode23(@chromate,[0,T],[a,b,c1(i),d,e,f,g],[],0);
    % Plot the GFP concentration over time.
    plot(t,u(:,7), 'LineWidth',2);
% End the for loop.
 end
 % set hold off, so that no more lines are plotted.
hold off
% Ensure that axis fits the data by using axis tight command.
axis tight
% Remove the values on the x and y axis as they are not relevant and set the x and y limits so that we get a zoomed in section of the plot.
set(gca,'YTick',[],'XTick',[], 'XLim',[909.850230414748 1359.85023041475],'YLim',[163.478891218168 187.138947135872]);
% Annotate the figure by adding arrows along the x and y axis to represent increasing time and concentration.
annotation(figure3,'arrow',[0.133928571428571 0.914285714285714],...
    [0.0466190476190482 0.0476190476190482],'LineWidth',4);
annotation(figure3,'arrow',[0.0982142857142857 0.0982142857142857],...
    [0.103761904761905 0.919047619047619],'LineWidth',4);
% Add a 3rd arrow to the plot to show increasing initial concentration of Cv in the legend.
annotation(figure3,'arrow',[0.817857142857141 0.817857142857143],...
    [0.597619047619051 0.238095238095238],'LineWidth',4);
% Set legend as just lines with no text, as text will be added later using paint (see wiki figures).
legend2=legend('','','','','','','','','','');
% Set the position of the legend and the width of the box line.
set(legend2,...
    'Position',[0.631547602609266 0.207142857142858 0.255952397390734 0.413492042689934],...
    'LineWidth',2);
% Set the labels of the x and y axis to Time and Concentration, respectively.
xlabel ('Time', 'FontSize', 15);
ylabel ('Fluorescence','FontSize', 15);
% END OF SECTION
%
%



%% Section 3: Solving the original system to investigate GFP production with chromate added and removed at specific times.
% The same initial conditions are used as modified systems so they do not need to be redefined.
% Solve the chrom_wt function using ode23 solver with set time range and defined initial conditions.
% Save time values in vector t and u(1)..u1(7) values in matrix u with no leakiness, L=0.
[t,u]=ode23(@chrom_wt,[0,T],[a,b,c,d,e,f,g],[],0);
% Call up a new figure to ensure figures are not overwritten.
figure4=figure(4)
% Plot t vector against the 7th column of the u matrix, that is the GFP concentration, and set linewidth to 3 so that it is easily read.
plot(t,u(:,7), 'LineWidth',3);
% Ensure that axis fits the data by using axis tight command.
axis tight
% Remove the values on the x and y axis as they are not relevant.
set(gca,'YTick',[],'XTick',[]);
% Annotate the figure by adding arrows along the x and y axis to represent increasing time and concentration.
annotation(figure4,'arrow',[0.133928571428571 0.914285714285714],...
    [0.0466190476190482 0.0476190476190482],'LineWidth',4);
annotation(figure4,'arrow',[0.0982142857142857 0.0982142857142857],...
    [0.103761904761905 0.919047619047619],'LineWidth',4);
% Add line to show modified level in comparrison.
annotation(figure4,'line',[0 1],...
    [0.9310344828 0.9310344828],'Color',[1 0 1],'LineWidth',2,...
    'LineStyle','--');
% Add text box.
annotation(figure4,'textbox',...
    [0.147428571428571 0.714285714285715 0.116857142857143 0.145238095238096],...
    'Color',[1 0 1],...
    'String',{'Modified','Pathway','Max','GFP'},...
    'LineStyle','none',...
    'FontWeight','bold',...
    'FontSize',12,...
    'FitBoxToText','off');
% Annotate the figure by adding text arrow to highlight where the chromate is added and removed.
annotation(figure4,'textarrow',[0.3875 0.25],...
    [0.346619047619048 0.119047619047619],'Color',[1 0 0],...
    'String',{'Chromate Added'},...
    'LineWidth',4,...
    'FontWeight','bold',...
    'FontSize',12);
annotation(figure4,'textarrow',[0.682142857142857 0.789285714285714],...
    [0.779952380952381 0.919047619047619],'Color',[1 0 0],...
    'String',{'Chromate Removed'},...
    'LineWidth',4,...
    'FontWeight','bold',...
    'FontSize',12);
% Set the x and y labels to Increasing Time and Increasing concentration.
xlabel ('Time', 'FontSize', 15);
ylabel ('Fluorescence','FontSize', 15);
% Add a legend for GFP Concentration.
legend3=legend('GFP Response');
% Set the legend position, box line width and font size/style.
set(legend3,...
    'Position',[0.468154768530456 0.149603206588803 0.360714277944395 0.0626984112082966],...
    'LineWidth',2,...
    'FontWeight','bold',...
    'FontSize',12);
% END OF SECTION
%
%



%% Section 4: Sensitivity analysis on effect of chromate added to GFP production in original pathway.
% Again set n as the number of values used for initial chromate.
n=10;
% T = Final time of simulation, in seconds.
T=3600;
% c1 = The range of values used for initial chromate concentration, with minimum at 0 and maximum at 400.
c1=linspace(0,400,n);
% Call up figure 5 to ensure no figures are overwritten.
figure5=figure(5)
% Set hold on so that multiple lines will be plotted on same figure.
hold on
% Set a for loop so that the n values for chromate are evaluated individually and the system solved for each of them.
for i=1:n
 % Solve the chromate function using ode23 solver over set time range and same initial conditions for all variables except chromate.
    % The initial concentration of chromate will depend on the value of i within the for loop.
    % The values will be stored in the t vector and u matrix with no leakiness, L=0.
    [t,u]=ode23(@chrom_wt,[0,T],[a,b,c1(i),d,e,f,g],[],0);
    % Plot the GFP concentration over time.
    plot(t,u(:,7), 'LineWidth',2);
% End the for loop.
end
% Then switch hold off so that no more lines are plotted on figure.
hold off
% Set the axis to tight so that the data fits the plot.
axis tight
% Add a rectangle onto the graph to highlight the section that will be zoomed in on in figure 6.
annotation('rectangle',[0.236714285714286 0.561904761904762 0.213285714285714 0.354761904761906], 'LineStyle', '--');
% Remove the values on the x and y axis as they are not relevant.
set(gca,'YTick',[],'XTick',[]);
% Annotate the figure by adding arrows along the x and y axis to represent increasing time and concentration.
annotation(figure5,'arrow',[0.133928571428571 0.914285714285714],...
    [0.0466190476190482 0.0476190476190482],'LineWidth',4);
annotation(figure5,'arrow',[0.0982142857142857 0.0982142857142857],...
    [0.103761904761905 0.919047619047619],'LineWidth',4);
% Annotate the figure by adding text arrow to highlight where the chromate is added and removed.
annotation(figure5,'textarrow',[0.3875 0.25],...
    [0.346619047619048 0.119047619047619],'Color',[1 0 0],...
    'String',{'Chromate Added'},...
    'LineWidth',4,...
    'FontWeight','bold',...
    'FontSize',12);
annotation(figure5,'textarrow',[0.682142857142857 0.789285714285714],...
    [0.779952380952381 0.919047619047619],'Color',[1 0 0],...
    'String',{'Chromate Removed'},...
    'LineWidth',4,...
    'FontWeight','bold',...
    'FontSize',12);
% Set the x and y labels as increasing Time and Increasing Concentration respectively.
xlabel ('Time', 'FontSize', 15);
ylabel ('Fluorescence','FontSize', 15);
%
% We now want to replot figure 5 with a section zoomed in.
%
% Call up figure 6 so that no other plots are overwritten.
figure6=figure(6)
% Set hold on so that multiple line can be plotted on one graph.
 hold on
 % Set a for loop so that the n values for chromate are evaluated individually and the system solved for each of them.
 for i=1:n
 % Solve the chromate function using ode23 solver over set time range and same initial conditions for all variables except chromate.
    % The initial concentration of chromate will depend on the value of i within the for loop.
    % The values will be stored in the t vector and u matrix with no leakiness, L=0.
    [t,u]=ode23(@chrom_wt,[0,T],[a,b,c1(i),d,e,f,g],[],0);
    % Plot the GFP concentration over time.
    plot(t,u(:,7), 'LineWidth',2);
% End the for loop.
 end
 % Set hold off so that no more lines are plotted on the figure.
hold off
% Ensure that axis fits the data by using axis tight command.
axis tight
% Remove the values on the x and y axis as they are not relevant and set the x and y limits so that we get a zoomed in section of the plot.
set(gca,'YTick',[],'XTick',[], 'XLim',[909.850230414748 1359.85023041475],'YLim',[163.478891218168 187.138947135872]);
% Annotate the figure by adding arrows along the x and y axis to represent increasing time and concentration
annotation(figure6,'arrow',[0.133928571428571 0.914285714285714],...
    [0.0466190476190482 0.0476190476190482],'LineWidth',4);
annotation(figure6,'arrow',[0.0982142857142857 0.0982142857142857],...
    [0.103761904761905 0.919047619047619],'LineWidth',4);
% Add a 3rd arrow to the plot to show increasing initial concentration of Cv in the legend.
annotation(figure6,'arrow',[0.817857142857141 0.817857142857143],...
    [0.597619047619051 0.238095238095238],'LineWidth',4);
% Set legend as just lines with no text, as text will be added later using paint (see wiki figures).
legend4=legend('','','','','','','','','','');
% Set the position of the legend and the width of the box line.
set(legend4,...
    'Position',[0.631547602609266 0.207142857142858 0.255952397390734 0.413492042689934],...
    'LineWidth',2);
% Set the x and y labels to Increasing Time and Increasing Concentration respectively.
xlabel ('Time', 'FontSize', 15);
ylabel ('Fluorescence','FontSize', 15);
%
%
% END OF SECTION


%% Section 5: Leakiness of both the modified and original pathways.
% All parameters are set as previous sections.
% Solve the chrom_wt function using ode23 solver with set time range and defined initial conditions.
% Save time values in vector t and u(1)..u(7) values in matrix u with leakiness L set at 0.05. 
[t,u]=ode23(@chrom_wt,[0,T],[a,b,c,d,e,f,g],[],0.05);
% Solve the chromate function using ode23 solver with set time range and defined initial conditions.
% Save time values in vector t1 and u1(1)..u1(7) values in matrix u1 with leakiness L set at 0.05.
[t1,u1]=ode23(@chromate,[0,T],[a,b,c,d,e,f,g],[],0.05);
% Call up a new figure to ensure figures are not overwritten.
figure7=figure(7);
% Plot t vector against the 7th column of the u matrix and plot t1 against the 7th column of u1 on the same plot for comparrison.
% Set linewidth to 2 so that it is easily read.
hold on
plot(t,u(:,7),'LineWidth',2);
plot(t1,u1(:,7),'LineWidth',2);
hold off
% Ensure that axis fits the data by using axis tight command.
axis tight
% Remove the values on the x and y axis as they are not relevant.
 set(gca,'YTick',[],'XTick',[]);
% Annotate the figure by adding arrows along the x and y axis to represent increasing Time and Fluorescence.
 annotation(figure7,'arrow',[0.133928571428571 0.914285714285714],...
     [0.0466190476190482 0.0476190476190482],'LineWidth',4);
 annotation(figure7,'arrow',[0.0982142857142857 0.0982142857142857],...
     [0.103761904761905 0.919047619047619],'LineWidth',4);

%  Annotate the figure by adding text arrow to highlight where the chromate is added and removed.

 annotation(figure7,'textarrow',[0.3875 0.25],...
     [0.346619047619048 0.119047619047619],'Color',[1 0 0],...
     'String',{'Chromate Added'},...
     'LineWidth',4,...
'FontWeight','bold',...
     'FontSize',12);
 annotation(figure7,'textarrow',[0.682142857142857 0.789285714285714],...
     [0.779952380952381 0.919047619047619],'Color',[1 0 0],...
     'String',{'Chromate Removed'},...
     'LineWidth',4,...
     'FontWeight','bold',...
     'FontSize',12);
% Set the x and y labels to Time and Fluoresence.
 xlabel ('Time', 'FontSize', 15);
 ylabel ('Fluorescence','FontSize', 15);
% Add a legend to distinguish between the to pathways.
 legend5=legend('Original pathway','Modified pathway');
% Set the legend position, box line width and font size/style.
 set(legend5,...
     'Position',[0.468154768530456 0.149603206588803 0.360714277944395 0.0626984112082966],...
     'LineWidth',2,...
     'FontWeight','bold',...
     'FontSize',12);
% END OF SECTION
%
%
%END OF FILE
View description of model

Bone Incision Data


Below is the raw data recorded for the Bone Incision Experiment. Hover the mouse on the image to see the analysed data, including errors, which was used to produce the graph seen on the Bone Incision Experiment page.



View description of experiment

Bone Incision Experiment Code


The code used in Matlab to produce the parabolic surface plot on the Bone Incision Experiment page, which relates the wear volume to the length of the blade and the force of stabbing.


  MATLAB code from bone.m file


k=6.23*10^(-9);%wear coefficient
W=zeros(1,101);%zero vector for calculated volume of bone incision m^3
s=(0:0.001:0.1);%range of values for blade length m, from 0 to 10cm
p=(0:2:200);%range of values for applied force N, from 0 to 200N

for i=1:101
    for j=1:101
    W(i,j)=k*p(i)*s(j); %Archards Equation in two for loops
    %to create a matrix of possible values for volume
end
end

surf(p,s,W)%creates a surface plot, where the height and therefore colour are dependand on the matric W
grid on
title('Relationship Between Volume of Bone Incison, Force and Blade length')
zlabel('Volume of Incision/m^3')
ylabel('Blade Length/m')
xlabel('Applied Load/N')
View description of experiment

To see the MATLAB code for the FluID section of the project or the Fingerprint Ageing section of the project use the following buttons.

Appendix 2: Fingerprint Ageing Appendix 1: FluID