[Bioc-devel] GenomicRanges List subclass and apply
hp@ge@ @ending from fredhutch@org
Mon May 14 20:15:01 CEST 2018
You can use
sapply(seq_along(gr), function(i) print(gr[i]))
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.
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, gr[1:2] still works normally.
> Are there any recommendations on a workaround for this issue without
> resorting back to for loops?
> Thanks all,
> [[alternative HTML version deleted]]
> Bioc-devel at r-project.org mailing list
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: hpages at fredhutch.org
Phone: (206) 667-5791
Fax: (206) 667-1319
More information about the Bioc-devel