Gviz Color Filling
3
0
Entering edit mode
dustar1986 ▴ 10
@dustar1986-10108
Last seen 7.2 years ago

Hi,

I'm using Gviz to display transcripts. I wanna highlight some exons with different color. My input is a tab-separated plain text file like the following:

new=read.table("myfile",header=T)
head(new,1)
   chromosome  start  end width strand   feature   gene exon transcript color
1  chrX 586072 586344   273      + protein_coding Gene1  Exon1 Trans1 red

gen="hg19"
chr="chrX"
gtrack <- GeneRegionTrack(new, genome = gen,chromosome = chr, fill=as.vector(new$color))
plotTracks(list(gtrack))

However, I found exons were not colored in the order of "color" column. My input file has already been sorted by coordinates. Did I miss something? How can I match an exon to its color?

Any help is appreciated. Thanks a lot.

 

Gviz • 5.0k views
ADD COMMENT
1
Entering edit mode
@florianhahnenovartiscom-3784
Last seen 6.2 years ago
Switzerland

Did you check the package vignette or the class' help page?

On page 33 of the vignette:

Unless we tell the Gviz package how to deal with the respective feature types they will all be treated in a similar fashion, i.e., they will be plotted using the default color as defined by the fill display parameter. To define colors for individual feature types we simply have to add them as additional display parameters, where the parameter name matches the feature type and its value is supposed to be a valid R color qualifier. Of course this implies that we can only use feature names that are not already occupied by other display parameters defined in the package

From the class documentation:

feature: Factor (or other vector that can be coerced into one), giving

          the feature types for the individual track items. When

          plotting the track to the device, if a display parameter with

          the same name as the value of 'feature' is set, this will be

          used as the track item's fill color. See 'grouping' for

          details.  Needs to be of equal length as the provided genomic

          coordinates, or of length 1.

 So essentially what you want to do here is provide the values from your color column as the class' feature argument, and define display parameters for the colors accordingly:

gtrack <- GeneRegionTrack(new, genome = gen,chromosome = chr, feature=as.vector(new$color), red="red")

 

 

 

 

 

ADD COMMENT
0
Entering edit mode

Thanks heap, Florian. It works perfectly, however it turned out a new question. I still have some exons not colored as expected. They were colored by the default yellow color which is not in my list. I found those exons are too close to their neighbors to be distinguished on the plot. Is that why they were not colored? Is there a way to achieve it without changing the plotted genomic range? Thanks a lot.

ADD REPLY
0
Entering edit mode

I have a similar problem.  I want to use TxDb as input and to highlight one whole transcripts of a gene. But the result confuses me. 

I created the TxDb from a GRanges Object, which is a subset of  GencodeV14 mm10 (filter:  gene_id==" ENSMUSG00000060126.14"). 

> print(txdb)
TxDb object:
# Db type: TxDb
# Supporting package: GenomicFeatures
# Genome: NA
# transcript_nrow: 8
# exon_nrow: 24
# cds_nrow: 6
# Db created by: GenomicFeatures package from Bioconductor
# Creation time: 2017-12-01 20:21:53 +0100 (Fri, 01 Dec 2017)
# GenomicFeatures version at creation time: 1.24.5
# RSQLite version at creation time: 1.1-2
# DBSCHEMAVERSION: 1.1
> transcripts(txdb)
GRanges object with 8 ranges and 2 metadata columns:
      seqnames               ranges strand |     tx_id              tx_name
         <Rle>            <IRanges>  <Rle> | <integer>          <character>
  [1]    chr14 [75845093, 75848415]      + |         1 ENSMUST00000110894.8
  [2]    chr14 [75845302, 75848525]      + |         2 ENSMUST00000142061.2
  [3]    chr14 [75845331, 75846892]      + |         3 ENSMUST00000150047.7
  [4]    chr14 [75845332, 75845969]      + |         4 ENSMUST00000128889.1
  [5]    chr14 [75845355, 75847088]      + |         5 ENSMUST00000154533.7
  [6]    chr14 [75845900, 75848297]      + |         6 ENSMUST00000134040.1
  [7]    chr14 [75845919, 75846777]      + |         7 ENSMUST00000151751.1
  [8]    chr14 [75846185, 75846987]      + |         8 ENSMUST00000125146.1
  -------
  seqinfo: 22 sequences from an unspecified genome; no seqlengths

