Question: New Version of R cannot coerce "GRanges" to "RangesList"
1
gravatar for hicklingmeb
13 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 • 633 views
ADD COMMENTlink modified 11 months ago by Hervé Pagès ♦♦ 14k • written 13 months ago by hicklingmeb10

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

ADD REPLYlink modified 13 months ago • written 13 months ago by Mike Smith3.7k

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.

ADD REPLYlink modified 11 months ago • written 11 months ago by Chris Seidel50
Answer: New Version of R cannot coerce "GRanges" to "RangesList"
2
gravatar for Hervé Pagès
11 months ago by
Hervé Pagès ♦♦ 14k
United States
Hervé Pagès ♦♦ 14k 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.

ADD COMMENTlink written 11 months ago by Hervé Pagès ♦♦ 14k

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.

ADD REPLYlink modified 8 months ago • written 8 months ago by dayne.filer0

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.

ADD REPLYlink written 8 months ago by Martin Morgan ♦♦ 23k

Previously, I passed a named IRanges object. Thanks for the feedback.

ADD REPLYlink written 8 months ago by dayne.filer0
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 16.09
Traffic: 136 users visited in the last hour