[BioC] GRanges - coercion from dataframe

Steve Lianoglou mailinglist.honeypot at gmail.com
Mon Nov 28 07:10:13 CET 2011


Hi,

On Sat, Nov 26, 2011 at 6:56 PM, Michael Lawrence
<lawrence.michael at gene.com> wrote:
> It's difficult in general to have a coercion method from a less structured
> data type (like a data frame) to one more structured/constrained (like a
> GRanges). There's just no conventions as to how data is stored in the data
> frame. The RangedData coercion is not biology-aware, so it is not going to
> interact well with something output from GenomicRanges. I would recommend
> the approach you took. It can be made a little cleaner via with().

While all of what Michael says is true, sometimes you just want to
shoot from GRanges <--> data.frame and back again rather easily.

I've defined my own setAs methods for this purpose which you can use here:

https://github.com/lianos/seqtools/blob/master/R/pkg/R/conversions.R

There is really no error checking going on between the conversions,
but if you have columns of "the right" names in a data.frame, it'll
convert your data.frame to a GRanges object with no fuss.

Note that if your data.frame has a start, end, and width column it
will ignore the width and use start/end. All other "non-GRanges"
columns will be converted into a DataFrame object and stuffed into the
values() slot of the GRanges object returned.

The usual "use at your own risk" disclaimer applies ...

Enjoy,
-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the Bioconductor mailing list