Skip to contents

Computes graph layouts for component graphs.

Usage

ComputeLayout(object, ...)

# S3 method for class 'tbl_graph'
ComputeLayout(
  object,
  layout_method = c("cpmds", "pmds", "wpmds", "spectral"),
  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", "spectral"),
  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 'CellGraphList'
ComputeLayout(
  object,
  layout_method = c("cpmds", "pmds", "wpmds", "spectral"),
  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 'MPXAssay'
ComputeLayout(
  object,
  layout_method = c("cpmds", "pmds", "wpmds", "spectral"),
  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", "spectral"),
  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", "spectral"),
  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", "spectral"),
  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", "spectral"),
  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", "spectral"),
  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

A tbl_graph, CellGraph, CellGraphList, CellGraphAssay, PNAAssay or Seurat object

...

Additional parameters passed to other methods

layout_method

The method for calculating the graph layout: coarsened Pivot MDS ("cpmds"), weighted Pivot MDS ("wpmds"), Pivot MDS ("pmds"), or spectral layout ("spectral"; see layout_with_spectral)

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_pmds for details

seed

Set seed for reproducibility

custom_layout_function

A custom function for layout computation. The function should take a tbl_graph object and a dim value as input and return a matrix of dimensions NxD, where N is the number of nodes and D is equal to dim. If the matrix has row names, they are used to match the coordinates to the graph nodes; otherwise the rows are assumed to follow the graph node order. Note that this will override the layout_method.

custom_layout_function_args

A list of arguments passed to custom_layout_function. The dim is automatically passed to custom_layout_function and should not be included in custom_layout_function_args.

layout_name

The name of the computed layout. If this name is not given, the layout_method will be used as the name. If dim = 3, a suffix of "_3d" will be added to the layout name. This behavior is ignored if layout_name is 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

Value

For a tbl_graph, a tbl_df with the layout coordinates. For all other classes, the input object with the layout stored in the layout slot of each CellGraph. For a CellGraphList, unloaded (NULL) graphs are kept in place.

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)
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/Rtmp3BjCtL/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
#> ✔ Created a <Seurat> object with 5 cells and 158 targeted surface proteins

# Load 1 cellgraph
seur <- LoadCellGraphs(seur,
  cells = colnames(seur)[4],
  force = TRUE
)
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/Rtmp3BjCtL/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
#> ℹ Fetching CellGraphs for 1 cells 
#> ✔ 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 layouts for all loaded graphs in a CellGraphList cgl <- ComputeLayout(CellGraphs(seur), layout_method = "cpmds") #> ℹ Computing layouts for 1 graph # 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 # Use cell_plot() to visualize the layout if (FALSE) { # \dontrun{ Plot3DGraph(seur, cell_id = colnames(seur)[4], layout_method = "cpmds_3d") } # }