This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to get the number of exons and visualize them?

Hello everyone, I would like to ask you how can I get the number of exon? I want visualize gene length vs. number of exons in gene.

For example:

I have the length of the gene:

exons <- getBM(attributes = c("external_gene_name","start_position","end_position","ensembl_exon_id"),
          filters = "chromosome_name",
          values = "21",
          mart = genes)
exons[5] <- exons$end_position - exons$start_position
names(exons)[5] <- "gene_length"

I tried to find out the number of exons:

as.data.frame(table(exons$ensembl_exon_id))

But now, I don't know what else. Please, somebody would help me?

r

Did you do first do:

ensembl=useMart("ensembl")
ensembl = useDataset("hsapiens_gene_ensembl",mart=ensembl)

I assume you are interested in human data?

Yes of course:

genes <- useDataset("hsapiens_gene_ensembl",mart=ensembl)

It looks great. I don't know tidyverse package, please could I do it something similarly also with dplyr?

marija : Please use ADD COMMENT/ADD REPLY when responding to existing posts to keep threads logically organized.

@genomax : better put this comment under my post as it's related to dplyr

@Nicolas: Mods can only move comments (that are not real answers) to the top post. We can't select a specific location to move them to in the thread. It is not ideal but the only option currently possible. If marija reposts under your answer then we can delete this set here.

Sorry. And @Nicolas thank you very much.

Accept @Nicolas' answer (green check mark) if you are happy with it.

1 answer

Something like :

require(tidyverse)
genes <- useDataset("hsapiens_gene_ensembl",mart=ensembl)
exons <- getBM(attributes =
      c("external_gene_name","start_position","end_position","ensembl_exon_id"),
      filters = "chromosome_name",
      values = "21",
      mart = genes)
exons <- as.tibble(exons)
exons.plot <- exons %>% 
    mutate(len=end_position-start_position) %>% 
    group_by(external_gene_name) %>% 
    summarize(geneLen=sum(len),exonNumber=n())
# plot
ggplot(exons.plot,aes(x=geneLen,y=exonNumber))+
  geom_point(alpha=0.5)+
  scale_y_log10()+
  scale_x_log10()+
  theme_bw()

FYI you should use ensembl_gene_id instead of gene name

enter image description here

@Nicolas Please do you know explain me why you use this command:

exonNumber=n()

Thank you

n() reports the number of elements in each group thus the number of exons

Log in to answer this question.