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():
concat = pysegul.AlignmentConcatenation(
input_fmt='nexus',
datatype='dna',
output_dir='tests/output',
output_fmt='fasta',
partition_fmt='raxml',
output_prefix='concatenated',
)
concat.from_files(['tests/data/alignment1.nex', 'tests/data/alignment2.nex'])
# Or concatenate every alignment in a directory that matches input_fmt
concat.from_dir('tests/data')
if __name__ == '__main__':
concat_alignments()
  • Run the script:
Terminal window
python concat_alignments.py

Most classes share these options. Each page lists the options of its class.

OptionValues
input_fmt'auto', 'fasta', 'nexus', 'phylip'. Interleaved files are detected automatically
datatype'dna', 'aa', 'ignore'
output_fmt / output_format'fasta', 'nexus', 'phylip', or interleaved 'fasta-int', 'nexus-int', 'phylip-int'
partition_fmt'charset', 'nexus', 'raxml'. Add -codon for codon partitions, e.g. 'raxml-codon'

Classes take input in one of two ways:

  • Run methods: call from_dir(input_dir) to use every file in a directory that matches input_fmt, or from_files(input_files) with a list of paths.
  • Input attributes: classes with several methods, such as AlignmentFiltering, take the input from the input_dir or input_files attribute. Set it before calling a method.
SEGUL commandPySEGUL class
segul align concatAlignmentConcatenation
segul align convertAlignmentConversion
segul align distanceAlignmentDistance (beta)
segul align filterAlignmentFiltering
segul align splitAlignmentSplitting
segul align summaryAlignmentSummary
segul align trimAlignmentTrimming (beta)
segul align unalignAlignmentUnalignment (beta)
segul partitionPartitionConversion
segul read summaryReadSummary
segul contig summaryContigSummary
segul maf convertMafConversion (beta)
segul maf summaryMafSummary (beta)
segul sequence addSequenceAddition (beta)
segul sequence extractSequenceExtraction
segul sequence filterSequenceFiltering (beta)
segul sequence idIDExtraction
segul sequence removeSequenceRemoval
segul sequence renameSequenceRenaming (beta)
segul sequence translateSequenceTranslation
segul sequence transposeSequenceTranspose (beta)
--plot and report viewersPlotOptions and report loaders (beta)

Features marked (beta) are new and may still change. Their options, outputs, and results may differ between versions.

If you use PySEGUL in a publication, cite the SEGUL paper and always report the exact PySEGUL version you used, especially for beta features. Check the version in Python:

from importlib.metadata import version
print(version("pysegul"))

If you built PySEGUL from source, also report the commit:

Terminal window
git -C pysegul rev-parse --short HEAD

PySEGUL v0.5.0 requires Python 3.9 or later. Later versions require Python 3.10 or later. Invalid options, such as an unknown format, raise a ValueError. Editors show the parameters and help of each class.

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.