Search
Question: coercion to Granges from empty data.frame ==> unexpected behavior ??
0
gravatar for Malcolm Cook
8 days ago by
Malcolm Cook1.4k
United States
Malcolm Cook1.4k wrote:

Hello,

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

as(data.frame(SeqID=character(),start=integer(),end=integer()),'GRanges')
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?

Thanks!

ADD COMMENTlink written 8 days ago by Malcolm Cook1.4k
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: 169 users visited in the last hour