Browse code

Fixed subseting for ReferenceSequenceTrack

Robert Ivánek authored on 19/04/2021 19:45:20
Showing 3 changed files

... ...
@@ -199,10 +199,13 @@ setMethod("subseq", "SequenceTrack", function(x, start = NA, end = NA, width = N
199 199
 })
200 200
 
201 201
 setMethod("subseq", "ReferenceSequenceTrack", function(x, start = NA, end = NA, width = NA) {
202
+    if (sum(c(is.na(start[1]),is.na(end[1]),is.na(width[1]))) >= 2) {
203
+      stop("Two out of the three in 'start', 'end' and 'width' have to be provided")
204
+    }
202 205
     if (!is.na(start[1] + end[1] + width[1])) {
203 206
         warning("All 'start', 'stop' and 'width' are provided, ignoring 'width'")
204 207
         width <- NA
205
-    }
208
+    } 
206 209
     ## We want start and end to be set if width is provided
207 210
     if (!is.na(width[1])) {
208 211
         if (is.na(start) && is.na(end)) {
... ...
@@ -120,8 +120,8 @@ test_that("subseq works", {
120 120
     expect_identical(as.character(subseq(seqTrack.dna, start=1, end=10)), as.character(DNAString("TAAAGGGACT")))
121 121
 
122 122
 
123
-    expect_error(subseq(SequenceTrack(fastafile, chromosome="chr1")), "at least two out of ")
124
-    expect_error(subseq(SequenceTrack(fastafile, chromosome="chr1"), start=1), "at least two out of ")
123
+    expect_error(subseq(SequenceTrack(fastafile, chromosome="chr1")), "Two out of the three in")
124
+    expect_error(subseq(SequenceTrack(fastafile, chromosome="chr1"), start=1), "Two out of the three in")
125 125
     expect_warning(as.character(subseq(SequenceTrack(fastafile, chromosome="chr1"), start=1, end=10, width=10)), "All ")
126 126
     expect_error(as.character(subseq(SequenceTrack(fastafile, chromosome="chr1"), start=NA, end=NA, width=10)), "Two ")
127 127
     expect_identical(as.character(subseq(SequenceTrack(fastafile, chromosome="chr1"), start=1, width=10)), as.character(DNAString("CTANGAGACG")))
... ...
@@ -160,7 +160,7 @@ test_that("conversion of junction to list for plotting works", {
160 160
     ## negative filterTolerance
161 161
     expect_warning(.convert.summarizedJunctions.to.sashimi.junctions(juns, filter=filt, filterTolerance=-1),
162 162
                    "can't be negative, taking absolute value of it")
163
-    ## transfromation
163
+    ## transformation
164 164
     expect_identical(.convert.summarizedJunctions.to.sashimi.junctions(juns, trans=list(function(x) {x})), out)
165 165
     expect_error(.convert.summarizedJunctions.to.sashimi.junctions(juns, trans=1),"must be a function with a single argument")
166 166
     expect_error(.convert.summarizedJunctions.to.sashimi.junctions(juns, trans=function(x) {x[-1]}),"invalid output")