Skip to content

Alignment Conversion

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
Option Description
-d, --dir Directory with alignments
-i, --input Alignment files. Allows wildcards
-f, --input-format Input format: auto (default), fasta, nexus, or phylip
--datatype Data type: dna (default), aa, or ignore
-F, --output-format Output format: nexus (default), phylip, fasta, nexus-int, phylip-int, or fasta-int
--sort Sort sequences by ID
-o, --output Output directory. Default: Align-Convert
--force Overwrite an existing output directory
--log Log file path. Default: segul.log