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:
pip install pysegulThen, 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 pythonis optional. It is used to make the script executable on Linux and macOS.
#!/usr/bin/env pythonimport 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:
python concat_alignments.pyCommon options
Section titled “Common options”Most classes share these options. Each page lists the options of its class.
| Option | Values |
|---|---|
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' |
Input files
Section titled “Input files”Classes take input in one of two ways:
- Run methods: call
from_dir(input_dir)to use every file in a directory that matchesinput_fmt, orfrom_files(input_files)with a list of paths. - Input attributes: classes with several methods, such as
AlignmentFiltering, take the input from theinput_dirorinput_filesattribute. Set it before calling a method.
Available features
Section titled “Available features”| SEGUL command | PySEGUL class |
|---|---|
segul align concat | AlignmentConcatenation |
segul align convert | AlignmentConversion |
segul align distance | AlignmentDistance (beta) |
segul align filter | AlignmentFiltering |
segul align split | AlignmentSplitting |
segul align summary | AlignmentSummary |
segul align trim | AlignmentTrimming (beta) |
segul align unalign | AlignmentUnalignment (beta) |
segul partition | PartitionConversion |
segul read summary | ReadSummary |
segul contig summary | ContigSummary |
segul maf convert | MafConversion (beta) |
segul maf summary | MafSummary (beta) |
segul sequence add | SequenceAddition (beta) |
segul sequence extract | SequenceExtraction |
segul sequence filter | SequenceFiltering (beta) |
segul sequence id | IDExtraction |
segul sequence remove | SequenceRemoval |
segul sequence rename | SequenceRenaming (beta) |
segul sequence translate | SequenceTranslation |
segul sequence transpose | SequenceTranspose (beta) |
--plot and report viewers | PlotOptions and report loaders (beta) |
Beta features
Section titled “Beta features”Features marked (beta) are new and may still change. Their options, outputs, and results may differ between versions.
Citing PySEGUL
Section titled “Citing PySEGUL”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:
git -C pysegul rev-parse --short HEADPySEGUL 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.