Skip to content

Instantly share code, notes, and snippets.

View tuhulab's full-sized avatar

Tu Hu tuhulab

View GitHub Profile
{"name":"coder_python","settings":"{\"settings\":\"{\\n \\\"workbench.colorTheme\\\": \\\"Visual Studio Dark\\\",\\n \\\"extensions.autoUpdate\\\": false,\\n \\\"workbench.startupEditor\\\": \\\"none\\\",\\n \\\"tabnine.experimentalAutoImports\\\": true\\n}\\n\"}","extensions":"[{\"identifier\":{\"id\":\"eamodio.gitlens\",\"uuid\":\"4de763bd-505d-4978-9575-2b7696ecf94e\"},\"displayName\":\"GitLens — Git supercharged\"},{\"identifier\":{\"id\":\"ms-python.debugpy\",\"uuid\":\"4bd5d2c9-9d65-401a-b0b2-7498d9f17615\"},\"displayName\":\"Python Debugger\"},{\"identifier\":{\"id\":\"ms-python.python\",\"uuid\":\"f1f59ae4-9318-4f3c-a9b5-81b2eaa5f8a5\"},\"displayName\":\"Python\"},{\"identifier\":{\"id\":\"ms-toolsai.jupyter\",\"uuid\":\"6c2f1801-1e7f-45b2-9b5c-7782f1e076e8\"},\"displayName\":\"Jupyter\"},{\"identifier\":{\"id\":\"ms-toolsai.jupyter-keymap\",\"uuid\":\"9f6dc8db-620c-4844-b8c5-e74914f1be27\"},\"displayName\":\"Jupyter Keymap\"},{\"identifier\":{\"id\":\"ms-toolsai.jupyter-renderers\",\"uuid\":\"b15
@tuhulab
tuhulab / ComplexHeatmap.R
Last active September 5, 2022 06:44
Plot a complex heatmap
library(ComplexHeatmap)
count_matrix # if your data is called count_matrix
# Read data
se <- readRDS("data/se.rds")
count_matrix <- assay(se)
# Data transformation
count_matrix_log2 <- log2(count_matrix + 1)
@tuhulab
tuhulab / mergeLib.R
Created March 8, 2021 08:40
R function to merge libraries
counttable_merge_library_fun <- function(counttable_data = ...,
lib_to_merge_vector = ...){
lib_id <- counttable_data %>% colnames() %>% str_extract("lib\\d{1,}")
merged_counttable <- sapply(lib_to_merge_vector, function(one_lib_id_to_merge){
merged_counts <- counttable_data %>% select((lib_id == one_lib_id_to_merge) %>% which()) %>% rowSums()
merged_counts_df <- tibble(one_lib_id_to_merge = merged_counts)
return(merged_counts_df)
}) # The function to merge libs for counttable -----------------
# list tidy
MergedLib <- do.call(rbind.data.frame, merged_counttable) %>% t() %>% as.data.frame() %>% tibble()
@tuhulab
tuhulab / gene_cleaneR.R
Last active March 8, 2021 12:47
quick trick to clean pseudo genes
library(dplyr)
a_vector_of_genes <- c("AP005212.4", "Z98257.1", "U62317.4", "CLIC4P3", "PGLYRP2", "NEK4P1")
a_vector_of_cleaned_genes <- data.frame(a_vector_of_genes) %>% filter(!a_vector_of_genes %>% stringr::str_detect("\\d{1,}P$|\\d{1,}P\\d{1,}$|\\.|-AS\\d{1}|-DT")) %>% pull(a_vector_of_genes)
@tuhulab
tuhulab / clusteR.R
Last active September 30, 2020 10:40
Performing cluster analyis in R
# Cluster analysis in R
# inspired by Dima Gorenshteyn, DataCamp
## standardize data
df_st <- scale(df)
## Hierachical clustering
d <- dist(df)
hc <- hclust(d, "method") # method %in% c("complete", "average", "single")
c <- cutree(hc, h = the_height) # h: the height to cut the tree # assign cluster
@tuhulab
tuhulab / gist:6f57f70b6b1e6db0ef07d1dc3c8d94b1
Created August 28, 2020 08:24
Neg feature maniputation for Muyao
pos_n_max <- pos_data %>% pull(feature) %>% stringr::str_match("\\d{1,}") %>% max()
neg_feature_n <- neg_data %>% pull(feature) %>% stringr::str_match("\\d{1,}")
neg_data %>% mutate(feature = paste0("F", neg_feature_n + pos_n_max))
@tuhulab
tuhulab / EnrichR.R
Created August 7, 2020 06:05
How to run Enrichr from R
# First install R (https://www.r-project.org/) and RStudio(https://rstudio.com/)
# Install enrichR
install.packages("enrichR")
# Load enrichR
library(enrichR)
# Get your gene list, e.g. type by hand
Inflammatory_markers <- c("IL13","MMP12","IL22","NTRK1", "CCL17", "IL36A", "ICOS", "CCL18", "ALOX15", "CCL1", "CCR5", "IL13RA2", "IL19", "CCR7","CCL20", "CCR4","CCR2","CCL11","CCL22","CCR8","CCL19","CCL26","CCL3")