Gviz (Bioconductor/R) ordering of groups in AnnotationTrack
1
0
Entering edit mode
8.5 years ago

Hi all,

I would like to order the groups in an AnnotationTrack. However, I cannot find a function to do this. In the code below I would like to position 'Group1' on the top, followed by 'GroupWithLongName' and afterwards 'AnotherGroup'.

Thank you in advance!

library(Gviz)
library(GenomicRanges)

# Creating example data
st <- c(0, 550, 0, 350, 550, 0, 550)
ed <- c(500, 800, 300, 500, 800, 500, 800)
str <- c("+", "+", "+", "-", "+", "+", "+")
gr <- c("Group1","Group1","AnotherGroup", "AnotherGroup", "AnotherGroup", "GroupWithLongName", "GroupWithLongName")
aTrack.groups <- AnnotationTrack(start=st, end=ed, strand=str, chromosome= 1,
                        genome="someGenome", feature="test", group=gr,
                        id=paste("annTrack item", 1:7),
                        name="Another annotation track",
                        stacking="squish")

ax <- GenomeAxisTrack()
# plotting
res <- plotTracks(list(ax, aTrack.groups), groupAnnotation = "group", cex.group = 1.2)

image: gviz plot

Gviz R • 3.2k views
ADD COMMENT
3
Entering edit mode
8.5 years ago
Jimbou ▴ 950

I'm not sure if there is a trick to order groups within an annotation track. I suggest to build three independent tracks like this:

df <- data.frame(gr,st,ed,str) #build dataframe
mytracks <- GenomeAxisTrack() # create list
# create three annotation tracks
aTrack <- sapply(levels(df$gr), function(x) AnnotationTrack(start=df$st[df$gr == x], end=df$ed[df$gr == x], strand=df$str[df$gr == x], chromosome= 1,group=df$gr[df$gr == x]))
mytracks <- append(mytracks,aTrack) # append the atrack to the other list
mytracks <- mytracks [c(4,2,3,1)] # ordering
res <- plotTracks(mytracks, groupAnnotation = "group", from = -300,cex.group =1) #plot
ADD COMMENT
0
Entering edit mode

Thanks! That is exactly what I was looking for!

ADD REPLY

Login before adding your answer.

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