通过Rule修改颜色

先看一个例子:

<link>

 <link>

 file       = data/5/segdup.txt            #导入link文件

 <rules>

  <rule>
   condition  = var(intrachr)              #是否显示染色体内的连线
   show       = no
  </rule>

  <rule>
   condition  = between(hs1,hs2)           #该连线是否存在与染色体1和2之间,是的话用绿色绘制
   color      = green
   z          = 10
   flow       = continue
  </rule>

  <rule>
   condition  = between(hs2,hs3)           #该连线是否存在与染色体3和2之间,是的话用蓝色绘制
   color      = blue
   thickness  = 2                          #线粗
   z          = 15                         #Z轴高度,压制上面的
  </rule>

 </rules>

 </link>

</links>

再来看一个更加复杂的例子,在该例中我们使用的eval函数和remap函数使参数设定更加灵活:

1. eval()函数用法:

perl中的eval()可以看作是Perl虚拟机,它的参数就是一段Perl代码。

#!/usr/bin/Perl-w  

push(@program,'$i=1;');  
push(@program,'$i=3;$j=2;$k=$i+$j');  
push(@program,'$i=3;return24;$k=$i+$j');  

foreach$exp(@program)  
{  
$rtn=eval($exp);  
print$rtn,"\n";  
}  
Output:  
1  
5  
24

2、remap()函数

remap将一个区间的值映射到另一个区间,具体来说可以吧link的span数值(通常很大)映射到thickness、color、radius、z 等参数可以接纳的范围。

本例中的conf代码:

<links>

z      = 0
radius = 0.975r
crest  = 1
bezier_radius        = 0r
bezier_radius_purity = 0.5

<link>
file         = data/5/segdup.txt
record_limit = 25000
<rules>

<rule>
condition  = var(intrachr)
show       = no
</rule>

<rule>
condition  = 1
thickness  = eval(sprintf("%d",remap_round(max(var(size1),var(size2)),1,25000,2,6)))
radius     = eval(sprintf("%fr",remap(min(var(size1),var(size2)),1,25000,0.5,0.999)))
color      = eval(sprintf("spectral-11-div-%d",remap_round(scalar min(var(size1),var(size2)),1,25000,1,11)))
z          = eval(int(max(var(size1),var(size2))/100))
</rule>

</rules>

</link>

注意上面sprintf格式化输出的使用。


通过link文本文件信息来修改颜色 粗细 层次

我们可以在文本文件中自定义一些参数,使文件看起来像这样:

segdup00002 hs1 486 76975
segdup00002 hs15 100263879 100338121
segdup00011 hs1 71096 76975 thickness=5
segdup00011 hs1 388076 393885 thickness=5
...
segdup00062 hs1 120975 125718 color=blue
segdup00062 hs1 220708073 220712741 color=blue
segdup00071 hs1 129327 166636 color=red
segdup00071 hs1 665046 702417 color=red
...

然后我们再通过rule来更改、筛选设置:

<rule>
condition  = var(thickness) == 4          #首先选出thickness=4的link
condition  = rand() < 0.25                #在上述选出的links中只选25%的!?
thickness  = 10                           #修改粗细 颜色 层次
color      = green
z          = 15
</rule>

<rule>
condition  = var(color) eq "red"          
thickness  = 4
z          = 10
flow       = restart                      #避免死循环
</rule>

<rule>
condition  = var(color) ne "grey" && var(thickness) == 2   #ne(none-equal)
z          = 5
</rule>

results matching ""

    No results matching ""