2014-05-21 36 views
2

我已經將一個系統發育樹轉換爲R中的igraph圖形對象。轉換非常簡單。 (我甚至寫我自己)igraph從系統發育樹(as.igraph()樹轉換)中失去內部節點結構

x <- read.tree(treeName) #library(ape) 
xg <- as.igraph(x)   #library(igraph) 
xn <- as.network(x)  #library(network) 

的問題是,失去的igraph內部節點,並把所有的節點,在一個超級節點的值相同。轉換爲網絡圖形對象不會執行此操作。

Blue nodes = igraph, red nodes = network, then the original phylogenetic tree plotted using ape

這可能是一個非常明顯的問題或沒有,但我怎麼挽留一個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] <- " " 

回答

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) 

這給了

resulting igraph