Created
August 6, 2015 15:42
-
-
Save zkamvar/95af8adaf1b3f01a4995 to your computer and use it in GitHub Desktop.
Place microsatellites in the correct order for genind objects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resort_microsat <- function(x){ | |
# Gather all alleles, convert to numeric, and reorder | |
alls <- adegenet::alleles(x) | |
alln <- lapply(alls, as.numeric) | |
alln <- lapply(alln, order) | |
# Loop over the names and paste together the locus name and the sorted alleles. | |
alls <- lapply(names(alls), function(i) paste(i, alls[[i]][ alln[[i]] ], sep = ".")) | |
# Convert to a vector an match the name to the column names of the data matrix. | |
cols <- unlist(alls, use.names = FALSE) | |
cols <- match(cols, colnames(tab(x))) | |
return(x[, cols]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here's a small working demonstration
This works:
This has problems:
This fixes everything: