This worked a treat, thanks!
Hi there,
I have a binary matrix in a tab-delimited file of aligned SNPs, where 1=SNP and 0=non-SNP. The rows are the loci and the column are different individuals. For example
Position Isolate 1 Isolate 2 Isolate 3 ... Isolate n
4 1 0 0 ... 0
5 0 0 1 ... 1
10 1 1 0 ...0
etc.
I've seen a couple of posts mentioning that the R package 'APE' is good for generating trees from this type of data. However, after reading the documentation, it is not clear to me how this is done. Has anyone used this package for this type of data, and if so, can you please point me in the right direction?
Many thanks
1 answer
One way is through calculating the distance and then making a neighbor-joining tree. You will probably have to transpose your existing matrix so that taxa are in rows, but I am entering them directly in that orientation using rbind.
library(ape)
snp = rbind(A=c(1,1,1,0,1),B=c(1,1,0,1,1),D=c(1,1,1,1,1),E=c(0,1,0,1,0))
stree = nj(dist.gene(snp))
plot(stree)
Log in to answer this question.