dance.transforms.graph

class dance.transforms.graph.CellFeatureBipartiteGraph(cell_feature_channel, *, mod=None, **kwargs)[source]
Parameters:
  • cell_feature_channel (str) –

  • mod (str | None) –

class dance.transforms.graph.CellFeatureGraph(cell_feature_channel, gene_feature_channel=None, *, mod=None, normalize_edges=True, **kwargs)[source]
Parameters:
  • cell_feature_channel (str) –

  • gene_feature_channel (str | None) –

  • mod (str | None) –

  • normalize_edges (bool) –

class dance.transforms.graph.DSTGraph(k_filter=200, num_cc=30, *, ref_split='train', inf_split='test', **kwargs)[source]

DSTG link graph construction.

The link graph consists of pseudo-spot nodes and real-spot nodes, where the psudo-spots are generated from reference data with known cell-type portions. The real-spot nodes are from the data. The linkage, i.e., edges are derived based on mutual nearest neighbor in the cononical correlation analysis embedding space.

Parameters:
  • k_filter (int) – Number of k-nearest neighbors to keep in the final graph.

  • num_cc (int) – Number of dimensions to use in the concanical correlation analysis.

  • ref_split (str) – Name of the reference data split, i.e., the pseudo-spot data.

  • inf_split (str) – Name of the inference data split, i.e., the real-spot data.

class dance.transforms.graph.FeatureFeatureGraph(threshold=0.3, *, positive_only=False, normalize_edges=True, score_func='pearson', score_func_kwargs=None, **kwargs)[source]

Feature-feature similarity graph.

Parameters:
  • threshold (float) – Edge similarity score threshold.

  • positive_only (bool) – Only use positive similarity score if set to True.

  • normalize_edges (bool) – Normalize edge weights following GCN if set to True.

  • score_func – Distance function to use, supported options are "pearson", "spearman", and "rbf"

  • score_func_kwargs (Optional[Dict[str, Any]]) – Optional kwargs passed to the score function, e.g. see dance.utils.matrix.dist_to_rbf().

class dance.transforms.graph.NeighborGraph(n_neighbors=15, *, n_pcs=None, knn=True, random_state=0, method='umap', metric='euclidean', channel='CellPCA', **kwargs)[source]

Construct neighborhood graph of observations.

This is a thin wrapper of the scanpy.pp.neighbors() class and uses the connectivities as the adjacency matrix. If you want full flexibility and support from the scanpy.pp.neighbors() method, please consider using the interface AnnDataTransform.

Parameters:
  • n_neighbors (int) – Number of neighbors.

  • n_pcs (Optional[int]) – Number of PCs to use.

  • knn (bool) – If True, then use a hard threshold to restrict the number of neighbors to n_neighbors.

  • random_state (int) – Random seed.

  • method (Optional[str]) – Method for computing the connectivities.

  • metric (str) – Distance metric.

  • channel (Optional[str]) – Name of the PC channel.

class dance.transforms.graph.PCACellFeatureGraph(n_components=400, split_name=None, *, normalize_edges=True, feat_norm_mode=None, feat_norm_axis=0, mod=None, log_level='WARNING')[source]
Parameters:
  • n_components (int) –

  • split_name (str | None) –

  • normalize_edges (bool) –

  • feat_norm_mode (str | None) –

  • feat_norm_axis (int) –

  • mod (str | None) –

  • log_level (Literal['NOTSET', 'DEBUG', 'INFO', 'WARNING', 'ERROR']) –

class dance.transforms.graph.SMEGraph(radius=3, *, channels=('spatial', 'spatial_pixel', 'MorphologyFeatureCNN', 'CellPCA'), channel_types=('obsm', 'obsm', 'obsm', 'obsm'), **kwargs)[source]

Spatial Morphological gene Expression graph.

Parameters:
  • radius (float) –

  • channels (Sequence[str]) –

  • channel_types (Sequence[str]) –

class dance.transforms.graph.ScMoGNNGraph(inductive=False, cell_init='none', pathway=True, subtask='openproblems_bmmc_cite_phase2_rna', pathway_weight=None, pathway_threshold=0.0, pathway_path='data/h.all.v7.4', **kwargs)[source]

Construct the cell-feature graph object for scmognn.

Parameters:
  • inductive (bool) – Whether to use inductive learning. Default: False.

  • cell_init (str) – Initialization method for cell features. Default: ‘none’.

  • pathway (bool) – Whether to use pathway information. Default: True.

  • subtask (str) – Subtask name. Default: ‘gex2adt’.

  • pathway_weight (str) – Weighting scheme for pathway filtering. Default: None.

  • pathway_threshold (float) – Threshold for pathway filtering. Default: 0.

  • pathway_path (str) – Path to pathway file. Default: ‘data/h.all.v7.4’.

Returns:

g – The generated graph.

Return type:

DGLGraph

class dance.transforms.graph.SpaGCNGraph(alpha, beta, *, channels=('spatial', 'spatial_pixel', 'image'), channel_types=('obsm', 'obsm', 'uns'), **kwargs)[source]
Parameters:
  • channels (Sequence[str]) –

  • channel_types (Sequence[str]) –

__init__(alpha, beta, *, channels=('spatial', 'spatial_pixel', 'image'), channel_types=('obsm', 'obsm', 'uns'), **kwargs)[source]

Initialize SpaGCNGraph.

Parameters:
  • alpha – Controls the color scale.

  • beta – Controls the range of the neighborhood when calculating grey values for one spot.

  • channels (Sequence[str]) –

  • channel_types (Sequence[str]) –

class dance.transforms.graph.SpaGCNGraph2D(*, channel='spatial_pixel', **kwargs)[source]
Parameters:

channel (str) –

class dance.transforms.graph.StagateGraph(model_name='radius', *, radius=1, n_neighbors=5, channel='spatial_pixel', channel_type='obsm', **kwargs)[source]

STAGATE spatial graph.

Parameters:
  • model_name (str) – Type of graph to construct. Currently support radius and knn. See NearestNeighbors for more info.

  • radius (float) – Radius parameter for radius_neighbors_graph.

  • n_neighbors (int) – Number of neighbors for kneighbors_graph.

  • channel (str) –

  • channel_type (str) –