25.methylation-variability/SKILL.md
This skill provides a complete and streamlined workflow for performing methylation variability and epigenetic heterogeneity analysis from whole-genome bisulfite sequencing (WGBS) data. It is designed for researchers who want to quantify CpG-level variability across biological samples or conditions, identify highly variable CpGs (HVCs), and explore epigenetic heterogeneity.
npx skillsauth add bisnake2001/chromskills methylation-variability-analysisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Main steps include:
Use this methylKit-based variability pipeline when you want to:
<sample1>.bed
<sample2>.bed
methylation_variability/
stats/
top_variable_CpGs.tsv
CpG_variability_stats.tsv
plots/
heatmap_top_variable_CpGs.pdf
distribution_CpG_variance.pdf
mean_vs_variance_scatter.pdf
temp/
library(methylKit)
file.list <- list(
"sample1.cov",
"sample2.cov",
"sample3.cov"
)
sample.id <- list("S1", "S2", "S3")
treatment <- c(0, 1, 1) # e.g. 0 = control, 1 = treated
# Read methylation data
myobj <- methRead(
location = file.list,
sample.id = sample.id,
assembly = "hg38", # provided by user
treatment = treatment,
context = "CpG",
pipeline = list(
fraction = FALSE, # percMeth is 0–100, fraction is 0-1, depend on inputs
chr.col = 1,
start.col = 2,
end.col = 3,
strand.col = 6, # provided by user
coverage.col = 10, # provided by user
freqC.col = 11 # provided by user
)
)
# Optional filtering: remove low / extremely high coverage CpGs
filtered.myobj <- filterByCoverage(
myobj,
lo.count = 10, lo.perc = NULL,
hi.count = 99.9, hi.perc = TRUE
)
# Unite CpGs across samples (common CpG sites)
meth <- unite(filtered.myobj, destrand = TRUE)
d <- getData(meth.united)
numCs.cols <- grep("numCs", colnames(d), value = TRUE)
cov.cols <- grep("coverage", colnames(d), value = TRUE)
pmat01 <- d[, numCs.cols] / d[, cov.cols]
pmat01 <- as.matrix(data.frame(pmat01))
var.cpg <- rowVars(pmat01, na.rm = TRUE) # Variance across samples
mad.cpg <- rowMads(pmat01, na.rm = TRUE) # Median absolute deviation (MAD)
# Coefficient of variation (CV = sd / mean)
mean.cpg <- rowMeans(pmat01, na.rm = TRUE)
sd.cpg <- sqrt(var.cpg)
cv.cpg <- sd.cpg / (mean.cpg + 1e-6) # add small constant to avoid division by zero
# Assemble statistics table
var.stats <- data.frame(
chr = d$chr,
start = d$start,
end = d$end,
mean = mean.cpg,
variance = var.cpg,
MAD = mad.cpg,
CV = cv.cpg,
stringsAsFactors = FALSE
)
var.stats <- var.stats[order(-var.stats$variance), ] # Sort by variance (descending)
# Save full table
write.table(
var.stats,
file = "CpG_variability_stats.tsv",
sep = " ",
quote = FALSE,
row.names = FALSE
)
topN <- 1000
top.idx <- head(order(-var.cpg), topN)
pmat.top <- pmat01[top.idx, , drop = FALSE]
# Save top-variable CpGs table
write.table(
var.stats[match(rownames(pmat.top), rownames(var.stats)), ],
file = "top_variable_CpGs.tsv",
sep = " ",
quote = FALSE,
row.names = FALSE
)
group.factor <- factor(ifelse(treatment == 0, "GM12878", "K562"))
ha <- HeatmapAnnotation(Group = group.factor)
Heatmap(
pmat.top,
name = "methylation",
show_row_names = FALSE,
show_column_names = TRUE,
top_annotation = ha,
cluster_rows = TRUE,
cluster_columns = TRUE
)
# Distribution of the CpG variability
var.df <- data.frame(
variance = var.cpg,
log10_variance = log10(var.cpg + 1e-8)
)
ggplot(var.df, aes(x = log10_variance)) +
geom_histogram(bins = 50) +
theme_minimal() +
labs(
title = "CpG-wise methylation variance (log10 scale)",
x = "log10(variance + 1e-8)",
y = "Count of CpGs"
)
# 3. Mean vs Variance scatter plot
ggplot(var.stats, aes(x = mean_methylation, y = variance)) +
geom_hex(bins = 50) +
scale_fill_viridis_c(trans = "log10") +
theme_minimal() +
labs(
title = "Mean Methylation vs Variance",
x = "Mean Methylation",
y = "Variance",
fill = "Count (log10)"
) +
theme(
plot.title = element_text(hjust = 0.5, size = 14, face = "bold")
)
GenomicRanges and TxDb annotations, then compute variability at region level by aggregating CpG variability.development
Align ChIP-seq or ATAC-seq FASTQ files to a reference genome using Bowtie2, with strict input validation, library layout detection, output organization and logging. Use it when raw sequencing reads must be converted into sorted/indexed BAM files before downstream QC, peak calling, or footprinting.
development
Align bisulfite sequencing DNA methylation reads using Bismark only, with explicit validation of reference preparation, library layout detection, output organization, logging, and alignment QC. Use it for WGBS, RRBS, or other bisulfite-converted DNA methylation sequencing data when raw FASTQ files must be aligned before methylation extraction and downstream analysis.
data-ai
Perform peak calling for ChIP-seq or ATAC-seq data using MACS3, with intelligent parameter detection from user feedback. Use it when you want to call peaks for ChIP-seq data or ATAC-seq data.
devops
The TF-differential-binding pipeline performs differential transcription factor (TF) binding analysis from ChIP-seq datasets (TF peaks) using the DiffBind package in R. It identifies genomic regions where TF binding intensity significantly differs between experimental conditions (e.g., treatment vs. control, mutant vs. wild-type). Use the TF-differential-binding pipeline when you need to analyze the different function of the same TF across two or more biological conditions, cell types, or treatments using ChIP-seq data or TF binding peaks. This pipeline is ideal for studying regulatory mechanisms that underlie transcriptional differences or epigenetic responses to perturbations.