Skip to content

Instantly share code, notes, and snippets.

View Zepeng-Mu's full-sized avatar
🖥️
Away

Zepeng (Phoenix) Mu Zepeng-Mu

🖥️
Away
View GitHub Profile
@Zepeng-Mu
Zepeng-Mu / tpManhattanSingle.R
Created June 1, 2025 18:22
Create a single Manhattan plot using the tidyplots package
tpManhattanSingle <- function(
summ.1, chr = "CHR", bp = "BP", p = "P", snp = "SNP",
summ.1.name = "$-log[10](P)$", plot.label = NULL,
logp = TRUE, size = 2, lead.snp = NULL, r2 = NULL,
plot.width = 100, plot.height = 50, ...
) {
if (!is.null(summ.1[[snp]])) {
d1 <- data.frame(CHR = summ.1[[chr]], BP = summ.1[[bp]], P = summ.1[[p]], SNP = summ.1[[snp]])
} else {
@Zepeng-Mu
Zepeng-Mu / Rstudio snippets
Created May 18, 2025 01:04
Attach this to the end of Snippets in RStudio -> Tools -> Global options -> Code -> Edit snippets.
snippet script_header
################################################################################
## Script Purpose: ${0}
## Author:Zepeng Mu ([email protected])
## Date: `r format(Sys.time(), "%a, %b %e %Y")`
################################################################################
snippet h1
# ${0:Header1} ----
@Zepeng-Mu
Zepeng-Mu / ggManhattanSingle.R
Last active June 1, 2025 18:23
Plot COLOC results
ggColocManhattanSingle <- function(
summ.1, chr = "CHR", bp = "BP", p = "P", snp = "SNP",
summ.1.name = expression(paste("", -log[10](P))),
logp = TRUE, size = 2, lead.snp = NULL, r2 = NULL, ...
) {
if (!is.null(summ.1[[snp]])) {
d1 <- data.frame(CHR = summ.1[[chr]], BP = summ.1[[bp]], P = summ.1[[p]], SNP = summ.1[[snp]])
} else {
d1 <- data.frame(CHR = summ.1[[chr]], BP = summ.1[[bp]], P = summ.1[[p]])
@Zepeng-Mu
Zepeng-Mu / glimpse_pipeline.smk
Last active February 20, 2025 01:55
Run GLIMPSE on scATAC-seq data
## Run GLIMPSE on scATAC bam files
import pandas as pd
import os
smp = os.listdir("/project/yangili1/zpmu/covid19/data/cellranger_out21")
SNPDIR = "/project/yangili1/zpmu/covid19/data/hornet_snp"
chrm = sorted([str(x) for x in range(1, 23)])
@Zepeng-Mu
Zepeng-Mu / ggQQplot.R
Created September 27, 2022 16:23
Plot QQ-plot using ggplot2
ggQQplot <- function(pList, colVec = c("black", "orange", "red", "purple"),
legendLabel = NULL, title = "", openRange = F, sampling = 1) {
if (is.null(legendLabel)) {
legendLabel = colVec
}
if (length(pList) > length(colVec)) {
stop("pList needs to be shorter than colVec!!!")
}
@Zepeng-Mu
Zepeng-Mu / getFDR.R
Created May 4, 2022 15:34
Calculate FDR using test statistics and null statistics, similar to `empPvals()` from qvalue package
getFDR <- function(Stat, Stat0) {
m <- length(Stat)
n <- length(Stat0)
v <- c(rep(T, m), rep(F, n))
v <- v[order(c(Stat, Stat0), decreasing = T)]
vSumT <- (m - cumsum(v == T)[v == T] + 1) / m
vSumF <- (n - cumsum(v == F)[v == T]) / n
fdr <- cummin(pmin(1, vSumF / vSumT))
fdr <- fdr[rank(-Stat)]
return(fdr)
@Zepeng-Mu
Zepeng-Mu / find_loci.R
Created April 21, 2022 20:22
Getting non-overlapping loci from GWAS for colocalization analysis
disjoinGr <- function(df, chr = "CHR", bp = "BP", pval = "Pval", snp = "SNP", size = 5e5) {
inGr <- GRanges(df[[chr]], IRanges(df[[bp]] - size, df[[bp]] + size - 1),
SNPID = df[[snp]], BP = df[[bp]], Pval = df[[pval]])
disjointGr <- disjoin(inGr)
ov <- findOverlaps(resize(inGr, 1, "center"), disjointGr)
hitGr <- disjointGr[subjectHits(ov)]
ovGr <- setdiff(disjointGr, hitGr)
firstHalf <- resize(ovGr, width(ovGr) / 2 - 1, "start")
secondHalf <- resize(ovGr, width(ovGr) / 2, "end")