Skip to contents

“An algorithm must be seen to be believed.”

-Donald Knuth

Export a graph for Gephi

The precise_viz() router draws panels but performs no file I/O. To take a graph into a dedicated tool like Gephi, use the small standalone helper precise_graphml(), which writes a plain weighted undirected graph to a .graphml file via igraph.

Like the rest of PreciseViz, precise_graphml() is a bring-your-own-matrix tool: it accepts either a row of a typed tibble (selected by key=) or a bare square symmetric matrix, so it works on PreciseDist output and on a matrix from anywhere else.

set.seed(1)
cells <- c(1:5, 60:64, 118:122)
cell_cycle <- as.matrix(data_cell_cycle[cells, 2:51])
rownames(cell_cycle) <- paste0(data_cell_cycle$Cell_cycle[cells], "_", cells)

From data to a GraphML file

Build a distance, project it to a graph, and export one row by its key:

d <- precise_dist(cell_cycle, dists = "euclidean", verbose = FALSE)
g <- precise_graph(d, methods = "knn", params = list(knn = list(k = 3)),
                   verbose = FALSE)

out <- precise_graphml(g, file = tempfile(fileext = ".graphml"),
                       key = "euclidean__knn")
basename(out)
#> [1] "file15e472e36246.graphml"

precise_graphml() refuses to overwrite an existing file, and it refuses a distance-typed row of a tibble. Edge weight means connection strength in every graph tool, so exporting a distance as an edge weight would make the least related pairs look like the strongest links. Convert or project the row first.

Any matrix will do

A bare matrix carries no type, so the pure export needs only a square symmetric matrix and no type= at all. That means you can hand it a matrix produced by a completely different method, say an affinity S from another package, and still get a Gephi-ready file:

precise_graphml(S, file = "my_graph.graphml")

Open the resulting .graphml in Gephi to lay out, colour, and explore the graph interactively.