[BioC] Plotting arbitrary lines at Gviz plotTracks

Hahne, Florian florian.hahne at novartis.com
Mon Sep 1 11:42:56 CEST 2014


Stackoverflow worked. The problem is that CustomTracks also will not help
you in this case because you essentially want to connect elements of
different tracks. You could however make use of the fact that Gviz stores
the pixel coordinates of all the items it draws, and this information is
returned by the plotTracks function. Essentially what you get is a named
list with one element per track. You could use the coords() method on the
list elements of interest to get the pixel coordinates for all of the
exons. If you use unique identifiers for them it should be quite straight
forward to draw the connecting lines:


at1 <- AnnotationTrack(start=c(1,50, 80), width=20, chromosome=1,
id=paste("at1", 1:3, sep="_"), name="at1")
at2 <- AnnotationTrack(start=c(30,70), width=20, chromosome=1,
id=paste("at2", 1:2, sep="_"), name="at2")
res <- plotTracks(c(at1, at2))
c1 <- coords(res$at1)
c1x <- c1[,1] + (c1[,3] - c1[,1])/2
c1y <- c1[,2] + (c1[,4] - c1[,2])/2

c2 <- coords(res$at2)
c2x <- c2[,1] + (c2[,3] - c2[,1])/2
c2y <- c2[,2] + (c2[,4] - c2[,2])/2

library(lattice)
pushViewport(viewport(xscale=c(0, dims[1]), yscale=c(dims[2], 0)))
panel.segments(c1x[c("at1_1", "at1_3")], c1y[c("at1_1", "at1_3")],
c2x[c("at2_1", "at2_2")], c2y[c("at2_1", "at2_2")])


Hope that gets you started.

Florian






From:  Vinicius Henrique da Silva <viniciushenrique_s at hotmail.com>
Date:  Monday 1 September 2014 10:47
To:  Florian Hahne <florian.hahne at novartis.com>
Subject:  RE: [BioC] Plotting arbitrary lines at Gviz plotTracks



Hello Florian,

Thank you very much for your attention.
I made the same question at stackoverflow:
http://stackoverflow.com/questions/25494125/plotting-arbitrary-lines-at-gvi
z-plottracks

Maybe the image there clarify my aim. Any ideas or directions in the
CustomTrack will be very appreciated.
Best,

Vinicius 

> From: florian.hahne at novartis.com
> To: viniciushenrique_s at hotmail.com; bioconductor at r-project.org
> Subject: Re: [BioC] Plotting arbitrary lines at Gviz plotTracks
> Date: Mon, 1 Sep 2014 08:29:58 +0000
> 
> Hi Vinicius,
> It looks like you sample image got stripped, so I can¹t see what exactly
> you are aiming for. That being said, from your description it seems like
> you are asking for a feature that is not available in Gviz. There are no
> low-level plotting functions at your disposal like in base R graphics.
> With quite a bit of effort you could archive some of this by using the
> CustomTrack class, but it would involve a bunch of steps that Gviz tries
> to hide away from the user, like computing the optimal stacking of
> overlaying genes, etc.
> Florian 
> 
> On 26/08/14 08:44, "Vinicius Henrique da Silva"
> <viniciushenrique_s at hotmail.com> wrote:
> 
> >I would like to plot lines between two itens at different
> >`AnnotationTrack`, or simple between two coordinates in my `Gviz`plot.
> >
> >genes data.frame:
> > start end
> > 72529373 72690449
> > 75457896 75536848
> > 76867833 76922959
> > 75664651 75870596
> > 76958977 77024110
> > 72065147 72204484
> > 74198711 74199129
> > 74816044 74978179
> > 76758753 76864805
> > 77032585 77176916
> > 73574461 73704802
> >
> >library(Gviz)
> >library(GenomicRanges)
> >ideoTrack <- IdeogramTrack(genome = "bosTau6", chromosome = "chr12",
> >fontsize=14, ucscChromosomeNames=TRUE)
> >axisTrack <- GenomeAxisTrack(range = IRanges(start = c(71959908,
> >76756891), end = c(72409907, 77206892), names = rep("Neighborhood", 2)),
> >fontsize=14, showId = TRUE, cex.id = 0.5, col.id = "black")
> >aTgenes1 <- AnnotationTrack(genes, name = "Genes", genome ="bosTau6",
> >chromosome ="chr12", showId = TRUE, stacking ="dense")
> >aTgenes2 <- AnnotationTrack(genes, name = "Genes", genome ="bosTau6",
> >chromosome ="chr12", showId = TRUE, stacking ="dense")
> >plotTracks(list(ideoTrack, axisTrack, aTgenes1, aTgenes2), from =
> >71959908, to = 77206892, sizes=c(1,1,1,1), margin=40, littleTicks =
> >TRUE)This above code result in this plot:
> >
> >
> >
> >
> >
> >Considering
> > the 11 plotted genes (the fourth gene is very small and hard to see), I
> > have the follow interaction between the genes:
> >gene 1 -> gene 2 and gene 11
> >gene 3 -> gene 5
> >gene 7 -> gene 6
> >With this interaction I expect some final plot similar to this picture:
> >
> >
> >I had tried some approachs that works in normal plots but not to Gviz
> >plots. Some ideas? Thank you very much!
> >
> >
> >Vinicius 
> > 
> > [[alternative HTML version deleted]]
> >
> >_______________________________________________
> >Bioconductor mailing list
> >Bioconductor at r-project.org
> >https://stat.ethz.ch/mailman/listinfo/bioconductor
> >Search the archives:
> >http://news.gmane.org/gmane.science.biology.informatics.conductor
> 



More information about the Bioconductor mailing list