-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.Rmd
221 lines (184 loc) · 7.07 KB
/
index.Rmd
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
---
title: "sgRNA + CCLE - heatmap"
author: "Ray"
date: "`r format(Sys.time(), '%d %B, %Y')`"
output: html_document
params:
workdir: "./"
prefix: "genomeCRIPSR"
tissue.type: "PANCREAS"
mut.genes: "TP53"
genealt.RDS: "./CRISPR_annot_allgenes_status.RDS"
sgRNA.RDS: "./GenomeCRISPR_full05112017.RDS"
ccle_tpm.RDS: "./CCLE_RNASeq_tpm_matched_CRISPR.RDS"
runtime: shiny
---
```{r, warning=FALSE, message=FALSE, echo=FALSE}
#rm(list = ls())
cleanMem <- function(n=10) { for (i in 1:n) gc() }
### Combine gene alteration status in CCLE data + CRISPR sgRNA data from genomeCRISPR database
library(shiny)
library(tidyverse)
library(pheatmap)
library(RColorBrewer)
source("helper.R")
options('download.file.method'='curl')
#folder <- params$workdir
#knitr::opts_chunk$set(echo = TRUE)
#knitr::opts_knit$set(root.dir = folder)
prefix <- params$prefix
# tissue <- params$tissue
tissue.type <- toupper(c("PANCREAS", "AML", "BREAST"))
mut.genes <- params$gene
genealt.RDS <- params$genealt.RDS
sgRNA.RDS <- params$sgRNA.RDS
ccle_tpm.RDS <- params$ccle_tpm.RDS
```
```{r ccle, echo=FALSE, message=FALSE, warning=FALSE}
### Input files
# genealt.RDS (CCLE mutational data)
# sgRNA.RDS (genomeCRISPR logFC data)
# ccle_tpm.RDS (CCLE expresion data)
genealt <- readRDS(genealt.RDS)
genealt$name <- gsub(" ", "-", genealt$name)
genealt$type <- gsub(" .*", "", genealt$type) %>%
gsub("^B$", "BURKITT", .)
# sgRNA
sgRNA <- readRDS(sgRNA.RDS)
# ccle_tpm
ccle_tpm <- readRDS(ccle_tpm.RDS)
```
```{r echo=FALSE}
### Filtering
##- Genes
#+ genes that have mutation info in CCLE
#+ genes in the sgRNA for plotting
#- Samples
#+ Type (tissue)
```
```{r snow, echo=FALSE, message=FALSE, fig.width=12, fig.height=12}
# observe({
# # periodically collect
# invalidateLater(1000,session)
# cleanMem()
# })
cleanMem()
# Copy the chunk below to make a group of checkboxes
checkboxGroupInput("tissue.type", label = h4("Please select:"),
choices = genealt$type %>% unique %>% sort %>% c("ALL", .),
inline = TRUE, width='600px',
selected = "AML")
selectizeInput("plot.genes", "Plot Genes (you can either select from below or type in your genes of interest)",
sgRNA$symbol %>% c("TP53", "KRAS", "NRAS", "PTEN", "EGFR", "MYC", "SMAD4", "CDKN1A", "CDKN2A", "IDH1", "IDH2", .) %>% unique,
selected = c("PCNA", "BRAF", "TP53", "MDM2"), multiple = TRUE, width="700px",
options = list(maxOptions = 5, placeholder = 'e.g., TP53, MDM2'))
selectizeInput("mut.genes", "Gene mutations info: (again, type in your genes of interest)",
colnames(genealt)[-c(1:9)] %>% gsub("-.*", "", .) %>% c("TP53", "KRAS", "NRAS", "PTEN", "EGFR", "MYC", "SMAD4", "CDKN1A", "CDKN2A", "IDH1", "IDH2", .) %>% unique,
selected = c("TP53"), multiple = TRUE, width="700px",
options = list(maxOptions = 10, placeholder = 'e.g., TP53, MDM2'))
renderPlot({
prefix <- paste(input$tissue.type, collapse = "_")
tissue.type <- input$tissue.type
# tissue.type <- c("AML", "BREAST", "NSCLC", "BL", "MELANOMA", "COLON", "LIVER", "OVARY")
# tissue.type <- "ALL"
tissue.type <- input$tissue.type
plot.genes <- input$plot.genes
#mut.genes <- c("TP53")
mut.genes <- input$mut.genes
# how to bin/combine coloring for mutations - simple, merge, all
mut.color.type <- "merge"
### Run from below
mut.genes.col <- expand.grid(mut.genes, c("-change", "-type")) %>%
mutate(Var1 = as.character(Var1),
Var2 = as.character(Var2),
name = paste0(Var1, Var2)) %>%
left_join(tibble(Var1 = mut.genes), ., by="Var1") %>%
pull(name)
# Sort by the number of mutations in the record by decending order
# NAs in column '-change' are the splice_sites
col.idx <- match(mut.genes.col, colnames(genealt))
mut.genes.annot <- genealt[, c(1:9, col.idx)] %>%
mutate(tissue = gsub("BREST", "BREAST", tissue)) %>%
mutate(type = ifelse(type == "B", "BURKITT", type)) %>%
replace(is.na(.), "Splice_Site") #%>%
# filter based on tissue type
min.samp <- 2
if (tissue.type != "ALL"){
final.annot <- mut.genes.annot %>%
filter(type %in% tissue.type)
if(nrow(final.annot) >= min.samp){
print(paste("### Running for type:", tissue.type, "with", nrow(final.annot), "samples"))
}else{
stop(paste("### samples for this type", tissue.type, "is less than", min.samp, "samples"))
}
}else{
prefix <- "ALL"
final.annot <- mut.genes.annot
}
final.annot <- final.annot %>%
mutate(Sample_name = paste(cell, pub, type, sep="_")) %>%
mutate(Sample_name = make.unique(Sample_name)) %>%
mutate_at(vars(contains("-type")), funs(merge_mutation(., type=mut.color.type)))
plot.sgRNA <- tibble(symbol = plot.genes) %>%
left_join(., sgRNA, by="symbol") %>%
dplyr::select(Gene = symbol, final.annot$name)
### pheatmap
x2 <- plot.sgRNA %>%
replace(is.na(.), 0) %>%
set_names(c("Gene", final.annot$Sample_name)) %>%
convert_tibble_to_dataframe()
# Defines the vector of colors for the legend (it has to be of the same lenght of breaksList)
x2.min <- floor(min(x2, na.rm = TRUE))
x2.max <- ceiling(max(x2, na.rm = TRUE))
breaks = c(seq(x2.min, -0.51, length.out = 101), seq(-0.5, 0.5, length.out = 101), seq(0.51, x2.max, length.out=101))
breaks2 <- breaks
# color <- colorRampPalette(c("cyan1", "grey5", "red"))(length(breaks2))
color <- colorRampPalette(c("lightskyblue1", "grey5", "red"))(length(breaks2))
# color <- colorRampPalette(c("cadetblue1", "grey5", "red"))(length(breaks2))
breaks2[length(breaks)] <- max(x2.max, max(breaks))
breaks2[1] <- min(x2.min, min(breaks))
fontsize_row <- pheatmap_fontsize_row(x2)
fontsize_col <- pheatmap_fontsize_col(x2)
### create_annot_for_color
annotation_col <- final.annot %>%
dplyr::select(Sample_name, type, mut.genes.col) %>%
dplyr::select(-contains("-change")) %>%
#select_if(~ length(unique(.)) > 1) %>%
set_names(gsub("-type", "", colnames(.))) %>%
convert_tibble_to_dataframe()
# create custom colors for each column_side_colors
# type.dat <- matrix(NA, nrow=nrow(annotation_col), ncol=ncol(annotation_col))
# colnames(type.dat) <- mut.genes
mycolors <- list()
for(i in 1:ncol(annotation_col)){
cur.typename <- colnames(annotation_col)[i]
cur.muttype <- annotation_col[, i]
if(cur.typename == "type"){
num.cur.muttype <- cur.muttype %>% unique %>% length
type_col <- colorRampPalette(brewer.pal(n = num.cur.muttype, name = "Spectral"))(num.cur.muttype)
names(type_col) <- cur.muttype %>% unique
mycolors[[cur.typename]] <- type_col
}else{
mycolors[[cur.typename]] <- mut_color_predefined()[unique(c("WT", sort(cur.muttype)))]
}
}
#
pdf_height <- pheatmap_pdf_height(x2) + 1
pdf_width <- pheatmap_pdf_width(x2)
pheatmap(x2, color=color,
clustering_method = "ward.D2",
annotation_col = annotation_col,
annotation_colors = mycolors,
breaks = breaks2,
cluster_cols = TRUE,
cluster_rows = TRUE,
scale = "none",
show_rownames = TRUE,
fontsize_row = fontsize_row,
fontsize_col = fontsize_col,
border_color = NA,
main = paste0(prefix, "\n")
)
#})
}, height=650)
```