跳到正文
0.16.6 文档
全站目录 · 按任务查找

选择合适的学习模块

本页目录

为你的问题选择布局,而不是为了圆形效果改变问题。下面用同一批真实随包记录比较三种表达。

怎么选择?

场景 更合适的图 应避免的误读
几条序列之间的总体对应关系 弦图 连线交叉本身不等于倒位
一条质粒或环形序列上的注释 圆图 多条序列不能塞进单序列坐标
比较位置、基因顺序与局部邻域 共线性图 显示对齐或翻转不等于生物学结论

三种图都消费已有数据,不计算新的 BLAST 比对。先尝试下面的最小组合,再进入原始记录流程、完整质粒图或局部同源比较。

本页准备

在新的 R 会话中先运行下方代码,再按页面顺序继续。配色和排版是可选的显示设置,输入只选择需要的列。

准备代码 · 在本页运行一次
代码
library(ggchord)
library(dplyr)
data(seq_data_example)
data(ribbon_data_example)
data(gene_data_example)
seqs <- seq_data_example |>
  select(accver, length)
links <- ribbon_data_example |>
  select(qaccver, saccver, qstart, qend, sstart, send)
# The fixture preserves biological strands separately from its old display strands.
genes <- gene_data_example |>
  transmute(accver, start, end, strand = source_strand)

# Optional appearance choices; none of these columns or scales is required input.
library(ggchord)
seq_palette <- setNames(
  c("#E64B35", "#233E4A", "#269B82", "#D59B17"),
  c("MT108731.1", "MT118296.1", "OQ646790.1", "OR222515.1")
)
gene_palette <- c("+" = "#CE1536", "-" = "#346B9D", "." = "#8291A6")

library(ggchord)
feature_palette <- c(
  CDS = "#993366", promoter = "#31849B", rep_origin = "#F1E51D",
  primer_bind = "#A020F0", misc_feature = "#A6ACB3", protein_bind = "#31849B"
)

library(ggchord)
doc_background <- "#FFFCF5"
identity_palette <- c("#303B71", "#36537D", "#269B82", "#A5D52C", "#ECEB31")
identity_values <- c(0, 0.5, 0.8, 0.9, 1)
identity_breaks <- c(0, 50, 80, 90, 100)
doc_legend_theme <- theme(
  legend.title = element_text(size = 13, face = "bold"),
  legend.text = element_text(size = 11),
  legend.key.width = unit(9, "mm"), legend.key.height = unit(5, "mm"),
  legend.spacing.x = unit(9, "mm"), legend.spacing.y = unit(7, "mm"),
  legend.margin = margin(l = 4, r = 4, unit = "mm")
)
sequence_guide <- guide_ggchord_legend(nrow = 1, theme = doc_legend_theme)
strand_guide <- guide_ggchord_legend(
  nrow = 1, override.aes = list(strand = c("+", "-")), theme = doc_legend_theme
)
identity_guide <- guide_ggchord_colourbar(
  position = "left", direction = "vertical",
  theme = theme(
    legend.key.height = unit(75, "mm"), legend.key.width = unit(5, "mm"),
    legend.title = element_text(size = 13, face = "bold"),
    legend.text = element_text(size = 11), legend.margin = margin(r = 7, unit = "mm")
  )
)
doc_theme <- theme_ggchord_publication(
  axis.text = element_text(size = 11),
  axis.text.check.overlap = TRUE
) +
  theme(
    legend.position = "bottom",
    legend.title = element_text(size = 13, face = "bold"),
    legend.text = element_text(size = 11),
    legend.key.width = unit(9, "mm"), legend.key.height = unit(5, "mm"),
    legend.spacing.x = unit(9, "mm"), legend.spacing.y = unit(7, "mm"),
    legend.box.spacing = unit(6, "mm"),
    plot.background = element_rect(fill = doc_background, colour = NA),
    panel.background = element_blank(),
    plot.title = element_text(face = "bold", size = 18),
    plot.subtitle = element_text(size = 10, colour = "#5C625A"),
    plot.margin = margin(14, 18, 14, 18)
  )
doc_axis <- function(coordinates = "relative") {
  scale_seq_position_continuous(
    coordinates = coordinates, n.breaks = 3, minor_breaks = NULL,
    labels = function(x) format(x, scientific = FALSE, big.mark = ",", trim = TRUE)
  )
}

