Skip to content

Introduction

PyPI version

SEGUL is available as a Python library called PySEGUL. It allows users to use SEGUL API in Python. You don’t need Rust knowledge to use the library. The library is available on PyPI and can be installed using pip:

Terminal window
pip install pysegul

Then, you can use the library in your Python script:

import pysegul
# <Your code here...>

Here is an example of how to use the library to concatenate alignments:

  • Create a file named concat_alignments.py.

  • Copy and paste the following code. The shebang line #!/usr/bin/env python is optional. It is used to make the script executable on Linux and macOS.

#!/usr/bin/env python
import pysegul
def concat_alignments():
input_paths = ['tests/data/alignment1.nex', 'tests/data/alignment2.nex']
# Available input_format values: nexus, fasta, phylip.
# Automatically detect interleaved format.
input_format = 'nexus'
# Available datatype values: dna, aa.
datatype = 'dna'
# Available output_format values: fasta, phylip, nexus.
# Suffix with -int for interleaved format. Example: phylip-int
output_format = 'fasta'
# Available partition_format values: raxml, nexus, charset.
# Charset format is only available for nexus output format.
# The charset partition data is stored in the same file as the alignment.
partition_format = 'raxml'
prefix = 'concatenated'
output_dir = 'tests/output'
concat = pysegul.AlignmentConcatenation(
input_format,
datatype,
output_dir,
output_format,
partition_format,
prefix
)
concat.from_files(input_paths)
# If you prefer to input a directory
# and let SEGUL API to find
# all alignment files that match the input format.
input_dir = 'tests/data'
concat.from_dir(input_dir)
if __name__ == '__main__':
concat_alignments()
  • Run the script:
Terminal window
python concat_alignments.py
SEGUL command PySEGUL class
segul align concat AlignmentConcatenation
segul align convert AlignmentConversion
segul align distance AlignmentDistance (upcoming)
segul align filter AlignmentFiltering
segul align split AlignmentSplitting
segul align summary AlignmentSummary
segul align trim AlignmentTrimming (upcoming)
segul align unalign AlignmentUnalignment (upcoming)
segul partition PartitionConversion
segul read summary ReadSummary
segul contig summary ContigSummary
segul maf convert MafConversion (upcoming)
segul maf summary MafSummary (upcoming)
segul sequence add SequenceAddition (upcoming)
segul sequence extract SequenceExtraction
segul sequence filter SequenceFiltering (upcoming)
segul sequence id IDExtraction
segul sequence remove SequenceRemoval
segul sequence rename SequenceRenaming (upcoming)
segul sequence translate SequenceTranslation
segul sequence transpose SequenceTranspose (upcoming)

Features marked (upcoming) are not yet published on PyPI. To use them now, build PySEGUL from source.