Skip to contents

Calculates a graph layout for a component's edgelist, and outputs a list with the bipartite graph, layout, and antibody counts per A pixel.

Usage

ComputeLayout(object, ...)

# S3 method for tbl_graph
ComputeLayout(
  object,
  layout_method = c("pmds", "wpmds", "fr", "kk", "drl"),
  dim = 2,
  normalize_layout = FALSE,
  project_on_unit_sphere = FALSE,
  k = 0,
  pivots = 100,
  seed = 123,
  custom_layout_function = NULL,
  custom_layout_function_args = NULL,
  ...
)

# S3 method for CellGraph
ComputeLayout(
  object,
  layout_method = c("pmds", "wpmds", "fr", "kk", "drl"),
  layout_name = NULL,
  dim = 2,
  normalize_layout = FALSE,
  project_on_unit_sphere = FALSE,
  k = 0,
  pivots = 100,
  seed = 123,
  custom_layout_function = NULL,
  custom_layout_function_args = NULL,
  ...
)

# S3 method for MPXAssay
ComputeLayout(
  object,
  layout_method = c("pmds", "wpmds", "fr", "kk", "drl"),
  layout_name = NULL,
  dim = 2,
  normalize_layout = FALSE,
  project_on_unit_sphere = FALSE,
  k = 0,
  pivots = 100,
  seed = 123,
  verbose = TRUE,
  custom_layout_function = NULL,
  custom_layout_function_args = NULL,
  cl = NULL,
  ...
)

# S3 method for CellGraphAssay
ComputeLayout(
  object,
  layout_method = c("pmds", "wpmds", "fr", "kk", "drl"),
  layout_name = NULL,
  dim = 2,
  normalize_layout = FALSE,
  project_on_unit_sphere = FALSE,
  k = 0,
  pivots = 100,
  seed = 123,
  verbose = TRUE,
  custom_layout_function = NULL,
  custom_layout_function_args = NULL,
  cl = NULL,
  ...
)

# S3 method for CellGraphAssay5
ComputeLayout(
  object,
  layout_method = c("pmds", "wpmds", "fr", "kk", "drl"),
  layout_name = NULL,
  dim = 2,
  normalize_layout = FALSE,
  project_on_unit_sphere = FALSE,
  k = 0,
  pivots = 100,
  seed = 123,
  verbose = TRUE,
  custom_layout_function = NULL,
  custom_layout_function_args = NULL,
  cl = NULL,
  ...
)

# S3 method for Seurat
ComputeLayout(
  object,
  assay = NULL,
  layout_method = c("pmds", "wpmds", "fr", "kk", "drl"),
  layout_name = NULL,
  dim = 2,
  normalize_layout = FALSE,
  project_on_unit_sphere = FALSE,
  k = 0,
  pivots = 100,
  seed = 123,
  verbose = TRUE,
  custom_layout_function = NULL,
  custom_layout_function_args = NULL,
  ...
)

Arguments

object

An object

...

Additional parameters passed to other methods

layout_method

The method for calculating the graph layout: weighted Pivot MDS ("wpmds"), Pivot MDS (pmds), Fruchterman-Reingold ("fr"), Kamada-Kawai ("kk"), "drl".

dim

An integer specifying the dimensions of the layout (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?

k

The size of the neighborhood from which to pool counts from in the UPIA antibody count table. 0 is recommended.

pivots

Only used for "wpmds" and "pmds" 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. 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.

verbose

Print messages

cl

A cluster object created by makeCluster, or 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

An object containing a graph layout

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 <- system.file("extdata/five_cells",
                        "five_cells.pxl",
                        package = "pixelatorR")

# Load example data
seur <- ReadMPX_Seurat(pxl_file)
#>  Created a 'Seurat' object with 5 cells and 80 targeted surface proteins

# Load 1 cellgraph
seur <- LoadCellGraphs(seur, cells = colnames(seur)[1],
                       load_as = "Anode", force = TRUE)
#> →    Loading CellGraphs for 1 cells from sample 1
#>  Successfully loaded 1 CellGraph object(s).

# Get CellGraph
cg <- CellGraphs(seur)[[colnames(seur)[1]]]

# Get tbl_graph object
tbl_graph <- slot(cg, name = "cellgraph")

# Compute layout for a tbl_graph
layout <- ComputeLayout(tbl_graph, layout_method = "fr")
layout %>% head()
#> # A tibble: 6 × 2
#>       x     y
#>   <dbl> <dbl>
#> 1 -13.9 -3.73
#> 2 -14.3 -1.98
#> 3 -12.6 -3.69
#> 4 -11.5 -3.45
#> 5 -12.9 -4.20
#> 6 -13.5 -2.32


# Compute layout for a CellGraph
cg <- ComputeLayout(cg, layout_method = "fr")


# Compute layout for a CellGraphAssay
cg_assay <- ComputeLayout(seur[["mpxCells"]], layout_method = "fr")
#>  Computing layouts for 1 graphs


# Compute layout for a Seurat object
seur <- ComputeLayout(seur, layout_method = "fr")
#>  Computing layouts for 1 graphs