unlist doesn't work for IRanges
2
0
Entering edit mode
li lilingdu ▴ 450
@li-lilingdu-1884
Last seen 6.6 years ago

Hello, 

> library(IRanges)
> dat<-IRanges(1,10)
> unlist(dat)
Error in (function (classes, fdef, mtable)  : 
  unable to find an inherited method for function ‘getListElement’ for signature ‘"IRanges"’
> as(dat,'vector')
Error in as.vector(from) : 
  no method for coercing this S4 class to a vector
> as(dat,'integer')
Error in as.vector(x, mode = "integer") : 
  no method for coercing this S4 class to a vector

 

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 17134)

Matrix products: default

locale:
[1] LC_COLLATE=Chinese (Simplified)_China.936  LC_CTYPE=Chinese (Simplified)_China.936    LC_MONETARY=Chinese (Simplified)_China.936 LC_NUMERIC=C                              
[5] LC_TIME=Chinese (Simplified)_China.936    

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

other attached packages:
[1] IRanges_2.14.10     S4Vectors_0.18.2    BiocGenerics_0.26.0

loaded via a namespace (and not attached):
[1] compiler_3.5.0
iranges • 5.4k views
ADD COMMENT
2
Entering edit mode
@james-w-macdonald-5106
Last seen 2 days ago
United States

When behaviors change the first place to look is the NEWS file for the respective package. From IRanges:

 

SIGNIFICANT USER-VISIBLE CHANGES

    o The Ranges virtual class is now the common parent of the IRanges,
      GRanges, and GAlignments classes (GRanges and GAlignments are defined
      in the GenomicRanges and GenomicAlignments packages, respectively).
      More precisely, Ranges is a virtual class that now serves as the parent
      class for any class that represents a vector of ranges. The ranges can
      be integer ranges (i.e. ranges on the space of integers) like in an
      IRanges object, or genomic ranges (i.e. ranges on a genome) like in a
      GRanges object. Note that because Ranges extends List, all Ranges
      derivatives are considered list-like objects. This means that GRanges
      objects and their derivatives are considered list-like objects, which
      is new (even though [[ don't work on them yet, this will be implemented
      in Bioconductor 3.8).

    o Similarly the RangesList virtual class is now the common parent of the
      IRangesList, GRangesList, and GAlignmentsList classes.

    o IRanges objects don't support [[, unlist(), as.list(), lapply(), and
      as.integer() anymore. This is a temporary situation only. These
      operations will be re-introduced in Bioconductor 3.8 but with a
      different semantic. The overall goal of all these changes is to bring
      more consitency between IRanges and GRanges objects (GRanges objects will
      also support [[, unlist(), as.list(), and lapply() in Bioconductor 3.8).
      Non-exported IRanges:::unlist_as_integer() helper is a temporary
      replacement for what unlist() and as.integer() used to do a IRanges
      object.
ADD COMMENT
0
Entering edit mode
@gordon-smyth
Last seen 1 hour ago
WEHI, Melbourne, Australia

Why would you expect unlist() to work on something that isn't a list? What made you think it would work on an IRanges object? What did you expect it to do?

> is.list(dat)
[1] FALSE
ADD COMMENT
0
Entering edit mode

Hi ,

Thanks for your reply.

> library(S4Vectors)
> library(IRanges)
> is(IRanges(1,10),"List")

TRUE

in previous version of IRanges and S4Vectors 

unlist(IRanges(1,10))

would give the result of integer vector   1:10

And there exists method of  'unlist' for 'List':

> showMethods('unlist',class='List',inc=T)
Function: unlist (package base)
x="List"
function (x, recursive = TRUE, use.names = TRUE) 
{
    if (!isTRUEorFALSE(use.names)) 
        stop("'use.names' must be TRUE or FALSE")
    if (length(x) == 0L) {
        elt_type <- elementType(x)
        if (isVirtualClass(elt_type)) 
            return(NULL)
        return(new(elt_type))
    }
    xx <- unname(as.list(x))
    if (length(dim(xx[[1L]])) < 2L) {
        unlisted_x <- do.call(c, xx)
    }
    else {
        unlisted_x <- do.call(rbind, xx)
    }
    if (use.names) 
        unlisted_x <- set_unlisted_names(unlisted_x, x)
    unlisted_x
}

 

 

ADD REPLY
0
Entering edit mode

I see, you're quite right. We'll have to wait for an IRanges expert to respond.

ADD REPLY
0
Entering edit mode

For now I guess you'll just have to use IRanges:::unlist_as_integer(). I'm hoping that there is a way to achieve the same effect in the future using an exported entry point.

ADD REPLY

Login before adding your answer.

Traffic: 424 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6