Switch to unified view

a b/Figures/clonevol/clonevol_P10_311018.R
1
library(dplyr)
2
library(plyr)
3
library(clonevol)
4
library(fishplot)
5
library(reshape)
6
7
####coverage: from reseq BAM files 
8
####step1: Using mpileup to extract coverage for each site. (Prepared 27/10/18), default parameter
9
10
####step2: Prepare input for pyclone, using segments from ASCAT
11
12
####step3: Run Pyclone twice. The first run is to identify founding cluster, 
13
####       the second run adding --tumour_content based on the cellular prevalence for each biopsy (29/10/18)
14
15
###step4: using clonevol to build evolution tree and model (in this script) (30/10/18)
16
17
###       using Fishplot to visulaize
18
19
###P10, 2 biopsies, hist_transform
20
21
22
23
24
#T1:LN_left_breast
25
#T2:LN_right_inguinal
26
27
28
setwd("F:/FL_exome_final/fl_latest/11_pyclone/BED_bam/counts_new/pyclone_output_301018/")
29
30
pyclone_out<- read.table(file="ouput_pyclone/output_200X_i2/P10_200X_i2/tables/loci.tsv",sep="\t",header=T)
31
32
mutations<-cast(pyclone_out[,1:4], mutation_id~sample_id, value="cellular_prevalence")
33
id<-unique(pyclone_out[, c(1,3)] )
34
35
P_case<- merge(id, mutations,by="mutation_id")
36
37
vafs = data.frame(cluster=P_case$cluster_id,
38
                  T1_vaf=(P_case$`GCF0150-0010-T01`/2)*100,
39
                  T2_vaf=(P_case$`GCF0150-0010-T02`/2)*100,
40
                  stringsAsFactors=F)
41
42
vafs$cluster<- vafs$cluster+1
43
44
###needs manully check density plot to identify which cluster is founding cluster
45
##clonevol requires founding cluster=1
46
47
max_id<- max(vafs$cluster)+1
48
49
vafs$cluster[vafs$cluster==1]<-max_id
50
vafs$cluster[vafs$cluster==3]<-1
51
vafs$cluster[vafs$cluster==max_id]<-3
52
53
54
55
samples<-c("P10_1","P10_2")
56
57
names(vafs)[2:3] = samples 
58
##step 2: run infer.clonal.models, run twice: 1. include all cluster. 
59
###########2. manual review density plot and exlcude cluster with small number of mutations
60
61
62
dir.create("./clonevol/P10")
63
##
64
65
66
##first: use all clusters, no consensus models
67
68
res = infer.clonal.models(variants=vafs, cluster.col.name="cluster", vaf.col.names=samples,
69
                          
70
                          subclonal.test="bootstrap", subclonal.test.model="non-parametric",
71
                          founding.cluster=1,
72
                          cluster.center="mean", num.boots=1000,
73
                          min.cluster.vaf=0.01, sum.p=0.01, alpha=0.01)
74
75
res = infer.clonal.models(variants=vafs, cluster.col.name="cluster", vaf.col.names=samples,
76
                          
77
                          subclonal.test="bootstrap", subclonal.test.model="non-parametric",
78
                          founding.cluster=1,ignore.clusters = c(2,8:13),
79
                          cluster.center="mean", num.boots=1000,
80
                          min.cluster.vaf=0.01, sum.p=0.01, alpha=0.01)
81
82
83
#Finding consensus models across samples...
84
#Found  0 consensus model(s)
85
#Found 0 consensus model(s)
86
87
88
##second: ignore cluster 5:7 consensus model based on manual review
89
90
91
vafs_used<- subset(vafs, !cluster %in% c(2,8:13))
92
93
vafs_used$cluster[vafs_used$cluster=="7"]<-2
94
95
96
res = infer.clonal.models(variants=vafs_used, cluster.col.name="cluster", vaf.col.names=samples,
97
                          subclonal.test="bootstrap", subclonal.test.model="non-parametric",
98
                          founding.cluster=1, 
99
                          cluster.center="mean", num.boots=1000,
100
                          min.cluster.vaf=0.01, sum.p=0.01, alpha=0.01)
