imctoolkit.SpatialCellGraph

class SpatialCellGraph(data, adj_mat, cell_properties=False, cell_channel_properties=False, _skip_data_preparation=False)

Spatial cell graph constructed from single-cell data

Variables
  • data – single-cell data, as pandas.DataFrame, with cell IDs as index and feature names as columns

  • adj_mat – boolean adjacency matrix, as xarray.DataArray with shape (cell_i, cell_j) and coordinates (cell IDs, cell IDs). A cell j is a neighbor of cell i, iff adj_mat[i, j] == True.

__init__(data, adj_mat, cell_properties=False, cell_channel_properties=False, _skip_data_preparation=False)
Parameters
  • data (SingleCellData or DataFrame-like) – single-cell data (rows: cell IDs, columns: feature names)

  • adj_mat (DataArray-like) – boolean adjacency matrix, shape: (cells, features)

  • cell_properties (Union[bool, Sequence[str]]) – list of cell properties (e.g. regionprops) to include as node attributes when using a SingleCellData object for data; set to True to include all

  • cell_channel_properties (Union[bool, Sequence[str]]) – list of cell channel properties (e.g. intensity values) to include as node attributes when using a SingleCellData object for data; set to True to include all

property num_cells

Number of cells

Return type

int

property cell_ids

Cell IDs

Return type

Collection[int]

property num_features

Number of features

Return type

int

property feature_names

Feature names

Return type

ndarray

property is_undirected

True, if adj_mat is symmetric, False otherwise

Return type

bool

to_dataset()

Returns an xarray.Dataset representation of the current instance

Return type

Dataset

Returns

Dataset with data and adj_mat as members and (cell IDs, feature names) as coordinates

to_networkx(weight_mat=None, create_using=None)

Returns a networkx.Graph representation of the current instance

Parameters
  • weight_mat – optional edge weight matrix, will be multiplied by adj_mat

  • create_using (see networkx.from_numpy_array()) – type of graph to create, defaults to networkx.Graph for undirected graphs and networkx.DiGraph for directed graphs when None

Return type

Graph

Returns

Graph or DiGraph with cell IDs as node labels and features as node attributes

to_igraph(mode=None)

Returns an igraph.Graph representation of the current instance

Parameters

mode (see igraph.Graph.Adjacency()) – graph mode, defaults to igraph.ADJ_UNDIRECTED for undirected graphs and igraph.ADJ_DIRECTED for directed graphs when None

Returns

Graph with cell IDs and features as vertex attributes

static load_dataset(dataset)

Creates a new SpatialCellGraph from its dataset representation, see

Parameters

dataset (Dataset) – Dataset of the same format as created by to_dataset()

Return type

SpatialCellGraph

Returns

a new SpatialCellGraph instance

classmethod construct_knn_graph(data, dist_mat, k, cell_properties=False, cell_channel_properties=False)

Constructs a new k-nearest cell neighbor graph

Parameters
  • data (SingleCellData or DataFrame-like) – single-cell data (rows: cell IDs, columns: feature names)

  • dist_mat (DataArray-like) – symmetric distance matrix, shape: (cells, cells)

  • k (int) – number of nearest neighbors for the graph construction

  • cell_properties (Union[bool, Sequence[str]]) – list of cell properties (e.g. regionprops) to include as node attributes; set to True to include all

  • cell_channel_properties (Union[bool, Sequence[str]]) – list of cell channel properties (e.g. intensity values) to include as node attributes; set to True to include all

Return type

SpatialCellGraph

Returns

a directed k-nearest cell neighbor graph

classmethod construct_dist_graph(data, dist_mat, dist_thres, cell_properties=False, cell_channel_properties=False)

Constructs a new cell neighborhood graph by distance thresholding

Parameters
  • data (SingleCellData or DataFrame-like) – single-cell data (rows: cell IDs, columns: feature names)

  • dist_mat (DataArray-like) – symmetric distance matrix, shape: (cells, cells)

  • dist_thres (float) – distance hot_pixel_thres, (strictly) below which cells are considered neighbors

  • cell_properties (Union[bool, Sequence[str]]) – list of cell properties (e.g. regionprops) to include as node attributes; set to True to include all

  • cell_channel_properties (Union[bool, Sequence[str]]) – list of cell channel properties (e.g. intensity values) to include as node attributes; set to True to include all

Return type

SpatialCellGraph

Returns

an undirected cell neighborhood graph