R scripts from Ze Zhang often used in DNA methylation analyses. Not the most clean but should be helpful