Skip to contents

Introduction

COmplex Network Description Of Regulators (CONDOR) implements methods for clustering bipartite networks and estimating the contribution of each node to its community’s modularity. For an application of this method to identify diesease-associated single nucleotide polymorphisms, see (https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1005033).

Installation

CONDOR can be installed through netZooR as follows:

if(!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install("netZooR")

Implementing the Bipartite Modularity Maximization

The code in condorModularityMax is an implementation of the method described in Michael Barber’s paper Modularity and community detection in bipartite networks (Phys. Rev. E 76, 066102 (2007)). A few general comments:

Workflow

condor works with an edgelist (elist in the code below) as its input.

r = c(1,1,1,2,2,2,3,3,3,4,4);
b = c(1,2,3,1,2,4,2,3,4,3,4);
reds <- c("Alice","Sue","Janine","Mary")
blues <- c("Bob","John","Ed","Hank")
elist <- data.frame(red=reds[r], blue=blues[b])

In elist, notice all nodes of the same type–women and men in this case–appear in the same column together. This is a requirement. createCondorObject will throw an error if a node appears in both columns.

condor.object <- createCondorObject(elist)

A condor.object is just a list. You can look at the different items using names

names(condor.object)
## [1] "G"          "edges"      "Qcoms"      "modularity" "red.memb"  
## [6] "blue.memb"  "qscores"

condorCluster will cluster the nodes and produce the overall modularity along with two community membership data.frames:

condor.object <- condorCluster(condor.object)
## [1] "modularity of projected graph 0"
## [1] "Q = 0"
## [1] "Q = 0.198347107438017"
## [1] "Q = 0.231404958677686"
## [1] "Q = 0.231404958677686"
print(condor.object$red.memb)
##   red.names com
## 1     Alice   1
## 2    Janine   2
## 3      Mary   2
## 4       Sue   1
print(condor.object$blue.memb)
##   blue.names com
## 1        Bob   1
## 2         Ed   2
## 3       Hank   2
## 4       John   1

Nodes in first community are {Alice, John, Bob, Sue}, nodes in second community are {Ed, Janine, Hank, Mary} based on the modularity maximization. Here’s a picture:

gtoy = graph.edgelist(as.matrix(elist),directed=FALSE)
set.graph.attribute(gtoy, "layout", layout.kamada.kawai(gtoy))
## IGRAPH 5a9c5ad UN-- 8 11 -- 
## + attr: layout (g/n), name (v/c)
## + edges from 5a9c5ad (vertex names):
##  [1] Alice--Bob    Alice--John   Alice--Ed     Bob  --Sue    John --Sue   
##  [6] Sue  --Hank   John --Janine Ed   --Janine Hank --Janine Ed   --Mary  
## [11] Hank --Mary
V(gtoy)[c(reds,blues)]$color <- c(rep("red",4),rep("blue",4))
plot(gtoy,vertex.label.dist=2)

To get each node’s modularity contribution (as a fraction of the community’s modularity), run

condor.object <- condorQscore(condor.object)

If you have a subset of nodes that you think are more likely to lie at the cores of your communities, you can test this using condorCoreEnrich:

q_women <- condor.object$qscores$red.qscore
core_stats <- condorCoreEnrich(test_nodes=c("Alice","Mary"),
                                 q=q_women,perm=TRUE,plot.hist=TRUE)

condor also works on weighted bipartite networks. The package comes with a quantitative pollination network data set (Small 1976) taken from the NCEAS interaction webs data base, containing interactions between 13 plants and 34 pollinators.

data(small1976)
condor.object <- createCondorObject(small1976)
condor.object <- condorCluster(condor.object, project=FALSE)
## [1] "modularity of projected graph 0.525346928655047"
## [1] "Q = 0.52666696475026"
## [1] "Q = 0.52666696475026"
condorPlotHeatmap(condor.object)

Session Information

## R version 4.3.2 (2023-10-31)
## Platform: aarch64-apple-darwin20 (64-bit)
## Running under: macOS Sonoma 14.1.2
## 
## Matrix products: default
## BLAS:   /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRblas.0.dylib 
## LAPACK: /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib;  LAPACK version 3.11.0
## 
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
## 
## time zone: America/New_York
## tzcode source: internal
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] netZooR_1.5.17      matrixcalc_1.0-6    pandaR_1.34.0      
## [4] Biobase_2.62.0      BiocGenerics_0.48.1 reticulate_1.35.0  
## [7] igraph_2.0.3       
## 
## loaded via a namespace (and not attached):
##   [1] STRINGdb_2.14.3             fs_1.6.3                   
##   [3] matrixStats_1.2.0           bitops_1.0-7               
##   [5] httr_1.4.7                  RColorBrewer_1.1-3         
##   [7] doParallel_1.0.17           Rgraphviz_2.46.0           
##   [9] repr_1.1.7                  tools_4.3.2                
##  [11] doRNG_1.8.6                 backports_1.4.1            
##  [13] utf8_1.2.4                  R6_2.5.1                   
##  [15] vegan_2.6-4                 HDF5Array_1.30.1           
##  [17] mgcv_1.9-1                  rhdf5filters_1.14.1        
##  [19] permute_0.9-7               prettyunits_1.2.0          
##  [21] base64_2.0.1                preprocessCore_1.64.0      
##  [23] cli_3.6.2                   textshaping_0.3.7          
##  [25] penalized_0.9-52            sass_0.4.9                 
##  [27] readr_2.1.5                 genefilter_1.84.0          
##  [29] askpass_1.2.0               pkgdown_2.0.7              
##  [31] Rsamtools_2.18.0            systemfonts_1.0.6          
##  [33] pbdZMQ_0.3-11               siggenes_1.76.0            
##  [35] illuminaio_0.44.0           AnnotationForge_1.44.0     
##  [37] scrime_1.3.5                plotrix_3.8-4              
##  [39] limma_3.58.1                rstudioapi_0.16.0          
##  [41] RSQLite_2.3.5               generics_0.1.3             
##  [43] GOstats_2.68.0              quantro_1.36.0             
##  [45] BiocIO_1.12.0               gtools_3.9.5               
##  [47] distributional_0.4.0        dplyr_1.1.4                
##  [49] GO.db_3.18.0                Matrix_1.6-5               
##  [51] fansi_1.0.6                 S4Vectors_0.40.2           
##  [53] abind_1.4-5                 lifecycle_1.0.4            
##  [55] yaml_2.3.8                  edgeR_4.0.16               
##  [57] SummarizedExperiment_1.32.0 gplots_3.1.3.1             
##  [59] rhdf5_2.46.1                SparseArray_1.2.4          
##  [61] BiocFileCache_2.10.1        grid_4.3.2                 
##  [63] blob_1.2.4                  crayon_1.5.2               
##  [65] lattice_0.22-6              GenomicFeatures_1.54.4     
##  [67] annotate_1.80.0             KEGGREST_1.42.0            
##  [69] pillar_1.9.0                knitr_1.45                 
##  [71] beanplot_1.3.1              GenomicRanges_1.54.1       
##  [73] rjson_0.2.21                codetools_0.2-19           
##  [75] glue_1.7.0                  downloader_0.4             
##  [77] data.table_1.15.2           vctrs_0.6.5                
##  [79] png_0.1-8                   gtable_0.3.4               
##  [81] assertthat_0.2.1            gsubfn_0.7                 
##  [83] cachem_1.0.8                xfun_0.42                  
##  [85] S4Arrays_1.2.1              survival_3.5-8             
##  [87] iterators_1.0.14            statmod_1.5.0              
##  [89] nlme_3.1-164                Category_2.68.0            
##  [91] bit64_4.0.5                 progress_1.2.3             
##  [93] filelock_1.0.3              GenomeInfoDb_1.38.8        
##  [95] tensorA_0.36.2.1            bslib_0.6.2                
##  [97] nor1mix_1.3-2               KernSmooth_2.23-22         
##  [99] colorspace_2.1-0            DBI_1.2.2                  
## [101] nnet_7.3-19                 processx_3.8.4             
## [103] tidyselect_1.2.1            bit_4.0.5                  
## [105] compiler_4.3.2              curl_5.2.1                 
## [107] chron_2.3-61                graph_1.80.0               
## [109] xml2_1.3.6                  desc_1.4.3                 
## [111] ggdendro_0.2.0              DelayedArray_0.28.0        
## [113] posterior_1.5.0             rtracklayer_1.62.0         
## [115] checkmate_2.3.1             scales_1.3.0               
## [117] caTools_1.18.2              hexbin_1.28.3              
## [119] quadprog_1.5-8              RBGL_1.78.0                
## [121] rappdirs_0.3.3              stringr_1.5.1              
## [123] digest_0.6.35               rmarkdown_2.26             
## [125] GEOquery_2.70.0             XVector_0.42.0             
## [127] htmltools_0.5.7             pkgconfig_2.0.3            
## [129] base64enc_0.1-3             sparseMatrixStats_1.14.0   
## [131] MatrixGenerics_1.14.0       highr_0.10                 
## [133] dbplyr_2.5.0                fastmap_1.1.1              
## [135] rlang_1.1.3                 DelayedMatrixStats_1.24.0  
## [137] jquerylib_0.1.4             jsonlite_1.8.8             
## [139] BiocParallel_1.36.0         mclust_6.1                 
## [141] RCurl_1.98-1.14             magrittr_2.0.3             
## [143] GenomeInfoDbData_1.2.11     Rhdf5lib_1.24.2            
## [145] IRkernel_1.3.2              munsell_0.5.0              
## [147] Rcpp_1.0.12                 proto_1.0.0                
## [149] sqldf_0.4-11                stringi_1.8.3              
## [151] RJSONIO_1.3-1.9             zlibbioc_1.48.2            
## [153] MASS_7.3-60.0.1             plyr_1.8.9                 
## [155] org.Hs.eg.db_3.18.0         bumphunter_1.44.0          
## [157] minfi_1.48.0                parallel_4.3.2             
## [159] Biostrings_2.70.3           IRdisplay_1.1              
## [161] splines_4.3.2               multtest_2.58.0            
## [163] hash_2.2.6.3                hms_1.1.3                  
## [165] locfit_1.5-9.9              ps_1.7.6                   
## [167] uuid_1.2-0                  RUnit_0.4.33               
## [169] base64url_1.4               rngtools_1.5.2             
## [171] reshape2_1.4.4              biomaRt_2.58.2             
## [173] stats4_4.3.2                XML_3.99-0.16.1            
## [175] evaluate_0.23               tzdb_0.4.0                 
## [177] foreach_1.5.2               tidyr_1.3.1                
## [179] openssl_2.1.1               purrr_1.0.2                
## [181] reshape_0.8.9               ggplot2_3.5.0              
## [183] xtable_1.8-4                restfulr_0.0.15            
## [185] viridisLite_0.4.2           ragg_1.3.0                 
## [187] RCy3_2.23.2                 tibble_3.2.1               
## [189] memoise_2.0.1               AnnotationDbi_1.64.1       
## [191] GenomicAlignments_1.38.2    IRanges_2.36.0             
## [193] cluster_2.1.6               cmdstanr_0.6.1.9000        
## [195] GSEABase_1.64.0