1

我想对图进行节点置换。请参阅下面我创建的测试图。当我使用 igraph R 库中的 permute() 方法时,新图形 permute() 不会发生任何变化。怎么了?

testG <- vector(mode="list", length=6); #assign initial probabilities 
testG = list("gene1"=0, "gene2"=0, "gene3"=0, "gene4"=0, "gene5"=0, "gene6"=0);
adjacency_test <- matrix(c(0,1,1,0,0,0,1,0,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0), nrow=6, ncol=6);
rownames(adjacency_test) <- c("gene1", "gene2", "gene3","gene4","gene5","gene6");
colnames(adjacency_test) <- c("gene1", "gene2", "gene3","gene4","gene5","gene6");
require(igraph)
p <- graph.adjacency(adjacency_test, mode="undirected", weighted=TRUE);
vids.permuted <- c(6,5,4,3,2,1)
p2 <- permute(p, permutation=vids.permuted)
plot(p)
plot(p2)

磷:

图 p - 原始图

p2:

图 p2 - p 的置换图

我希望置换图 (p2) 中的集团是gene6、gene5、gene4,而不是gene1、gene2 和gene3,就像原来的那样。

怎么了?


编辑:

根据下面的回答,这是正确的,我还有另一个担心。当我手动重新排列节点名称时,当我检查所有边是否相同,以及原始图与置换图的度数是否相同时,igraph 是否正确?

p <- graph.adjacency(adjacency_test, mode="undirected", weighted=TRUE);
p2 <- p
V(p2)$name <- V(p)$name[sample(length(V(p)$name), replace=FALSE)]
# p is for sure different from p2 now
plot(p, layout=layout.reingold.tilford)
plot(p2, layout=layout.reingold.tilford)
# But why are the degrees still the same, and edges still the same?
all(E(p)==E(p2))
degs1 <- degree(p)
degs2 <- degree(p2)
all(degs1==degs2)
4

1 回答 1

2

permute 函数交换顶点 ID 并创建同构图。这不是你想要的。要交换顶点标签,请使用,

p2=p
V(p2)$name=paste("gene ",6:1)
于 2016-08-23T22:22:35.827 回答