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