Answers.Body: <p>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:</p>
  
  <pre><code>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   -
  </code></pre>
  
  <p>For more step-by-step information, please check the answer from the mailing list archives here (in particular the Exon Method 1 section):
  <a href="https://groups.google.com/a/soe.ucsc.edu/d/msg/genome/BJ-6DlaZNCY/grgGIpuJAwAJ" rel="nofollow noreferrer">https://groups.google.com/a/soe.ucsc.edu/d/msg/genome/BJ-6DlaZNCY/grgGIpuJAwAJ</a></p>
  
  <p>Also note that UCSC provides several mailing lists for support, if you have futher questions please send them there:</p>
  
  <ul>
  <li>General questions: genome@soe.ucsc.edu </li>
  <li>Questions involving private
  data: genome-www@soe.ucsc.edu </li>
  <li>Questions involving mirror sites:
  genome-mirror@ose.ucsc.edu</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-28T16:15:13.173Z
Answers.LastActivityDate: 2017-06-28T16:15:13.173Z
Answers.UserDisplayName: Christopher Lee
Answers.Body: <p>You can download a list of transcript annotations as a flat file from UCSC:</p>
  
  <p><a href="http://hgdownload.cse.ucsc.edu/goldenPath/hg19/database/refGene.txt.gz" rel="nofollow noreferrer">http://hgdownload.cse.ucsc.edu/goldenPath/hg19/database/refGene.txt.gz</a></p>
  
  <p>It is not exactly a BED file, but it does contain information about the known transcripts for this assembly (hg19, in this case):</p>
  
  <pre><code>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,
  </code></pre>
  
  <p>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:</p>
  
  <ol>
  <li>bin</li>
  <li>name</li>
  <li>chrom</li>
  <li>strand</li>
  <li>txStart</li>
  <li>txEnd</li>
  <li>cdsStart</li>
  <li>cdsEnd</li>
  <li>exonCount</li>
  <li>exonStarts</li>
  <li>exonEnds</li>
  <li>score</li>
  <li>name2</li>
  <li>cdsStartStat</li>
  <li>cdsEndStat</li>
  <li>exonFrames</li>
  </ol>
  
  <p>(The column information was obtained from the <a href="http://hgdownload.cse.ucsc.edu/goldenpath/hg19/database/refGene.sql" rel="nofollow noreferrer">sql file here</a>)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-04T16:06:20.003Z
Answers.LastActivityDate: 2017-07-04T16:06:20.003Z
Answers.UserDisplayName: juniper-
Answers.Body: <p>Via Gencode and BEDOPS <code>convert2bed</code>:</p>
  <pre><code><span class="math-container">$ wget -qO- ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_28/gencode.v28.annotation.gff3.gz \
      | gunzip --stdout - \
      | awk '$</span>3 == &quot;gene&quot;' - \
      | convert2bed -i gff - \
      &gt; genes.bed
  </code></pre>
  <p>You can modify the <code>awk</code> statement to get exons, by replacing <code>gene</code> with <code>exon</code>.</p>
  <p>To get HGNC symbol names in the ID field, you can add the <code>--attribute-key=&quot;gene_name&quot;</code> option to v2.4.40 or later of <code>convert2bed</code>. This slight modification extracts the <code>gene_name</code> attribute from the annotation record and puts it in the fourth (ID) column:</p>
  <pre><code><span class="math-container">$ wget -qO- ftp://ftp.ebi.ac.uk/pub/databases/gencode/Gencode_human/release_28/gencode.v28.annotation.gff3.gz \
      | gunzip --stdout - \
      | awk '$</span>3 == &quot;gene&quot;' - \
      | convert2bed -i gff --attribute-key=&quot;gene_name&quot; - \
      &gt; genes.bed
  </code></pre>
  <p>BEDOPS: <a href="https://github.com/bedops/bedops" rel="nofollow noreferrer">https://github.com/bedops/bedops</a></p>
  <p>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: <a href="https://www.biostars.org/p/124515/#124522" rel="nofollow noreferrer">https://www.biostars.org/p/124515/#124522</a></p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-06-27T12:10:45.623Z
Answers.Text: No need to specify the input “file” `-` for `gunzip`.
Answers.UserDisplayName: Konrad Rudolph
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2018-02-05T00:39:46.593Z
Answers.Text: For those who want to know the last release number (now it should be 27) you may check here: http://www.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`
Answers.UserDisplayName: gc5
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-26T15:24:47.623Z
Answers.Text: 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.
Answers.UserDisplayName: Pastafarianist
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-07-31T14:58:40.770Z
Answers.Text: 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.
Answers.UserDisplayName: user345394
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2017-06-24T15:37:00.853Z
Answers.LastActivityDate: 2022-01-07T21:28:26.383Z
Answers.LastEditDate: 2022-01-07T21:28:26.383Z
Answers.UserDisplayName: Alex Reynolds
Body: <p>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.</p>
  
  <p>How can I get such BED file?</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-06-27T08:31:18.323Z
Comments.Text: 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?
Comments.UserDisplayName: Kristoffer Vitting-Seerup
Tags: <bed><public-databases>
Title: How to obtain .bed file with coordinates of all genes
ThreadText: # How to obtain .bed file with coordinates of all genes
  
  (Asked by: username_0 on 2017-06-24)
  
  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?
  
  **Tags:** bed, public-databases
  
  > **Comments:**
  > **username_1**: 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?  
  
  ---
  
  ## 3 answers
  
  ### Answer by username_4 on 2017-06-24. Score: 17 | Accepted answer
  
  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>
  
  > **Comments:**
  > **username_5**: No need to specify the input “file” `-` for `gunzip`.  
  > **username_6**: For those who want to know the last release number (now it should be 27) you may check here: http://www.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`  
  > **username_7**: 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.  
  > **username_8**: 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.  
  
  ---
  
  ### Answer by username_2 on 2017-06-28. Score: 4
  
  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:
  
  * General questions: genome@soe.ucsc.edu
  * Questions involving private
    data: genome-www@soe.ucsc.edu
  * Questions involving mirror sites:
    genome-mirror@ose.ucsc.edu
  
  
  ---
  
  ### Answer by username_3 on 2017-07-04. Score: 2
  
  You can download a list of transcript annotations as a flat file from UCSC:
  
  <http://hgdownload.cse.ucsc.edu/goldenPath/hg19/database/refGene.txt.gz>
  
  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](http://hgdownload.cse.ucsc.edu/goldenpath/hg19/database/refGene.sql))
  
  
  ---
  
  