A command-line tool for batch processing GenBank (.gb) files. It sorts records by taxonomic lineage and extracts coding sequence (CDS) features into sanitized, BLAST-ready FASTA files.
Built on Biopython, gb_processor is designed for phylogenetics and comparative-genomics workflows where many GenBank files need to be reorganized and reduced to their protein-coding regions in a single pass.
- Sort records within each file alphabetically by their full taxonomy lineage, grouping un-annotated records under
Unknown. - Extract every CDS feature into a FASTA file, with headers carrying the parent record's description, accession, and lineage.
- Combined mode that sorts and then extracts in one step (the default).
- Header sanitization that collapses GenBank's duplicate accession blocks, strips the
PREDICTED:prefix, removes parentheses, and converts headers into single whitespace-free tokens safe for downstream tools. - Flexible inputs — accepts individual files, directories (scanned one level deep), or a mix of both. With no arguments, it scans the current directory after confirmation.
- Safe-by-default cleanup — originals are kept unless you explicitly opt in to archiving or deletion.
- Resilient processing — a failure on one feature or file is logged without aborting the rest of the batch.
- Python 3.9 or newer
- Biopython
Install the dependency with:
pip install biopythonNo packaging step is required. Download gb_processor.py and, optionally, make it executable:
chmod +x gb_processor.pyYou can then run it directly (./gb_processor.py) or via the interpreter (python gb_processor.py).
gb_processor.py [MODE] [-d] [PATH ...]
If no PATH is given, the current working directory is scanned for .gb files. When invoked with no arguments at all, you are asked to confirm before processing begins.
Exactly one mode may be selected. If none is given, --all is used.
| Flag | Aliases | Description |
|---|---|---|
-a |
--all |
Sort by taxonomy, then extract CDS features. (default) |
-s |
--sort |
Sort records by taxonomy only. Produces a .gb file. |
-e |
-x, --extract, --xtract |
Extract CDS features only. Produces a .fas file. |
| Flag | Aliases | Description |
|---|---|---|
-d |
-r, --delete, --remove |
After successful processing, archive originals (extract mode) or delete them (sort and all modes). |
--version |
Print the version and exit. | |
-h |
--help |
Show the help message and exit. |
Scan the current directory and run the default sort-then-extract workflow:
gb_processor.pySort and extract a single file:
gb_processor.py -a sample.gbSort every .gb file in a directory:
gb_processor.py -s data/Extract CDS features from all matching files, then archive the originals:
gb_processor.py -e -d *.gbgb_processor writes its results into subdirectories created alongside each processed input file:
| Directory | Contents |
|---|---|
processed_gb/ |
Sorted GenBank files (*_sorted.gb) and, when --delete is used in extract mode, archived originals. |
cds_extracts_from_gb/ |
Extracted FASTA files (*_out.fas in extract mode, *_sorted.fas in combined mode). |
The --delete flag behaves differently per mode so that source data is never lost without a recoverable copy:
- Extract mode — the original is moved into
processed_gb/(archived). - Sort and all modes — the original is deleted, since a sorted copy of the same records already exists in
processed_gb/.
Without --delete, originals are always left untouched.
CDS FASTA headers are normalized to produce a single BLAST-safe token. The transformation reproduces the sed pipeline from the upstream Schott toolkit:
- Drop everything between the first
)and the next@, collapsing GenBank's duplicate accession block. - Strip the
PREDICTED:prefix that NCBI applies to computationally predicted records. - Remove parentheses.
- Replace spaces with underscores.
| Code | Meaning |
|---|---|
0 |
Success (or user cancelled at the confirmation prompt). |
1 |
Setup failure — for example, no .gb files were found. |
2 |
One or more files failed to process. |
gb_processor began as a reimplementation of Schott-Lab/Extract-CDS-Genbank. Its CDS-extraction core and the sed-based header-cleaning pipeline are reproduced from that project; all other functionality — taxonomy-based sorting, the unified multi-mode command-line interface, flexible file/directory input handling, configurable cleanup behavior, and resilient batch processing — is original to this tool.
Released under the MIT License.
Arshia Farajollahi