Skip to contents

Create a CellGraphAssay object from a count matrix. The expected format of the input matrix is features x cells.

Usage

CreateCellGraphAssay(
  counts,
  cellgraphs,
  polarization = NULL,
  colocalization = NULL,
  fs_map = NULL,
  verbose = FALSE,
  ...
)

Arguments

counts

Unnormalized data (raw counts)

cellgraphs

A named 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

verbose

Print messages

...

Additional arguments passed to CreateAssayObject

Value

A CellGraphAssay object

Examples


library(pixelatorR)
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 CellGraphAssay
cg_assay <- CreateCellGraphAssay(counts = counts, cellgraphs = bipartite_graphs)
cg_assay
#> CellGraphAssay data with 80 features for 5 cells
#> First 10 features:
#>  CD274, CD44, CD25, CD279, CD41, HLA-ABC, CD54, CD26, CD27, CD38 
#> Loaded CellGraph objects:
#>  5