Skip to content

Commit

Permalink
readAnnotate.R:
Browse files Browse the repository at this point in the history
	- annotateWithFeature: feature.name taken by default from
	a variable
  • Loading branch information
frenkiboy committed Nov 12, 2013
1 parent d251f7f commit e23c639
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions R/readAnnotate.R
Expand Up @@ -579,7 +579,7 @@ setGeneric("annotateWithFeatureFlank",
#' @rdname annotateWithFeatureFlank-methods
setMethod( "annotateWithFeatureFlank",
signature(target = "GRanges",feature="GRanges",flank="GRanges"),
function(target, feature, flank,feature.name,flank.name,strand,
function(target, feature, flank, feature.name, flank.name, strand,
intersect.chr){


Expand All @@ -589,7 +589,7 @@ setMethod( "annotateWithFeatureFlank",
unique(as.character(seqnames(feature))))
if(length(chrs) == 0)
stop('target and feature do not have intersecting chromosomes')
target=target[seqnames(target) %in% chrs]
target = target[seqnames(target) %in% chrs]
feature = feature[seqnames(feature) %in% chrs]
}

Expand Down Expand Up @@ -649,10 +649,12 @@ setMethod( "annotateWithFeatureFlank",
#' sides as much as \code{extend}
#' @param feature.name name of the annotation feature.
#' For example: H3K4me1,CpGisland etc.
#' by default the name is taken from the given variable
#' @param intersect.chr boolean, whether to select only chromosomes that are
#' common to feature and target. FALSE by default

#' @usage annotateWithFeature(target,feature,strand=FALSE,extend=0,feature.name="feat1")
#' @usage annotateWithFeature(target,feature,strand=FALSE,extend=0,
#' feature.name="feat1", intersect.chr=FALSE)
#' @return returns an \code{AnnotationByFeature} object
#'
#'
Expand All @@ -670,7 +672,7 @@ setGeneric("annotateWithFeature",
feature,
strand=FALSE,
extend=0,
feature.name="feat1",
feature.name=NULL,
intersect.chr=FALSE)
standardGeneric("annotateWithFeature") )

Expand All @@ -680,12 +682,13 @@ setMethod("annotateWithFeature",
signature(target = "GRanges",feature="GRanges"),
function(target, feature, strand,extend,feature.name,intersect.chr){

if( ! strand){strand(target)="*"}
memb=rep(0,length(target))
if(is.null(feature.name))
feature.name=deparse(substitute(feature))

if(extend>0){
message('extending features...')
feature = resize(feature, width=(width(feature)+2*extend), fix='center')
feature = resize(feature, width=(width(feature)+2*extend),
fix='center')
}

# selects common chromosomes for target and feature
Expand All @@ -699,6 +702,9 @@ setMethod("annotateWithFeature",
feature = feature[seqnames(feature) %in% chrs]
}

if( ! strand){strand(target)="*"}
memb=rep(0,length(target))

memb[countOverlaps(target,feature) > 0] = 1

annotation = c( 100*sum(memb > 0)/length(memb) ,
Expand Down

0 comments on commit e23c639

Please sign in to comment.