-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathFigures.Rmd
309 lines (298 loc) · 13.6 KB
/
Figures.Rmd
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
---
title: "code snippet"
author: "Jianhong Ou"
date: "DEC 11, 2018"
output:
html_document:
fig_caption: yes
self_contained: no
toc: yes
---
```{r setup, include=FALSE}
figure.cap.id <- c("1A", "1B", "1C", "1D")
fn = local({
i = 0
function(x, cnt=TRUE){
if(cnt) i <<- i + 1
paste0('Figure ', figure.cap.id[i], ": ", x)
}
})
library(trackViewer)
library(GenomicFeatures)
library(org.Mm.eg.db)
library(VariantAnnotation)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(org.Hs.eg.db)
library(rtracklayer)
library(Biostrings)
library(motifStack)
library(knitr)
if(Sys.getenv("USER")=="jianhongou"){
opts_chunk$set(dev=c("pdf", "png"))
}
```
# Figure 1A
```{r figure1A,fig.width=12,fig.height=8,dpi=300,fig.cap=fn("Tracks for Sort1 exclusive exon"), message=FALSE}
library(trackViewer) # load package
gr <- parse2GRanges("chr3:108,476,000-108,485,000")
gr # interesting genomic locations
library(GenomicFeatures) # load GenomicFeatures to create TxDb from UCSC
#if(interactive()){
# mm8KG <- makeTxDbFromUCSC(genome="mm8", tablename="knownGene")
# saveDb(mm8KG, "mm8KG.sqlite")
#}else{## mm8KG was saved as sqlite file
mm8KG <- loadDb("mm8KG.sqlite")
#}
library(org.Mm.eg.db) # load annotation database
## create the gene model tracks information
trs <- geneModelFromTxdb(mm8KG, org.Mm.eg.db, gr=gr)
## import data from bedGraph/bigWig/BED ... files, see ?importScore for details
CLIP <- importScore("CLIP.bedGraph", format="bedGraph", ranges=gr)
control <- importScore("control.bedGraph", format="bedGraph", ranges=gr)
knockdown <- importScore("knockdown.bedGraph", format="bedGraph", ranges=gr)
## create styles by preset theme
optSty <- optimizeStyle(trackList(trs, knockdown, control, CLIP), theme="col")
trackList <- optSty$tracks
viewerStyle <- optSty$style
## adjust the styles for this track
### rename the trackList for each track
names(trackList)[1:2] <- paste0("Sort1: ", names(trackList)[1:2])
names(trackList)[3] <- "RNA-seq TDP-43 KD"
names(trackList)[4] <- "RNA-seq control"
### change the lab positions for gene model track to bottomleft
setTrackStyleParam(trackList[[1]], "ylabpos", "bottomleft")
setTrackStyleParam(trackList[[2]], "ylabpos", "bottomleft")
### change the color of gene model track
setTrackStyleParam(trackList[[1]], "ylabgp", list(cex=1, col="red"))
setTrackStyleParam(trackList[[2]], "ylabgp", list(cex=1, col="green"))
### remove the xaxis
setTrackViewerStyleParam(viewerStyle, "xaxis", FALSE)
### add a scale bar in CLIP track
setTrackXscaleParam(trackList[[5]], "draw", TRUE)
## plot the tracks
vp <- viewTracks(trackList, gr=gr, viewerStyle=viewerStyle)
### add guide lines to show the range of CLIP-seq signal
addGuideLine(c(108481252, 108481887), vp=vp)
### add arrow mark to show the alternative splicing event
addArrowMark(list(x=c(108483570, 108483570),
y=c(3, 4)), ##layer 3 and 4
label=c("Inclusive\nexon", ""),
col=c("blue", "cyan"),
vp=vp, quadrant=1)
```
# Figure 1B
```{r figure1B,fig.width=12,fig.height=8,dpi=300,fig.cap=fn("lollipop plot"), message=FALSE}
library(trackViewer) # load package
library(VariantAnnotation)
library(TxDb.Hsapiens.UCSC.hg19.knownGene)
library(org.Hs.eg.db)
library(rtracklayer)
fl <- system.file("extdata", "chr22.vcf.gz", package="VariantAnnotation")
## set the track range
gr <- GRanges("22", IRanges(50968014, 50970514, names="TYMP"))
## read in vcf file
tab <- TabixFile(fl)
vcf <- readVcf(fl, "hg19", param=gr)
## get GRanges from VCF object
mutation.frequency <- rowRanges(vcf)
## keep the metadata
mcols(mutation.frequency) <-
cbind(mcols(mutation.frequency),
VariantAnnotation::info(vcf))
## set colors
mutation.frequency$border <- "gray30"
mutation.frequency$color <-
ifelse(grepl("^rs", names(mutation.frequency)),
"lightcyan", "lavender")
## plot Global Allele Frequency based on AC/AN
mutation.frequency$score <- round(mutation.frequency$AF*100)
## change the SNPs label rotation angle
mutation.frequency$label.parameter.rot <- 45
## keep sequence level style same
seqlevelsStyle(gr) <- seqlevelsStyle(mutation.frequency) <- "UCSC"
## extract transcripts in the range
trs <- geneModelFromTxdb(TxDb.Hsapiens.UCSC.hg19.knownGene,
org.Hs.eg.db, gr=gr)
## subset the features to show the interested transcripts only
features <- GRangesList(trs[[1]]$dat, trs[[5]]$dat, trs[[6]]$dat)
flen <- elementNROWS(features)
features <- unlist(features)
## define the feature track layers
features$featureLayerID <- rep(1:2, c(sum(flen[-3]), flen[3]))
## define the feature labels
names(features) <- features$symbol
## define the feature colors
features$fill <- rep(c("lightblue", "mistyrose", "mistyrose"), flen)
## define the feature heights
features$height <- ifelse(features$feature=="CDS", .04, .02)
## import methylation data from a bed file
methy <- import(system.file("extdata", "methy.bed", package="trackViewer"), "BED")
## subset the data
methy <- methy[methy$score > 20]
## simulate multiple patients
rand.id <- sample.int(length(methy), 3*length(methy), replace=TRUE)
rand.id <- sort(rand.id)
methy.mul.patient <- methy[rand.id]
## pie.stack require metadata "stack.factor", and the metadata can not be
## stack.factor.order or stack.factor.first
len.max <- max(table(rand.id))
stack.factors <- paste0("patient",
formatC(1:len.max,
width=nchar(as.character(len.max)),
flag="0"))
methy.mul.patient$stack.factor <-
unlist(lapply(table(rand.id), sample, x=stack.factors))
methy.mul.patient$score <-
sample.int(100, length(methy.mul.patient), replace=TRUE)
## for a pie plot, two or more numeric meta-columns are required.
methy.mul.patient$score2 <- 100 - methy.mul.patient$score
## set different color set for different patient
patient.color.set <- as.list(as.data.frame(rbind(rainbow(length(stack.factors)),
"#FFFFFFFF"),
stringsAsFactors=FALSE))
names(patient.color.set) <- stack.factors
methy.mul.patient$color <-
patient.color.set[methy.mul.patient$stack.factor]
## set the legends
legends <- list(list(labels=c("known", "unkown"),
fill=c("lightcyan", "lavender"),
color=c("gray80", "gray80")),
list(labels=stack.factors, col="gray80",
fill=sapply(patient.color.set, `[`, 1)))
## lollipop plot
lolliplot(list(mutaions=mutation.frequency, methylations=methy.mul.patient),
features, ranges=gr, type=c("circle", "pie.stack"),
legend=legends, newpage = TRUE)
```
# Figure 1C
FMR1 methylation and expression (GSE108577)
```{r figure1C,fig.width=12,fig.height=8,dpi=300,fig.cap=fn("Visualization of mutations/SNPs and RNA-seq data together"), message=FALSE}
library(trackViewer) #load package
library(Biostrings)
library(motifStack)
motif <- importMatrix("TET1.PWM.txt", format = "cisbp") ## motif was downloaded from cis-bp
pwm <- pfm2pwm(motif[[1]])
fa <- readDNAStringSet("FMR1.ups3K.dws3K.fasta")
names(fa) <- "FMR1"
TET1.binding.sites.v <- matchPWM(pwm, subject = fa[[1]],
min.score = "95%", with.score = TRUE)
TET1.binding.sites <- shift(ranges(TET1.binding.sites.v), shift = 147908950)
TET1.binding.sites <- GRanges("chrX", TET1.binding.sites, strand = "+",
score=mcols(TET1.binding.sites.v)$score)
width(TET1.binding.sites) <- 1
TET1.binding.sites$border <- "gray80"
TET1.binding.sites$color <- 3
## set lollipop plot type to pin.
TET1.binding.sites$type <- "pin"
TET1.binding.sites <- new("track", dat=TET1.binding.sites, type="lollipopData")
gr <- GRanges("chrX", IRanges(147910500, 147914000))
## extract transcripts in the range
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
library(org.Hs.eg.db)
FMR1 <- geneTrack(get("FMR1", org.Hs.egSYMBOL2EG), TxDb.Hsapiens.UCSC.hg38.knownGene)[[1]]
FMR1$dat2 <- GRanges("chrX",
IRanges(c(147911604, 147911617, 147911727, 147911743, 147911758,
147911768, 147911810, 147911821, 147911854, 147911877,
147911882, 147911902, 147911963), width = 1,
names = c("AP2", "UBP1", "Sp1", "Sp1", "NRF1",
"Sp1", "AGP", "NRF1", "Sp1", "AP2",
"Sp1-like", "Myc", "Zeste")))
FMR1$dat2$color <- as.numeric(factor(names(FMR1$dat2)))
FMR1$dat2$border <- "gray"
## set lollipop label parameter.
FMR1$dat2$label.parameter.rot <- 45
## add methylation counts
maxX <- GRanges("chrX", IRanges(147911550, width=1), score=9,
color="white", border="white")
FX52_mock_methy <- GRanges("chrX", IRanges(147911556+seq.int(35)*4, width=1),
score=c(8, 8, 8, 7, 8, 9, 9, 9, 8, 9, 9, 9, 9, 8, 9,
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
9, 9, 9, 8, 9), color=5, border="gray")
FX52_mock_methy <- new("track", dat=c(FX52_mock_methy, maxX), type="lollipopData")
FX52_dC_T_methy <- GRanges("chrX", IRanges(147911556+seq.int(35)*4, width=1),
score=c(3, 5, 3, 2, 0, 1, 1, 2, 0, 1, 1, 0, 0, 1, 0,
0, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 1, 0, 0, 1), color=4, border="gray")
FX52_dC_T_methy$color[FX52_dC_T_methy$score==0] <- "white"
FX52_dC_T_methy <- new("track", dat=c(FX52_dC_T_methy, maxX), type="lollipopData")
## import RNA-seq tracks
iPSC_dC_T.RNAseq <- importScore("iPSC_dC-T.bw", ranges = gr, format = "BigWig")
iPSC_mock.RNAseq <- importScore("iPSC_mock.bw", ranges = gr, format = "BigWig")
## import ChIP-Bisulfite-Seq tracks
iPSC_dC_T.BSseq <- importScore("IPSC_dC-T.methy.bedgraph", "IPSC_dC-T.demethy.bedgraph", ranges = gr, format = "bedGraph")
iPSC_dC_dT.BSseq <- importScore("IPSC_dC-dT.methy.bedgraph", "IPSC_dC-dT.demethy.bedgraph", ranges = gr, format = "bedGraph")
##stronger the signals
width(iPSC_dC_T.BSseq$dat) <- width(iPSC_dC_T.BSseq$dat) + 1
width(iPSC_dC_dT.BSseq$dat) <- width(iPSC_dC_dT.BSseq$dat) + 1
## optimize stlye
optSty <- optimizeStyle(trackList(FMR1, TET1.binding.sites,
FX52_dC_T_methy, FX52_mock_methy,
iPSC_dC_dT.BSseq, iPSC_dC_T.BSseq,
iPSC_mock.RNAseq, iPSC_dC_T.RNAseq,
heightDist=c(2, 1, 1, 1, 1, 1, 1, 1)),
theme="col")
trackList <- optSty$tracks
viewerStyle <- optSty$style
## adjust y scale
for(i in c("iPSC_dC_T.RNAseq", "iPSC_mock.RNAseq")){
setTrackStyleParam(trackList[[i]], "ylim", c(0, 20))
}
## adjust track stlyes
setTrackStyleParam(trackList[["iPSC_dC_T.BSseq"]], "color", c("#E69F00", "pink"))
setTrackStyleParam(trackList[["iPSC_dC_T.BSseq"]], "ylabgp",
list(cex=trackList[["iPSC_dC_T.BSseq"]]$style@ylabgp$cex,
col="orange"))
setTrackStyleParam(trackList[["iPSC_dC_dT.BSseq"]], "color", c("#E69F00", "pink"))
setTrackStyleParam(trackList[["FMR1"]], "ylabgp", list(cex=2, col="red"))
vp <- viewTracks(trackList, gr=gr, viewerStyle=viewerStyle)
addGuideLine(c(147911556, 147911695, 147912052, 147912111),
col = c("#CC79A7", "#CC79A7", "#0072B2", "#0072B2"), vp=vp)
addArrowMark(pos = list(x=c(147911626, 147912070), y=c(4, 1)),
label = c("CpG island", "(CGG)n"),
col = c("#CC79A7", "#0072B2"), vp=vp)
```
# Figure 1D
TP53 mutations were downloaded from http://p53.iarc.fr/DownloadDataset.aspx.
```{r figure1D,fig.width=12,fig.height=8,dpi=300,fig.cap=fn("Dandelion plot"), message=FALSE}
library(trackViewer) #load package
## loading data.
data <- read.delim("IARC-TP53/datasets/somaticMutationDataIARC TP53 Database, R19.txt",
stringsAsFactors = FALSE)
data <- data[data$Morphology %in% "Small cell carcinoma, NOS" &
data$Effect %in% c("nonsense", "missense", "silent", "intronic"),
c("hg38_Chr17_coordinates", "g_description_GRCh38", "Effect")]
counts <- table(data$g_description_GRCh38)
data$counts <- as.numeric(counts[data$g_description_GRCh38])
data <- unique(data)
## prepare a GRanges object for mutations
snps <- with(data, GRanges("chr17", IRanges(hg38_Chr17_coordinates, width=1),
effect=factor(Effect), score=counts))
## set the bristles head colors of the pappus by mutation types
snps$color <- as.numeric(snps$effect)+1
## parepare the legends
legends <- list(list(labels=levels(snps$effect),
fill=seq.int(length(levels(snps$effect)))+1))
## set the beak color of dandelion seeds.
snps$border <- "gray"
## set plotting region
gr <- GRanges("chr17", IRanges(7669000, 7677000))
## extract transcripts in the range
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
library(org.Hs.eg.db)
trs <- geneModelFromTxdb(TxDb.Hsapiens.UCSC.hg38.knownGene,
org.Hs.eg.db, gr=gr)
## subset the features to show the interested transcripts only
features <- c(trs[[1]]$dat, trs[[3]]$dat, trs[[4]]$dat)
lens <- sapply(trs[c(1, 3, 4)], function(.e) length(.e$dat))
## define the feature legend name
names(features) <- rep(names(trs)[c(1, 3, 4)], lens)
## define the feature track layers
features$featureLayerID <- rep(seq.int(3), lens)
## define the feature colors
features$fill <- rep(c("lightblue", "mistyrose", "orange"), lens)
## define the feature heights
features$height <- ifelse(features$feature=="CDS", 0.02, 0.01)
## plot, use mean function to calculate the height of beak of dandelion seeds.
dandelion.plot(snps, features, ranges=gr, legend = legends, type="circle",
heightMethod = mean, yaxis = TRUE, ylab='mean of mutation counts')
```