+ write.table(df$vertices, nodesfile, sep='\t', row.names=FALSE)
+ }
+ if (!is.null(edgesfile)) {
+ write.table(df$edges, edgesfile, sep='\t', row.names=FALSE)
+ }
+ if (is.null(edgesfile) & is.null(nodesfile)) {
+ df
+ }
+}
+
+graph.to.file2 <- function(graph, layout, nodesfile = NULL, edgesfile = NULL, community = FALSE, color = NULL, sweight = NULL) {
+ require(igraph)
+ g <- graph
+ V(g)$x <- layout[,1]
+ V(g)$y <- layout[,2]
+ if (ncol(layout) == 3) {
+ V(g)$z <- layout[,3]
+ }
+ v.colors <- col2rgb(V(g)$color)
+ V(g)$r <- v.colors[1,]
+ V(g)$g <- v.colors[2,]
+ V(g)$b <- v.colors[3,]
+
+ if (!is.null(sweight)) {
+ V(g)$sweight <- sweight
+ }
+ df <- get.data.frame(g, what='both')
+ if (!is.null(nodesfile)) {
+ write.table(df$vertices, nodesfile, sep='\t', row.names=FALSE)