101
102
103
104
res<-convert.consensus.tree.clone.to.branch(res, branch.scale = 'sqrt')
105
106
pdf("./clonevol/P10/P10_trees.pdf", useDingbats = FALSE)
107
plot.all.trees.clone.as.branch(res, branch.width = 0.5, node.size = 1, node.label.size = 0.5)
108
dev.off()
109
110
111
plot.clonal.models(res,
112
                   # box plot parameters
113
                   box.plot = TRUE,
114
                   fancy.boxplot = TRUE,
115
                   fancy.variant.boxplot.highlight = 'is.driver',
116
                   fancy.variant.boxplot.highlight.shape = 21,
117
                   fancy.variant.boxplot.highlight.fill.color = 'red',
118
                   fancy.variant.boxplot.highlight.color = 'black',
119
                   fancy.variant.boxplot.highlight.note.col.name = 'gene',
120
                   fancy.variant.boxplot.highlight.note.color = 'blue',
121
                   fancy.variant.boxplot.highlight.note.size = 2,
122
                   fancy.variant.boxplot.jitter.alpha = 1,
123
                   fancy.variant.boxplot.jitter.center.color = 'grey50',
124
                   fancy.variant.boxplot.base_size = 12,
125
                   fancy.variant.boxplot.plot.margin = 1,
126
                   fancy.variant.boxplot.vaf.suffix = '.VAF',
127
                   # bell plot parameters
128
                   clone.shape = 'bell',
129
                   bell.event = TRUE,
130
                   bell.event.label.color = 'blue',
131
                   bell.event.label.angle = 60,
132
                   clone.time.step.scale = 1,
133
                   bell.curve.step = 2,
134
                   # node-based consensus tree parameters
135
                   merged.tree.plot = TRUE,
136
                   tree.node.label.split.character = NULL,
137
                   tree.node.shape = 'circle',
138
                   tree.node.size = 30,
139
                   tree.node.text.size = 0.5,
140
                   merged.tree.node.size.scale = 1.25,
141
                   merged.tree.node.text.size.scale = 2,
142
                   merged.tree.cell.frac.ci = FALSE,
143
                   # branch-based consensus tree parameters
144
                   merged.tree.clone.as.branch = TRUE,
145
                   mtcab.event.sep.char = ',',
146
                   mtcab.branch.text.size = 1,
147
                   mtcab.branch.width = 0.75,
148
                   mtcab.node.size = 3,
149
                   mtcab.node.label.size = 1,
150
                   mtcab.node.text.size = 1.5,
151
                   # cellular population parameters
152
                   cell.plot = TRUE,
153
                   num.cells = 100,
154
                   cell.border.size = 0.25,
155
                   cell.border.color = 'black',
156
                   clone.grouping = 'horizontal',
157
                   #meta-parameters
158
                   scale.monoclonal.cell.frac = TRUE,
159
                   show.score = FALSE,
160
                   cell.frac.ci = TRUE,
161
                   disable.cell.frac = FALSE,
162
                   # output figure parameters
163
                   out.dir = './clonevol/P10/',
164
                   out.format = 'pdf',
165
                   overwrite.output = TRUE,
166
                   width = 10,
167
                   height = 4,
168
                   # vector of width scales for each panel from left to right
169
                   panel.widths = c(1.5,2.5,1.5,2.5,2))
170
171
###removing cell.frac annotation
172
173
plot.clonal.models(res,
174
                   # box plot parameters
175
                   box.plot = TRUE,
176
                   fancy.boxplot = TRUE,
177
                   fancy.variant.boxplot.highlight = 'is.driver',
178
                   fancy.variant.boxplot.highlight.shape = 21,
179
                   fancy.variant.boxplot.highlight.fill.color = 'red',
180
                   fancy.variant.boxplot.highlight.color = 'black',
181
                   fancy.variant.boxplot.highlight.note.col.name = 'gene',
182
                   fancy.variant.boxplot.highlight.note.color = 'blue',
183
                   fancy.variant.boxplot.highlight.note.size = 2,
184
                   fancy.variant.boxplot.jitter.alpha = 1,
185
                   fancy.variant.boxplot.jitter.center.color = 'grey50',
186
                   fancy.variant.boxplot.base_size = 12,
187
                   fancy.variant.boxplot.plot.margin = 1,
188
                   fancy.variant.boxplot.vaf.suffix = '.VAF',
189
                   # bell plot parameters
190
                   clone.shape = 'bell',
191
                   bell.event = TRUE,
192
                   bell.event.label.color = 'blue',
193
                   bell.event.label.angle = 60,
194
                   clone.time.step.scale = 1,
195
                   bell.curve.step = 2,
196
                   # node-based consensus tree parameters
197
                   merged.tree.plot = TRUE,
198
                   tree.node.label.split.character = NULL,
199
                   tree.node.shape = 'circle',
200
                   tree.node.size = 30,
201
                   tree.node.text.size = 0.5,
202
                   merged.tree.node.size.scale = 1.25,
203
                   merged.tree.node.text.size.scale = 2,
204
                   merged.tree.cell.frac.ci = FALSE,
205
                   # branch-based consensus tree parameters
206
                   merged.tree.clone.as.branch = TRUE,
207
                   mtcab.event.sep.char = ',',
208
                   mtcab.branch.text.size = 1,
209
                   mtcab.branch.width = 0.75,
210
                   mtcab.node.size = 3,
211
                   mtcab.node.label.size = 1,
212
                   mtcab.node.text.size = 1.5,
213
                   # cellular population parameters
214
                   cell.plot = TRUE,
215
                   num.cells = 100,
216
                   cell.border.size = 0.25,
217
                   cell.border.color = 'black',
218
                   clone.grouping = 'horizontal',
219
                   #meta-parameters
220
                   scale.monoclonal.cell.frac = TRUE,
221
                   show.score = FALSE,
222
                   cell.frac.ci = TRUE,
223
                   disable.cell.frac = TRUE,
224
                   # output figure parameters
225
                   out.dir = './clonevol/P10/',
226
                   out.format = 'pdf',
227
                   overwrite.output = TRUE,
228
                   width = 10,
229
                   height = 4,
230
                   # vector of width scales for each panel from left to right
231
                   panel.widths = c(1.5,2.5,1.5,2.5,2))
