thackl / gggenomes

A grammar of graphics for comparative genomics
https://thackl.github.io/gggenomes/
Other
606 stars 65 forks source link

Adding UTRs in the plot #143

Closed ChongLC closed 1 year ago

ChongLC commented 1 year ago

Dear gggenomes developer,

I am trying to plot the genome organization plot of flavi sequences using gggenomes. However, I faced difficulties to add the 3'UTR and 5'UTR in the plot. Do you have any idea to add this?

R code snippet that I ran:

GenoInfo$seq_id[GenoInfo$seq_id == 'NC_001477.1'] <- 'NC_001477.1 (DENV1)'
GenoInfo$seq_id[GenoInfo$seq_id == 'NC_001474.2'] <- 'NC_001474.2 (DENV2)'
GenoInfo$seq_id[GenoInfo$seq_id == 'NC_001475.2'] <- 'NC_001475.2 (DENV3)'
GenoInfo$seq_id[GenoInfo$seq_id == 'NC_002640.1'] <- 'NC_002640.1 (DENV4)'

GenoInfo <- GenoInfo[GenoInfo$type != 'CDS',]
GenoInfo$type[GenoInfo$type == 'mature_protein_region_of_CDS'] <- 'CDS'
GenoInfo <- GenoInfo[GenoInfo$type == 'CDS',]
GenoInfo$product <- reName(GenoInfo$product)

GenoFeat <- GenoInfo
GenoFeat$introns <- NULL
GenoFeat$bin_id <- paste0('id_',seq(1,nrow(GenoFeat)))

p <- gggenomes(genes=GenoInfo, seqs=SeqInfo, feats = GenoFeat) + 
  geom_seq() + geom_gene(aes(fill=product))
p <- p + scale_fill_discrete(limits=c("C", "prM", "E", "NS1", "NS2A", "NS2B", "NS3", "NS4A", "protein 2K", "NS4B", "NS5")) + 
  labs(fill = 'Protein')
p

Current view of the plot: image

Best regards, Chong

thackl commented 1 year ago

Hi Chong,

the problem might be that you remove all but CDS from GeneInfo (GenoInfo <- GenoInfo[GenoInfo$type == 'CDS',]), so when you later do GeneFeat <- GeneInfo, there is not more UTRs in there.

Here's my approach based on one DenV1 gff from NCBI. Does this help?

library(gggenomes)
d0 <- read_feats("deng1.gff3")

s0 <- d0 |> 
  filter(type == "region") |> 
  transmute(seq_id, length=end)

g0 <- d0 |> 
  filter(type == "mature_protein_region_of_CDS") |>
  mutate(type = "CDS")

gggenomes(seqs=s0, genes=g0, feats=d0) +
  geom_seq() +
  geom_gene(aes(fill=product)) +
  geom_feat(data=feats(1, str_detect(type, "UTR")))

image

thackl commented 1 year ago

Closing for now, let feel free to reopen if you have additional questions

ChongLC commented 1 year ago

Dear @thackl,

Oh yes, I tried and it solved my issue. I forget to reply here. I will close it. Thank you for your help.

Best regards, Chong