技巧(五)
17. 自动化热图
17.1 更改热图颜色
热图的颜色是使用颜色列表指定的
color = red,green,blue
或
color = spectral-11-div
计数器可用于动态更改配色方案
color = eval(sprintf("spectral-%d-div",remap_round(counter(plot),0,99,11,3)))
将 0-99
从外到内映射到颜色 spectral-11-div,...,spectral-3-div
也可以组合多个颜色表
color = eval(sprintf("blues-%d-seq-rev,oranges-%d-seq-rev",
remap_round(counter(plot),0,99,9,3),
remap_round(counter(plot),0,99,9,3)))
由于内侧的轨迹分辨率更低,因此减少颜色数量可以使图像更清晰
17.1 对数范围调整
scale_log_base
参数用于控制热图值映射到颜色的方式,默认值为 1
,表示线性映射。
在保持颜色列表不变的情况下,通过改变 scale_log_base
的值,log_scale_base < 1
会增加小值颜色的范围,log_scale_base > 1
会增加大值颜色的范围。
color = spectral-11-div
# 0.05, 0.10, 0.15, ..., 5.00
scale_log_base = eval(0.05*(1+counter(plot)))
![](https://img.haomeiwen.com/i18546936/067020d030436080.png)
18. 圆形堆积条形图
18.1 创建轴
我们创建一条长度为 1000
的 ideogram
,并将数据进行标准化,使其不超过 1000
,轴名为 gh
# scale.txt
chr - gh gh 0 1000 black
并设置
# circos.conf
...
karyotype = scale.txt
chromosomes_units = 1
chromosomes_display_default = yes
...
18.2 创建数据
我们随机创建 27
个数据文件,每个文件包含 4-10
个数据点。
并命名为 species.0.txt ... species.26.txt
# species.0.txt
gh 0 401 id=gh6
gh 401 468 id=gh8
gh 468 674 id=gh9
gh 674 1000 id=gh10
...
# species.26.txt
gh 0 235 id=gh3
gh 235 454 id=gh4
gh 454 534 id=gh7
gh 534 710 id=gh8
gh 710 757 id=gh9
gh 757 1000 id=gh10
每个数据值都有一个唯一的 id(gh1 ... gh10)
用于设置颜色
18.3 自动化显示轨迹
我们总共绘制 21
个数据集,想要更多的图像可以添加 <<include speciesplot.conf>>
# circos.conf
<plots>
<<include speciesplot.conf>>
<<include speciesplot.conf>>
<<include speciesplot.conf>>
<<include speciesplot.conf>>
<<include speciesplot.conf>>
<<include speciesplot.conf>>
<<include speciesplot.conf>>
</plots>
speciesplot.conf
为
<plot>
type = highlight
file = species.counter(plot).txt
r0 = eval(sprintf("%fr",conf(track_start) - conf(track_step) * counter(plot) ))
r1 = eval(sprintf("%fr",conf(track_start) - conf(track_step) * counter(plot) + conf(track_width) ))
fill_color = black
stroke_thickness = 10p
stroke_color = white
#stroke_color = black
<<include ghcolorrule.conf>>
</plot>
18.4 为数据着色
我们用 rule
块为不同的 id
着色
<rules>
<rule>
condition = 1
# ghN -> spectral-10-div-N
fill_color = eval(sprintf("spectral-10-div-%d",substr(var(id),2)))
</rule>
</rules>
18.5 放置轨迹
我们用三个 track_*
参数控制轨迹的放置
# if using 7 data sets
# well spaced
#track_width = 0.08
#track_step = 0.1
#track_start = 0.9
# abutting
track_width = 0.1
track_step = 0.1
track_start = 0.9
# if using 3x7 data sets
#track_width = 0.03
#track_step = 0.04
#track_start = 0.95
![](https://img.haomeiwen.com/i18546936/b88d23671399ebef.png)
19. 细胞周期 —— I
本例将展示如何绘制细胞周期图片(G1, S, G2, M)
,并使用 link
和 text
进行注释
19.1 周期阶段
细胞周期分为四个阶段 gap 1 (G1)
, synthesis (S)
, gap 2 (G2)
和 mitosis (M)
。在这我们不考虑 G0
期。
每个阶段的持续时间大致为:G1 45%
, S 35%
, G2 15%
和 M 5%
。
第一步是将每个阶段定义为单独的轴。circos
需要整数坐标,所以我任意选择使每个相位轴有 100
个单位长度。图像中轴长度的变化将通过 chromosomes_scale
设置
# phases.txt
chr - g1 g1 0 100 greys-4-seq-1
chr - s s 0 100 greys-4-seq-2
chr - g2 g2 0 100 greys-4-seq-3
chr - m m 0 100 greys-4-seq-4
让每个轴长度相等有助于定义坐标。例如,如果要将 25%
的坐标放置在相位 G1
中 g1 25 25
19.2 阶段颜色
在这里,我们使用灰色的调色板 greys-4-seq
,将阶段颜色变灰,能够更加突出其他部位的颜色
你可以用 chromosomes_color
为轴设置颜色
chromosomes_color = g1=spectral-7-seq-2,s=spectral-7-seq-3,g2=spectral-7-seq-6,m=spectral-7-seq-7
也可以定义颜色变量并用 conf()
设置 chromosomes_color
的颜色
palette = specral-7-seq
chromosomes_color = g1=conf(palette)-2,s=conf(palette)-3,g2=conf(palette)-6,m=conf(palette)-7
可以使用 <phase>
块添加颜色索引的定义,可以使定义更清晰
palette = spectral-7-div
<phases>
g1 = 2
s = 3
g2 = 6
m = 7
</phases>
chromosomes_color = g1=conf(palette)-conf(phases,g1),
s=conf(palette)-conf(phases,s),
g2=conf(palette)-conf(phases,g2),
m=conf(palette)-conf(phases,m)
这样就不用更改 chromosomes_color
的值,而是只要在 <phases>
中设置索引或更改 palette
参数的值
19.3 轴以及标记
每个阶段为一个轴
我们为每个阶段定义自己的轴,具有唯一的名称和坐标。这样可以方便的为每个阶段设置特定的坐标位置
# 25% into G1
g1 25 25
# 5% into G2
g2 5 5
# 50% into M
m 50 50
但是也有一个缺点,就是要计算周期内的位置坐标会比较困难
刻度标记
我们设置了两个刻度,每 10%
设置一个刻度,每 5%
在设置一个刻度
<ticks>
spacing_type = relative
<tick>
rspacing = 0.05
</tick>
<tick>
rspacing = 0.10
</tick>
</ticks>
然后设置对应的刻度标签,在 10%
的刻度处显示对应的百分比
<ticks>
label_relative = yes # the label will be pos/axis_length
format = %d
rmultiplier = 100 # 0.45 will be shown as 0.45*100=45
suffix = %
<tick>
rspacing = 0.10
show_label = yes
label_size = 26p
label_offset = 5p
</tick>
</ticks>
并为刻度设置网格,可以将刻度的分割线延伸到图像的其他部分
show_grid = yes
<ticks>
grid = yes
grid_start = dims(ideogram,radius_outer) # grid runs from outer ideogram edge
grid_end = dims(ideogram,radius_inner) # ... to inner ideogram edge
grid_color = white
<tick>
rspacing = 0.05
grid_thickness = 1p
</tick>
<tick>
rspacing = 0.10
grid_thickness = 2p
</tick>
</ticks>
19.4 为每个阶段添加缩放
我们根据每个阶段持续的时间,为其设置相应的缩放
chromosomes_scale = g1=0.45,s=0.35,g2=0.15,m=0.05
相比于坐标的缩放,这种方法的好处是能够在更改阶段长度是保持所有点的相对位置不变。
例如
# 45:35:15:5
chromosomes_scale = g1=0.45,s=0.35,g2=0.15,m=0.05
# shorter G1: 20:60:15:5
chromosomes_scale = g1=0.20,s=0.60,g2=0.15,m=0.05
19.5 删除一个阶段
#don't show phase m
chromosomes = -m
19.6 标记细胞周期阶段的位置
假设有 7
个基因 (A...I)
,我们定义数据文件
# genes.txt
# A active at 5% into g1
g1 5 5 0 name=A,type=1
# B active at 25% into g1
g1 25 25 0 name=B,type=1
g1 45 45 0 name=C,type=1
g1 55 55 0 name=D,type=1
g1 75 75 0 name=E,type=1
s 25 25 0 name=F,type=1
s 75 75 0 name=G,type=1
g2 15 15 0 name=H,type=2
g2 35 35 0 name=I,type=2
g2 65 65 0 name=J,type=2
用于在图中标识这 7
个基因。
我们设置最小刻度在轴内部位置
r0 = 0.95r
但是文本标签在对应阶段轴的外部,然后用标签 link
连接起来
show_links = yes
link_dims = 0p,200p,20p,10p,20p
link_thickness = 3
link_color = black
然后用 rule
为文本标签着色
<rule>
condition = 1
value = eval(var(name))
</rule>
19.7 用符号标记细胞周期相位位置
在图上放置符号的一种方法是定义零高度的散点图。我们可以使用与文本标签相同的数据文件。并用 rule
根据 type
参数更改符号的颜色
<plot>
type = scatter
file = genes.txt
r0 = 0.95r
r1 = 0.95r
glyph = circle
glyph_size = 36
color = white
stroke_color = black
stroke_thickness = 2
<rules>
<rule>
condition = var(type) == 1
color = blues-5-seq-4
</rule>
<rule>
condition = var(type) == 2
color = reds-5-seq-4
</rule>
</rules>
</plot>
19.8 连接细胞周期位置
要用曲线将细胞周期中的位置连接起来,这里的输入数据文件将每个连接定义为一个坐标对,并带有可选参数
# links.txt
g1 5 5 g1 25 25 type=1
g1 5 5 g1 45 45 type=1
g1 5 5 g1 55 55 type=1
g1 5 5 g1 75 75 type=1
g2 15 15 g2 35 35 type=2
g2 15 15 g2 65 65 type=2
...
然后设置
<link>
file = links.txt
radius = 0.95r
bezier_radius = 0r
# shorter links will be drawn closer
# to the edge of the circle
bezier_radius_purity = 0.1
crest = 1
thickness = 3
<rules>
<rule>
condition = var(type) == 1
color = red
</rule>
<rule>
condition = var(type) == 2
color = blue
</rule>
</rules>
</link>
最后,图片是这样子的
![](https://img.haomeiwen.com/i18546936/25ba6aa7000edb0d.png)
完成。
改天再介绍另一种绘制方法。
网友评论