Skip to content

Instantly share code, notes, and snippets.

@zkamvar
Last active February 12, 2018 20:49
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/aeaff83b9d126d55aade to your computer and use it in GitHub Desktop.
Save zkamvar/aeaff83b9d126d55aade to your computer and use it in GitHub Desktop.
Convert a genind object to a genambig object from polsay
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