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