stefpeschel / NetCoMi

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

hubs not shown when filtering nodes by connectivity in plot() #67

Closed Valentin-Bio-zz closed 1 year ago

Valentin-Bio-zz commented 2 years ago

Hello I dont have clear if I'm doing something wrong but I elaborated a Network analysis with two networks and I constructed the netcomi object from spieceasi adjacency matrices as follows:

oral_NO_AR_net <- netConstruct(data = adjma_oral_AR,
                               data2 = adjma_oral_NO,
                               dataType = "condDependence", normMethod = "none", 
                               sparsMethod = "none", zeroMethod = "none", 
                               verbose = 3, seed = 1234)

After constructing the networks I used netAnalyze() employing 3 metrics for hub calulcaitons:


oral_NO_AR_comp <- netAnalyze(oral_NO_AR_net, centrLCC = FALSE, avDissIgnoreInf = TRUE,
                              clustMethod = "cluster_fast_greedy", 
                              hubPar = c("between","degree","eigenvector"), hubQuant = 0.90,
                              normDeg = TRUE, normBetw = TRUE, normEigen = TRUE)

when I plot all the nodes with plot() function I got the following network:

plot(oral_NO_AR_comp, groupNames = c("Rhinitis asthmatic", "Healthy"), cexNodes = 1.5, 
     cexHubLabels = 3 , cexLabels = 2.5, cexTitle = 3.7, nodeColor = "cluster", 
     sameColThresh = 3, cexHubs = 3.0, layoutGroup = "union", rmSingles = "inboth") 

image

from here I want to display only the most connected nodes around the hubs.For that purpose (and assuming that the hubs are one of the most connected nodes given the degree and betweenness parameters for hub determination). I did the following modification using the nodeFilter argument:

plot(oral_NO_AR_comp, groupNames = c("Rhinitis asthmatic", "Healthy"), cexNodes = 1.5, 
     cexHubLabels = 3 , cexLabels = 2.5, cexTitle = 3.7, nodeColor = "cluster", 
     sameColThresh = 3, cexHubs = 3.0, layoutGroup = "union", rmSingles = "inboth", 
     nodeFilter = "highestConnect", nodeFilterPar = 300)  

But I got the nets without the hubs:

image

To evaluate if the hubs are just not being highlighted as appointed with the cexHubs argument I search for the hub names with oral_NO_AR_comp$hubs and I verified that they are not shown on the nets.

Thanks so much for your time Stefannie, best,

Valentín.

stefpeschel commented 2 years ago

Hey Valentín,

By selecting nodes with highest connectivity, you won't necessarily see nodes that are connected to hubs. In doing so, you select nodes with the highest sum of edge weights.

You could instead try setting nodeFilter to "highestEigen", which should include at least some of your hubs because eigenvector centrality is part of your hub criterion. By setting hubPar = "eigenvector", all hubs would be included in the plot.

Selecting all nodes connected to the hubs is not implemented. You could do this "by hand" by selecting these nodes from the adjacency matrix and setting nodeFilter to "names".

Hope this helps to produce a more readable plot.

Best, Stefanie

Valentin-Bio-zz commented 2 years ago

Hey Stefanie,

Ok so I misunderstood the theory there. Now I changed the filtering criteria to "higuestEigen" and I got my hubs represented on the graphical net, Thanks a lot.

besides that what element of the microNetProps class object controls the displayed node's names on the plot()?

I tried with the oral_NO_AR_comp$lccNames1 in a way that I want to display the genus of the nodes as following:

oral_NO_AR_comp$lccNames1 <- as.data.frame(tax_table(oral_AR_ps))$Genus

But when I run the plot() function, they still have the initial names

stefpeschel commented 2 years ago

If the labels argument is not set, the row/column names of the adjacency matrices are used as node labels. Note that labels must be a named vector (please see the help page).

lccNames gives the names of taxa in the largest connected component but does not affect the labels.

Valentin-Bio-zz commented 1 year ago

Thanks so much Stefanie. I created a list of two named character vectors for my data. (nets have different OTUs/ASVs).

Best,

Valentín.