Gviz: How to plot UTRs with GRanges object?
2
0
Entering edit mode
stianlagstad ▴ 90
@stianlagstad-9723
Last seen 4.1 years ago

I wish to plot a transcript with the UTRs as thinner boxes. BiomartGeneRegionTrack does this automatically:

transcriptID <- "ENST00000398958"

# ---------- USING MART

mart <- biomaRt::useMart(
  biomart = "ENSEMBL_MART_ENSEMBL",
  dataset = "hsapiens_gene_ensembl",
  host = "dec2013.archive.ensembl.org")

# Create transcript track
biomartTrack <- Gviz::BiomartGeneRegionTrack(
  filters = list(
    ensembl_transcript_id = transcriptID),
  biomart = mart)

# Plots with UTRs as thinner boxes
Gviz::plotTracks(biomartTrack)

But as I cannot connect to the internet for each plot I create, I need to use a TxDb from a local file:

transcriptID <- "ENST00000398958"

# ---------- USING TXDB

txdbhg19 <- AnnotationDbi::loadDb(file = "Biomart_Ensembl_HS_dec2013.archive.ensembl.org.sqlite")

# The sqlite was created like this:
# txdbhg19 <- GenomicFeatures::makeTxDbFromBiomart(
#   biomart = "ENSEMBL_MART_ENSEMBL",
#   dataset = "hsapiens_gene_ensembl",
#   host = "dec2013.archive.ensembl.org")
# AnnotationDbi::saveDb(txdbhg19, file="Biomart_Ensembl_HS_dec2013.archive.ensembl.org.sqlite")

# See what data can be retrieved
columns(txdbhg19)
# [1] "CDSCHROM"   "CDSEND"     "CDSID"      "CDSNAME"    "CDSSTART"   "CDSSTRAND"  "EXONCHROM"  "EXONEND"    "EXONID"     "EXONNAME"
# [11] "EXONRANK"   "EXONSTART"  "EXONSTRAND" "GENEID"     "TXCHROM"    "TXEND"      "TXID"       "TXNAME"     "TXSTART"    "TXSTRAND"
# [21] "TXTYPE"

# Which of these columns will help me?

# Get all exon information
allExons <- GenomicFeatures::exons(
  txdbhg19,
  filter = list(tx_name = transcriptID),
  columns = list())

# I wish to create a GeneRegionTrack that has the same feature values as the BiomartGeneRegionTrack above has:
Gviz::feature(biomartTrack)
# [1] "utr5"           "utr5"           "utr5"           "utr5"           "protein_coding" "protein_coding" "protein_coding"
# [8] "protein_coding" "protein_coding" "protein_coding" "protein_coding" "protein_coding" "protein_coding" "utr3"

# But I'm not sure how to accomplish this.

Can anyone help me create the same plot using the TxDb?

gviz • 1.8k views
ADD COMMENT
1
Entering edit mode
@steve-lianoglou-2771
Last seen 14 months ago
United States

Last I thought Gviz took care of this already (and I think I actually helped provide a patch for that several years back now :-) -- does it no longer work?

Look at page 42 of the current Gviz vignette where the plot from plotTracks(txTr) is shown ... looks about right to me, no?

 

ADD COMMENT
0
Entering edit mode

Thank you for answering! Could you point me to the relevant parts in the Gviz source code? For my purposes I don't want to use the TxDb object directly, but create a track from a GRanges object.

ADD REPLY
1
Entering edit mode

Sorry, just don't have the time to dig into it right now, but maybe start your search through the source code by looking for "thinBoxFeature", "utr", etc ... 

ADD REPLY
1
Entering edit mode
@florianhahnenovartiscom-3784
Last seen 5.6 years ago
Switzerland

Did you check the section in the vignette that Steve was referring to? You can build a GeneRegionTrack straight from a TxDB object, and that will give you all the UTRs just as you get them from Biomart:

library(GenomicFeatures)
options(ucscChromosomeNames=FALSE)
grt <- GeneRegionTrack(txdbhg19)
plotTracks(grt, from=1e6, to=2e6)

Btw, I'd recommend to not calling functions from their Namespace with the :: notation, unless there is a good reason to do so. You should always properly attach the packages you need using library() calls. Otherwise there is no guarantee that all dependencies in the search path are properly resolved.

Florian

 
ADD COMMENT
0
Entering edit mode

Yes, I saw that, but I do not want to build the object from a TxDb object - I need to build it from a GRanges object.

ADD REPLY
2
Entering edit mode

???

This is your question from above:

"Can anyone help me create the same plot using the TxDb?"

If you want to create it from a GRanges object then you will have to to come up with a structure that has all the UTRs and exons as separate ranges and supply the necessary feature identifiers (utr5, utr3, protein_coding). This is all described in the GeneRegionTrack class documentation, and in the vignette.

Within a TxDb object the UTRs are not stored as separate ranges, and Gviz will take that extra burden from you to recreate UTRs based on the transcript and exon coordinates. Its really not clear to me why you would want to re-invent that wheel, but knock yourself out.

ADD REPLY
0
Entering edit mode

I'm sorry about the confusion. What I want to accomplish is to build the structure I have to provide to Gviz manually, so that I produce the same plot as with BiomartGeneRegionTrack. That is, I wish to extract the relevant data from the TxDb myself, create a GRanges object with everything that is needed (here is where I got lost), and then give that to GeneRegionTrack. But I'll think about this some more. Thanks for the help!

ADD REPLY

Login before adding your answer.

Traffic: 789 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6