I want to convert a genetic matrix (rows are samples, columns are alleles) into a STRUCTURE file (output .str) within R. Is there a preferred way to achieve this? I've found genind_to_structure in the graph4lg R package, but I wanted to see if there are other approaches.
An example of what I mean by a "genetic matrix":
# Build a matrix of alleles
temp <- lapply(1:30, function(i) sample(1:9, 4, replace = TRUE))
temp <- sapply(temp, paste, collapse="")
temp <- matrix(temp, nrow = 10, dimnames = list(paste("ind",1:10), paste("loc",1:3)))
temp
# Convert matrix to genind format (for adegenet package)
test <- df2genind(temp, ploidy = 4, sep = "")
test
# How to convert to STRUCTURE?
If anyone has input, please chime in! Thanks