1
0
Fork 0
mirror of https://github.com/MillironX/beefblup.git synced 2024-11-14 03:23:09 +00:00

Make column names more robust

This commit is contained in:
Thomas A. Christensen II 2021-08-31 18:27:16 -05:00
parent 91fc553c4c
commit 4b66ad8b1f
Signed by: millironx
GPG key ID: 139C07724802BC5D

View file

@ -58,6 +58,9 @@ function beefblup(path::String, savepath::String, h2::Float64)
# Import data from a suitable spreadsheet
data = DataFrame(CSV.File(path))
# Make sure the data is in the proper format
renamecolstospec!(data)
# Sort the array by date
sort!(data, :birthdate)
@ -293,5 +296,23 @@ function additiverelationshipmatrix(id::AbstractVector, damid::AbstractVector, s
return A
end
"""
renamecolstospec(::DataFrame)
Renames the first four columns of the beefblup data sheet so that they can be referred to by
name instead of by column index, regardless of user input.
"""
function renamecolstospec!(df::DataFrame)
# Pull out the fixed-effect and observation name
othernames = propertynames(df)[5:end]
# Put specification column names and user-defined names together
allnames = cat([:id, :birthdate, :dam, :sire], othernames, dims=1)
# Rename in the DataFrame
rename!(df, allnames, makeunique=true)
return df
end
end