From 4b66ad8b1fee95cacdae105f3e46a2d33e5d10c6 Mon Sep 17 00:00:00 2001 From: "Thomas A. Christensen II" <25492070+MillironX@users.noreply.github.com> Date: Tue, 31 Aug 2021 18:27:16 -0500 Subject: [PATCH] Make column names more robust --- src/BeefBLUP.jl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/BeefBLUP.jl b/src/BeefBLUP.jl index e8db8a1..11e7834 100755 --- a/src/BeefBLUP.jl +++ b/src/BeefBLUP.jl @@ -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