# Rocchetti 2013
# TGI model in vivo with two drugs in combination.
#
# This model is used for estimation.
#
# Limitations:
# - EVID encoded as a covariate in the data object
#
# Compatibility:
# NONMEM
# (at the time of submission, Monolix is not supported due to the absence of EVID support)
#
# Dataset:
# Simulated dataset
#
# Evaluation method for this model:
# run NONMEM estimation via TEL;
# compare individual fits with figures in the paper (FIG. 5B)
#
# By Elisa Borella, Letizia Carrara, Silvia Lavezzi, Paolo Magni, Giulia Muzio, Lorenzo Pasotti, Elena Tosca
# BMS lab - Univ Pavia
# Copyright 2015
#

rocchetti2013_data = dataObj{
	
   DECLARED_VARIABLES{Y::observation Q0_A::dosingTarget Q0_B::dosingTarget}
   
   DATA_INPUT_VARIABLES{
      ID:{use is id}
      TIME:{use is idv} #day
      DV:{use is dv, variable=Y}
      AMT:{use is amt,  define={1 in CMT as Q0_A, 3 in CMT as Q0_B}} #micromole/kg
      CMT:{use is cmt}
      EVID:{use is evid}
   }   
	SOURCE{
		srcfile: {file = "Simulated_rocchetti2013_data.csv",
	    inputFormat is nonmemFormat}
   }
}

rocchetti2013_pri = priorObj{
	PRIOR_PARAMETERS{
		par_CV1=1
		par_CV2=1
		par_IC50COMBO1=1
		par_IC50COMBO2=1
	}
	PRIOR_VARIABLE_DEFINITION{
		POP_LAMBDA0=0.14
		POP_LAMBDA1=0.129
		POP_W0=0.062
		POP_K1=3.54
		POP_K2=0.221
		POP_IC50=2.02
		SIGMA_RES_W=1
		CV=0.1
		POP_IC50COMBO=1
#		CV ~ distribuzione(par1=par_CV1,par2=par_CV2)
#		POP_IC50COMBO ~ distribuzione(par1=par_IC50COMBO1,par2=par_IC50COMBO2)
	}
}

rocchetti2013_par = parObj{

   STRUCTURAL{
      POP_LAMBDA0:{value=0.14, fix=true} #1/day
      POP_LAMBDA1:{value=0.129, fix=true} #g/day
      POP_W0:{value=0.062, fix=true} #g
      POP_K1:{value=3.54, fix=true} #1/day
      POP_K2:{value=0.221, fix=true} #L/micromole/day
      POP_IC50:{value=2.02, fix=true} #micromole/L
      POP_IC50COMBO:{value=7, lo=0} #micromole/L
      CV:{value=0.1, lo=0}
   }

   VARIABILITY{
      SIGMA_RES_W:{value=1, type is var, fix=true}
   }
}

rocchetti2013_mdl = mdlObj{

	IDV{T}
	
	STRUCTURAL_PARAMETERS{
      POP_LAMBDA0
      POP_LAMBDA1  
      POP_W0
      POP_K1
      POP_K2
      POP_IC50
      POP_IC50COMBO
      CV
	}
	
	VARIABILITY_PARAMETERS{
      SIGMA_RES_W
	}
	
	VARIABILITY_LEVELS{
	   DV: {level=1, type is observation} 
	   ID: {level=2, type is parameter}
	}
	
	INDIVIDUAL_VARIABLES{
	  LAMBDA0 = POP_LAMBDA0
      LAMBDA1 = POP_LAMBDA1  
      W0 = POP_W0
      K1 = POP_K1
      K2 = POP_K2
      IC50 = POP_IC50
	  IC50COMBO = POP_IC50COMBO
	}
	
	RANDOM_VARIABLE_DEFINITION(level=DV){
	   eps_RES_W ~ Normal(mean=0, var=SIGMA_RES_W)
	}
	
	MODEL_PREDICTION{

	    DEQ{
	    KA_A=24*ln(2)/6.19 #=2.69 1/day
	  	KE_A=ln(2)/6.05 #=0.115 1/day
	  	FV1_A=1/0.119 #8.4 kg/L
	  	KA_B=18.8 #1/day
	  	KE_B=49.2 #1/day
	  	K21=10.4 #1/day
	  	K12=141.1 #1/day
	  	FV1_B=1/2.13 #0.469 kg/L
	  	EMAX=1
	  	PSI=20	
	  	
	    C1_A=Q1_A*FV1_A
		C1_B=Q1_B*FV1_B
		K2INH=K2*(1-C1_A/(C1_A+IC50COMBO))
		
		WTOT=Z0+Z1+Z2+Z3
		
		Q0_A:{deriv=-KA_A*Q0_A, init=0}
		Q1_A:{deriv=KA_A*Q0_A-KE_A*Q1_A, init=0}
		
		Q0_B:{deriv=-KA_B*Q0_B, init=0}
		Q1_B:{deriv=KA_B*Q0_B-(K12+KE_B)*Q1_B+K21*Q2_B, init=0}
		Q2_B:{deriv=K12*Q1_B-K21*Q2_B, init=0}
		
		Z0:{deriv=(LAMBDA0*Z0/((1+(WTOT*LAMBDA0/LAMBDA1)^PSI)^(1/PSI)))*(1-EMAX*C1_A/(C1_A+IC50))-K2INH*C1_B*Z0, init=W0}
		Z1:{deriv=K2INH*C1_B*Z0-K1*Z1, init=0}
		Z2:{deriv=K1*Z1-K1*Z2, init=0}
		Z3:{deriv=K1*Z2-K1*Z3, init=0}
	    }
   }
   
   OBSERVATION{
   Y : { type is proportionalError, proportional = CV, eps = eps_RES_W, prediction = WTOT }
   }
}

rocchetti2013_task = taskObj{ 

    ESTIMATE{ 
	set algo is mcmc
	        TARGET_SETTINGS(target="BUGS"){
            set 
            nchains = 1,
            burnin = 1,
            niter = 1,
        #    parameters = "LAMBDA0_POP,LAMBDA1_POP,K1_POP,K2_POP,W0_POP,LAMBDA0,K2,CV",
         #    thinupdater=1,
          #  thinsamples=5, # uno dei due
#           odesolver="LSODA", #oppure LSODA
        #    dic="true",
        	winbugsgui="true" # oppure no
        }
    }
}

rocchetti2013 = mogObj{

	OBJECTS{
		rocchetti2013_data : { type is dataObj }
		rocchetti2013_mdl : { type is mdlObj }
		rocchetti2013_pri : { type is priorObj }
		rocchetti2013_task: { type is taskObj }
	}
}
