text: user349: 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?
  
  user9: 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:
  
  bin
  name
  chrom
  strand
  txStart
  txEnd
  cdsStart
  cdsEnd
  exonCount
  exonStarts
  exonEnds
  score
  name2
  cdsStartStat
  cdsEndStat
  exonFrames
  
  (The column information was obtained from the sql file here)
  
  user1000: 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
  
  
  user776: 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
  
original_text: 349: <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>
   9: <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>
   1000: <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>
   776: <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>
  