Last active
January 11, 2017 22:58
-
-
Save zkamvar/bacbad22c27251196829052652b985c8 to your computer and use it in GitHub Desktop.
Replacing multilocus lineages with one representative sample
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
# Replacing multilocus lineages with one representative sample | |
library(poppr) | |
data(monpop) | |
mlg.filter(monpop) <- 0 + .Machine$double.eps | |
mondf <- genind2df(monpop, usepop = FALSE) | |
mid <- mlg.id(monpop) | |
orders <- unlist(mid, use.names = FALSE) | |
monpop <- monpop[orders, ] | |
mondif <- mondf[orders, ] | |
n <- vapply(mid, length, integer(1)) | |
sam <- vector(mode = "character", length = length(n)) | |
for (i in seq(mid)){ | |
sam[i] <- sample(mid[[i]], 1) # for a random sample | |
# sam[i] <- mid[[i]][length(mid[[i]])] # for the last sample | |
# sam[i] <- mid[[i]][1] # for the first sample | |
} | |
monpop2 <- df2genind(mondf[rep(sam, n), ], ploidy = 1, | |
ind.names = indNames(monpop), | |
pop = pop(monpop), | |
strata = strata(monpop)) | |
other(monpop2) <- other(monpop) | |
monpop2 <- as.genclone(monpop2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment