In this assessment, we will examine Epigenomics Roadmap data on the human H1 stem cell line. The Roadmap id number is “E003”. We will use data on build “hg19” of the human genome, “narrowPeak” peak quantification. To make our work simpler, we will restrict our analysis to chromosome 22. Otherwise results are reported on the standard human autosomes (chromosomes 1 to 22).

load libraries

library(AnnotationHub)
## Loading required package: BiocGenerics
## Loading required package: parallel
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:parallel':
## 
##     clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
##     clusterExport, clusterMap, parApply, parCapply, parLapply,
##     parLapplyLB, parRapply, parSapply, parSapplyLB
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, xtabs
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, append, as.data.frame, as.vector, cbind,
##     colnames, do.call, duplicated, eval, evalq, Filter, Find, get,
##     grep, grepl, intersect, is.unsorted, lapply, lengths, Map,
##     mapply, match, mget, order, paste, pmax, pmax.int, pmin,
##     pmin.int, Position, rank, rbind, Reduce, rownames, sapply,
##     setdiff, sort, table, tapply, union, unique, unlist, unsplit
library(Biostrings)
## Loading required package: S4Vectors
## Loading required package: stats4
## Loading required package: IRanges
## Loading required package: XVector
library(BSgenome)
## Loading required package: GenomeInfoDb
## Loading required package: GenomicRanges
## Loading required package: rtracklayer
library(GenomicRanges)
library(rtracklayer)
library(Rsamtools)

# Load Genomes
source("https://bioconductor.org/biocLite.R")
## Bioconductor version 3.2 (BiocInstaller 1.20.3), ?biocLite for help
## A new version of Bioconductor is available after installing the most
##   recent version of R; see http://bioconductor.org/install
biocLite("BSgenome.Hsapiens.UCSC.hg19")
## BioC_mirror: https://bioconductor.org
## Using Bioconductor 3.2 (BiocInstaller 1.20.3), R 3.2.3 (2015-12-10).
## Installing package(s) 'BSgenome.Hsapiens.UCSC.hg19'
## 
## The downloaded source packages are in
##  '/tmp/RtmpTKeanZ/downloaded_packages'
## Old packages: 'boot', 'cluster', 'codetools', 'foreign', 'lattice',
##   'Matrix', 'mgcv', 'nlme', 'survival'
library("BSgenome.Hsapiens.UCSC.hg19")

biocLite("TxDb.Hsapiens.UCSC.hg19.knownGene")
## BioC_mirror: https://bioconductor.org
## Using Bioconductor 3.2 (BiocInstaller 1.20.3), R 3.2.3 (2015-12-10).
## Installing package(s) 'TxDb.Hsapiens.UCSC.hg19.knownGene'
## 
## The downloaded source packages are in
##  '/tmp/RtmpTKeanZ/downloaded_packages'
## Old packages: 'boot', 'cluster', 'codetools', 'foreign', 'lattice',
##   'Matrix', 'mgcv', 'nlme', 'survival'
library("TxDb.Hsapiens.UCSC.hg19.knownGene")
## Loading required package: GenomicFeatures
## Loading required package: AnnotationDbi
## Loading required package: Biobase
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## 
## Attaching package: 'Biobase'
## The following object is masked from 'package:AnnotationHub':
## 
##     cache

Q1: What is the GC content of “chr22” in the “hg19” build of the human genome?

library(BSgenome.Hsapiens.UCSC.hg19)
Hsapiens
## Human genome:
## # organism: Homo sapiens (Human)
## # provider: UCSC
## # provider version: hg19
## # release date: Feb. 2009
## # release name: Genome Reference Consortium GRCh37
## # 93 sequences:
## #   chr1                  chr2                  chr3                 
## #   chr4                  chr5                  chr6                 
## #   chr7                  chr8                  chr9                 
## #   chr10                 chr11                 chr12                
## #   chr13                 chr14                 chr15                
## #   ...                   ...                   ...                  
## #   chrUn_gl000235        chrUn_gl000236        chrUn_gl000237       
## #   chrUn_gl000238        chrUn_gl000239        chrUn_gl000240       
## #   chrUn_gl000241        chrUn_gl000242        chrUn_gl000243       
## #   chrUn_gl000244        chrUn_gl000245        chrUn_gl000246       
## #   chrUn_gl000247        chrUn_gl000248        chrUn_gl000249       
## # (use 'seqnames()' to see all the sequence names, use the '$' or '[['
## # operator to access a given sequence)
# count total bases on chr22
totalBases <- letterFrequency(Hsapiens$chr22, "A") +
              letterFrequency(Hsapiens$chr22, "C") +
              letterFrequency(Hsapiens$chr22, "G") +
              letterFrequency(Hsapiens$chr22, "T")

