这一节的目标是画出下面的图
所谓连线,就是连接染色体组两个不同位置的线。这是circos的最主要目的及用途之一。
首先需要定义数据结构。这里还需要第二节的关于染色体组型(karyotypes)数据结构的知识。
数据结构
LABEL ID START END
这里的LABEL是连线的名称,因为两点确定一条线,所以基本上连线的数据都是同一个名称出现两行数据,分别记录线两端对应的染色体组位置。ID对应的是karyotypes数据文件当中的ID,start和end分别定义起始和终止的位置。下面就是具体的例子:
segdup00001 hs1 465 30596 segdup00001 hs2 114046768 114076456 segdup00002 hs1 486 76975 segdup00002 hs15 100263879 100338121
数据保存在文本文件当中就可以了,之后由conf文件调用。
当然这一数据文件可以更复杂,用于定义每条线的起止半径,色彩,以及宽度等等。比如
segdup00011 hs1 71096 76975 thickness=5 segdup00011 hs1 388076 393885 thickness=5 segdup00051 hs1 116091 121750 color=blue segdup00051 hs7 55828312 55834013 color=blue segdup00004 hs1 486 9707 radius=0.8r segdup00004 hsY 57762276 57771573
设置文件
与之前一致的,我们需要设置好circos的设置文件,它需要包括前一节介绍的全部:circos.conf, ideogram.conf,和ticks.conf来定义一,数据源,二如何画染色体,三如何画坐标。而links的部分,直接定在circos.conf文件当中也好,或者写在links.conf当中,由circos.conf来调用也是一样的。我们来看具体circos.conf的示例:
<> <> <> <> <> <> karyotype = data/karyotype/karyotype.human.hg19.txt chromosomes_units = 1000000 chromosomes = hs1;hs2;hs3 chromosomes_display_default = no # chromosomes_radius = hs2:0.9r;hs3:0.8r
这一部分,与之前一节别而二致。其下的内容就是如何载入links的数据了:
# Links (bezier curves or straight lines) are defined in blocks. # Each link data set is defined within a named block. The name # of the block is arbitrary, but must be unique. # # As with highlights, parameters defined # in the root of affect all data sets and are considered # global settings. Individual parameters value can be refined by # values defined within blocks, or additionally on each # data line within the input file. z = 0 radius = 0.975r bezier_radius = 0.2r show = yes color = black_a5 thickness = 2 file = data/5/segdup.txt record_limit = 5000
在links的定义当中,自定义属性有:
r0 - highlight的内径 r1 - highlight的外径 offset - 内外径的偏移值 fill_color - highlight slice的填充色 stroke_color - highlight边框颜色,如果指定的边框大小的话 stroke_thickness - 边框大小 z - z轴,决定着划图的先后次序,后画的可能会盖住先画的 ideogram - toggles the position of the highlight to be within the ideogram extent radius = 定义连线终止的半径; 在使用相对比例尺时,当radius < 1 时,连线会画在染色体组内,否则边线会画在染色体组外 bezier_radius = 决定曲线的第三点位置,如果不设置,连线就会以直线的形式出现。 color = 连线的颜色 thickness = 连线的粗细 record_limit = 从数据文件中读取多少组数据。在debug的时候会很有用。
设置好设置文件之后,就可以使用circos出图了。
/path/to/circos/bin/circos -conf path/to/circos.conf
注意,这里include会从circos所在的目录开始寻找,而不是当前目录。
上面的画出来的图,使用的是最简单的数据结构。如果我们需要对每一条线都分别定义色彩,位置等属性,那就需要使用上面提到的复杂的数据结构了。其效果如下:
如果对每一条线分别设置属性,有时候会变得很麻烦。如果可以使用筛选条件一次来进行属性定义就方便了。而circos也考虑到了这一点。它可以设置rule,其写法为:
<links> z = 0 radius = 0.975r crest = 0.5 thickness = 2 color = black bezier_radius = 0.2r bezier_radius_purity = 0.5 <link segdup> file = data/5/segdup.txt <rules> flow = continue <rule> importance = 150 condition = _INTRACHR_ show = no </rule> <rule> importance = 100 condition = (_CHR1_ eq "hs1" && _CHR2_ eq "hs2") || (_CHR1_ eq "hs2" && _CHR2_ eq "hs1") color = green z = 10 </rule> <rule> importance = 50 condition = (_CHR1_ eq "hs2" && _CHR2_ eq "hs3") || (_CHR1_ eq "hs3" && _CHR2_ eq "hs2") color = blue z = 15 </rule> </rules> </link> </links>
其规则如下(n代表同一名称下的第几个点,一般为1,或者2):
_CHRn_ - 对应着数据格式当中的ID _STARTn_ - 对应着数据格式当中的START _ENDn_ - 对应着数据格式当中的END _POSITIONn_ - middle position of span n in the link _SIZEn_ - 连线的属性size _INTERCHR_ - 是否在同一染色体内 _INTRACHR_ - 是否在不同染色体间 _THICKNESSn_ 连线的属性thickness _COLORn_ 连线的属性color
可以使用简单的函数比如max,min, abs, eval, rand()等等。字符比较,需要使用ne(不等于), eq(等于)来比较,数值型可以使用>,=,
我们再多看几组示例:
<rule> importance = 200 condition = _INTERCHR_ && ((_CHR1_ eq "hs2" && _START1_ > 65Mb && _START1_ < 75Mb) || (_CHR2_ eq "hs2" && _START2_ > 65Mb && _START2_ < 75Mb)) z = 60 color = red thickness = 5 </rule> <rule> importance = 150 condition = max(_SIZE1_,_SIZE2_) > 40000 z = 50 color = black thickness = 5 </rule> <rule> importance = 250 condition = _INTRACHR_ && abs(_POSITION1_ - _POSITION2_) < 50Mb bezier_radius = 1r bezier_radius_purity = 0.75 color = lblue </rule> <rule> importance = 225 condition = _INTRACHR_ show = no </rule> <rule> ... thickness = eval(_SIZE1_/1000) </rule> <rule> importance = 100 condition = 1 thickness = eval(max(1,log(max(_SIZE1_,_SIZE2_))-5)) radius = eval(min(_SIZE1_/5,_SIZE2_/5,1150)) color = eval((qw(grey red orange yellow green blue purple))[ int(min(_SIZE1_/1000,_SIZE2_/1000,6)) ]) z = eval(int(max(_SIZE1_,_SIZE2_)/100)) </rule> <rule> importance = 100 condition = _COLOR1_ eq "red" thickness = 4 z = 10 </rule> <rule> importance = 90 condition = _COLOR1_ ne "grey" && _THICKNESS1_ == 2 z = 5 </rule>
有的时候,我们可能觉着线型太线,不好看,这时可以使用ribbon及flat参数,如:
<links> z = 0 radius = 0.99r crest = 1 color = grey_a3 bezier_radius = 0.2r bezier_radius_purity = 0.5 <link segdup> file = data/5/segdup.txt ribbon = yes flat = yes stroke_color = vdgrey stroke_thickness = 2 <rules> flow = continue <rule> importance = 250 condition = _INTRACHR_ && abs(_POSITION1_ - _POSITION2_) < 10Mb show = no </rule> <rule> importance = 200 condition = max(_SIZE1_,_SIZE2_) < 10000 show = no </rule> <rule> importance = 150 condition = 1 z = eval(int(max(_SIZE1_,_SIZE2_)/5000)) </rule> <rule> importance = 125 condition = _INTRACHR_ && ((_CHR1_ eq "hs1" && _START1_ < 1Mb) || (_CHR2_ eq "hs1" && _START2_ < 1Mb)) color = orange stroke_color = dorange </rule> <rule> importance = 115 condition = _INTRACHR_ && ((_CHR1_ eq "hs1" && _START1_ > 16Mb && _START1_ < 17Mb) || (_CHR2_ eq "hs1" && _START2_ > 16Mb && _START2_ < 17Mb)) color = lblue stroke_color = dblue </rule> </rules> </link> </links>
本节所使用的代码下载links
转载请注明文章来自糗世界博客







