Question: coercion to Granges from empty data.frame ==> unexpected behavior ??
gravatar for Malcolm Cook
11 months ago by
Malcolm Cook1.5k
United States
Malcolm Cook1.5k wrote:


I find it odd that coersion to GRanges with as fails in the case of an empty data.frame:

This works fine:

> as(data.frame(SeqID=c('s'),start=c(1),end=c(2)),'GRanges')
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]        s    [1, 2]      *
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

But if the data.frame is empty and untyped, no dice:

> as(data.frame(SeqID=c(),start=c(),end=c()),'GRanges')
Error in .find_start_end_cols(df_colnames0, start.field0, end.field0) : 
  cannnot determine start/end columns

Taking the diagnostic literally, I type the columns in the data.frame and get a little further

Error in validObject(.Object) : 
  invalid class "GRanges" object: NROW(strand(x)) != length(x)

Almost across the line. Let's add the strand in too:

> as(data.frame(SeqID=character(),start=integer(),end=integer(),strand=character()),'GRanges')
GRanges object with 0 ranges and 0 metadata columns:
   seqnames    ranges strand
      <Rle> <IRanges>  <Rle>
  seqinfo: no sequences

That works.

But, is this truely by design?

At the very least, I would hope that the 3rd example would have worked, with the strand column optional...

Or is there a "good reason" it works just as it does?


granges coercion • 212 views
ADD COMMENTlink written 11 months ago by Malcolm Cook1.5k
Please log in to add an answer.


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