% This function estimates the steady state distribution by time frame expansion technique for the T cell network. % INPUT: % threshold value: when the norm of the difference of the two adjancent distribution vectors are below this value, then the loop will be broken; % M: the stochastic sequence length, e.g. M = 10000; % p: the perturbation probability, e.g. p = 0.01; % when there is no perturbation, p = 0. % OUTPUT: % Output: The state distribution of the network for all the clock cycles. % Also state distributions of the last three clock cycles (t=period-2, t=period-1 and t=period) are plotted. % Copyright @ The authors, 2012. function Output = time_frame_expansion(threshold,M,p) tic %% initialization n = 12; % gene numbers Output1=zeros(1,2^n); Output2=zeros(1,2^n); Output3=ones(1,2^n); %% time frame expansion gn = zeros(2,n,M); gn(1,1,:)=ones(1,M); gn(1,7,:)=ones(1,M); gn(1,8,:)=ones(1,M); gn(1,10,:)=ones(1,M); gn(1,11,:)=ones(1,M); gup = zeros(1,n,M); gdown = zeros(1,n,M); period=0; while (norm(Output1-Output2,2)>threshold)|(norm(Output2-Output3,2)>threshold) period=period+1 norm(Output1-Output2,2) norm(Output2-Output3,2) Output3=Output2; Output2=Output1; Output1=zeros(1,2^n); % generation of controlling sequences for muxes. It should be noted that in every time frame, the stochastic sequences for the muxes should be generated independently. e2=randomsequence(1,M,500); e6=randomsequence(1,M, 63); e9=randomsequence(1,M,500); e110=zeros(1,1,M); e111=zeros(1,1,M); while sum(e110)~=148; jj=int32(1+(length(e110)-1)*rand); e110(jj)=1; e111(jj)=1; end while sum(e110)~=(148+370); ii = int32(1+(length(e110)-1)*rand); if e110(ii)~=1 e110(ii)=1; else end end while sum(e111)~=(148+185); ii = int32(1+(length(e111)-1)*rand); if or(e110(ii),e111(ii))~=1 e111(ii)=1; else end end % description of the network gup(1,1,:) = not(gn(1,6,:)); f21 = or ( gn(1,3,:), gn(1,6,:) ); f22 = or ( gn(1,2,:), gn(1,6,:) ); gup(1,2,:) = mux2(f21,f22,e2); gup(1,3,:) = gn(1,2,:); gup(1,4,:) = not(gn(1,2,:)); gup(1,5,:) = not(gn(1,3,:)); f61 = and(not(gn(1,10,:)),or(or(gn(1,1,:),gn(1,9,:)),or(gn(1,11,:),gn(1,12,:)))); f62 = not(gn(1,10,:)); gup(1,6,:) = mux2(f61,f62,e6); gup(1,7,:) = gn(1,3,:); gup(1,8,:) = not(gn(1,5,:)); f91 = or(gn(1,4,:),gn(1,12,:)); f92 = or ( gn(1,5,:), gn(1,12,:) ); gup(1,9,:) = mux2(f91,f92,e9); gup(1,10,:) = gn(1,11,:); f111 = not(gn(1,6,:)); %%% 0.297 f112 = and(not(gn(1,6,:)), or ( gn(1,7,:), not(or(gn(1,4,:),gn(1,5,:))) )); %%% 0.185 f113 = and ( not(or(gn(1,4,:),gn(1,5,:))), not(gn(1,6,:)) ); %%% 0.37 f114 = and (not(gn(1,6,:)), gn(1,7,:));%0.148 gup(1,11,:) = mux4(f111,f112,f113,f114, e110, e111); gup(1,12,:) = not(gn(1,8,:)); %% perturbation ee1=randomsequence(1,M,M*p); ee2=randomsequence(1,M,M*p); ee3=randomsequence(1,M,M*p); ee4=randomsequence(1,M,M*p); ee5=randomsequence(1,M,M*p); ee6=randomsequence(1,M,M*p); ee7=randomsequence(1,M,M*p); ee8=randomsequence(1,M,M*p); ee9=randomsequence(1,M,M*p); ee10=randomsequence(1,M,M*p); ee11=randomsequence(1,M,M*p); ee12=randomsequence(1,M,M*p); gdown(1,1,:) = xor(gn(1,1,:),ee1); gdown(1,2,:) = xor(gn(1,2,:),ee2); gdown(1,3,:) = xor(gn(1,3,:),ee3); gdown(1,4,:) = xor(gn(1,4,:),ee4); gdown(1,5,:) = xor(gn(1,5,:),ee5); gdown(1,6,:) = xor(gn(1,6,:),ee6); gdown(1,7,:) = xor(gn(1,7,:),ee7); gdown(1,8,:) = xor(gn(1,8,:),ee8); gdown(1,9,:) = xor(gn(1,9,:),ee9); gdown(1,10,:) = xor(gn(1,10,:),ee10); gdown(1,11,:) = xor(gn(1,11,:),ee11); gdown(1,12,:) = xor(gn(1,12,:),ee12); sel = or(or(or(or(or(or(or(or(or(or(or(ee1,ee2),ee3),ee4),ee5),ee6),ee7),ee8),ee9),ee10),ee11),ee12); gn(2,1,:) = mux2(gup(1,1,:),gdown(1,1,:),sel); gn(2,2,:) = mux2(gup(1,2,:),gdown(1,2,:),sel); gn(2,3,:) = mux2(gup(1,3,:),gdown(1,3,:),sel); gn(2,4,:) = mux2(gup(1,4,:),gdown(1,4,:),sel); gn(2,5,:) = mux2(gup(1,5,:),gdown(1,5,:),sel); gn(2,6,:) = mux2(gup(1,6,:),gdown(1,6,:),sel); gn(2,7,:) = mux2(gup(1,7,:),gdown(1,7,:),sel); gn(2,8,:) = mux2(gup(1,8,:),gdown(1,8,:),sel); gn(2,9,:) = mux2(gup(1,9,:),gdown(1,9,:),sel); gn(2,10,:) = mux2(gup(1,10,:),gdown(1,10,:),sel); gn(2,11,:) = mux2(gup(1,11,:),gdown(1,11,:),sel); gn(2,12,:) = mux2(gup(1,12,:),gdown(1,12,:),sel); %% compute the distribution at each time point for k = 1:M j = 1; for kkk = 1:n j = j + gn(2,kkk,k)*2^(kkk-1); end Output1(j) = Output1(j) + 1/M; end gn(1,:,:)=gn(2,:,:); end figure; hold on; subplot(3,1,1) stem([1:4096],Output1); subplot(3,1,2) stem([1:4096],Output2); subplot(3,1,3) stem([1:4096],Output3); Output=Output3; toc end function c=randomsequence(c1,c2,c3) % randomsequence sequence generator c=zeros(1,c1,c2); irandom=0; while irandom ~= c3 x=int32(1+(length(c)-1)*rand); if c(x)~=1 c(x)=1; irandom=irandom+1; end end end