Spiky: Analysing cfMeDIP-seq data with spike-in controls

Samantha L Wilson and Lauren M Harmon

February 8, 2021


To meet the need for a reference control in cell-free methylated DNA immunoprecipitation-sequencing (cfMeDIP-seq)1,2 experiments, we designed spike-in controls and ligated unique molecular indexes (UMI) to adjust for PCR bias, and immunoprecipitation bias caused by the fragment length, G+C content, and CpG density of the DNA fragments that are immunoprecipitated3. This enables absolute quantification of methylated DNA in picomoles, while retaining epigenomic information that allows for sensitive, tissue-specific detection as well as comparable results between different experiments. We designed DNA fragments with 2x3x3x3=54 combinations of methylation status (methylated and unmethylated), fragment length in basepair (bp) (80 bp, 160 bp, 320 bp), G+C content (35%, 50%, 65%), and fraction of CpGs within a fragment (1 CpG/ 80 bp, 1 CpG/ 40 bp, 1 CpG/ 20 bp). Spiky was developed for analyzing DNA methylation of cell-free DNA obtained from cfMeDIP-seq method using reference ‘spike-in’ controls. This package will:


Install and load the spiky package from Bioconductor.

#To install this package, start R (version "3.6" or later) and enter:
  #if (!requireNamespace("BiocManager", quietly = TRUE))
  #  install.packages("BiocManager")


Load spike database, or create your own with process_spikes().

Input: A Fasta file, GRanges, or dataframe of spike-in sequences, and a vector of booleans (0 or 1) describing whether each spike-in sequence is methylated.

Output: The output contains a DataFrame with the following columns:

sequence (DNAStringSet) methylated (boolean) CpGs (integer) fmol (numeric) molmass (numeric) GCfrac (numeric) OECpG (numeric) conc (numeric) *frag_grp (character)

If you are using the same synthetic spike-in sequences as described in the manuscript, you may load the spike-in sequence database using:

If you are using custom spike-ins, you can create your own spike-in sequence database using the process_spikes() function, which accepts as input a Fasta file, GRanges, or dataframe, and a vector of booleans (0 or 1) describing whether each spike-in sequence is methylated. The input Fasta file can also be generated from BAM header info as follows:

The spike-in database can then be created with this input Fasta.

Process the input files

Spiky supports input files in either BAM or BEDPE format.

BAM Input

