[Bioc-sig-seq] flank vs shift behaviour on GRanges objects

Patrick Aboyoun paboyoun at fhcrc.org
Thu Aug 26 08:00:39 CEST 2010


  Aaron,
shift() currently doesn't respect strand because the most common use 
case for the function is to change from a 0-based index system to a 
1-based index system, which is strand independent. The shift argument to 
the shift function, however, does accept an integer vector so you could 
use the following code, or something similar, to perform this operation 
somewhat efficiently:

amount <- strand(g1)
runValue(amount) <- ifelse(runValue(amount) == "-", -1L, 1L)
shift(g1, as.vector(amount))

Perhaps this can be made simpler in the future if more users what 
strand-dependent shifting.


Patrick



On 8/25/10 9:54 PM, Aaron Statham wrote:
> Hi all,
>
> Just ran into this - flank() takes notice of the strand for GRanges objects,
> whilst shift() doesn't.
> Would it make sense for shift to use the strand in the GRanges method, or is
> there a nice alternative? (at the moment I'm doing a shift per strand)
>
>
>> g1<- GRanges(rep("chr1", 3), IRanges(rep(5, 3), width=1), c("+","-","*"))
>> g1
> GRanges with 3 ranges and 0 elementMetadata values
>      seqnames    ranges strand |
>         <Rle>  <IRanges>   <Rle>  |
> [1]     chr1    [5, 5]      + |
> [2]     chr1    [5, 5]      - |
> [3]     chr1    [5, 5]      * |
>
> seqlengths
>   chr1
>     NA
>> flank(g1,3)
> GRanges with 3 ranges and 0 elementMetadata values
>      seqnames    ranges strand |
>         <Rle>  <IRanges>   <Rle>  |
> [1]     chr1    [2, 4]      + |
> [2]     chr1    [6, 8]      - |
> [3]     chr1    [2, 4]      * |
>
> seqlengths
>   chr1
>     NA
>> shift(g1,3)
> GRanges with 3 ranges and 0 elementMetadata values
>      seqnames    ranges strand |
>         <Rle>  <IRanges>   <Rle>  |
> [1]     chr1    [8, 8]      + |
> [2]     chr1    [8, 8]      - |
> [3]     chr1    [8, 8]      * |
>
> seqlengths
>   chr1
>     NA
>
> R version 2.11.0 (2010-04-22)
> x86_64-unknown-linux-gnu
>
> locale:
>   [1] LC_CTYPE=en_AU.UTF-8       LC_NUMERIC=C
>   [3] LC_TIME=en_AU.UTF-8        LC_COLLATE=en_AU.UTF-8
>   [5] LC_MONETARY=C              LC_MESSAGES=en_AU.UTF-8
>   [7] LC_PAPER=en_AU.UTF-8       LC_NAME=C
>   [9] LC_ADDRESS=C               LC_TELEPHONE=C
> [11] LC_MEASUREMENT=en_AU.UTF-8 LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] GenomicRanges_1.0.7 IRanges_1.6.15
>
> Thanks,
> Aaron
>



More information about the Bioc-sig-sequencing mailing list