Skip to contents

Convert objects to a CellGraphAssay5

Usage

as.CellGraphAssay5(x, ...)

# S3 method for Assay5
as.CellGraphAssay5(
  x,
  cellgraphs = NULL,
  polarization = NULL,
  colocalization = NULL,
  fs_map = NULL,
  ...
)

Arguments

x

An object to convert to class CellGraphAssay5

...

Arguments passed to other methods

cellgraphs

A list of CellGraph objects

polarization

A tbl_df with polarization scores

colocalization

A tbl_df with colocalization scores

fs_map

A tbl_df with information on source pxl file paths, sample IDs, and component IDs

Value

A CellGraphAssay5 object

Examples


library(pixelatorR)
library(SeuratObject)
library(dplyr)
library(tidygraph)

pxl_file <- system.file("extdata/five_cells",
                        "five_cells.pxl",
                        package = "pixelatorR")
counts <- ReadMPX_counts(pxl_file)
#>  Loading count data from /private/var/folders/gw/bdcqhnvs0m9gs_mq8n51jtbc0000gn/T/RtmpMJapOH/temp_libpatha88241f348a/pixelatorR/extdata/five_cells/five_cells.pxl
edgelist <- ReadMPX_item(pxl_file, items = "edgelist")
#>  Loading item(s) from: /private/var/folders/gw/bdcqhnvs0m9gs_mq8n51jtbc0000gn/T/RtmpMJapOH/temp_libpatha88241f348a/pixelatorR/extdata/five_cells/five_cells.pxl
#> →   Loading edgelist data
#>  Returning a 'tbl_df' object
components <- colnames(counts)
edgelist_split <-
  edgelist %>%
  select(upia, upib, component) %>%
  distinct() %>%
  group_by(component) %>%
  group_split() %>%
  setNames(nm = components)

# Convert data into a list of CellGraph objects
bipartite_graphs <- lapply(edgelist_split, function(x) {
  x <- x %>% as_tbl_graph(directed = FALSE)
  x <- x %>% mutate(node_type = case_when(name %in% edgelist$upia ~ "A", TRUE ~ "B"))
  attr(x, "type") <- "bipartite"
  CreateCellGraphObject(cellgraph = x)
})

# Create Assay5
assay5 <- CreateAssay5Object(counts = counts)
#> Warning: Data is of class matrix. Coercing to dgCMatrix.

# Convert Assay5 to CellGraphAssay5
cg_assay <- as.CellGraphAssay5(assay5, cellgraphs = bipartite_graphs)
cg_assay
#> CellGraphAssay (v5) data with 80 features for 5 cells
#> First 10 features:
#>  CD274, CD44, CD25, CD279, CD41, HLA-ABC, CD54, CD26, CD27, CD38 
#> Layers:
#>  counts 
#> Loaded CellGraph objects:
#>  5