<p>Here I provide an ordered list of options (note that I am the author of <code>bed2gtf</code> and <code>bed2gff</code>):</p>
<h2>bed2gtf</h2>
<p>A high-performance BED-to-GTF converter written in Rust from <a href="https://github.com/alejandrogzi/bed2gtf" rel="nofollow noreferrer">https://github.com/alejandrogzi/bed2gtf</a>.</p>
<pre><code>Usage: bed2gtf[EXE] --bed/-b &lt;BED&gt; --isoforms/-i &lt;ISOFORMS&gt; --output/-o &lt;OUTPUT&gt; --threads/-t &lt;THREADS&gt;

where:
--bed &lt;BED&gt;: a .bed file
--isoforms &lt;ISOFORMS&gt;: a tab-delimited file
--output &lt;OUTPUT&gt;: path to output file (*.gtf)
</code></pre>
<p>The isoforms file specification:</p>
<blockquote>
<p>a tab-delimited .txt/.tsv/.csv/... file with genes/isoforms (all the transcripts in .bed file should appear in the isoforms file):</p>
</blockquote>
<pre><code>&gt; cat isoforms.txt

ENSG00000198888 ENST00000361390
ENSG00000198763 ENST00000361453
ENSG00000198804 ENST00000361624
ENSG00000188868 ENST00000595977
</code></pre>
<p>Converts</p>
<ul>
<li>Homo sapiens GRCh38 GENCODE 44 (252,835 transcripts) in 3.25 seconds.</li>
<li>Mus musculus GRCm39 GENCODE 44 (149,547 transcritps) in 1.99 seconds.</li>
<li>Canis lupus familiaris ROS_Cfam_1.0 Ensembl 110 (55,335 transcripts) in 1.20 seconds.</li>
<li>Gallus galus bGalGal1 Ensembl 110 (72,689 transcripts) in 1.36 seconds.</li>
</ul>
<h2>bed2gff</h2>
<p>A Rust BED-to-GFF3 translator that runs in parallel from <a href="https://github.com/alejandrogzi/bed2gff" rel="nofollow noreferrer">https://github.com/alejandrogzi/bed2gff</a>.</p>
<pre><code>Usage: bed2gff[EXE] --bed/-b &lt;BED&gt; --isoforms/-i &lt;ISOFORMS&gt; --output/-o &lt;OUTPUT&gt; --threads/-t &lt;THREADS&gt;

where:
--bed &lt;BED&gt;: a .bed file
--isoforms &lt;ISOFORMS&gt;: a tab-delimited file
--output &lt;OUTPUT&gt;: path to output file (*.gff)
</code></pre>
<p>The isoforms file specification:</p>
<blockquote>
<p>a tab-delimited .txt/.tsv/.csv/... file with genes/isoforms (all the transcripts in .bed file should appear in the isoforms file):</p>
</blockquote>
<pre><code>&gt; cat isoforms.txt

