Browse code

0.99.18. Fix the bug of subAxt

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

Ge Tan authored on 12/03/2014 18:54:14
Showing 3 changed files

... ...
@@ -1,6 +1,6 @@
1 1
 Package: CNEr 
2
-Version: 0.99.17
3
-Date: 2014-03-11
2
+Version: 0.99.18
3
+Date: 2014-03-12
4 4
 Title: CNE detection and visualization.
5 5
 Description: Large-scale identification and advanced visualization of sets of conserved noncoding elements.
6 6
 Author: Ge Tan <ge.tan09@imperial.ac.uk> 
... ...
@@ -131,12 +131,12 @@ setMethod("subAxt", signature(x="Axt", chr="character",
131 131
       stop("qSize must be an integer object.")
132 132
     }
133 133
   }
134
-  start <- as.integer(start)
135
-  end <- as.integer(end)
136 134
   searchGRanges <- GRanges(seqnames=chr,
137 135
                            ranges=IRanges(start=start, end=end),
138 136
                            strand="+")
139 137
   searchGRanges <- reduce(searchGRanges)
138
+  start <- start(searchGRanges)
139
+  end <- end(searchGRanges)
140 140
   if(select == "target"){
141 141
     ## First we find the axts totally within the coordinates
142 142
     hitsWithin <- findOverlaps(targetRanges(x),
... ...
@@ -152,9 +152,9 @@ setMethod("subAxt", signature(x="Axt", chr="character",
152 152
     newAxts = list()
153 153
     if(length(hitsPartial) > 0L){
154 154
       newStarts <- pmax(start(targetRanges(x)[queryHits(hitsPartial)]), 
155
-                        start[subjectHits(hitsPartial)])
155
+                        start(searchGRanges)[subjectHits(hitsPartial)])
156 156
       newEnds <- pmin(end(targetRanges(x)[queryHits(hitsPartial)]), 
157
-                      end[subjectHits(hitsPartial)])
157
+                      end(searchGRanges)[subjectHits(hitsPartial)])
158 158
       for(i in 1:length(hitsPartial)){
159 159
         newAxts[[i]] <- subAln(x[queryHits(hitsPartial[i])], 
160 160
                                newStarts[i], newEnds[i],
... ...
@@ -177,9 +177,9 @@ setMethod("subAxt", signature(x="Axt", chr="character",
177 177
     newAxts = list()
178 178
     if(length(hitsPartial) > 0L){
179 179
       newStarts <- pmax(start(queryRanges(x))[queryHits(hitsPartial)], 
180
-                        start[subjectHits(hitsPartial)])
180
+                        start(searchGRanges)[subjectHits(hitsPartial)])
181 181
       newEnds <- pmin(end(queryRanges(x))[queryHits(hitsPartial)], 
182
-                      end[subjectHits(hitsPartial)])
182
+                      end(searchGRanges)[subjectHits(hitsPartial)])
183 183
       for(i in 1:length(hitsPartial)){
184 184
         newAxts[[i]] <- subAln(x[queryHits(hitsPartial[i])], 
185 185
                                newStarts[i], newEnds[i],
... ...
@@ -192,6 +192,7 @@ setMethod("subAxt", signature(x="Axt", chr="character",
192 192
                              ranges=IRanges(start=qSize-end+1,
193 193
                                             end=qSize-start+1),
194 194
                              strand="-")
195
+    searchGRanges <- reduce(searchGRanges)
195 196
     hitsNegativeWithin <- findOverlaps(queryRanges(x),
196 197
                                        searchGRanges, type="within",
197 198
                                        select="all")
... ...
@@ -204,9 +205,9 @@ setMethod("subAxt", signature(x="Axt", chr="character",
204 205
     newAxts2 = list()
205 206
     if(length(hitsPartial) > 0L){
206 207
       newStarts <- pmax(start(queryRanges(x))[queryHits(hitsPartial)], 
207
-                        qSize-end+1[subjectHits(hitsPartial)])
208
+                        (qSize-end(searchGRanges)+1)[subjectHits(hitsPartial)])
208 209
       newEnds <- pmin(end(queryRanges(x))[queryHits(hitsPartial)], 
209
-                      qSize-start+1[subjectHits(hitsPartial)])
210
+                      (qSize-start(searchGRanges)+1)[subjectHits(hitsPartial)])
210 211
       for(i in 1:length(hitsPartial)){
211 212
         newAxts2[[i]] <- subAln(x[queryHits(hitsPartial[i])], 
212 213
                                 newStarts[i], newEnds[i],
... ...
@@ -1,17 +1,20 @@
1 1
 
2 2
 
3 3
 test_subAxt <- function(){
4
-  #axtFilesHg19DanRer7 <- file.path(system.file("extdata", package="CNEr"),
5
-  #                                 "hg19.danRer7.net.axt")
6
-  #axtHg19DanRer7 <- readAxt(axtFilesHg19DanRer7)
4
+  data(axtHg19DanRer7)
7 5
   ## Check the nr of axts
8
-  #checkIdentical(length(axtHg19DanRer7), 133L)
6
+  checkIdentical(length(axtHg19DanRer7), 133L)
9 7
 
10 8
   ## Check the subAxt on target
11
-  #foo <- subAxt(axtHg19DanRer7, chr="chr11", start=31500113, end=31500120, 
12
-  #              select="target")
13
-  #checkIdentical(as.character(targetSeqs(foo)), "AAATGCAG")
14
-  #checkIdentical(as.character(querySeqs(foo)), "GAGTGC-T")
9
+  foo <- subAxt(axtHg19DanRer7, chr="chr11", start=31500113, end=31500120, 
10
+                select="target")
11
+  checkIdentical(as.character(targetSeqs(foo)), "AAATGCAG")
12
+  checkIdentical(as.character(querySeqs(foo)), "GAGTGC-T")
15 13
 
14
+  ## Check the subAxt on multiple ranges
15
+  foo <- subAxt(axtHg19DanRer7, chr="chr11", start=c(31082021, 32461267),
16
+                end=c(31082862,32461581), select="target")
17
+  checkIdentical(length(foo), 3L)
18
+  
16 19
 }
17 20