Utilities¶
Helper functions and network utilities used internally by SpaceTravLR and available for advanced users building custom workflows.
Spatial Utilities¶
- SpaceTravLR.tools.utils.gaussian_kernel_2d(origin, xy_array, radius, eps=0.001)[source]¶
Compute a 2D Gaussian kernel weights for a given origin on a given grid.
- Args:
origin (np.ndarray): The center point for the Gaussian kernel. xy_array (np.ndarray): Array of points to compute weights for. radius (float): The radius of the Gaussian kernel. eps (float): A small epsilon value to prevent division by zero.
- Returns:
np.ndarray: Array of Gaussian weights.
- SpaceTravLR.tools.utils.knn_distance_matrix(data, metric=None, k=40, mode='connectivity', n_jobs=4)[source]¶
Calculate a nearest neighbour distance matrix
Notice that k is meant as the actual number of neighbors NOT INCLUDING itself To achieve that we call kneighbors_graph with X = None
- SpaceTravLR.tools.utils.is_mouse_data(adata)[source]¶
Determine if an AnnData object contains mouse or human data based on gene names.
This function examines gene names to determine if the data is from mouse (capitalized first letter only) or human (all caps gene symbols). It samples a subset of genes to make the determination.
- Parameters:
adata (AnnData) – The annotated data matrix to check
- Returns:
True if the data appears to be from mouse, False if it appears to be from human
- Return type:
bool
Ligand-Receptor Utilities¶
- SpaceTravLR.models.parallel_estimators.received_ligands(xy, ligands_df, lr_info, scale_factor=1)[source]¶
Compute the amount of ligand received on the surface of each cell based on location.
- Args:
xy (np.ndarray): Array of spatial coordinates (x, y). ligands_df (pd.DataFrame): ligand gene expression values.
- Returns:
pd.DataFrame: DataFrame of received ligands for each cell.
- SpaceTravLR.models.parallel_estimators.init_received_ligands(adata, radius, cell_threshes, contact_distance=50, scale_factor=1, layer='imputed_count')[source]¶