# count GC bases on chr22  
gcBase <- letterFrequency(Hsapiens$chr22, "GC")
#calculate GC ratio on chr22
gcContent <- gcBase/totalBases

gcContent
##       G|C 
## 0.4798807

Q2: What is the mean GC content of H3K27me3 “narrowPeak” regions of Epigenomics Roadmap from the H1 stem cell line on chr 22.

# Obtain H3K27me3 dataset
ah <- AnnotationHub()
## snapshotDate(): 2016-08-15
H3K27me3_qh <- query(ah, c("H3K27me3", "E003", "narrowPeak"))
H3K27me3_qh
## AnnotationHub with 1 record
## # snapshotDate(): 2016-08-15 
## # names(): AH29892
## # $dataprovider: BroadInstitute
## # $species: Homo sapiens
## # $rdataclass: GRanges
## # $title: E003-H3K27me3.narrowPeak.gz
## # $description: Narrow ChIP-seq peaks for consolidated epigenomes from ...
## # $taxonomyid: 9606
## # $genome: hg19
## # $sourcetype: BED
## # $sourceurl: http://egg2.wustl.edu/roadmap/data/byFileType/peaks/conso...
## # $sourcelastmodifieddate: 2013-10-09
## # $sourcesize: 1926389
## # $tags: EpigenomeRoadMap, peaks, consolidated, narrowPeak, E003,
## #   ESC, ESC.H1, H1 Cells 
## # retrieve record with 'object[["AH29892"]]'
# retrieve data
H3K27me3_data <- H3K27me3_qh[["AH29892"]]
# get genomic ranges on chr22
H3K27me3_data.chr22 <- subset(H3K27me3_data, seqnames == "chr22")
# get DNA seqence on chr22
H3K27me3_data.chr22.seq <- Views(Hsapiens, H3K27me3_data.chr22)
# calculate GC content on chr22
gcContents <- letterFrequency(H3K27me3_data.chr22.seq, "GC", as.prob = T)
meanGcContents <- mean(gcContents)

meanGcContents
## [1] 0.528866

Q3: What is the correlation between GC content and “signalValue” of these regions (on chr22)?

# values of signalValues
sigV <- mcols(H3K27me3_data.chr22.seq)$signalValue

# calculate correlation
cor(sigV, gcContents)
##              G|C
## [1,] 0.004467924

Q4: What is the correlation between the “signalValue” of the “narrowPeak” regions and the average “fc.signal” across the same regions?

# Obtain fc.signal file
H3K27me3_fc <- query(ah, c("H3K27me3", "E003", "fc.signal"))
H3K27me3_fc
## AnnotationHub with 1 record
## # snapshotDate(): 2016-08-15 
## # names(): AH32033
## # $dataprovider: BroadInstitute
## # $species: Homo sapiens
## # $rdataclass: BigWigFile
## # $title: E003-H3K27me3.fc.signal.bigwig
## # $description: Bigwig File containing fold enrichment signal tracks fr...
## # $taxonomyid: 9606
## # $genome: hg19
## # $sourcetype: BigWig
## # $sourceurl: http://egg2.wustl.edu/roadmap/data/byFileType/signal/cons...
## # $sourcelastmodifieddate: 2013-10-08
## # $sourcesize: 525643252
## # $tags: EpigenomeRoadMap, signal, consolidated, macs2signal,
## #   E003, ESC, ESC.H1, H1 Cells 
## # retrieve record with 'object[["AH32033"]]'
# retrieve data
H3K27me3_fc.data <- H3K27me3_fc[["AH32033"]]
## loading from cache '/home/mcc/.AnnotationHub/37473'
# get subset data on chr22
gr.chr22 <- GRanges(seqnames = "chr22", 
                    ranges = IRanges(start =1, end = 51304566))

