So in Julia I want to create a dictionary (hash table or associative array) of arrays to store breed composition in dairy cattle. It took me a while but I found out how to declare it:
julia> a=Dict{String,Array{Float64,1}}()
Imagine the following pedigree
A 0 0 Holstein
B 0 0 Jersey
C A B
D A C
B 0 0 Jersey
C A B
D A C
then this Julia script computes breed fractions
#=
A 0 0 Holstein
B 0 0 Jersey
C A B
D A C
=#
breedcomp=Dict{String,Array{Float64,1}}()
#purebred founders
breedcomp["A"]=[1.0,0.0]
breedcomp["B"]=[0.0,1.0]
#rest of pedigree
breedcomp["C"]=0.5*(breedcomp["A"]+breedcomp["B"])
breedcomp["D"]=0.5*(breedcomp["A"]+breedcomp["C"])
display(breedcomp)
Dict{String, Vector{Float64}} with 4 entries:
"B" => [0.0, 1.0]
"A" => [1.0, 0.0]
"C" => [0.5, 0.5]
"D" => [0.75, 0.25]
No comments:
Post a Comment