Question: Convert Clustal To Nexus Format In Python
0
gravatar for Gergana Vandova
5.1 years ago by
Stanford, CA
Gergana Vandova170 wrote:

I would like to convert a 'clustal' formatted alignment into a 'nexus' format alignment in python. I then would like to use the nexus file to build a phylogenetic tree using Mrbayes (http://mrbayes.sourceforge.net/). How can I do that?

python alignment tree • 4.8k views
ADD COMMENTlink modified 3.4 years ago by janwillem.wijnands0 • written 5.1 years ago by Gergana Vandova170

Does it have to be Python? There are lots of conversion utilities already available, both online e.g. here and command-line e.g. here

ADD REPLYlink modified 5.1 years ago • written 5.1 years ago by Neilfws48k

I would like to do this conversion for many files, so I wanted to automate it with a script. As I am using python for the multiple sequence alignments, it would be nice if I can use python for the format conversion as well. The Nexus created by NCLconverter that you also recommended is not usable by MrBayes 3.1.

ADD REPLYlink modified 5.1 years ago • written 5.1 years ago by Gergana Vandova170

trimal does an excellent job at file conversions, it is command line and can be incorporated into your script. It is designed for trimming alignments, but if you omit trimming options, it merely can be used as a convertor.

ADD REPLYlink written 5.1 years ago by Adrian Pelin2.2k

@akoik063 What would be the command for just the conversion? I am checking it out.

ADD REPLYlink written 5.1 years ago by Gergana Vandova170
2

trimal -in $file -out $file <options>

And part of options is:

   -clustal                 Output file in CLUSTAL format
    -fasta                   Output file in FASTA format
    -nbrf                    Output file in NBRF/PIR format
    -nexus                   Output file in NEXUS format
    -mega                    Output file in MEGA format
    -phylip3.2               Output file in PHYLIP3.2 format
    -phylip                  Output file in PHYLIP/PHYLIP4 format

So, from clustal to nexus: trimal -in $file -out $file -nexus

ADD REPLYlink modified 5.1 years ago • written 5.1 years ago by Adrian Pelin2.2k

Trimal works! Thanks!

ADD REPLYlink written 5.1 years ago by Gergana Vandova170

Should be easy enough to incorporate an existing command-line tool into your script; seqret from the EMBOSS suite may be another option. I didn't recommend NCLconverter, it was just an example.

ADD REPLYlink modified 5.1 years ago • written 5.1 years ago by Neilfws48k

Do you recommend seqret?

ADD REPLYlink written 5.1 years ago by Gergana Vandova170

I recommend the EMBOSS suite in general, as a great set of small tools, easily incorporated into scripts and pipelines in the "UNIX tradition". I know seqret is a good converter; as to whether it does exactly what you want, you'll have to try it and see!

ADD REPLYlink written 5.1 years ago by Neilfws48k
3
gravatar for gammyknee
5.1 years ago by
gammyknee190
Australia
gammyknee190 wrote:

With Biopython you can (assuming you have it downloaded and installed)

$ python
> from Bio import AlignIO
> AlignIO.convert("file.clustal", "clustal", "file.nexus", "nexus")
ADD COMMENTlink modified 5.1 years ago • written 5.1 years ago by gammyknee190

It doesn't work: ValueError: Need a DNA, RNA or Protein alphabet

ADD REPLYlink written 5.1 years ago by Gergana Vandova170
1

try adding from Bio import Alphabet then adding the argument alphabet=Alphabet.generic_dna to AlignIO.convert

ADD REPLYlink written 5.1 years ago by David W4.7k
0
gravatar for janwillem.wijnands
3.4 years ago by
janwillem.wijnands0 wrote:

It is possible to delete the quotes in the headers (Seq_name) of the output nexus file?
I would like to use AlignIO from BioPython for this approach.


Example:

#NEXUS
begin data;
   dimensions ntax=3 nchar=50;
   format datatype=dna missing=? gap=-;
matrix
'Seq_name'           AGGGA
'Seq_name'           AGCGG
'Seq_name'           ACTGG

MrBayes gives me an error because of the quotes.

ADD COMMENTlink written 3.4 years ago by janwillem.wijnands0
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: 2014 users visited in the last hour