### Install NetCoMi from GitHub Source: https://netcomi.de/index.html Use this command to install the latest stable version of NetCoMi from GitHub. Ensure you have devtools installed. ```r devtools::install_github("stefpeschel/NetCoMi", repos = c("https://cloud.r-project.org/", BiocManager::repositories())) ``` -------------------------------- ### Install NetCoMi and Dependencies Source: https://netcomi.de/readme.html Installs required packages like devtools and BiocManager, followed by GitHub-installed dependencies (SpiecEasi, SPRING) and then NetCoMi itself. Ensure these dependencies are installed first for a smooth NetCoMi installation. ```r install.packages("devtools") install.packages("BiocManager") devtools::install_github("zdk123/SpiecEasi") devtools::install_github("GraceYoon/SPRING") devtools::install_github("stefpeschel/NetCoMi", repos = c("https://cloud.r-project.org/", BiocManager::repositories())) ``` -------------------------------- ### Accessing testGCM examples Source: https://netcomi.de/reference/testGCM.html Reference to the calcGCD help page for further examples. ```R # See help page of calcGCD() ?calcGCD ``` -------------------------------- ### NetCoMi Package Navigation Source: https://netcomi.de/reference/netcompare This section outlines the navigation structure for the NetCoMi package documentation, including 'Get started', 'Reference', and 'Articles'. ```markdown * Get started * Reference * Articles * Changelog ``` -------------------------------- ### Construct and Analyze Network Source: https://netcomi.de/reference/calcgcm Example workflow demonstrating network construction using SpiecEasi data and subsequent visualization. ```R # Load data set from American Gut Project (from SpiecEasi package) data("amgut1.filt") # Network construction net <- netConstruct(amgut1.filt, filtTax = "highestFreq", filtTaxPar = list(highestFreq = 50), measure = "pearson", normMethod = "clr", zeroMethod = "pseudoZO", sparsMethod = "thresh", thresh = 0.5) #> Checking input arguments ... #> Done. #> Data filtering ... #> 77 taxa removed. #> 50 taxa and 289 samples remaining. #> #> Zero treatment: #> Zero counts replaced by 1 #> #> Normalization: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Calculate 'pearson' associations ... #> Done. #> #> Sparsify associations via 'threshold' ... #> Done. # Get adjacency matrices adja <- net$adjaMat1 # Network visualization props <- netAnalyze(net) plot(props, rmSingles = TRUE, cexLabels = 1.7) ``` -------------------------------- ### Install NetCoMi dependencies Source: https://netcomi.de/index.html Install required packages from CRAN and GitHub to prepare the environment for NetCoMi. ```R # Required packages install.packages("devtools") install.packages("BiocManager") # Since two of NetCoMi's dependencies are only available on GitHub, # it is recommended to install them first: devtools::install_github("zdk123/SpiecEasi") devtools::install_github("GraceYoon/SPRING") ``` -------------------------------- ### Construct and Analyze Networks for GCD Source: https://netcomi.de/reference/calcGCD.html Example workflow demonstrating data preparation, network construction using netConstruct, and visualization using netAnalyze. ```R library(phyloseq) # Load data sets from American Gut Project (from SpiecEasi package) data("amgut2.filt.phy") # Split data into two groups: with and without seasonal allergies amgut_season_yes <- phyloseq::subset_samples(amgut2.filt.phy, SEASONAL_ALLERGIES == "yes") amgut_season_no <- phyloseq::subset_samples(amgut2.filt.phy, SEASONAL_ALLERGIES == "no") # Make sample sizes equal to ensure comparability n_yes <- phyloseq::nsamples(amgut_season_yes) ids_yes <- phyloseq::get_variable(amgut_season_no, "X.SampleID")[1:n_yes] amgut_season_no <- phyloseq::subset_samples(amgut_season_no, X.SampleID %in% ids_yes) # Network construction net <- netConstruct(amgut_season_yes, amgut_season_no, filtTax = "highestFreq", filtTaxPar = list(highestFreq = 50), measure = "pearson", normMethod = "clr", zeroMethod = "pseudoZO", sparsMethod = "thresh", thresh = 0.5) # Get adjacency matrices adja1 <- net$adjaMat1 adja2 <- net$adjaMat2 # Network visualization props <- netAnalyze(net) plot(props, rmSingles = TRUE, cexLabels = 1.7) ``` -------------------------------- ### Examples - Network Construction and Analysis Source: https://netcomi.de/reference/plotHeat.html Provides R code examples for constructing networks and analyzing graphlet correlation matrices using the Netcomi.de project data. ```APIDOC ## Examples __``` # Load data sets from American Gut Project (from SpiecEasi package) data("amgut2.filt.phy") # Split data into two groups: with and without seasonal allergies amgut_season_yes <- phyloseq::subset_samples(amgut2.filt.phy, SEASONAL_ALLERGIES == "yes") amgut_season_no <- phyloseq::subset_samples(amgut2.filt.phy, SEASONAL_ALLERGIES == "no") # Sample sizes phyloseq::nsamples(amgut_season_yes) #> [1] 121 phyloseq::nsamples(amgut_season_no) #> [1] 163 # Make sample sizes equal to ensure comparability n_yes <- phyloseq::nsamples(amgut_season_yes) amgut_season_no <- phyloseq::subset_samples(amgut_season_no, X.SampleID %in% get_variable(amgut_season_no, "X.SampleID")[1:n_yes]) #> Error in h(simpleError(msg, call)): error in evaluating the argument 'table' in selecting a method for function '%in%': error in evaluating the argument 'object' in selecting a method for function 'sample_data': object 'amgut_season_no' not found # Network construction amgut_net <- netConstruct(data = amgut_season_yes, data2 = amgut_season_no, measure = "pearson", filtTax = "highestVar", filtTaxPar = list(highestVar = 50), zeroMethod = "pseudoZO", normMethod = "clr", sparsMethod = "thresh", thresh = 0.4, seed = 123456) #> Checking input arguments ... #> Done. #> Data filtering ... #> 95 taxa removed in each data set. #> 1 rows with zero sum removed in group 1. #> 1 rows with zero sum removed in group 2. #> 43 taxa and 120 samples remaining in group 1. #> 43 taxa and 162 samples remaining in group 2. #> #> Zero treatment in group 1: #> Zero counts replaced by 1 #> #> Zero treatment in group 2: #> Zero counts replaced by 1 #> #> Normalization in group 1: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Normalization in group 2: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Calculate 'pearson' associations ... #> Done. #> #> Calculate associations in group 2 ... #> Done. #> #> Sparsify associations via 'threshold' ... #> Done. #> #> Sparsify associations in group 2 ... #> Done. # Estimated and sparsified associations of group 1 plotHeat(amgut_net$assoEst1, textUpp = "none", labCex = 0.6) plotHeat(amgut_net$assoMat1, textUpp = "none", labCex = 0.6) # Compute graphlet correlation matrices and perform significance tests adja1 <- amgut_net$adjaMat1 adja2 <- amgut_net$adjaMat2 gcm1 <- calcGCM(adja1) gcm2 <- calcGCM(adja2) gcmtest <- testGCM(obj1 = gcm1, obj2 = gcm2) #> Perform Student's t-test for GCM1 ... #> Adjust for multiple testing ... #> #> Proportion of true null hypotheses: 0.22 #> Done. #> #> Perform Student's t-test for GCM2 ... #> Adjust for multiple testing ... #> #> Proportion of true null hypotheses: 0.08 #> Done. #> #> Test GCM1 and GCM2 for differences ... #> Adjust for multiple testing ... #> #> Proportion of true null hypotheses: 0.64 #> Done. # Mixed heatmap of GCM1 and significance codes plotHeat(mat = gcmtest$gcm1, pmat = gcmtest$pAdjust1, type = "mixed", textLow = "code") # Mixed heatmap of GCM2 and p-values (diagonal disabled) plotHeat(mat = gcmtest$gcm1, pmat = gcmtest$pAdjust1, diag = FALSE, type = "mixed", textLow = "pmat") # Mixed heatmap of differences (GCM1 - GCM2) and significance codes plotHeat(mat = gcmtest$diff, pmat = gcmtest$pAdjustDiff, type = "mixed", textLow = "code", title = "Differences between GCMs (GCM1 - GCM2)", mar = c(0, 0, 2, 0)) # Heatmap of differences (insignificant values are blank) plotHeat(mat = gcmtest$diff, pmat = gcmtest$pAdjustDiff, type = "full", textUpp = "sigmat") # Same as before but with higher significance level plotHeat(mat = gcmtest$diff, pmat = gcmtest$pAdjustDiff, type = "full", textUpp = "sigmat", argsUpp = list(sig.level = 0.1)) # Heatmap of absolute differences # (different position of labels and legend) plotHeat(mat = gcmtest$absDiff, type = "full", labPos = "d", legendPos = "b") # Mixed heatmap of absolute differences ``` ``` -------------------------------- ### Install NetCoMi Optional Packages Source: https://netcomi.de/reference/installnetcomipacks This function installs R packages used in NetCoMi that are not listed as dependencies. It uses `BiocManager::install` for installation and can optionally install only missing packages. ```APIDOC ## Function: installNetCoMiPacks ### Description Installs R packages used in NetCoMi that are not listed as dependencies or imports in NetCoMi's description file. These are optional packages needed for specific network construction settings. ### Usage ``` installNetCoMiPacks(onlyMissing = TRUE, lib = NULL, ...) ``` ### Arguments #### `onlyMissing` (logical) - Default: `TRUE` - If `TRUE`, checks installed packages and installs only those that are missing. If `FALSE`, all packages are installed or updated. #### `lib` (character vector) - Default: `NULL` - Specifies library directories for installing missing packages. If `NULL`, the first element of `.libPaths` is used. #### `...` (additional arguments) - Additional arguments passed to `install` or `install.packages`. ``` -------------------------------- ### Load NetCoMi and phyloseq Libraries Source: https://netcomi.de/articles/plot_modifications.html Load the necessary libraries for network construction and analysis. Ensure these libraries are installed before running. ```R library(NetCoMi) library(phyloseq) ``` -------------------------------- ### Value and Examples Source: https://netcomi.de/reference/renameTaxa.html Describes the return value and provides usage examples for taxonomy table manipulation. ```APIDOC ## Value Renamed taxonomy table (matrix or phyloseq object, depending on the input). ## Examples __``` #--- Load and edit data ----------------------------------------------------- library(phyloseq) data("GlobalPatterns") global <- subset_taxa(GlobalPatterns, Kingdom == "Bacteria") taxtab <- global@tax_table@.Data[1:10, ] # Add some unclassified taxa taxtab[c(2,3,5), "Species"] <- "unclassified" taxtab[c(2,3), "Genus"] <- "unclassified" taxtab[2, "Family"] <- "unclassified" # Add some blanks taxtab[7, "Genus"] <- " " taxtab[7:9, "Species"] <- " " # Add taxon that is unclassified up to Kingdom taxtab[9, ] <- "unclassified" taxtab[9, 1] <- "Unclassified" ``` ``` -------------------------------- ### Install NetCoMi Development Version Source: https://netcomi.de/readme.html Installs the latest development version of NetCoMi from GitHub, allowing access to new features not yet included in stable releases. This requires specifying the 'develop' branch. ```r devtools::install_github("stefpeschel/NetCoMi", ref = "develop", repos = c("https://cloud.r-project.org/", BiocManager::repositories())) ``` -------------------------------- ### Network Construction Example Source: https://netcomi.de/reference/calcGCM.html Constructs a network from filtered data using specified methods for filtering, correlation, normalization, and sparsification. This example uses data from the American Gut Project. ```R # Load data set from American Gut Project (from SpiecEasi package) data("amgut1.filt") # Network construction net <- netConstruct(amgut1.filt, filtTax = "highestFreq", filtTaxPar = list(highestFreq = 50), measure = "pearson", normMethod = "clr", zeroMethod = "pseudoZO", sparsMethod = "thresh", thresh = 0.5) #> Checking input arguments ... #> Done. #> Data filtering ... #> 77 taxa removed. #> 50 taxa and 289 samples remaining. #> #> Zero treatment: #> Zero counts replaced by 1 #> #> Normalization: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Calculate 'pearson' associations ... #> Done. #> #> Sparsify associations via 'threshold' ... #> Done. ``` -------------------------------- ### Install NetCoMi via Bioconda Source: https://netcomi.de/readme.html Installs NetCoMi using the conda package manager from the bioconda channel. It's recommended to create and activate a dedicated environment for NetCoMi before installation. ```bash # You can install an individual environment firstly with # conda create -n NetCoMi # conda activate NetCoMi conda install -c bioconda -c conda-forge r-netcomi ``` -------------------------------- ### Install NetCoMi Packages Source: https://netcomi.de/reference/installnetcomipacks Installs R packages used by NetCoMi that are not listed as dependencies. Use this function to ensure all optional packages for specific network construction settings are available. By default, it only installs missing packages. ```R installNetCoMiPacks(onlyMissing = TRUE, lib = NULL, ...) ``` -------------------------------- ### Load NetCoMi Package Source: https://netcomi.de/articles/asso_as_input.html Loads the NetCoMi R package. Ensure this package is installed before running. ```r library(NetCoMi) ``` -------------------------------- ### Examples of colToTransp Source: https://netcomi.de/reference/coltotransp Demonstrates applying transparency to various color formats and using the output in barplots. ```R # Excepts hexadecimal strings, written colors, or numbers as input colToTransp("#FF0000FF", 50) #> [1] "#FF00007F" colToTransp("black", 50) #> [1] "#0000007F" colToTransp(2) #> [1] "#DF536B7F" # Different shades of red r80 <- colToTransp("red", 80) r50 <- colToTransp("red", 50) r20 <- colToTransp("red", 20) barplot(rep(5, 4), col=c("red", r20, r50, r80), names.arg = 1:4) # Vector as input rain_transp <- colToTransp(rainbow(5), 50) barplot(rep(5, 5), col = rain_transp, names.arg = 1:5) ``` -------------------------------- ### R Data Table Output Example Source: https://netcomi.de/reference/renameTaxa.html This is an example output of a printed R data frame, likely a taxonomic table. It illustrates how row names and column data are displayed, including different taxonomic ranks and classifications. ```text Kingdom Phylum Class Order OTU1 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" OTU2 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" OTU3 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" OTU4 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" OTU5 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" OTU6 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" OTU7 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" OTU8 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" OTU9 "Unclassified" "unclassified" "unclassified" "unclassified" OTU10 "Bacteria" "Actinobacteria" "Actinobacteria" "Actinomycetales" Family Genus Species OTU1 "Propionibacteriaceae" "Propionibacterium" "Propionibacteriumacnes" OTU2 "unclassified" "unclassified" "unclassified" OTU3 "Propionibacteriaceae" "unclassified" "unclassified" OTU4 "Propionibacteriaceae" "Tessaracoccus" NA OTU5 "Propionibacteriaceae" "Aestuariimicrobium" "unclassified" OTU6 NA NA NA OTU7 "Nocardioidaceae" " " " " OTU8 "Nocardioidaceae" "Propionicimonas" " " OTU9 "unclassified" "unclassified" "unclassified" OTU10 NA NA NA ``` -------------------------------- ### Register Parallel Backend with doSNOW Source: https://netcomi.de/articles/create_asso_perm.html Set up a parallel cluster and register the doSNOW backend for use with foreach. Ensure you choose an appropriate number of cores for your system. ```r library("foreach") cores <- 2 # Please choose an appropriate number of cores cl <- parallel::makeCluster(cores) doSNOW::registerDoSNOW(cl) ``` -------------------------------- ### Install Optional NetCoMi Packages Source: https://netcomi.de/readme.html Automatically installs packages that are optionally required by NetCoMi for specific functionalities. If not installed via this function, required packages will be installed by the respective NetCoMi function when needed. ```r installNetCoMiPacks() ``` -------------------------------- ### Load SPRING Package and Data Source: https://netcomi.de/articles/asso_as_input.html Loads the SPRING package and the QMP dataset. 'nlambda' and 'rep.num' are set to 10 for reduced execution time; increase these values for real-world data. ```r library(SPRING) # Load the QMP data set data("QMP") # Run SPRING for association estimation fit_spring <- SPRING(QMP, quantitative = TRUE, lambdaseq = "data-specific", nlambda = 10, rep.num = 10, seed = 123456, ncores = 1, Rmethod = "approx", verbose = FALSE) # Optimal lambda opt.K <- fit_spring$output$stars$opt.index # Association matrix assoMat <- as.matrix(SpiecEasi::symBeta(fit_spring$output$est$beta[[opt.K]], mode = "ave")) rownames(assoMat) <- colnames(assoMat) <- colnames(QMP) ``` -------------------------------- ### Initialize network comparison with netCompare Source: https://netcomi.de/articles/create_asso_perm.html Use this function to compare network properties with permutation testing enabled. Ensure the input objects are correctly formatted before execution. ```R comp_amgut1 <- netCompare(props_amgut, permTest = TRUE, nPerm = 100, fileLoadAssoPerm = "assoPerm_comp", storeCountsPerm = FALSE, seed = 123456) ``` -------------------------------- ### Load NetCoMi and American Gut Data Source: https://netcomi.de/articles/NetCoMi.html Initializes the environment by loading the NetCoMi and phyloseq libraries and the required American Gut Project datasets. ```R library(NetCoMi) library(phyloseq) # Load data sets data("amgut1.filt") # ASV count matrix data("amgut2.filt.phy") # phyloseq objext ``` -------------------------------- ### Theme Selection Options Source: https://netcomi.de/reference/netcompare Provides options for selecting the documentation theme: Light, Dark, or Auto. ```markdown * Light * Dark * Auto ``` -------------------------------- ### Construct Differential Networks with NetCoMi Source: https://netcomi.de/reference/diffnet.html Demonstrates how to prepare data, generate group assignments, and construct networks using the netConstruct function. ```R knitr::opts_chunk$set(fig.width = 10, fig.height = 6) # Load data sets from American Gut Project (from SpiecEasi package) data("amgut1.filt") # Generate a random group vector set.seed(123456) group <- sample(1:2, nrow(amgut1.filt), replace = TRUE) # Network construction: amgut_net <- netConstruct(amgut1.filt, group = group, measure = "pearson", filtTax = "highestVar", filtTaxPar = list(highestVar = 30), zeroMethod = "pseudoZO", normMethod = "clr") #> Checking input arguments ... #> Done. #> Data filtering ... #> 97 taxa removed. #> 30 taxa and 289 samples remaining. #> #> Zero treatment: #> Zero counts replaced by 1 #> #> Normalization: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Calculate 'pearson' associations ... #> Done. #> #> Calculate associations in group 2 ... #> Done. #> #> Sparsify associations via 't-test' ... #> #> Adjust for multiple testing via 'adaptBH' ... #> Done. #> Done. #> #> Sparsify associations in group 2 ... #> #> Adjust for multiple testing via 'adaptBH' ... #> Done. #> Done. ``` -------------------------------- ### Iterative Bootstrapping for Network Construction Source: https://netcomi.de/reference/netConstruct.html Demonstrates how to split large bootstrap replicates into smaller iterations using the assoBoot argument to manage memory and computation. ```R niter <- 5 nboot <- 1000 # Overall number of bootstrap replicates: 5000 # Use a different seed for each iteration seeds <- sample.int(1e8, size = niter) # List where all bootstrap association matrices are stored assoList <- list() for (i in 1:niter) { # assoBoot is set to TRUE to return the bootstrap association matrices net <- netConstruct(amgut1.filt, filtTax = "highestFreq", filtTaxPar = list(highestFreq = 50), filtSamp = "totalReads", filtSampPar = list(totalReads = 0), measure = "pearson", normMethod = "clr", zeroMethod = "pseudoZO", sparsMethod = "bootstrap", cores = 1, nboot = nboot, assoBoot = TRUE, verbose = 1, # Set to 2 for progress bar seed = seeds[i]) assoList[(1:nboot) + (i - 1) * nboot] <- net$assoBoot1 } # Construct the actual network with all 5000 bootstrap association matrices net_final <- netConstruct(amgut1.filt, filtTax = "highestFreq", filtTaxPar = list(highestFreq = 50), filtSamp = "totalReads", filtSampPar = list(totalReads = 0), measure = "pearson", normMethod = "clr", zeroMethod = "pseudoZO", sparsMethod = "bootstrap", cores = 1, nboot = nboot * niter, assoBoot = assoList, verbose = 1) # Set to 2 for progress bar # Network analysis props <- netAnalyze(net_final, clustMethod = "cluster_fast_greedy") # Network plot plot(props) ``` -------------------------------- ### Summary Method for Network Properties Source: https://netcomi.de/news/index.html New 'show' arguments have been added to the summary methods for microNetProps and microNetComp objects. These arguments control which specific network properties are displayed in the summary output. ```R summary(object, show = c("all")) ``` -------------------------------- ### NetConstruct Zero Replacement Method Source: https://netcomi.de/news/index.html NetConstruct() now supports a new zero replacement method 'pseudoZO'. This method adds a pseudo count only to zero entries in the count matrix, preserving ratios between non-zero counts. ```R netConstruct(..., zero_method = "pseudoZO", pseudo_count = 0.01) ``` -------------------------------- ### GET /summary Source: https://netcomi.de/articles/NetCoMi.html Retrieves a summary of network properties, including component sizes, global properties, clusters, hubs, and centrality measures. ```APIDOC ## GET /summary ### Description Provides a comprehensive summary of the network properties, including component sizes, global network metrics, cluster information, hub identification, and ranked centrality measures. ### Method GET ### Parameters #### Query Parameters - **numbNodes** (integer) - Optional - The number of nodes to display in the centrality rankings. ### Response #### Success Response (200) - **Component sizes** (object) - Sizes of network components. - **Global network properties** (object) - Metrics like LCC size, clustering coefficient, and modularity. - **Clusters** (object) - Cluster distribution information. - **Hubs** (array) - List of identified hub nodes. - **Centrality measures** (object) - Ranked lists for Degree, Betweenness, Closeness, and Eigenvector centralities. ``` -------------------------------- ### Construct Network and Visualize Associations Source: https://netcomi.de/reference/plotheat Prepare microbiome data, construct a network using netConstruct, and visualize the association matrices. ```R # Load data sets from American Gut Project (from SpiecEasi package) data("amgut2.filt.phy") # Split data into two groups: with and without seasonal allergies amgut_season_yes <- phyloseq::subset_samples(amgut2.filt.phy, SEASONAL_ALLERGIES == "yes") amgut_season_no <- phyloseq::subset_samples(amgut2.filt.phy, SEASONAL_ALLERGIES == "no") # Sample sizes phyloseq::nsamples(amgut_season_yes) #> [1] 121 phyloseq::nsamples(amgut_season_no) #> [1] 163 # Make sample sizes equal to ensure comparability n_yes <- phyloseq::nsamples(amgut_season_yes) amgut_season_no <- phyloseq::subset_samples(amgut_season_no, X.SampleID %in% get_variable(amgut_season_no, "X.SampleID")[1:n_yes]) #> Error in h(simpleError(msg, call)): error in evaluating the argument 'table' in selecting a method for function '%in%': error in evaluating the argument 'object' in selecting a method for function 'sample_data': object 'amgut_season_no' not found # Network construction amgut_net <- netConstruct(data = amgut_season_yes, data2 = amgut_season_no, measure = "pearson", filtTax = "highestVar", filtTaxPar = list(highestVar = 50), zeroMethod = "pseudoZO", normMethod = "clr", sparsMethod = "thresh", thresh = 0.4, seed = 123456) #> Checking input arguments ... #> Done. #> Data filtering ... #> 95 taxa removed in each data set. #> 1 rows with zero sum removed in group 1. #> 1 rows with zero sum removed in group 2. #> 43 taxa and 120 samples remaining in group 1. #> 43 taxa and 162 samples remaining in group 2. #> #> Zero treatment in group 1: #> Zero counts replaced by 1 #> #> Zero treatment in group 2: #> Zero counts replaced by 1 #> #> Normalization in group 1: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Normalization in group 2: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Calculate 'pearson' associations ... #> Done. #> #> Calculate associations in group 2 ... #> Done. #> #> Sparsify associations via 'threshold' ... #> Done. #> #> Sparsify associations in group 2 ... #> Done. # Estimated and sparsified associations of group 1 plotHeat(amgut_net$assoEst1, textUpp = "none", labCex = 0.6) plotHeat(amgut_net$assoMat1, textUpp = "none", labCex = 0.6) ``` -------------------------------- ### Construct and Analyze Microbial Networks Source: https://netcomi.de/reference/netcompare Demonstrates loading phyloseq data, filtering samples for comparability, constructing networks with netConstruct, and performing analysis with netAnalyze. ```R knitr::opts_chunk$set(fig.width = 16, fig.height = 8) # Load data sets from American Gut Project (from SpiecEasi package) data("amgut2.filt.phy") # Split data into two groups: with and without seasonal allergies amgut_season_yes <- phyloseq::subset_samples(amgut2.filt.phy, SEASONAL_ALLERGIES == "yes") amgut_season_no <- phyloseq::subset_samples(amgut2.filt.phy, SEASONAL_ALLERGIES == "no") amgut_season_yes #> phyloseq-class experiment-level object #> otu_table() OTU Table: [ 138 taxa and 121 samples ] #> sample_data() Sample Data: [ 121 samples by 166 sample variables ] #> tax_table() Taxonomy Table: [ 138 taxa by 7 taxonomic ranks ] amgut_season_no #> phyloseq-class experiment-level object #> otu_table() OTU Table: [ 138 taxa and 163 samples ] #> sample_data() Sample Data: [ 163 samples by 166 sample variables ] #> tax_table() Taxonomy Table: [ 138 taxa by 7 taxonomic ranks ] # Filter the 121 samples (sample size of the smaller group) with highest # frequency to make the sample sizes equal and thus ensure comparability. n_yes <- phyloseq::nsamples(amgut_season_yes) # Network construction amgut_net <- netConstruct(data = amgut_season_yes, data2 = amgut_season_no, measure = "pearson", filtSamp = "highestFreq", filtSampPar = list(highestFreq = n_yes), filtTax = "highestVar", filtTaxPar = list(highestVar = 30), zeroMethod = "pseudoZO", normMethod = "clr") #> Checking input arguments ... #> Done. #> Data filtering ... #> 0 samples removed in data set 1. #> 42 samples removed in data set 2. #> 114 taxa removed in each data set. #> 1 rows with zero sum removed in group 1. #> 24 taxa and 120 samples remaining in group 1. #> 24 taxa and 121 samples remaining in group 2. #> #> Zero treatment in group 1: #> Zero counts replaced by 1 #> #> Zero treatment in group 2: #> Zero counts replaced by 1 #> #> Normalization in group 1: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Normalization in group 2: #> Execute clr(){SpiecEasi} ... #> Done. #> #> Calculate 'pearson' associations ... #> Done. #> #> Calculate associations in group 2 ... #> Done. #> #> Sparsify associations via 't-test' ... #> #> Adjust for multiple testing via 'adaptBH' ... #> Done. #> Done. #> #> Sparsify associations in group 2 ... #> #> Adjust for multiple testing via 'adaptBH' ... #> Done. #> Done. # Network analysis # Note: Please zoom into the GCM plot or open a new window using: # x11(width = 10, height = 10) amgut_props <- netAnalyze(amgut_net, clustMethod = "cluster_fast_greedy") # Network plot plot(amgut_props, sameLayout = TRUE, title1 = "Seasonal allergies", title2 = "No seasonal allergies") ``` -------------------------------- ### Rename Taxa Including 'Unclassified' Source: https://netcomi.de/reference/renametaxa This example is similar to the previous one but includes 'Unclassified' in the 'unknown' argument to ensure it is also renamed. This corrects the renaming of OTU9. ```R renamed6 <- renameTaxa(taxtab, unclass = NULL, unknown = c(NA, " ", "unclassified", "Unclassified"), pat = "", substPat = "_()") ``` -------------------------------- ### POST /network/configure Source: https://netcomi.de/reference/netConstruct.html Configures the parameters for network construction, including data transformation and sparsification logic. ```APIDOC ## POST /network/configure ### Description Configures the preprocessing and sparsification parameters for network construction. ### Method POST ### Endpoint /network/configure ### Parameters #### Request Body - **zeroMethod** (string) - Optional - Method for zero replacement: "none", "pseudo", "pseudoZO", "multRepl", "alrEM", "bayesMult". - **zeroPar** (list) - Optional - Parameters for zero replacement method. - **normMethod** (string) - Optional - Normalization method: "none", "TSS", "CSS", "COM", "rarefy", "VST", "clr", "mclr". - **normPar** (list) - Optional - Parameters for normalization method. - **sparsMethod** (string) - Optional - Sparsification method: "none", "t-test", "bootstrap", "threshold", "softThreshold", "knn". - **thresh** (numeric vector) - Optional - Threshold for sparsification if method is "threshold". - **alpha** (numeric vector) - Optional - Significance level for t-test or bootstrap. - **adjust** (string) - Optional - Multiple testing adjustment method: "lfdr", "adaptBH", or p.adjust methods. - **trueNullMethod** (string) - Optional - Method for estimating true null hypotheses: "convest", "lfdr", "mean", "hist", "farco". - **lfdrThresh** (numeric vector) - Optional - Threshold for local FDR correction. - **nboot** (integer) - Optional - Number of bootstrap samples. - **assoBoot** (logical/list) - Optional - Bootstrap association matrix settings. - **cores** (integer) - Optional - Number of CPU cores for parallel processing. ### Request Example { "zeroMethod": "multRepl", "normMethod": "TSS", "sparsMethod": "t-test", "alpha": 0.05, "adjust": "lfdr" } ### Response #### Success Response (200) - **status** (string) - Configuration status message ``` -------------------------------- ### Rename Taxa with Specific Unknowns Source: https://netcomi.de/reference/renametaxa This example renames taxa, specifying 'NA', ' ', and 'unclassified' as unknown values. It uses a pattern to substitute names and include the rank. ```R renamed5 <- renameTaxa(taxtab, unclass = NULL, unknown = c(NA, " ", "unclassified"), pat = "", substPat = "_()") ``` -------------------------------- ### Rename Taxa with substPat Source: https://netcomi.de/reference/renametaxa Renames taxa in a taxonomic table using a pattern substitution. This example shows how to substitute a pattern like '_' with ' ()'. ```r renamed3 <- renameTaxa(taxtab, numUnclassPat = "_", pat = "", substPat = " ()") renamed3 ``` -------------------------------- ### Prepare taxonomy data for renaming Source: https://netcomi.de/reference/renametaxa Demonstrates loading a phyloseq dataset and manually introducing unclassified and blank entries into the taxonomy table for testing renaming logic. ```R #--- Load and edit data ----------------------------------------------------- library(phyloseq) data("GlobalPatterns") global <- subset_taxa(GlobalPatterns, Kingdom == "Bacteria") taxtab <- global@tax_table@.Data[1:10, ] # Add some unclassified taxa taxtab[c(2,3,5), "Species"] <- "unclassified" taxtab[c(2,3), "Genus"] <- "unclassified" taxtab[2, "Family"] <- "unclassified" # Add some blanks taxtab[7, "Genus"] <- " " taxtab[7:9, "Species"] <- " " # Add taxon that is unclassified up to Kingdom taxtab[9, ] <- "unclassified" taxtab[9, 1] <- "Unclassified" ``` -------------------------------- ### Parallel Association Permutation Calculation in R Source: https://netcomi.de/articles/create_asso_perm.html Executes parallel computations for association permutation tests using foreach and dopar. Requires the 'NetComi' package and a parallel cluster setup with progress bar options. ```r tmp <- foreach(i = 1:repetitions, .packages = c("NetCoMi"), .options.snow = opts) %dopar% { progress(i) NetCoMi::createAssoPerm(props_amgut, nPerm = blocksize, permGroupMat = permGroupMat[(i-1) * blocksize + 1:blocksize, ], computeAsso = TRUE, fileStoreAssoPerm = paste0("assoPerm", i), storeCountsPerm = FALSE, append = FALSE) } #> | |============== | 20% | |============================ | 40% | |========================================== | 60% | |======================================================== | 80% | |======================================================================| 100% ``` -------------------------------- ### Construct a network using SPRING Source: https://netcomi.de/articles/NetCoMi.html Configures netConstruct to estimate associations using the SPRING method with specific filtering and normalization parameters. ```R net_spring <- netConstruct(amgut_genus_renamed, taxRank = "Rank6", filtTax = "highestFreq", filtTaxPar = list(highestFreq = 50), filtSamp = "totalReads", filtSampPar = list(totalReads = 1000), measure = "spring", measurePar = list(nlambda=10, rep.num=10, Rmethod = "approx"), normMethod = "none", zeroMethod = "none", sparsMethod = "none", dissFunc = "signed", verbose = 2, seed = 123456) ``` -------------------------------- ### Run netCompare with permutation testing Source: https://netcomi.de/reference/createassoperm Executes a network comparison using pre-stored permutation association matrices. Requires the input object and configuration for permutation testing. ```R amgut_comp2 <- netCompare(amgut_props, permTest = TRUE, nPerm = 100L, fileLoadAssoPerm = "assoPerm") ``` -------------------------------- ### Plot Network by Feature with Custom Shapes Source: https://netcomi.de/reference/plot.micronetprops Visualizes the network using a feature vector for node coloring and another feature vector for node shapes. This allows for multi-dimensional representation of node attributes. Hubs are not highlighted in this example. ```R # Use a further feature vector for node shapes shapeVec <- sample(1:3, ncol(amgut1.filt), replace = TRUE) names(shapeVec) <- colnames(amgut1.filt) plot(amgut_props, rmSingles = TRUE, nodeColor = "feature", featVecCol = featVec, colorVec = heat.colors(5), nodeShape = c("circle", "square", "diamond"), featVecShape = shapeVec, highlightHubs = FALSE) ``` -------------------------------- ### Rename Taxa with Pattern Substitution Source: https://netcomi.de/reference/renametaxa Use `renameTaxa` to rename taxa based on patterns. This example renames unclassified entries to a format like 'Unclassified_1' and substitutes specific names with a new format including a substitution name and rank. ```R renamed4 <- renameTaxa(taxtab, numUnclassPat = "_", pat = "", substPat = " ()") renamed4 ``` -------------------------------- ### Rename Taxa from a Phyloseq Object Source: https://netcomi.de/reference/renametaxa This example shows how to rename taxa within a phyloseq object. It first subsets the object to reduce runtime and then applies the renameTaxa function. The output displays the first 5 taxa from the taxonomy table. ```R global_sub <- subset_taxa(global, Class == "Clostridia") renamed2 <- renameTaxa(global_sub) tax_table(renamed2)[1:5, ] ```