BAM file in standard format (For full details about the BAM format, see https://samtools.github.io/hts-specs/SAMv1.pdf). The BAM must also have an accompanying index file, which can be created using samtools index ${filename.bam}. (http://www.htslib.org/doc/samtools-index.html)

BAM required columns

Output: The output objects will be used downstream in the analysis, including


BEDPE file in standard format. For full details about the BEDPE format, see Bedtools documentation (https://bedtools.readthedocs.io/en/latest/content/general-usage.html#bedpe-format). In short, for a pair of ranges 1 and 2, we have fields chrom1, start1, end1, chrom2, start2, end2, and (optionally) name, score, strand1, strand2, plus any other user defined fields that may be included (these are not yet supported by Spiky). For example, two valid BEDPE lines are:

chr1 100 200 chr5 5000 5100 bedpe_example1 30

chr9 900 5000 chr9 3000 3800 bedpe_example2 99 + -

The BEDPE must also have an accompanying index file, which can be created using Bedtools, as in the example shown below, where ${file} represents the name of a BEDPE file.

bedtools sort -i \({file} > sorted_\){file} bgzip sorted_\({file} tabix sorted_\){file}.gz

Output: The output objects will be used downstream in the analysis, including

Methylation specificity

For each combination of parameters, we designed two distinct spike-in sequences. One to be methylated and one to be unmethylated. The allows us to assess non-specific binding of the monoclonal antibody on a sample-by-sample basis. To calculate methylation specificity we take the number of methylated reads divided by the total number of reads. It is our recommendation that if methylation specificity is <0.98, then the sample should be flagged or removed from analysis as the cfMeDIP performed inadequately.

This calculation is done by the ‘methylation_specificity’ function.

Input: The output of the ‘scan_spike_contigs’ or ‘scan_spike_bedpe’ functions

Output: methylation specificity mean and median


Fit a Gaussian model to predict the molar amount of DNA sequences

For each batch of samples, the coefficients used in the Gaussian generalized linear model will differ. The ‘model_glm_pmol’ will calculate these coefficients and output the model to be used to calculate molar amount (picomoles) on the user’s DNA sequences of interest. We assume that all DNA sequences of interest are methylated after undergoing cfMeDIP-seq. As such, we build the Gaussian generalized linear model on only the methylated spike-in control fragments. A generated Bland-Altman plot will visualize how well the model performs.

Input: The output of the ‘scan_spike_contigs’ or ‘scan_spike_bedpe’ functions



Calculating molar amount on DNA sequences of interest

For the samples in which the Gaussian generalized linear model was built, we will calculate the molar amount (picomoles) for each DNA sequence of interest.

Input: The output of the ‘scan_genomic_contigs’ or ‘scan_genomic_bedpe’ functions and the Gaussian generalized linear model

Output: sample_pmol_data


Adjusting molar amount to binned genomic windows

For our analyses, we binned the genome into 300 bp non-overlapping windows. We then look overlap between fragments in our data with each of the 300 bp genomic windows. We adjust the molar amount (picomoles) by a multiplier. This multiplier is the proportion of overlap between our fragment and the 300 bp window. This is done for every fragment in our sample.

Input: output dataframe produced from predict_pmol

Output: sample_binned_data


Session Info

#> R version 4.2.1 (2022-06-23)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.5 LTS
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
#> LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB              LC_COLLATE=C              
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> other attached packages:
#>  [1] BSgenome.Hsapiens.UCSC.hg38_1.4.4 spiky_1.4.0                      
#>  [3] Rsamtools_2.14.0                  Biostrings_2.66.0                
#>  [5] XVector_0.38.0                    GenomicRanges_1.50.0             
#>  [7] GenomeInfoDb_1.34.0               IRanges_2.32.0                   
#>  [9] S4Vectors_0.36.0                  BiocGenerics_0.44.0              
#> [11] devtools_2.4.5                    usethis_2.1.6                    
#> loaded via a namespace (and not attached):
#>   [1] nlme_3.1-160                bitops_1.0-7               
#>   [3] matrixStats_0.62.0          fs_1.5.2                   
#>   [5] rprojroot_2.0.3             tools_4.2.1                
#>   [7] profvis_0.3.7               bslib_0.4.0                
#>   [9] utf8_1.2.2                  R6_2.5.1                   
#>  [11] DBI_1.1.3                   mgcv_1.8-41                
#>  [13] colorspace_2.0-3            urlchecker_1.0.1           
#>  [15] withr_2.5.0                 sp_1.5-0                   
#>  [17] tidyselect_1.2.0            prettyunits_1.1.1          
#>  [19] processx_3.8.0              compiler_4.2.1             
#>  [21] cli_3.4.1                   Biobase_2.58.0             
#>  [23] desc_1.4.2                  DelayedArray_0.24.0        
#>  [25] rtracklayer_1.58.0          sass_0.4.2                 
#>  [27] scales_1.2.1                mvtnorm_1.1-3              
#>  [29] callr_3.7.2                 stringr_1.4.1              
#>  [31] digest_0.6.30               rmarkdown_2.17             
#>  [33] pkgconfig_2.0.3             htmltools_0.5.3            
#>  [35] sessioninfo_1.2.2           MatrixGenerics_1.10.0      
#>  [37] fastmap_1.1.0               BSgenome_1.66.0            
#>  [39] htmlwidgets_1.5.4           rlang_1.0.6                
#>  [41] rstudioapi_0.14             shiny_1.7.3                
#>  [43] generics_0.1.3              BiocIO_1.8.0               
#>  [45] jquerylib_0.1.4             jsonlite_1.8.3             
#>  [47] BiocParallel_1.32.0         dplyr_1.0.10               
#>  [49] RCurl_1.98-1.9              magrittr_2.0.3             
#>  [51] GenomeInfoDbData_1.2.9      Formula_1.2-4              
#>  [53] Matrix_1.5-1                fansi_1.0.3                
#>  [55] Rcpp_1.0.9                  munsell_0.5.0              
#>  [57] lifecycle_1.0.3             stringi_1.7.8              
#>  [59] yaml_2.3.6                  SummarizedExperiment_1.28.0
#>  [61] zlibbioc_1.44.0             pkgbuild_1.3.1             
#>  [63] grid_4.2.1                  parallel_4.2.1             
#>  [65] promises_1.2.0.1            crayon_1.5.2               
#>  [67] miniUI_0.1.1.1              lattice_0.20-45            
#>  [69] splines_4.2.1               pillar_1.8.1               
#>  [71] knitr_1.40                  ps_1.7.2                   
#>  [73] rjson_0.2.21                BlandAltmanLeh_0.3.1       
#>  [75] codetools_0.2-18            pkgload_1.3.1              
#>  [77] XML_3.99-0.12               glue_1.6.2                 
#>  [79] evaluate_0.17               MBA_0.0-9                  
#>  [81] remotes_2.4.2               vctrs_0.5.0                
#>  [83] httpuv_1.6.6                gtable_0.3.1               
#>  [85] purrr_0.3.5                 assertthat_0.2.1           
#>  [87] ggplot2_3.3.6               cachem_1.0.6               
#>  [89] xfun_0.34                   mime_0.12                  
#>  [91] xtable_1.8-4                restfulr_0.0.15            
#>  [93] coda_0.19-4                 later_1.3.0                
#>  [95] survival_3.4-0              tibble_3.1.8               
#>  [97] GenomicAlignments_1.34.0    memoise_2.0.1              
#>  [99] bamlss_1.1-8                ellipsis_0.3.2


1. Shen, S. Y. et al. Sensitive tumour detection and classification using plasma cell-free dna methylomes. Nature 563, 579–583 (2018).

2. Shen, S. Y., Burgener, J. M., Bratman, S. V. & De Carvalho, D. D. Preparation of cfMeDIP-seq libraries for methylome profiling of plasma cell-free dna. Nature protocols 14, 2749–2780 (2019).

3. Wilson, S. L. et al. Sensitive and reproducible cell-free methylome quantification with synthetic spike-in controls. Cell Reports Methods 100294 (2022) doi:https://doi.org/10.1016/j.crmeth.2022.100294.