Skip to content

Sequence Extraction

Extract sequences by sequence ID, using a regular expression, a list of IDs, or a file of IDs.

Set the input with input_dir or input_files, then call an extraction method.

import pysegul
def extract_sequences():
extract = pysegul.SequenceExtraction(
input_fmt='nexus',
datatype='dna',
output_path='tests/output',
output_format='fasta',
)
extract.input_dir = 'tests/align-data'
# Or use a list of files:
# extract.input_files = ['tests/align-data/alignment1.nex']
extract.extract_regex('(?i)^(abce)')
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'
AttributeDescription
input_dirDirectory of input sequence files
input_filesList of input sequence files
MethodExtract sequences
extract_regex(regex)whose IDs match a regular expression (Rust regex syntax)
extract_id_list(list)with the IDs in a list, e.g. ['abce1', 'abce2']
extract_id_file(path) (beta)with the IDs in a text file, one per line. A missing file raises a FileNotFoundError

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.