circos 学习手册(二十八)

技巧(三)

10. ID 字段

本节将演示如何根据 ID 字段格式化数据

每个数据点都可以为格式化参数设置值,如 color, stroke_thickness, fill_color 等。

这些格式化参数都可以在数据文件中定义。

ID 字段可以为数据点指定注释,并通过注释计算每个数据点的格式,它不会直接影响数据的显示,而是在 rule 块中使用字符串来标记它。

10.1 格式化条带

例如,有如下数据

...
chr21 30003462 30003712 AluSx SINE Alu
chr21 30003734 30003925 L1MD LINE L1
chr21 30004082 30004207 L1ME4a LINE L1
chr21 30004229 30004286 AT_rich Low_complexity Low_complexity
chr21 30004378 30004615 L1ME4a LINE L1
chr21 30004781 30004872 AT_rich Low_complexity Low_complexity
chr21 30004942 30005099 CT-rich Low_complexity Low_complexity
chr21 30005358 30005634 MER7A DNA MER2_type
chr21 30006113 30006265 L1ME4a LINE L1
...

每个元素都有多个分类(如 AluSx, SINE, Alu)。要使用这些分类,需要解析数据并将 ID 参数与每个数据点关联

#!/usr/bin/perl
use strict;
$,=" ";
$\="\n";
while(<>) {
    chomp;
    my $id;
    s/chr/hs/;
    if(/L(\d+)/) {
        $id = "LINE$1";
    } elsif (/S(\d+)/ || /SINE(\d?)/) {
        #my $num = $1 || 0;
        $id = "SINE" . ($1||0);
    } elsif (/low/i || /simple/i) {
        $id = "SIMPLE";
    } elsif (/LTR/) {
        $id = "LTR";
    } else {
        $id = "OTHER";
    }
    my @tok = split;
    print @tok[0..2],"id=$id";
}

上面的数据将会转换为

...
hs21 30003462 30003712 id=SINE0
hs21 30003734 30003925 id=LINE1
hs21 30004082 30004207 id=LINE1
hs21 30004229 30004286 id=SIMPLE
hs21 30004378 30004615 id=LINE1
hs21 30004781 30004872 id=SIMPLE
hs21 30004942 30005099 id=SIMPLE
hs21 30005358 30005634 id=OTHER
hs21 30006113 30006265 id=LINE1
...

定义 tile 块展示数据

<plot>
type = tile
file = repeats.withid.txt
r0   = 0.8r
r1   = 0.98r
orientation = in
layers      = 50
thickness   = 20p
padding     = 6p
margin      = 0.001u
color       = black
# for very small tiles a stroke is useful because
# it ensures that tiles associated with very small
# spans will be visible
stroke_thickness = 2p
stroke_color = black

# RULES WILL GO HERE

</plot>

所有的条带将具有相同的格式,要对特定 ID 值设置格式

# test with regular expression
condition = var(id) =~ /LINE/

或者

# test string equality
condition = var(id) eq "LINE"

例如,下面的规则将不同的颜色应用于 ID 为 LINE、SINE、SIMPLE 和 OTHER 的元素。

对于 LINE 元素,设置为绿色填充色,但是 LINE1 和 LINE2 元素具有附加的 stroke_color 条件

<plot>

...

<rules>

<rule>
condition    = var(id) =~ /LINE/
color        = green
flow         = continue
</rule>

<rule>
condition    = var(id) =~ /LINE[12]/
stroke_color = red
</rule>

<rule>
condition    = var(id) =~ /SINE/
color        = blue
stroke_color = blue
</rule>

<rule>
condition    = var(id) =~ /SIMPLE/
color        = dgrey
</rule>

<rule>
condition    = var(id) =~ /OTHER/
color        = lgrey
</rule>

</rules>

</plot>

10.2 格式化 link

让我们看看如何以同样的方式调整连接格式。

在本例中,我们使用数字格式的注释。注释格式是任意的,不局限于一种方式

...
linkid5 hs21 30772491 30777591 id=87-69
linkid5 hs21 30602230 30607330 id=87-69
linkid6 hs21 30257977 30263077 id=60-22
linkid6 hs21 30367808 30372908 id=60-22
linkid7 hs21 30079003 30084103 id=54-90
linkid7 hs21 30771970 30777070 id=54-90
...

首先,根据 ID 字段的第一个值,设置 link 的厚度

<rule>
# make sure that the id field matches the required number-number format
condition  = var(id) =~ /(\d+)-(\d+)/
# extract the two number in 'id' to @match and use remap() function to map
# the first number in the range 1..100 to thickess in the range 1..10.
thickness  = eval( my @match = var(id) =~ /(\d+)-(\d+)/; remap($match[0],1,100,1,10) )
# so that other rules can trigger too
flow = continue
</rule>

让我们扩展规则以重新映射z值(深度),颜色和透明度

<rule>
# make sure that the id field matches the required number-number format
condition  = var(id) =~ /(\d+)-(\d+)/
# extract the two number in 'id' to @match and use remap_int() function to map
# the first number in the range 1..100 to integer thickess in the range 1..10.
thickness  = eval( my @match = "var(id)" =~ /(\d+)-(\d+)/; remap_int($match[0],1,100,1,10) )

# use the first number as the z-value (i.e. thick links will be drawn on top)
z          = eval( my @match = "var(id)" =~ /(\d+)-(\d+)/; $match_int[0] )