232
233
234
##generating fish plot
235
f<- generateFishplotInputs(results = res)
236
fishes=createFishPlotObjects(f)
237
238
samples2<-samples1<-c("P10_1\nPretreat_1\nLN_left_breast","P10_2\nPretreat_2\nLN_right_inguinal")
239
240
241
pdf('./clonevol/P10/P10_fish_200x_pyclone_anno_loc.pdf', width=14, height=7)
242
for (i in 1:length(fishes)){
243
  
244
  fish = layoutClones(fishes[[i]])
245
  fish = setCol(fish,f$clonevol.clone.colors)
246
  fishPlot(fish,shape="spline", title.btm="P1", cex.title=0.7,cex.vlab = 1.4,
247
           vlines=seq(1, length(samples2)), vlab=samples2, pad.left=0.5)
248
}
249
dev.off()
250
251
252
253
pdf("./clonevol/P10/P10_box.pdf", width=3, height=3,useDingbats = FALSE, title='')
254
pp<-plot.variant.clusters(vafs_used,
255
                          cluster.col.name = 'cluster',
256
                          show.cluster.size = FALSE,
257
                          cluster.size.text.color = 'blue',
258
                          vaf.col.names = samples,
259
                          vaf.limits = 70,
260
                          sample.title.size = 20,
261
                          violin = FALSE,
262
                          box = FALSE,
263
                          jitter = TRUE,
264
                          jitter.shape = 1,
265
                          
266
                          jitter.size = 3,
267
                          jitter.alpha = 1,
268
                          jitter.center.method = 'median',
269
                          jitter.center.size = 1,
270
                          jitter.center.color = 'darkgray',
271
                          jitter.center.display.value = 'none',
272
                          highlight = 'is.driver',
273
                          highlight.shape = 21,
274
                          highlight.color = 'blue',
275
                          highlight.fill.color = 'green',
276
                          highlight.note.col.name = 'gene',
277
                          highlight.note.size = 2,
278
                          order.by.total.vaf = FALSE)
279
280
dev.off()
281
282
283
plot.pairwise(vafs_used, col.names = samples,
284
              out.prefix = './clonevol/P10/P10_variants.pairwise.plot')
285
286
287
pdf('./clonevol/P10/P10_flow.pdf')
288
plot.cluster.flow(vafs_used, vaf.col.names = samples,
289
                  sample.names = c('Pretreat1', 'Pretreat'))
290
dev.off()
291
292
293
####checking coverage f
294
295
296
297
P10_1<- read.table(file="input_pyclone_271018_newpara/200X/GCF0150-0010-N01_200X/GCF0150-0010-T01.txt",sep="\t",header=T)
298
P10_2<- read.table(file="input_pyclone_271018_newpara/200X/GCF0150-0010-N01_200X/GCF0150-0010-T02.txt",sep="\t",header=T)
299
Pcase<- rbind(P10_1, P10_2)
300
301
302
303
########
304
#min (dp) =min(c1inP4_1$var_counts+c1inP4_1$ref_counts)=273
305
306
#max (dp) =max(c1inP4_1$var_counts+c1inP4_1$ref_counts)=648
307
#median (dp) =median(c1inP4_1$var_counts+c1inP4_1$ref_counts)=380
308
#mean (dp) =mean(c1inP4_1$var_counts+c1inP4_1$ref_counts)=417
309
310
library(ggplot2)
311
312
313
314
pdf("clonevol/P10/coverage.pdf")
315
ggplot(Pcase, aes(x=var_counts+ref_counts, fill=sample))+geom_histogram()
316
317
dev.off()
318
319
320
321
ggplot(vafs_used, aes(x=vafs_used$cluster, y=P10_1, group=cluster))+geom_violin()