Skip to content

Sequence Renaming

Rename sequence IDs across many sequence files at once.

Set the input with input_dir or input_files, then call a renaming method.

import pysegul
def rename_sequences():
rename = pysegul.SequenceRenaming(
input_fmt='nexus',
datatype='dna',
output_path='tests/output',
output_format='fasta',
)
rename.input_dir = 'tests/align-data'
rename.replace_id([('seq1', 'Rattus_rattus'), ('seq2', 'Mus_musculus')])
OptionDefaultDescription
input_fmtRequired'auto', 'fasta', 'nexus', 'phylip'
datatypeRequired'dna', 'aa', 'ignore'
output_pathRequiredOutput directory
output_formatRequired'fasta', 'nexus', 'phylip', or interleaved 'fasta-int', 'nexus-int', 'phylip-int'
dry_runFalseLog the new IDs without writing any files
AttributeDescription
input_dirDirectory of input sequence files
input_filesList of input sequence files

Regular expressions follow the Rust regex syntax.

MethodDescription
replace_id(names)Replace IDs using a list of (original ID, new ID) pairs
replace_id_from_file(path)Replace IDs using a CSV or TSV file with a header row and two columns: original ID and new ID
remove_string(input_str)Remove a string from the IDs
remove_regex(regex, all=False)Remove the first regex match, or every match with all=True
replace_string(from_, to)Replace a string in the IDs
replace_regex(regex, to, all=False)Replace the first regex match, or every match with all=True
rename.remove_regex(r'_\d+$')
rename.replace_string('Rattus', 'R')

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.