H3K27me3_fc.rel <- import(H3K27me3_fc.data, which = gr.chr22, as = "Rle")
H3K27me3_fc.rel.chr22 <- H3K27me3_fc.rel$chr22

# view fc.signal data
fc.signal.chr22 <- Views(H3K27me3_fc.rel.chr22, 
                         start = start(H3K27me3_data.chr22), 
                         end = end(H3K27me3_data.chr22))
# calculate mean values
fc.signal.mean <- mean(fc.signal.chr22)

# calculate correlation
cor(fc.signal.mean, sigV)
## [1] 0.9149614

Q5: Question: How many bases on chr22 have an fc.signal greater than or equal to 1?

sum(H3K27me3_fc.rel.chr22 >= 1)
## [1] 10914671

Q6: Identify the regions of the genome where the signal in E003 is 0.5 or lower and the signal in E055 is 2 or higher.

H3K27me3_fc_E055 <- query(ah, c("H3K27me3", "E055"))
H3K27me3_fc_E055_data <- H3K27me3_fc_E055[[4]]
## loading from cache '/home/mcc/.AnnotationHub/37910'
# get subset data on chr22
gr.chr22 <- GRanges(seqnames = "chr22", 
                    ranges = IRanges(start =1, end = 51304566))
H3K27me3_fc.rel_E055 <- import(H3K27me3_fc_E055_data, which =gr.chr22, as = "Rle")
H3K27me3_fc.rel_E055.chr22 <- H3K27me3_fc.rel_E055$chr22

# identify region
region_E003 <- slice(H3K27me3_fc.rel.chr22, upper = 0.5)
region_E055 <- slice(H3K27me3_fc.rel_E055.chr22, lower = 2)
region_E003 <- as(region_E003, "IRanges")
region_E055 <- as(region_E055, "IRanges")
inter_region <- intersect(region_E003, region_E055)
sum(width(inter_region))
## [1] 1869937

Q7: What is the average observed-to-expected ratio of CpG dinucleotides for CpG Islands on chromosome 22?

# load hg19 CpG dataset
CpGIsland <- query(ah, c("hg19", "CpG Islands"))
CpGIsland_data <- CpGIsland[["AH5086"]]

# get data on chr22
CpGIsland_data.chr22 <- subset(CpGIsland_data, seqnames == "chr22")
CpGIsland_data.chr22.vi <- Views(Hsapiens, CpGIsland_data.chr22)

# calculate observed GC bases
region_length <- width(CpGIsland_data.chr22.vi)
observed_gcBase <- dinucleotideFrequency(CpGIsland_data.chr22.vi)[,7]/region_length

# calculate expected GC bases
freq_C <- letterFrequency(CpGIsland_data.chr22.vi, "C")
freq_G <- letterFrequency(CpGIsland_data.chr22.vi, "G")
expected_gcBase <- (freq_C/region_length)*(freq_G/region_length)

# calculate ration
mean(observed_gcBase/expected_gcBase)
## [1] 0.8340929

Q8: How many TATA boxes are there on chr 22 of build hg19 of the human genome?

# load hg19 build dataset
library(BSgenome.Hsapiens.UCSC.hg19)

TATA_boxes <- countPattern("TATAAA", Hsapiens$chr22) + 
              countPattern("TATAAA", reverseComplement(Hsapiens$chr22))

TATA_boxes
## [1] 27263

Q9: How many transcript promoters are on chromosome 22, which contain a coding sequence, such as a TATA box on the same strand as the transcript?

library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene

gr <- GRanges(seqnames = "chr22", 
              ranges = IRanges(start = 1, end = 52330658))

gr.trans.chr22 <- subsetByOverlaps(transcripts(txdb), 
                                   gr, 
                                   ignore.strand = TRUE)

