r - igraph permute() method bug -
i want node permute graph. see test graph have created, below. when use permute() method igraph r library, no changes occur in new graph permute() makes. happening?
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:
i expect clique in permuted graph (p2) gene6, gene5, gene4, not gene1, gene2, , gene3 again, in original.
what happening?
edit:
per response below, correct, had worry. when rearrange node names manually, how come when check if edges same, , degrees same of original graph versus permuted graph, igraph says true?
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 sure different p2 plot(p, layout=layout.reingold.tilford) plot(p2, layout=layout.reingold.tilford) # why degrees still same, , edges still same? all(e(p)==e(p2)) degs1 <- degree(p) degs2 <- degree(p2) all(degs1==degs2)
the permute function swaps vertex ids , creates isomorphic graph. not want. swap vertex labels use,
p2=p v(p2)$name=paste("gene ",6:1)
Comments
Post a Comment