Re: [Bioc-devel] GenomicRanges List subclass and apply

2018-05-14 Thread Jack Fu

Thanks all -> I definitely see the appeal of vectorization.
I'm going to take a few pokes to do just that.

Best,
Jack

Hervé Pagès wrote:


Hi Jack,

You can use

  sapply(seq_along(gr), function(i) print(gr[i]))

instead of

  sapply(gr, print)

But yes, as Michael noted, looping on a GRanges or IRanges object
is generally not efficient and should be avoided. There is almost
always a "vectorized" solution and it's generally much faster.
However, depending on what you are trying to do exactly, coming up
with a "vectorized" solution can be tricky.

Cheers,
H.

On 05/14/2018 07:28 AM, Jack Fu wrote:

Hey all,

I think some of the recent changes to GRanges has affected using the
apply class functions with GRanges objects:

   o GenomicRanges now is a List subclass. This means that GRanges 
objects
and their derivatives are now considered list-like objects 
(even though
[[ don't work on them yet, this will be implemented in 
Bioconductor 3.8).



The following code will throw:
gr <- GRanges(1, IRanges(1:2, 3:4))
sapply(gr, print)

Error in (function (classes, fdef, mtable)  :
unable to find an inherited method for function 'getListElement' for
signature '"GRanges"'

Access using gr[1], gr[1:2] still works normally.
Are there any recommendations on a workaround for this issue without
resorting back to for loops?

Thanks all,
Jack

[[alternative HTML version deleted]]

___
Bioc-devel@r-project.org mailing list
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_bioc-2Ddevel=DwICAg=eRAMFD45gAfqt84VtBcfhQ=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA=k5vpJVkh58WH_4jBoE8Hcz_bmop9lW6D_bqF-tDiDm8=s_wv4S9c-aOZ3KFs8bcPcZL8UJUz0xC6cOi4LMqmkRc= 







___
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel


Re: [Bioc-devel] GenomicRanges List subclass and apply

2018-05-14 Thread Hervé Pagès

Hi Jack,

You can use

  sapply(seq_along(gr), function(i) print(gr[i]))

instead of

  sapply(gr, print)

But yes, as Michael noted, looping on a GRanges or IRanges object
is generally not efficient and should be avoided. There is almost
always a "vectorized" solution and it's generally much faster.
However, depending on what you are trying to do exactly, coming up
with a "vectorized" solution can be tricky.

Cheers,
H.

On 05/14/2018 07:28 AM, Jack Fu wrote:

Hey all,

I think some of the recent changes to GRanges has affected using the
apply class functions with GRanges objects:

   o GenomicRanges now is a List subclass. This means that GRanges objects
and their derivatives are now considered list-like objects (even though
[[ don't work on them yet, this will be implemented in Bioconductor 
3.8).


The following code will throw:
gr <- GRanges(1, IRanges(1:2, 3:4))
sapply(gr, print)

Error in (function (classes, fdef, mtable)  :
unable to find an inherited method for function 'getListElement' for
signature '"GRanges"'

Access using gr[1], gr[1:2] still works normally.
Are there any recommendations on a workaround for this issue without
resorting back to for loops?

Thanks all,
Jack

[[alternative HTML version deleted]]

___
Bioc-devel@r-project.org mailing list
https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_bioc-2Ddevel=DwICAg=eRAMFD45gAfqt84VtBcfhQ=BK7q3XeAvimeWdGbWY_wJYbW0WYiZvSXAJJKaaPhzWA=k5vpJVkh58WH_4jBoE8Hcz_bmop9lW6D_bqF-tDiDm8=s_wv4S9c-aOZ3KFs8bcPcZL8UJUz0xC6cOi4LMqmkRc=



--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:(206) 667-1319

___
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel


Re: [Bioc-devel] GenomicRanges List subclass and apply

2018-05-14 Thread Michael Lawrence
It's possible that you could vectorize this code. Maybe open an issue
on the support site.

On Mon, May 14, 2018 at 7:56 AM, Jack Fu  wrote:
> Hi Michael,
>
> Mostly for sending each element of the GRanges object to a custom function
> that runs an identical analysis on each element.
> I have some functions that take as input a single range -> calculate number
> of reads that overlap the range -> subset the range into K number of
> segments based on coverage patterns across the range.
>
> Thanks!
> Jack
>
>
> Michael Lawrence wrote:
>
> Just out of curiosity, why are you looping over a GRanges in the first
> place?
>
> On Mon, May 14, 2018 at 7:28 AM, Jack Fu  wrote:
>
> Hey all,
>
> I think some of the recent changes to GRanges has affected using the
> apply class functions with GRanges objects:
>
>   o GenomicRanges now is a List subclass. This means that GRanges objects
>and their derivatives are now considered list-like objects (even
> though
>[[ don't work on them yet, this will be implemented in Bioconductor
> 3.8).
>
>
> The following code will throw:
> gr <- GRanges(1, IRanges(1:2, 3:4))
> sapply(gr, print)
>
> Error in (function (classes, fdef, mtable)  :
>unable to find an inherited method for function 'getListElement' for
> signature '"GRanges"'
>
> Access using gr[1], gr[1:2] still works normally.
> Are there any recommendations on a workaround for this issue without
> resorting back to for loops?
>
> Thanks all,
> Jack
>
> [[alternative HTML version deleted]]
>
> ___
> Bioc-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>
>
>

___
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel


Re: [Bioc-devel] GenomicRanges List subclass and apply

2018-05-14 Thread Jack Fu
Hi Michael,

Mostly for sending each element of the GRanges object to a custom 
function that runs an identical analysis on each element.
I have some functions that take as input a single range -> calculate 
number of reads that overlap the range -> subset the range into K number 
of segments based on coverage patterns across the range.

Thanks!
Jack

Michael Lawrence wrote:
> Just out of curiosity, why are you looping over a GRanges in the first place?
>
> On Mon, May 14, 2018 at 7:28 AM, Jack Fu  wrote:
>> Hey all,
>>
>> I think some of the recent changes to GRanges has affected using the
>> apply class functions with GRanges objects:
>>
>>o GenomicRanges now is a List subclass. This means that GRanges objects
>> and their derivatives are now considered list-like objects (even 
>> though
>> [[ don't work on them yet, this will be implemented in Bioconductor 
>> 3.8).
>>
>>
>> The following code will throw:
>> gr<- GRanges(1, IRanges(1:2, 3:4))
>> sapply(gr, print)
>>
>> Error in (function (classes, fdef, mtable)  :
>> unable to find an inherited method for function 'getListElement' for
>> signature '"GRanges"'
>>
>> Access using gr[1], gr[1:2] still works normally.
>> Are there any recommendations on a workaround for this issue without
>> resorting back to for loops?
>>
>> Thanks all,
>> Jack
>>
>>  [[alternative HTML version deleted]]
>>
>> ___
>> Bioc-devel@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>>
>
>


[[alternative HTML version deleted]]

___
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel


Re: [Bioc-devel] GenomicRanges List subclass and apply

2018-05-14 Thread Michael Lawrence
Just out of curiosity, why are you looping over a GRanges in the first place?

On Mon, May 14, 2018 at 7:28 AM, Jack Fu  wrote:
> Hey all,
>
> I think some of the recent changes to GRanges has affected using the
> apply class functions with GRanges objects:
>
>   o GenomicRanges now is a List subclass. This means that GRanges objects
>and their derivatives are now considered list-like objects (even though
>[[ don't work on them yet, this will be implemented in Bioconductor 
> 3.8).
>
>
> The following code will throw:
> gr <- GRanges(1, IRanges(1:2, 3:4))
> sapply(gr, print)
>
> Error in (function (classes, fdef, mtable)  :
>unable to find an inherited method for function 'getListElement' for
> signature '"GRanges"'
>
> Access using gr[1], gr[1:2] still works normally.
> Are there any recommendations on a workaround for this issue without
> resorting back to for loops?
>
> Thanks all,
> Jack
>
> [[alternative HTML version deleted]]
>
> ___
> Bioc-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/bioc-devel
>

___
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel


[Bioc-devel] GenomicRanges List subclass and apply

2018-05-14 Thread Jack Fu
Hey all,

I think some of the recent changes to GRanges has affected using the 
apply class functions with GRanges objects:

  o GenomicRanges now is a List subclass. This means that GRanges objects
   and their derivatives are now considered list-like objects (even though
   [[ don't work on them yet, this will be implemented in Bioconductor 3.8).


The following code will throw:
gr <- GRanges(1, IRanges(1:2, 3:4))
sapply(gr, print)

Error in (function (classes, fdef, mtable)  :
   unable to find an inherited method for function 'getListElement' for 
signature '"GRanges"'

Access using gr[1], gr[1:2] still works normally.
Are there any recommendations on a workaround for this issue without 
resorting back to for loops?

Thanks all,
Jack

[[alternative HTML version deleted]]

___
Bioc-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/bioc-devel