Identifying filterDist value
Closed this issue · 2 comments
Hello Jean and team,
Thank you for all your previous help. I'm writing to ask if there's a good way to identify a filterDist value within getSpatialNeighbors. Are there specific characteristics to look in the plots generated by getSpatialNeighbors?
Thank you in advance!
Hi li-shimin,
Sorry for the delayed response!
filtDist
is a parameter defined as the "Euclidean distance beyond which two cells cannot be considered neighbors". Essentially it is a filter that can be used to determine how close two cells need to be in order to be considered neighbors in the binary weight matrix that is produced. You can think of this threshold in terms of whatever the positional measurements of the cells in your dataset are. For example, if the x-y coordinates of your cells are in microns, then filtDist
is a micron-distance in which cells that are farther away than this distance are no longer considered neighbors.
This filtering distance will depend on the positional coordinates of the cells in your dataset, as well as other considerations you may want to think about. For example, if the positions of the cells are in microns, perhaps you do not want to consider cells a certain micron distance away to be neighbors for some biological reason.
In the vignette mOB_analysis
, the weight matrix, and thus the connections between cells that are considered neighbors can be visualized via:
# Get neighbor relationships
w <- getSpatialNeighbors(pos, filterDist = 2.5)
plotNetwork(pos, w)
In the resulting graph, each point is a cell and each edge indicates if they are neighbors. You may want to play around with the filtDist
param until you see edges formed between cells that do indeed appear to be neighbors. It could also be worthwhile to explore the weight matrix output of getSpatialNeighbors
. You'll see that it is a 2D matrix in which the rows and columns are the cell IDs and the values indicate 1 if two cells are neighbors, or 0 if they are not.
Let me know if this doesn't make sense and happy to clarify,
Brendan
Someone else asked a similar question via email, so I will leave my response here as well:
The goal of filterDist
is primarily to remove extraneous neighbor relationships particularly along the edge of the tissue. It may also be useful to remove neighbor relationships between cells that exceed a know interaction distance based on diffusion or other physical processes. If the Euclidean distance between two cells is greater than filterDist
, then they will not be considered neighbors even if their tesslations suggest they are. An example of extraneous neighbor relationships can be seen here:
My recommendation would be to try getSpatialNeighbors
on a small subset of your data via:
# Get neighbor-relationships for subset vi
vi <- mOB$pos[,1] < 15 & mOB$pos[,2] < 15
table(vi)
w <- getSpatialNeighbors(mOB$pos[vi,], filterDist = 2)
plotNetwork(mOB$pos[vi,], w)
If this choice of filterDist
looks reasonable, then you can apply it to the full dataset:
w <- getSpatialNeighbors(mOB$pos, filterDist = 2)
plotNetwork(mOB$pos, w)