Created
June 18, 2016 20:18
-
-
Save ngopal/b7ada612bf2612fa2f00b86d05a34a2b to your computer and use it in GitHub Desktop.
Convert iGraph to CytoscapeJS elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toCytojs(g) { | |
s = c() | |
s = append(s,"[") | |
for (i in 1:length(V(g))) { | |
s = append(s, paste("{ data: { id: \'",i,"\' } },", sep='')) | |
} | |
temp <- get.edgelist(g) | |
for (i in 1:length(E(g))) { | |
if (i == length(E(g))) { | |
s = append(s, paste("{ data: { id: \'",i+length(V(g)),"\', source: \'",temp[i,1],"\', target: \'",temp[i,2],"\' } }", sep='')) | |
} | |
else { | |
s = append(s, paste("{ data: { id: \'",i+length(V(g)),"\', source: \'",temp[i,1],"\', target: \'",temp[i,2],"\' } },", sep='')) | |
} | |
} | |
s = append(s, "]") | |
return( paste(s, collapse="") ) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment