Last active
January 4, 2016 02:59
-
-
Save al2na/8558751 to your computer and use it in GitHub Desktop.
get O/E ration and CpG ratio and GC content for given GRanges object and BSgenome. Returns a matrix of O/E ratio, CpGcontent and GC content
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
require(GenomicRanges) | |
require(Biostrings) | |
#' get OE ratio and GC content for a given set of DNAstrings | |
getOE.strset<-function(str.set) | |
{ | |
di.mat=dinucleotideFrequency( str.set ) | |
a.mat =alphabetFrequency( str.set ,baseOnly=TRUE ) | |
exp=(a.mat[,2]*a.mat[,3])/width(str.set ) | |
obs=di.mat[,"CG"] | |
OE=obs/exp | |
cbind(oe=OE,CpGcont=obs/(width(str.set)-1),gc=100*(a.mat[,2]+a.mat[,3])/rowSums(a.mat[,1:4]) ) | |
} | |
#' get OE ratio and GC content for a given set of targetgenes | |
#' @param wins GRanges object | |
#' @param bs BSgenome object | |
getOE.gr<-function(wins,bs) | |
{ | |
str.set=getSeq(bs,wins) | |
getOE.strset(str.set) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
library(devtools)
source_url("https://gist.github.com/al2na/8558751/raw/186547f599175d6958ce547c806c4317f453483a/getOE.R")
#' wins: GRanges object
#' bs: BSgenome object
' example
getOE.gr(wins,bs=Mmusculus)