Trouble converting clustal to nexus
1
0
Entering edit mode
4.9 years ago
mac03pat ▴ 30

Used this code:

from Bio import AlignIO

AlignIO.convert('aligned_KS1.clw', 'clustal', 'aligned_KS.nexus', 'nexus')

On this file: https://drive.google.com/open?id=1UX7H1sDdRSVT0I3fXb-rGXbfRZx10hGZ

And received this error:

Traceback (most recent call last):
  File "C:\Users\mac03\AppData\Local\Programs\Python\Python37\MBSProject\KS_tree_builder.py", line 3, in <module>
    tree = Phylo.read('aligned_KS.clw', 'phyloxml')
  File "C:\Users\mac03\AppData\Local\Programs\Python\Python37\lib\site-packages\Bio\Phylo\_io.py", line 63, in read
    tree = next(tree_gen)
  File "C:\Users\mac03\AppData\Local\Programs\Python\Python37\lib\site-packages\Bio\Phylo\_io.py", line 51, in parse
    for tree in getattr(supported_formats[format], 'parse')(fp, **kwargs):
  File "C:\Users\mac03\AppData\Local\Programs\Python\Python37\lib\site-packages\Bio\Phylo\PhyloXMLIO.py", line 98, in parse
    return Parser(file).parse()
  File "C:\Users\mac03\AppData\Local\Programs\Python\Python37\lib\site-packages\Bio\Phylo\PhyloXMLIO.py", line 297, in __init__
    event, root = next(context)
  File "C:\Users\mac03\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 1222, in iterator
    yield from pullparser.read_events()
  File "C:\Users\mac03\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 1297, in read_events
    raise event
  File "C:\Users\mac03\AppData\Local\Programs\Python\Python37\lib\xml\etree\ElementTree.py", line 1269, in feed
    self._parser.feed(data)
  File "<string>", line None
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0

A new nexus file is created but it's empty.

I am converting to nexus in order to build a phylogenetic tree with this code:

from Bio import Phylo

tree = Phylo.read('aligned_KS.nexus', 'nexus')
tree.ladderize()
Phylo.draw(tree)
clustalw nexus clw • 1.2k views
ADD COMMENT
0
Entering edit mode
4.9 years ago
AK ★ 2.2k

Hi mac03pat,

Please check out Question: Convert Clustal To Nexus Format In Python. From that discussion the following codes work for me:

from Bio import AlignIO
from Bio import Alphabet

AlignIO.convert('aligned_KS1.clw', 'clustal', 'aligned_KS1.nexus', 'nexus', alphabet=Alphabet.generic_dna)

Results:

$ head aligned_KS1.nexus
#NEXUS
begin data;
    dimensions ntax=19 nchar=1415;
    format datatype=dna missing=? gap=- interleave;
matrix
MG777497.1      ATTGTCATTGTTGGCATGGCTTGCCGACTTCCAGGCGATGTCGATAGCGCCTCGAGCCTATGGAAGTTGT
JX067626.1      ATCGCCGTCGTTGGTATGGCTCTCCAAGTCCCT---GGGGCTAATGATCTGGAAGAATTCTCCCAGCTCT
MG777490.1      ATCGCGATCATTGGTATGGGTTGTAGATTCCCG---GGTGCTGATTCCATTGACGAGTATTGGAATTTGC
MG777492.1      GTTGCCATTATCGGCGCTTCATGTCGCCTACCG---GGCGCCAATAGTATGGAGGAGCTCTGGGACCTCA
MG777500.1      ATAGCCGTTGTCGGTATGGCATGCCGCTTTCCA---GGTGCTAATACAACGGAAGAGTTCTGGGATCTTC
ADD COMMENT

Login before adding your answer.

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