gggenomes icon indicating copy to clipboard operation
gggenomes copied to clipboard

coord_polar

Open thackl opened this issue 2 years ago • 1 comments

Originally posted by @iferres in https://github.com/thackl/gggenomes/issues/85#issuecomment-938697228

I assume the following feature request is not trivial at all, but have you considered ... + coord_polar() to draw circularized contigs? Playing with the package (and diving into the source code) I found that the following kinda works:

library(gggenomes) 

s0 <- tibble(
  gene_id = letters[1:6],
  bin_id = c("A", "A", "B", "B", "B", "B"),
  seq_id = factor(c("A1", "A1", "B1", "B1", "B2", "B2"), levels = c("A1", "B2", "B1")), # set factor to order contigs
  feat_id = c("a1","a2","b3", "b4", "b1", "b2"),
  start = c(1, 20, 1, 50, 1, 20),
  end = c(10, 30, 40, 70, 10, 30),
  strand = c(1, 1, 1, 1, 1, 1),
  length = c(1000, 1000, 1000, 1000, 1000, 1000)
)

gggenomes(s0) + 
  geom_seq() + 
  gggenomes:::geom_gene2() + 
  coord_polar() # + 
  # facet_wrap(~bin_id)

but I guess is experimental and there's a lot to work with to make it stable and user friendly, isn't it?

thackl avatar Oct 08 '21 20:10 thackl

Yes, I thought about it and, yep, your last sentence perfectly sums it up :D.

Here's something I put together playing around before. There's definitely potential, but also a lot of things that break (like geom_gene()). At this point it's not high enough up on my priority list to put in the effort and fully implement it. But it might already be useful to some users to provide guidance on how to explore it as an experimental feature (as you did)

gggenomes(emale_genes %>% mutate(gene_id=feat_id), emale_seqs[1:5,], feats=emale_gc) %>%
  add_clusters(emale_cogs) %>%
  flip_by_links() +
  geom_seq() +
  geom_wiggle(aes(z=score, color=score), geom="linerange", offset=-.4) +
  geom_link(offset=c(0.2,0.2), color=NA) +
  gggenomes:::geom_gene2() +
  coord_polar() + ylim(-2, NA) + xlim(-9000,NA) +
  geom_bin_label(aes(x=0, label=paste0(bin_id, "   ")), angle=-90, hjust=1, vjust=.5, nudge_left = 0.02) +
  scale_colour_viridis_b(option="A")

emales-polar

thackl avatar Oct 08 '21 20:10 thackl