gff3sort
GFF3sort: A Perl Script to sort gff3 files and produce suitable results for tabix tools
gff3sort, fixing unstable sorts for tabix
A Perl script that sorts GFF3 files for tabix, working around a bug where lines sharing a start position end up in random order and parent features land after their children.
The sort that tabix wants
The tabix tool from htslib expects input files sorted by chromosome and position. For GFF3 files that means sorting by column 1, the chromosome, and column 4, the start position. GFF3sort is a Perl script written to produce exactly that kind of output, and it is released under GPL-3.0.
The tie bug
The README points out a real problem: either GNU sort or the gt tool places lines with identical chromosomes and start positions randomly. When parent and child features share a start position, the parent line can end up after its children, which breaks the order downstream tools rely on. It links a jbrowse issue as an example of the resulting bug.
How the fix works
The script adjusts lines that share a start position by moving lines carrying a Parent attribute, matched case insensitively, behind lines without one. The README shows the effect with two mRNA lines at position 473 that previously landed after two exon lines at the same position, and the corrected ordering after the adjustment.
Scope of the script
This is a focused utility: one Perl script, GPL-3.0 licensed, built to solve one ordering problem so GFF3 data behaves for tabix. The README keeps to the background, the bug, the example, and the fix, which is about the right amount of documentation for something this targeted.
Editorial conclusion
By forcing ties to a deterministic order, the script produces the parent-before-child output tabix users need, and it links the downstream bug this is meant to avoid.
Community notes