
Compute a graph layout
ComputeLayout.RdComputes graph layouts for component graphs.
Usage
ComputeLayout(object, ...)
# S3 method for class 'tbl_graph'
ComputeLayout(
object,
layout_method = c("cpmds", "pmds", "wpmds"),
dim = 3,
normalize_layout = FALSE,
project_on_unit_sphere = FALSE,
pivots = 100,
seed = 123,
custom_layout_function = NULL,
custom_layout_function_args = NULL,
...
)
# S3 method for class 'CellGraph'
ComputeLayout(
object,
layout_method = c("cpmds", "pmds", "wpmds"),
layout_name = NULL,
dim = 3,
normalize_layout = FALSE,
project_on_unit_sphere = FALSE,
pivots = 100,
seed = 123,
custom_layout_function = NULL,
custom_layout_function_args = NULL,
...
)
# S3 method for class 'MPXAssay'
ComputeLayout(
object,
layout_method = c("cpmds", "pmds", "wpmds"),
layout_name = NULL,
dim = 3,
normalize_layout = FALSE,
project_on_unit_sphere = FALSE,
pivots = 100,
seed = 123,
verbose = TRUE,
custom_layout_function = NULL,
custom_layout_function_args = NULL,
cl = NULL,
...
)
# S3 method for class 'CellGraphAssay'
ComputeLayout(
object,
layout_method = c("cpmds", "pmds", "wpmds"),
layout_name = NULL,
dim = 3,
normalize_layout = FALSE,
project_on_unit_sphere = FALSE,
pivots = 100,
seed = 123,
verbose = TRUE,
custom_layout_function = NULL,
custom_layout_function_args = NULL,
cl = NULL,
...
)
# S3 method for class 'CellGraphAssay5'
ComputeLayout(
object,
layout_method = c("cpmds", "pmds", "wpmds"),
layout_name = NULL,
dim = 3,
normalize_layout = FALSE,
project_on_unit_sphere = FALSE,
pivots = 100,
seed = 123,
verbose = TRUE,
custom_layout_function = NULL,
custom_layout_function_args = NULL,
cl = NULL,
...
)
# S3 method for class 'PNAAssay'
ComputeLayout(
object,
layout_method = c("cpmds", "pmds", "wpmds"),
layout_name = NULL,
dim = 3,
normalize_layout = FALSE,
project_on_unit_sphere = FALSE,
pivots = 100,
seed = 123,
verbose = TRUE,
custom_layout_function = NULL,
custom_layout_function_args = NULL,
cl = NULL,
...
)
# S3 method for class 'PNAAssay5'
ComputeLayout(
object,
layout_method = c("cpmds", "pmds", "wpmds"),
layout_name = NULL,
dim = 3,
normalize_layout = FALSE,
project_on_unit_sphere = FALSE,
pivots = 100,
seed = 123,
verbose = TRUE,
custom_layout_function = NULL,
custom_layout_function_args = NULL,
cl = NULL,
...
)
# S3 method for class 'Seurat'
ComputeLayout(
object,
assay = NULL,
layout_method = c("cpmds", "pmds", "wpmds"),
layout_name = NULL,
dim = 3,
normalize_layout = FALSE,
project_on_unit_sphere = FALSE,
pivots = 100,
seed = 123,
verbose = TRUE,
custom_layout_function = NULL,
custom_layout_function_args = NULL,
cl = NULL,
...
)Arguments
- object
An object
- ...
Additional parameters passed to other methods
- layout_method
The method for calculating the graph layout: coarsened Pivot MDS (cpmds), weighted Pivot MDS ("wpmds") or Pivot MDS (pmds)
- dim
An integer specifying the dimensions of the layout (2 or 3). Note that for "cpmds", "pmds" and "wpmds", the x and y coordinates will be identical regardless if dim is set to 2 or 3.
- normalize_layout
Logical specifying whether the coordinate system should be centered at origo and the coordinates scaled such that their median length (euclidean norm) is 1.
- project_on_unit_sphere
Should the resulting layout be projected onto a unit sphere?
- pivots
Used for Pivot MDS layout algorithms. See
?layout_with_pmdsfor details- seed
Set seed for reproducibility
- custom_layout_function
A custom function for layout computation. The function should take a
tbl_graphobject and adimvalue as input and return a matrix of dimensions NxD, where N is the number of nodes and D is equal todim. Note that this will override thelayout_method.- custom_layout_function_args
A list of arguments passed to
custom_layout_function. Thedimis automatically passed tocustom_layout_functionand should not be included incustom_layout_function_args.- layout_name
The name of the computed layout. If this name is not given, the
layout_methodwill be used as the name. Ifdim = 3, a suffix of "_3d" will be added to the layout name. This behavior is ignored iflayout_nameis provided.- verbose
Print messages
- cl
An integer to indicate number of child-processes (integer values are ignored on Windows) for parallel evaluations. See Details on performance in the documentation for
pbapply. The default is NULL, which means that no parallelization is used.- assay
Name of assay to compute layouts for
See also
center_layout_coordinates() for centering layout coordinates,
normalize_layout_coordinates() for normalizing layout coordinates and
project_layout_coordinates_on_unit_sphere() for projecting layout coordinates onto a unit sphere.
Examples
library(pixelatorR)
library(dplyr)
pxl_file <- minimal_pna_pxl_file()
# Load example data
seur <- ReadPNA_Seurat(pxl_file)
#> ✔ Created a <Seurat> object with 5 cells and 158 targeted surface proteins
# Load 1 cellgraph
seur <- LoadCellGraphs(seur,
cells = colnames(seur)[4],
force = TRUE
)
#> ℹ Fetching edgelists for 1 cells
#> → Creating <CellGraph> objects
#> → Fetching marker counts
#> → Adding marker counts to <CellGraph> object(s)
#> ✔ Successfully loaded 1 <CellGraph> object(s).
# Get CellGraph
cg <- CellGraphs(seur)[[colnames(seur)[4]]]
# Get tbl_graph object
tbl_graph <- slot(cg, name = "cellgraph")
# Compute layout for a tbl_graph
layout <- ComputeLayout(tbl_graph, layout_method = "cpmds")
# Visualize
plotly::plot_ly(
data = layout, x = ~x, y = ~y, z = ~z,
type = "scatter3d", mode = "markers", marker = list(size = 2)
)
# Compute layout for a CellGraph
cg <- ComputeLayout(cg, layout_method = "cpmds")
# Compute layout for a PNAAssay
cg_assay <- ComputeLayout(seur[["PNA"]], layout_method = "cpmds")
#> ℹ Computing layouts for 1 graphs
# Seurat method
seur <- ComputeLayout(seur)
#> ℹ Computing layouts for 1 graphs
# Visualize with Plot3DGraph
Plot3DGraph(seur, cell_id = colnames(seur)[4], layout_method = "cpmds_3d")