You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于新冠样本系统发育树生成Circos环形图?

生成新冠样本系统发育Circos环形图的三种可行方案

方案1:R语言(ggtree + circlize)

ggtree结合circlize可快速实现环形树+注释轨道的可视化,解决你之前用ggtree未出目标图的问题,核心是确保样本ID匹配并配置环形布局:

输入文件准备

  • 系统发育树文件:IQ-TREE输出的.treefile(Newick格式)
  • 样本注释表:sample_metadata.tsv,格式示例:
    sample_id	clades	lineage
    Sample_1	Clade_Alpha	B.1.1.7
    Sample_2	Clade_Delta	B.1.617.2
    ...
    

R脚本示例

# 首次运行需安装依赖包
install.packages(c("ggtree", "tidyverse", "circlize"))

# 加载包
library(ggtree)
library(tidyverse)
library(circlize)

# 读取树文件与注释数据
tree <- read.tree("your_tree.treefile")
metadata <- read_tsv("sample_metadata.tsv")

# 构建环形树并添加注释
p <- ggtree(tree, layout = "circular") +
  # 按clades标记叶节点颜色
  geom_tippoint(aes(color = clades), size = 3) +
  # 添加lineage标签(可根据拥挤程度调整offset和size)
  geom_tiplab(aes(label = lineage), size = 2, offset = 0.5) +
  # 自定义clades颜色
  scale_color_brewer(palette = "Set1") +
  # 调整布局显示
  theme_tree2() +
  theme(legend.position = "right")

# 输出PDF/PNG
ggsave("circular_phylogeny.pdf", p, width = 12, height = 12)
ggsave("circular_phylogeny.png", p, width = 12, height = 12, dpi = 300)

方案2:Python(ete3)

ete3支持环形树绘制,可通过自定义TreeStyle添加注释轨道,适配Python工作流:

输入文件准备

同方案1,树文件与样本注释表。

Python脚本示例

from ete3 import Tree, TreeStyle, NodeStyle, CircleFace, AttrFace
import pandas as pd

# 读取树与注释数据
tree = Tree("your_tree.treefile")
metadata = pd.read_csv("sample_metadata.tsv", sep="\t")
meta_dict = metadata.set_index("sample_id").to_dict("index")

# 配置节点样式
ns = NodeStyle()
ns["size"] = 0  # 隐藏内部节点圆点

# 配置环形树形样式
ts = TreeStyle()
ts.mode = "c"  # 环形模式
ts.root_opening_factor = 1  # 环形开口大小
ts.show_leaf_name = False  # 关闭默认叶节点名称
ts.scale = 20  # 调整树缩放比例

# 为每个叶节点添加注释
for leaf in tree:
    sample_id = leaf.name
    clade = meta_dict[sample_id]["clades"]
    lineage = meta_dict[sample_id]["lineage"]
    
    # 添加clades颜色标记
    color_map = {"Clade_Alpha": "#E41A1C", "Clade_Delta": "#377EB8", "Clade_Omicron": "#4DAF4A"}
    circle_face = CircleFace(radius=5, color=color_map.get(clade, "#999999"), style="circle")
    leaf.add_face(circle_face, column=0, position="aligned")
    
    # 添加lineage标签
    text_face = AttrFace("name", fsize=8, textcolor="black")
    text_face.text = lineage
    leaf.add_face(text_face, column=1, position="aligned")

# 保存输出
tree.render("circular_phylogeny_ete3.pdf", tree_style=ts, w=1000, h=1000)
tree.render("circular_phylogeny_ete3.png", tree_style=ts, w=1000, h=1000, dpi=300)

方案3:直接使用Circos工具(Bash工作流)

Circos是专业环形图工具,需将树转换为其可识别的格式,适合纯命令行环境:

步骤1:安装Circos

# Ubuntu/Debian系统
sudo apt install circos
# 或通过conda安装
conda install -c bioconda circos newick2circos

步骤2:转换树为Circos链接文件

newick2circos -i your_tree.treefile -o tree_links.txt

步骤3:准备注释轨道文件

创建clades_track.txt:

chr - Sample_1 0 1 clade=Clade_Alpha
chr - Sample_2 0 1 clade=Clade_Delta
...

创建lineage_track.txt:

chr - Sample_1 0 1 lineage=B.1.1.7
chr - Sample_2 0 1 lineage=B.1.617.2
...

步骤4:编写Circos配置文件circos.conf

<general>
outputdir = ./
file = circular_phylogeny_circos.pdf
</general>

<image>
angle_offset = -90
radius = 2500
background = white
</image>

<links>
<link>
file = tree_links.txt
color = black_a4
thickness = 2
</link>
</links>

<ideogram>
show_label = yes
label_font = condensed
label_radius = dims(image,radius) + 60p
label_size = 10p
</ideogram>

<plots>
<plot>
type = heatmap
file = clades_track.txt
r0 = dims(image,radius) + 100p
r1 = dims(image,radius) + 150p
color = Clade_Alpha:#E41A1C,Clade_Delta:#377EB8,Clade_Omicron:#4DAF4A
</plot>

<plot>
type = text
file = lineage_track.txt
r0 = dims(image,radius) + 160p
r1 = dims(image,radius) + 210p
label_field = lineage
size = 8p
color = black
</plot>
</plots>

步骤5:运行Circos

circos -conf circos.conf

关键注意事项

  • 确保样本ID在树文件和注释表中完全一致(大小写、空格需严格匹配)
  • 若环形图拥挤,可调整布局参数(如R中的offset、Python中的scale、Circos中的radius)
  • 可根据实际clades数量扩展颜色映射列表

内容的提问来源于stack exchange,提问作者Vinit24

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.19 22:35:42