model{
# E is the number of exons belong to gene
# T is the number of isoforms belong to gene
# l[i] is the length of exon i
# A is the isoform structure of gene, row corresponding to exon,and column corresponding to isoforms
# Sample is the matrix: row corresponding to sample, column correspongding to exon# length_transcript is the length of transcript
# parameters : N and p[] are interested
 # initialize r mu and alpha[]
 C <- 10000000
 for(i in 1:E){
       zeros[i] ~ dpois(zeros.mean[i])
       zeros.mean[i] <- -Log[i] + C

       Log[i] <- log(lambda[i]) + (Sample[i]-1)*log(lambda[i]+omega[i]*Sample[i])-lambda[i]-omega[i]*Sample[i]-loggam(Sample[i]+1)
       lambda[i] <- read_depth*l[i]*inprod(A[i,],f[1:T])
 }
for(w in 1:E){
 omega[w] <- 1-sqrt(1/(D[w]+1))
 D[w] ~ dexp(0.9765026) 
 
}


read_depth ~ dnorm(0.007,10000000)



for(m in 1:T) {       
delta[m] ~ dgamma(alpha[m],1);        
p[m] <- delta[m] / sum(delta[]);  
 }  
q[1]<- p[1];  
for(k in 2:T){     
  q[k] <- p[k]/(1-sum(p[1:(k-1)]));   
  } 
 f[1] ~ dbin(q[1],N); 
 for(j in 2:(T-1)) {   
  pi[j] <- N-sum(f[1:(j-1)])   
  f[j] ~ dbin(q[j],pi[j])  
 } 
 f[T]<-N-sum(f[1:(T-1)])  
N ~ dpois(lambda1) 
 lambda1 ~ dunif(r,mu)




}
