Skip to content

Alignment Conversion

Parts of a SEGUL commandThe command segul align convert --input loci.nexus --output-format fasta has five parts: the program segul, the command align for the task group, the subcommand convert for the task, the input --input loci.nexus (file), and the option --output-format fasta (output format).segulProgramalignCommandtask groupconvertSubcommandtask--input loci.nexusInputfile--output-format fastaOptionsoutput format

SEGUL can convert a single file to multiple files in the same directory.

To convert a single file, use the --input or -i.

Terminal window
segul align convert --input [a-path-to-file] --output-format [sequence-format]

SEGUL should be able to infer the input file format based on the extension of your file. If your file extension is uncommon (for example, .aln instead of .fas), specify the --input-format:

Terminal window
segul align convert --input [a-path-to-file] --input-format [sequence-format] --output-format [sequence-format]

For example, here we will convert a nexus file containing DNA sequences named loci.nexus to fasta format:

Terminal window
segul align convert --input alignments/loci.nexus --output-format fasta

You can ignore specifying the output format if you want the output files in NEXUS format. For example, we will convert loci.fasta to nexus format:

Terminal window
segul align convert --input alignments/loci.fasta

Some segul arguments are available in short format (note the uppercase 'F' for the output format):

Terminal window
segul align convert -i alignments/loci.nexus -f nexus -F fasta --datatype aa -o alignment-fasta

Batch converting sequence files in a directory

Section titled “Batch converting sequence files in a directory”

We have the option to provide the input files to the program. Use the --dir or -d input. SEGUL detects the format from the file extensions. Add --input-format for unusual extensions:

Terminal window
segul align convert --dir [path-to-your-repository] --input-format [sequence-format] --output [your-output-dir-name] --output-format [sequence-format]

In short format:

Terminal window
segul align convert -d [path-to-your-repository] -f [sequence-format] -o [your-output-dir-name]

For example, suppose we want to convert all the nexus files in the directory below to fasta formats and name the output directory alignments-fas:

Terminal window
alignments/
├── locus_1.nexus
├── locus_2.nexus
└── locus_3.nexus

The command will be:

Terminal window
segul align convert -d alignments/ -f nexus -F fasta -o alignments-fas

We can also input wildcard (*) using the --input or -i option to achieve the same results:

Terminal window
segul align convert -i alignments/*.nexus -f nexus -F fasta -o alignments-fas

The outputs will be:

Terminal window
alignments-fas/
├── locus_1.fas
├── locus_2.fas
└── locus_3.fas

By default, the SEGUL datatype is set to convert DNA sequences. If your file contains amino acid sequences, use the argument --datatype aa. For example:

Terminal window
segul align convert --input alignments/loci.nexus --output-format fasta --datatype aa

By default, segul will write the result in a directory called Align-Convert. To specify the output directory, use the --output argument. For example, here, we will specify the output directory to alignment-fasta.

Terminal window
segul align convert --input alignments/loci.nexus --output-format fasta --datatype aa --output alignment-fasta

By default, SEGUL maintains the original order of the sequences in the input file(s). Using the --sort flag, you can sort the sequences in alphabetical order based on their IDs:

Terminal window
segul align convert --input alignments/loci.nexus --output-format fasta --datatype aa --output alignment-fasta --sort
OptionDescription
-d, --dirDirectory with alignments
-i, --inputAlignment files. Allows wildcards
-f, --input-formatInput format: auto (default), fasta, nexus, or phylip
--datatypeData type: dna (default), aa, or ignore
-F, --output-formatOutput format: nexus (default), phylip, fasta, nexus-int, phylip-int, or fasta-int
--sortSort sequences by ID
-o, --outputOutput directory. Default: Align-Convert
--forceOverwrite an existing output directory
--logLog file path. Default: segul.log

This material is based upon work supported by the National Science Foundation under grant numbers: DEB-1754393 and DEB-2244754. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.