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())
@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 / 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
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
library(GetoptLong)
library(shiny)
library(rvest)
library(DT)
html = read_html("https://cran.r-project.org/web/checks/check_summary_by_package.html")
html %>% html_element("table") %>% html_table(header = FALSE) -> tb
tb = as.data.frame(tb)
library(COVID19)
library(ComplexHeatmap)
library(circlize)
library(spiralize)
library(RColorBrewer)
library(shiny)
library(lubridate)
env = new.env()
library(COVID19)
library(ComplexHeatmap)
library(circlize)
library(spiralize)
library(RColorBrewer)
spiral_initialize_by_time(xlim = c("2020-01-02", "2022-01-07"),
vp_param = list(x = unit(0, "npc"), width = unit(0.9, "snpc"), height = unit(0.9, "snpc"), just = "left"))
load(system.file("extdata", "doodle.RData", package = "circlize"))
img = do.call(cbind, lapply(img_list, function(x) as.matrix(as.raster(x)[1:106, 1:150])))
img = as.raster(img)
library(spiralize)
spiral_initialize(scale = "curve", start = 180, end = 360*3)
spiral_track(background = FALSE)
spiral_raster(0.5, 0.5, img, facing = "curved_inside")