1

I want to node permute a graph. See the test graph I have created, below. When I use the permute() method from the igraph R library, no changes occur in the new graph permute() makes. What is 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:

Graph p - the original graph

p2:

Graph p2 - the permuted graph of p

I expect the clique in the permuted graph (p2) to be gene6, gene5, gene4, not gene1, gene2, and gene3 again, as in the original.

What is happening?


EDIT:

Per the response below, which is correct, I had another worry. When I rearrange the node names manually, how come when I check if all the edges are the same, and the degrees are the same of the 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 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)
zx8754
  • 52,746
  • 12
  • 114
  • 209
lrthistlethwaite
  • 494
  • 2
  • 6
  • 23

1 Answers1

2

The permute function swaps vertex IDs and creates an isomorphic graph. This is not what you want. To swap vertex labels use,

p2=p
V(p2)$name=paste("gene ",6:1)
Ryan Haunfelder
  • 766
  • 3
  • 11
  • 1
    Ugh the documentation was so generic. I was wondering why the sample code had the graph.isomorphic() method as a test line. Thank you! – lrthistlethwaite Aug 23 '16 at 22:38
  • 1
    I'd have to agree with you on the documentation, there is a bit of ambiguity in the wording. – Ryan Haunfelder Aug 23 '16 at 22:41
  • I know I accepted your answer already, but do you have any comment on my edit (above)? Another worry presented itself, when I checked if all the edges are the same, and the degrees are the same of the original graph versus permuted graph Why does igraph say true, when the plots are clearly different? – lrthistlethwaite Aug 23 '16 at 22:50
  • Comparing the edges evaluates to TRUE because the vertex IDs have not changed, just their labels. Try typing E(p)[[]] and E(p2)[[]] into the console and I think you will see what is happening. The permute function will swap ids if that's what you want. – Ryan Haunfelder Aug 23 '16 at 23:00