Last active
March 23, 2020 22:20
-
-
Save al2na/7097442 to your computer and use it in GitHub Desktop.
getting average score of a GRanges over another GRanges object.
summarizeScores(loc.gr,score.gr,score.col)
This file contains hidden or 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
.libPaths("/work2/gschub/altuna/RlibsDev") | |
require(data.table) | |
summarizeScores<-function(loc.gr,score.gr,score.col){ | |
ov <- as.matrix(findOverlaps(loc.gr,score.gr)) | |
dt=data.table(id=ov[,1],score=values(score.gr)[ov[,2],which(names(values(score.gr))==score.col)]) | |
dt=dt[,list(av=mean(score)),by=id] | |
res=loc.gr[dt$id,] | |
mcols(res)=DataFrame(mcols(res),score=dt$av) | |
res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment