circos是基因组学最经常使用的图之一,软件按照调试已经完成了,相对简单。circos最繁盛的地方是学习conf文件配置,下面从零开始记录circos的学习历程。
1. Hello World
CIRCOS.CONF
# 这是一个极简的配置文件,里面仅包含circos必须的信息
#
# 配置染色体名称、大小和颜色
karyotype = data/karyotype/karyotype.human.txt
# <ideogram>块 通常定义染色体的位置、大小、标签或其他属性。
#下方</ideogram> 表示此代码块结束,一个ideogram块代表circos图中的一圈。
<ideogram>
<spacing>
# 这里表示两个染色体之间的距离,后缀r表示圆周的相对值。
default = 0.005r
# 也可以特定增加某两个染色体之间的距离,例如
#<pairwise hsY;hs1>
#spacing = 10r
#</pairwise> ## 这里表示第一次pairwise块结束
#<pairwise hsY;hs1>
#spacing = 10r
#</pairwise> ##这样我们就增大1号染色体 和 上下染色体的距离。
</spacing> ## 这里表示 spacing块结束
# 指定Ideogram 的位置,厚度和充填。
#
# Radial代表ideogram图形的位置,通过它可以设定circos每层所在的位置。
radius = 0.90r ## 这个数越小,图形越靠近圆心。
# Thickness 指定 ideograms图形的厚度,可以是绝对值(p后缀),也可以是相对值(r后缀), 当为相对值时是radius的分数。
#
thickness = 20p ##
# Ideograms可以被充填,添加外围轮廓,或both。
#当被充填时,将根据karyotype文件最后一列内容获取颜色,或者通过chromosomes_colors设置颜色,颜色设定方法,后续再讨论。
#
#当stroke_thickness=0p or或缺少此参数时,ideogram图形没有外轮廓,stroke_color参数无意义。
fill = yes
stroke_color = dgrey
stroke_thickness = 2p
</ideogram> ## 到这里一个 ideogram块结束
################################################################
# 后面的内容时circos标准且必须的, 每个circos作图都会至少需要这些参数,在需要的时候可以被修改,具体内容请查看 etc/文件夹
#
<image>
# Included from Circos distribution.
<<include etc/image.conf>>
</image>
# RGB/HSV color definitions, color lists, location of fonts, fill
# patterns. Included from Circos distribution.
#
# In older versions of Circos, colors, fonts and patterns were
# included individually. Now, this is done from a central file. Make
# sure that you're not importing these values twice by having
#
# *** DO NOT DO THIS ***
# <colors>
# <<include etc/colors.conf>>
# <colors>
# **********************
<<include etc/colors_fonts_patterns.conf>>
# Debugging, I/O an dother system parameters
# Included from Circos distribution.
<<include etc/housekeeping.conf>>
![](https://img.haomeiwen.com/i18085596/6b15373ccc39e63a.png)
2. TICKS & LABELS
#下面学习添加ideogram坐标以及标签
#为此, 需要在 `<ideogram>`块里拓展<ticks>块。.
### IDEOGRAM LABELS
#Labels 的参数格式多、设置灵活,这里展示最简单的设置。
<ideogram>
<spacing>
default = 0.005r
</spacing>
# Ideogram position, fill and outline
radius = 0.90r
thickness = 20p
fill = yes
stroke_color = dgrey
stroke_thickness = 2p
# 简单的 标签设置.
# 标签内容由karyotype 文件定义
show_label = yes
# see etc/fonts.conf for list of font names
label_font = default
label_radius = 1r + 15p ##标签位置可以多种方式定义,这里使用相对位置 +绝对位置的方式。
label_size = 30
label_parallel = yes
</ideogram>
刻度以及标签设定
下面是基础设定
show_ticks = yes
show_tick_labels = yes
<ticks>
radius = 1r
color = black
thickness = 2p
# 刻度标签是通过乘以刻度位置得到的
# by 'multiplier' and casting it in 'format':
#
# sprintf(format,position*multiplier)
multiplier = 1e-6
# %d - 整数
# %f - 浮点数
# %.1f - 保留小数点后一位
# %.2f - 保留小数点后两位
#
format = %d
<tick>
spacing = 5u
size = 10p
</tick>
<tick>
spacing = 25u
size = 15p
show_label = yes
label_size = 20p
label_offset = 10p
format = %d
</tick>
</ticks>
随后,将上面两段代码分别保存成ideogram.conf和ticks.conf文件,并修改circos.conf,将ideogram作为单独模块隔离出来,同时指定其他模块的作图单位chromsomes_units参数:
# circos.conf
karyotype = data/karyotype/karyotype.human.txt
chromosomes_units=1000000
<<include Feng.ideogram.conf>>
<<include Feng.ticks.conf>>
# 后面的内容都是标准且必须的。每个circos作图都会至少需要这些参数,在需要的时候可以被修改,具体内容请查看 etc/文件夹
<image>
# 在circos文件夹下
<<include etc/image.conf>>
</image>
# 颜色定义
<<include etc/colors_fonts_patterns.conf>>
# 调试参数
<<include etc/housekeeping.conf>>
运行以后可以得到一个有标签的circos
![](https://img.haomeiwen.com/i18085596/5d247c76cc75366d.png)
3. 染色体选择,缩放,颜色以及方向
染色体选择
默认是展示所有的染色体,顺序是按照文件里的顺序,但是可以通过chromsomes_display_default参数设定需要展示的部分:
chromosomes_display_default = no
chromosomes = hs1;hs2;hs3;h4 ##分号作为分隔符
#
chromosomes = /hs[1-4]$/ ## 正则表达式
#
chromosomes = /hs[1-4]$/;hs10;hs11 ## 混用
#
chromosomes = /hs[1-4]$/;-hs3 ## ‘-’ 号表示不显示。
#
染色体缩放
可以通过相对指定和绝对指定两种模式来设定染色体大小。
绝对指定如下:
# hs1 0.25x zoom
# hs2 2.00x zoom
chromosomes_scale = hs1=0.25,hs2=2.0
相对指定如下:
# hs1 25% of figure
# hs2 50% of figure
chromosomes_scale=hs1=0.25r,hs2=0.50r
也可以指定多少个染色体分享多少比例的图片
# hs1,hs2 50% of figure (后缀 rn 表示均分)
chromosomes_scale=/hs[12]/=0.50rn
#或一起均分
chromosomes_scale = /./=1rn
染色体颜色
默认颜色设定来自karyotype文件,可以通过chromosomes_color参数设定
chromosomes_color = hs1=red,hs2=orange,hs3=green,hs4=blue
染色体方向
默认染色体的排列方向事顺时针,可以通过<image>模块里的angle_orientation参数来设定为逆时针:
<image>
angle_orientation* = counterclockwise
# * 号的意义在于覆盖一个参数
<<include etc/image>>
</image>
# 或使用chromosomes_reverse反转某一个或多个染色体的排列顺序
chromosomes-reverse=/hs[14]$/
染色体径向位置
默认事将所有的染色体以一样的径向位置排列,通过<ideogram>模块里的radial参数,可以改变所有染色体的径向位置,或者通过chromosomes_radius 参数设定某一个或多个染色体的径向位置
chromosomes_radius = hs1:1.1r
![](https://img.haomeiwen.com/i18085596/548d41926fbd3ca3.png)
柱状图
circos支持线图、散点图、柱状图和热图等多种展示形式。
数据格式
线图、散点图、热图和柱状图使用的数据格式相同
#chr start end value [options]
...
hs3 196000000 197999999 71.0000
hs3 198000000 199999999 57.0000
hs4 0 1999999 28.0000
hs4 2000000 3999999 40.0000
hs4 4000000 5999999 59.0000
...
# [options]列可以展示颜色或标识符
hs3 196000000 197999999 71.0000 fill_color=blue
#参数(如id)可以和<rule>连用,用于选择或修改数据点
# in data file
hs3 196000000 197999999 71.0000 id=abc
# in rule block
<rule>
condition = var(id) eq "abc"
fill_color = blue
</rule>
图块
每一个直方图都定义在<plots>块的一个<plot>内
<plots>
<plot>
type = histogram
...
</plot>
<plot>
type = histogram
...
</plot>
...
</plots>
直方图
本教程定义了两个直方图:规则直方图和堆叠直方图。
除了指定type和file参数外,r0和r1分别定义轨道的内部和外部半径。
type = histogram
file = data/5/segdup.hs1234.hist.txt
r1 = 0.88r
r0 = 0.81r
链接bins
直方图是由bins组成的,如果bins像下面那样不相邻
hs1 10 20 0.5
hs1 30 40 0.25
则需要选择拓展bins的外延,直到遇到相邻为止
extend_bin = no | yes
充填和颜色
直方图既可以充填又可以设定轮廓,本例充填very dark grey
默认设定保存在etc/tracks/*.conf文件下,直方图默认参数如下
# etc/tracks/histogram.conf
color = black
thickness = 1
r1 = 0.89r
r0 = 0.8r
orientation = out
直方图方向
orientation = in | out
管理默认参数
# 关闭轮廓设置的两种方法
thickness = 0p
thickness = undef
规则 Rule
隐藏1号染色体直方图
<rule>
condition = on(hs1)
show = no
</rule>
导入rule
有些rule可以重复利用,可以将其保存在文件里,然后再导入
<rules>
<<include exclude.hs1.rule>>
</rules>
改变格式参数
规则可以更改数据点的可见性、格式和值。例如,通过设置show=no,将一个数据点隐藏。可以设置任何格式参数
<rule>
condition = on(hs1)
fill_color = blue
color = vdblue
thickness = 2p
</rule>
rule中的条件
rule的条件遵循perl代码
# applies to every data point - always true
1
# check whether a data point is on a chromosome
var(chr) eq "hs1"
on(hs1) # shortcut
# check whether a data point is not on a chromosome
var(chr) ne "hs1"
!on(hs1)
# combine tests with or (||)
on(hs1) || on(hs2)
var(chr) =~ /hs(1|22)$/;
# check position
var(start) > 10Mb
# use the value
var(value) < 0.05
# use any parameter
var(color) eq "red"
var(stroke_color) eq "vdred"
还可以设置多个条件
<rule>
# data point must be on hs1 and value < 0.05
condition = on(hs1)
condition = var(value) < 0.05
...
</rule>
在rule中引用数据点参数
例如在文件中定义id和mult
# in data file
hs3 196000000 197999999 71.0000 id=abc,mult=5
然后在rule中调用
<rule>
condition = var(id) eq "abc"
fill_color = blue
value = eval(var(value)*var(mult))
</rule>
堆砌直方图
直方图可以通过堆砌方式展示,文件格式如下:
#chr start end value,value,value,... [options]
...
hs3 196000000 197999999 0.0000,7.0000,64.0000,0.0000
hs3 198000000 199999999 21.0000,6.0000,18.0000,12.0000
hs4 0 1999999 5.0000,3.0000,1.0000,19.0000
hs4 2000000 3999999 1.0000,6.0000,16.0000,17.0000
hs4 4000000 5999999 1.0000,13.0000,25.0000,20.0000
...
当文件中有多个values存在得时候,circos会自动绘制堆砌直方图。
![](https://img.haomeiwen.com/i18085596/801fdea4786047fd.png)
网友评论