diff --git a/ICsolvers/N803_shared.m b/ICsolvers/N803_shared.m new file mode 100644 index 0000000..605247d --- /dev/null +++ b/ICsolvers/N803_shared.m @@ -0,0 +1,262 @@ +%% N803_shared.m - solves model for 2 cohorts with shared parameters +% +% /--------------------------------------------------------------\ +% | Date: 07/02/2022 | +% | Author: Jonathan Cody | +% | Affiliation: Purdue University | +% | Weldon School of Biomedical Engineering | +% | Pienaar Computational Systems Pharmacology Lab | +% \--------------------------------------------------------------/ +% +% Nomenclature: V = SIV virions [#/無] +% T8 = total CD8+ T cells [#/無] +% E0 = resting SIV-specific CD8+ T cells [#/無] +% Ea = active SIV-specific CD8+ T cells [#/無] +% B0 = resting bystander CD8+ T cells [#/無] +% Ba = active bystander CD8+ T cells [#/無] +% X = N803 at absorption site [pmol/kg] +% C = N803 plasma concentration [pM] +% R = regulation [] (dimensionless quantity) +% +%% ======================================================================== +% INPUTS +% ======================================================================== +% +% SoluTimes = ascending vector of days at which to evaluate solution +% +% DoseTimes{c} = ascending vector of days at which to administer doses +% (elements of 'DoseTimes' must also be in 'SoluTimes') +% +% AllPars = vector of parameters (see list in function) +% +%% ======================================================================== +% OPTIONS +% ======================================================================== +% +% SkipTimes{c} = [min max] time point beyond which to skip model solving +% (outputs before 'min' will be made equal to output at 'min') +% (leave as [] to ignore and solve for all 'SoluTimes') +% +% oneCohort = scalar to run model for just one cohort ('1' or '2') +% (leave as [] to ignore and solve for both cohorts) +% +% All additional inputs will be passed as a cell vector to 'N803_model_2' +% and used to define options (see function for list) +% EX: N803_single(SoluTimes,DoseTimes,AllPars,'AbsTol',1e-2} +% will set ode solver absolute tolerance to 1e-2 +% +%% ======================================================================== +% OUTPUTS +% ======================================================================== +% +% Y_OUT(:,1) = V at points in 'SoluTimes' [log fold change] cohort 1 +% Y_OUT(:,2) = T8 at points in 'SoluTimes' [fold change] cohort 1 +% Y_OUT(:,3) = V at points in 'SoluTimes' [log fold change] cohort 2 +% Y_OUT(:,4) = T8 at points in 'SoluTimes' [fold change] cohort 2 +% +% PARS(1,:) = parameters for cohort 1 (see code) +% PARS(2,:) = parameters for cohort 2 (see code) +% +%% ======================================================================== +% FUNCTION +% ======================================================================== +function [Y_OUT,PARS] = ... + N803_shared(SoluTimes,DoseTimes,AllPars,SkipTimes,oneCohort,... + varargin) + +if isempty(oneCohort) ; RunCohort = [ 1 1 ] ; +elseif oneCohort == 1 ; RunCohort = [ 1 0 ] ; +else ; RunCohort = [ 0 1 ] ; +end + +Y_Cohort = cell(1,2) ;% cell for storing outputs +P_Cohort = cell(1,2) ;% cell for storing parmeters + +% Rename inputed parameters ----------------------------------------------- +Vi(1) = AllPars(01) ;% V initial value [log(#/mL)] (cohort 1) +Vi(2) = AllPars(02) ;% V initial value [log(#/mL)] (cohort 2) +EBi(1) = AllPars(03) ;% E+B initial value [#/無] (cohort 1) +EBi(2) = AllPars(04) ;% E+B initial value [#/無] (cohort 2) +fE(1) = AllPars(05) ;% initial frequency: E/(E+B) (cohort 1) +fEn = AllPars(06) ;% normalized E/(E+B) (co 2) +fE(2) = fE(1)+(0.5-fE(1))*fEn ;% initial frequency: E/(E+B) (cohort 2) + +q = AllPars(07) ;% V growth rate (if E+B were absent) [/d] +psi = AllPars(08) ;% ratio of base killing rates gB0/gE0 +V50E = AllPars(09) ;% 50% viral stimulation saturation for E [#/mL] +V50B = AllPars(10) ;% 50% viral stimulation saturation for B [#/mL] +mEn = AllPars(11) ;% normalized Ea reversion rate constant [] +mBn = AllPars(12) ;% normalized Ba reversion rate constant [] + +EB50 = AllPars(13) ;% 50% E+B proliferation saturation [#/無] +p0n = AllPars(14) ;% nomalized E0/B0 proliferation rate constant [/d] +pE = AllPars(15) ;% Ea proliferation rate constant [/d] +pB = AllPars(16) ;% Ba proliferation rate constant [/d] +d = AllPars(17) ;% E0/B0 death rate constant [/d] +dA = AllPars(18) ;% Ea/Ba death rate constant [/d] + +Xi = AllPars(19) ;% X initial condition [pmol/kg] +ka = AllPars(20) ;% N803 absorption rate constant [/d] +ke = AllPars(21) ;% N803 elimination rate constant [/d] +vd = AllPars(22) ;% N803 'volume of distribution'/'bioavailability' [L/kg] +C50 = AllPars(23) ;% 50% N803 stimulation concentration [pM] (Cohort 1) +pm = AllPars(24) ;% E0/B0 maximum proliferation rate [] +aE1 = AllPars(25) ;% E activation stimulation factor [] +aB1 = AllPars(26) ;% B activation stimulation factor [] + +dR = AllPars(27) ;% R decay rate constant [/d] +sig = AllPars(28) ;% ratio of initial regulation due to B/E +p2 = AllPars(29) ;% E0/B0 proliferation regulation factor [] +gB2 = AllPars(30) ;% B killing regulation factor [] (cohort 1) + +%% ------------------------------------------------------------------------ +% Calculate some initial conditions & parameters -------------------------- + +Vi = 10.^(Vi - 3) ;% converting V initial value [#/無] +V50E = V50E/1000 ;% 50% viral stimulation saturation for E [#/無] +V50B = V50B/1000 ;% 50% viral stimulation saturation for B [#/無] +YE = Vi ./ (Vi+ V50E) ;% initial V/(V50E+V) [cohort 1,2] +YB = Vi ./ (Vi+ V50B) ;% initial V/(V50B+V) [cohort 1,2] + +% calculate initial R, and sE,sB +z = YE + sig*YB ; +Ri = [ 1 , (z(2)/z(1)) ] ;% initial regulation [cohort 1,2] +R = Ri(2) ;% initial regulation (cohort 2) +sE = dR / ( YE(1) + sig*YB(1) ) ;% R generation due to E0 activation [/d] +sB = sig*sE ;% R generation due to B0 activation [/d] + +% restrict mE and mB such that initial activation aE and aB are positive +UE = (2*pE/(pE+dA))^7 ; +UB = 2*pB/(pB+dA) ; +mE = mEn*dA/(UE-1) ;% Ea reversion rate constant [/d] +mB = mBn*dA/(UB-1) ;% Ba reversion rate constant [/d] + +% solve for initial ratios below (based on active steady-state) +ZE = UE/(mE+dA) ; +for i = 1:7 + ZE = ZE + (2*pE)^(i-1)/(pE+dA)^i ;% EAi/aEi/E0i +end +ZB = 1/(pB+dA) + UB/(mB+dA) ;% BAi/aBi/B0i + +WE = 1 ; +for i = 1:7 + WE = WE + (mE+dA)*(pE+dA)^(i-1)/(2*pE)^i ;% EAi/E8i +end +WB = 1 + (mB+dA)/(2*pB) ;% BAi/B2i + +QE = mE/WE - 1/ZE ;% collection +QB = mB/WB - 1/ZB ;% collection + +% restrict p0 to ensure same sign for E0/EA and for B0/BA +p0_max = min( d*(1+p2*Ri).*(EB50+EBi)/EB50 ) ;% maximum value for p0 +p0 = p0n * p0_max ;% E0/B0 prolif rate constant [/d] +p1 = pm/p0 ;% E0/B0 proliferation stimulation factor +pi = p0*EB50./(EB50+EBi)./(1+p2*Ri) ;% initial E0/B0 prolif rate [/d] + +% calculate aE0,aB0 and aE2,aB2 +aEi = (d-pi)/QE/ZE ;% initial E0 activation rate [/d] +aBi = (d-pi)/QB/ZB ;% initial B0 activation rate [/d] +z = aEi./YE ; +aE2 = ( z(1)-z(2) ) / ( R*z(2)-z(1) ) ;% E0 activation rate constant [/d] +aE0 = aEi(1) / YE(1) * (1+aE2) ;% E activation regulation factor [] +z = aBi./YB ; +aB2 = ( z(1)-z(2) ) / ( R*z(2)-z(1) ) ;% B0 activation rate constant [/d] +aB0 = aBi(1) / YB(1) * (1+aB2) ;% B activation regulation factor [] + +% solve for initial values of E0,Ea,B0,Ba each cohort +Ei = EBi.*fE ;% initial E +Bi = EBi.*(1-fE) ;% initial B +E0 = Ei./(1+ZE*aEi) ;% initial E0 +B0 = Bi./(1+ZB*aBi) ;% initial B0 +EA = E0.*(ZE*aEi) ;% initial EA +BA = B0.*(ZB*aBi) ;% initial BA + +% calculate gE0,gB0 and gE2 +beta = psi * BA ./ (1+gB2*Ri) ; z = beta(1) - beta(2) ; +a = z*R ; b = EA(1)*R - EA(2) + z*(1+R) ; c = EA(1) - EA(2) + z ; +gE2 = ( -b + sqrt(b^2 - 4*a*c) ) / (2*a) ;% E killing regulation factor [] +gE0 = q / ( EA(1)/(1+gE2) + beta(1) ) ;% Ea killing rate constant [無/#-d] +gB0 = psi * gE0 ;% Ba killing rate constant [無/#-d] + +%% Do for each cohort (NOT indenting loop) ================================ +for c = 1:2 + +% solve for initial E1-8 and B1-2 +E = zeros(1,8) ;% initial E1-E8 +E(8) = EA(c)/WE ;% E8 +E(7) = E(8) * (mE+dA)/(2*pE) ;% E7 +for i = 6:-1:1 + E(i) = E(i+1) * (pE+dA) / (2*pE) ;% E6 to E1 +end +B = BA(c)/WB * [ (mB+dA) / (2*pB) , 1 ] ;% initial B1-B2 + +%% ------------------------------------------------------------------------ +% Prepare parameter and initial value vectors and call 'N803_model_2' ----- + +Pars(01) = q ;% V growth rate (if E+B were absent) [/d] +Pars(02) = gE0 ;% Ea killing rate constant [無/#-d] +Pars(03) = gB0 ;% Ba killing rate constant [無/#-d] + +Pars(04) = V50E ;% 50% viral stimulation saturation for E [#/無] +Pars(05) = V50B ;% 50% viral stimulation saturation for B [#/無] +Pars(06) = aE0 ;% E0 activation rate constant [/d] +Pars(07) = aB0 ;% B0 activation rate constant [/d] +Pars(08) = mE ;% Ea reversion rate constant [/d] +Pars(09) = mB ;% Ba reversion rate constant [/d] + +Pars(10) = EB50 ;% 50% E+B proliferation saturation [#/無] +Pars(11) = p0 ;% E0/B0 proliferation rate constant [/d] +Pars(12) = pE ;% Ea proliferation rate constant [/d] +Pars(13) = pB ;% Ba proliferation rate constant [/d] +Pars(14) = d ;% E0/B0 death rate constant [/d] +Pars(15) = dA ;% Ea/Ba death rate constant [/d] + +Pars(16) = Xi ;% X initial condition [pmol/kg] +Pars(17) = ka ;% N803 absorption rate constant [/d] +Pars(18) = ke ;% N803 elimination rate constant [/d] +Pars(19) = vd ;% N803 'volume of distribution'/'bioavailability' [L/kg] +Pars(20) = C50 ;% 50% N803 stimulation concentration [pM] +Pars(21) = p1 ;% E0/B0 proliferation stimulation factor [] +Pars(22) = aE1 ;% E activation stimulation factor [] +Pars(23) = aB1 ;% B activation stimulation factor [] + +Pars(24) = sE ;% R generation due to E0 activation [/d] +Pars(25) = sB ;% R generation due to B0 activation [/d] +Pars(26) = dR ;% R decay rate constant [/d] +Pars(27) = gE2 ;% E killing regulation factor [] +Pars(28) = gB2 ;% B killing regulation factor [] +Pars(29) = p2 ;% E0/B0 proliferation regulation factor [] +Pars(30) = aE2 ;% E activation regulation factor [] +Pars(31) = aB2 ;% B activation regulation factor [] + +% V E0-8 B0-2 X C R initial values +Yic = [ Vi(c) E0(c) E B0(c) B 0 0 Ri(c) Ri(c) ] ; + +if any( [ Pars Yic ] < 0 ) + error('Negative parameters or initial values.') +end + +% If 'SkipTimes' is empty, do not skip any times +if isempty(SkipTimes{c}) ; SkipTimes{c} = [-inf inf] ; end + +idLo = SoluTimes < SkipTimes{c}(1) ;% index of early times to skip soln +idHi = SoluTimes > SkipTimes{c}(2) ;% index of later times to skip soln +idSol = ~ ( idLo | idHi ) ;% index of times in 'SoluTimes' to solve + +if RunCohort(c) == 1 + Y_COH = N803_model_2(SoluTimes(idSol),DoseTimes{c},Pars,Yic,varargin) ; + Y_LO = ones(sum(idLo),1)*Y_COH(1 ,:) ;% constant Y for early times + Y_HI = ones(sum(idHi),1)*Y_COH(end,:) ;% constant Y for later times + Y_COH = [ Y_LO ; Y_COH ; Y_HI ] ;%#ok % total 'solution' matrix + Y_Cohort{c} = Y_COH ; + P_Cohort{c} = [ Pars Yic ] ; +end + +end + +%% Prepare main outputs 'Y_OUT' and 'PARS' ================================ + +Y_OUT = [ Y_Cohort{1} , Y_Cohort{2} ] ; +PARS = [ P_Cohort{1} ; P_Cohort{2} ] ; + +end \ No newline at end of file