# use the second number for the color and transparency
color      = eval( my @match = "var(id)" =~ /(\d+)-(\d+)/;  
                   sprintf("spectral-9-div-%d_a%d", remap_int($match[1],1,100,1,9),  
                                                    remap_int($match[1],1,100,5,1 ) ) )
</rule>

请注意,ID 字段(文本)用引号包裹的。这是用于计算的 Perl 表达式

# correct - "87-69" treated as string
my @match = "87-69" =~ /(\d+)-(\d+)/

# incorrect - 87-69 treated as literal
my @match = 87-69 =~ /(\d+)-(\d+)/

可以在 命令行中添加 -debug_group rules 输出解析 rule 时的信息

10.3 格式化文本

根据 ID 字段设置文本格式与上面的做法相同,例如文本如下

...
hs21 30829740 30829740 tb id=64
hs21 30405360 30405360 oe id=31
hs21 30112849 30112849 ps id=74
hs21 30721834 30721834 dg id=25
hs21 30325022 30325022 sj id=22
...

然后根据 ID 字段设置文本的颜色和大小

<rule>
condition  = 1
color      = eval(sprintf("set2-4-qual-%d",remap_int(var(id),1,100,1,4)))
label_size = eval(sprintf("%dp",remap_int(var(id),1,100,12,48)))
</rule>

在这里,我们使用 condition = 1,不检查 ID 字段的格式是否正确,因为参数值是数值,不需要用引号引起来。

image.png

11. 热图 link

您可以按关联的值为 link 着色,以创建热图效果

11.1 为 link 设置值

在这里,无法用上述相同的方式将值与 link 相关联,但是可以破坏其中一个参数来执行此操作。例如,使用 value 参数

hs12 117427133 132349534 hs2 94056542 114056542 value=2
hs22 33232924 49691432 hs4 88399610 108399610 value=5

11.2 根据值为 link 着色

现在每个 link 都有值了,可以用它来设置颜色了。

可以用 val(value) 获取值

<rules>

<rule>
# always trigger this rule
condition  = 1
# use the link's value to sample from a list of colors
color      = eval((qw(red orange green blue purple))[ var(value) ])
# continue parsing other rules
flow       = continue
</rule>

<rule>
# always trigger this rule
condition  = 1
# add _a3 to the color of the ribbon, giving it 50% transparency (3/6)
color      = eval(sprintf("%s_a3",var(color)))
</rule>

</rules>

第一条规则将值映射到颜色,需要编写一行 perl代码来对颜色列表采样。如果列表中的元素没有包含空格,可以使用 qw() 运算符将单词转换为列表

qw(red orange green blue purple)

perl 采样语法

( ...list here...)[i]

结合起来就是

(qw(red orange green blue purple))[i]

在这里, i 是 value 参数的值,即 val(value)

image.png

12. 颠倒的 link

本节将介绍如何格式化颠倒的 link

如果链接的两端方向相互颠倒,则该链接被视为颠倒。例如,给定一个由两端 chrA:start1-end1 和 chrB:start2-end2 定义的链接,如果

start1 < end1 && start2 > end2

or

start1 > end1 && start2 < end2

12.1 link 几何

要设置 link 不扭曲,可以设置 flat 参数

flat = yes

但是,如果你在数据文件中设置了 twist 参数

hs1 100 200 hs2 100 200
# this link's ribbon will be twisted, even if flat=yes is set
hs3 100 200 hs4 100 200 twist=1

那么 flat = yes 将不会有任何作用,该扭曲还是会扭曲

hs1 100 200 hs2 100 200
# when a link end has inverted*=1, its start/end coordinates
# are reversed. For the start of the link use inverted1 and
# for the end inverted2.
hs3 100 200 hs4 100 200 inverted=1

可以将 inverted 参数添加到数据文件中,link 的一个端点将交换其起点和终点坐标

link 的默认绘制方式是 start1 -> end1 -> end2 -> start2,如果染色体方向发生改变,也会影响 link 的扭曲

12.2 测试颠倒

要测试 link 是否扭转,可以使用 val(rev1) 和 val(rev2),如果连接的开始和结束分别反转,则每个字符串的值都为 1

例如,将末端倒置的连接绘制成橙色

<rule>
condition  = var(rev2)
color      = orange
</rule>

测试两端的反转,如果两端都反转,那么也可以认为是未反转的

<rule>
condition  = var(rev1) && var(rev2)
color      = red
</rule>

<rule>
condition  = var(rev1)
color      = green
</rule>

<rule>
condition  = var(rev2)
color      = orange
</rule>
image.png

12.3 定义颠倒的 link

为了表明链接是反向的,你可以反向链接其一端之一的坐标,也可以为其分配反向参数

# this is a normal link
chr1 100 200 chr2 100 200

# this is an inverted link - its first end is inverted
chr1 200 100 chr2 100 200

# this is an inverted link - its first end is inverted using the 'inverted' flag
chr1 100 200 chr2 100 200 inverted1=1

# this is an inverted link - its second end is inverted
chr1 100 200 chr2 200 100

# this is an inverted link - its second end is inverted using the 'inverted' flag
chr1 100 200 chr2 100 200 inverted2=1
image.png
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,657评论 6 505
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,889评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,057评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,509评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,562评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,443评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,251评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,129评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,561评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,779评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,902评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,621评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,220评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,838评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,971评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,025评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,843评论 2 354

推荐阅读更多精彩内容