I have a set of gene names in HGNC standard and I want to get all their exons (in BED format) from the UCSC browser but it seems like the browser doesn't index genes by their HGNC name. How can I do that?

  • 1
    $\begingroup$ Does it have to be UCSC? This is trivial with biomart. $\endgroup$
    – Devon Ryan
    Feb 18, 2018 at 21:22

2 Answers 2


You could grab exons via Gencode v27 (hg38) GFF annotations and convert them to BED via BEDOPS convert2bed/gff2bed:

$ wget -qO- ftp://ftp.sanger.ac.uk/pub/gencode/Gencode_human/release_27/gencode.v27.annotation.gff3.gz \
    | gunzip --stdout - \
    | awk '$3 == "exon"' \
    | convert2bed -i gff - \
    > exons.bed

Then use grep to filter exons against your list of gene names:

$ grep -w -f hgnc.txt exons.bed > exons.filtered.bed

If you need a 3-column BED, you can just use standard Unix tools:

curl ftp://ftp.sanger.ac.uk/pub/gencode/Gencode_human/release_27/gencode.v27.annotation.gtf.gz \
  | gzip -dc \
  | grep -wFf list.txt \
  | awk -vFS="\t" '$3=="exon"{print $1"\t"($4-1)"\t"$5"\t"$9}' > out-3.bed

If you need a 12-column BED:

# install k8 and paftools.js
curl -L http://bit.ly/k8-024 | tar -jxf -
cp k8-0.2.4/k8-`uname -s` k8
git clone https://github.com/lh3/minimap2
# actual command line:
curl ftp://ftp.sanger.ac.uk/pub/gencode/Gencode_human/release_27/gencode.v27.annotation.gtf.gz \
  | ./k8 minimap2/misc/paftools.js gff2bed - \
  | grep -wFf list.txt > out-12.bed

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.