Skip to content

Sequence Transposition

Parts of a SEGUL commandThe command segul sequence transpose --dir alignments/ --datatype aa has five parts: the program segul, the command sequence for the task group, the subcommand transpose for the task, the input --dir alignments/ (folder or files), and the option --datatype aa (optional).segulProgramsequenceCommandtask grouptransposeSubcommandtask--dir alignments/Inputfolder or files--datatype aaOptionsoptional

Transpose locus alignments into per-sample sequence files. Locus alignments store one locus per file with a sequence for each sample. Transposing creates one file for each sample with a sequence for each locus. This is useful for creating sample-level reference sequences, for example, to map reads from each sample back to its own loci.

Assume we have two alignment files in FASTA format. locus_1.fas:

>sample1
AT-GC?
>sample2
ATTGCA

And locus_2.fas, which does not have sample2:

>sample1
--GGCC

To transpose the alignments, use the following command:

Terminal window
segul sequence transpose --dir alignments/

SEGUL creates one file for each sample. Each sequence is named after the locus it comes from, and gaps (-) and missing data (?) are removed. Sequence-Transpose/sample1/sample1.fas:

>locus_1
ATGC
>locus_2
GGCC

Sequence-Transpose/sample2/sample2.fas:

>locus_1
ATTGCA

To transpose sequences, use the sequence transpose command:

Terminal window
segul sequence transpose --dir <alignment-dir>

The locus name is the input file name without its extension. Samples missing from a locus are skipped for that locus, so each sample file only contains the loci where the sample is present.

For amino acid sequences, use the --datatype aa option:

Terminal window
segul sequence transpose --dir alignments/ --datatype aa

Specifying the output directory and format

Section titled “Specifying the output directory and format”

By default, the output directory is Sequence-Transpose. Each sample is written to its own folder: Sequence-Transpose/<sample>/<sample>.fas. You can change the output directory name using the --output or -o option:

Terminal window
segul sequence transpose --dir alignments/ --output sample-references

Because gaps are removed, the output sequences are unaligned and are always in FASTA format. Use the --output-format or -F option to choose between sequential (fasta, the default) and interleaved (fasta-int) FASTA:

Terminal window
segul sequence transpose --dir alignments/ --output-format fasta-int

You can also specify input files using the --input or -i option. For example:

Terminal window
segul sequence transpose --input alignments/*.fasta
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: fasta (default) or fasta-int
-o, --outputOutput directory. Default: Sequence-Transpose
--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.