6
|
1 #!/usr/bin/Rscript
|
|
2
|
|
3 #-----------------------------------#
|
|
4 # Author: Maude #
|
|
5 # Script: somaticSignature_Galaxy.r #
|
|
6 # Last update: 29/07/15 #
|
|
7 #-----------------------------------#
|
|
8
|
|
9
|
|
10 #########################################################################################################################################
|
|
11 # Run NMF algorithm and represent the composition of somatic signatures and the contribution in each samples #
|
|
12 #########################################################################################################################################
|
|
13
|
|
14 #-------------------------------------------------------------------------------
|
|
15 # Load library for recovering the arguments
|
|
16 #-------------------------------------------------------------------------------
|
|
17 suppressMessages(suppressWarnings(require("getopt")))
|
|
18
|
|
19
|
|
20 #-------------------------------------------------------------------------------
|
|
21 # Recover the arguments
|
|
22 #-------------------------------------------------------------------------------
|
|
23 spec = matrix(c(
|
|
24 "input" , "i", 1, "character",
|
|
25 "nbSignature", "nbSign", 1, "integer",
|
|
26 "cpu", "cpu", 1, "integer",
|
|
27 "output", "o", 1, "character",
|
|
28 "help", "h", 0, "logical"
|
|
29 ),
|
|
30 byrow=TRUE, ncol=4
|
|
31 )
|
|
32
|
|
33 opt = getopt(spec);
|
|
34
|
|
35 # No argument is pass to the command line
|
|
36 if(length(opt) == 1)
|
|
37 {
|
|
38 cat(paste("Usage:\n somaticSignature_Galaxy.r --input <matrix> --nbSignature <nbSign> --cpu <cpu> --output <outputdir>\n",sep=""))
|
|
39 q(status=1)
|
|
40 }
|
|
41
|
|
42 # Help was asked for.
|
|
43 if ( !is.null(opt$help) )
|
|
44 {
|
|
45 # print a friendly message and exit with a non-zero error code
|
|
46 cat(paste("Usage:\n somaticSignature_Galaxy.r --input <matrix> --nbSignature <nbSign> --cpu <cpu> --output <outputdir>\n",sep=""))
|
|
47 q(status=1)
|
|
48 }
|
|
49
|
|
50
|
|
51
|
|
52 #-------------------------------------------------------------------------------
|
|
53 # Load library
|
|
54 #-------------------------------------------------------------------------------
|
|
55 suppressMessages(suppressWarnings(library(NMF)))
|
|
56 suppressMessages(suppressWarnings(library(ggplot2)))
|
|
57 suppressMessages(suppressWarnings(library(reshape)))
|
|
58 suppressMessages(suppressWarnings(library(grid)))
|
|
59 suppressMessages(suppressWarnings(library(scales))) # Set the maximum value to the y axis (graph composition somatic signature)
|
|
60 suppressMessages(suppressWarnings(library(gridExtra))) # function "unit"
|
|
61
|
|
62
|
|
63
|
|
64 ###############################################################################
|
|
65 # Load the functions #
|
|
66 ###############################################################################
|
|
67
|
|
68 #-------------------------------------------------------------------------------
|
|
69 # Set the font depending on X11 availability
|
|
70 #-------------------------------------------------------------------------------
|
|
71 font <- ""
|
|
72 # Check the device available
|
|
73 device <- capabilities()
|
|
74 # X11 is available
|
|
75 if(device[5]) { font <- "Helvetica" } else { font <- "Helvetica-Narrow" }
|
|
76
|
|
77 #-------------------------------------------------------------------------------
|
|
78 # My own theme
|
|
79 #-------------------------------------------------------------------------------
|
|
80 theme_custom <- function(base_size = 4, base_family = "")
|
|
81 {
|
|
82 # Starts with theme_grey and then modify some parts
|
|
83 theme_grey(base_size = base_size, base_family = base_family) %+replace%
|
|
84 theme(
|
|
85 axis.text = element_text(size = rel(0.8), family=font),
|
|
86 axis.ticks = element_line(colour = "black", size=.2),
|
|
87 axis.line = element_line(colour = "black", size = .2),
|
|
88 axis.ticks.length= unit(.05, "cm"),
|
|
89 axis.ticks.margin= unit(.05, "cm"), # space between tick mark and tick label (‘unit’)
|
|
90 legend.key.size = unit(.2, "cm"),
|
|
91 legend.margin = unit(-.5, "cm"),
|
|
92 panel.background = element_blank(),
|
|
93 panel.border = element_blank(),
|
|
94 panel.grid.major = element_blank(),
|
|
95 panel.grid.minor = element_blank(),
|
|
96 strip.text.y = element_text(size = 3)
|
|
97 )
|
|
98 }
|
|
99
|
|
100 #-------------------------------------------------------------------------------
|
|
101 # Customize the theme for adding a y axis
|
|
102 #-------------------------------------------------------------------------------
|
|
103 mytheme <- theme_custom()
|
|
104 mytheme$axis.line.x <- mytheme$axis.line.y <- mytheme$axis.line
|
|
105 mytheme$axis.line.x$colour <- 'white'
|
|
106
|
|
107 #-------------------------------------------------------------------------------
|
|
108 # Replace the signature number by alphabet letter
|
|
109 #-------------------------------------------------------------------------------
|
|
110 ConvertNb2Aphabet <- function(c)
|
|
111 {
|
|
112 if(c == "row1" || c == "col1") { c <- "A" } else
|
|
113 if(c == "row2" || c == "col2") { c <- "B"} else
|
|
114 if(c == "row3" || c == "col3") { c <- "C"} else
|
|
115 if(c == "row4" || c == "col4") { c <- "D"} else
|
|
116 if(c == "row5" || c == "col5") { c <- "E"} else
|
|
117 if(c == "row6" || c == "col6") { c <- "F"} else
|
|
118 if(c == "row7" || c == "col7") { c <- "G"} else
|
|
119 if(c == "row8" || c == "col8") { c <- "H"} else
|
|
120 if(c == "row9" || c == "col9") { c <- "I"} else
|
|
121 if(c == "row10" || c == "col10") { c <- "J"} else
|
|
122 if(c == "row11" || c == "col11") { c <- "K"} else
|
|
123 if(c == "row12" || c == "col12") { c <- "L"} else
|
|
124 if(c == "row13" || c == "col13") { c <- "M"} else
|
|
125 if(c == "row14" || c == "col14") { c <- "N"} else
|
|
126 if(c == "row15" || c == "col15") { c <- "O"} else
|
|
127 if(c == "row16" || c == "col16") { c <- "P"} else
|
|
128 if(c == "row17" || c == "col17") { c <- "Q"} else
|
|
129 if(c == "row18" || c == "col18") { c <- "R"} else
|
|
130 if(c == "row19" || c == "col19") { c <- "S"} else
|
|
131 if(c == "row20" || c == "col20") { c <- "T"} else
|
|
132 if(c == "row21" || c == "col21") { c <- "U"} else
|
|
133 if(c == "row22" || c == "col22") { c <- "V"} else
|
|
134 if(c == "row23" || c == "col23") { c <- "W"} else
|
|
135 if(c == "row24" || c == "col24") { c <- "X"} else
|
|
136 if(c == "row25" || c == "col25") { c <- "Y"} else
|
|
137 if(c == "row26" || c == "col26") { c <- "Z"} else { c <- c }
|
|
138 }
|
|
139
|
|
140 #-------------------------------------------------------------------------------
|
|
141 # Check the file doesn't have lines equal to zero
|
|
142 #-------------------------------------------------------------------------------
|
|
143 CheckFile <- function(rowsum, dataFrame, x)
|
|
144 {
|
|
145 if(rowsum == 0)
|
|
146 {
|
|
147 write("\n\nERROR: There is not enough mutations for running NMF!!!", stderr())
|
|
148 write(paste0("Input matrix contains at least one null row ", rownames(dataFrame)[x], "\n\n"), stderr())
|
|
149 stop()
|
|
150 }
|
|
151 }
|
|
152
|
|
153 #-------------------------------------------------------------------------------
|
|
154 # Contribution to Signature as the number of SBS per sample
|
|
155 #-------------------------------------------------------------------------------
|
|
156 Contri2SignSBS <- function(Total_SBS, Percent)
|
|
157 {
|
|
158 Total_SBS*Percent/100
|
|
159 }
|
|
160
|
|
161 #-------------------------------------------------------------------------------
|
|
162 # Combined two plots and share the legend
|
|
163 #-------------------------------------------------------------------------------
|
|
164 grid_arrange_shared_legend <- function(...)
|
|
165 {
|
|
166 plots <- list(...)
|
|
167 g <- ggplotGrob(plots[[1]] + theme(legend.position="bottom"))$grobs
|
|
168 legend <- g[[which(sapply(g, function(x) x$name) == "guide-box")]]
|
|
169 lheight <- sum(legend$height)
|
|
170 grid.arrange(
|
|
171 do.call(arrangeGrob, lapply(plots, function(x)
|
|
172 x + theme(legend.position="none"))),
|
|
173 legend,
|
|
174 ncol = 1,
|
|
175 heights = unit.c(unit(1, "npc") - lheight, lheight))
|
|
176 }
|
|
177
|
|
178 #-------------------------------------------------------------------------------
|
|
179 # Calculate the mean of each signatures in each cluster
|
|
180 #-------------------------------------------------------------------------------
|
|
181 meanCluster <- function(df)
|
|
182 {
|
|
183 max <- opt$nbSignature+1
|
|
184 sapply(2:max, function(x) { round(mean(as.numeric(as.matrix(df[,x]))), 2) } )
|
|
185 }
|
|
186
|
|
187
|
|
188
|
|
189
|
|
190 ###############################################################################
|
|
191 # Check file #
|
|
192 ###############################################################################
|
|
193
|
|
194 # The input musn't contains lines equal to zero !!!
|
|
195 matrixNMF <- read.table(opt$input, header=T)
|
|
196 # suppresses the return of sapply function
|
|
197 invisible( sapply(1:nrow(matrixNMF), function(x) { CheckFile(rowSums(matrixNMF)[x], matrixNMF, x) } ) )
|
|
198
|
|
199
|
|
200
|
|
201 ###############################################################################
|
|
202 # Run NMF #
|
|
203 ###############################################################################
|
|
204
|
|
205 # Create the output directories
|
|
206 output_NMF <- paste0(opt$output, "/NMF")
|
|
207 dir.create(output_NMF)
|
|
208 output_Figures <- paste0(output_NMF, "/", "Figures")
|
|
209 dir.create(output_Figures)
|
|
210 output_Files <- paste0(output_NMF, "/", "Files")
|
|
211 dir.create(output_Files)
|
|
212
|
|
213 # Define the output filenames
|
|
214 output_cluster <- paste0(output_Files, "/", "Cluster_MixtureCoeff.txt")
|
|
215 figure_cluster <- paste0(output_Figures, "/", "Heatmap_MixtureCoeff.png")
|
|
216 output_matrixW <- paste0(output_Files, "/", "MatrixW-Normto100.txt")
|
|
217 output_matrixW_ggplot2 <- paste0(output_Files, "/", "MatrixW-Inputggplot2.txt")
|
|
218 output_matrixH_ggplot2 <- paste0(output_Files, "/", "MatrixH-Inputggplot2.txt")
|
|
219 output_matrixH_cluster <- paste0(output_Files, "/", "Average_ContriByCluster.txt")
|
|
220 figure_matrixW_png <- paste0(output_Figures, "/", "CompositionSomaticMutation.png")
|
|
221 figure_matrixH_png <- paste0(output_Figures, "/", "ContributionMutationSignature.png")
|
|
222 figure_matrixH_cluster <- paste0(output_Figures, "/", "Average_ContriByCluster.png")
|
|
223
|
|
224
|
|
225 # Run NMF
|
|
226 # request a certain number of cores to use .opt="vP4"
|
|
227 nbCPU <- paste0("vP", opt$cpu)
|
|
228 res <- nmf(matrixNMF, opt$nbSignature, "brunet", nrun=200, .opt=nbCPU)
|
|
229
|
|
230 # If there is more than 300 samples the creation of the heatmap returns an error
|
|
231 if(ncol(matrixNMF) <= 300)
|
|
232 {
|
|
233 # Save the clustered heatmap generated by NMF
|
|
234 graphics.off() # close graphics windows
|
|
235 options(bitmapType='cairo')
|
|
236 png(figure_cluster)
|
|
237 coefmap(res, Colv="consensus")
|
|
238 dev.off()
|
|
239 }
|
|
240
|
|
241 # Recover the matrix W and H
|
|
242 matrixW <- basis(res)
|
|
243 matrixH <- coef(res)
|
|
244
|
|
245 # Recover the cluster of the samples
|
|
246 matrix_cluster <- cbind(as.numeric(predict(res, what="samples")), colnames(matrixNMF))
|
|
247 colnames(matrix_cluster) <- c("Cluster", "Samples")
|
|
248
|
|
249 ## Save the cluster matrix
|
|
250 write.table(matrix_cluster, file=output_cluster, quote=F, sep="\t", col.names=T, row.names=F)
|
|
251
|
|
252
|
|
253
|
|
254 ###############################################################################
|
|
255 # Composition of somatic signatures #
|
|
256 ###############################################################################
|
|
257
|
|
258 # Normalize to 100%
|
|
259 matrixW_norm <- t((t(matrixW)/colSums(matrixW))*100)
|
|
260 # Add a column name
|
|
261 colnames(matrixW_norm) <- colnames(matrixW_norm, do.NULL = FALSE, prefix = "col")
|
|
262 # Replace the name of the columns by the signature name
|
|
263 colnames(matrixW_norm) <- sapply(1:length(colnames(matrixW_norm)), function(x) { ConvertNb2Aphabet(colnames(matrixW_norm)[x]) } )
|
|
264
|
|
265 # Split the sequence context from the mutation type
|
|
266 context <- c() # Create an empty vector for the sequence context
|
|
267 alteration <- c() # Create an empty vector for the mutation type
|
|
268 for(i in 1:nrow(matrixW_norm))
|
|
269 {
|
|
270 temp <- strsplit((strsplit(rownames(matrixW_norm)[i], ""))[[1]], "")
|
|
271
|
|
272 context[i] <- paste0(temp[1], "_", temp[7])
|
|
273 alteration[i] <- paste0(temp[3], temp[4], temp[5])
|
|
274 }
|
|
275
|
|
276 # Melt the matrix using the signatures as variable
|
|
277 matrixW_melt <- melt(matrixW_norm)
|
|
278
|
|
279 # Add columns for the mutation type and the sequence context
|
|
280 matrixW_norm <- cbind(matrixW_norm, alteration, context)
|
|
281 # Reorder (alteration) for having the same order as in the matrice of published signatures
|
|
282 matrixW_norm <- matrixW_norm[order(matrixW_norm[,"alteration"], matrixW_norm[,"context"]), ]
|
|
283 # Reorder (columns) for having the same order as in the matrice of published signatures
|
|
284 matrixW_norm <- cbind(matrixW_norm[,c("alteration", "context")], matrixW_norm[,1:(ncol(matrixW_norm)-2)]) # Put the column alteration and context at the begining
|
|
285 # Save the matrix
|
|
286 write.table(matrixW_norm, file=output_matrixW, quote=F, sep="\t", col.names=T, row.names=F)
|
|
287
|
|
288 # Add columns for the mutation type and the sequence context
|
|
289 matrixW_melt <- cbind(matrixW_melt, alteration)
|
|
290 matrixW_melt <- cbind(matrixW_melt, context)
|
|
291 # Rename the columns
|
|
292 colnames(matrixW_melt) <- c("", "Signature", "value", "alteration", "context")
|
|
293
|
|
294 # Save the input for ggplot2
|
|
295 input_ggplot2 <- as.matrix(matrixW_melt)
|
|
296 input_ggplot2 <- input_ggplot2[,2:ncol(input_ggplot2)]
|
|
297 write.table(input_ggplot2, file=output_matrixW_ggplot2, quote=F, sep="\t", col.names=T, row.names=F)
|
|
298
|
|
299 # Maximum value of the y axis
|
|
300 max_matrixW <- as.numeric(max(matrixW_melt$value))
|
|
301
|
|
302
|
|
303 # Base plot
|
|
304 p <- ggplot(matrixW_melt, aes(x=context, y=value, fill=alteration)) + geom_bar(stat="identity", width=0.5) + facet_grid(Signature ~ alteration, scales="free_y")
|
|
305 # Color the mutation types
|
|
306 p <- p + scale_fill_manual(values=c("blue", "black", "red", "#828282", "#00CC33", "pink"))
|
|
307 # Remove the legend
|
|
308 p <- p + guides(fill=FALSE)
|
|
309 # Customized theme (no background, no facet grid and strip, y axis only)
|
|
310 p <- p + mytheme
|
|
311 # Remove the title of the x facet strip
|
|
312 p <- p + theme(strip.text.x=element_blank())
|
|
313 # Remove the x axis ticks and title
|
|
314 p <- p + theme(axis.title.x=element_blank(), axis.ticks.x = element_blank(), axis.title.y=element_text(size=5))
|
|
315 # Rename the y axis
|
|
316 p <- p + ylab("% contribution to signatures")
|
|
317 # Set the maximum value of the y axis to the maximum value of the matrix W
|
|
318 p <- p + scale_y_continuous(limits=c(0,max_matrixW), oob=squish, breaks=c(0,round(max_matrixW)))
|
|
319 # Save some space for adding the sequence context at the bottom
|
|
320 p <- p + theme(plot.margin=unit(c(.3, 0, 0, 0), "cm"))
|
|
321 p <- p + scale_x_discrete(breaks = c("A_A","A_C","A_G","A_T", "C_A","C_C","C_G","C_T", "G_A","G_C","G_G","G_T", "T_A","T_C","T_G","T_T"),
|
|
322 labels =c('A\nA',"\nC","\nG","\nT", 'C\nA',"\nC","\nG","\nT",
|
|
323 'G\nA',"\nC","\nG","\nT", 'T\nA',"\nC","\nG","\nT")
|
|
324 )
|
|
325
|
|
326
|
|
327 #------------------------------------------------------------------------------------------------------------------------------
|
|
328 # Change the color of the facets for the mutation type
|
|
329 #------------------------------------------------------------------------------------------------------------------------------
|
|
330 cols <- rep( c("blue", "black", "red", "#828282", "#00CC33", "pink")) # Facet strip colours
|
|
331
|
|
332 # Make a grob object
|
|
333 Pg <- ggplotGrob(p)
|
|
334 # To keep track of strip.background grobs
|
|
335 idx <- 0
|
|
336 # Find each strip.background and alter its backround colour
|
|
337 for( g in 1:length(Pg$grobs) )
|
|
338 {
|
|
339 if( grepl( "strip.absoluteGrob" , Pg$grobs[[g]]$name ) )
|
|
340 {
|
|
341 idx <- idx + 1
|
|
342 sb <- which( grepl( "strip\\.background" , names( Pg$grobs[[g]]$children ) ) )
|
|
343 Pg$grobs[[g]]$children[[sb]][]$gp$fill <- cols[idx]
|
|
344 }
|
|
345 }
|
|
346
|
|
347 # Reduce the size of the facet strip
|
|
348 Pg$heights[[3]] = unit(.05,"cm")
|
|
349
|
|
350
|
|
351 #------------------------------------------------------------------------------------------------------------------------------
|
|
352 # Save the graph in a png file
|
|
353 #------------------------------------------------------------------------------------------------------------------------------
|
|
354 options(bitmapType='cairo')
|
|
355 png(figure_matrixW_png, width=1300, heigh=500, res=300, pointsize = 4)
|
|
356 plot(Pg)
|
|
357 ## Add label for the mutation type above the strip facet
|
|
358 grid.text(0.12, unit(1,"npc") - unit(1.4,"line"), label="C>A")
|
|
359 grid.text(0.27, unit(1,"npc") - unit(1.4,"line"), label="C>G")
|
|
360 grid.text(0.42, unit(1,"npc") - unit(1.4,"line"), label="C>T")
|
|
361 grid.text(0.58, unit(1,"npc") - unit(1.4,"line"), label="T>A")
|
|
362 grid.text(0.74, unit(1,"npc") - unit(1.4,"line"), label="T>C")
|
|
363 grid.text(0.89, unit(1,"npc") - unit(1.4,"line"), label="T>G")
|
|
364 invisible( dev.off() )
|
|
365
|
|
366
|
|
367
|
|
368 ###############################################################################
|
|
369 # Contribution of mutational signature in each samples #
|
|
370 ###############################################################################
|
|
371
|
|
372 # Recover the total number of SBS per samples
|
|
373 NbSBS <- colSums(matrixNMF)
|
|
374 # Normalized matrix H to 100%
|
|
375 matrixH_norm <- t((t(matrixH)/colSums(matrixH))*100)
|
|
376 # Add a row name
|
|
377 rownames(matrixH_norm) <- rownames(matrixH_norm, do.NULL = FALSE, prefix = "row")
|
|
378 # Replace the signature number by letter
|
|
379 rownames(matrixH_norm) <- sapply(1:length(rownames(matrixH_norm)), function(x) { ConvertNb2Aphabet(rownames(matrixH_norm)[x]) } )
|
|
380
|
|
381 ## Combined the contribution with the total number of SBS
|
|
382 matrixH_norm_melt <- melt(matrixH_norm)
|
|
383 matrixH_norm_melt <- cbind(matrixH_norm_melt, rep(NbSBS, each = opt$nbSignature))
|
|
384 colnames(matrixH_norm_melt) <- c("Signature", "Sample", "Value", "Total_SBS")
|
|
385
|
|
386 # Calculate the contribution in number of SBS
|
|
387 matrixH_norm_melt$ContriSBS <- sapply(1:nrow(matrixH_norm_melt), function(x) { Contri2SignSBS(matrixH_norm_melt$Total_SBS[x], matrixH_norm_melt$Value[x]) } )
|
|
388
|
|
389
|
|
390 # Save the matrix
|
|
391 write.table(matrixH_norm_melt, file=output_matrixH_ggplot2, quote=F, sep="\t", col.names=T, row.names=F)
|
|
392
|
|
393 # Base plot for the contribution of each samples according the count of mutations
|
|
394 p2 <- ggplot(matrixH_norm_melt, aes(x=reorder(Sample, -ContriSBS), y=ContriSBS, fill=Signature)) + geom_bar(stat="identity") + theme_classic()
|
|
395 # Remove the name of samples
|
|
396 p2 <- p2 + theme(axis.text.x = element_blank())
|
|
397 # Reverse the y axis
|
|
398 p2 <- p2 + scale_y_reverse()
|
|
399 # Rename the y and x axis
|
|
400 p2 <- p2 + ylab("Number of mutations") + xlab("Samples")
|
|
401 # Remove the x axis line
|
|
402 p2 <- p2 + theme(axis.line.x=element_blank())
|
|
403
|
|
404 # Base plot for the contribution of each samples in percentages
|
|
405 p3 <- ggplot(matrixH_norm_melt, aes(x=reorder(Sample, -ContriSBS), y=Value, fill=Signature)) + geom_bar(stat="identity") + theme_classic() + theme(axis.text.x = element_blank()) + xlab("") + ylab("% of mutations")
|
|
406 # Remove the x axis line
|
|
407 p3 <- p3 + theme(axis.line.x=element_blank(), axis.ticks.x=element_blank())
|
|
408
|
|
409
|
|
410 # Plot PNG
|
|
411 png(figure_matrixH_png, width=3000, heigh=2000, res=300)
|
|
412 # Combined the two plots for the contribution of the samples
|
|
413 suppressWarnings( grid_arrange_shared_legend(p3, p2) )
|
|
414 invisible( dev.off() )
|
|
415
|
|
416
|
|
417 ###############################################################################
|
|
418 # Average contributions of each signature in each cluster #
|
|
419 ###############################################################################
|
|
420
|
|
421 matrixH_cluster <- cbind(matrix_cluster[,1], t(matrixH_norm))
|
|
422 colnames(matrixH_cluster) <- c("Cluster", colnames(t(matrixH_norm)))
|
|
423
|
|
424 df <- as.data.frame(matrixH_cluster)
|
|
425
|
|
426 tmp_mat <- sapply(1:opt$nbSignature, function(x) { meanCluster(df[df[,1] == x,]) } )
|
|
427 # Add a name for the row and the col
|
|
428 rownames(tmp_mat) <- sapply(1:opt$nbSignature, function(x) { paste0("Sig. ", x) } )
|
|
429 colnames(tmp_mat) <- sapply(1:opt$nbSignature, function(x) { paste0("Cluster ", x) } )
|
|
430 tmp_mat <- t(tmp_mat)
|
|
431 # Recover the number of samples in each cluster
|
|
432 nbSampleByCluster <- sapply(1:opt$nbSignature, function(x) { as.numeric( strsplit( as.character(dim(df[df[,1] == x,])), " " ) ) } )
|
|
433 # Combined the average contribution and the number of samples
|
|
434 tmp_mat <- cbind(tmp_mat, nbSampleByCluster[1,])
|
|
435 # Add a name for the row and the col
|
|
436 colnames(tmp_mat)[opt$nbSignature+1] <- "Number of samples"
|
|
437 # Save the matrix
|
|
438 write.table(tmp_mat, file=output_matrixH_cluster, quote=F, sep="\t", col.names=T, row.names=T)
|
|
439
|
|
440 ## Create an image of the table with ggplot2
|
|
441 # Dummy plot
|
|
442 p4 <- qplot(1:10, 1:10, geom = "blank") +
|
|
443 theme(panel.grid.major = element_blank(),
|
|
444 panel.grid.minor = element_blank(),
|
|
445 panel.border = element_rect(fill=NA,color="white", size=0.5, linetype="solid"),
|
|
446 axis.line = element_blank(),
|
|
447 axis.ticks = element_blank(),
|
|
448 panel.background = element_rect(fill="white"),
|
|
449 plot.background = element_rect(fill="white"),
|
|
450 legend.position = "none",
|
|
451 axis.text = element_blank(),
|
|
452 axis.title = element_blank()
|
|
453 )
|
|
454 # Adding a table
|
|
455 p4 <- p4 + annotation_custom(grob = tableGrob(tmp_mat),
|
|
456 xmin = 4, xmax = 7,
|
|
457 ymin = 0, ymax = 10)
|
|
458
|
|
459 # Save the table
|
|
460 png(figure_matrixH_cluster, width=2500, heigh=1000, res=300)
|
|
461 # Combined the two plots for the contribution of the samples
|
|
462 plot(p4)
|
|
463 invisible( dev.off() )
|
|
464
|
|
465
|
|
466 # Delete the empty plot created by the script
|
|
467 if (file.exists("Rplots.pdf")) invisible( file.remove("Rplots.pdf") )
|