This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How much the sorting order of a gff file matters?

Hi guys,

While editing a gff3 file (genome annotation) with a custom script, I need to split the file by strand, obtaining a "forward.gff" and a "reverse.gff". For downstream analysis it's required, after editing, to merge these two into a single one.

I noticed that the gff3 format is sorted by chromosome's number (1st column) and start position (4th column) of a gene, with associated records (mRNA, exon, etc..) following. Now it's clear that in order to merge these two files and to sort them I couldn't just launch a sort command by 1st and 4th field, because start coordinates are indipendent between strands.

So here's the question: if I would just merge the two files without caring of start coordinates, how much will impact onto downstream analysis (reads alignment and gene counting)? Does the sorting order of a gff file truly matters?

Additional question: if someone knows a fast way to sort them back like the previous file, please write it down.

gff rna-seq annotation

AGAT toolkit contains many GFF file related tools. Check to see if you find something usable. @Juke (author) participates on Biostars and will likely notice this question too.

^^ you were right, here I am

1 answer

I quickly raise the topic there: https://github.com/NBISweden/AGAT/wiki/Topological-sorting-of-gff-features .

Does the sorting order of a gff file truly matters?

I would say it depends the tools. Most of time when it really matter the tools mention it in the manual. It depends also what you mean by "order". As in your case having reverse features later in the file compare to the forward ones should not be a problem for most of the tools. But mixing up the features of a same direction (having exon defined before its mRNA) might be more problematic. If you use the sort command you might end up in this situation. As explained here about GNU sort:

Lines with the same chromosomes and start positions would be placed randomly. Therefore, parent feature lines might sometimes be placed after their children lines

Most of tools will complain if something is wrong with the sorting while parsing the file.

Thanks for the answer. STAR for alignment and HtSeq for counts.

I'll definitly try to merge the two strand files into a single one sorting by chromosome and strand, in order to have a structure like:

chr1     [...]    +
chr1     [...]    -
chr2     [...]    +

In order to prevent alterations of the part-of relationship: to test later with mentioned tools. Linked post suggest gff3-retainids, I'll try to use it against the unordered merged file to see results. Which is the AGAT tool I could try to use? It needs to just sort, no records must be changed in its attributes.

Agat_convert_sp_gxf2gxf.pl —gff in.gff —o out.sorted.gff

I've tried (after a missing package into the declared dependencies, I'll push an issue on Github) but sadly the software does several other things, and my result is an alterated gff where UTR attributes were completely changed.

Probably missing UTRs that have been created. Look at the log to see what has been fixed by the tool. You can avoid that by using the --no_check parameter.

Log in to answer this question.