| 1 |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 2 |
<html xmlns="http://www.w3.org/1999/xhtml"> |
| 3 |
<head> |
| 4 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 5 |
<meta http-equiv="Content-Style-Type" content="text/css" /> |
| 6 |
<meta name="generator" content="pandoc" /> |
| 7 |
<meta name="author" content="Aaron Quinlan" /> |
| 8 |
<title>bedtools Tutorial</title> |
| 9 |
<style type="text/css">code{white-space: pre;}</style> |
| 10 |
<link rel="stylesheet" href="bootstrap.css" type="text/css" /> |
| 11 |
</head> |
| 12 |
<body> |
| 13 |
<div class="navbar navbar-static-top"> |
| 14 |
<div class="navbar-inner"> |
| 15 |
<div class="container"> |
| 16 |
<span class="doc-title">bedtools Tutorial</span> |
| 17 |
<ul class="nav pull-right doc-info"> |
| 18 |
<li><p class="navbar-text">Aaron Quinlan</p></li> |
| 19 |
</ul> |
| 20 |
</div> |
| 21 |
</div> |
| 22 |
</div> |
| 23 |
<div class="container"> |
| 24 |
<div class="row"> |
| 25 |
<div class="span12"> |
| 26 |
<h1 id="puzzles-to-help-teach-you-more-bedtools.">Puzzles to help teach you more bedtools.</h1> |
| 27 |
<ol style="list-style-type: decimal"> |
| 28 |
<li>Create a BED file representing all of the intervals in the genome that are NOT exonic and are not Promoters (based on the promoters in the hESC file).</li> |
| 29 |
</ol> |
| 30 |
<p>Answer:</p> |
| 31 |
<pre><code>grep Promoter hesc.chromHmm.bed > hesc.promoters.bed |
| 32 |
|
| 33 |
cat exons.bed hesc.promoters.bed | sort -k1,1 -k2,2n | exons.and.promoters.bed |
| 34 |
|
| 35 |
bedtools complement -i exons.and.promoters.bed -g genome.txt > notexonsorpromoters.bed</code></pre> |
| 36 |
<ol start="2" style="list-style-type: decimal"> |
| 37 |
<li>What is the average distance from GWAS SNPs to the closest exon? (Hint - have a look at the <a href="http://bedtools.readthedocs.org/en/latest/content/tools/closest.html">closest</a> tool.)</li> |
| 38 |
</ol> |
| 39 |
<p>Answer:</p> |
| 40 |
<pre><code>bedtools closest -a gwas.bed -b exons.bed -d | head |
| 41 |
chr1 1005805 1005806 rs3934834 chr1 1007125 1007955 NM_001205252_exon_0_0_chr1_1007126_r 0 - 1320 |
| 42 |
chr1 1079197 1079198 rs11260603 chr1 1078118 1079434 NR_038869_exon_2_0_chr1_1078119_f 0 + 0 |
| 43 |
chr1 1247493 1247494 rs12103 chr1 1247397 1247527 NM_001256456_exon_1_0_chr1_1247398_r 0 - 0 |
| 44 |
chr1 1247493 1247494 rs12103 chr1 1247397 1247527 NM_001256460_exon_1_0_chr1_1247398_r 0 - 0 |
| 45 |
chr1 1247493 1247494 rs12103 chr1 1247397 1247527 NM_001256462_exon_1_0_chr1_1247398_r 0 - 0 |
| 46 |
chr1 1247493 1247494 rs12103 chr1 1247397 1247527 NM_001256463_exon_1_0_chr1_1247398_r 0 - 0 |
| 47 |
chr1 1247493 1247494 rs12103 chr1 1247397 1247527 NM_017871_exon_1_0_chr1_1247398_r 0 - 0 |
| 48 |
chr1 2069171 2069172 rs425277 chr1 2066700 2066786 NM_001033581_exon_1_0_chr1_2066701_f 0 + 2386 |
| 49 |
chr1 2069171 2069172 rs425277 chr1 2066700 2066786 NM_001033582_exon_1_0_chr1_2066701_f 0 + 2386 |
| 50 |
chr1 2069171 2069172 rs425277 chr1 2066700 2066786 NM_001242874_exon_1_0_chr1_2066701_f 0 + 2386 |
| 51 |
|
| 52 |
bedtools closest -a gwas.bed -b exons.bed -d \ |
| 53 |
| awk '{ sum += $11 } END { if (NR > 0) print sum / NR }' |
| 54 |
46713.1</code></pre> |
| 55 |
<ol start="3" style="list-style-type: decimal"> |
| 56 |
<li>Count how many exons occur in each 500kb interval (“window”) in the human genome. (Hint - have a look at the <code>makewindows</code> tool.)</li> |
| 57 |
</ol> |
| 58 |
<p>Answer:</p> |
| 59 |
<pre><code>bedtools makewindows -g genome.txt -w 500000 > genome.windows.bed |
| 60 |
bedtools intersect -a genome.windows.bed -b exons.bed -c > genome.windows.exoncount.bedg</code></pre> |
| 61 |
<p>or…</p> |
| 62 |
<pre><code>bedtools makewindows -g genome.txt -w 500000 \ |
| 63 |
| bedtools intersect -a - -b exons.bed -c \ |
| 64 |
> genome.windows.exoncount.bedg</code></pre> |
| 65 |
<ol start="4" style="list-style-type: decimal"> |
| 66 |
<li>Are there any exons that are completely overlapped by an enhancer? If so, how many?</li> |
| 67 |
</ol> |
| 68 |
<p>Answer:</p> |
| 69 |
<pre><code>bedtools intersect -a exons.bed \ |
| 70 |
-b <(grep Enhancer hesc.chromHmm.bed) \ |
| 71 |
-wa -wb -f 1.0 \ |
| 72 |
| head |
| 73 |
chr1 948846 948956 NM_005101_exon_0_0_chr1_948847_f 0 + chr1 948337 949337 4_Strong_Enhancer |
| 74 |
chr1 1051439 1051736 NM_017891_exon_9_0_chr1_1051440_r 0 - chr1 1051337 1051737 6_Weak_Enhancer |
| 75 |
chr1 1109285 1109306 NM_001130045_exon_0_0_chr1_1109286_f 0 + chr1 1108537 1109537 6_Weak_Enhancer |
| 76 |
chr1 1109803 1109869 NM_001130045_exon_2_0_chr1_1109804_f 0 + chr1 1109737 1109937 6_Weak_Enhancer |
| 77 |
chr1 1219357 1219470 NM_001130413_exon_4_0_chr1_1219358_f 0 + chr1 1219137 1220137 7_Weak_Enhancer |
| 78 |
chr1 1219357 1219470 NR_037668_exon_4_0_chr1_1219358_f 0 + chr1 1219137 1220137 7_Weak_Enhancer |
| 79 |
chr1 1229202 1229313 NM_030649_exon_1_0_chr1_1229203_r 0 - chr1 1228937 1229937 6_Weak_Enhancer |
| 80 |
chr1 1229469 1229579 NM_030649_exon_2_0_chr1_1229470_r 0 - chr1 1228937 1229937 6_Weak_Enhancer |
| 81 |
chr1 1234724 1234736 NM_030649_exon_14_0_chr1_1234725_r 0 - chr1 1234137 1234937 7_Weak_Enhancer |
| 82 |
chr1 1245060 1245231 NM_153339_exon_4_0_chr1_1245061_f 0 + chr1 1244937 1245337 4_Strong_Enhancer |
| 83 |
|
| 84 |
bedtools intersect -a exons.bed \ |
| 85 |
-b <(grep Enhancer hesc.chromHmm.bed) \ |
| 86 |
-wa -wb -f 1.0 -u \ |
| 87 |
| wc -l |
| 88 |
13746</code></pre> |
| 89 |
<ol start="5" style="list-style-type: decimal"> |
| 90 |
<li>What fraction of the GWAS SNPs are exonic?</li> |
| 91 |
</ol> |
| 92 |
<p>Answer (Any idea why we need -u?):</p> |
| 93 |
<pre><code>wc -l gwas.bed |
| 94 |
17680 gwas.bed |
| 95 |
|
| 96 |
bedtools intersect -a gwas.bed -b exons.bed -u | wc -l |
| 97 |
1625 |
| 98 |
|
| 99 |
echo "foo" | awk '{print 1625/17680}' |
| 100 |
0.0919118</code></pre> |
| 101 |
<ol start="6" style="list-style-type: decimal"> |
| 102 |
<li>What fraction of the GWAS SNPs are lie in either enhancers or promoters in the hESC data we have?</li> |
| 103 |
</ol> |
| 104 |
<p>Answer (Any idea why we need -u?):</p> |
| 105 |
<pre><code>bedtools intersect -a gwas.bed -b <(egrep "Enhancer|Promoter" hesc.chromHmm.bed) -u \ |
| 106 |
| wc -l |
| 107 |
1285 |
| 108 |
|
| 109 |
echo "foo" | awk '{print 1285/17680}' |
| 110 |
0.072681</code></pre> |
| 111 |
<ol start="7" style="list-style-type: decimal"> |
| 112 |
<li>Create intervals representing the canonical 2bp splice sites on either side of each exon (don’t worry about excluding splice sites at the first or last exon). (Hint - have a look at the <a href="http://bedtools.readthedocs.org/en/latest/content/tools/flank.html">flank</a> tool.)</li> |
| 113 |
</ol> |
| 114 |
<p>Answer:</p> |
| 115 |
<pre><code>bedtools flank -l 2 -r 2 -i exons.bed -g genome.txt > splice-sites.bed</code></pre> |
| 116 |
<p>Or:</p> |
| 117 |
<pre><code>bedtools slop -b 2 -i exons.bed -g genome.txt > exons.plus2.bed |
| 118 |
bedtools subtract -a exons.plus2.bed -b exons.bed > splice-sites.bed</code></pre> |
| 119 |
<ol start="8" style="list-style-type: decimal"> |
| 120 |
<li>What is the Jaccard statistic between CpG and hESC enhancers? Compare that to the Jaccard statistic between CpG and hESC promoters. Does the result make sense? (Hint - you will need <code>grep</code>).</li> |
| 121 |
</ol> |
| 122 |
<p>Answer:</p> |
| 123 |
<pre><code>bedtools jaccard -a cpg.bed -b <(grep Enhancer hesc.chromHmm.bed) |
| 124 |
intersection union-intersection jaccard n_intersections |
| 125 |
1148180 132977386 0.0086344 4969 |
| 126 |
|
| 127 |
bedtools jaccard -a cpg.bed -b <(grep Promoter hesc.chromHmm.bed) |
| 128 |
intersection union-intersection jaccard n_intersections |
| 129 |
15661111 53551816 0.292448 20402</code></pre> |
| 130 |
<ol start="9" style="list-style-type: decimal"> |
| 131 |
<li>What would you expect the Jaccard statistic to look like if promoters were randomly distributed throughout the genome? (Hint - you will need the <a href="http://bedtools.readthedocs.org/en/latest/content/tools/shuffle.html">shuffle</a> tool.)</li> |
| 132 |
</ol> |
| 133 |
<p>Answer:</p> |
| 134 |
<pre><code>bedtools shuffle -i <(grep Promoter hesc.chromHmm.bed) -g genome.txt \ |
| 135 |
| sort -k1,1 -k2,2n \ |
| 136 |
> promoters.shuffled.bed |
| 137 |
|
| 138 |
bedtools jaccard -a cpg.bed -b promoters.shuffled.bed |
| 139 |
intersection union-intersection jaccard n_intersections |
| 140 |
294071 68556207 0.00428949 78</code></pre> |
| 141 |
<ol start="10" style="list-style-type: decimal"> |
| 142 |
<li>Which hESC ChromHMM state (e.g., 11_Weak_Txn, 10_Txn_Elongation) represents the most number of base pairs in the genome? (Hint: you will need to use <code>awk</code> or <code>perl</code> here, as well as the <a href="http://bedtools.readthedocs.org/en/latest/content/tools/groupby.html">groupby</a> tool.)</li> |
| 143 |
</ol> |
| 144 |
</div> |
| 145 |
</div> |
| 146 |
</div> |
| 147 |
</body> |
| 148 |
</html> |