ENSG00000198888 ENST00000361390
ENSG00000198763 ENST00000361453
ENSG00000198804 ENST00000361624
ENSG00000188868 ENST00000595977
</code></pre>
<p>Convert</p>
<ul>
<li>Homo sapiens GRCh38 GENCODE 44 (252,835 transcripts) in 4.16 seconds.</li>
<li>Mus musculus GRCm39 GENCODE 44 (149,547 transcritps) in 2.15 seconds.</li>
<li>Canis lupus familiaris ROS_Cfam_1.0 Ensembl 110 (55,335 transcripts) in 1.30 seconds.</li>
<li>Gallus gallus bGalGal1 Ensembl 110 (72,689 transcripts) in 1.51 seconds.</li>
</ul>
<h2>bedToGenePred + genePredToGtf + refTable</h2>
<p>UCSC offers a fast way to convert BED into GTF files through KentUtils or specific binaries using:</p>
<pre><code>bedToGenePred in.bed /dev/stdout | genePredToGtf file /dev/stdin out.gtf
</code></pre>
<p>You can install these tools with bioconda, or download them <a href="http://hgdownload.cse.ucsc.edu/admin/exe/" rel="nofollow noreferrer">here</a>. The gene_id is only achieved when using refTables (a format specified in UCSC's web browser), you can see a more elaborate answer here <a href="https://www.biostars.org/p/54863/" rel="nofollow noreferrer">Obtaining Ucsc Tables Via Ftp And Converting Them To Proper Gff3 Via Genepredtogtf?</a>.</p>
<h2>Other options</h2>
<p>Other scripts/tools <strong>That DO NOT produce a complete GTF file (lacking gene_id attributes)</strong> are:</p>
<ul>
<li>gtf2bed</li>
</ul>
<pre><code>gtf2bed &lt; foo.gtf | sort-bed - &gt; foo.bed 
awk '{print $1&quot;\t&quot;$7&quot;\t&quot;$8&quot;\t&quot;($2+1)&quot;\t&quot;$3&quot;\t&quot;$5&quot;\t&quot;$6&quot;\t&quot;$9&quot;\t&quot;(substr($0, index($0,$10)))}' foo.bed &gt; foo_from_gtf2bed.gtf
</code></pre>
<p>-kscript
from <a href="https://github.com/holgerbrandl/kscript" rel="nofollow noreferrer">https://github.com/holgerbrandl/kscript</a>:</p>
<pre><code>kscript https://git.io/vbJ4B my.bed &gt; my.gtf
</code></pre>
<ul>
<li>pfurio/bed2gtf</li>
</ul>
<p>from <a href="https://github.com/pfurio/bed2gtf" rel="nofollow noreferrer">https://github.com/pfurio/bed2gtf</a>:</p>
<pre><code>python bed2gtf [options] &lt;mandatory&gt;
</code></pre>
<ul>
<li>AGAT</li>
</ul>
<p><a href="https://agat.readthedocs.io/en/latest/tools/agat_convert_bed2gff.html" rel="nofollow noreferrer">AGAT</a></p>
<p>Considering only the options that produce gene_ids attributes, bed2gtf and bed2gff are faster by ~3-4 seconds than UCSC's C binaries. More detailed instructions of this tools are explained in the sources linked.</p>

CC BY-SA 4.0
2023-12-03T07:14:10.697Z
Thank you. These are great resources.
gringer
CC BY-SA 4.0
2023-12-02T18:44:19.307Z
2023-12-05T09:57:38.570Z
2023-12-05T09:57:38.570Z
Alejandro Gonzales-Irribarren
<p>Given a .bed (BED12), how can I convert it to GTF/GFF formats with gene_id attributes? What is the fastest way or available tools to do it?</p>
<p>For example, given an input like this:</p>
<pre><code>chr27 17266469 17281218 ENST00000541931.8 1000 + 17266469 17281218 0,0,200 2 103,74, 0,14675,
</code></pre>
<p>How can I convert it to:</p>
<pre><code>chr27 bed2gtf gene 17266470 17285418 . + . gene_id &quot;ENSG00000151743&quot;;
chr27 bed2gtf transcript 17266470 17281218 . + . gene_id &quot;ENSG00000151743&quot;; transcript_id &quot;ENST00000541931.8&quot;;
chr27 bed2gtf exon 17266470 17266572 . + . gene_id &quot;ENSG00000151743&quot;; transcript_id &quot;ENST00000541931.8&quot;; exon_number &quot;1&quot;; exon_id &quot;ENST00000541931.8.1&quot;;
</code></pre>

<bed><format-conversion><gtf><gff>
How can I convert a BED file to GTF/GFF with gene_ids?
# How can I convert a BED file to GTF/GFF with gene_ids?

(Asked by: username_0 on 2023-12-02)

Given a .bed (BED12), how can I convert it to GTF/GFF formats with gene_id attributes? What is the fastest way or available tools to do it?
For example, given an input like this:
chr27 17266469 17281218 ENST00000541931.8 1000 + 17266469 17281218 0,0,200 2 103,74, 0,14675,

How can I convert it to:
chr27 bed2gtf gene 17266470 17285418 . + . gene_id "ENSG00000151743";
chr27 bed2gtf transcript 17266470 17281218 . + . gene_id "ENSG00000151743"; transcript_id "ENST00000541931.8";
chr27 bed2gtf exon 17266470 17266572 . + . gene_id "ENSG00000151743"; transcript_id "ENST00000541931.8"; exon_number "1"; exon_id "ENST00000541931.8.1";

**Tags:** bed, format-conversion, gtf, gff

---

## 1 answers

### Answer by username_0 on 2023-12-02. Score: 6 | Accepted answer

Here I provide an ordered list of options (note that I am the author of bed2gtf and bed2gff):
bed2gtf
A high-performance BED-to-GTF converter written in Rust from https://github.com/alejandrogzi/bed2gtf.
Usage: bed2gtf[EXE] --bed/-b  --isoforms/-i  --output/-o  --threads/-t 

where:
--bed : a .bed file
--isoforms : a tab-delimited file
--output : path to output file (*.gtf)

The isoforms file specification:

a tab-delimited .txt/.tsv/.csv/... file with genes/isoforms (all the transcripts in .bed file should appear in the isoforms file):

> cat isoforms.txt

ENSG00000198888 ENST00000361390
ENSG00000198763 ENST00000361453
ENSG00000198804 ENST00000361624
ENSG00000188868 ENST00000595977

Converts

Homo sapiens GRCh38 GENCODE 44 (252,835 transcripts) in 3.25 seconds.
Mus musculus GRCm39 GENCODE 44 (149,547 transcritps) in 1.99 seconds.
Canis lupus familiaris ROS_Cfam_1.0 Ensembl 110 (55,335 transcripts) in 1.20 seconds.
Gallus galus bGalGal1 Ensembl 110 (72,689 transcripts) in 1.36 seconds.

bed2gff
A Rust BED-to-GFF3 translator that runs in parallel from https://github.com/alejandrogzi/bed2gff.
Usage: bed2gff[EXE] --bed/-b  --isoforms/-i  --output/-o  --threads/-t 

where:
--bed : a .bed file
--isoforms : a tab-delimited file
--output : path to output file (*.gff)

The isoforms file specification:

a tab-delimited .txt/.tsv/.csv/... file with genes/isoforms (all the transcripts in .bed file should appear in the isoforms file):

> cat isoforms.txt

ENSG00000198888 ENST00000361390
ENSG00000198763 ENST00000361453
ENSG00000198804 ENST00000361624
ENSG00000188868 ENST00000595977

Convert

Homo sapiens GRCh38 GENCODE 44 (252,835 transcripts) in 4.16 seconds.
Mus musculus GRCm39 GENCODE 44 (149,547 transcritps) in 2.15 seconds.
Canis lupus familiaris ROS_Cfam_1.0 Ensembl 110 (55,335 transcripts) in 1.30 seconds.
Gallus gallus bGalGal1 Ensembl 110 (72,689 transcripts) in 1.51 seconds.

bedToGenePred + genePredToGtf + refTable
UCSC offers a fast way to convert BED into GTF files through KentUtils or specific binaries using:
bedToGenePred in.bed /dev/stdout | genePredToGtf file /dev/stdin out.gtf

You can install these tools with bioconda, or download them here. The gene_id is only achieved when using refTables (a format specified in UCSC's web browser), you can see a more elaborate answer here Obtaining Ucsc Tables Via Ftp And Converting Them To Proper Gff3 Via Genepredtogtf?.
Other options
Other scripts/tools That DO NOT produce a complete GTF file (lacking gene_id attributes) are:

gtf2bed

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

-kscript
from https://github.com/holgerbrandl/kscript:
kscript https://git.io/vbJ4B my.bed > my.gtf


pfurio/bed2gtf

from https://github.com/pfurio/bed2gtf:
python bed2gtf [options] 


AGAT

AGAT
Considering only the options that produce gene_ids attributes, bed2gtf and bed2gff are faster by ~3-4 seconds than UCSC's C binaries. More detailed instructions of this tools are explained in the sources linked.

> **Comments:**
> **username_1**: Thank you. These are great resources.  

---

