Switch to unified view

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