This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Cellchat rankNet information flow

Does anyone know why the following code is here in the cellchat rankNet function (lines 1070-1081 of analysis.R)? I'm trying to understand the "information flow" shown on the rankNet chart when in pathway-level 'weight' mode, but the resulting value on the bar chart seems to be generated by this code with no explanation for why it is taking -1/log(pSum), which only returns positive values for 0 < pSum < 1, or why the negative results are replaced with values from 1.1*max to 1.5*max -- doesn't this mean that the resulting value can't be interpeted as the 'actual' information flow for the pathway? as in, reading the x axis will be invalid when pSum was greater than 1? Let me know if I am understanding something incorrectly.

if (measure == "weight") {
  pSum <- -1/log(pSum)
  pSum[is.na(pSum)] <- 0
  idx1 <- which(is.infinite(pSum) | pSum < 0)
  values.assign <- seq(max(pSum)*1.1, max(pSum)*1.5, length.out = length(idx1))
  position <- sort(pSum.original[idx1], index.return = TRUE)$ix
  pSum[idx1] <- values.assign[match(1:length(idx1), position)]
} else if (measure == "count") {
  pSum <- pSum.original
}
cellchat single cell

IMO (I have never used this tool)

The negative reciprocal log transformation (-1/log(pSum)) is being used to convert pSum (0 < pSum < 1)to weights. Because of the reciprocal, a higher probability gets a higher weight and vice versa. After transformation, 'NA' values are replaced by 0, and edge cases where pSum_log is infinite or negative (input pSum >= 1) are replaced by values between max(pSum)*1.1 and max(pSum)*1.5.

Thank you for responding even though you haven't used the tool before. I understand what you're saying, although I can't find any biological or statistical reason why cellchat does this, maybe someone else knows. It's only for visualization so there is no downstream effect, but it still seems strange to make the visuals so unrepresentative of the underlying data. According to the documentation the argument 'show.raw' turns off this scaling, and it says "Default = FALSE, showing the scaled information flow to provide compariable data scale" While it does scale down large values (p > 1) I'm not sure why it uses this method.

In -1/log(x) values increase asymptotically as x increases towards 1. Why should values less than, but close to 1, be exaggerated?

f(0.9) ~ 21.9, f(0.95) ~ 44.9

This could make sense to me if values were bounded to be less than 1, but this is not the case at all. Values input to the function can be greater than 1, and in my experience, these values are greater than 1 for pathways with high communication. This means that

f(0.9) ~ 21.9, f(0.95) ~ 44.9, f(1.01) ~ 1.1*44.9, f(15) ~ 1.5*44.9

assuming that 44.9 is the maximum. So the difference between 0.9 and 0.95 appears like a 2x increase, but the difference between 0.95 and 15 appears like a 1.5x increase.

I can see the use for visually compressing large values to make smaller details easier to visualize, however this method causes dramatic visual changes depending on the largest value less than 1. For example, if f(0.95) wasn't present in the data (but the other three points were) than the visual difference becomes:

f(0.9) ~ 21.9, f(1.01) ~ 1.1*21.9, f(15) ~ 1.5*21.9

since 21.9 is the new maximum. What was previously a ~3x increase ( f(0.9) ~ 21.9 compared to f(15) ~ 1.5*44.9 ~ 67 ) is now only a 1.5x increase ( f(0.9) ~ 21.9 compared to f(15) ~ 1.5*21.9 ) for the exact same pair of values, because pSum values greater than 1 depend on the maximum for pSum values less than 1, and those maximum values change wildly because of the asymptotic behavior approaching 1. The example I gave was relatively tame compared to the potential impact of values even closer to 1 (0.98, 0.99).

Again, while the score is called a 'probability' in cellchat, the sum of these values isn't necessarily less than 1. In my case there were values greater than 1:

MHC-I 13.809914 MHC-II 10.707000 APP 5.716628 COLLAGEN 4.328560 ADGRE 2.661693 CD45 2.537294 ICAM 2.390399 VCAM 1.678024 THBS 1.381773 SEMA4 1.381360 IL16 0.956840 CLEC 0.915074 GALECTIN 0.904351 CD52 0.814971 COMPLEMENT 0.710253 SELPLG 0.505181 THY1 0.480900 CXCL 0.474584 FN1 0.405102 LCK 0.307677

0 answers

No answers yet.

Log in to answer this question.