Skip to content

Instantly share code, notes, and snippets.

@al2na
Last active January 4, 2016 02:59
Show Gist options
  • Save al2na/8558751 to your computer and use it in GitHub Desktop.
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
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)
}
@al2na
Copy link
Author

al2na commented Jan 22, 2014

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment