Convert Distance Matrix To Newick Format- Biopython
1
1
Entering edit mode
10.8 years ago
asmariyaz23 ▴ 10

Need to make a plot merging heat map and a phylogenetic tree in Python. I have already made the heat map using the square distance matrix that I have with the help of numpy and matplotlib but now I would like to merge a phylogentic tree with this heat map, For this purpose I found a BioPython Package called ETE2, however the problem with this is that it needs a newick formatted file instead of the distance matrix(Phylip format) that I have. Is there a module in BioPython which could help me in this conversion(Distance matrix to Newick)?

python distance phylogenetics • 11k views
ADD COMMENT
1
Entering edit mode
10.8 years ago
jhc ★ 3.0k

You will need a method like UPGMA or Neighbor joining to convert your matrix into a tree. If your matrix data is not based on sequence distances, probably you just need a clustering strategy such as UPGMA.

I provided a recipe in stackoverflow to run a clustering analysis with hcluster in python and convert the result into a tree using the ETE toolkit. Take a look, it may help you.

ADD COMMENT
0
Entering edit mode

I got a tree with your program. However, I had to avoid the organism names and make data matrix out of numerical values alone. However I face a problem when I need to make a heat map out of such a tree.With the use of "Tree" and Profileface (which is used for heatmap) in ETE2 package, I tried making it but tree node does not have a profile face attribute.

Here is my code: def distmat_clustered_tree(fullmatrix_filename): list_lines=reading_file(fullmatrix_filename) full_mapped_floats,org_list=convert_num(list_lines) Z=linkage(full_mapped_floats,"average") T=to_tree(Z) return T

def clusT_eteTree(T): root=Tree() root.dist=0 root.name="root" item2node={T:root} to_visit =[T] while to_visit: node=to_visit.pop() cl_dist =node.dist/2.0 for ch_node in [node.left, node.right]: if ch_node: ch=Tree() ch.dist=cl_dist ch.name=strch_node.id) item2node[node].add_child(ch) item2node[ch_node]=ch to_visit.append(ch_node)
tree=root ##tree.add_face(ProfileFace(20, 1, 3, width=200, height=40, style='lines', colorscheme=2),column=0,position="branch-right") tree.show() ##nw_str=tree.get_newick(features=[],format=1) return

ADD REPLY
0
Entering edit mode
ADD REPLY

Login before adding your answer.

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