Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust gene position in plot according to orf #198

Open
SergejRuff opened this issue Sep 24, 2024 · 4 comments
Open

Adjust gene position in plot according to orf #198

SergejRuff opened this issue Sep 24, 2024 · 4 comments

Comments

@SergejRuff
Copy link

ggggenomes allows to change position of orfs via

geom_feat(size = 3,position = "pile")

But how do I change the position of the genes in geom_gene() to make sure the ORF and genes allign?
position="pile" doesnt do the same thing.

@SergejRuff
Copy link
Author

genome_map_complete_2109

Here is what I mean: The genes in the first contig with the longet length do not match the orf position as some are elevated.

The code i use:

gggenomes(seqs = s0, genes = g0, feats = orf0) +
  geom_feat(size = 3,position = "pile") +
  geom_seq() +
  geom_gene(aes(fill = interpro_description))  +
  # geom_gene(data = genes(g0_filtered),aes(fill = interpro_description))  +
  # geom_gene(aes(fill = interpro_description),position = position_strand(flip = FALSE, base = 0.1))  +
  theme(plot.margin = margin(1, 1, 1, 1, "cm")) +
  theme(legend.position = "bottom", axis.text.x = element_text(size = 10)) +
  scale_x_continuous(labels = function(x) format(x, big.mark = ",", scientific = FALSE),
                     breaks = c(0, 5000, 10000, 15000, 20000, 25000,30000) )

@thackl
Copy link
Owner

thackl commented Sep 25, 2024

Unfortunately, it is not possible to automatically have the genes match the position of the ORF when using "pile". Piling is run on each geom layer independently, so geom_gene does not know where ORFs placed by geom_feat end up.

If you want all ORFs on the same line (as the genes), you can set position="identity", and for example, change the coloring of the ORFs

#| fig-height: 1
#| fig-width: 8
library(tidyverse)
library(gggenomes)

g0 <- tibble(seq_id = "foo", start=c(10,100,200,400,500), end=start +60)
orfs <- tibble(seq_id="foo", start=c(10, 200, 400), end=c(200, 400, 560)) |> 
  mutate(orf_id=paste0("orf", row_number()), alternate=row_number() %%2)

gggenomes(g0, feats=orfs) +
  geom_feat(aes(color=alternate), position="identity", size=5, alpha=.3) +
  geom_gene()

image

And if you know the orf_id for each gene, you can manually set alternating positions for ORFs and genes consistently.

#| fig-height: 1
#| fig-width: 8
g1_with_orf_id <- g0 |> mutate(
  orf_id = paste0("orf", c(1,1,2,3,3))) |> 
  left_join(select(orfs, orf_id, alternate))

gggenomes(g1_with_orf_id, feats=orfs) +
  geom_feat(aes(y=y+0.4*alternate, yend=y+0.4*alternate), position="identity", size=5) +
  geom_gene(aes(y=y+0.4*alternate, yend=y+0.4*alternate))

image

@SergejRuff
Copy link
Author

Thanks. What is "alternate" in the second example?

@thackl
Copy link
Owner

thackl commented Sep 25, 2024

It's that alternating counter that I added to orfs with alternate= row_number %% 2. It's value will alternating between 1 and 0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants