Viewing Results with Gephi.Rmd
“An algorithm must be seen to be believed.”
Gephi is a fabulous graphing tool, so we have made sure the results of precise_viz()
can be written out into a format that Gephi understands. First, we will quickly calculate a distance matrix, transform it with precise_transform()
, turn it into a graph with precise_graph()
, and then write out a GraphML file with precise_viz()
, which we can subsequently load into Gephi. Rather than using the output of precise_dist()
with precise_fuse()
, however, we will use the results of SIMLR()
directly. We do this to drive home the point that precise_transform()
, precise_graph()
and precise_viz()
are universal functions that can take any distance matrix as input. The following functions were detailed in the Cell Cycle vignette, so they are being lumped together here:
library(PreciseDist)
data("data_cell_cycle")
library(tibble)
as_tibble(data_cell_cycle)
library(dplyr)
cell_cycle_data <- data_cell_cycle %>%
dplyr::select(-Cell_cycle) %>%
as.matrix()
cell_cycle_labels <- data_cell_cycle %>%
dplyr::select(Cell_cycle) %>%
as.matrix()
library(SIMLR)
cell_cycle_simlr <- cell_cycle_data %>%
t() %>%
SIMLR(c = 3)$S
Now we can play with the distance matrix output of SIMLR()
:
cell_cycle_simlr_simil <- cell_cycle_simlr$S %>%
precise_transform(enforce_sim = TRUE) %>%
precise_transform(binary_matrix = "0.20") %>%
precise_transform(transform = "binorm") %>%
precise_transform(transform = "random_walk") %>%
precise_transform(enforce_dist = TRUE)
Lastly, create the graph and input it into precise_viz()
. Note that we have set a file path for the graphml parameter here:
cell_cycle_graph <- precise_graph(
data = cell_cycle_simlr_simil,
method = 1,
n_neighbors = 5,
spread = 5,
min_dist = 0.00,
bandwidth = 1,
parallel = FALSE,
verbose = TRUE
)
cell_cycle_viz <- precise_viz(
cell_cycle_graph,
plot_type = "fr_2d_graph",
k = 15,
color_vec = as.character(cell_cycle_labels),
colors = c("#0017FF", "#000000", "#FF0017"),
size = 1,
graphml = "/absolute_path/to_somewhere/with_full_name/not_including_the/file_extension",
html = NULL,
verbose = TRUE
)
The GraphML output file can now be opened in Gephi v0.9.2. To view the layout precise_viz()
calculated, install the MdsLayout plugin and use gravity_x and gravity_y as the inputs into Dimension 1 and Dimension 2, respectively. Note that the colors seen upon initial loading into Gephi are written into the GraphML file after being passed from the precise_viz()
color_vec and colors arguments:
Of course, you can now also leverage Gephi’s layouts like ForceAtlas2:
Or, their fruchterman-reingold layout, which gives aesthetic results very different from precise_viz()
:
P.S. The embedding of downloadable Gephi-exported static images into pkgdown was done using plotly_embed()
from this package (i.e. PreciseDist).