Skip to content

Sequence ID Renaming

Parts of a SEGUL commandThe command segul sequence rename --dir alignments/ --replace-id names.csv has five parts: the program segul, the command sequence for the task group, the subcommand rename for the task, the input --dir alignments/ (folder or files), and the option --replace-id names.csv (new names).segulProgramsequenceCommandtask grouprenameSubcommandtask--dir alignments/Inputfolder or files--replace-id names.csvOptionsnew names

SEGUL provides an easy way to rename sequence IDs across all your alignments. To use this function, SEGUL requires a list of the original IDs and the names it needs to change. The input IDs can be written in a tabulated format as a comma-delimited file (.csv) or a tab-delimited file (.tsv).

The table must contain two columns with a header for each column. Both the header names and the IDs should contain no space. The name of the header does not matter. You'll be able to name it whichever makes sense for you. It is only there for record keeping. The order of the columns, however, is essential. The first column should be the original IDs, and the second should be the new ones. For example:

Original_namesNew_names
Genus_species1_randomGenus_species1_voucherID
Genus_species2_randomGenus_species2_voucherID

You can use --dry-run option to check if the input names are parsed correctly:

Terminal window
segul sequence rename -d alignments/ -f nexus --replace-id new_names.csv --dry-run

By default, SEGUL will write the result in Sequence-Rename directory. To change the output directory, use the --output or -o option.

Terminal window
segul sequence rename -d alignments/ --input-format nexus --replace-id new_names.csv --output new_seq_names/

Like other functions, SEGUL will not overwrite your original files. The output files will default to NEXUS. To change the output format, use the --output-format or -F function:

Terminal window
segul sequence rename -d alignments/ --input-format nexus --replace-id new_names.csv --output new_seq_names/ --output-format fasta

You can remove a matching text from the sequence ID. This is useful if you have a common text in all your sequence IDs that you want to remove. For example, if all your sequence IDs have a common suffix _contigs, you can remove this suffix using the --remove option:

Terminal window
segul sequence rename -d alignments/ --input-format nexus --remove _contigs

You can also remove a matching regular expression from the sequence ID. This is useful if you have a common pattern in all your sequence IDs that you want to remove. For example, if all your sequence IDs have a common prefix locus followed by a number, you can remove this pattern using the --remove-re:

Terminal window
segul sequence rename -d alignments/ --input-format nexus --remove-re="^locus[0-9]"

Suppose multiple patterns exist in a single sequence ID. The command above will only remove the first matching pattern. Then, it will continue to look for the same pattern in the following sequence ID.

You can also remove all the matches found in a single sequence ID by using the --remove-re-all option instead:

Terminal window
segul sequence rename -d alignments/ --input-format nexus --remove-re-all="locus[0-9]"

You can also replace a matching text from the sequence ID. For example, you can replace locus01 with locus1 using the --replace-from and --replace-to options:

Terminal window
segul sequence rename -d alignments/ --input-format nexus --replace-from="locus01" --replace-to="locus1"

Find and replace a matching regular expression

Section titled “Find and replace a matching regular expression”

You can also replace a regular expression matching the sequence ID. For example, if all your sequence IDs have a common prefix locus followed by a number, you can use the regular expression ^locus[0-9] to match the pattern. Use the --replace-from-re and --replace-to options to replace the matching prefix. Use --replace-from-re-all to replace every match in each ID:

Terminal window
segul sequence rename -d alignments/ --input-format nexus --replace-from-re="^locus[0-9]" --replace-to="locus"
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
--replace-idCSV or TSV file of original and new IDs
--dry-runCheck the parsed IDs without writing files
--removeRemove matching text
--remove-re=Remove the first match of a regular expression
--remove-re-all=Remove all matches of a regular expression
--replace-from=Text to replace. Use with --replace-to=
--replace-from-re=Replace the first match of a regular expression. Use with --replace-to=
--replace-from-re-all=Replace all matches of a regular expression. Use with --replace-to=
--replace-to=Replacement text
-F, --output-formatOutput format: nexus (default), phylip, fasta, nexus-int, phylip-int, or fasta-int
-o, --outputOutput directory. Default: Sequence-Rename
--forceOverwrite an existing output directory
--logLog file path. Default: segul.log

Use one renaming option per run. Options that end with = need the equal sign, with the value in quotes.

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.