#### The support.bioconductor.org editor has been updated to markdown! Please see more info at: Tutorial: Updated Support Site Editor

Question: New Version of R cannot coerce "GRanges" to "RangesList"
1
9 months ago by
hicklingmeb10
hicklingmeb10 wrote:

Hi, I have recently updated my R and am now getting an error message when I attempt to convert a GRanges value to a RangesList. This never happened in the older versions. Does anyone know a way around this? I'm using known human polyA sites. Here is a quick snippet of the code I've been using:

ax1 = data.frame(reducedHumanPas, stringsAsFactors = F)
ax1p = ax1[ax1$strand == "+",] ax1pr = makeGRangesFromDataFrame(ax1p, keep.extra.columns=TRUE, ignore.strand=FALSE, seqinfo=seq_info_object1, seqnames.field="seqnames", start.field="start", end.field="end", strand.field="strand", starts.in.df.are.0based=F) ax1n = ax1[ax1$strand == "-",]
ax1nr = makeGRangesFromDataFrame(ax1n, keep.extra.columns=TRUE, ignore.strand=FALSE, seqinfo=seq_info_object1, seqnames.field="seqnames", start.field="start", end.field="end", strand.field="strand", starts.in.df.are.0based=F)

wp = as(ax1pr, "RangesList")
wn = as(ax1nr, "RangesList")

Error in as(ax1pr, "RangesList") :
no method or default for coercing “GRanges” to “RangesList”

The above is the error code I receive when I try and execute the final two commands. Is there a way around this? Many thanks.

grangeslist irangeslist • 501 views
modified 7 months ago by Hervé Pagès ♦♦ 13k • written 9 months ago by hicklingmeb10

Is there such a class as RangesList? Do you mean GRangesList?

Yes, RangesList is a thing. The Views() function could take an RLE coverage object and a RangesList, and return coverages on the ranges. I have a bunch of code to find coverage on regions that's all broken now because I can't convert GRanges to RangesList. Like hicklingmeb, I'm looking for whatever is the modern solution.

Answer: New Version of R cannot coerce "GRanges" to "RangesList"
2
7 months ago by
Hervé Pagès ♦♦ 13k
United States
Hervé Pagès ♦♦ 13k wrote:

Hi,

In BioC 3.7, the RangesList class was replaced with the IntegerRangesList class. So:

library(GenomicRanges)
gr <- GRanges(Rle(c("A", "B"), 3), IRanges(9:4, 10))
gr
# GRanges object with 6 ranges and 0 metadata columns:
#       seqnames    ranges strand
#          <Rle> <IRanges>  <Rle>
#   [1]        A      9-10      *
#   [2]        A      8-10      *
#   [3]        A      7-10      *
#   [4]        B      6-10      *
#   [5]        B      5-10      *
#   [6]        B      4-10      *
#   -------
#   seqinfo: 2 sequences from an unspecified genome; no seqlengths

as(gr, "IntegerRangesList")
# IRangesList of length 2
# $A # IRanges object with 3 ranges and 1 metadata column: # start end width | strand # <integer> <integer> <integer> | <Rle> # [1] 9 10 2 | * # [2] 8 10 3 | * # [3] 7 10 4 | * # #$B
# IRanges object with 3 ranges and 1 metadata column:
#           start       end     width | strand
#       <integer> <integer> <integer> |  <Rle>
#   [1]         6        10         5 |      *
#   [2]         5        10         6 |      *
#   [3]         4        10         7 |      *

Cheers,

H.

I am having issues using IRanges objects. Previously, I was able to give an IRanges object to Rsamtools::ScanBamParam(), and now get the 'no method or default for coercing “IRanges” to “IntegerRangesList” ' error.

Are you sure you used an IRanges() instance? The argument needs to know the chromosome to select, so something like IRangesList(chr1=IRanges(100, 1000)) would make sense, but IRanges(100, 1000) would not... and whether or not it made sense in the past, I think you don't have a choice but to use IRangesList / GRanges.