proms <- promoters(gr.trans.chr22, 
                   upstream = 100, 
                   downstream = 900)

cdseq <- subsetByOverlaps(genes(txdb), 
                          gr, 
                          ignore.strand = TRUE)

proms_cds <- findOverlaps(proms, cdseq)
unique(queryHits(proms_cds))
##    [1]    8    9   10   11   12   13   14   15   16   18   19   20   21
##   [14]   22   23   24   25   26   27   28   29   30   31   32   33   34
##   [27]   35   36   37   38   39   40   41   42   44   45   46   47   48
##   [40]   49   50   51   57   58   59   60   61   62   63   64   66   67
##   [53]   68   69   70   71   72   73   74   75   76   77   78   79   80
##   [66]   81   82   83   84   85   86   87   88   89   90   91   92   93
##   [79]   94   95   96   97   98   99  100  101  102  103  104  105  106
##   [92]  107  108  109  110  111  112  114  115  116  117  125  126  127
##  [105]  128  129  130  131  132  133  134  135  136  137  138  139  140
##  [118]  141  142  143  151  152  153  154  155  157  158  159  160  161
##  [131]  162  163  164  165  166  167  168  169  170  171  172  173  174
##  [144]  175  179  180  183  184  185  186  187  188  189  195  196  197
##  [157]  198  199  200  201  202  203  204  205  206  207  208  209  210
##  [170]  211  214  215  216  217  219  223  224  225  226  227  228  229
##  [183]  230  231  232  233  234  235  236  237  238  239  240  241  242
##  [196]  243  244  245  246  247  248  249  250  251  252  253  254  255
##  [209]  256  257  258  259  260  261  262  263  264  265  268  269  270
##  [222]  271  272  273  274  275  276  277  278  279  280  281  282  283
##  [235]  284  285  286  287  288  289  290  291  292  293  294  295  296
##  [248]  297  298  299  300  301  302  303  304  305  306  307  309  310
##  [261]  311  312  313  314  315  316  317  318  319  320  321  322  323
##  [274]  324  325  326  327  328  329  330  331  332  333  334  335  336
##  [287]  337  338  339  340  341  342  343  344  345  346  347  348  349
##  [300]  350  351  352  353  355  356  357  358  360  361  362  363  364
##  [313]  365  366  367  368  369  370  371  372  373  374  375  376  377
##  [326]  378  379  380  381  382  383  384  385  386  387  388  389  390
##  [339]  391  392  393  394  395  396  397  398  399  400  401  402  403
##  [352]  404  405  406  407  408  409  410  411  413  414  415  416  417
##  [365]  418  419  420  421  422  423  424  425  426  427  428  429  430
##  [378]  431  432  433  434  435  436  437  438  439  440  441  442  443
##  [391]  444  445  446  447  448  449  450  451  452  453  454  455  456
##  [404]  457  458  459  460  461  462  463  464  465  466  467  468  469
##  [417]  470  471  472  473  474  475  476  477  479  481  482  483  484
##  [430]  485  486  487  488  489  490  491  492  493  494  495  496  497
##  [443]  498  499  500  501  502  503  504  505  506  507  508  509  510
##  [456]  511  512  513  514  515  516  517  518  519  520  521  522  523
##  [469]  524  525  526  527  528  529  530  531  532  533  534  535  536
##  [482]  537  538  539  540  541  542  543  544  545  546  547  548  549
##  [495]  550  551  552  553  554  556  557  558  559  560  561  562  563
##  [508]  564  565  566  567  568  569  570  571  573  574  575  576  577
##  [521]  578  579  580  581  582  583  584  585  586  587  588  589  590
##  [534]  591  592  593  594  595  596  597  598  599  600  601  602  603
##  [547]  604  605  606  607  608  609  610  611  612  613  614  615  616
##  [560]  617  618  619  620  622  623  624  625  626  627  628  629  630
##  [573]  631  632  633  634  635  636  637  638  639  640  641  642  643
##  [586]  644  645  646  647  648  650  651  652  653  654  655  656  657
##  [599]  658  659  660  661  662  663  664  665  666  667  668  669  670
##  [612]  671  672  673  674  675  676  677  678  679  680  681  682  683
##  [625]  684  685  686  687  688  689  690  691  692  693  694  695  696
##  [638]  697  698  699  700  701  702  703  704  705  706  707  708  709
##  [651]  710  711  712  713  714  715  716  717  718  719  720  721  722
##  [664]  723  724  725  726  727  728  729  730  731  732  733  734  735
##  [677]  736  737  738  740  741  742  743  744  745  746  747  748  749
##  [690]  750  751  752  753  754  755  756  757  758  759  760  761  762
##  [703]  763  764  765  767  768  769  770  771  773  774  775  776  777
##  [716]  778  779  780  781  782  783  784  785  786  787  788  789  790
##  [729]  791  792  793  794  795  796  797  798  799  800  801  802  803
##  [742]  804  805  806  807  808  809  810  811  812  813  814  815  816
##  [755]  817  818  819  820  821  822  823  824  825  826  827  828  829
##  [768]  830  831  832  833  834  835  836  837  838  839  840  841  842
##  [781]  843  844  845  846  847  848  849  850  851  852  853  854  855
##  [794]  856  857  858  859  860  861  862  863  864  865  866  867  868
##  [807]  869  870  871  872  873  874  875  876  877  878  879  880  881
##  [820]  882  885  886  887  888  889  890  891  892  893  894  895  896
##  [833]  897  898  899  900  901  902  903  904  905  906  907  908  909
##  [846]  910  911  912  913  914  915  916  917  918  919  920  921  922
##  [859]  923  924  925  926  927  928  929  930  931  932  933  934  936
##  [872]  937  938  939  940  941  942  943  944  945  946  947  948  949
##  [885]  966  967  968  969  970  971  972  974  975  977  978  979  980
##  [898]  981  982  983  984  985  986  987  988  989  990  991  992  993
##  [911]  994  995  996  997  998  999 1000 1001 1002 1003 1004 1005 1006
##  [924] 1007 1008 1009 1010 1011 1012 1013 1014 1017 1018 1019 1020 1021
##  [937] 1022 1023 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035
##  [950] 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
##  [963] 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
##  [976] 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074
##  [989] 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087
## [1002] 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1104
## [1015] 1105 1106 1107 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119
## [1028] 1121 1130 1131 1132 1133 1134 1135 1138 1139 1140 1141 1142 1143
## [1041] 1144 1145 1146 1147 1148 1149 1150 1151 1152 1154 1155 1156 1157
## [1054] 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170
## [1067] 1171 1172 1173 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184
## [1080] 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1197 1198
## [1093] 1199 1200 1201 1202 1203 1209 1210 1211 1212 1213 1214 1215 1216
## [1106] 1217 1218 1219 1220 1221 1222 1223 1224 1227 1228 1229 1230 1231
## [1119] 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1245
## [1132] 1246 1247 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259
## [1145] 1260 1261 1262 1263 1264 1265 1269 1270 1271 1272 1273 1274 1275
## [1158] 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
## [1171] 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301
## [1184] 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314
## [1197] 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327
## [1210] 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340
## [1223] 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353
## [1236] 1354 1355 1356 1357 1358 1359 1360 1363 1364 1365 1366 1367 1368
## [1249] 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
## [1262] 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1394 1395
## [1275] 1396 1397 1398 1399 1400 1401 1403 1404 1405 1406 1407 1408 1409
## [1288] 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1421 1422 1423
## [1301] 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436
## [1314] 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449
## [1327] 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
## [1340] 1463 1464 1465 1466 1467 1468 1469 1470 1471 1473 1474 1475 1476
## [1353] 1477 1478 1479 1480 1481 1482 1483 1484 1534 1535 1536 1537 1538
## [1366] 1539 1540 1541 1542 1543 1544 1545 1546 1549 1550 1551 1552 1553
## [1379] 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
## [1392] 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579
## [1405] 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592
## [1418] 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
## [1431] 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619
## [1444] 1620 1621 1623 1624 1625 1626 1627 1628 1629 1630 1631 1634 1635
## [1457] 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648
## [1470] 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661
## [1483] 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1673 1674 1675
## [1496] 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688
## [1509] 1689 1690 1691 1692 1693 1694 1695 1696 1699 1700 1701 1702 1703
## [1522] 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1716 1717
## [1535] 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730
## [1548] 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
## [1561] 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756
## [1574] 1759 1760 1761 1762 1765 1766 1767 1768 1769 1770 1771 1772 1775
## [1587] 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788
## [1600] 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801
## [1613] 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814
## [1626] 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827
## [1639] 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840
## [1652] 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853
## [1665] 1854 1855 1856 1857 1858 1859 1861 1862 1863 1864 1865 1866 1867
## [1678] 1868
count = 0
for (i in unique(queryHits(proms_cds))){
  proms_cds_view <- Views(Hsapiens, proms[i])
  count = count + vcountPattern("TATAAA", DNAStringSet(proms_cds_view))
}

