#Pkg.add("Distributions") using Distributions nRows = 10 nCols = 5 X = sample([0,1,2],(nRows,nCols)) methods(sample) X = [ones(nRows,1) X] nRowsX, nColsX = size(X) mean = 0.0 std = 0.5 b = rand(Normal(mean,std),nColsX) resStd = 1.0 y = X*b + rand(Normal(0,resStd),nRowsX) using Distributions function simDat(nObs,nLoci,bMean,bStd,resStd) X = [ones(nObs,1) sample([0,1,2],(nObs,nLoci))] b = rand(Normal(bMean,bStd),size(X,2)) y = X*b + rand(Normal(0.0, resStd),nObs) return (y,X,b) end nObs = 10 nLoci = 5 bMean = 0.0 bStd = 0.5 resStd = 1.0 res = simDat(nObs,nLoci,bMean,bStd,resStd) y = res[1] X = res[2] b = res[3] X # installing package # only needs to be done once #Pkg.clone("https://github.com/reworkhow/XSim.jl.git") using XSim chrLength = 1.0 numChr = 1 numLoci = 2000 mutRate = 0.0 locusInt = chrLength/numLoci mapPos = [0:locusInt:(chrLength-0.0001)] geneFreq = fill(0.5,numLoci) XSim.init(numChr,numLoci,chrLength,geneFreq,mapPos,mutRate) pop = startPop() nGen = 20 popSize = 500 pop.popSample(nGen,popSize) M = pop.getGenotypes() k = size(M,2) nQTL = 50 QTLPos = sample([1:k],nQTL,replace=false) mrkPos = deleteat!([1:k],sort(QTLPos)) Q = M[:,QTLPos] X = M[:,mrkPos] nQTL = size(Q,2) nObs = size(Q,1) α = rand(Normal(0,1),nQTL) a = Q*α # scaling breeding values to have variance 25.0 v = var(a) genVar = 25.0 a *= sqrt(genVar/v) ans = var(a) println("genetic variance = ", ans) # formatted printing @printf "genetic variance = %8.2f " ans resVar = 75.0 resStd = sqrt(resVar) e = rand(Normal(0,resStd),nObs) y = 100 + a + e @printf "phenotypic mean = %8.2f \n" Base.mean(y) @printf "phenotypic variance = %8.2f \n" var(y) popA = pop.popNew(100) popB = pop.popNew(100) popAB = XSim.popCross(100,popA,popB) MAB = popAB.getGenotypes() freq=Base.mean(M,1)/2; using Gadfly plot(x=freq,Geom.histogram, Guide.title("Distribution of Gene Frequency"), Guide.ylabel("Frequency"), Guide.xlabel("Gene Frequency")) ;ipython nbconvert --to slides wrkShpSlides1.ipynb