drieslab / Giotto

Spatial omics analysis toolbox
https://drieslab.github.io/Giotto_website/
Other
240 stars 94 forks source link

spat/exprCellCellcom can return Inf/Inf- values that error plotCCcomDotplot #951

Closed rbutleriii closed 1 month ago

rbutleriii commented 1 month ago

Both spatCellCellcom and exprCellCellcom can produce p.adj values of exactly 0, resulting in PI of Inf and Inf-. These then result in an error for plotCCcomDotplot

Error in stats::hclust(d = corclus_cells_dist, method = aggl_method) :
  NA/NaN/Inf in foreign function call (arg 10)

You can fix it by setting the p.adj to the machine double min to get real values and recalculate PI

# fix error with Inf values
spatial_all_scores[p.adj == 0, p.adj := .Machine$double.xmin]
spatial_all_scores[, PI := log2fc * -log10(p.adj)]
expr_only_scores[p.adj == 0, p.adj := .Machine$double.xmin]
expr_only_scores[, PI := log2fc * -log10(p.adj)]
rbutleriii commented 1 month ago

This turns out to only be an issue if recalculating PI outside of specificCellCellcommunicationScores based on the NA values in #948. The relevant bit of code to add if recalculating log2fc would be:

    # get minimum adjusted p.value that is not zero
    all_p.adj = comScore[['p.adj']]
    lowest_p.adj = min(all_p.adj[all_p.adj != 0])
    comScore[, PI := ifelse(p.adj == 0, log2fc*(-log10(lowest_p.adj)), log2fc*(-log10(p.adj)))]