Sequence Renaming
Rename sequence IDs across many sequence files at once. Available renaming methods:
- Replace IDs using a list of ID pairs or a CSV/TSV file
- Remove a string or a regular expression match
- Replace a string or a regular expression match
Regular expressions follow the Rust regex syntax.
Install PySEGUL using pip if you haven’t done it yet
pip install pysegulCreate a new Python script, import the library, and write python code.
import pysegul
def rename_sequences(): input_dir = 'tests/align-data' input_format = 'nexus' datatype = 'dna' output_format = 'fasta' output_dir = 'tests/output' rename = pysegul.SequenceRenaming( input_format, datatype, output_dir, output_format, # Optional. Log the new IDs without writing any files. dry_run=False, ) rename.input_dir = input_dir # Or use a list of files: # rename.input_files = ['tests/align-data/locus1.nex']
# Replace IDs using a list of (original ID, new ID) pairs rename.replace_id([('seq1', 'Rattus_rattus'), ('seq2', 'Mus_musculus')])Use one of the other methods instead of replace_id:
# Replace IDs using a CSV or TSV file with a header row# and two columns: original ID and new IDrename.replace_id_from_file('new_ids.csv')# Remove a string from the IDsrename.remove_string('_voucher')# Remove the first regex match. Set all=True to remove every match.rename.remove_regex(r'_\d+$', all=False)# Replace a stringrename.replace_string('Rattus', 'R')# Replace the first regex match. Set all=True to replace every match.rename.replace_regex(r'^([A-Z])[a-z]+_', 'X_', all=False)Copyright © 2026 H. Handika & J. A. Esselstyn.