Creating a standard GeneRegionTrack is easy then:

 > grTrack <- GeneRegionTrack(txdb, name="Tpt1")

I inspected some slots of the GeneRegionTrack to understand the structure:

> feature(grTrack)
 [1] "utr5"  "utr5"  "ncRNA" "ncRNA" "ncRNA" "CDS"   "CDS"   "ncRNA" "ncRNA"
[10] "ncRNA" "ncRNA" "ncRNA" "ncRNA" "CDS"   "CDS"   "ncRNA" "ncRNA" "ncRNA"
...
> group(grTrack)
 [1] "ENSMUST00000110894.8" "ENSMUST00000142061.2" "ENSMUST00000150047.7"
 [4] "ENSMUST00000128889.1" "ENSMUST00000154533.7" "ENSMUST00000110894.8"
 [7] "ENSMUST00000110894.8" "ENSMUST00000150047.7" "ENSMUST00000154533.7"
[10] "ENSMUST00000128889.1" "ENSMUST00000134040.1" "ENSMUST00000151751.1"
[13] "ENSMUST00000125146.1" "ENSMUST00000110894.8" "ENSMUST00000142061.2"
...

I would have expected that feature(grTrack)[1] belongs to group(grTrack)[1] . The slot start(grTrack) seems to match, too. If I am right, the paramter "fill" has to have the same order. Thus, one shoud be able to fill transcripts parts by using slot "group". 

> displayPars(grTrack) <- list(fill=ifelse( group(grTrack) %in% "ENSMUST00000142061.2", "red", "green"))
> getPar(grTrack,"fill")
 [1] "green" "red"   "green" "green" "green" "green" "green" "green" "green"
[10] "green" "green" "green" "green" "green" "red"   "green" "green" "green"
...

However, the plot is strange. Exons of different transcripts are filled red instead of the choosen transcript.

> plotTracks( grTrack, transcriptAnnotation="transcript",  just.group="above" )

Is that a bug, an example of somewhat "erratic" you mentioned or do I  miss something? Using parameter "fill" within plotTracks is no option, because I want to use several other tracks. 

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

This behaviour is controlled by the collapse display parameter. There is a whole section on this in the vignette. However, there is no guarantee that you will get the intended color, since over-plotting on the graphic device is somewhat erratic, and it is hard to control which of the two exons is plotted first. 

ADD COMMENT
0
Entering edit mode

Yes, I tried different parameters. Some of them are fixed but some ones never changed. I guess I'll do the remaining manually in Illustrator. Thank you so much for your help. It's a great visualization tool.

ADD REPLY
0
Entering edit mode
li lilingdu ▴ 450
@li-lilingdu-1884
Last seen 6.5 years ago

load and use the geneModels data included in the package as examples, we only focus on two transcripts:

library(Gviz)
data(geneModels)
geneModels[geneModels$transcript %in% c('ENST00000487720','ENST00000481204'),]->dat

And set the filled color as the default #FFD58A for all exons except of four exons we hoping to highlighted using blue filled-color:

dat$fill.col<-rep(rep("#FFD58A",nrow(dat)))
dat$fill.col[which(dat$exon %in% c('ENSE00002788238','ENSE00001924916'))]<-'blue'

This might be important to order the exon for each transcript, and if not, the final graph might be confusing.

######order the exon for each transcript
do.call('rbind',lapply(split(dat,dat$transcript),function(xxx) xxx[order(xxx$start),]))->dat
######

Then do the plot, and some annotations were added to show the highlighted exons.

top <- GeneRegionTrack(dat, genome = 'hg19',chromosome ='chr7', name = "Gene example")
plotTracks(top,rotation.item=45,fontcolor.item='black',
               col=NULL,from=26881079,to=26906773 ,
               fill=dat$fill.col,
               transcriptAnnotation = "transcript",
               showExonId=T)

--- Gang

ADD COMMENT

Login before adding your answer.

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