Question: Convert From Graphviz (Dot Language) to Newick format
0
gravatar for richard_95
4.0 years ago by
richard_950
Germany
richard_950 wrote:

Hello,

I'm working on gain/loss gene events and for that I'm using a tool that gives as an output a gene tree in Graphviz format (dot language) like this:

digraph G {

0[label=Series];

1[label=Parallel];

2[label=Series];

3[label=v2];

4[label=v5];

5[label=v8];

6[label=Series];

7[label=v0];

8[label=v3];

9[label=v6];

10[label=v1];

11[label=v4];

12[label=v7];

0->1 ;

1->2 ;

2->3 ;

2->4 ;

2->5 ;

1->6 ;

6->7 ;

6->8 ;

6->9 ;

0->10 ;

0->11 ;

0->12 ;

}

It represents the tree as a directed graph in direction from the root to the leaves. Then it enumerates the nodes and each node has a label. The last part is the edges of the tree.

I would like to convert this output to Newick format. However I don't know much about programming so I was wondering if you can help me with this :)

ADD COMMENTlink modified 4.0 years ago by jhc2.8k • written 4.0 years ago by richard_950

I don't know of an easy solution short of writing a converter yourself. You could explore converting to another intermediate graph format and see if there is any tool that can then do the conversion from there to Newick (I don't know of any from the top of my head). I think your best bet would be to convert your dot file to a distance matrix from which you rebuild the tree with a phylogeny software that can read distance matrices. Also do you have to work with dot files ? The format is not suited to phylogenetic data, it's mostly designed for drawing graphs.

ADD REPLYlink written 4.0 years ago by Jean-Karim Heriche22k
1
gravatar for jhc
4.0 years ago by
jhc2.8k
Spain
jhc2.8k wrote:

with a little transformation of the graphviz format, you could get a parent->child tab delimited text based table. In example

v0 v1 1.0
v0 v2 1.0
v1 v3 1.0 
v1 v4 1.0

(third column represents branch distance)

Then you can use ETE3 to load that table as a tree structure (http://etetoolkit.org/docs/latest/reference/reference_tree.html#ete3.TreeNode.from_parent_child_table)

from ete3 import Tree
t = Tree.from_parent_child_table([line.split() for line in open("parent_child.txt")] )
print t
#      /-v3
#   /-|
#--|   \-v4
#  |
#   \-v2

and finally export as newick

t.write()
ADD COMMENTlink modified 4.0 years ago • written 4.0 years ago by jhc2.8k
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: 932 users visited in the last hour