Browse code

refactorization of plotting code

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/bsseq@71540 bc3139a8-67e5-0310-9ffc-ced21a209358

Kasper D. Hansen authored on 29/11/2012 01:20:27
Showing1 changed files

... ...
@@ -127,25 +127,27 @@ plotManyRegions <- function(BSseq, regions = NULL, extend = 0, main = "", addReg
127 127
     main
128 128
 }
129 129
 
130
-
131
-.plotSmoothData <- function(BSseq, region, extend, addRegions, col, lty, lwd, regionCol,
132
-                            addTicks, addPoints, pointsMinCov, highlightMain) {
133
-    if(is.data.frame(region))
134
-        region <- data.frame2GRanges(region)
135
-
136
-    if(!is.null(region)) {
130
+.bsGetGr <- function(object, region, extend) {
131
+    if(is.null(region)) {
132
+        gr <- GRanges(seqnames = seqnames(object)[1],
133
+                      ranges = IRanges(start = min(start(object)),
134
+                      end = max(start(object))))
135
+    } else {
137 136
         if(is(region, "data.frame"))
138 137
             gr <- data.frame2GRanges(region, keepColumns = FALSE)
139 138
         else
140 139
             gr <- region
141 140
         if(!is(gr, "GRanges") || length(gr) != 1)
142 141
             stop("'region' needs to be either a 'data.frame' (with a single row) or a 'GRanges' (with a single element)")
143
-    } else {
144
-        gr <- GRanges(seqnames = seqnames(BSseq)[1],
145
-                      ranges = IRanges(start = min(start(BSseq)),
146
-                      end = max(start(BSseq))))
142
+        gr <- resize(gr, width = 2*extend + width(gr), fix = "center")
147 143
     }
148
-    gr <- resize(gr, width = 2*extend + width(gr), fix = "center")
144
+    gr
145
+}
146
+
147
+
148
+.plotSmoothData <- function(BSseq, region, extend, addRegions, col, lty, lwd, regionCol,
149
+                            addTicks, addPoints, pointsMinCov, highlightMain) {
150
+    gr <- .bsGetGr(Bsseq, region, extend)
149 151
     BSseq <- subsetByOverlaps(BSseq, gr)
150 152
     
151 153
     ## Extract basic information
... ...
@@ -206,7 +208,8 @@ plotRegion <- function(BSseq, region = NULL, extend = 0, main = "", addRegions =
206 208
                             col = col, lty = lty, lwd = lwd, regionCol = regionCol,
207 209
                             addTicks = addTicks, addPoints = addPoints,
208 210
                             pointsMinCov = pointsMinCov, highlightMain = highlightMain)
209
-
211
+    gr <- .bsGetGr(BSseq, region, extend)
212
+    
210 213
     if(!is.null(BSseqTstat)) {
211 214
         if(!is.null(BSseqTstat))
212 215
             BSseqTstat <- subsetByOverlaps(BSseqTstat, gr)