I have a dataset with different levels of branches starting from the top level: stock -> mbranch -> sbranch -> lsbranch. I want to be able to visualize these levels of my data into Newick format. I have different language groups within each stock level and would like to make different trees based off of these highest level groups.
For example my data is in the format as follows:
sample= data.frame("stock" = c("A", "A", "B", "B", "B"), "mbranch" = c("C", "D", "E", "F", "G"), "sbranch" = c("H", "O", NA, "K", "L"), "lsbranch" = c("I", "J", NA, "M", "N"), "name" = c("Andrea", "Kevin", "Charlie", "Naomi", "Sam"))
And I am trying to have an output of the newick tree format which would be something like:
tree = "(A(C(H(I(Andrew))),D(O(J(Kevin)))),B(E(Charlie),F(K(M(Naomi))),G(L(N(Sam)))));"
plot(read.dendrogram(tree))
I'm doing this so later on I can do a distance matrix of the nodes of my outputted tree.
Would the function write.tree be able to analyze data like this and make a tree from this (assuming my actual dataset is much larger)? Or in general, a function that would output the tree format. Thanks
You can use the
ape::read.tree()
function to read your newick format treeYou can then use
ape::write.tree
to save the tree into a newick file:To convert your table into a
"phylo"
object fromape
you can use this function (that might need some adjustements):Cheers, Thomas