Calculate the adjacency matrix given a spatial coordinate matrix with 2-dimension or 3-dimension or more.

AddAdj(
  pos,
  type = "fixed_distance",
  platform = c("Others", "Visium", "ST"),
  neighbors = 6,
  ...
)

Arguments

pos

a matrix object, with columns representing the spatial coordinates that can be any diemsion, i.e., 2, 3 and >3.

type

an optional string, specify which type of neighbors' definition. Here we provide two definition: one is "fixed_distance", the other is "fixed_number".

platform

a string, specify the platform of the provided data, default as "Others". There are more platforms to be chosen, including "Visuim", "ST" and "Others" ("Others" represents the other SRT platforms except for 'Visium' and 'ST') The platform helps to calculate the adjacency matrix by defining the neighborhoods when type="fixed_distance" is chosen.

neighbors

an optional postive integer, specify how many neighbors used in calculation, default as 6.

...

Other arguments passed to getAdj_auto.

Value

return a sparse matrix, representing the adjacency matrix.

Details

When the type = "fixed_distance", then the spots within the Euclidean distance cutoffs from one spot are regarded as the neighbors of this spot. When the type = "fixed_number", the K-nearest spots are regarded as the neighbors of each spot.

References

None

See also

None

Examples

data(CosMx_subset)
pos <- as.matrix(CosMx_subset@meta.data[,c("x", "y")])
Adj_sp <- AddAdj(pos)
#> The spatial cooridnates are 2 dimensions
#> Find the adjacency matrix by bisection method...
#> Current radius is 65.52
#> Median of neighborhoods is 0
#> Current radius is 97.78
#> Median of neighborhoods is 2
#> Current radius is 97.78
#> Median of neighborhoods is 5