count
## [1] 218

Q10: How many bases on chr22 are part of more than one promoter of a coding sequence?

library(GenomicFeatures)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene

seqlevels(txdb, force=TRUE) <- c("chr22")
gr <- GRanges(seqnames = "chr22", 
              ranges = IRanges(start = 1, end = 52330658))

gr.trans.chr22 <- subsetByOverlaps(transcripts(txdb), 
                                   gr, 
                                   ignore.strand = TRUE)
length(gr.trans.chr22) 
## [1] 1868
gr.prom <- promoters(gr.trans.chr22, 
                     upstream = 100, 
                     downstream = 900)
tl.chr22 <- transcriptLengths(txdb, 
                              with.cds_len = TRUE) #rtn df

tl.chr22  <- tl.chr22[tl.chr22$cds_len > 0,]

trans.eval <- gr.prom[mcols(gr.prom)$tx_id %in% tl.chr22$tx_id]

sum(coverage(trans.eval) > 1)
##  chr22 
## 309991
sessionInfo()
## R version 3.2.3 (2015-12-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04 LTS
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    parallel  stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] TxDb.Hsapiens.UCSC.hg19.knownGene_3.2.2
##  [2] GenomicFeatures_1.22.13                
##  [3] AnnotationDbi_1.32.3                   
##  [4] Biobase_2.30.0                         
##  [5] BSgenome.Hsapiens.UCSC.hg19_1.4.0      
##  [6] BiocInstaller_1.20.3                   
##  [7] Rsamtools_1.22.0                       
##  [8] BSgenome_1.38.0                        
##  [9] rtracklayer_1.30.4                     
## [10] GenomicRanges_1.22.4                   
## [11] GenomeInfoDb_1.6.3                     
## [12] Biostrings_2.38.4                      
## [13] XVector_0.10.0                         
## [14] IRanges_2.4.8                          
## [15] S4Vectors_0.8.11                       
## [16] AnnotationHub_2.2.5                    
## [17] BiocGenerics_0.16.1                    
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_0.12.7                  futile.logger_1.4.3         
##  [3] formatR_1.4                  futile.options_1.0.0        
##  [5] bitops_1.0-6                 tools_3.2.3                 
##  [7] zlibbioc_1.16.0              biomaRt_2.26.1              
##  [9] digest_0.6.10                evaluate_0.9                
## [11] RSQLite_1.0.0                shiny_0.14.1                
## [13] DBI_0.5-1                    curl_2.1                    
## [15] yaml_2.1.13                  httr_1.2.1                  
## [17] stringr_1.1.0                knitr_1.14                  
## [19] R6_2.2.0                     BiocParallel_1.4.3          
## [21] XML_3.98-1.4                 rmarkdown_1.0               
## [23] lambda.r_1.1.9               magrittr_1.5                
## [25] GenomicAlignments_1.6.3      htmltools_0.3.5             
## [27] SummarizedExperiment_1.0.2   mime_0.5                    
## [29] interactiveDisplayBase_1.8.0 xtable_1.8-2                
## [31] httpuv_1.3.3                 stringi_1.1.2               
## [33] RCurl_1.95-4.8