Thanks. It works.
Hello,
I've seen a lot of posts that convert gtf to bed files. However, I have a bed file that I'm trying to convert to gtf.
Is there any tool that can convert bed->gtf?
Thanks
5 answers
Depends on the BED data you want to convert to GTF. If your raw data was originally a GTF file converted with BEDOPS gtf2bed, then the lossless conversion result (BED-formatted) contains all the columns you need to rebuild the original data, by simply printing out columns in a different order and setting the correct coordinate index:
$ gtf2bed < foo.gtf | sort-bed - > foo.bed
$ awk '{print $1"\t"$7"\t"$8"\t"($2+1)"\t"$3"\t"$5"\t"$6"\t"$9"\t"(substr($0, index($0,$10)))}' foo.bed > foo_from_gtf2bed.gtf
Changing the coordinate is really simple, just add one to the start coordinate. But the GTF format also needs attributes such as gene_id and transcript_id fields that are not present in the BED format. Therefore you will need a third source of information.
Alliteratively you could convert bed to gtf using this kscriptlet:
kscript https://git.io/vbJ4B my.bed > my.gtf
Log in to answer this question.