First, spatial gradients for each embedding dimension are computed for every points (cell) by looking at each cell's neighbors. These point gradients can be smoothed using bilateral/anisotropic filtering. Then gradients for triangles are computed as the average of their vertices (3 for proper triangles, 2 for degenerate exterior triangles at the boundaries). Finally, primal and dual edge gradients are computed as the sum of the gradients for the two points and two triangles, respectively, that are associated with each edge.
Usage
compute_gradients(
dmt,
smooth_distance = "none",
smooth_similarity = "none",
smooth_iter = 1,
on_edges = FALSE
)Arguments
- dmt
A list containing the mesh data structures:
ptsis aNx2+Mdata table with columnsXandYcontaining the coordinates of cells and additional metadata.trisis aFx4data table containing the X,Y coordinates of each triangle's centroid in the first two columns, and area and largest height of each triangle in the last two columns.edgesis aEx14data table with columnsfrom_pt,to_pt,from_tri,to_tri,x0_pt,x1_pt,y0_pt,y1_pt,x0_tri,x1_tri,y0_tri,y1_tri,length_pt,length_tri. If only one triangle uses an edge, then thefrom_tri,x0_tri, andy0_trifields will contain NaN values.tri_to_ptis aFxNsparse matrix with value 1 at (i,j) if triangle i uses point j as a vertex.udv_cellscontains cell embeddings stored inembeddings(aNxDmatrix withD-dimensional embeddings for each cell) andloadings(aGxDmatrix with gene loadings for each latent variable).
- smooth_distance
One of
c('none', 'euclidean', 'projected', 'constant'). If eithersmooth_distanceorsmooth_similarityis'none'(the default), then no smoothing of the gradient field is conducted.- smooth_similarity
One of
c('none', 'euclidean', 'projected', 'constant'). If eithersmooth_distanceorsmooth_similarityis'none'(the default), then no smoothing of the gradient field is conducted.- smooth_iter
Number of rounds of gradient smoothing.
Value
A gradient field with the following attributes:
- pts
A
2xDxNarray in column-major ordering containing the spatial gradient in expression for each ofDlatent variables at every point in space.- tris
A
2xDxFarray in column-major ordering containing the spatial gradient in expression for each ofDlatent variables at every triangle in the mesh. Average of the vertices (3 for full triangles, 2 for degenerate triangles).- edges_pts
A
2xDxEarray in column-major ordering containing the spatial gradient in expression for each ofDlatent variables at every primal edge (point-to-point) in the mesh. Average of the two endpoints.- edges_tris
A
2xDxEarray in column-major ordering containing the spatial gradient in expression for each ofDlatent variables at every dual edge (triangle-to-triangle) in the mesh. Average of the two adjacent triangles.