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 columnsadj_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, iffadj_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 fordata
; set toTrue
to include allcell_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 fordata
; set toTrue
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
, ifadj_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
andadj_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
- 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 toigraph.ADJ_UNDIRECTED
for undirected graphs andigraph.ADJ_DIRECTED
for directed graphs whenNone
- 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 byto_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 constructioncell_properties¶ (
Union
[bool
,Sequence
[str
]]) – list of cell properties (e.g. regionprops) to include as node attributes; set toTrue
to include allcell_channel_properties¶ (
Union
[bool
,Sequence
[str
]]) – list of cell channel properties (e.g. intensity values) to include as node attributes; set toTrue
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 neighborscell_properties¶ (
Union
[bool
,Sequence
[str
]]) – list of cell properties (e.g. regionprops) to include as node attributes; set toTrue
to include allcell_channel_properties¶ (
Union
[bool
,Sequence
[str
]]) – list of cell channel properties (e.g. intensity values) to include as node attributes; set toTrue
to include all
- Return type
SpatialCellGraph
- Returns
an undirected cell neighborhood graph