Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

netAnalysis_signalingRole_heatmap : Heatmap/annotation names are duplicated: Relative strength #170

Closed
jv-20 opened this issue Apr 1, 2021 · 12 comments

Comments

@jv-20
Copy link

jv-20 commented Apr 1, 2021

Hi @sqjin

A quick question. When drawing two heatmaps together based netAnalysis_signalingRole_heatmap function, the relative strength bar - row annotation is the same for two heatmaps.

I run the following code

out=netAnalysis_signalingRole_heatmap(cellchat_ob, signaling = pathway_Q1,pattern="outgoing")
in=netAnalysis_signalingRole_heatmap(cellchat_ob, signaling = pathway_Q1,pattern="incoming")
draw(out+in)

and receive the following error message

Warning message:
Heatmap/annotation names are duplicated: Relative strength 

Example shown below
Picture2

The definition of relative strength here is the row sum of outdegree or indegree connections for a pathway is it?

Could you please advise?

Thanks

@cswoboda
Copy link

cswoboda commented Apr 1, 2021

Hi! Not the creator, but I think I can help. Have you tried not using draw and just typing out + in?

@sqjin this is likely coming from lines 2382-2391 in the analysis.R documentation. I think its some sort of clashing with the draw function where it attempts to call a certain slot for annotation but you've already generated the heatmaps before hand so it merges the values.

The associated warning message is coming from the complexheatmap package. You can see it here: https://github.com/jokergoo/ComplexHeatmap/blob/master/R/HeatmapAnnotation-class.R at lines 957.

Here's the snippet of code:

nm = names(x)

ld = duplicated(nm)
if(any(ld)) {
  dup = unique(nm[ld])
  warning_wrap(paste0("Following annotation names are duplicated:\n  ", paste(dup, collapse = ", ")))
  nm2 = nm
  nm2[unlist(split(seq_along(nm), nm))] = unlist(lapply(split(nm, nm), seq_along))
  l = nm %in% dup
  nm[l] = paste0(nm[l], "_", nm2[l])
  names(x) = nm
}

My guess is your use of draw recalls the HeatmapAnnotation from that package and it throws this bug.

@sqjin
Copy link
Owner

sqjin commented Apr 2, 2021

@jv-20 The row annotation issue is fixed now! The row bar height are the sum of outgoing signaling strength (i.e., communication probabilities) across all cell groups for a pathway. In the outgoing pattern/heatmap, the relative strength (i.e., the color in the heatmap) is the normalized communication probability sending from one cell group via one pathway. We normalize each row so that the maximum value is 1, which produces the so-called relative strength.

You can simply ignore the warning when combing two figures.

@sqjin
Copy link
Owner

sqjin commented Apr 2, 2021

@cswoboda Thanks for the help.

@jv-20
Copy link
Author

jv-20 commented Apr 2, 2021

Hi @sqjin and @cswoboda

Thanks for the replies. The issue is not resolved for me. I re-installed the package and the rowbars for the two heatmaps are still the same.

I tried using out + in without using draw() and still receive the same warning message and the rowbars remains the same between two heatmaps. Please advise.

Thanks

@cswoboda
Copy link

cswoboda commented Apr 2, 2021

Hi @jv-20, sorry that didn't help out! Two things I'd check if I were in your situation to make diagnosing the problem easier, and @sqjin is the expert here so feel free to just wait for their advice. Note, the warning message is as @sqjin was saying probably unrelated to your error so ignore that.

  1. Does the command work normally when not specifying signaling pathways?
  2. Would you generate the pattern = c("all") heatmap and see if that ones look similar to the others?
  3. When you just generate a single heatmap (out as one plot, in as another), does the problem remain the same?

This just lets me know where in the function documentation to look at potential faulty transformations of the data before plotting, or if this is happening directly at the plotting level.

Also @sqjin, just wanted to let you know that in your commit you make the value pSum redundant with your fix. Not sure what checks it was performing, but you can see here it's not called now that you've changed it. May want to revert if it's not solving the issue:

