I want to get a .bed file with the genes' names and canonical coordinates, also I would like to have coordinates of exons, too. I can get the list from UCSC, however, if I choose UCSC Genes - knownCanonical, I can not extract coordinates of exons. If I use other options - I am getting coordinates of as many transcriptional isoforms as were detected while I need only one canonical form.

How can I get such BED file?

  • $\begingroup$ So if we have a case with two exons that respecitively have position 1-10 and 5-15 - what coordinates do you want in that case? $\endgroup$ Commented Jun 27, 2017 at 8:31

3 Answers 3


Via Gencode and BEDOPS convert2bed:

$ wget -qO- ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_28/gencode.v28.annotation.gff3.gz \
    | gunzip --stdout - \
    | awk '$3 == "gene"' - \
    | convert2bed -i gff - \
    > genes.bed

You can modify the awk statement to get exons, by replacing gene with exon.

To get HGNC symbol names in the ID field, you can add the --attribute-key="gene_name" option to v2.4.40 or later of convert2bed. This slight modification extracts the gene_name attribute from the annotation record and puts it in the fourth (ID) column:

$ wget -qO- ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_28/gencode.v28.annotation.gff3.gz \
    | gunzip --stdout - \
    | awk '$3 == "gene"' - \
    | convert2bed -i gff --attribute-key="gene_name" - \
    > genes.bed

BEDOPS: https://github.com/bedops/bedops

This is based off an answer I wrote on Biostars, which includes a Perl script for generating a BED file of introns from gene and exon annotations: https://www.biostars.org/p/124515/#124522

  • 1
    $\begingroup$ No need to specify the input “file” - for gunzip. $\endgroup$ Commented Jun 27, 2017 at 12:10
  • 1
    $\begingroup$ For those who want to know the last release number (now it should be 27) you may check here: gencodegenes.org/releases/current.html . So the first URL should be ftp://ftp.sanger.ac.uk/pub/gencode/Gencode_human/release_27/gencode.v27.annotation.gff3.gz $\endgroup$
    – gc5
    Commented Feb 5, 2018 at 0:39
  • 1
    $\begingroup$ The latest link should be ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_28/gencode.v28.annotation.gff3.gz, as Sanger no longer participates in Gencode. $\endgroup$ Commented Jul 26, 2018 at 15:24
  • $\begingroup$ On could also load the gff3 file as a dataframe, and save the columns used in the bed file as a tab separated file without headers and index. $\endgroup$
    – user345394
    Commented Jul 31, 2018 at 14:58

You can indeed get this information from the UCSC Table Browser. Select knownGene as your primary table, make a filter, add knownCanonical to as a linked table to filter on, then in the free-form query section add "1" without the quotes. Then click submit and select Bed output, where you can choose "exons plus" as an output option. This will lead to output like the following:

chr1    17368   17436   uc031tla.1_exon_0_0_chr1_17369_r    0   -
chr1    29553   30039   uc057aty.1_exon_0_0_chr1_29554_f    0   +
chr1    30563   30667   uc057aty.1_exon_1_0_chr1_30564_f    0   +
chr1    30975   31097   uc057aty.1_exon_2_0_chr1_30976_f    0   +
chr1    30365   30503   uc031tlb.1_exon_0_0_chr1_30366_f    0   +
chr1    34553   35174   uc001aak.4_exon_0_0_chr1_34554_r    0   -
chr1    35276   35481   uc001aak.4_exon_1_0_chr1_35277_r    0   -
chr1    35720   36081   uc001aak.4_exon_2_0_chr1_35721_r    0   -

For more step-by-step information, please check the answer from the mailing list archives here (in particular the Exon Method 1 section): https://groups.google.com/a/soe.ucsc.edu/d/msg/genome/BJ-6DlaZNCY/grgGIpuJAwAJ

Also note that UCSC provides several mailing lists for support, if you have futher questions please send them there:


You can download a list of transcript annotations as a flat file from UCSC:


It is not exactly a BED file, but it does contain information about the known transcripts for this assembly (hg19, in this case):

585 NR_046018   chr1    +   11873   14409   14409   14409   3   11873,12612,13220,  12227,12721,14409,  0   DDX11L1 unk unk -1,-1,-1,
585 NR_024540   chr1    -   14361   29370   29370   29370   11  14361,14969,15795,16606,16857,17232,17605,17914,18267,24737,29320,  14829,15038,15947,16765,17055,17368,17742,18061,18366,24891,29370,  0   WASH7P  unk unk -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,

The gene name can be found in column 13. The exon start and end positions are in columns 10 and 11, respectively. More information can be found in the other columns:

  1. bin
  2. name
  3. chrom
  4. strand
  5. txStart
  6. txEnd
  7. cdsStart
  8. cdsEnd
  9. exonCount
  10. exonStarts
  11. exonEnds
  12. score
  13. name2
  14. cdsStartStat
  15. cdsEndStat
  16. exonFrames

(The column information was obtained from the sql file here)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.