Last active
December 30, 2015 21:49
-
-
Save al2na/7889940 to your computer and use it in GitHub Desktop.
a version of tileMethylCounts where the chromosome names obtained from GRanges out of unique seqnames, so there will be no chr names that do not have coverage. see the discussion here: https://groups.google.com/forum/#!topic/methylkit_discussion/75y6dbrbCWI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setGeneric("tileMethylCounts2", | |
function(object,win.size=1000,step.size=1000,cov.bases=0) | |
standardGeneric("tileMethylCounts2") ) | |
setMethod("tileMethylCounts2", signature(object="methylRaw"), | |
function(object,win.size,step.size,cov.bases){ | |
g.meth =as(object,"GRanges") | |
chrs =as.character(unique(seqnames(g.meth))) | |
widths =seqlengths(g.meth) | |
all.wins=GRanges() | |
for(i in 1:length(chrs)) | |
{ | |
# get max length of feature covered chromosome | |
max.length=max(IRanges::end(g.meth[seqnames(g.meth)==chrs[i],])) | |
#get sliding windows with covered CpGs | |
numTiles=floor( (max.length-(win.size-step.size) )/step.size )+1 | |
temp.wins=GRanges(seqnames=rep(chrs[i],numTiles), | |
ranges=IRanges(start=1+0:(numTiles-1)*step.size, | |
width=rep(win.size,numTiles)) ) | |
all.wins=suppressWarnings(c(all.wins,temp.wins)) | |
} | |
regionCounts(object,all.wins,cov.bases,strand.aware=FALSE) | |
} | |
) | |
#' @aliases tileMethylCounts,methylRawList-method | |
#' @rdname tileMethylCounts-methods | |
setMethod("tileMethylCounts2", signature(object="methylRawList"), | |
function(object,win.size,step.size,cov.bases){ | |
new.list=lapply(object,tileMethylCounts,win.size,step.size,cov.bases) | |
new("methylRawList", new.list,treatment=object@treatment) | |
}) | |
#' @aliases tileMethylCounts,methylBase-method | |
#' @rdname tileMethylCounts-methods | |
setMethod("tileMethylCounts2", signature(object="methylBase"), | |
function(object,win.size,step.size,cov.bases){ | |
g.meth =as(object,"GRanges") | |
chrs =as.character(unique(seqnames(g.meth))) | |
widths =seqlengths(g.meth) | |
all.wins=GRanges() | |
for(i in 1:length(chrs)) | |
{ | |
# get max length of feature covered chromosome | |
max.length=max(IRanges::end(g.meth[seqnames(g.meth)==chrs[i],])) | |
#get sliding windows with covered CpGs | |
numTiles=floor( (max.length-(win.size-step.size) )/step.size )+1 | |
temp.wins=GRanges(seqnames=rep(chrs[i],numTiles), | |
ranges=IRanges(start=1+0:(numTiles-1)*step.size, | |
width=rep(win.size,numTiles)) ) | |
all.wins=suppressWarnings(c(all.wins,temp.wins)) | |
} | |
regionCounts(object,all.wins,cov.bases,strand.aware=FALSE) | |
} | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment