[R-sig-genetics] genlight to treemix conversion
Zhian Kamvar
zkamvar at gmail.com
Mon Mar 14 21:54:19 CET 2016
Hi Daniel,
I'm not exactly sure this will work, but this might help:
# Setting up fake data
library('adegenet')
x <- glSim(100, 1e3, ploid=2)
pop(x) <- rep(letters[1:5], each = 20)
# conversion
altlist <- lapply(seppop(x), as.matrix)
get_pop_counts <- function(altmatrix){
alt <- apply(altmatrix, 2, sum, na.rm = TRUE)
ref <- apply(2 - altmatrix, 2, sum, na.rm = TRUE)
paste(alt, ref, sep = ",")
}
dat <- data.frame(lapply(altlist, get_pop_counts))
write.table(dat, file = "mydata.treemix", sep = "\t", row.names = FALSE, col.names = TRUE)
Zhian
> On Mar 12, 2016, at 00:32 , Daniel Fulop <dfulop.ucd at gmail.com> wrote:
>
> Dear all,
>
> I’m wondering if someone has code for converting data from genlight to treemix format. If you do and wouldn’t mind sharing it I would be most grateful.
>
> I think one could do as.matrix(genlight-object) and then sum the alleles for each population, but then I’m not sure how to deal with NAs.
>
> Thanks!
> Dan.
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-genetics mailing list
> R-sig-genetics at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-genetics
More information about the R-sig-genetics
mailing list