Alignment Filtering
In a typical phylogenomic workflow, you may want to filter problematic alignments before running a phylogenetic analysis. This feature provides multiple ways to filter alignments.
Available filtering methods (required SEGUL v0.23.0 and later):
- Min or max alignment length
- Data matrix completeness
- Min, max, or percentage of parsimony informative sites
- Proportion of missing data
- Minimum taxon counts
- Taxon ID
Quick example
Section titled “Quick example”The command is structured as below:
segul align filter <input-option> [alignment-path] <filtering-option> <value>To filter alignments in the alignments/ directory with a minimal length of 500 bp, use the command below:
segul align filter --dir alignments/ --input-format nexus --min-len 500All command examples:
# Minimum alignment lengthsegul align filter --dir alignments/ --input-format nexus --min-len 500
# Maximum alignment lengthsegul align filter --dir alignments/ --input-format nexus --max-len 800
# Data matrix completenesssegul align filter --dir alignments/ --input-format nexus --percent 0.8
# Using multiple data matrix completeness valuessegul align filter --dir alignments/ --input-format nexus --npercent 0.9 0.8 0.75
# Minimum parsimony informative sitessegul align filter --dir alignments/ --input-format nexus --min-pinf 50
# Maximum parsimony informative sitessegul align filter --dir alignments/ --input-format nexus --max-pinf 200
# Percentage of minimal parsimony informative sitessegul align filter --dir alignments/ --input-format nexus --percent-inf 0.8
# Proportion of missing datasegul align filter --dir alignments/ --missing-data 0.3
# Minimum taxon countssegul align filter --dir alignments/ --min-ntax 100
# Taxon IDsegul align filter --dir alignments/ --taxon-id path/to/taxon_ids.txtTo check the available filtering options and other command arguments, use the --help option:
segul align filter --helpDetailed usage
Section titled “Detailed usage”Filtering based on alignment length
Section titled “Filtering based on alignment length”Minimum alignment length
Section titled “Minimum alignment length”You can filter alignments based on their length using the --min-len option. For example, if you want to filter alignments in the alignments/ below:
alignments/├── locus_1.nexus├── locus_2.nexus└── locus_3.nexusTo filter alignments with a minimum length of 200 bp, use the command below:
segul align filter --dir alignments/ --input-format nexus --min-len 200Maximum alignment length
Section titled “Maximum alignment length”To filter alignments based on the maximum length, use the --max-len option. For example:
segul align filter --dir alignments/ --input-format nexus --max-len 800Filtering based on data matrix completeness
Section titled “Filtering based on data matrix completeness”This filtering method is based on the percentage of minimal taxa present in your alignments, similar to phyluce_align_get_only_loci_with_min_taxa in Phyluce pipeline. For example, given a collection of alignments with 100 taxa with 90 percent completeness, SEGUL will filter alignments containing at least 90 taxa.
We use the --percent option with input in decimals to filter alignments based on data matrix completeness. For example, here we will filter alignments in the alignments directory with 80 percent data matrix completeness:
segul align filter --dir alignments/ --input-format nexus --percent 0.8You can also write the percentage as .8, and it will parse the same way you write it with 0.
Using multiple data matrix completeness values
Section titled “Using multiple data matrix completeness values”Sometimes, we want to build phylogenetic trees with different data matrix completeness. Using segul, we can do it in a single command using the npercent option:
segul align filter --dir alignments/ --input-format nexus --npercent 0.9 0.8 0.75SEGUL will create an output directory for each data matrix completeness value, with the percentage values suffixed on the directory names. For the example above, it will create three directories named alignments_90p, alignments_80p, and alignments_75p.
Filtering based on parsimony informative sites
Section titled “Filtering based on parsimony informative sites”SEGUL provides two ways of filtering based on parsimony informative sites:
Minimum informative sites
Section titled “Minimum informative sites”This option filters alignments that contain at least the specified number of informative sites.
For example, in the command below, we will filter alignments in the alignments directory with a minimum containing 50 parsimony informative sites:
segul align filter --dir alignments/ --input-format nexus --min-pinf 50Maximum informative sites
Section titled “Maximum informative sites”To filter alignments based on the maximum number of informative sites, use the --max-pinf option. For example:
segul align filter --dir alignments/ --input-format nexus --max-pinf 200Percentage of minimal parsimony informative sites
Section titled “Percentage of minimal parsimony informative sites”This value is counted based on the highest number of informative sites on your alignments. It is similar to computing data matrix completeness but based on the number of informative sites. You only need to input the percentage value. SEGUL will determine the highest number of informative sites across all input alignments.
For example, the highest number of informative sites in the input alignments is 100. We will filter with a minimal 80 percent of the highest parsimony informative value. Using the --percent-inf .8 option, SEGUL will filter alignments with at least containing 80 parsimony informative sites:
segul align filter --dir alignments/ --percent-inf 0.8Filtering based on the proportion of missing data
Section titled “Filtering based on the proportion of missing data”The proportion of missing data is calculated using the following formula:
Proportion of missing data = (Total missing data in alignment) / (Total number of characters in alignment)It works at per alignment level. For example, if an alignment has 1000 characters and 300 of them are missing (gaps or ambiguous characters), the proportion of missing data would be 0.3 (or 30%).
SEGUL will will copy the matching alignments to the output directory. To filter alignments based on the proportion of missing data, use the --missing-data option. For example:
segul align filter --dir alignments/ --missing-data 0.3Filtering based on minimum taxon counts
Section titled “Filtering based on minimum taxon counts”To filter alignments based on the minimum number of taxa present in each alignment, use the --min-ntax option. For example, to filter alignments with at least 100 taxa, use the command below:
segul align filter --dir alignments/ --min-ntax 100Filtering based on taxon ID
Section titled “Filtering based on taxon ID”The taxon ID is the same as your sequence ID. To use this feature, you need to provide a text file containing a list of taxon IDs (one taxon ID per line). SEGUL will filter alignments that contain the taxon IDs specified in the file. For example, if you have a file named taxon_ids.txt with the following content:
taxon_1taxon_2taxon_3You can use the following command to filter alignments in the alignments/ directory that contain these taxon IDs:
segul align filter --dir alignments/ --taxon-id path/to/taxon_ids.txtSpecifying output directories
Section titled “Specifying output directories”By default, SEGUL output directories for filtering are based on the input directory names suffixed with filtering values. The format is as follows:
[input-dir](underscore)[filtering-values]For example, if your input directory is named alignments/ and the filtering option is a minimal alignment length of 500 bp, the output directory will be alignments_500bp.
The --output or -o option allows you to change the prefix names of the output directory.
Concatenating the results
Section titled “Concatenating the results”By default, SEGUL copies the alignments that match the filtering option. Instead of copying the files, you can concatenate them using the --concat flag. All options for the align concat subcommand are available for this task. You are, however, required to specify the --output or -o name and the partition format --partition-format or -p option.
For example, in the command below, we will filter based on alignments with a length of 500 bp and will concat the result:
segul align filter --dir alignments/ --input-format nexus --min-len 500 --concat --partition-format raxml -o concat_alignmentOther input options
Section titled “Other input options”You can use --input or -i to specify a single alignment file or multiple alignments using wildcards. For example:
segul align filter --input alignments/*.fasta --min-len 300For Amino Acid alignments
Section titled “For Amino Acid alignments”By default, SEGUL assumes the input alignments are DNA sequences. It will fails to run if the data is amino acid sequences. To filter amino acid alignments, use the --datatype aa option. For example:
segul align filter --dir alignments/ --input-format fasta --datatype aa --min-len 300All options
Section titled “All options”| Option | Description |
|---|---|
-d, --dir |
Directory with alignments |
-i, --input |
Alignment files. Allows wildcards |
-f, --input-format |
Input format: auto (default), fasta, nexus, or phylip |
--datatype |
Data type: dna (default), aa, or ignore |
--min-len |
Minimum alignment length |
--max-len |
Maximum alignment length |
--percent |
Minimum data matrix completeness, as a proportion of taxa |
--npercent |
Several data matrix completeness values. Writes one output per value |
--min-pinf |
Minimum number of parsimony informative sites |
--max-pinf |
Maximum number of parsimony informative sites |
--percent-inf |
Minimum parsimony informative sites, as a proportion of the highest count |
--missing-data |
Maximum proportion of missing data |
--min-ntax |
Minimum number of taxa |
--taxon-id |
Text file of taxon IDs, one per line |
--concat |
Concatenate the filtered alignments instead of copying them |
-F, --output-format |
Output format with --concat: nexus (default), phylip, fasta, nexus-int, phylip-int, or fasta-int |
-p, --partition-format |
Partition format with --concat: nexus (default), charset, or raxml |
--codon |
Write the partition as a codon model, with --concat |
--prefix |
Prefix of the output files, with --concat |
-o, --output |
Output directory. Default: named after the input directory and filter value |
--force |
Overwrite an existing output directory |
--log |
Log file path. Default: segul.log |
Use one filtering option per run.
Copyright © 2026 H. Handika & J. A. Esselstyn.