Question: Convert Distance Matrix To Newick Format- Biopython
1
gravatar for asmariyaz23
7.1 years ago by
asmariyaz2310
United States
asmariyaz2310 wrote:

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 phylogenetics distance • 8.1k views
ADD COMMENTlink modified 7.1 years ago by jhc2.9k • written 7.1 years ago by asmariyaz2310
1
gravatar for jhc
7.1 years ago by
jhc2.9k
Spain
jhc2.9k wrote:

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 COMMENTlink written 7.1 years ago by jhc2.9k

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 REPLYlink written 7.1 years ago by asmariyaz2310

response in the ete mailing list: https://groups.google.com/forum/#!topic/etetoolkit/pXr4B71Ozt0

ADD REPLYlink written 7.1 years ago by jhc2.9k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1990 users visited in the last hour
_