Mixed up colors in GViz GeneRegionTrack
0
0
Entering edit mode
@senanupearson-10973
Last seen 8.4 years ago

Hi,

 I am trying to color genes in a GeneRegionTrack according to a pre-defined criteria. I have set up the color that I'd like the genes to be in a column of the GRanges object. If I plot the entire GRanges object, then everything works fine. However, if I plot only a portion, then the colors remain in the same order, but they are now attached to different genes.

I suspect that this is because the color vector does not get subset by the range like the symbol does, so the entire vector gets used when plotting the whole thing, but the vector starts at the first element even when plotting only a later subset.

The following code should be reproducible.

rm(list=ls())

library(optparse)
library(Gviz)
library(GenomicRanges)

## Set up 3 regions
start <- c(1,10, 20)
end <- c(5,15,25)
genes <- c('g1','g2','g3')
chromosome <- rep('chr1', times=3)
color.temp<- as.character(c("green", 'blue', 'blue'))
color2.temp <- as.character(c("red", 'black', 'black'))
dat <- GRanges(seqnames=chromosome,
               ranges=IRanges(start, end=end),
               gene=genes,
               color.fill=color.temp,
               color.border=color2.temp)

dtrack <- GeneRegionTrack(dat, symbol=dat$gene, showId=TRUE,
                          fill=dat$color.fill, col=dat$color.border, lwd=4)

## In the following case, the fill colors are painted fine
plotTracks(dtrack, chromosome='chr1', from=1, to=30)
## In the following case, the fill colors are painted without subsetting
## according to what is actually being painted
plotTracks(dtrack, chromosome='chr1', from=10, to=30)

It seems that I shouldn't need to manipulate and subset the colors separately from the rest of the GenomiRanges object (which looks like this)

> dat
GRanges object with 3 ranges and 3 metadata columns:
      seqnames    ranges strand |        gene  color.fill color.border
         <Rle> <IRanges>  <Rle> | <character> <character>  <character>
  [1]     chr1  [ 1,  5]      * |          g1       green          red
  [2]     chr1  [10, 15]      * |          g2        blue        black
  [3]     chr1  [20, 25]      * |          g3        blue        black
  -------
  seqinfo: 1 sequence from an unspecified genome; no seqlengths

Finally, why can't I seem to be able to control the border coloring in the same way?

Thank you very much!

color GeneRegionTrack • 1.2k views
ADD COMMENT

Login before adding your answer.

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