Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
545 lines (488 loc) · 17.9 KB
/
Copy pathindex.html
File metadata and controls
545 lines (488 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!DOCTYPE html>
<html>
<head>
<title>Reading mySQL</title>
<meta charset="utf-8">
<meta name="description" content="Reading mySQL">
<meta name="author" content="Jeffrey Leek">
<meta name="generator" content="slidify" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<link rel="stylesheet" href="../../libraries/frameworks/io2012/css/default.css" media="all" >
<link rel="stylesheet" href="../../libraries/frameworks/io2012/phone.css"
media="only screen and (max-device-width: 480px)" >
<link rel="stylesheet" href="../../libraries/frameworks/io2012/css/slidify.css" >
<link rel="stylesheet" href="../../libraries/highlighters/highlight.js/css/tomorrow.css" />
<base target="_blank"> <!-- This amazingness opens all links in a new tab. -->
<script data-main="../../libraries/frameworks/io2012/js/slides"
src="../../libraries/frameworks/io2012/js/require-1.0.8.min.js">
</script>
<link rel="stylesheet" href = "../../assets/css/custom.css">
<link rel="stylesheet" href = "../../assets/css/custom.css.BACKUP.546.css">
<link rel="stylesheet" href = "../../assets/css/custom.css.BASE.546.css">
<link rel="stylesheet" href = "../../assets/css/custom.css.LOCAL.546.css">
<link rel="stylesheet" href = "../../assets/css/custom.css.orig">
<link rel="stylesheet" href = "../../assets/css/custom.css.REMOTE.546.css">
<link rel="stylesheet" href = "../../assets/css/ribbons.css">
</head>
<body style="opacity: 0">
<slides class="layout-widescreen">
<!-- LOGO SLIDE -->
<!-- END LOGO SLIDE -->
<!-- TITLE SLIDE -->
<!-- Should I move this to a Local Layout File? -->
<slide class="title-slide segue nobackground">
<aside class="gdbar">
<img src="../../assets/img/bloomberg_shield.png">
</aside>
<hgroup class="auto-fadein">
<h1>Reading mySQL</h1>
<h2></h2>
<p>Jeffrey Leek<br/>Johns Hopkins Bloomberg School of Public Health</p>
</hgroup>
</slide>
<!-- SLIDES -->
<slide class="" id="slide-1" style="background:;">
<hgroup>
<h2>mySQL</h2>
</hgroup>
<article>
<ul>
<li>Free and widely used open source database software</li>
<li>Widely used in internet based applications</li>
<li>Data are structured in
<ul>
<li>Databases</li>
<li>Tables within databases</li>
<li>Fields within tables</li>
</ul></li>
<li>Each row is called a record</li>
</ul>
<p><a href="http://en.wikipedia.org/wiki/MySQL">http://en.wikipedia.org/wiki/MySQL</a>
<a href="http://www.mysql.com/">http://www.mysql.com/</a></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-2" style="background:;">
<hgroup>
<h2>Example structure</h2>
</hgroup>
<article>
<p><img class=center src=../../assets/img/03_ObtainingData/database-schema.png height=450></p>
<p><a href="http://dev.mysql.com/doc/employee/en/sakila-structure.html">http://dev.mysql.com/doc/employee/en/sakila-structure.html</a></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-3" style="background:;">
<hgroup>
<h2>Step 1 - Install MySQL</h2>
</hgroup>
<article>
<p><img class=center src=../../assets/img/03_ObtainingData/installmysql.png height=450></p>
<p><a href="http://dev.mysql.com/doc/refman/5.7/en/installing.html">http://dev.mysql.com/doc/refman/5.7/en/installing.html</a></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-4" style="background:;">
<hgroup>
<h2>Step 2 - Install RMySQL</h2>
</hgroup>
<article>
<ul>
<li>On a Mac: <code>install.packages("RMySQL")</code></li>
<li>On Windows:
<ul>
<li>Official instructions - <a href="http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL">http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL</a> (may be useful for Mac/UNIX users as well)</li>
<li>Potentially useful guide - <a href="http://www.ahschulz.de/2013/07/23/installing-rmysql-under-windows/">http://www.ahschulz.de/2013/07/23/installing-rmysql-under-windows/</a><br></li>
</ul></li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-5" style="background:;">
<hgroup>
<h2>Example - UCSC database</h2>
</hgroup>
<article>
<p><img class=center src=../../assets/img/03_ObtainingData/ucsc.png height=450></p>
<p><a href="http://genome.ucsc.edu/">http://genome.ucsc.edu/</a></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-6" style="background:;">
<hgroup>
<h2>UCSC MySQL</h2>
</hgroup>
<article>
<p><img class=center src=../../assets/img/03_ObtainingData/ucscmysql.png height=450></p>
<p><a href="http://genome.ucsc.edu/goldenPath/help/mysql.html">http://genome.ucsc.edu/goldenPath/help/mysql.html</a></p>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-7" style="background:;">
<hgroup>
<h2>Connecting and listing databases</h2>
</hgroup>
<article>
<pre><code class="r">ucscDb <- dbConnect(MySQL(),user="genome",
host="genome-mysql.cse.ucsc.edu")
result <- dbGetQuery(ucscDb,"show databases;"); dbDisconnect(ucscDb);
</code></pre>
<pre><code>[1] TRUE
</code></pre>
<pre><code class="r">result
</code></pre>
<pre><code> Database
1 information_schema
2 ailMel1
3 allMis1
4 anoCar1
5 anoCar2
6 anoGam1
7 apiMel1
8 apiMel2
9 aplCal1
10 bosTau2
11 bosTau3
12 bosTau4
13 bosTau5
14 bosTau6
15 bosTau7
16 bosTauMd3
17 braFlo1
18 caeJap1
19 caePb1
20 caePb2
21 caeRem2
22 caeRem3
23 calJac1
24 calJac3
25 canFam1
26 canFam2
27 canFam3
28 cavPor3
29 cb1
30 cb3
31 ce10
32 ce2
33 ce4
34 ce6
35 cerSim1
36 choHof1
37 chrPic1
38 ci1
39 ci2
40 danRer1
41 danRer2
42 danRer3
43 danRer4
44 danRer5
45 danRer6
46 danRer7
47 dasNov3
48 dipOrd1
49 dm1
50 dm2
51 dm3
52 dp2
53 dp3
54 droAna1
55 droAna2
56 droEre1
57 droGri1
58 droMoj1
59 droMoj2
60 droPer1
61 droSec1
62 droSim1
63 droVir1
64 droVir2
65 droYak1
66 droYak2
67 echTel1
68 echTel2
69 equCab1
70 equCab2
71 eriEur1
72 felCat3
73 felCat4
74 felCat5
75 fr1
76 fr2
77 fr3
78 gadMor1
79 galGal2
80 galGal3
81 galGal4
82 gasAcu1
83 geoFor1
84 go
85 go080130
86 gorGor3
87 hetGla1
88 hetGla2
89 hg16
90 hg17
91 hg18
92 hg19
93 hg19Patch10
94 hg19Patch2
95 hg19Patch5
96 hg19Patch9
97 hgFixed
98 hgTemp
99 hgcentral
100 latCha1
101 loxAfr3
102 macEug1
103 macEug2
104 melGal1
105 melUnd1
106 micMur1
107 mm10
108 mm10Patch1
109 mm5
110 mm6
111 mm7
112 mm8
113 mm9
114 monDom1
115 monDom4
116 monDom5
117 musFur1
118 myoLuc2
119 nomLeu1
120 nomLeu2
121 nomLeu3
122 ochPri2
123 oreNil1
124 oreNil2
125 ornAna1
126 oryCun2
127 oryLat2
128 otoGar3
129 oviAri1
130 oviAri3
131 panTro1
132 panTro2
133 panTro3
134 panTro4
135 papAnu2
136 papHam1
137 performance_schema
138 petMar1
139 petMar2
140 ponAbe2
141 priPac1
142 proCap1
143 proteins120806
144 proteins121210
145 proteome
146 pteVam1
147 rheMac1
148 rheMac2
149 rheMac3
150 rn3
151 rn4
152 rn5
153 sacCer1
154 sacCer2
155 sacCer3
156 saiBol1
157 sarHar1
158 sorAra1
159 sp120323
160 sp121210
161 speTri2
162 strPur1
163 strPur2
164 susScr2
165 susScr3
166 taeGut1
167 tarSyr1
168 test
169 tetNig1
170 tetNig2
171 triMan1
172 tupBel1
173 turTru2
174 uniProt
175 vicPac1
176 vicPac2
177 visiGene
178 xenTro1
179 xenTro2
180 xenTro3
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-8" style="background:;">
<hgroup>
<h2>Connecting to hg19 and listing tables</h2>
</hgroup>
<article>
<pre><code class="r">hg19 <- dbConnect(MySQL(),user="genome", db="hg19",
host="genome-mysql.cse.ucsc.edu")
allTables <- dbListTables(hg19)
length(allTables)
</code></pre>
<pre><code>[1] 10949
</code></pre>
<pre><code class="r">allTables[1:5]
</code></pre>
<pre><code>[1] "HInv" "HInvGeneMrna" "acembly" "acemblyClass" "acemblyPep"
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-9" style="background:;">
<hgroup>
<h2>Get dimensions of a specific table</h2>
</hgroup>
<article>
<pre><code class="r">dbListFields(hg19,"affyU133Plus2")
</code></pre>
<pre><code> [1] "bin" "matches" "misMatches" "repMatches" "nCount" "qNumInsert"
[7] "qBaseInsert" "tNumInsert" "tBaseInsert" "strand" "qName" "qSize"
[13] "qStart" "qEnd" "tName" "tSize" "tStart" "tEnd"
[19] "blockCount" "blockSizes" "qStarts" "tStarts"
</code></pre>
<pre><code class="r">dbGetQuery(hg19, "select count(*) from affyU133Plus2")
</code></pre>
<pre><code> count(*)
1 58463
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-10" style="background:;">
<hgroup>
<h2>Read from the table</h2>
</hgroup>
<article>
<pre><code class="r">affyData <- dbReadTable(hg19, "affyU133Plus2")
head(affyData)
</code></pre>
<pre><code> bin matches misMatches repMatches nCount qNumInsert qBaseInsert tNumInsert tBaseInsert strand
1 585 530 4 0 23 3 41 3 898 -
2 585 3355 17 0 109 9 67 9 11621 -
3 585 4156 14 0 83 16 18 2 93 -
4 585 4667 9 0 68 21 42 3 5743 -
5 585 5180 14 0 167 10 38 1 29 -
6 585 468 5 0 14 0 0 0 0 -
qName qSize qStart qEnd tName tSize tStart tEnd blockCount
1 225995_x_at 637 5 603 chr1 249250621 14361 15816 5
2 225035_x_at 3635 0 3548 chr1 249250621 14381 29483 17
3 226340_x_at 4318 3 4274 chr1 249250621 14399 18745 18
4 1557034_s_at 4834 48 4834 chr1 249250621 14406 24893 23
5 231811_at 5399 0 5399 chr1 249250621 19688 25078 11
6 236841_at 487 0 487 chr1 249250621 27542 28029 1
blockSizes
1 93,144,229,70,21,
2 73,375,71,165,303,360,198,661,201,1,260,250,74,73,98,155,163,
3 690,10,32,33,376,4,5,15,5,11,7,41,277,859,141,51,443,1253,
4 99,352,286,24,49,14,6,5,8,149,14,44,98,12,10,355,837,59,8,1500,133,624,58,
5 131,26,1300,6,4,11,4,7,358,3359,155,
6 487,
qStarts
1 34,132,278,541,611,
2 87,165,540,647,818,1123,1484,1682,2343,2545,2546,2808,3058,3133,3206,3317,3472,
3 44,735,746,779,813,1190,1195,1201,1217,1223,1235,1243,1285,1564,2423,2565,2617,3062,
4 0,99,452,739,764,814,829,836,842,851,1001,1016,1061,1160,1173,1184,1540,2381,2441,2450,3951,4103,4728,
5 0,132,159,1460,1467,1472,1484,1489,1497,1856,5244,
6 0,
tStarts
1 14361,14454,14599,14968,15795,
2 14381,14454,14969,15075,15240,15543,15903,16104,16853,17054,17232,17492,17914,17988,18267,24736,29320,
3 14399,15089,15099,15131,15164,15540,15544,15549,15564,15569,15580,15587,15628,15906,16857,16998,17049,17492,
4 14406,20227,20579,20865,20889,20938,20952,20958,20963,20971,21120,21134,21178,21276,21288,21298,21653,22492,22551,22559,24059,24211,24835,
5 19688,19819,19845,21145,21151,21155,21166,21170,21177,21535,24923,
6 27542,
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-11" style="background:;">
<hgroup>
<h2>Select a specific subset</h2>
</hgroup>
<article>
<pre><code class="r">query <- dbSendQuery(hg19, "select * from affyU133Plus2 where misMatches between 1 and 3")
affyMis <- fetch(query); quantile(affyMis$misMatches)
</code></pre>
<pre><code> 0% 25% 50% 75% 100%
1 1 2 2 3
</code></pre>
<pre><code class="r">affyMisSmall <- fetch(query,n=10); dbClearResult(query);
</code></pre>
<pre><code>[1] TRUE
</code></pre>
<pre><code class="r">dim(affyMisSmall)
</code></pre>
<pre><code>[1] 10 22
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-12" style="background:;">
<hgroup>
<h2>Don't forget to close the connection!</h2>
</hgroup>
<article>
<pre><code class="r">dbDisconnect(hg19)
</code></pre>
<pre><code>[1] TRUE
</code></pre>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="" id="slide-13" style="background:;">
<hgroup>
<h2>Further resources</h2>
</hgroup>
<article>
<ul>
<li>RMySQL vignette <a href="http://cran.r-project.org/web/packages/RMySQL/RMySQL.pdf">http://cran.r-project.org/web/packages/RMySQL/RMySQL.pdf</a></li>
<li>List of commands <a href="http://www.pantz.org/software/mysql/mysqlcommands.html">http://www.pantz.org/software/mysql/mysqlcommands.html</a>
<ul>
<li><strong>Do not, do not, delete, add or join things from ensembl. Only select.</strong></li>
<li>In general be careful with mysql commands</li>
</ul></li>
<li>A nice blog post summarizing some other commands <a href="http://www.r-bloggers.com/mysql-and-r/">http://www.r-bloggers.com/mysql-and-r/</a></li>
</ul>
</article>
<!-- Presenter Notes -->
</slide>
<slide class="backdrop"></slide>
</slides>
<!--[if IE]>
<script
src="http://ajax.googleapis.com/ajax/libs/chrome-frame/1/CFInstall.min.js">
</script>
<script>CFInstall.check({mode: 'overlay'});</script>
<![endif]-->
</body>
<!-- Grab CDN jQuery, fall back to local if offline -->
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.min.js"></script>
<script>window.jQuery || document.write('<script src="../../libraries/widgets/quiz/js/jquery-1.7.min.js"><\/script>')</script>
<!-- Load Javascripts for Widgets -->
<!-- MathJax: Fall back to local if CDN offline but local image fonts are not supported (saves >100MB) -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [['$','$'], ['\\(','\\)']],
processEscapes: true
}
});
</script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<!-- <script src="https://c328740.ssl.cf1.rackcdn.com/mathjax/2.0-latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script> -->
<script>window.MathJax || document.write('<script type="text/x-mathjax-config">MathJax.Hub.Config({"HTML-CSS":{imageFont:null}});<\/script><script src="../../libraries/widgets/mathjax/MathJax.js?config=TeX-AMS-MML_HTMLorMML"><\/script>')
</script>
<!-- LOAD HIGHLIGHTER JS FILES -->
<script src="../../libraries/highlighters/highlight.js/highlight.pack.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<!-- DONE LOADING HIGHLIGHTER JS FILES -->
</html>