[BioC] selecting score(GRanges_object) based on coordinates

Philip Lijnzaad p.lijnzaad at umcutrecht.nl
Mon Feb 3 13:38:28 CET 2014


On 2014-02-03 13:07, Philip Lijnzaad wrote:
> Dear all,
>
> I can't seem to select a run of scores from GRanges object, using the
> coordinates from another GRanges object.
>
> An example:
>
> coverage <- GRanges(seqnames="chrI",
>
>              ranges=IRanges(start=c(1,11,21), width=10),
>
>              score=c(0, 42, 0)
>
>              )
>
> feature <- GRanges(seqnames="chrI", ranges=IRanges(start=5, end=25))
>
> In ascii this looks like:
>
> coverage: ...__________----------__________...
>
> feature:  .......xxxxxxxxxxxxxxxxxxxxx........
>
> wanted:          _____----------______
>
> I tried using
>
>    score(subsetByOverlaps(coverage, feature))
>
> which I hope  would give me back
>
>    0  0  0  0  0 42 42 42 42 42 42 42 42 42 42  0  0  0  0  0
>
> or maybe
>
>   numeric-Rle of length 20 with 3 runs
>
>     Lengths:  5 10  5
>
>     Values :  0 42  0

Mmm ... seems I stumbled across a solution myself. If I do

    scores <- Rle(score(coverage), width(ranges(coverage)))


I can do

   scores[ ranges(feature) ]


which seems to do exactly what I need. Is this the right (and fastest) 
way? If so, might be nice to have this
in one of the vignettes.

Cheers,

Ph

------------------------------------------------------------------------------

De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is
uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht
ontvangt, wordt u verzocht de inhoud niet te gebruiken en de afzender direct
te informeren door het bericht te retourneren. Het Universitair Medisch
Centrum Utrecht is een publiekrechtelijke rechtspersoon in de zin van de W.H.W.
(Wet Hoger Onderwijs en Wetenschappelijk Onderzoek) en staat geregistreerd bij
de Kamer van Koophandel voor Midden-Nederland onder nr. 30244197.

Denk s.v.p aan het milieu voor u deze e-mail afdrukt.

------------------------------------------------------------------------------

This message may contain confidential information and is...{{dropped:8}}



More information about the Bioconductor mailing list