Switch to unified view

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