slidingIRanges in IRanges ... odd behavior
1
1
Entering edit mode
@storybenjamin-11722
Last seen 7 months ago
Germany
slidingIRanges
function (len, width, shift = 1L) 
{
    start <- seq(1L, len - width, by = shift)
    end <- seq(width, len, by = shift)
    IRanges(start, end)
}
<environment: namespace:IRanges>

It seems to me that this function doesn't really work... given that let's say I'm trying to generate a 1 nt sliding window across a sequence of length 10.

> length(seq(1L,10-1))
[1] 9
> length(seq(1,10))
[1] 10
> 

Should it be? start <- seq(1L, len - width + 1, by = shift) Or maybe I'm missing something... I was just trying to generate a sliding IRanges window.

IRanges • 986 views
ADD COMMENT
0
Entering edit mode

Maybe I'm the first person to ever use the function!

https://code.bioconductor.org/search/search?q=slidingIRanges

ADD REPLY
1
Entering edit mode
@herve-pages-1542
Last seen 1 day ago
Seattle, WA, United States
> slidingIRanges(7, width=7)
Error in seq.default(1L, len - width, by = shift) : 
  wrong sign in 'by' argument

> slidingIRanges(10, width=7)
IRanges object with 4 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         7         7
  [2]         2         8         7
  [3]         3         9         7
  [4]         1        10        10  <-- wrong!
Warning messages:
1: In 1 + end - start :
  longer object length is not a multiple of shorter object length
2: In ans[] <- x :
  number of items to replace is not a multiple of replacement length

> slidingIRanges(10, width=7, shift=3)
IRanges object with 2 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         7         7
  [2]         1        10        10  <-- wrong!

Yes this function seems quite broken and is not documented so you're probably the first person to use it since it was added in 2015! Please open an issue here.

Thanks,

H.

ADD COMMENT
0
Entering edit mode

I ran into the same problem: see here the updated function, where I have included the fix by story.benjamin. I have tested it for widths and shift sizes and it works consistently. See the github issue to request a change: https://github.com/Bioconductor/IRanges/issues/47

slidingIRanges <- function (len, width, shift = 1L)  {
  start <- seq(1L, len - width + 1 , by = shift)
  end <- seq(width, len, by = shift)
  IRanges(start, end)
}

> slidingIRanges(7, width=7)
IRanges object with 1 range and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         7         7

> slidingIRanges(10, width=7)
IRanges object with 4 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         7         7
  [2]         2         8         7
  [3]         3         9         7
  [4]         4        10         7
ADD REPLY

Login before adding your answer.

Traffic: 648 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6