stefpeschel / NetCoMi

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

Error in order(y) : unimplemented type 'list' in 'orderVector1' #68

Closed Valentin-Bio-zz closed 1 year ago

Valentin-Bio-zz commented 1 year ago

Hello Stefanie,

I'm trying to plot two nets with different number of OTUs:

adjma_oral_AR <- as.matrix(symBeta(getOptBeta(oral_AR_net)))
adjma_oral_NO <- as.matrix(symBeta(getOptBeta(oral_NO_net)))
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)

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)

On the visualization with plot() What I'm trying to do is to add a different colour to the hubs. Let's say I want hubs coloured in blue and the other nodes coloured in orange for two different networks with unequal numbers of ASVs/OTUs. For that purpose I created a list of two named vectors as follows:

hubs_col_oral_AR <- ifelse(rownames(as.data.frame(tax_table(oral_AR_ps))) %in% 
                             oral_NO_AR_comp$hubs$hubs1, "blue", "orange")
names(hubs_col_oral_AR) <- rownames(tax_table(oral_AR_ps))

hubs_col_oral_NO <- ifelse(rownames(as.data.frame(tax_table(oral_NO_ps))) %in% 
                             oral_NO_AR_comp$hubs$hubs2, "blue", "orange")
names(hubs_col_oral_NO) <- rownames(tax_table(oral_NO_ps))

colhubs_list <- list(hubs_col_oral_AR, hubs_col_oral_NO)

Finally, I run the plot() function adding the colhubs_list named list to the featVecCol argument and I got the following error message:


plot(oral_NO_AR_comp, groupNames = c("Rhinitis asthmatic", "Healthy"), cexNodes = 0.6, 
     cexHubLabels = 2 , cexLabels = 1.8, cexTitle = 3.7, nodeColor = "feature",
     featVecCol = colhubs_list_oral_ARNO, 
     sameColThresh = 3, cexHubs = 1.7, layoutGroup = "union", rmSingles = "inboth", 
     nodeFilter = "highestEigen", nodeFilterPar = 50, repulsion = 2.8, 
     labels =  labs_bh_ARNO_oral,
     layout = "spring") 

Error in order(y) : unimplemented type 'list' in 'orderVector1'

Is It possible to add a named list to the featVecCol argument?

Best,

Valentín.

stefpeschel commented 1 year ago

Hi Valentín,

I think the colorVec argument is what you're looking for.

Here's an example with the amgut data:

library(NetCoMi)
library(phyloseq)

data("amgut2.filt.phy")

# Split the phyloseq object into two groups
amgut_split <- metagMisc::phyloseq_sep_variable(amgut2.filt.phy, 
                                                "SEASONAL_ALLERGIES")

# Network construction
net_season <- netConstruct(data = amgut_split$no, 
                           data2 = amgut_split$yes,  
                           filtTax = "highestVar",
                           filtTaxPar = list(highestVar = 50),
                           measure = "spieceasi",
                           measurePar = list(method = "mb",
                                             pulsar.params = list(rep.num = 10),
                                             symBetaMode = "ave"),
                           normMethod = "none", 
                           zeroMethod = "none",
                           sparsMethod = "none", 
                           dissFunc = "signed",
                           verbose = 3,
                           seed = 123456)

adjma_oral_AR <- net_season$adjaMat1
adjma_oral_NO <- net_season$adjaMat2

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)

hubs_col_oral_AR <- ifelse(rownames(adjma_oral_AR) %in% 
                             oral_NO_AR_comp$hubs$hubs1, "blue", "orange")

names(hubs_col_oral_AR) <- rownames(adjma_oral_AR)

hubs_col_oral_NO <- ifelse(rownames(adjma_oral_NO) %in% 
                             oral_NO_AR_comp$hubs$hubs2, "blue", "orange")

names(hubs_col_oral_NO) <- rownames(adjma_oral_NO)

colhubs_list <- list(hubs_col_oral_AR, hubs_col_oral_NO)

plot(oral_NO_AR_comp,
     groupNames = c("Rhinitis asthmatic", "Healthy"),
     cexNodes = 0.6,
     cexHubLabels = 2 ,
     cexLabels = 1,
     cexTitle = 2,
     nodeColor = "colorVec",
     colorVec = colhubs_list,
     sameColThresh = 3,
     cexHubs = 1.7,
     layoutGroup = "union",
     rmSingles = "inboth",
     nodeFilter = "highestEigen",
     nodeFilterPar = 50,
     repulsion = 1,
     #labels =  labs_bh_ARNO_oral,
     layout = "spring") 

Rplot

Valentin-Bio-zz commented 1 year ago

Hello Stefanie,

sorry for the late response, it worked. thanks a lot!