How To Make A Phylogenetic Tree From A Binary Matrix
2
1
Entering edit mode
11.0 years ago
Diego D. ▴ 50

Hello :)

I need to generate a phylogenetic tree from a binary matrix.

First, i mapped the reads to the reference genome, then, i made the SNP calling with samtools, finally, i wrote a small script in perl to construct the matrix.

I have seen that there is a R package called "ape" that i can use for this purpose. I downloaded and installed it, but i don't know how to use it, i don't know much about R.

Anyone know how to get the tree from the binary matrix with ape?

thanks in advance.

• 9.3k views
ADD COMMENT
0
Entering edit mode

Related question here

ADD REPLY
4
Entering edit mode
8.3 years ago
gdevailly ▴ 40

I know that this is a really old question, but still it comes pretty early in my google search, I though I'd give you my solution:

library(ape)
mat <- matrix(
    c(
      1,1,1,1,1,1,1,
      0,0,1,0,1,0,1,
      0,0,1,0,0,0,1,
      1,1,1,0,1,1,1,
      0,0,0,0,0,0,0

    ), byrow = TRUE, nrow = 5, dimnames = list(paste0("r", 1:5), paste0("c", 1:7))
)

mat.nj <- nj(dist.gene(mat)) # neighbour joining tree construction
plot(mat.nj, "phylo") # we plot it
nodelabels() # we id node label

# internal node state reconstruction
MPR(mat[,1], mat.nj, outgroup = "r1") # this give us the value of all internal nodes for c1 assuming root of the tree is r1

# lapply magic to call MPR on all character/gene/whatever
internalNodes <- lapply(seq_len(ncol(mat)), function(x) MPR(mat[, x], mat.nj, outgroup = "r1")[, 1, drop = FALSE])
internalNodes <- do.call(cbind, internalNodes)
ADD COMMENT
0
Entering edit mode
11.0 years ago
Adrian Pelin ★ 2.6k

The Phylip package has something. but if you find how to do it with ape, I am interested to know.

ADD COMMENT

Login before adding your answer.

Traffic: 1800 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