function [qinfo,p,a] = qtlsim(x,snp,vfrac)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
%                       QTL_SIM                          %
%                                                        %
%   A function to simulate the quantitive trait values   %
%                                                        %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

x_dim=size(x);
nsub = x_dim(1);



qinfo=zeros(nsub,1);
n2=sum(x(:,snp));

p=n2/(2*nsub);



v=p*(1-p)*2;
a = sqrt(vfrac/v);


for i=1:nsub;
    if x(i,snp)==0
        qinfo(i)=(0-a+normrnd(0,(1-vfrac)^0.5));
    end
    
    if x(i,snp)==1
        qinfo(i)=(normrnd(0,(1-vfrac)^0.5));
    end
    
    if x(i,snp)==2
        qinfo(i)=(0+a+normrnd(0,(1-vfrac)^0.5));
    end
    
end



end

