-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 19.1 KB
/
.Rhistory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
combined_plot <- pc3 + pc4 + plot_layout(nrow = 2)
combined_plot
pc3 <- plot_contribution(nmf_res$contribution,
nmf_res$signatures,
mode="relative",
coord_flip = TRUE)
pc4 <- plot_contribution(nmf_res$contribution,
nmf_res$signatures,
mode="absolute",
coord_flip = TRUE)
combined_plot <- pc3 + pc4 + plot_layout(nrow = 2)
ggsave("figures/signature_contribution_flipped.png", dpi = 300)
# Heatmaps
plot_contribution_heatmap(nmf_res$contribution, sig_order = c("Signature A", "Signature B"))
plot_contribution_heatmap(nmf_res$contribution, cluster_samples = FALSE)
# GRID
pch1 <- plot_contribution_heatmap(nmf_res$contribution, sig_order = c("Signature A", "Signature B"))
pch2 <- plot_contribution_heatmap(nmf_res$contribution, cluster_samples = FALSE)
pch1
pch2
pch1 <- plot_contribution_heatmap(nmf_res$contribution, sig_order = c("Signature A", "Signature B"))
pch2 <- plot_contribution_heatmap(nmf_res$contribution, cluster_samples = FALSE)
combined_plot <- pch1 + pch2 + plot_layout(nrow = 2)
combined_plot
combined_plot <- pch1 + pch2 + plot_layout(ncol = 2)
ggsave("figures/signature_contribution_flipped.png", dpi = 300)
combined_plot
# Contribution of Signatures in a bar plot
pc1 <- plot_contribution(nmf_res$contribution,
nmf_res$signatures,
mode = "relative") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
pc2 <- plot_contribution(nmf_res$contribution,
nmf_res$signatures,
mode = "absolute") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
# Combine plots using patchwork
pc1 + pc2 + plot_layout(nrow = 2)
ggsave("figures/signature_contribution.png", dpi = 300)
# Flip X and Y coordinates
pc3 <- plot_contribution(nmf_res$contribution,
nmf_res$signatures,
mode="relative",
coord_flip = TRUE)
pc4 <- plot_contribution(nmf_res$contribution,
nmf_res$signatures,
mode="absolute",
coord_flip = TRUE)
pc3 + pc4 + plot_layout(nrow = 2)
ggsave("figures/signature_contribution_flipped.png", dpi = 300)
pch1 <- plot_contribution_heatmap(nmf_res$contribution, sig_order = c("Signature A", "Signature B"))
pch2 <- plot_contribution_heatmap(nmf_res$contribution, cluster_samples = FALSE)
pch1 + pch2 + plot_layout(ncol = 2)
pch1 + pch2 + plot_layout(ncol = 2)
pch1 <- plot_contribution_heatmap(nmf_res$contribution, sig_order = c("Signature A", "Signature B"))
pch2 <- plot_contribution_heatmap(nmf_res$contribution, cluster_samples = FALSE)
pch1 + pch2 + plot_layout(ncol = 2)
ggsave("figures/signature_contribution_heatmap.png", dpi = 300)
# GRID
pch1 <- plot_contribution_heatmap(nmf_res$contribution, sig_order = c("Signature A", "Signature B"))
pch2 <- plot_contribution_heatmap(nmf_res$contribution, cluster_samples = FALSE)
pch1 + pch2 + plot_layout(nrow = 2)
ggsave("figures/signature_contribution_heatmap.png", dpi = 300)
# Compare reconstructed mutational profile with original mutational profile
plot_compare_profiles(mut_mat[,1],
nmf_res$reconstructed[,1],
profile_names = c("Original", "Reconstructed"),
condensed = TRUE)
# Compare reconstructed mutational profile with original mutational profile
plot_compare_profiles(mut_mat[,1],
nmf_res$reconstructed[,1],
profile_names = c("Original", "Reconstructed"),
condensed = TRUE)
ggsave("figures/profile_comparison.png", dpi = 300)
# Cosmic Mutational Signatures
sp_url <- paste("https://cancer.sanger.ac.uk/cancergenome/assets/signatures_probabilities.txt", sep = " ")
cancer_signatures = read.table(sp_url, sep = "\t", header = TRUE)
# Match the order of the mutation types to MutationalPatterns standardnew_order = match(row.names(mut_mat), cancer_signatures$Somatic.Mutation.Type)
# Reorder cancer signatures dataframe
new_order = match(row.names(mut_mat), cancer_signatures$Somatic.Mutation.Type)
cancer_signatures = cancer_signatures[as.vector(new_order),]
# Add trinucletiode changes names as row.names
row.names(cancer_signatures) = cancer_signatures$Somatic.Mutation.Type
# Keep only 96 contributions of the signatures in matrix
cancer_signatures = as.matrix(cancer_signatures[,4:33])
# Plot mutational profile of the first two COSMIC signatures
plot_96_profile(cancer_signatures[,1:2], condensed = TRUE, ymax = 0.3)
# Plot mutational profile of the first two COSMIC signatures
plot_96_profile(cancer_signatures[,1:2], condensed = TRUE, ymax = 0.3)
ggsave("figures/cosmic_signatures.png", dpi = 300)
# Dendogram
hclust_cosmic = cluster_signatures(cancer_signatures, method = "average")
cosmic_order = colnames(cancer_signatures)[hclust_cosmic$order]
plot(hclust_cosmic)
cos_sim(mut_mat[,1], cancer_signatures[,1])
cos_sim_samples_signatures = cos_sim_matrix(mut_mat, cancer_signatures)
plot_cosine_heatmap(cos_sim_samples_signatures,
col_order = cosmic_order,
cluster_rows = TRUE)
# Dendogram
hclust_cosmic = cluster_signatures(cancer_signatures, method = "average")
cosmic_order = colnames(cancer_signatures)[hclust_cosmic$order]
plot(hclust_cosmic)
ggsave("figures/cosmic_dendrogram.png", dpi = 300)
# Dendogram
hclust_cosmic = cluster_signatures(cancer_signatures, method = "average")
cosmic_order = colnames(cancer_signatures)[hclust_cosmic$order]
plot(hclust_cosmic)
cos_sim(mut_mat[,1], cancer_signatures[,1])
cos_sim_samples_signatures = cos_sim_matrix(mut_mat, cancer_signatures)
plot_cosine_heatmap(cos_sim_samples_signatures,
col_order = cosmic_order,
cluster_rows = TRUE)
cos_sim(mut_mat[,1], cancer_signatures[,1])
cos_sim_samples_signatures = cos_sim_matrix(mut_mat, cancer_signatures)
plot_cosine_heatmap(cos_sim_samples_signatures,
col_order = cosmic_order,
cluster_rows = TRUE)
ggsave("figures/cosine_similarity_heatmap.png", dpi = 300)
# Load Packages
library(BSgenome) # for available ref-genome
library(MutationalPatterns) # for mutational signature analysis
library(NMF) # for non-negative matrix factorization(NMF or NNMF)
library(gridExtra) # for managing plots and grid system
library("TxDb.Hsapiens.UCSC.hg19.knownGene")
BiocManager::install("TxDb.Hsapiens.UCSC.hg19.knownGene")
# List vailable genomes
head(available.genomes())
# Load data
ref_genome <- "BSgenome.Hsapiens.UCSC.hg19"
library(ref_genome, character.only = TRUE)
# Store VCF Files into vcf_files[vcf=variant call format]
vcf_files <- list.files(system.file("extdata", package = "MutationalPatterns"), pattern = ".vcf", full.names = TRUE)
vcf_files
# Extract sample names from file paths
sample_names <- gsub("\\.vcf$", "", basename(vcf_files))
sample_names
# Load VCF files into GRanges[vcf_files, sample_names, ref_genome]
vcfs <- read_vcfs_as_granges(vcf_files, sample_names, ref_genome)
# Set tissue type [came from vcf_files]
tissue <- c(rep("colon", 3), rep("intestine", 3), rep("liver", 3))
sample_names
# Load VCF files into GRanges[vcf_files, sample_names, ref_genome]
vcfs <- read_vcfs_as_granges(vcf_files, sample_names, ref_genome)
# Load Genes
genes_hg19 <- genes(TxDb.Hsapiens.UCSC.hg19.knownGene)
library("TxDb.Hsapiens.UCSC.hg19.knownGene")
genes(TxDb.Hsapiens.UCSC.hg19.knownGene)
# Load Genes
genes_hg19 <- genes(TxDb.Hsapiens.UCSC.hg19.knownGene)
genes_hg19
# Mutation Strand
strand = mut_strand(vcfs[[1]], genes_hg19)
head(strand, 10)
# Transcriptional strand bias analysis
# Mutation Strand Matrix
mut_mat_strand <- mut_matrix_stranded(vcfs, ref_genome, genes_hg19)
# Matrix Indexing
mut_mat_strand[1:5, 1:5]
# Starin Counts
strand_counts <- strand_occurrences(mut_mat_strand, by=tissue)
head(strand_counts)
# Strain Bias
strand_bias <- strand_bias_test(strand_counts)
# 1.2.3 Pan-cancer gene expression and immune-related genes correlation
# Load required packages
library(TCGAplot)
library(tidyverse)
# Input your gene symbol
gene <- "PIK3R1"
# Define color gradients
lowcol <- "#3182bd"
highcol <- "#f03b20"
# 1.2.3.1 Pan-cancer gene expression and ICGs correlation
gene_checkpoint_heatmap <- gene_checkpoint_heatmap(
gene,
method = "pearson",
lowcol = lowcol,
highcol = highcol,
cluster_row = TRUE,
cluster_col = TRUE,
legend = TRUE
)
ggsave(
filename = paste0("figures/06_icg_correlation/",gene, "_icg_correlation.png"),
plot = gene_checkpoint_heatmap,
width = 8,
height = 4,
dpi = 300
)
# 1.2.3.3 Pan-cancer gene expression and Chemokine receptor correlation
gene_receptor_heatmap <- gene_receptor_heatmap(
gene,
method = "pearson",
lowcol = lowcol,
highcol = highcol,
cluster_row = TRUE,
cluster_col = TRUE,
legend = TRUE
)
ggsave(
filename = paste0("figures/08_chemokine_receptor_correlation/", gene, "_chemokine_receptor_correlation.png"),
plot = gene_receptor_heatmap,
width = 8,
height = 5,
dpi = 300
)
# 1.2.3.4 Pan-cancer gene expression and Immune stimulator correlation
gene_immustimulator_heatmap <- gene_immustimulator_heatmap(
gene,
method = "pearson",
lowcol = lowcol,
highcol = highcol,
cluster_row = TRUE,
cluster_col = TRUE,
legend = TRUE
)
ggsave(
filename = paste0("figures/09_immune_stimulator_correlation/", gene, "_immune_stimulator_correlation.png"),
plot = gene_immustimulator_heatmap,
width = 8,
height = 9,
dpi = 300
)
setwd("I:/dataviz-gallery/code/tcga_workflow")
# 1.2.3.3 Pan-cancer gene expression and Chemokine receptor correlation
gene_receptor_heatmap <- gene_receptor_heatmap(
gene,
method = "pearson",
lowcol = lowcol,
highcol = highcol,
cluster_row = TRUE,
cluster_col = TRUE,
legend = TRUE
)
ggsave(
filename = paste0("figures/08_chemokine_receptor_correlation/", gene, "_chemokine_receptor_correlation.png"),
plot = gene_receptor_heatmap,
width = 8,
height = 5,
dpi = 300
)
# 1.2.3.3 Pan-cancer gene expression and Chemokine receptor correlation
gene_receptor_heatmap <- gene_receptor_heatmap(
gene,
method = "pearson",
lowcol = lowcol,
highcol = highcol,
cluster_row = TRUE,
cluster_col = TRUE,
legend = TRUE
)
ggsave(
filename = paste0("figures/08_chemokine_receptor_correlation/", gene, "_chemokine_receptor_correlation.png"),
plot = gene_receptor_heatmap,
width = 8,
height = 5,
dpi = 300
)
# 1.2.3.4 Pan-cancer gene expression and Immune stimulator correlation
gene_immustimulator_heatmap <- gene_immustimulator_heatmap(
gene,
method = "pearson",
lowcol = lowcol,
highcol = highcol,
cluster_row = TRUE,
cluster_col = TRUE,
legend = TRUE
)
ggsave(
filename = paste0("figures/09_immune_stimulator_correlation/", gene, "_immune_stimulator_correlation.png"),
plot = gene_immustimulator_heatmap,
width = 8,
height = 9,
dpi = 300
)
setwd("I:/dataviz-gallery/code/biological_dataviz")
data <- read.csv("data/", sep="\t", header=TRUE)
data <- read.csv("data/micro_array_results_table1.txt", sep="\t", header=TRUE)
# Version info: R 4.2.2, Biobase 2.58.0, GEOquery 2.66.0, limma 3.54.0
################################################################
# Differential expression analysis with limma
library(GEOquery)
library(limma)
library(umap)
# load series and platform data from GEO
gset <- getGEO("GSE21942", GSEMatrix =TRUE, AnnotGPL=TRUE)
setwd("I:/dataviz-gallery/code/GEO2R")
# Version info: R 4.2.2, Biobase 2.58.0, GEOquery 2.66.0, limma 3.54.0
################################################################
# Differential expression analysis with limma
library(GEOquery)
library(limma)
library(umap)
# load series and platform data from GEO
gset <- getGEO("GSE21942", GSEMatrix =TRUE, AnnotGPL=TRUE)
if (length(gset) > 1) idx <- grep("GPL570", attr(gset, "names")) else idx <- 1
gset <- gset[[idx]]
# make proper column names to match toptable
fvarLabels(gset) <- make.names(fvarLabels(gset))
# group membership for all samples
gsms <- "00000000000000011111111111111"
sml <- strsplit(gsms, split="")[[1]]
# log2 transformation
ex <- exprs(gset)
qx <- as.numeric(quantile(ex, c(0., 0.25, 0.5, 0.75, 0.99, 1.0), na.rm=T))
LogC <- (qx[5] > 100) ||
(qx[6]-qx[1] > 50 && qx[2] > 0)
if (LogC) { ex[which(ex <= 0)] <- NaN
exprs(gset) <- log2(ex) }
# assign samples to groups and set up design matrix
gs <- factor(sml)
groups <- make.names(c("Control","MS"))
levels(gs) <- groups
gset$group <- gs
design <- model.matrix(~group + 0, gset)
colnames(design) <- levels(gs)
gset <- gset[complete.cases(exprs(gset)), ] # skip missing values
fit <- lmFit(gset, design) # fit linear model
# set up contrasts of interest and recalculate model coefficients
cts <- paste(groups[1], groups[2], sep="-")
cont.matrix <- makeContrasts(contrasts=cts, levels=design)
fit2 <- contrasts.fit(fit, cont.matrix)
# compute statistics and table of top significant genes
fit2 <- eBayes(fit2, 0.01)
tT <- topTable(fit2, adjust="fdr", sort.by="B", number=250)
tT <- subset(tT, select=c("ID","adj.P.Val","P.Value","t","B","logFC","GB_ACC","SPOT_ID","Gene.Symbol","Gene.symbol","Gene.title"))
fit2
tT
subset(tT, select=c("ID","adj.P.Val","P.Value","t","B","logFC","GB_ACC","SPOT_ID","Gene.Symbol","Gene.symbol","Gene.title"))
# Load series and platform data from GEO
gset <- getGEO("GSE21942", GSEMatrix = TRUE, AnnotGPL = TRUE) %>%
{if (length(.) > 1) .[[grep("GPL570", attr(., "names"))]] else .[[1]]}
# Load Packages
library(BSgenome) # for available ref-genome
library(MutationalPatterns) # for mutational signature analysis
library(NMF) # for non-negative matrix factorization(NMF or NNMF)
library(patchwork) # for managing plots and grid system
# List vailable genomes
head(available.genomes())
# Load data
ref_genome <- "BSgenome.Hsapiens.UCSC.hg19"
setwd("I:/dataviz-gallery/code/mutational_patterns")
# Load data
ref_genome <- "BSgenome.Hsapiens.UCSC.hg19"
library(ref_genome, character.only = TRUE)
# Store VCF Files into vcf_files[vcf=variant call format]
vcf_files <- list.files(system.file("extdata", package = "MutationalPatterns"), pattern = ".vcf", full.names = TRUE)
vcf_files
# Extract sample names from file paths
sample_names <- gsub("\\.vcf$", "", basename(vcf_files))
sample_names
# Load VCF files into GRanges[vcf_files, sample_names, ref_genome]
vcfs <- read_vcfs_as_granges(vcf_files, sample_names, ref_genome)
mut_mat <- mut_matrix(vcf_list=vcfs, ref_genome = ref_genome)
head(mut_mat)
mut_mat <- mut_mat + 0.0001
estimate <- nmf(mut_mat, rank=2:5, method = "brunet", nrun=10, seed=123456)
plot(estimate)
# Heatmap
consensusmap(estimate)
# Save the NMF heatmap
ggsave("figures/nmf_heatmap.png", dpi = 300)
# Heatmap
consensusmap(estimate)
# Save the NMF heatmap
ggsave("figures/nmf_heatmap.png", dpi = 300)
library(tidyverse)
# Save the NMF heatmap
ggsave("figures/nmf_heatmap.png", dpi = 300)
# Heatmap
consensusmap(estimate)
# Save the NMF heatmap
ggsave("figures/nmf_heatmap.png", dpi = 300)
# Heatmap
consensusmap(estimate)
plot(estimate)
# Save the NMF estimation plot
ggsave("figures/nmf_estimate.png", dpi = 300)
# Heatmap
consensusmap(estimate)
# Save the NMF heatmap
ggsave("figures/nmf_heatmap.png", dpi = 300)
consensusmap(estimate)
# Heatmap
nmf_heatmap <- consensusmap(estimate)
# Save the NMF heatmap
ggsave(nmf_heatmap, "figures/nmf_heatmap.png", dpi = 300)
# Heatmap
nmf_heatmap <- consensusmap(estimate)
# Save the NMF heatmap
ggsave("figures/nmf_heatmap.png", dpi = 300)
# Heatmap
consensusmap(estimate)
# Mutational Signatures Extraction
nmf_res <- extract_signatures(mut_mat, rank = 2, nrun=10)
colnames(nmf_res$signatures) <- c("Signature A", "Signature B")
rownames(nmf_res$contribution) <- c("Signature A", "Signature B")
plot_96_profile(nmf_res$signatures, condensed = TRUE)
# Save the mutational profiles
ggsave("figures/mutational_profiles.png", dpi = 300)
# Heatmap
consensusmap(estimate)
# Save the NMF heatmap
ggsave("figures/nmf_heatmap.png", dpi = 300)
# List vailable genomes
head(available.genomes())
# De novo mutational signature extraction using NMF
mut_mat <- mut_mat + 0.0001
# 96 Mutational Profile
mut_mat <- mut_matrix(vcf_list=vcfs, ref_genome = ref_genome)
# Store VCF Files into vcf_files[vcf=variant call format]
vcf_files <- list.files(system.file("extdata", package = "MutationalPatterns"), pattern = ".vcf", full.names = TRUE)
vcf_files
# Extract sample names from file paths
sample_names <- gsub("\\.vcf$", "", basename(vcf_files))
sample_names
# Load VCF files into GRanges[vcf_files, sample_names, ref_genome]
vcfs <- read_vcfs_as_granges(vcf_files, sample_names, ref_genome)
# Load Packages
library(BSgenome) # for available ref-genome
library(MutationalPatterns) # for mutational signature analysis
library(NMF) # for non-negative matrix factorization(NMF or NNMF)
library(patchwork) # for managing plots and grid system
library(tidyverse)
# List vailable genomes
head(available.genomes())
# Load data
ref_genome <- "BSgenome.Hsapiens.UCSC.hg19"
library(ref_genome, character.only = TRUE)
# Store VCF Files into vcf_files[vcf=variant call format]
vcf_files <- list.files(system.file("extdata", package = "MutationalPatterns"), pattern = ".vcf", full.names = TRUE)
vcf_files
# Extract sample names from file paths
sample_names <- gsub("\\.vcf$", "", basename(vcf_files))
sample_names
# Load VCF files into GRanges[vcf_files, sample_names, ref_genome]
vcfs <- read_vcfs_as_granges(vcf_files, sample_names, ref_genome)
# 96 Mutational Profile
mut_mat <- mut_matrix(vcf_list=vcfs, ref_genome = ref_genome)
head(mut_mat)
# De novo mutational signature extraction using NMF
mut_mat <- mut_mat + 0.0001
estimate <- nmf(mut_mat, rank=2:5, method = "brunet", nrun=10, seed=123456)
plot(estimate)
# Save the NMF estimation plot
ggsave("figures/nmf_estimate.png", dpi = 300)
# Heatmap
consensusmap(estimate)
ggsave("figures/nmf_heatmap.png", dpi = 300)
# Heatmap
p <- consensusmap(estimate)
ggsave("figures/nmf_heatmap.png", plot = p, dpi = 300)
# Heatmap
p <- consensusmap(estimate)
ggsave("figures/nmf_heatmap.png", plot = p, dpi = 300)
ggsave("figures/nmf_heatmap.png", dpi = 300)
# Mutational Signatures Extraction
nmf_res <- extract_signatures(mut_mat, rank = 2, nrun=10)
colnames(nmf_res$signatures) <- c("Signature A", "Signature B")
rownames(nmf_res$contribution) <- c("Signature A", "Signature B")
plot_96_profile(nmf_res$signatures, condensed = TRUE)
# Save the mutational profiles
ggsave("figures/mutational_profiles.png", dpi = 300)
plot_96_profile(nmf_res$signatures, condensed = TRUE)
# De novo mutational signature extraction using NMF
mut_mat <- mut_mat + 0.0001
estimate <- nmf(mut_mat, rank=2:5, method = "brunet", nrun=10, seed=123456)
# Save the NMF estimation plot
ggsave("figures/nmf_estimate.png", dpi = 300)
plot(estimate)
# Save the NMF estimation plot
ggsave("figures/nmf_estimate.png", dpi = 300)
# Heatmap
consensusmap(estimate)
ggsave("figures/nmf_heatmap.png", dpi = 300)
plot(estimate)
nmf_rank_estimate <- nmf(mut_mat, rank=2:5, method = "brunet", nrun=10, seed=123456)
plot(nmf_rank_estimate)
# Save the NMF estimation plot
ggsave("figures/nmf_estimate.png", dpi = 300)
# Heatmap
nmf_mat_estimate <- nmf(mut_mat, rank=2:5, method = "brunet", nrun=10, seed=123456)
consensusmap(nmf_mat_estimate)
ggsave("figures/nmf_heatmap.png", dpi = 300)
# Heatmap
consensusmap(nmf_mat_estimate)
estimate <- nmf(mut_mat, rank=2:5, method = "brunet", nrun=10, seed=123456)
p1 <- plot(estimate)
# Save the NMF estimation plot
ggsave(p1, "figures/nmf_estimate.png", dpi = 300)
# Save the NMF estimation plot
ggsave("figures/nmf_estimate.png", plot = p1, dpi = 300)
# Heatmap
p2 <- consensusmap(nmf_mat_estimate)
ggsave("figures/nmf_heatmap.png", plot = p2, dpi = 300)
# Heatmap
png("figures/nmf_heatmap.png", res = 300, width = 1500, height = 1500)
consensusmap(nmf_mat_estimate)
dev.off()
# Heatmap
png("figures/nmf_heatmap.png", res = 300)
consensusmap(nmf_mat_estimate)
plot(estimate)
plot(estimate)
# Save the NMF estimation plot
ggsave("figures/nmf_estimate.png", dpi = 300)
# De novo mutational signature extraction using NMF
mut_mat <- mut_mat + 0.0001
estimate <- nmf(mut_mat, rank=2:5, method = "brunet", nrun=10, seed=123456)
# Save the NMF estimation plot
ggsave("figures/nmf_estimate.png", dpi = 300)