This is a test version of Biostars. For the public version, visit https://www.biostars.org.
change the attribute order on a gtf file

Hi, I have a gtf file. Could someone tell me how to change the order of attributes on the 9th column (gene_id comes first, then transcript_id, and lastly gene_name)?

Currently the format is below:

DDB0169550  dictyBase Curator   exon    11729   12478   .   +   .   transcript_id "DDB0201587"; gene_id "DDB_G0294088"; gene_name "A";
DDB0169550  dictyBase Curator   exon    13479   13862   .   +   .   transcript_id "DDB0201587"; gene_id "DDB_G0294088"; gene_name "B";
DDB0169550  dictyBase Curator   CDS 6411    6676    .   +   0   transcript_id "DDB0201587"; gene_id "DDB_G0294088"; gene_name "C";

Thanks for your help!

gtf

May I ask why you want to change the order of the attributes? In theory it should not matter.

EDIT: Sorry I'm wrong, in GTF there are two mandatory attributes gene_id and transcript_id, any other attributes or comments must appear after these two. So yes order matter. (More details here: https://agat.readthedocs.io/en/latest/gxf.html)

1 answer

do not post the images of the data.

$ sed -r '/^#/! s/(transcript_id ".*"); (gene_id ".*"); (gene_name ".*");/\2; \1; \3/' test.gtf

DDB0169550  dictyBase   Curator exon    11729   12478   .      .   gene_id "DDB_G0294088"; transcript_id "DDB0201587"; gene_name "A"
DDB0169550  dictyBase   Curator exon    13479   13862   .      .   gene_id "DDB_G0294088"; transcript_id "DDB0201587"; gene_name "B"
DDB0169550  dictyBase   Curator CDS 6411    6676    .      0   gene_id "DDB_G0294088"; transcript_id "DDB0201587"; gene_name "C"

Log in to answer this question.