This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m = matrix(rnorm(100), 10) | |
rownames(m) = paste0("row", 1:10) | |
colnames(m) = paste0("column", 1:10) | |
ht = draw(Heatmap(m, name = "mat")) | |
highlight_row = function(which, padding = unit(1, "mm"), gp = gpar()) { | |
row_order = row_order(ht) | |
i = which(row_order == which) | |
nr = length(row_order) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rect3D = function(x, y, w, h, l, theta = 60, default.units = "npc", fill = "white", col = "black") { | |
if(!is.unit(x)) x = unit(x, default.units) | |
if(!is.unit(y)) y = unit(y, default.units) | |
if(!is.unit(w)) w = unit(w, default.units) | |
if(!is.unit(h)) h = unit(h, default.units) | |
if(!is.unit(l)) l = unit(l, default.units) | |
x1 = x - w*0.5 | |
x2 = x + w*0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(GenomicRanges) | |
library(HilbertCurve) | |
library(ComplexHeatmap) | |
library(InteractiveComplexHeatmap) | |
library(GetoptLong) | |
file_list = c( | |
"IDH_DMV" = "https://ftp.ncbi.nlm.nih.gov/geo/series/GSE121nnn/GSE121721/suppl/GSE121721_IDH_methylation_features_DMV.bed.gz", | |
"IDH_LMR" = "https://ftp.ncbi.nlm.nih.gov/geo/series/GSE121nnn/GSE121721/suppl/GSE121721_IDH_methylation_features_LMR.bed.gz", | |
"IDH_PMD" = "https://ftp.ncbi.nlm.nih.gov/geo/series/GSE121nnn/GSE121721/suppl/GSE121721_IDH_methylation_features_PMD.bed.gz", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gsub_eval = function(pattern, replacement, x, ignore.case = FALSE, perl = FALSE, | |
fixed = FALSE, useBytes = FALSE, envir = parent.frame()) { | |
txt = gsub( | |
pattern = pattern, | |
replacement = replacement, | |
x = x, | |
ignore.case = ignore.case, | |
perl = perl, | |
fixed = fixed, | |
useBytes = useBytes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(circlize) | |
par(mfrow = c(2, 2)) | |
circos.initialize(c("a"), xlim = c(0, 1)) | |
circos.track(ylim = c(0, 1), track.height = 0.7, bg.border = NA, | |
panel.fun = function(x, y) { | |
circos.lines(CELL_META$cell.xlim, rep(CELL_META$cell.ylim[1], 2), col = "#CCCCCC") | |
circos.lines(CELL_META$cell.xlim, rep(CELL_META$cell.ylim[2], 2), col = "#CCCCCC") | |
x0 = runif(1000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(circlize) | |
seed_color = c("1-3" = 2, | |
"4-6" = 3, | |
"7-9" = 4, | |
"10-12" = 5, | |
"13-16" = 6, | |
"(Missing)" = "grey") | |
round_name = c("Champoin", | |
"Runner-up", | |
"Final Four", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set.seed(123) | |
m = matrix(rnorm(100*10), nrow = 100) | |
# you should clustr the columns before making the heatmap because the column | |
# ordering will be used in `panel.fun` | |
column_hclust = hclust(dist(t(m))) | |
subgroup = sample(letters[1:3], 100, replace = TRUE, prob = c(1, 5, 10)) | |
rg = range(m) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(grid) | |
word_cloud_grob = function(text, fontsize, | |
line_space = unit(4, "pt"), word_space = unit(4, "pt"), max_width = unit(80, "mm"), | |
col = function(fs) circlize::rand_color(length(fs), luminosity = "dark"), | |
test = FALSE) { # width in mm | |
if(length(text) != length(fontsize)) { | |
stop("`text` and `fontsize` should the same length.") | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type = c(rep("Tumor", 10), rep("Control", 10)) | |
set.seed(888) | |
###################################### | |
# generate methylation matrix | |
rand_meth = function(k, mean) { | |
(runif(k) - 0.5)*min(c(1-mean), mean) + mean | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(circlize) | |
library(ComplexHeatmap) | |
mat = matrix(runif(100), 10) | |
col_fun = colorRamp2(c(0, 0.1, 1), c("blue", "white", "red")) | |
Heatmap(mat, col = col_fun, cell_fun = function(j, i, x, y, w, h, fill) { | |
if(mat[i, j] < 0.1) { |