library(dplyr)
data(plasmid_example_pUC19)
plasmid_seq <- plasmid_example_pUC19 |>
  select(accver, length)
feature_source <- find_common_features(plasmid_example_pUC19)
features <- feature_source |>
  select(accver, start, end, strand, type, anno)

下列对象都可按普通 ggplot 组合, 打印或使用 ggsave() 保存。

弦图:比较多条序列

代码
p_chord <- ggchord(seq_data = seqs, ribbon_data = links, gene_data = genes) +
  geom_link_ribbon(aes(ribbon_fill = qaccver), alpha = .7) +
  scale_ribbon_fill_manual(values = seq_palette, guide = "none") +
  geom_seq(show.legend = FALSE) +
  geom_gene(position = position_strand(.1), width = .04) +
  geom_seq_label(size = 4, seq_label_radius = .84, seq_label_hjust = .5) +
  coord_chord() +
  scale_seq_colour_manual(values = seq_palette) +
  scale_gene_fill_manual(values = gene_palette) +
  doc_theme
p_chord
随包序列与已有比对区间的弦图
随包序列与已有比对区间的弦图 · 点击放大查看

连接按 query 序列标识配色,与骨架使用同一类别色板;这不表示相似度或同源基因分组。按真实相似度配色见原始记录教程。 coord_chord() 控制全局旋转和拟合。逐序列半径、曲率、间隙和方向属于 geom_seq()。 连接控制点为 NULL 时,弦图保留历史的原点路径,并不表示各模式统一使用直线。 区间连接默认避障为 uniform,点连接默认避障为 none。

共线性图:对齐局部比较

代码
anchors <- genes |>
  group_by(accver) |>
  slice_max(end - start, n = 1, with_ties = FALSE) |>
  ungroup() |>
  select(accver, start, end)
p_collinear <- ggchord(seq_data = seqs, ribbon_data = links, gene_data = genes) +
  geom_link_ribbon(aes(ribbon_fill = qaccver), alpha = .7) +
  scale_ribbon_fill_manual(values = seq_palette, guide = "none") +
  geom_seq() +
  geom_gene(position = position_strand(.1)) +
  geom_seq_label(size = 4) +
  coord_collinear(anchor = anchors, align = "center", orientation = "auto") +
  doc_axis() +
  scale_seq_colour_manual(values = seq_palette) +
  scale_gene_fill_manual(values = gene_palette) +
  doc_theme
p_collinear
按选定注释锚定的随包序列共线性图
按选定注释锚定的随包序列共线性图 · 点击放大查看

本例分别选每条序列最长的已知基因作显示锚点,不将它们当作同源基因。 anchor 对齐指定区间,orientation = "auto" 按现有证据选择支持的显示方向。 应查看方向诊断,不能直接把显示翻转解释为生物学倒位。区间连接默认连接相邻显示行; 使用 adjacent_only = FALSE 或明确 pairs 保留其他连接。非相邻边框默认虚线, 显式样式优先。这些规则与弦图不同。局部视图与分段为裁剪或局部翻转 保留源坐标。

圆图:注释单条序列

代码
circle_features <- features |>
  filter(type %in% c("CDS", "rep_origin"))
p_circular <- ggchord(seq_data = plasmid_seq) +
  geom_seq() +
  geom_feature(aes(feature_fill = type), data = circle_features, position = position_plasmid()) +
  geom_feature_label_repel(data = circle_features, position = position_plasmid(), size = 4) +
  geom_seq_center_label() +
  scale_feature_fill_manual(values = feature_palette, breaks = unique(circle_features$type)) +
  coord_circular() +
  doc_theme
p_circular
pUC19 注释的单序列圆图
pUC19 注释的单序列圆图 · 点击放大查看

本例只选 CDS 与复制起点显示,保留完整序列的 bp 刻度。 coord_circular() 要求单条序列。通用注释可带未知链。 geom_feature_plasmid() 是有独立默认值的便利预设,应在需要这些默认值时显式选择。 引物和酶切图层见识别注释。

完成后检查

先看序列数:单序列注释用圆图;多序列总体连接用弦图;位置、距离或邻域比较用共线性图。