stefpeschel / NetCoMi

Network construction, analysis, and comparison for microbial compositional data
GNU General Public License v3.0
150 stars 27 forks source link

Issue with node size and netCompare #124

Open alexmsalmeida opened 4 months ago

alexmsalmeida commented 4 months ago

Hi,

Thanks for developing NetComi, it's been a great tool for our work. However, I have been having a couple of issues I was hoping you might be able to help.

1) When plotting two networks side by side, using "degree" as node size, some nodes that seem to simply have one connection are plotted much larger than others with single connections (see attached figure with some of the nodes in question highlighted in red). netcomi_networks

I am currently plotting the network as follows:

plot(network.obj, sameLayout = TRUE, layoutGroup = "union", rmSingles = "inboth", groupNames = c("",""), negDiffCol = FALSE, 
     edgeWidth=10, cut=0, edgeTranspLow=0, edgeFilter = "none",
     nodeColor = "darkgreen", nodeSize = "degree", posCol = "darkgrey", labels = FALSE, highlightHubs = FALSE, cexNodes = 1.5, hubBorderCol  = "gray40")

2) When running netCompare() on these same two networks I am getting an error related with number of rows:

> netCompare(network.obj)
Checking input arguments ... Done.
Error in h(simpleError(msg, call)) : 
  error in evaluating the argument 'x' in selecting a method for function 'nrow': all arguments must have the same length

Any help in making sense of this would be greatly appreciated.

Alex

stefpeschel commented 4 months ago

Hi Alex,

Could you please provide me with the complete code you used for network construction? The arguments passed to netConstruct() and netAnalyze() might help to solve the problems. From the output of netCompare() I cannot tell where exactly the error occurred because nrow() is called quite often within the function. I can try to reproduce the error if you send me your code.

As for the node sizes: I could imagine that the degree values are normalized. Then the values for two nodes with the same number of edges might be different between networks.

alexmsalmeida commented 4 months ago

Hi,

Thanks for the quick reply. I did a bit of digging and realized that both issues were related with the fact I had some taxa in network2 missing from network1. Once I filtered those everything looks ok now.

One last issue that I encountered though after plotting the diffnet() results from this is that I am getting most of the edges with a dark blue colour (not cyan). The legend does not include this colour in the descriptor. Any idea on how to interpret this?

stefpeschel commented 3 months ago

Glad to hear that you could solve the other issues.

In diffnet, the colors depend on the method used and on whether or not the correlation matrix contains any zeros. The blue colors correspond to the case "cor1=0, cor2>0", but only if there are correlations equal to zero. However, the legend should always include all colors used in the network plot. Could you please post the diffnet code? Maybe I can reproduce the issue.

alexmsalmeida commented 3 months ago

Ah that makes sense then. I do have quite a few more correlations in cor2 compared to cor1. This is the code I am using:

# construct networks
net.construct = netConstruct(data = as.matrix(entero_no), data2 = as.matrix(entero_yes),
                          dataType = "correlation", sparsMethod = "none", seed = 1234)

# identify differentially associated taxa
diff.res = diffnet(x=net.construct, diffMethod="fisherTest", adjust = "lfdr", n1=1960, n2=3145)

Thanks for the help!

stefpeschel commented 1 month ago

If you reproduce the attached example, is the dark blue color then included in the legend? 2024-08_issue124_diffnet.pdf