CIRCOS圈图绘制 – 最简单绘图和解释

Circos是绘制圈图的神器,在http://circos.ca/images/页面有很多CIRCOS可视化的示例。

CIRCOS圈图绘制 – 最简单绘图和解释-图片1

CIRCOS圈图绘制 – 最简单绘图和解释-图片2

Circos可以在线使用,在线使用时是把表格转为圈图,不过只允许最大75行和75列;做一些简单的示意图会比较好,最后时会介绍下在线的tableviewer的使用。

也可以安装在本地,在本地可以绘制基于基因组的更复杂的图。

Circos由Perl写成,安装相对简单,只要Perl的包都装好了就可以了。

Circos安装

  • 从http://circos.ca/software/download/circos/下载Circos安装包,并解压,把安装包内的bin目录加载到环境变量。
  1. wget http://circos.ca/distribution/circos-0.69-6.tgz
  2. tar xvzf circos-0.69-6.tgz
  3. ln -s `pwd`/circos-0.69-6/bin/* ~/bin #make sure ~/bin is in $PATH
  4.  
  5. or
  6. # 注意pwd两侧的反引号
  7. export PATH=$PATH:`pwd`/circos-0.69/bin
  • 安装依赖的Perl包

配置CPANM (CPANM是一个文件,下载下来,增加可执行属性,放到环境变量中即可使用)

  1. # 若无根用户权限,也可放入自己家目录下在环境变量内的目录中就可以
  2. wget https://raw.githubusercontent.com/miyagawa/cpanminus/master/cpanm -O /sbin/cpanm
  3. chmod +x /sbin/cpanm

获得依赖的Perl包,circos -module

  1. ok 1.11 Carp
  2. missing Clone
  3. missing Config::General
  4. ok 3.3 Cwd
  5. ok 2.124 Data::Dumper
  6. ok 2.55 Digest::MD5
  7. ok 2.77 File::Basename
  8. ok 3.3 File::Spec::Functions
  9. ok 0.22 File::Temp
  10. ok 1.50 FindBin
  11. missing Font::TTF::Font
  12. missing GD
  13. missing GD::Polyline
  14. ok 2.38 Getopt::Long
  15. ok 1.14 IO::File
  16. missing List::MoreUtils
  17. ok 1.21 List::Util
  18. missing Math::Bezier
  19. ok 1.60 Math::BigFloat
  20. missing Math::Round
  21. missing Math::VecStat
  22. ok 1.01_03 Memoize
  23. ok 1.17 POSIX
  24. missing Params::Validate
  25. ok 1.36 Pod::Usage
  26. missing Readonly
  27. missing Regexp::Common
  28. missing SVG
  29. missing Set::IntSpan
  30. missing Statistics::Basic
  31. ok 2.20 Storable
  32. ok 1.11 Sys::Hostname
  33. ok 2.0.0 Text::Balanced
  34. missing Text::Format
  35. ok 1.9721 Time::HiRes

获取缺失模块并安装

  1. # 第一句话的目的只是查看需要运行的命令,直接运行第二句就好
  2. circos -module | grep 'missing' | awk '{a=a" "$2;}END{print "cpanm"a}'
  3. circos -module | grep 'missing' | awk '{a=a" "$2;}END{system("cpanm"a);}'

再运行circos -module发现GDGD::Polyline没安装上,查看错误信息是No package 'gdlib' found

  1. # 根用户
  2. yum install gd-devel

然后再用cpanm安装GDGD::Polyline

最简单出图

把下面的内容存储到任意目录下的任意文件比如ehbio.conf下,然后运行circos -conf ehbio.conf就可以获得circos的图circos.pngcircos.svg

  1. karyotype = data/karyotype/karyotype.human.txt
  2.  
  3. <ideogram>
  4.  
  5. <spacing>
  6. default = 0.005r
  7. </spacing>
  8.  
  9. radius = 0.9r
  10. thickness = 20p
  11. fill = yes
  12.  
  13. </ideogram>
  14.  
  15. ################################################################
  16. # The remaining content is standard and required. It is imported
  17. # from default files in the Circos distribution.
  18. #
  19. # These should be present in every Circos configuration file and
  20. # overridden as required. To see the content of these files,
  21. # look in etc/ in the Circos distribution.
  22.  
  23. <image>
  24. # Included from Circos distribution.
  25. <<include etc/image.conf>>
  26. </image>
  27.  
  28. # RGB/HSV color definitions, color lists, location of fonts, fill patterns.
  29. # Included from Circos distribution.
  30. <<include etc/colors_fonts_patterns.conf>>
  31.  
  32. # Debugging, I/O an dother system parameters
  33. # Included from Circos distribution.
  34. <<include etc/housekeeping.conf>>

CIRCOS圈图绘制 – 最简单绘图和解释-图片3

上述命令是怎么运行的呢?

  1. # karyotype定义染色体的名字、ID、起始位置信息,是绘制图的根本
  2. karyotype = data/karyotype/karyotype.human.txt
  3.  
  4. # 必须的部分,控制染色体信息显示
  5. <ideogram>
  6.  
  7. # 定义染色体之间的间距,为图形半径的5% (r代表radius,半径)
  8. <spacing>
  9. default = 0.005r
  10. </spacing>
  11.  
  12. # 染色体区域的绘制位置,默认所有染色体都处于远离圆心同样距离的位置
  13. # 这里设置的是图形半径的0.9倍的位置
  14. # 也可以设置绝对像素值
  15. radius    = 0.9r
  16. # 染色体区域的宽度,可以是相对图形半径,也可以说绝对像素值
  17. thickness = 20p
  18.  
  19. # 染色体区域填充颜色
  20. fill      = yes
  21.  
  22. </ideogram>
  23.  
  24. ################################################################
  25. # The remaining content is standard and required. It is imported
  26. # from default files in the Circos distribution.
  27. #
  28. # These should be present in every Circos configuration file and
  29. # overridden as required. To see the content of these files,
  30. # look in etc/ in the Circos distribution.
  31.  
  32. # 这些都是引用文件,暂时不去管什么意思,后面用到再逐个解释。
  33. # 但是绘图时这些必须引用。下面会解释下最关键的引用位置。
  34. <image>
  35. # Included from Circos distribution.
  36. <<include etc/image.conf>>
  37. </image>
  38.  
  39. # RGB/HSV color definitions, color lists, location of fonts, fill patterns.
  40. # Included from Circos distribution.
  41. <<include etc/colors_fonts_patterns.conf>>
  42.  
  43. # Debugging, I/O an dother system parameters
  44. # Included from Circos distribution.
  45. <<include etc/housekeeping.conf>>

最开始看CIRCOS的配置文件时,不理解其是如何查找用到的数据和配置目录时,不过上面配置文件中被注释掉的一句话泄露了天机look in etc/ in the Circos distribution。配置文件和数据文件默认先在当前目录查找,若没有则去CIRCOS的安装目录下查找。

下面列出了CIRCOS搜索配置文件时查找的目录(搜索数据时也类似)

  1. .
  2. ./etc
  3. /MPATHB/soft/circos-0.69-6/bin/etc
  4. /MPATHB/soft/circos-0.69-6/bin/../etc
  5. /MPATHB/soft/circos-0.69-6/bin/..
  6. /MPATHB/soft/circos-0.69-6/bin

不得不敢写CIRCOS的日志输出,很详细,每次都刷屏。当我们运行CIRCOS失败时,看下日志信息,会得到很多提示。

数据和配置文件都在CIRCOS安装目录下,那么先看看它的目录结构吧。

circos安装目录介绍

bin: 目录下是circos可执行程序,加入环境变量即可

data: 目录下有一个文件夹karyotype,里面收录了几个物种染色体信息文件。

  1. karyotype.chimp.txt karyotype.arabidopsis.tair10.txt
  2. karyotype.human.hg38.txt karyotype.human.hg19.txt
  3. karyotype.mouse.mm10.txt karyotype.yeast.txt karyotype.zeamays.txt

这个是绘制CIRCOS图所必须的一个文件 (文件的内容虽然通常是染色体的信息,但不局限于染色体信息,其它的区域信息、时间序列信息都可以使用)

文件内容如下 (#后面是注释,会被忽略)

前两列是固定的,chr -chr表示定义一条染色体;-表示指定这个区域的父区域,染色体没有父区域,用-代替。

ID是当前区域的名字,其子区域的父区域列都使用这个名字。如果同时绘制多个物种,可在ID中包含物种的代号。

LABEL是当前区域显示的名字。

START END是当前区域的范围,必须是整个的区域。如果想显示部分区域,可在后续配置中修改。

COLOR是当前区域的颜色,CIRCOS为每个染色体有定义好的颜色,存储于etc/colors.conf。除了预先定义了染色体的颜色,还定义了一些颜色变量可以直接使用。

  1. #chr - ID LABEL START END COLOR
  2. chr - hs1 1 0 248956422 chr1
  3. chr - hs2 2 0 242193529 chr2
  4. chr - hs3 3 0 198295559 chr3
  5. chr - hs4 4 0 190214555 chr4
  6. chr - hs5 5 0 181538259 chr5
  7. chr - hs6 6 0 170805979 chr6
  8. chr - hs7 7 0 159345973 chr7
  9. chr - hs8 8 0 145138636 chr8
  10. chr - hs9 9 0 138394717 chr9

etc目录下是配置文件,前面引用到了3个。

image.conf内容如下

  1. <<include image.generic.conf>>
  2. <<include background.white.conf>>

image.generic.conf内容如下,定义了输出的图形的名字、格式、大小等,这些都可以在自定义配置文件,即前面提到的ehbio.conf中覆盖。

  1. dir   = .
  2. #dir  = conf(configdir)
  3. file  = circos.png
  4. png   = yes
  5. svg   = yes
  6.  
  7. # radius of inscribed circle in image
  8. radius         = 1500p
  9.  
  10. # by default angle=0 is at 3 o'clock position
  11. angle_offset      = -90
  12.  
  13. #angle_orientation = counterclockwise
  14.  
  15. auto_alpha_colors = yes
  16. auto_alpha_steps  = 5

background.white.conf只定义了背景是白色。

colors_fonts_patterns.conf引用了颜色、字体、预定义的图形文件信息的配置

  1. <colors>
  2. <<include etc/colors.conf>>
  3. </colors>
  4. <fonts>
  5. <<include etc/fonts.conf>>
  6. </fonts>
  7. <patterns>
  8. <<include etc/patterns.conf>>
  9. </patterns>

colors.conf及其引用文件内容摘录如下,利用RGB组合设置了颜色变量、系列颜色和染色体的颜色。(染色体的名字全部使用小写)

  1. dpblue   = 0,153,237
  2. vdpblue  = 0,136,220
  3. vvdpblue = 0,120,204
  4.  
  5. vvlpurple = purples-7-seq-1
  6. vlpurple  = purples-7-seq-2
  7.  
  8. gpos100 = 0,0,0
  9. gpos    = 0,0,0
  10. gpos75  = 130,130,130
  11.  
  12. chr1  = 153,102,0
  13. chr2  = 102,102,0
  14. chr3  = 153,153,30

patterns.conf定义特殊小图形的信息

  1. # pattern fills for PNG files
  2.  
  3. vline        = tiles/vlines.png
  4. vline-sparse = tiles/vlines-sparse.png
  5.  
  6. hline        = tiles/hlines.png
  7. hline-sparse = tiles/hlines-sparse.png
  8.  
  9. checker        = tiles/checkers.png
  10. checker-sparse = tiles/checkers-sparse.png
  11.  
  12. dot        = tiles/dots.png
  13. dot-sparse = tiles/dots-sparse.png
  14. solid      = tiles/solid.png

housekeeping.conf必须在最上层自定义配置文件中(也就是ehbio.conf)中引用。这个文件名字起的很生物,持家配置,必须要,而且不建议修改。具体内容就不列出了,感兴趣的自己去看。

发表评论

匿名网友

拖动滑块以完成验证
加载失败