Skip to content

Instantly share code, notes, and snippets.

View jokergoo's full-sized avatar
🚀

Zuguang Gu jokergoo

🚀
View GitHub Profile
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)
@jokergoo
jokergoo / heatmap_3d.R
Last active October 3, 2022 11:54
a simple 3D heatmap
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
@jokergoo
jokergoo / jaccard_heatmap.R
Last active October 3, 2022 11:53
jaccard_heatmap.R
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",
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
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)
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",
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)
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.")
}
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
}
@jokergoo
jokergoo / gist:ac65ed4061c83fe26a4a3e182c9cb6f9
Created April 16, 2020 13:57
add asterisks on heatmap
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) {