methylKit icon indicating copy to clipboard operation
methylKit copied to clipboard

provide simple function to find dmrs

Open alexg9010 opened this issue 5 years ago • 2 comments

#' Find regions of differential methylation
#' 
#' This function performs unsupervised segmentation of 
#' the methylation differences calculated from calculateDiffMeth.
#' Then it classifies hyper and hypo methylated segments based 
#' on a methylation difference threshold and joins 
#' neighbouring segments with the same class. 
#'
#' @param methylDiff methylDiff or methylDiffDB object generated with calculateDiffMeth
#' @param meth.diff integer methylation difference threshold
#'
#' @return A GRanges object with segment classification and information. 
#' 'seg.mean' column shows the mean methylation per segment. 
#' 'seg.group' column shows the segment groups obtained by mixture modeling
#' @export
#'
#' @examples
find_DMR <- function(methylDiff, meth.diff = 25) {
    
    # segment first
    mDiffRegion <- methSeg(methylDiffDB, )
    # reassign groups based on meth.diff cutoff
    mDiffRegion$seg.group <- "none"
    mDiffRegion[mDiffRegion$seg.mean < -meth.diff]$seg.group <- "hypo"
    mDiffRegion[mDiffRegion$seg.mean > meth.diff]$seg.group <- "hyper"
    # join neighbouring with same groups
    mDiffRegionJoined <- joinSegmentNeighbours(mDiffRegion)
    
    return(mDiffRegionJoined)
}

alexg9010 avatar Apr 29 '20 09:04 alexg9010

@al2na do you think this would make sense to be added? In general it is just a wrapper about existing functionality.

alexg9010 avatar Apr 29 '20 09:04 alexg9010

For aggregating region level statistics, we can do the same what methcp does, use either fisher's method or stouffer method

https://github.com/boyinggong/MethCP/blob/master/R/segmentMethCP.R https://github.com/boyinggong/MethCP/blob/master/R/utils.R

alexg9010 avatar May 06 '20 11:05 alexg9010