lvulliard / BioCircos.R

Htmlwidgets binding R commands to the BioCircos.js library
GNU General Public License v2.0
37 stars 9 forks source link

CNV Track Colors #20

Open rkmeade opened 2 years ago

rkmeade commented 2 years ago

This is more of a request, but I am trying to use the CNV track for visualizing genome-wide QTL.

The issue I'm having is that it accepts only one color instead of a vector of colors, so all radial segments are monochromatic. Would it be possible to modify this track to either accept a single color or a vector of colors?

Thank you for this awesome package!

rchapple2 commented 2 years ago

This would be very helpful. I tried passing a vector of colors, and it correctly assigns each CNV to the appropriate color in the tracks[[1]][[2]]$CNVColor slot. However, it still renders every CNV one color.

koalive commented 2 years ago

It would indeed be a nice addition. As a workaround, it is already possible to define one track per segment. This is doable also when you have a vector of colors (one per segment, or a few colors that should be cycled through). Adapting the example from the vignette, that would look like that:

library(BioCircos)

# Arcs coordinates
snvChr = rep(4:9, 3)
snvStart = c(rep(1,6), rep(40000000,6), rep(100000000,6))
snvEnd = c(rep(39999999,6), rep(99999999,6), 
  191154276, 180915260, 171115067, 159138663, 146364022, 141213431)
# Values associated with each point, used as radial coordinate 
#   on a scale going to minRadius for the lowest value to maxRadius for the highest value
snvValues = (1:18%%5)+1
# Alternate between colors for each SNV track
snvColors = c("#CC0000", "#00CC00", "#0000CC")
# Loop over each segment and define it as a track
tracks = mapply(
    function(v,w,x,y,z) BioCircosCNVTrack('cnv_track', v, w, x, y, color = z, range = c(0,6)),
    as.character(snvChr), snvStart, snvEnd, snvValues, snvColors
)
tracks = BioCircosTracklist() + unname(tracks)

# Add background
tracks = tracks + BioCircosBackgroundTrack("arcs_background", colors = "#2222EE")

BioCircos(tracks, genomeFillColor = "YlOrBr", genomeTicksDisplay = F, genomeLabelDy = 0)

Hope that helps.