bernatgel / karyoploteR

karyoploteR - An R/Bioconductor package to plot arbitrary data along the genome
https://bernatgel.github.io/karyoploter_tutorial/
299 stars 42 forks source link

Individual Colors for Histone Tracks #146

Closed g-zavagno closed 10 months ago

g-zavagno commented 10 months ago

Hi, I've really enjoyed working with KaryoploteR and the tutorials have been fantastic. I was wondering whether it was possible to color each histone track individually? Such as H3K4me1 enhancers as yellow, and H3K4me3 promoters as red? I've tried making a vector:

kp <- kpPlotBigWig(kp, data=bigwig.file, ymax="visible.region", r0=at$r0, r1=at$r1, col = c("lightblue3", "green", "grey", "blue"), data.panel=2)

but get this error:

Error in is.na(col) && is.null(border) : 
  'length = 4' in coercion to 'logical(1)'

Thank you!

bernatgel commented 10 months ago

Hi @g-zavagno

The error you are seeing is because the function expects a single color, since it plots a single bigwig area plot. The idea is that you use multiple calls to kpPlotBigWig, one for each mark, and specify the color in each call.

If this is not what you are doing or it does not work for you, could you please send a minimal complete example with a minimal data file?

Hope this helps!

Bernat

g-zavagno commented 10 months ago

Hi, thanks for your quick reply. I've been using autotracks to plot 4 histone tracks in one data panel - so does this mean that when using autotracks, there's no option for changing the colour of each histone track? An example would actually be your tutorial on ENCODE Epigenetic plotting. I'm following the tutorial to the letter. As a solution to my problem, I could plot the four tracks without autotracks and configure the r0 and r1 to align them if I wanted them individually coloured.

bernatgel commented 10 months ago

Ok, now I see the problem.

Yes, you can combine autotracks with different colors. For that, you can use the same strategy as for the track labels. In the for loop you define i as the current histone mark number. With that you select the histone mark name with names(histone.marks)[i]. So the best approach would be to define a color vector before the start of the loop

histone.mark.colors <- c("red", "green", "blue", "orchid")

and then, in the call to kpPlotBigWig select the color you want for that track:

col=histone.mark.colors[i]

Does it make sense?

Bernat

g-zavagno commented 10 months ago

Thanks for your quick reply! Yes, it's worked perfectly. Seems so obvious in retrospect. Thanks again for your time!

Capture

Best,

Giulia

bernatgel commented 10 months ago

No problem!

Happy to help