Skip to content

Instantly share code, notes, and snippets.

View tuhulab's full-sized avatar
:octocat:

Tu Hu tuhulab

:octocat:
View GitHub Profile
@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")