(I also asked this question on the Bioconductor support site [here][1].)

I'm stumped. I'm trying to plot a few transcripts at the same time, given transcript names and a TxDb. These are examples of approaches I've tried:

    # ------------------------------------------------------------------------------
    # Setup:
    library(TxDb.Hsapiens.UCSC.hg19.knownGene)
    library(Gviz)
    txdb <- TxDb.Hsapiens.UCSC.hg19.knownGene
    
    # ------------------------------------------------------------------------------
    # Try 1:
    gr <- GenomicFeatures::exons(
      txdb,
      vals = list(tx_name = c("uc001aaa.3", "uc010nxq.1")),
      columns = list("EXONNAME", "TXNAME", "GENEID"))
    track <- Gviz::GeneRegionTrack(gr)
    Gviz::plotTracks(track)
    # Creates a plot, but doesn't show transcript grouping

![enter image description here][2]
    
    # ------------------------------------------------------------------------------
    # Try 2
    gr <- GenomicFeatures::transcripts(
      txdb,
      vals = list(tx_name = c("uc001aaa.3", "uc010nxq.1")),
      columns = list("EXONNAME", "TXNAME", "GENEID"))
    track <- Gviz::GeneRegionTrack(gr)
    Gviz::plotTracks(track)
    # Creates a plot, but has no exon/intron information

![enter image description here][3]
    
    # ------------------------------------------------------------------------------
    # Try 3
    gr <- exonsBy(txdb, by = "tx", use.names=TRUE)[c("uc001aaa.3", "uc010nxq.1")]
    track <- Gviz::GeneRegionTrack(gr)
    # Error in .fillWithDefaults(DataFrame(chromosome = as.character(seqnames(range)),  : 
    # Number of elements in argument 'feature' is invalid

None of these work for me. I want to display exon/intron-structures and have arrows between exons. Does anyone have suggestions?


  [1]: https://support.bioconductor.org/p/80221/
  [2]: http://s8.postimg.org/dv9mopwhh/try1.png
  [3]: http://s23.postimg.org/hi1ta61pn/try2.png
I found a solution that worked! Typical to find it shortly after asking the question, but here it is:

    # ------------------------------------------------------------------------------
    # Try 4
    gr <- exonsBy(txdb, by = "tx", use.names=TRUE)[c("uc001aaa.3", "uc010nxq.1")]
    gr <- unlist(gr)
    elementMetadata(gr)$transcript <- names(gr)
    track <- Gviz::GeneRegionTrack(gr)
    Gviz::plotTracks(track)

![enter image description here][1]

Using exonsBy gives a GrangesList with one GRanges object for each transcript. Unlisting the GrangesList creates a named (important!) GRanges object with all exons. Using those names to set the $transcript metadata column solved the problem.


  [1]: http://s16.postimg.org/ong5l77w5/try4.png