Entering edit mode
Stephanie M. Gogarten
▴
870
@stephanie-m-gogarten-5121
Last seen 5 months ago
University of Washington
lapply
used to work with GRanges objects in Bioconductor 3.6, but it no longer works in 3.7. What is the recommended replacement?
> x <- GRanges(seqnames=c(1,1), ranges=IRanges(start=c(1,10), width=10))
> lapply(x, print)
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘getListElement’ for signature ‘"GRanges"’
> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.6
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages:
[1] parallel stats4 stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] GenomicRanges_1.32.3 GenomeInfoDb_1.16.0 IRanges_2.14.10
[4] S4Vectors_0.18.2 BiocGenerics_0.26.0
loaded via a namespace (and not attached):
[1] zlibbioc_1.26.0 compiler_3.5.0 XVector_0.20.0
[4] GenomeInfoDbData_1.1.0 RCurl_1.95-4.10 bitops_1.0-6
Thanks! I remembered that this thread existed, but failed to find it because I was searching for "lapply" instead of "apply" or "sapply". And I thought it might be useful to have this question answered on the support site.
Hi, I thought this might be relevant too:
how do I subset the Granges object by an element of the metadata? if i want to access to the one specific chr I can:
r[seqnames(r)=="chr7"]
but if i want the granges subset of an entry whose id is specified in the metadata?
both
r[r$tx_name=="uc057bpa.1"]
and
r[elementMetadata(r)$tx_name=="uc057bpa.1"]
give:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘getListElement’ for signature ‘"GRanges"’
elementMetadata(r)$tx_name=="uc057bpa.1" and r$tx_name=="uc057bpa.1" are LogicalLists, how do I use them to select the ranges I need?
many thanks
There can be multiple transcript names per element of the GRanges. How do you want to resolve that case? If you know that there is exactly one per range, just
unlist()
it, otherwise you might want something likeany()
. The point is, you need to consider the complexity of the data.