Skip to content

Instantly share code, notes, and snippets.

@zkamvar
Last active January 11, 2017 22:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkamvar/bacbad22c27251196829052652b985c8 to your computer and use it in GitHub Desktop.
Save zkamvar/bacbad22c27251196829052652b985c8 to your computer and use it in GitHub Desktop.
Replacing multilocus lineages with one representative sample
# 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