pSum <- rowSums(mat.ori)
 pSum.original <- pSum
 pSum <- -1/log(pSum)
 pSum[is.na(pSum)] <- 0
 idx1 <- which(is.infinite(pSum) | pSum < 0)
 if (length(idx1) > 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)]
 }

 ha1 = rowAnnotation(Strength = anno_barplot(rowSums(mat.ori), border = FALSE), show_annotation_name = FALSE)

@sqjin
Copy link
Owner

sqjin commented Apr 3, 2021

@cswoboda Thanks! You are right. I restore the code now.

@sqjin
Copy link
Owner

sqjin commented Apr 3, 2021

@jv-20 The warning message is fixed now. After careful thinking, the two row annotation bars should be the same. For one pathway, the total outgoing signaling strength across all cell groups should be the same as the total incoming signaling strength.

@jv-20
Copy link
Author

jv-20 commented Apr 6, 2021

Hi @sqjin and @cswoboda ,thanks a lot for your insights and help.

@cswoboda
Does the command work normally when not specifying signaling pathways?
Yes

Would you generate the pattern = c("all") heatmap and see if that ones look similar to the others?
Using "all" within same dataset for out and in looks the same. But looks different when using different datasets. For example (out.dataset1 + out.dataset2)

When you just generate a single heatmap (out as one plot, in as another), does the problem remain the same?
Yes the bars remain the same for out and in within the dataset

@sqjin
Thank you - if the row annotation bars should be the same for incoming and outgoing signaling pattern heatmaps within a dataset, then my issue is solved. However, I still receive the warning message. I suppose I can ignore them?

Thanks again for your kind help and replies. Much appreciated

@jv-20
Copy link
Author

jv-20 commented Apr 6, 2021

Hi @sqjin,

Just another question. Is there a function to cluster a list of pathways of interest based on network centrality measures (outdegree,indegree,meadiators and influencers)?

When I try to use the cluser.rows=T parameter with netAnalysis_signalingRole_heatmap(cellchat_ob, signaling = pathway_Q1, ,pattern="outgoing",cluster.rows = T) I receive the following error.


Error in hclust(get_dist(submat, distance), method = method) : 
  NA/NaN/Inf in foreign function call (arg 10)

Would you have some insights? Thank you

@sqjin
Copy link
Owner

sqjin commented Apr 6, 2021

@jv-20 There is no function available in CellChat. But you can extract the data and use the Heatmap function to plot and cluster the signaling pathways.

@jv-20
Copy link
Author

jv-20 commented Apr 14, 2021

Thanks @sqjin

@jv-20 jv-20 closed this as completed Apr 14, 2021
@yaolutian
Copy link

Hi @jv-20, sorry that didn't help out! Two things I'd check if I were in your situation to make diagnosing the problem easier, and @sqjin is the expert here so feel free to just wait for their advice. Note, the warning message is as @sqjin was saying probably unrelated to your error so ignore that.

  1. Does the command work normally when not specifying signaling pathways?
  2. Would you generate the pattern = c("all") heatmap and see if that ones look similar to the others?
  3. When you just generate a single heatmap (out as one plot, in as another), does the problem remain the same?

This just lets me know where in the function documentation to look at potential faulty transformations of the data before plotting, or if this is happening directly at the plotting level.

Also @sqjin, just wanted to let you know that in your commit you make the value pSum redundant with your fix. Not sure what checks it was performing, but you can see here it's not called now that you've changed it. May want to revert if it's not solving the issue:

pSum <- rowSums(mat.ori)
 pSum.original <- pSum
 pSum <- -1/log(pSum)
 pSum[is.na(pSum)] <- 0
 idx1 <- which(is.infinite(pSum) | pSum < 0)
 if (length(idx1) > 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)]
 }

 ha1 = rowAnnotation(Strength = anno_barplot(rowSums(mat.ori), border = FALSE), show_annotation_name = FALSE)

Hi, thanks for your explanation, I am wondering if you can further explain the pSum here, does it reflect the sum of all signals for one pathway, in my practice, I got ~1500 for the max pSum number for one condition, while other condition is about 80, I cannot figure out the calculation here. Thanks for your help, much appreciated.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants