gpt4 book ai didi

r - 如何通过节点或叶子中的标签折叠系统发育树中的分支?

转载 作者:行者123 更新时间:2023-12-04 10:46:14 25 4
gpt4 key购买 nike

我为一个蛋白质家族建立了一个系统发育树,可以将其分成不同的组,根据受体类型或 react 类型对每个组进行分类。树中的节点被标记为受体的类型。

在系统发育树中,我可以看到属于相同组或受体类型的蛋白质聚集在相同的分支中。所以我想折叠这些具有共同标签的分支,按给定的关键字列表对它们进行分组。

命令将是这样的:

./collapse_tree_by_label -f phylogenetic_tree.newick -l list_of_labels_to_collapse.txt -o collapsed_tree.eps(或pdf)

我的 list_of_labels_to_collapse.txt 应该是这样的:
一种

C
D

我的新树将是这样的:
(A_1:0.05,A_2:0.03,A_3:0.2,A_4:0.1):0.9,((((B_1:0.05,B_2:0.02,B_3:0.04):0.6,(C_1:0.6,C_2:0.08):0.7) :0.5,(D_1:0.3,D_2:0.4,D_3:0.5,D_4:0.7,D_5:0.4):1.2)

没有折叠的输出图像是这样的:
http://i.stack.imgur.com/pHkoQ.png

输出图像折叠应该是这样的(collapsed_tree.eps):
http://i.stack.imgur.com/TLXd0.png

三角形的宽度应代表分支长度,三角形的高必须代表分支中的节点数。

我一直在玩 R 中的“ape”包。我能够绘制系统发育树,但我仍然无法弄清楚如何通过标签中的关键字折叠分支:

require("ape")

这将加载树:
cat("((A_1:0.05,A_2:0.03,A_3:0.2,A_4:0.1):0.9,(((B_1:0.05,B_2:0.02,B_3:0.04):0.6,(C_1:0.6,C_2:0.08):0.7):0.5,(D_1:0.3,D_2:0.4,D_3:0.5,D_4:0.7,D_5:0.4):1.2):0.5);", file = "ex.tre", sep = "\n")
tree.test <- read.tree("ex.tre")

这里应该是要折叠的代码

这将绘制树:
plot(tree.test)

最佳答案

您存储在 R 中的树已经将提示存储为多项式。这只是用代表多分体的三角形绘制树的问题。
ape中没有功能要做到这一点,我知道,但是如果你稍微弄乱了绘图功能,你可以把它拉下来

# Step 1: make edges for descendent nodes invisible in plot:
groups <- c("A", "B", "C", "D")
group_edges <- numeric(0)
for(group in groups){
group_edges <- c(group_edges,getMRCA(tree.test,tree.test$tip.label[grepl(group, tree.test$tip.label)]))
}
edge.width <- rep(1, nrow(tree.test$edge))
edge.width[tree.test$edge[,1] %in% group_edges ] <- 0


# Step 2: plot the tree with the hidden edges
plot(tree.test, show.tip.label = F, edge.width = edge.width)

# Step 3: add triangles
add_polytomy_triangle <- function(phy, group){
root <- length(phy$tip.label)+1
group_node_labels <- phy$tip.label[grepl(group, phy$tip.label)]
group_nodes <- which(phy$tip.label %in% group_node_labels)
group_mrca <- getMRCA(phy,group_nodes)

tip_coord1 <- c(dist.nodes(phy)[root, group_nodes[1]], group_nodes[1])
tip_coord2 <- c(dist.nodes(phy)[root, group_nodes[1]], group_nodes[length(group_nodes)])
node_coord <- c(dist.nodes(phy)[root, group_mrca], mean(c(tip_coord1[2], tip_coord2[2])))

xcoords <- c(tip_coord1[1], tip_coord2[1], node_coord[1])
ycoords <- c(tip_coord1[2], tip_coord2[2], node_coord[2])
polygon(xcoords, ycoords)
}

然后你只需要遍历组来添加三角形
for(group in groups){
add_polytomy_triangle(tree.test, group)
}

关于r - 如何通过节点或叶子中的标签折叠系统发育树中的分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34403957/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com