Circos > Documentation > Tutorials > Recipes > Transparent Links
Loading
20 imperatives of information design — BioVis 2012

Use the latest version of Circos and read Circos best practices—these list recent important changes and identify sources of common problems.
If you are having trouble, post your issue to the Circos Google Group and include all files and detailed error logs. Please do not email me directly unless it is urgent—you are much more likely to receive a timely reply from the group.
Don't know what question to ask? Read Points of View: Visualizing Biological Data by Bang Wong from the Points of View series.

8 — Recipes

9. Transparent Links

This tutorial shows how you can improve the layout of your links using color transparency. The data for this tutorial was created using tools/randomlinks. This script generates random links between chromosomes based on your karyotype file and a flexible configuration which controls how many links to create, how large their spans should be, and so on. The configuration file, randomlinks.conf, can be found in this tutorial's directory.

using z-depth

If you have many ribbon links that overlap, one way to bring important (e.g. large) links to the foreground is to use z-depth.

This rule will set the z-depth for each link independently, as a function of its size. Larger links (i.e. those with large start/end spans) will have a high z-depth and therefore be shown on top.

<rules>
<rule>
condition  = 1
z          = eval( scalar min(var(size1),var(size2) ) )
</rule>
</rules>

The problem of link occlusion still remains - if you have a lot of links you won't be able to see them all.

defining transparent colors

To define a transparent color, add a fourth value to its RGB triplet. This value will be the transparency and it is a number between 0 (opaque) and 127 (fully transparent). For example, in addition to the default colors, I add a transparent black

<<include colors_fonts_patterns.conf>>
<colors>
blackweak = 0,0,0,100
</colors>

The transparency is 100/127, which gives blackweak an RGB value of 200,200,200 when drawn on white. When links are assigned this color,

<link>
ribbon = yes
color  = blackweak
...
</link>

the ribbons are drawn with transparency.

The blackweak color is black with 79% transparency. The alpha blending in GD results in multiplication of overlapping RGB colors. Thus, for every overlapping ribbon the RGB values are scaled from 200,200,200 by 79% (two overlapping ribbons result in 157,157,157, three in 123,123,123, and so on).

automatic definition of colors with transparency

By default, Circos defines 5 levels of transparency for each color you define.

Each color (e.g. pure red, pred=255,0,0) will yield 5 new color definitions pred_a1, pred_a2, pred_a3, pred_a4, and pred_a5 with each _aN color having a transparency N/(5+1). Thus pred_a1 will have a 17% transparency, pred_a2 33%, pred_a3 50%, pred_a4 67% and pred_a5 83%.

Note that pred_a0 is not defined (you already have it in pred) and pred_a5 is not 100% transparent.

With the automatic allocation of these colors, you can immediately use them

<link>
ribbon = yes
color  = black_a5 # black with 83% transparency
...
</link>

You can change the number of transparency steps using auto_alpha_steps in the <image> block.

<image>
<<include etc/image.conf>>
# overwrite auto_alpha_steps from default value included in etc/image.conf
auto_alpha_steps* = 10
</image>

adding transparency with rules

You can easily make elements that use opaque colors (e.g. red) to use transparent versions (e.g. red_a5) by writing rules to rewrite the color value.

For this example, I generated random links across all chromosomes in the human genome. Each link is conventionally colored by its starting chromosome.

hs7 127586339 141410899 hsY 30737607 31414129 color=chr7

but uses an opaque color. By writing the rule below, each color name has the transparency suffix (_aN) attached and becomes transparent.

<rule>
condition  = 1
color      = eval( var(color) ."_a4")
</rule>

With this rule, all links color names are modified (e.g. chr7 to chr7_a4) and shown at 67% transparency (default value of auto_alpha_steps=5).

transparency in bitmaps vs svg

Transparency in SVG is experimental. It works, but it is basic. For example, independent transparency for outlines is not yet available.