Question: seqlengths is not an exported object from namespace GenomicRanges
1
19 days ago by
Germany

?GRanges mentions the accessor function seqlengths(). Trying to use it seems to be throwing an error about that not being exported. Hmm...looks like I am overlooking something. But what? :-)

granges <- GenomicRanges::GRanges(
seqnames = 'chr1',
ranges = IRanges::IRanges(start = 100, end = 200),
strand = '-',
seqlengths = c(chr1 = 1000))

GenomicRanges::seqlengths(granges)
Error: 'seqlengths' is not an exported object from 'namespace:GenomicRanges'

genomicranges • 44 views
modified 19 days ago by Michael Lawrence11k • written 19 days ago by Aditya120
Answer: seqlengths is not an exported object from namespace GenomicRanges
4
19 days ago by
United States
Michael Lawrence11k wrote:

It's defined by the GenomeInfoDb package. To find that out, you could print the seqlengths() function at the console,

> seqlengths
standardGeneric for "seqlengths" defined from package "GenomeInfoDb"

function (x)
standardGeneric("seqlengths")
<bytecode: 0x55ef9a8508f8>
<environment: 0x55ef9a84aaf0>
Methods may be defined for arguments: x
Use  showMethods("seqlengths")  for currently available ones.


If you're developing a package, it's often a lot easier to just import namespaces into your namespace, so that there's no need to remember which package defines what. Or, when working interactively, just call library(GenomicRanges), which will attach all relevant dependencies, such as GenomeInfoDb.

2

As a little bit of further commentary, it's worth noting that there is no method for GRanges:

> methods('seqlengths')
[1] seqlengths,ANY-method     seqlengths,Seqinfo-method
see '?methods' for accessing help and source code


and that's because of the interesting pattern where the implementation of ANY is based on reuse of the Seqinfo method:

> getMethod("seqlengths", "ANY")
Method Definition:

function (x)
seqlengths(seqinfo(x))
<bytecode: 0x7f90c8438a38>
<environment: namespace:GenomeInfoDb>

Signatures:
x
target  "ANY"
defined "ANY"


and actually GenomicRanges (re)exports the seqinfo generic

> GenomicRanges::seqinfo
standardGeneric for "seqinfo" defined from package "GenomeInfoDb"
...


and relevant methods

> getMethod("seqinfo", "GRanges")
Method Definition:

function (x)
x@seqinfo
<bytecode: 0x7f90c32a8d98>
<environment: namespace:GenomicRanges>

Signatures:
x
target  "GRanges"
defined "GRanges"


These would be good discussions for the bioc-devel mailing list (for package development, which I believe is what is going on here?) or the Bioconductor community slack.

Thankyou Martin, also for the reference to BioC community slack, which I was yet unaware of :-).