circos

circos 学习手册(三)

2020-12-08  本文已影响0人  名本无名

配置文件语法(续)

4 动态执行参数

在配置文件中,通常以如下方式设置一个常量

variable = value

例如

color = blue

但是,有时候,你可能想用另一个参数的值或函数来指定配置参数的值。

4.1 访问配置参数的值

可以使用语法将一个参数的值赋值给另一个参数

parameter2 = conf(parameter1)

或者,用指定块内的参数赋值

parameter2 = conf(block1,parameter1)
parameter2 = conf(block1,block2,parameter1)
...

举个例子

<plots>
 show_histogram = yes
 <plot>
  show = conf(plots,show_histogram)
  type = histogram
  ...

在解析配置文件的时候,会将所有 conf(parameter) 替换成对应的 parameter 的值

使用这个语法时,需要确保包含参数的完整块路径,如

<block1>
<block2>
parameter1 = ...
</block2>
</block1>

要使用 conf(block1,block2,parameter1) 获取对应的值

如果你想要在当前块引用参数并向上层进行搜索,可以用 . 代表路径

<plots>
 <plot>
  type = histogram
  r0   = 0.5r
  r1   = conf(.,r0)+50p
  ...

这种方式在 rules 中非常有用

<plots>
 <plot>
  x    = 10
  ...

  <rules>
   <rule>
   # x 没有在这个块中定义,但是会
   # 在外面的块中搜索
   condition = conf(.,x) == 10
   ...

4.2 访问数据属性

<rules> 中,可以用 var() 函数来获取数据点属性,如位置或者值等信息

<rule>
COLOR = var(ID)

4.3 对参数执行操作

任何参数都可以编写为 Perl 代码并在运行时执行

但是必须将参数写在 eval 函数内

thickness = eval(1+1)
color     = eval("b"."l"."u"."e")

eval 函数能够非常方便的推断和操作其他配置文件中的参数

track_color = blue
track_width = 100
track_start = 0.5

<plots>
<plot>

# color=blue
color = conf(track_color)
# r0  = 0.5r
r0    = eval(conf(track_start) . "r")
# r1  = 0.5r+100p
r1    = eval(conf(track_start) . "r" + conf(track_width) . "p")
</plot>
</plots>

conf(track_color) 会做简单的替换,并不需要使用 eval 函数,如果你要对参数值进行操作,不需保证 eval 函数内的表达式是一个有效的可执行代码

因为 eval 参数需要书写正确的 perl 语法,因此错误率很高

注意:最常犯的错是忘记加引号

## OK
x = eval( 1.05 . "r" )
## NOT OK,perl 会将 r 作为一个裸词,引发错误
x = eval( 1.05 . r )
覆盖值

上面已经提到过,通常,只有少数参数能够设置多个实例,大多数参数都不支持多个实例

那如何覆盖原来的值呢?

<ideogram>
position = 0.9r
position* = 0.8r # this value will be used
...
</ideogram>

通过在参数名称添加后缀 *,将会用新值来覆盖原来定义的值

你可以在参数名后面添加任意多的 *,而参数最后的值是 * 最多的那次的赋值

5 字体

字体文件在 fonts 文件夹下

light          = fonts/modern/cmunbmr.otf # CMUBright-Roman
normal         = fonts/modern/cmunbmr.otf # CMUBright-Roman
default        = fonts/modern/cmunbmr.otf # CMUBright-Roman
semibold       = fonts/modern/cmunbsr.otf # CMUBright-Semibold
bold           = fonts/modern/cmunbbx.otf # CMUBright-Bold
italic         = fonts/modern/cmunbmo.otf # CMUBright-Oblique
bolditalic     = fonts/modern/cmunbxo.otf # CMUBright-BoldOblique
italicbold     = fonts/modern/cmunbxo.otf # CMUBright-BoldOblique

如果要设置自己的字体,可以将你的字体 TTF 文件拷贝到 fonts 文件夹下,然后在 fonts.conf 配置文件中引入

6 单位

配置文件中定义的许多参数都需要单位

有后缀的值可以混合使用

# 1 pixel padding
padding = 1p 
# relative padding (e.g. relative to label width)
padding = -0.25r

# radius of track (relative to inner ideogram radius)
r0 = 0.5r
# combination of relative and pixel values
r1 = 0.5r+200p

(未完,待再续......)

上一篇 下一篇

猜你喜欢

热点阅读