dev/koff_fit_repeats.R

######=------>
library(ADASPR)
#-------->testing code for multiligandmodel
#kon<-c(2E3, 1E5, 3E4)
kon<-c(2E3, 1E5, 3E2)
#koff<-c(1E-4, 1E-4, 5E-3)
koff<-c(1E-2, 1E-3, 1E-3)

analyteConcentrations<-c(
							#5E-4, 4E-4, 3E-4, 2E-4, 
							#1E-5, 9E-6, 6E-6, 3E-6, 2E-6
							9E-5, 7E-5, 5E-5, 3E-5, 2E-5
						)
associationLength<-1000 
dissociationLength<-2000
#Rmax<-c(30,120,40)
Rmax<-c(30,100,40)

mlgm<- new("MultiLigandModel", kon=kon, koff=koff, analyteConcentrations=analyteConcentrations, 
		associationLength=associationLength, dissociationLength=dissociationLength, Rmax=Rmax
		)
#now start multiple runs for estimation distributions of results
runs<-500
fpc_lst<-vector("list", runs)
fpc_m<-NULL
m_m<-NULL


moments<-7
setwd("E:\\feng\\LAB\\hg\\SPR_models\\meanAffinity_mixture")
tmStep<-as.numeric(Sys.time())
count<-4000
for (i in 1:runs)
{
	cat("doing ", i, "th data set....\n")
	flush.console()
	set.seed(i+count)		
	sData<-Simulate(mlgm,sampleFreq=0.01, sd=0.1)	

	#non-steady state
	###=======> now following the previous code, we start testing the koffs
	fpc<-fitPolySPRsKoff(sData[[1]], debug=T, degree=100, weights.type="exp", weights.step=0.01, weights.scale=200)

	###======>
	###now testing the steady state koff
	##based on the previous fitPolySPRsKoff
	ms<-fitCoefficientPolySPRsKoff(fpc, analyteConcentrations, debug=F, degree=1)#, sum(Rmax))
	
	#degree<-length(analyteConcentrations)
	nConc<-length(analyteConcentrations)
	fpc_m<-matrix(rep(0, moments*nConc), ncol=moments, nrow=nConc)
	for(j in 1:nConc) #row
	{
		Y<-rep(0, moments)
		
		for(k in 1:moments)
		{
			fpc_m[j,k]<-fpc[[j]][[1]][k]
		}
		
		#Y<-(-1)^(curr_degree-1)*Y
	}
	rownames(fpc_m)<-paste(rep("conc", nConc), c(1:nConc))
	colnames(fpc_m)<-paste(rep("moments", moments), c(1:moments))
	fpc_lst[[i]]<-fpc_m
	if(i==1)
	{
		m_m<-matrix(rep(0,runs*moments), nrow=runs, ncol=moments)
	}
	m_m[i,]<-ms
	if(i%%20==0)
	{
		save(m_m, fpc_lst, file=paste("koff_",count,"_",tmStep,".Rdata",sep=""))
	}
}

#start to get the distribution from koffs
r0<-matrix(Rmax,nrow=length(analyteConcentrations),ncol=length(Rmax), byrow=T)
for(i in 1:length(analyteConcentrations))
{
r0[i,]<-Rmax*kon*analyteConcentrations[i]/(kon*analyteConcentrations[i]+koff)*(1-exp(-(kon*analyteConcentrations[i]+koff)*associationLength))
}
#expected koff moments over R0
E_R0<-c(sum(r0[1,]),sum(r0[2,]),sum(r0[3,]),sum(r0[4,]),sum(r0[5,]))
E_koff1<-rep(0,length(analyteConcentrations))
E_koff2<-rep(0,length(analyteConcentrations))
E_koff3<-rep(0,length(analyteConcentrations))
E_koff4<-rep(0,length(analyteConcentrations))

for(i in 1:length(analyteConcentrations))
{
	E_koff1[i]<-sum(koff*r0[i,]/sum(r0[i,]))
	E_koff2[i]<-sum(koff^2*r0[i,]/sum(r0[i,]))
	E_koff3[i]<-sum(koff^3*r0[i,]/sum(r0[i,]))
	E_koff4[i]<-sum(koff^4*r0[i,]/sum(r0[i,]))
	
}


#expected koff moments over Rmax
E_koff<-rep(0,7)
E_koff[1]<-sum(Rmax)
E_koff[2]<-sum(koff*Rmax/sum(Rmax))
E_koff[3]<-sum(koff^2*Rmax/sum(Rmax))
E_koff[4]<-sum(koff^3*Rmax/sum(Rmax))
E_koff[5]<-sum(koff^4*Rmax/sum(Rmax))
E_koff[6]<-sum(koff^5*Rmax/sum(Rmax))
E_koff[7]<-sum(koff^6*Rmax/sum(Rmax))
ffeng23/ADASPR documentation built on July 13, 2019, 1:15 p.m.