我已经将系统发育树转换为R中的igraph图形对象。转换非常简单。 (我甚至自己写过)
x <- read.tree(treeName) #library(ape)
xg <- as.igraph(x) #library(igraph)
xn <- as.network(x) #library(network)
问题是igraph丢失内部节点并将所有节点放在超级节点中具有相同的值。转换为网络图表对象不会这样做。
这是一个非常明显的问题,但是如何保留一个尽可能接近原始无根系统发育树的igraph无向图?
这是我的树:
> write.tree(x)
[1] "(Stramenopiles:0.2264266375,(Rhodophyta:0.4773545356,(((Cyanobacteria:0.1381636873,((Cyanobacteria:0.0960776914,((Cyanobacteria:1.22123006e-06,Cyanobacteria:1.22123006e-06)100:0.03668339087,(Cyanobacteria:0.008925185678,(Cyanobacteria:0.02104285045,Cyanobacteria:0.01965272436)36:0.01191598625)100:0.08128993413)100:0.05623189811)40:0.02452201162,(Cyanobacteria:0.1215399949,(Cyanobacteria:0.08131938398,Cyanobacteria:0.1076590417)100:0.09027431172)56:0.02578283222)68:0.03740629446)100:0.1614683078,Rhizaria:0.4422343375)96:0.1466952346,((Firmicutes:0.2770757471,(BacteriaUnclassified:0.2238897211,((Firmicutes:1.22123006e-06,Firmicutes:1.22123006e-06)100:0.01388349775,(Firmicutes:0.01298811881,((Firmicutes:0.002455529288,Firmicutes:0.004912852781)96:0.01323989785,((Firmicutes:1.22123006e-06,(Firmicutes:1.22123006e-06,Firmicutes:1.22123006e-06)16:1.22123006e-06)12:1.22123006e-06,Firmicutes:1.22123006e-06)100:0.03379320834)92:0.0227065105)56:0.006847837211)100:0.2438513586)100:0.1331984947)100:0.1927737595,((((Thermotogae:0.2108367786,(Thermotogae:0.1031317823,Thermotogae:0.1447857053)100:0.1261652654)100:0.1193650964,(Thermotogae:0.04519932853,(Thermotogae:0.005668612775,((Thermotogae:1.22123006e-06,Thermotogae:1.22123006e-06)84:0.002822865755,Thermotogae:1.22123006e-06)64:1.22123006e-06)100:0.04363820472)100:0.1709187935)100:0.2678650283,(ChlamydiaeVerrucomicrobia:0.4849309265,ChlamydiaeVerrucomicrobia:0.3496477841)100:0.2385727076)60:0.04921379025,((Aquificae:0.3447440894,(Deferribacteres:0.3738656857,Proteobacteria:0.3458622172)64:0.05695037101)72:0.05488303029,(((Proteobacteria:0.3106123704,Proteobacteria:0.1793013243)100:0.1352912373,((Proteobacteria:0.1530616043,Proteobacteria:0.2157366776)60:0.07037030162,((Proteobacteria:0.005423860635,Proteobacteria:0.002575761354)84:0.01541355309,Proteobacteria:0.02622197026)100:0.1743560584)48:0.05780270366)68:0.04303933379,(Proteobacteria:0.4228268048,Proteobacteria:0.29377905)68:0.06111029)100:0.2071501222)40:0.02291143376)36:0.06368422427)96:0.1497733491)100:0.1422326131)100:0.1793317277,Stramenopiles:0.3338671992);"
仅供参考,使用as.igraph()将此树转换为igraph将需要以下黑客攻击:
x$node.label[1] <- " "
答案 0 :(得分:3)
我认为您需要做的就是让所有节点名称都是唯一的。这应该可以防止一些崩溃发生。看起来x
有一堆名为100
的节点。如果我们是独一无二的,那么它可能更接近你想要的结果。在这里,我在重复节点名称的末尾添加了数字。
我试过
uniqeify<-function(x, sep=" ") paste(x, ave(x, x, FUN=seq_along), sep=sep)
x$tip.label<-uniqeify(x$tip.label)
x$node.label<-uniqeify(x$node.label, ".")
x$node.label[1] <- "root"
xg <- as.igraph(x)
plot(xg, layout=layout.reingold.tilford)
哪个给了