model{
  for (i in 1:nSNP){
    # likelihood
    z[i] ~ dbetabin(a[i],b[i],N[i])
    mixture[i] ~ dcat(p[1:3])
    a[i] <- equals(mixture[i],1)*(m + (step(i-cgp1)*step(cgp2-i))*d1)*kappa + equals(mixture[i],2)*(m - (step(i-cgp1)*step(cgp2-i))*d2)*kappa + equals(mixture[i],3)*1
    b[i] <- equals(mixture[i],1)*(1 - m - (step(i-cgp1)*step(cgp2-i))*d1)*kappa + equals(mixture[i],2)*(1- m + (step(i-cgp1)*step(cgp2-i))*d2)*kappa + equals(mixture[i],3)*1
  }


# hyper-hyper prior
  f ~ dbeta(1,1)
  kappa ~ dgamma(1,0.1)
  cgp1 ~ dunif(1,nSNP)
  cgp2 ~ dunif(cgp1+0.25*nSNP,nSNP)

  p[1] <- 0.495
  p[2] <- 0.495
  p[3] <- 0.01

  d1 <- m*(1+f)/(1-f+2*m*f) - m
  d2 <- m - m*(1-f)/(f-2*m*f+1) 

  # coverage part
  for (i in 1:nSites){
    # likelihood
    N_cov[i] ~ dnegbin(p_cov,r_cov)
  }
  #prior
  p_cov <- r_cov/(m_cov+r_cov)
  m_cov <- m0
  r_cov ~ dgamma(0.01,0.01)
}
