teunbrand / ggnomics

A small project to add ggplot2 extensions
https://teunbrand.github.io/ggnomics/
Other
80 stars 4 forks source link

Genomic Coordinates as position scales #32

Open teunbrand opened 4 years ago

teunbrand commented 4 years ago

Basically to have a GRanges object (chromsome:start-end parametrisation) as the position on the x- or y-axis and have a coord_* function reflect this.

The struggle at the moment is to have a vector-like implementation of GRanges as a single column in a base R data.frame. See my related SO question: https://stackoverflow.com/questions/59370461/granges-as-column-in-basedata-frame

teunbrand commented 4 years ago

I'm now having a decent vctrs-based (vctr_rcrd) S3 equivalent of the GRanges class, but I am having trouble marching these through the internals of ggplot. The intention is to let this be a hidden class that doesn't need to face the user but is used as a representation of genomic ranges internally.

Particularly, I can't seem to get past certain unlist operations in scale_apply(). See related SO question: https://stackoverflow.com/questions/59401011/unlist-behaviour-on-vctr-rcrd-class-objects

teunbrand commented 4 years ago

I'm now leaning towards making a general vctrs-compatible scale and coordinate system as a seperate package, which I could then extend in ggnomics.

teunbrand commented 4 years ago

I found out that we can have GRanges objects as columns with some workarounds, so I'll probably make a coordinate system based on the original S4 class.

teunbrand commented 4 years ago

Update: the genomic position scale appears to be working in theory.

image

Caveat: I can't get any expression other than the plain column name to work. I'd need the compute aesthetics parts of ggplot to change and allow S4 classes in order to achieve this properly.