Skip to content

Instantly share code, notes, and snippets.

View jokergoo's full-sized avatar
🚀

Zuguang Gu jokergoo

🚀
View GitHub Profile
x = sessionInfo()
base_pkgs = x$basePkgs
other_pkgs = sapply(x$otherPkgs, function(x)x$Package)
loaded_pkgs = sapply(x$loadedOnly, function(x)x$Package)
db = reformat_db(installed.packages())
library(COVID19)
library(ComplexHeatmap)
library(circlize)
library(spiralize)
library(RColorBrewer)
library(shiny)
library(lubridate)
env = new.env()
@jokergoo
jokergoo / translocations.R
Created December 9, 2022 19:48
intra- and inter-translocations
x = sort(runif(20))
df1 = data.frame(x1 = x[1:20 %% 2 == 0], x2 = x[1:20 %% 2 == 1])
df1 = cbind(gene = "A", df1)
x = sort(runif(10, max = 0.5))
df2 = data.frame(x1 = x[1:10 %% 2 == 0], x2 = x[1:10 %% 2 == 1])
@jokergoo
jokergoo / text_height.R
Created November 24, 2022 20:27
text height
library(grid)
grid.newpage()
pushViewport(viewport())
str = "Hfgj"
gb = textGrob(str, 0.2, 0.5, gp = gpar(fontsize = 60, fontfamily = "mono"))
grid.draw(gb)
grid.points(0.2, 0.5, pch = 16, gp = gpar(col = "red"))
grid.rect(0.2, 0.5, width = grobWidth(gb), height = grobHeight(gb), gp = gpar(col = "black"))
@jokergoo
jokergoo / r_pkg_downloads.R
Created October 2, 2022 15:07
Number of downloads from CRAN/Bioc/conda
library(rvest)
library(jsonlite)
downloads_from_conda = function(pkg) {
x = read_html(paste0("https://anaconda.org/search?q=r-", pkg))
tb = html_nodes(x, "table") %>% html_table()
if(length(tb) > 0) {
tb = tb[[1]]
sum(tb[, 2])
} else {
0
@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",
@jokergoo
jokergoo / viz_lift_over.R
Last active September 12, 2022 18:27
Visualize lift over between two assemblies
library(rtracklayer)
library(circlize)
library(EnrichedHeatmap)
viz_lift_over = function(from = "hg19", to = "hg38",
from_chromosomes = NULL, to_chromosomes = NULL,
window_size = 5000, links_to_sample = 10000) {
to2 = to
@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) {
library(matrixStats)
library(genefilter)
gene_level = function(mat, condition, method = "tvalue", transform = "none",
binarize = function(x) x) {
le = levels(condition)
l_group1 = condition == le[1]
l_group2 = !l_group1