This is a test version of Biostars. For the public version, visit https://www.biostars.org.
convert bed12 to sorted gtf

Hello I m trying to convert bed12 to sorted gtf but output file 'Precapture_uniq.gff' is empty i m very new for this work if you can help me to solve this i appreciate it.

awk -f bed12togff  Postcapture_uniq_chr.bed12 | sort -k1,1 -k4,4n -k5,5n "$@" > Precapture_uniq.gff

and my bed12togff is like that:

#! /bin/awk -f
# converts BED12 input into GFF

{
    split($11,sz,",");
    split($12,st,",");
    for(i=1; i<=$10; i++)
    {
        line[i]=$1"\thts\texon\t"($2+st[i]+1)"\t"($2+st[i]+sz[i])"\t.\t"$6"\t.\tgene_id \""$4"\"; transcri$
    }
    if(rev==""||rev==0)
    {
        for(i=1; i<=$10; i++)
        {
            print line[i];
        }
    }
    else
    {
        for(i=$10; i>=1; i--)
        {
            print line[i];
        }
    }
}
bed12 gtf gff awk

You might prefer to use existing tools like agat_convert_bed2gff.pl from AGAT

1 answer

Hi! I there are this two tools that you could use:

bed2gtf, a GTF-to-BED converter written in Rust that overcomes the limitations of using C binaries.

gtfsort, a fast and efficient chr/pos/feature GTF sorter also in Rust that outperforms current tools by far (such as gff3sort, AGAT, GNU, etc)!

and recently bed2gff, that includes a sorting step, so the output .gff3 is naturally sorted (a similar approach used in gtfsort).

Log in to answer this question.