Fit_Fig1B.m function main() D=xlsread('Data chemotaxis benefit.xlsx',1,'D2:G10') lam=D(:,1); SDlam=D(:,2); Ptar=D(:,3); SDPtar=D(:,4); % A Lam0 guess=[10000, 1]; fit=fminsearch(@(par) chi2(par,lam,Ptar),guess) 1000*fit(2) Lam=0.1:0.1:1; Phic=fit(1)*(1-Lam/fit(2)); plot(lam,Ptar,'s',Lam,Phic,'k-') xlim([0.3 1]) xlabel ('Growth rate \lambda'); ylabel ('P_{tar} activity'); filename = 'fit_Fig1b.xlsx'; A = [Lam' Phic'] xlswrite(filename,A) function error=chi2(par,lam,data) error=sum((data-par(1)*(1-lam/par(2))).^2); end Fit_Fig1E_WTvsCheY_beads_Nvalue.m function fit1F() % data D=xlsread('Data chemotaxis benefit mod.xlsx',1,'D35:L43'); Lam=D(:,1); % exp growth rate WTpc=0.5*(D(:,3)+D(:,5)); % exp WT percentages Nval=D(:,9); % corresponding model N values %s2, betab guess=[0.2,100*4.6e-3]; fit=fminsearch(@(par) chi2(par,Nval,WTpc),guess,optimset('MaxFunEvals',50)) % run again with best fit parameters ratio=[]; Nvalue=[]; L1=[]; i=1; for nval=0.1:0.01:0.6 % N1 N2 n1 n2 s2 betab Nvalue [t,y]=ode45(@model,[0 15],[1e3;0;1e3;0;fit(1);fit(2);nval]); % culture only WT=y(numel(t),1)+y(numel(t),2); cheY=y(numel(t),3)+y(numel(t),4); ratio(i)=100*WT/(cheY+WT); Nvalue(i)=nval; rho=0.76; w=0.9; phiRmax=0.55; phi0=0.76*0.087; kt=4.5; calphaEkEmaxS=nval*5.8; Kn1=calphaEkEmaxS*rho; % N value [h^{-1}] l1=kt*Kn1*w/(kt+Kn1*w)*(phiRmax-phi0)/rho; % L1(i)=l1; i=i+1; end % plot best fit parameters plot(Lam,WTpc,'s',L1,ratio,'r--'); xlabel('N value'); ylabel('Percentage WT'); title('WT vs \Delta{cheY} with bead secretion (fit for Fig. 1f)') filename = 'fit_Fig1f.xlsx'; A = [L1' ratio']; xlswrite(filename,A) end function error=chi2(par,Nval,data) ratio=[]; for i=1:numel(Nval) % Nvalue=sugar concentrationhere % N1 N2 n1 n2 s2 betab Nvalue [t,y]=ode45(@model,[0 15],[1e3;0;1e3;0;par(1);par(2);Nval(i)]); % culture only WT=y(numel(t),1)+y(numel(t),2); cheY=y(numel(t),3)+y(numel(t),4); ratio(i)=100*WT/(cheY+WT); i=i+1; end error=sum((data-ratio').^2) end function dydt=model(t,y) N1=y(1); N2=y(2); n1=y(3); n2=y(4); s2=y(5); betab=abs(y(6)); NvalueS=y(7); % nutrient S1=20000; % mM and not uM S2=20000; s1=0; % primary crabon source calphaEkEmaxS=NvalueS*5.8; % secondary carbon source Nvalues=1;% N value for CA is growth rate [h^{-1}] calphaEkEmaxs=Nvalues*5.8; beta=2.5e-10;%10; % uM Ks=0.5; % threshold % other parameters phiRmax=0.55; phi0=0.76*0.087; rho=0.76; kt=4.5; KE=1; %Michaelis constant uM KM=0; D=300; %um^2/s kd=D/10^8*3600; % motility hopping rate, converted to [h^-1] w=0.9; e=8; % chemotactic efficiency (should really be 0.5) % use all carbon sources Kn1=calphaEkEmaxS*rho*S1/(KE+S1); % N value [h^{-1}] Kn2=calphaEkEmaxS*rho*S2/(KE+S2); % N value kn1=calphaEkEmaxs*rho*s1/(KE+s1); % N value [h^{-1}] kn2=calphaEkEmaxs*rho*s2/(KE+s2); % N value % individual growth rates L1=kt*Kn1*w/(kt+Kn1*w)*(phiRmax-phi0)/rho; % [h^(-1)] L2=kt*Kn2*w/(kt+Kn2*w)*(phiRmax-phi0)/rho; l1=kt*kn1*w/(kt+kn1*w)*(phiRmax-phi0)/rho; % [h^(-1)] l2=kt*kn2*w/(kt+kn2*w)*(phiRmax-phi0)/rho; % combined growth rate Eq. 7 in above paper lc=1.2; %/h fit lam1=(L1+l1-2*L1*l1/lc)/(1-L1*l1/lc^2); lam2=(L2+l2-2*L2*l2/lc)/(1-L2*l2/lc^2); % gradients for chemotaxis dS12=e*(S1-S2); Sbar=(S1+S2)/2; ds12=e*(s1-s2); sbar=(s1+s2+Ks)/2; % fraction of protein involved in chemotaxis or motility phip1=phiRmax-phi0; phip2=phiRmax-phi0; lam0=1.03; %/h fit phic1=(1-w)*phip1;%*(1-lam1/lam0); % growth rate dependent chemotactic fraction phic2=(1-w)*phip2;%*(1-lam2/lam0); % WT dN1dt=lam1*N1+2*(phic2*N2-phic1*N1)*kd*(Sbar/(KM+Sbar)+sbar/(KM+sbar))+(phic2*N2+phic1*N1)*kd*(dS12/(KM+Sbar)+ds12/(KM+sbar)); dN2dt=lam2*N2-2*(phic2*N2-phic1*N1)*kd*(Sbar/(KM+Sbar)+sbar/(KM+sbar))-(phic2*N2+phic1*N1)*kd*(dS12/(KM+Sbar)+ds12/(KM+sbar)); % cheY dn1dt=lam1*n1+2*(phic2*n2-phic1*n1)*kd*(Sbar/(KM+Sbar)+sbar/(KM+sbar)); dn2dt=lam2*n2-2*(phic2*n2-phic1*n1)*kd*(Sbar/(KM+Sbar)+sbar/(KM+sbar)); % secondary nutrient ds2dt=betab-beta*L2*(N2+n2)*heaviside(s2)*sign(s2); dydt=[dN1dt;dN2dt;dn1dt;dn2dt;ds2dt;0;0]; end Fit_Fig2A_WTvsCheY_secretion_Nvalue function fit2a() % data D=xlsread('Data chemotaxis benefit mod.xlsx',1,'D46:L54'); Lam=D(:,1); % exp growth rate WTpc=0.5*(D(:,3)+D(:,5)); % exp WT percentages Nval=D(:,9); % corresponding model N values %s2, betac guess=[1, 2.5e-10]; fit=fminsearch(@(par) chi2(par,Nval,WTpc),guess,optimset('MaxFunEvals',30)) fit(2)*1e0 % to get full precision % run again with best fit parameters ratio=[]; Nvalue=[]; L1=[]; i=1; for nval=0.1:0.01:0.6 % N1 N2 n1 n2 s2 betac Nvalue [t,y]=ode45(@model,[0 15],[1e3;0;1e3;0;fit(1);fit(2);nval]); % culture only WT=y(numel(t),1)+y(numel(t),2); cheY=y(numel(t),3)+y(numel(t),4); ratio(i)=100*WT/(cheY+WT); Nvalue(i)=nval; rho=0.76; w=0.9; phiRmax=0.55; phi0=0.76*0.087; kt=4.5; calphaEkEmaxS=nval*5.8; Kn1=calphaEkEmaxS*rho; % N value [h^{-1}] l1=kt*Kn1*w/(kt+Kn1*w)*(phiRmax-phi0)/rho; % L1(i)=l1; i=i+1; end % plot best fit parameters plot(Lam,WTpc,'s',L1,ratio,'r--'); xlabel('N value'); ylabel('Percentage WT'); title('WT vs \Delta{cheY} with metabolite secretion (fit for Fig. 2a)') filename = 'fit_Fig2a.xlsx'; A = [L1' ratio']; xlswrite(filename,A) end function error=chi2(par,Nval,data) ratio=[]; for i=1:numel(Nval) % Nvalue=sugar concentrationhere % N1 N2 n1 n2 s2 betac Nvalue [t,y]=ode45(@model,[0 15],[1e3;0;1e3;0;par(1);par(2);Nval(i)]); % culture only WT=y(numel(t),1)+y(numel(t),2); cheY=y(numel(t),3)+y(numel(t),4); ratio(i)=100*WT/(cheY+WT); i=i+1; end error=sum((data-ratio').^2) end function dydt=model(t,y) N1=y(1); N2=y(2); n1=y(3); n2=y(4); s2=y(5); betac=y(6); NvalueS=y(7); % nutrient S1=20000; % mM and not uM S2=20000; s1=0; % primary crabon source calphaEkEmaxS=NvalueS*5.8; % secondary carbon source Nvalues=1;% N value for CA is growth rate [h^{-1}] calphaEkEmaxs=Nvalues*5.8; beta=2.5e-10; % uM Ks=0.5; % threshold % other parameters phiRmax=0.55; phi0=0.76*0.087; rho=0.76; kt=4.5; KE=1; %Michaelis constant uM KM=0; D=300; %um^2/s kd=D/10^8*3600; % motility hopping rate, converted to [h^-1] w=0.9; e=8; % chemotactic efficiency (should really be 0.5) % use all carbon sources Kn1=calphaEkEmaxS*rho*S1/(KE+S1); % N value [h^{-1}] Kn2=calphaEkEmaxS*rho*S2/(KE+S2); % N value kn1=calphaEkEmaxs*rho*s1/(KE+s1); % N value [h^{-1}] kn2=calphaEkEmaxs*rho*s2/(KE+s2); % N value % individual growth rates L1=kt*Kn1*w/(kt+Kn1*w)*(phiRmax-phi0)/rho; % [h^(-1)] L2=kt*Kn2*w/(kt+Kn2*w)*(phiRmax-phi0)/rho; l1=kt*kn1*w/(kt+kn1*w)*(phiRmax-phi0)/rho; % [h^(-1)] l2=kt*kn2*w/(kt+kn2*w)*(phiRmax-phi0)/rho; % combined growth rate Eq. 7 in above paper lc=1.2; %/h fit lam1=(L1+l1-2*L1*l1/lc)/(1-L1*l1/lc^2); lam2=(L2+l2-2*L2*l2/lc)/(1-L2*l2/lc^2); % gradients for chemotaxis dS12=e*(S1-S2); Sbar=(S1+S2)/2; ds12=e*(s1-s2); sbar=(s1+s2+Ks)/2; % fraction of protein involved in chemotaxis or motility phip1=phiRmax-phi0; phip2=phiRmax-phi0; lam0=1.03; %/h fit phic1=(1-w)*phip1;%*(1-lam1/lam0); % growth rate dependent chemotactic fraction phic2=(1-w)*phip2;%*(1-lam2/lam0); % WT dN1dt=lam1*N1+2*(phic2*N2-phic1*N1)*kd*(Sbar/(KM+Sbar)+sbar/(KM+sbar))+(phic2*N2+phic1*N1)*kd*(dS12/(KM+Sbar)+ds12/(KM+sbar)); dN2dt=lam2*N2-2*(phic2*N2-phic1*N1)*kd*(Sbar/(KM+Sbar)+sbar/(KM+sbar))-(phic2*N2+phic1*N1)*kd*(dS12/(KM+Sbar)+ds12/(KM+sbar)); % cheY dn1dt=lam1*n1+2*(phic2*n2-phic1*n1)*kd*(Sbar/(KM+Sbar)+sbar/(KM+sbar)); dn2dt=lam2*n2-2*(phic2*n2-phic1*n1)*kd*(Sbar/(KM+Sbar)+sbar/(KM+sbar)); % secondary nutrient ds2dt=betac*lc*(N1+N2+n1+n2)-beta*L2*(N2+n2)*heaviside(s2)*sign(s2); dydt=[dN1dt;dN2dt;dn1dt;dn2dt;ds2dt;0;0]; end Fit_FigS4d function main() D=xlsread('Data chemotaxis benefit.xlsx',1,'D89:G97') lam1=D(:,1); SDlam=D(:,2); Dlam=D(:,3); SDDlam=D(:,4); % lamC lam2 guess=[1.16 1]; fit=fminsearch(@(par) chi2(par,lam1,Dlam),guess) Lam1=0.2:0.1:1; DLam=(Lam1+fit(2)-2*Lam1*fit(2)/fit(1))./(1-Lam1*fit(2)/fit(1)^2)-Lam1; plot(lam1,Dlam,'s',Lam1,DLam,'k-') xlim([0.3 1]) xlabel ('Growth rate \lambda'); ylabel ('Difference \Delta\lambda'); filename = 'fit_FigS5c.xlsx'; A = [Lam1' DLam'] xlswrite(filename,A) function error=chi2(par,lam1,data) %lam2=1; model=(lam1+par(2)-2*lam1*par(2)/par(1))./(1-lam1*par(2)/par(1)^2)-lam1; error=sum((data-model).^2); end