Skip to content

Sequence Filtering

Parts of a SEGUL commandThe command segul sequence filter --dir alignments/ --min-length 5 has five parts: the program segul, the command sequence for the task group, the subcommand filter for the task, the input --dir alignments/ (folder or files), and the option --min-length 5 (filtering method).segulProgramsequenceCommandtask groupfilterSubcommandtask--dir alignments/Inputfolder or files--min-length 5Optionsfiltering method

The sequence filtering method works at the sequence level, which differs from the SEGUL alignment filtering feature, which works on the alignment level. Using the alignment filtering feature will filter the entire alignment that does not meet the filtering criteria. However, the sequence filtering feature will remove sequences that do not meet the criteria while retaining the same alignment if at least one sequence is left in the alignment. The feature works on many alignments simultaneously and will never overwrite your original datasets; it will create new files with the filtered sequences.

Available filtering methods:

  1. Sequence length
  2. Proportion of gaps

The command is structured as below:

Terminal window
segul sequence filter <input-option> [alignment-path] <filtering-option> <value>

Given a collection of alignments, SEGUL will remove sequences with non-gapped characters less than the specified length in each alignment. For example, we have an alignment with three sequences:

>seq_1
agtctgatc
>seq_2
agtc-----
>seq_3
agtcgatct

We want to filter sequences that contain at least 5 bp of sequences, excluding gaps. We can use the --min-length option. Use --max-length to remove sequences longer than a value:

Terminal window
segul sequence filter --dir alignments/ --min-length 5

It will filter out the seq_2 because it only has 4 bp sequences. The result will be:

>seq_1
agtctgatc
>seq_3
agtcgatct

Filtering based on the maximum proportion of gaps

Section titled “Filtering based on the maximum proportion of gaps”

SEGUL considers - and ? as gap characters. The app will remove sequences with a proportion of gaps greater than the specified value. To filter sequences, use the --max-gap option with a value between 0 and 1.

Terminal window
segul sequence filter --dir alignments/ --max-gap 0.3
OptionDescription
-d, --dirDirectory with alignments
-i, --inputAlignment files. Allows wildcards
-f, --input-formatInput format: auto (default), fasta, nexus, or phylip
--datatypeData type: dna (default), aa, or ignore
--min-lengthMinimum sequence length, excluding gaps
--max-lengthMaximum sequence length, excluding gaps
--max-gapMaximum proportion of gaps, from 0 to 1
-F, --output-formatOutput format: nexus (default), phylip, fasta, nexus-int, phylip-int, or fasta-int
-o, --outputOutput directory. Default: Sequence-Filter
--forceOverwrite an existing output directory
--logLog file path. Default: segul.log

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.