Hi,
Anyone knows How to convert tree in phylip format into newick format?
Thanks!
Hi,
Anyone knows How to convert tree in phylip format into newick format?
Thanks!
Very easily with biopython (you will need to install it of course, if you haven't already):
Create the following script:
from Bio import Phylo
import sys
infile = sys.argv[1]
intype = sys.argv[2]
outfile = sys.argv[3]
outtype = sys.argv[4]
Phylo.convert(infile,intype, outfile, outtype)
then call it from the command line like so:
$ python convert_trees.py mytree.nx nexus mytree.nwk newick
not working Traceback (most recent call last): File "convert_trees.py", line 9, in <module> Phylo.convert(infile,intype, outfile, outtype) File "/home/maria/.local/lib/python2.7/site-packages/Bio/Phylo/_io.py", line 90, in convert return write(trees, out_file, out_format, kwargs) File "/home/maria/.local/lib/python2.7/site-packages/Bio/Phylo/_io.py", line 81, in write n = getattr(supported_formats[format], 'write')(trees, fp, *kwargs) File "/home/maria/.local/lib/python2.7/site-packages/Bio/Phylo/NewickIO.py", line 58, in write return Writer(trees).write(handle, plain=plain, *kwargs) File "/home/maria/.local/lib/python2.7/site-packages/Bio/Phylo/NewickIO.py", line 251, in write for treestr in self.to_strings(kwargs): File "/home/maria/.local/lib/python2.7/site-packages/Bio/Phylo/NewickIO.py", line 285, in to_strings for tree in self.trees: File "/home/maria/.local/lib/python2.7/site-packages/Bio/Phylo/_io.py", line 51, in parse for tree in getattr(supported_formats[format], 'parse')(fp, **kwargs): KeyError: 'phylip'
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
any help?
I'd suggest opening a new question, but in any event, this shouldn't be posted as an answer here.
EDIT, the previous code I posted was untested so I've just noticed a couple of problems with it and updated it accordingly. It's tested and should work properly now.
am so sorry for adding this as an answer. sorry its just in mistake.
its still give error.
Please post the command you're using.
Ah yeah I see the issue. My fault. The previous code should not have said 'phylip'. This is an alignment format not a tree format.
What file are you trying to convert?
I have a tree in phylip format and i want to convert it to newick format
Are you certain of that? Can you post a snippet of the file you have?
From the
BioPython.Phylo
documentation: