Install any skill in seconds. Free to start, no credit card required.
Get Started Free →DNA methylation analysis with methylKit in R. Import Bismark coverage files, filter by coverage, normalize samples, and perform statistical comparisons. Use when analyzing single-base methylation patterns, comparing samples, or preparing data for DMR detection.
.claude/skills/bio-methylation-methylkit/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-18 | ✗→✓ | ▲ Improved | — | — |
| case-08 | ✗→✓ | ▲ Improved | — | — |
| case-02 | ✗→✓ | ▲ Improved | — | — |
| case-19 | ✗→✓ | ▲ Improved | — | — |
| case-13 | ✗→✓ | ▲ Improved | — | — |
Reference examples tested with: Bismark 0.24+, methylKit 1.28+
Before using code patterns, verify installed versions match. If versions differ:
packageVersion('<pkg>') then ?function_name to verify parametersIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
"Analyze methylation patterns across my samples" → Import per-cytosine methylation data, filter by coverage, normalize across samples, and test for differential methylation at individual CpG sites.
methylKit::methRead() → filterByCoverage() → normalizeCoverage() → calculateDiffMeth()rlibrary(methylKit) file_list <- list('sample1.bismark.cov.gz', 'sample2.bismark.cov.gz', 'sample3.bismark.cov.gz', 'sample4.bismark.cov.gz') sample_ids <- c('ctrl_1', 'ctrl_2', 'treat_1', 'treat_2') treatment <- c(0, 0, 1, 1) # 0 = control, 1 = treatment meth_obj <- methRead( location = as.list(file_list), sample.id = as.list(sample_ids), treatment = treatment, assembly = 'hg38', context = 'CpG', pipeline = 'bismarkCoverage' )
rmeth_obj <- methRead( location = as.list(file_list), sample.id = as.list(sample_ids), treatment = treatment, assembly = 'hg38', context = 'CpG', pipeline = 'bismarkCytosineReport' )
r# Coverage statistics getMethylationStats(meth_obj[[1]], plot = TRUE, both.strands = FALSE) # Coverage per sample getCoverageStats(meth_obj[[1]], plot = TRUE, both.strands = FALSE)
r# Remove CpGs with very low or very high coverage meth_filtered <- filterByCoverage( meth_obj, lo.count = 10, # Minimum 10 reads lo.perc = NULL, hi.count = NULL, hi.perc = 99.9 # Remove top 0.1% (likely PCR artifacts) )
r# Normalize coverage between samples (recommended) meth_norm <- normalizeCoverage(meth_filtered, method = 'median')
r# Find common CpGs across all samples meth_united <- unite(meth_norm, destrand = TRUE) # Combine strands # Allow some missing data meth_united <- unite(meth_norm, destrand = TRUE, min.per.group = 2L)
r# Correlation between samples getCorrelation(meth_united, plot = TRUE) # PCA of samples PCASamples(meth_united, screeplot = TRUE) PCASamples(meth_united) # Clustering clusterSamples(meth_united, dist = 'correlation', method = 'ward.D', plot = TRUE)
r# Calculate differential methylation diff_meth <- calculateDiffMeth( meth_united, overdispersion = 'MN', # Use shrinkage test = 'Chisq', mc.cores = 4 ) # Get significant differentially methylated CpGs dmcs <- getMethylDiff(diff_meth, difference = 25, qvalue = 0.01) # Hyper vs hypomethylated dmcs_hyper <- getMethylDiff(diff_meth, difference = 25, qvalue = 0.01, type = 'hyper') dmcs_hypo <- getMethylDiff(diff_meth, difference = 25, qvalue = 0.01, type = 'hypo')
Goal: Detect differentially methylated regions by aggregating single CpG data into fixed-size genomic windows.
Approach: Tile individual CpG measurements into 1kb windows, unite common tiles across samples, and run differential methylation testing on the aggregated tiles.
r# Aggregate CpGs into tiles/windows tiles <- tileMethylCounts(meth_obj, win.size = 1000, step.size = 1000) tiles_united <- unite(tiles, destrand = TRUE) # Differential methylation on tiles diff_tiles <- calculateDiffMeth(tiles_united, overdispersion = 'MN', mc.cores = 4) dmrs <- getMethylDiff(diff_tiles, difference = 25, qvalue = 0.01)
r# To data frame diff_df <- getData(dmcs) write.csv(diff_df, 'dmcs_results.csv', row.names = FALSE) # To BED file library(genomation) dmcs_gr <- as(dmcs, 'GRanges') export(dmcs_gr, 'dmcs.bed', format = 'BED')
rlibrary(genomation) gene_obj <- readTranscriptFeatures('genes.bed') annotated <- annotateWithGeneParts(as(dmcs, 'GRanges'), gene_obj) # Or with annotatr library(annotatr) annotations <- build_annotations(genome = 'hg38', annotations = 'hg38_basicgenes') dmcs_annotated <- annotate_regions(regions = as(dmcs, 'GRanges'), annotations = annotations)
r# For more than 2 groups meth_obj <- reorganize( meth_united, sample.ids = c('A1', 'A2', 'B1', 'B2', 'C1', 'C2'), treatment = c(0, 0, 1, 1, 2, 2) )
r# Combine biological replicates meth_pooled <- pool(meth_united, sample.ids = c('control', 'treatment'))
| Function | Purpose | |----------|---------| | methRead | Read methylation files | | filterByCoverage | Remove low/high coverage | | normalizeCoverage | Normalize between samples | | unite | Find common CpGs | | calculateDiffMeth | Statistical test | | getMethylDiff | Filter significant results | | tileMethylCounts | Region-level analysis | | PCASamples | PCA visualization | | getCorrelation | Sample correlation |
| Parameter | Default | Description | |-----------|---------|-------------| | overdispersion | none | MN (shrinkage) or shrinkMN | | test | Chisq | Chisq, F, fast.fisher | | mc.cores | 1 | Parallel cores | | slim | TRUE | Remove unused columns |
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-21 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +45 percentage points is the difference between those two pass rates over the 21 comparable cases.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.