Gviz: Plot only exons?
3
2
Entering edit mode
stianlagstad ▴ 90
@stianlagstad-9723
Last seen 4.8 years ago

Is there an easy way to plot only exons, not introns? Consider:

gr <- GenomicRanges::GRanges(17, IRanges(start = c(5,20,30,50), end = c(10,25,40,60)))
mcols(gr)$transcript <- "test"
tr <- Gviz::GeneRegionTrack(gr)
Gviz::plotTracks(tr)

Which plots this:

How could I plot this without the introns? With the exons "smacked together", so to speak? I was imagining something like this:

Gviz::plotTracks(
  tr,
  ranges = gr
)
gviz • 2.7k views
ADD COMMENT
1
Entering edit mode
stianlagstad ▴ 90
@stianlagstad-9723
Last seen 4.8 years ago

For others that might be interested, I solved this by shifting all exons to the left. A full example:

gr <- GenomicRanges::GRanges(17, IRanges(start = c(5,20,30,50), end = c(10,25,40,60)))
mcols(gr)$transcript <- "test"
tr <- Gviz::GeneRegionTrack(gr)
Gviz::plotTracks(tr)

This produces the plot in my original question:

Now let's remove spaces between exons:

# Move the first exon down to position 1, and then remove the spaces between all the others. Effectively pushing all exons to the leftmost edge.
for (i in 1:length(gr)) {
  if (i == 1) {
    gr[i] <- IRanges::shift(gr[i], shift = 1-start(gr[i]))
  } else {
    shiftDownBy <- -(start(gr[i])-end(gr[i-1]))+1
    gr[i] <- IRanges::shift(gr[i], shift = shiftDownBy)
  }
}

tr <- Gviz::GeneRegionTrack(gr)
Gviz::plotTracks(tr)

This produces the following plot:

ADD COMMENT
0
Entering edit mode

Hey, I just want to comment a convenient way to do this, for anyone who might look at it. It can be done with: 

exon <- exonsBy(TxDb.Hsapiens.UCSC.hg19.knownGene, 'tx')[42]
exon_mapped <- GenomicFeatures::mapToTranscripts(exon[[1]],exon)

And this is just the intended transformation of the exons.

 

exon
GRangesList object of length 1:
$42 
GRanges object with 13 ranges and 3 metadata columns:
       seqnames           ranges strand |   exon_id   exon_name exon_rank
          <Rle>        <IRanges>  <Rle> | <integer> <character> <integer>
   [1]     chr1 [861302, 861393]      + |        36        <NA>         1
   [2]     chr1 [865535, 865716]      + |        37        <NA>         2
   [3]     chr1 [866419, 866469]      + |        38        <NA>         3
   [4]     chr1 [871152, 871276]      + |        39        <NA>         4
   [5]     chr1 [874420, 874509]      + |        42        <NA>         5
   ...      ...              ...    ... .       ...         ...       ...
   [9]     chr1 [877790, 877868]      + |        51        <NA>         9
  [10]     chr1 [877939, 878438]      + |        53        <NA>        10
  [11]     chr1 [878633, 878757]      + |        54        <NA>        11
  [12]     chr1 [879078, 879188]      + |        55        <NA>        12
  [13]     chr1 [879288, 879961]      + |        58        <NA>        13

-------
seqinfo: 93 sequences (1 circular) from hg19 genome

 

 

exon_mapped
GRanges object with 13 ranges and 2 metadata columns:
       seqnames       ranges strand |     xHits transcriptsHits
          <Rle>    <IRanges>  <Rle> | <integer>       <integer>
   [1]       42   [  1,  92]      + |         1               1
   [2]       42   [ 93, 274]      + |         2               1
   [3]       42   [275, 325]      + |         3               1
   [4]       42   [326, 450]      + |         4               1
   [5]       42   [451, 540]      + |         5               1
   ...      ...          ...    ... .       ...             ...
   [9]       42 [ 930, 1008]      + |         9               1
  [10]       42 [1009, 1508]      + |        10               1
  [11]       42 [1509, 1633]      + |        11               1
  [12]       42 [1634, 1744]      + |        12               1
  [13]       42 [1745, 2418]      + |        13               1
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths
ADD REPLY
1
Entering edit mode
@florianhahnenovartiscom-3784
Last seen 6.3 years ago
Switzerland

That is not possible since it would essentially imply a non-continuous x axis. One of the fundamental concepts of Gviz is that every track shares the same x axis of genomic coordinates. You are asking for a plot along transcript coordinates. 

ADD COMMENT
0
Entering edit mode
@florianhahnenovartiscom-3784
Last seen 6.3 years ago
Switzerland

Please take a look at section 4.5 in the vignette. The parameter you want to look at is called collapseTranscripts.

Florian

ADD COMMENT
0
Entering edit mode

I'm sorry, I mean "smacked together" horizontally, not vertically. As if there were no spaces in between the exons in my example plot. Is that possible? Maybe this can help explain: drawing.

My end goal is a plot of the transcript (but only exons) with coverage, using GeneRegionTrack and AlignmentsTrack.

ADD REPLY

Login before adding your answer.

Traffic: 610 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