Skip to content

Zero value in the computeRegionDistance #466

Description

@JinAshley

computeCommunProb fails for Xenium spatial data because computeRegionDistance returns zero group-level distances

Hi CellChat team,

I am running CellChat on Xenium single-cell spatial transcriptomics data. Xenium coordinates are already in microns, so I set ratio = 1. Following the guidance for single-cell spatial data, I tested small tol values and also tried tol = min center-to-center distance / 2.

However, computeCommunProb() fails when distance.use = TRUE because the internal group-level spatial distance matrix returned by computeRegionDistance() contains many zero values.

Data setup

I create the CellChat object from a normalized expression matrix:

cellchat <- createCellChat(
  object = data.input,
  meta = meta,
  group.by = "labels",
  datatype = "spatial",
  coordinates = spatial.locs,
  spatial.factors = spatial.factors
)

spatial.factors <- data.frame(
  ratio = 1,
  tol = 0.04
)

min(d.spatial[d.spatial != 0])
# 0.08259252

cellchat <- computeCommunProb(
  cellchat,
  type = "truncatedMean",
  trim = 0.1,
  distance.use = TRUE,
  interaction.range = 100,
  scale.distance = 1,
  contact.dependent = TRUE,
  contact.range = 10
)
### 
I get a error when run the computeCommuProb:
The suggested minimum value of scaled distances is in [1,2],
and the calculated value here is 0

Error:
Please increase the value of `scale.distance` and use a value that is slighly smaller than Inf



I wrapped computeRegionDistance() to inspect its output. It returns a list:
names(last_region_distance)
# "d.spatial" "adj.contact"
The returned d.spatial is group-level, not cell-level:
dim(last_region_distance$d.spatial)
# 9 9
The matrix contains many zeros:
Number of zero values: 71
So the failure appears to come from the zero values in the group-level d.spatial matrix being included in the minimum scaled-distance check. But I have checked that there would be no overlapping cell centroid coordinates,
Question
For Xenium/single-cell spatial data, what is the recommended way to handle zero values in the group-level d.spatial matrix returned by computeRegionDistance()?
Should off-diagonal zero values be interpreted as:
true spatial overlap / extremely close groups,
no valid/proximal group-level distance after filtering,
same-group/self-distance behavior,
or something else?
Would it be appropriate for CellChat to ignore diagonal zeros and/or ignore zero values when checking the minimum scaled distance?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions