1. circos 的安装
circos 是基于perl 语言的软件,常用来做基因组的圈图或比较基因组学的图片,而且不仅仅这些,功能非常强大.官方教程
perl模块的安装:
sudo perl -MCPAN -e shell
install [模块名]
Config::General
File::Basename
File::Spec::Functions
GD #先安装libgd模块
GD::Polyline
Getopt::Long
IO::File
List::Util
Math::Bezier
Math::BigFloat
Math::Round
Math::VecStat
Memoize
Params::Validate
Pod::Usage
Readonly
Set::IntSpan
Regexp::Common
然后下载circos 软件解压到常用软件文件夹内,然后将/bin/circos加入到环境变量
sudo gedit ~/.bashrc
export PATH="$PATH:~/tools/circos-0.69-6/bin/circos"
#或者利用重定向的方法
echo "export PATH='$PATH:~/tools/circos-0.69-6/bin/circos" >> ~/.bashrc
#立即生效的:
source ~/.bashrc
circos的使用参数
-version
查询circos版本
-modules
检测perl模块
-conf <string>
输入主配置文件
-outputdir <string>
设置输出文件的路径
-outputfile <string>
设置输出文件名,该参数的值以.png为后缀
-svg
生成svg结果文件
-nosvg
不生成svg结果文件
2. circos 的简单介绍
可视化的工作流程
- 确定如何展示数据(最难的部分)
- 原始数据转化为Circos所需文件格式
- 编写配置文件
- 运行circos 得到PNG和SVG文件
- 编辑输出文件用于发表(增加说明和文本标签等)
整体说明
配置文件是以block 的形式来分层进行编写,类似html的标签,可以进行分层的嵌套
配置参数可以存放到四种位置: global track data rules
备注:参数的优先级问题中的参数会覆盖 data file 中的参数;data 中的参数会覆盖 或者中的参数; 或中的参数会覆盖 或者 中的参数
一般情况下使主文件模块化,通常使用«include [模块名]»导入配置模块
下面两个文件在主配置文件中一定要出现,一般不需要改动
<<include etc/colors_fonts_patterns.conf>>
<<include etc/housekeeping.conf>>
而colors_fonts_patterns.conf文件本身又包含了三个文件,内容如下:
<colors>
<<include etc/colors.conf>>
</colors>
<fonts>
<<include etc/fonts.conf>>
</fonts>
<patterns>
<<include etc/patterns.conf>>
</patterns>
3. 相关配置文件的简单配置
circos.conf文件的配置
karyotype = data/karyotype/karyotype.human.txt
##根据染色体本身的长度来设定一个单位,用'u'来表示
chromosomes_units = 1000000
##以下两个写在单独的文件中
<<include ideogram.conf>>
<<include ticks.conf>>
#######################################################
##下面的内容每一个配置文件都需要的,一般情况下不需要修改默认的设置
#######################################################
<image>
<<include etc/image.conf>>
</image>
<<include etc/colors_fonts_patterns.conf>>
<<include etc/housekeeping.conf>>
ticks.conf 文件的配置
##下面两个参数是全局配置,决定了图象中染色体上是否会现实刻度以及刻度上的数字
show_ticks = yes
show_tick_labels = yes
<ticks>
radius = 1r
##刻度线的颜色
color = black
##刻度线的厚度
thickness = 2p
##调整刻度线上数字的位数
multiplier = 1e-6
##以下四个参数可以确定数字的展示效果,比如整数形式,或者若干位小数
## %d -integer 整数
## %f -float 小数
## %.1f -一位小数
## %.2f -两位小数
format = %d
<tick>
##小刻度
spacing = 5u
size = 10p
</tick>
<tick>
##大刻度
spacing = 25u
#这个spacing 是上一个的5倍小刻度线被分成5份
size = 15p
show_label = yes #是否要展示数字
label_size = 20p #展示数字的大小
label_offset = 10p #偏移量,刻度尺上的数字离刻度线的距离
format = %d #展示形式
</tick>
</ticks>
ideogram.conf
<ideogram>
<spacing>
default = 0.005r
#通常使用默认值即可,表示两个染色体之间的距离
</spacing>
#接下来定义Ideogram 的位置,填充和轮廓参数
radius = 0.90r #半径
thickness = 20p #厚度
fill= yes #是否填充
stroke_color= dgrey #颜色
stroke_thickness = 2p #厚度
##与下面参数对比
#radius = 0.80r
#thickness = 25p
#fill = yes
#stroke_color = blue
#stroke_thickness = 5p
#对ideogram 的标签进行最基本的设置
show_label = yes
label_font = default #默认字体 bold light
label_radius = dims(image,radius)-60p #标签的位置
label_size = 30
label_parallel = yes
#这个参数是设置label和圆圈是否平行,如果选择no则垂直与圆的直径
</ideogram>
运行:circos -conf circos.conf -outputfile 1.png
得到下图:
ideogram的选择 颜色 比例 和方向
#circos 默认展示karyotype原始文件的所有内容,但是可以选择展示一部分
karyotype = data/karyotype/karyotype.human.txt
chromosomes_units = 1000000
chromosomes_display_default = no
#显示连续的4条染色体
#chromosomes = /hs[1-4]$/
chromosomes = hs1;hs2;hs3;hs4
#染色体在图中占用的相对量
#hs1 = 0.5
#使用相对单位"r"其含义是相对于圆形周长的多少
#hs1 = 0.5r
#'rn'后缀表示其他几条所占用的比例
#/hs[234]/=0.5rn 将会使hs2,hs3,hs4各占图中的16%
chromosomes_scale= hs1=0.5r,/hs[234]/=0.5rn
#默认情况下,展示方向是顺时针方向,但是可以在<image>block使用
#angle_orientation=(clockwise or counterclockwise)
#也可以使用'chromosomes-reverse'将某一条染色体方向扭转
#chromosomes_reverse = /hs[234]/
#对每一条染色体的颜色进行设置
chromosomes_color= hs1=red,hs2=orange,hs3=green,hs4=blue
#改变某条染色体的位置
chromosomes_radius = hs4:0.9r
##以下两个写在单独的文件中
<<include ideogram.conf>>
<<include ticks.conf>>
<<include links.conf>>
##下面的内容每一个配置文件都需要的,一般情况下不需要修改默认的设置
<image>
<<include etc/image.conf>>
</image>
<<include etc/colors_fonts_patterns.conf>>
<<include etc/housekeeping.conf>>
links.conf 的配置
<links>
<link>
#文件的一般格式为:
#chr1 start end chr2 start end
#hs1 465 30596 hs2 114046768 114076456
#表明这两个染色体区域有联系,如这个区域的序列长度>1kb且序列相似性>=90%
file = data/5/segdup.txt
#link 曲线的半径
radius = 0.8r
#贝塞尔曲线设大后曲线比较扁平
bezier_radius = 0r
#设置曲线的颜色,a4代表透明度
color = black_a4
#link 曲线的厚度
thickness = 2
#可以设置多个rules 来对link进行设置,对特定设置展示或者不展示
<rules>
<rule>
#如果条件为真,rule就会生效,其他的rules就不再起作用(但是flow=continue时除外)
#如果条件为假,则检查下一个rule
#var(X) 中变量X代表数据点
condition = var(intrachr) #代表染色体内部
# 任何染色体内部的 links 都不会被展示,后面的其他rules也不会生效
show = no
</rule>
<rule>
condition = 1
#所有条件下都适用时令condition =1
color = eval(var(chr2))#取出二号染色体的信息重新评估其颜色
#注意:如果写成color = var(chr2)那所有的线就是都是2号染色体的颜色了。
flow = continue
#应用完这一条规则后继续下一个
</rule>
<rule>
# 如果link从hs1开始,则link曲线半径为0.99r
condition = from(hs1)
radius1 = 0.99r
</rule>
<rule>
# 如果link结束于hs1,则其link曲线的半径为0.99r
condition = to(hs1)
radius2 = 0.99r
# 'radius2'代表link变量'radius'的结束位置
</rule>
</rules>
</link>
</links>
运行命令: circos -conf circos.conf -outputfile 2.png
生成下图:
直方图的绘制
将基因组序列的GC含量,表达量以直方图的形式在圈图中展示出来,将以下配置信息放入到单独的配置文件中,命名为plots_histogram.conf
<plot>
#首先要说明类型,比如histogram 或者scatter(散点图)
type = histogram
#文件数据的类型
#chromosome start end data
#hs1 0 1999999 180.0000
file = data/5/segdup.hs1234.hist.txt
#写清楚引用原始文件的位置
#设置直方图的位置,默认的方向向外
r1 = 0.88r
r0 = 0.81r
#柱状图的填充颜色
fill_color = vdgrey
#vdgrey的意思是very deep
#如果不想要轮廓,可以将outline的thickness设置为20
#thickness = 0p
extend_bin = no
##可以加入相关的rule
<rules>
<<include rule.exclude.hs1.conf>>
</rules>
</plot>
##柱状图的堆叠
#指定了type 后,而且有多个value会自动绘制堆叠的柱状图
<plot>
type = histogram
file = data/5/segdup.hs1234.stacked.txt
r1 = 0.99r
r0 = 0.92r
#使用默认给定的颜色
fill_color = hs1,hs2,hs3,hs4
extend_bin = no
#柱状图的延伸方向可以单独进行设置
orientation = in
#修改为no 则向外
<rules>
<<include rule.exclude.hs1.conf>>
</rules>
</plot>
此处可以创建rule.exclude.hs1.conf 不显示第一条染色体
<rule>
condition = on(hs1)
show = no
</rule>
运行命令: circos -conf circos.conf -outputfile 3.png
图片如下:
Axes和Backgrounds的配置
backgrounds.conf 文件
#整体底色是一个颜色,然后给了三个相对区间,最后的效果是显示四个颜色
<backgrounds>
#只在有ideogram的位置显示背景
show = data
<background>
color = vvlgrey
</background>
<background>
color = vlgrey
y0 = 0.2r
y1 = 0.5r
</background>
<background>
color = lgrey
y0 = 0.5r
y1 = 0.8r
</background>
<background>
color = grey
y0 = 0.8r
</background>
</backgrounds>
axes.conf 文件
#每隔0.1r 画一条坐标轴,那这个track 上应该有10个这样的坐标轴
#如果是position = o.5r 表示只在0.5r处有一条坐标轴
<axes>
#只在有track 的地方显示坐标轴
show = data
thickness = 1
color = lgrey
<axis>
spacing = 0.1r
</axis>
<axis>
spacing = 0.2r
color = grey
</axis>
<axis>
position = 0.5r
color = red
</axis>
<axis>
position = 0.85r
color = green
thickness = 2
</axis>
</axes>
另外修改主配置文件 circos.conf,注意上述两个文件的引用位置
karyotype = wode/karyotype/karyotype.human.txt
chromosomes_units = 1000000
chromosomes_display_default = no
chromosomes = /hs[1234]$/
chromosomes_radius = hs4:0.9r
<colors>
chr1* = red
chr2* = orange
chr3* = green
chr4* = blue
</colors>
chromosomes_reverse = /hs[234]/
chromosomes_scale = hs1=0.5r,/hs[234]/=0.5rn
<plots>
<plot>
type = histogram
file = data/5/segdup.hs1234.hist.txt
r1 = 0.88r
r0 = 0.81r
fill_color = vdgrey
extend_bin = no
<rules>
<<include rule-exclude-hs1.conf>>
</rules>
<<include backgrounds.conf>>
</plot>
<plot>
type = histogram
file = data/5/segdup.hs1234.stacked.txt
r1 = 0.99r
r0 = 0.92r
fill_color = hs1,hs2,hs3,hs4
extend_bin = no
orientation = in
<rules>
<<include rule-exclude-hs1.conf>>
</rules>
<<include axes.conf>>
</plot>
</plots>
##以下三个写在单独的文件中
<<include ideogram.conf>>
<<include ticks.conf>>
<<include links.conf>>
##下面的内容每一个配置文件都需要的,一般情况下不需要修改默认的设置
<image>
<<include etc/image.conf>>
</image>
<<include etc/colors_fonts_patterns.conf>>
<<include etc/housekeeping.conf>>
运行命令: circos -conf circos.conf -outputfile 4.png
图片如下:
heatmap 的简单配置
创建主配置文件plots_heatmap.conf
<plot>
#热图和柱状图展示内容差不多,只是展示方法不同
#颜色选取规则:先设定value 的最大最小值,而且假设选取的
#颜色list 有N个值
#如果是线性的heat map 计算方式如下:
#f = (value -min)/(max-min)
#n = N * f
type = heatmap
#数据文件的格式
#chrID start end data class
#hs1 0 1999999 113.0000 id=hs1
#hs1 0 1999999 40.0000 id=hs4
file = data/5/segdup.hs1234.heatmap.txt
r1 = 0.89r
r0 = 0.88r
# 颜色的选取有多种参考依据
# Brewer palletes (see etc/colors.brewer.lists.conf) as
# N-step hue (hue-sN, e.g. hue-s5 =hue000,hue005,hue010,...)
# N-color hue (hue-sN, e.g. hue-3 =hue000,hue120,hue140)
color = hs1_a5,hs1_a4,hs1_a3,hs1_a2,hs1_a1,hs1
#a代表颜色的透明度
# 如果是非线性 heat map,使用如下方式进行计算:
# n = N * f**(1/scale_log_base)
scale_log_base = 0.25
#调整为1.25可以查看对比效果
<rules>
<<include rule.exclude.hs1.conf>>
<rule>
condition = var(id) ne "hs1"
show = no
</rule>
</rules>
</plot>
<plot>
type = heatmap
file = data/5/segdup.hs1234.heatmap.txt
r1 = 0.90r
r0 = 0.89r
color = hs2_a5,hs2_a4,hs2_a3,hs2_a2,hs2_a1,hs2
scale_log_base = 0.25
<rules>
<<include rule.exclude.hs1.conf>>
<rule>
condition = var(id) ne "hs2"
show = no
</rule>
</rules>
</plot>
<plot>
type = heatmap
file = data/5/segdup.hs1234.heatmap.txt
r1 = 0.91r
r0 = 0.90r
color = hs3_a5,hs3_a4,hs3_a3,hs3_a2,hs3_a1,hs3
scale_log_base = 0.25
<rules>
<<include rule.exclude.hs1.conf>>
<rule>
condition = var(id) ne "hs3"
show = no
</rule>
</rules>
</plot>
<plot>
type = heatmap
file = data/5/segdup.hs1234.heatmap.txt
r1 = 0.92r
r0 = 0.91r
color = hs4_a5,hs4_a4,hs4_a3,hs4_a2,hs4_a1,hs4
scale_log_base = 0.25
<rules>
<<include rule.exclude.hs1.conf>>
<rule>
condition = var(id) ne "hs4"
show = no
</rule>
</rules>
</plot>
运行命令: circos -conf circos.conf -outputfile 5.png
图片如下:
Text 的简单配置
要在圈图上显示一些基因的名称,此时需要以文本形式显示数据,放入单独的配置文件 命名为plots_text.conf
<plot>
#显示文字
type = text
#数据文件路径
file = data/6/genes.labels.txt
#显示在图形中的位置
r1 = 0.8r
r0 = 0.6r
#标签的字体
label_font = light
#标签大小
label_size = 12p
# 文字边缘的大小,设置较小则不同单词就可能会连接到一起了。
# padding - text margin in angular direction
# rpadding - text margin in radial direction
rpadding = 5p
# 设置是否需要在 label 前加一条线,用来指出 lable 的位置。
show_links = no
link_dims = 0p,2p,5p,2p,2p
link_thickness = 2p
link_color = black
<rules>
<<include rule.exclude.hs1.conf>>
# 设置 rule ,对 label 中含有字母 a 或 b 的特异性显示
<rule>
condition = var(value) =~ /a/i
label_font = bold
flow = continue
</rule>
<rule>
condition = var(value) =~ /b/i
color = blue
</rule>
</rules>
</plot>
全部主文件配置
#circos 默认展示karyotype原始文件的所有内容,但是可以选择展示一部分
karyotype = data/karyotype/karyotype.human.txt
chromosomes_units = 1000000
chromosomes_display_default = no
#显示连续的4条染色体
#chromosomes = /hs[1-4]$/
chromosomes = hs1;hs2;hs3;hs4
#染色体在图中占用的相对量
#hs1 = 0.5
#使用相对单位"r"其含义是相对于圆形周长的多少
#hs1 = 0.5r
#'rn'后缀表示其他几条所占用的比例
#/hs[234]/=0.5rn 将会使hs2,hs3,hs4各占图中的16%
chromosomes_scale= hs1=0.5r,/hs[234]/=0.5rn
#默认情况下,展示方向是顺时针方向,但是可以在<image>block使用
#angle_orientation=(clockwise or counterclockwise)
#也可以使用'chromosomes-reverse'将某一条染色体方向扭转
chromosomes_reverse = /hs[234]/
#对每一条染色体的颜色进行设置
chromosomes_color= hs1=red,hs2=orange,hs3=green,hs4=blue
#改变某条染色体的位置
chromosomes_radius = hs4:0.9r
<plots>
<<include wode/etc/plots_text.conf>>
<<include wode/etc/plots_heatmap.conf>>
<<include wode/etc/plots_histogram.conf>>
</plots>
##以下两个写在单独的文件中
<<include ideogram.conf>>
<<include ticks.conf>>
<<include links.conf>>
##下面的内容每一个配置文件都需要的,一般情况下不需要修改默认的设置
<image>
<<include etc/image.conf>>
</image>
<<include etc/colors_fonts_patterns.conf>>
<<include etc/housekeeping.conf>>
注意links.conf 中的半径应该为0.6r 否则基因的名字会与link 连线重合
运行命令: circos -conf circos.conf -outputfile 6.png
图片如下: