Question: How to convert tree in phylip format into newick format
0
gravatar for arash.iranzadeh1980
12 months ago by
arash.iranzadeh198010 wrote:

Hi,

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

Thanks!

ADD COMMENTlink modified 11 months ago by neutrinoscientist0 • written 12 months ago by arash.iranzadeh198010
 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 REPLYlink modified 11 months ago by genomax65k • written 11 months ago by neutrinoscientist0

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 REPLYlink modified 11 months ago • written 11 months ago by jrj.healey12k

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 REPLYlink modified 11 months ago by h.mon24k • written 11 months ago by neutrinoscientist0

Please post the command you're using.

ADD REPLYlink written 11 months ago by jrj.healey12k
  python convert_trees.py phyliptree.phy phylip mytree.nwk newick
ADD REPLYlink modified 11 months ago by h.mon24k • written 11 months ago by neutrinoscientist0

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 REPLYlink written 11 months ago by jrj.healey12k

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

ADD REPLYlink written 11 months ago by neutrinoscientist0

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 REPLYlink modified 11 months ago by RamRS21k • written 11 months ago by jrj.healey12k
2
gravatar for jrj.healey
12 months ago by
jrj.healey12k
United Kingdom
jrj.healey12k wrote:

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 COMMENTlink modified 11 months ago • written 12 months ago by jrj.healey12k

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 REPLYlink written 11 months ago by neutrinoscientist0
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: 2232 users visited in the last hour