Binary SNP matrix into APE (R)
1
0
Entering edit mode
9.9 years ago
biogirl ▴ 210

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

alignment Phylogenetics SNP R Trees • 7.3k views
ADD COMMENT
2
Entering edit mode
9.9 years ago
beroe1 ▴ 40

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)
ADD COMMENT
0
Entering edit mode

This worked a treat, thanks!

ADD REPLY

Login before adding your answer.

Traffic: 2695 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6