Last active
February 12, 2018 20:49
-
-
Save zkamvar/aeaff83b9d126d55aade to your computer and use it in GitHub Desktop.
Convert a genind object to a genambig object from polsay
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
gen2polysat <- function(gen, newploidy = gen@ploidy){ | |
if (!require(polysat)){ | |
stop("User needs polysat installed") | |
} | |
gen <- recode_polyploids(gen, newploidy) | |
gendf <- genind2df(gen, sep = "/", usepop = FALSE) | |
gendf <- lapply(gendf, strsplit, "/") | |
gendf <- lapply(gendf, lapply, as.numeric) | |
ambig <- new("genambig", samples = indNames(gen), loci = locNames(gen)) | |
for (i in names(gendf)){ | |
res <- lapply(gendf[[i]], function(x) ifelse(is.na(x), Missing(ambig), x)) | |
Genotypes(ambig, loci = i) <- res | |
} | |
return(ambig) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment