paste3.model_selection.generate_graph
- paste3.model_selection.generate_graph(slice, aligned_spots=None, degree=4)[source]
Generates a graph using the networkx library where each node represents a spot from the given slice object, and edges are formed between each node and its closest neighbors based on spatial distance. The number of neighbors is controlled by the degree parameter.
- Parameters:
slice (AnnData) -- AnnData object containing data for a slice.
aligned_spots (pd.Series, optional) -- A boolean pandas Series mapping each node (spot index) to cluster labels. A cluster labeled True means that a spot in slice A is aligned with another spot in slice B after computing pairwise alignment.
degree (int, optional, default: 4) -- The number of closest edges to connect each node to.
- Returns:
G (networkx.Graph) -- A NetworkX graph where each node represents a spot, and each edge represents a connection to one of the closest neighbors. The nodes are indexed by the indices of the spots in the input slice.
node_dict (dict) -- A dictionary mapping each node (spot index) to its corresponding label ( index from the slice.obs.index).