Search
Question: how to transform a list of IRanges into a RangesList instance
0
gravatar for tobias.kockmann
3 months ago by
tobias.kockmann20 wrote:

Dear bioC support,

I have constructed a list of IRanges named rl:

> class(rl)
[1] "list"
> class(rl[[1]])
[1] "IRanges"
attr(,"package")
[1] "IRanges"

Now I realized that there is already a RangesList class in the IRanges package that I could use instead of the "primitive" list. Problem: I used dlply() from the plyr package to construct the list and I do not see how I could use the RangesList constructor function in the split+apply+combine context. But one can coerce a RangedList to a list by as. list(), Now I was wondering, is there a function that does the opposite?

Greetings,

Tobi

> sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: macOS Sierra 10.12.3

locale:
[1] C

attached base packages:
[1] parallel  stats4    stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] lattice_0.20-34     plyr_1.8.4          Biostrings_2.42.1   XVector_0.14.0     
[5] IRanges_2.8.1       S4Vectors_0.12.1    BiocGenerics_0.20.0

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.9           nloptr_1.0.4          MSstats_3.7.3         bitops_1.0-6         
 [5] tools_3.3.2           zlibbioc_1.20.0       lme4_1.1-12           preprocessCore_1.36.0
 [9] tibble_1.2            nlme_3.1-130          gtable_0.2.0          Matrix_1.2-8         
[13] ggrepel_0.6.5         stringr_1.1.0         gtools_3.5.0          caTools_1.17.1       
[17] grid_3.3.2            marray_1.52.0         survival_2.40-1       minpack.lm_1.2-1     
[21] gdata_2.17.0          limma_3.30.9          minqa_1.2.4           ggplot2_2.2.1        
[25] reshape2_1.4.2        magrittr_1.5          scales_0.4.1          gplots_3.0.1         
[29] MASS_7.3-45           splines_3.3.2         assertthat_0.1        colorspace_1.3-2     
[33] KernSmooth_2.23-15    stringi_1.1.2         lazyeval_0.2.0        munsell_0.4.3        
>
ADD COMMENTlink modified 3 months ago by James W. MacDonald43k • written 3 months ago by tobias.kockmann20
3
gravatar for James W. MacDonald
3 months ago by
United States
James W. MacDonald43k wrote:

It's just as one might imagine:

> lst <- list(IRanges(3,5), IRanges(4,5), IRanges(3,6))
> lst
[[1]]
IRanges object with 1 range and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         3         5         3

[[2]]
IRanges object with 1 range and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         4         5         2

[[3]]
IRanges object with 1 range and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         3         6         4

> as(lst, "RangesList")
RangesList of length 3
[[1]]
IRanges object with 1 range and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         3         5         3

[[2]]
IRanges object with 1 range and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         4         5         2

[[3]]
IRanges object with 1 range and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         3         6         4
ADD COMMENTlink written 3 months ago by James W. MacDonald43k

THX!

> real.rl <- as(rl, "RangesList")
> class(real.rl)
[1] "SimpleRangesList"
attr(,"package")
[1] "IRanges"

Where is that function documented?

ADD REPLYlink written 3 months ago by tobias.kockmann20

The as function is documented as part of the methods package. I think under the hood it ends up calling RangesList though, which is documented in ?RangesList. Either way works:
 

> class(as(rlst, "RangesList"))
[1] "SimpleRangesList"
attr(,"package")
[1] "IRanges"
> class(RangesList(rlst))
[1] "SimpleRangesList"
attr(,"package")
[1] "IRanges"

 

ADD REPLYlink written 3 months ago by James W. MacDonald43k

The as() function call looks for coerce() methods, so ?"coerce,list,RangesList". Many things in that last sentence are not obvious.

ADD REPLYlink written 3 months ago by Martin Morgan ♦♦ 20k

THX Martin! A general question: I am starting to develop a package for dealing with peptide mapping data (data coming from a bottom-up proteomics experiment) and I think the Biostrings and IRanges package could be the basis for this, but I am having trouble to get an overview what functionality is already available. Where can I find such information apart from the package vignettes?
 

ADD REPLYlink written 3 months ago by tobias.kockmann20

The  GenomicRanges vignettes are also relevant to IRanges. One might also look at conference presentations, especially last year and other course material.

ADD REPLYlink written 3 months ago by Martin Morgan ♦♦ 20k

Hi Martin,

I am having a bit of a problem using as(..., "RangesList") in the context of my package. I always get the error that the appropriate method is not found in the context of testthat(...). How would you handle this? Calling the RangesList() constructor directly instead of as() -> coerce() -> ...

?

ADD REPLYlink written 17 days ago by tobias.kockmann20

Better to ask questions about package development on the Bioconductor devel mailing list. For packages you need to import the appropriate method, importMethodsFrom(IRanges, coerce). if your unit test uses the public interface to your package, then problems likely indicate inappropriate NAMESPACE, but a more accurate diagnosis would benefit from actually looking at  the package code, e.g., including  a github reference.

ADD REPLYlink written 17 days ago by Martin Morgan ♦♦ 20k

Note that there is also an IRangesList() constructor function that is very similar to RangesList() except that it produces an IRangesList object which is more specific than a RangesList (i.e. the former is a subclass of the latter):

IRangesList(lst)
# IRangesList of length 3
# [[1]]
# IRanges object with 1 range and 0 metadata columns:
#           start       end     width
#       <integer> <integer> <integer>
#   [1]         3         5         3
#
# [[2]]
# IRanges object with 1 range and 0 metadata columns:
#           start       end     width
#       <integer> <integer> <integer>
#   [1]         4         5         2
#
# [[3]]
# IRanges object with 1 range and 0 metadata columns:
#           start       end     width
#       <integer> <integer> <integer>
#   [1]         3         6         4

Also, IRangesList() has a compress argument to let you choose between 2 internal representations: CompressedIRangesList or SimpleIRangesList. By default you get the first, which is more efficient than the second if the list is very long (e.g. has > 10000 list elements).

H.

ADD REPLYlink written 3 months ago by Hervé Pagès ♦♦ 12k

I tried to use as(..., "IRangesList") and got:

Error in as(y, "IRangesList") :
  no method or default for coercing "list" to "IRangesList"

Is there a reason why one can not coerce a list to a IRangesList? What is more specific about IRangesList objects?

ADD REPLYlink written 9 weeks ago by tobias.kockmann20
1

No particular reason. It was just missing. I added it to IRanges 2.9.20.

Cheers,

H.

ADD REPLYlink written 9 weeks ago by Hervé Pagès ♦♦ 12k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.2.0
Traffic: 124 users visited in the last hour