How to convert tree in phylip format into newick format
1
1
Entering edit mode
6.1 years ago

Hi,

Anyone knows How to convert tree in phylip format into newick format?

Thanks!

phylip to newick conversion • 4.4k views
ADD COMMENT
0
Entering edit mode
 File "/home/x/.local/lib/python2.7/site-packages/Bio/AlignIO/__init__.py", line 234, in write
    raise ValueError("Unknown format '%s'" % format) ValueError: Unknown format 'newick'

any help?

ADD REPLY
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

am so sorry for adding this as an answer. sorry its just in mistake.

its still give error.

Traceback (most recent call last):
  File "convert_trees.py", line 9, in <module>
    Phylo.convert(infile,intype, outfile, outtype)
  File "/home/x/.local/lib/python2.7/site-packages/Bio/Phylo/_io.py", line 90, in convert
    return write(trees, out_file, out_format, **kwargs)
  File "/home/x/.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/x/.local/lib/python2.7/site-packages/Bio/Phylo/NewickIO.py", line 58, in write
    return Writer(trees).write(handle, plain=plain, **kwargs)
  File "/home/x/.local/lib/python2.7/site-packages/Bio/Phylo/NewickIO.py", line 251, in write
    for treestr in self.to_strings(**kwargs):
  File "/home/x/.local/lib/python2.7/site-packages/Bio/Phylo/NewickIO.py", line 285, in to_strings
    for tree in self.trees:
  File "/home/x/.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'
ADD REPLY
0
Entering edit mode

Please post the command you're using.

ADD REPLY
0
Entering edit mode
  python convert_trees.py phyliptree.phy phylip mytree.nwk newick
ADD REPLY
0
Entering edit mode

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?

ADD REPLY
0
Entering edit mode

I have a tree in phylip format and i want to convert it to newick format

ADD REPLY
0
Entering edit mode

Are you certain of that? Can you post a snippet of the file you have?

From the BioPython.Phylo documentation:

The second argument to each function is the target format. Currently, the following formats are supported:

newick
nexus
nexml
phyloxml
cdao

ADD REPLY
2
Entering edit mode
6.1 years ago
Joe 21k

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
ADD COMMENT
0
Entering edit mode

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'

ADD REPLY

Login before adding your answer.

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