### Install BiocManager and Core Packages Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/index.html Installs the BiocManager package and core Bioconductor packages necessary for further installations. This is a prerequisite for installing other Bioconductor-related packages. ```R install.packages("BiocManager") # install Bioconductor core packages BiocManager::install() ``` -------------------------------- ### Install hdWGCNA with Conda Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/index.html This snippet shows how to create a new conda environment for hdWGCNA and install necessary R dependencies. ```shell conda create -n hdWGCNA -c conda-forge r-base r-essentials conda activate hdWGCNA ``` -------------------------------- ### Install hdWGCNA package from GitHub Source: https://github.com/smorabit/hdwgcna/blob/dev/README.md This code snippet shows how to install the latest development version of the hdWGCNA package directly from its GitHub repository using the devtools package in R. ```r devtools::install_github('smorabit/hdWGCNA', ref='dev') ``` -------------------------------- ### Troubleshooting dependency installation with Conda Source: https://github.com/smorabit/hdwgcna/blob/dev/README.md This snippet demonstrates how to install an R package dependency, such as 'devtools', using Conda if facing issues with other installation methods. This is useful for resolving conflicts or specific installation problems. ```bash conda install conda-forge::r-devtools ``` -------------------------------- ### Install hdWGCNA dependencies using Conda and R Source: https://github.com/smorabit/hdwgcna/blob/dev/README.md This snippet details the steps to set up an R environment using Conda and install necessary R packages including Bioconductor, devtools, WGCNA, UCell, GenomicRanges, GeneOverlap, and Seurat. ```bash # create new conda environment for R conda create -n hdWGCNA -c conda-forge r-base r-essentials # activate conda environment conda activate hdWGCNA ``` ```r # install BiocManager install.packages("BiocManager") # install Bioconductor core packages BiocManager::install() # install devtools BiocManager::install("devtools") # install additional packages BiocManager::install(c("WGCNA", "UCell", "GenomicRanges", "GeneOverlap")) # install latest version of Seurat from CRAN install.packages("Seurat") # alternatively, install Seurat v4 install.packages("Seurat", repos = c("https://satijalab.r-universe.dev', 'https://cloud.r-project.org")) ``` -------------------------------- ### Standard hdWGCNA Workflow Setup Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/consensus_wgcna.html Demonstrates the standard hdWGCNA workflow for comparison, including setting up the Seurat object, normalizing metacells, setting expression data, testing soft powers, and constructing the network. ```r # setup new hdWGCNA experiment seurat_obj <- SetupForWGCNA( seurat_obj, gene_select = "fraction", fraction = 0.05, wgcna_name = 'ASC_standard', metacell_location = 'ASC' ) seurat_obj <- NormalizeMetacells(seurat_obj) # construct network seurat_obj <- SetDatExpr(seurat_obj,group_name = "ASC",group.by = "cell_type") seurat_obj <- TestSoftPowers(seurat_obj) seurat_obj <- ConstructNetwork(seurat_obj,soft_power=8, tom_name = "ASC_standard") # plot the dendrogram PlotDendrogram(seurat_obj, main='ASC standard Dendrogram') ``` -------------------------------- ### Add SCTransform Tutorial Source: https://github.com/smorabit/hdwgcna/blob/dev/NEWS.md A new tutorial has been added to guide users on using SCTransform normalized data with hdWGCNA. This facilitates integration with workflows that utilize SCTransform for normalization. ```r Tutorial for using SCTransform normalized data. ``` -------------------------------- ### Install Seurat Package Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/index.html Installs the Seurat package, a popular toolkit for single-cell data analysis, from CRAN. It also provides an alternative for installing Seurat version 4 from a specific R Universe repository. ```R # install latest version of Seurat from CRAN install.packages("Seurat") # alternatively, install Seurat v4 install.packages("Seurat", repos = c("https://satijalab.r-universe.dev', 'https://cloud.r-project.org")) ``` -------------------------------- ### Install and Load STRINGdb Package Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/ppi_integration.html Installs the STRINGdb package from Bioconductor and loads it into the current R session for use in network analysis. ```r BiocManager::install('STRINGdb') # load STRINGdb library(STRINGdb) ``` -------------------------------- ### ProjectModules Function Example Usage - R Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/ProjectModules.html An example demonstrating the usage of the ProjectModules function. It shows how to call the function with essential arguments like the Seurat objects and provides a glimpse into the function's internal logic for handling WGCNA names and retrieving modules. ```r ProjectModules #> function (seurat_obj, seurat_ref, modules = NULL, group.by.vars = NULL, #> gene_mapping = NULL, genome1_col = NULL, genome2_col = NULL, #> overlap_proportion = 0.5, vars.to.regress = NULL, scale.model.use = "linear", #> wgcna_name = NULL, wgcna_name_proj = NULL, ...) #> { #> if (is.null(wgcna_name)) { #> wgcna_name <- seurat_ref@misc$active_wgcna #> } #> CheckWGCNAName(seurat_ref, wgcna_name) #> if (is.null(modules)) { #> modules <- GetModules(seurat_ref, wgcna_name) #> } #> else { #> if (!all(c("gene_name", "module", "color") %in% colnames(modules))) { ``` -------------------------------- ### Consensus Network Analysis Setup and Construction (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/consensus_wgcna.html This snippet demonstrates the setup for consensus network analysis in hdWGCNA. It includes preparing the Seurat object, constructing metacells, setting expression matrices for multiple species, testing soft powers, constructing the consensus network, and plotting the dendrogram. This approach aims to preserve co-expression structure across different species. ```r seurat_merged <- SetupForWGCNA( seurat_merged, gene_select = "fraction", fraction = 0.05, wgcna_name = 'ASC_consensus' ) # construct metacells: seurat_merged <- MetacellsByGroups( seurat_merged, group.by = c("cell_type", "Sample", 'Species'), k = 25, max_shared = 12, min_cells = 50, target_metacells = 250, reduction = 'harmony', ident.group = 'cell_type' ) seurat_merged <- NormalizeMetacells(seurat_merged) # setup expression matrices for each species in astrocytes seurat_merged <- SetMultiExpr( seurat_merged, group_name = "ASC", group.by = "cell_type", multi.group.by ="Species", multi_groups = NULL ) # identify soft power thresholds seurat_merged <- TestSoftPowersConsensus(seurat_merged) # plot soft power results plot_list <- PlotSoftPowers(seurat_merged) consensus_groups <- unique(seurat_merged$Species) p_list <- lapply(1:length(consensus_groups), function(i){ cur_group <- consensus_groups[[i]] plot_list[[i]][[1]] + ggtitle(paste0(cur_group)) + theme(plot.title=element_text(hjust=0.5)) }) wrap_plots(p_list, ncol=2) # consensus network analysis seurat_merged <- ConstructNetwork( seurat_merged, soft_power=c(7,7), consensus=TRUE, tom_name = "Species_Consensus" ) # plot the dendrogram PlotDendrogram(seurat_merged, main='ASC cross species dendrogram') ``` -------------------------------- ### Metacells by Groups Example Usage Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/metacells_by_groups.html An example of how to use the 'metacells_by_groups' function with a Seurat object named 'pbmc'. This example demonstrates a common use case but may result in an error if the 'pbmc' object is not defined. ```R metacells_by_groups(pbmc) #> Error in metacells_by_groups(pbmc): object 'pbmc' not found ``` -------------------------------- ### Install Devtools and Additional Packages Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/index.html Installs the devtools package and other specified R packages like WGCNA, UCell, GenomicRanges, and GeneOverlap using BiocManager. These packages are often dependencies for more complex bioinformatic analyses. ```R BiocManager::install("devtools") # install additional packages BiocManager::install(c("WGCNA", "UCell", "GenomicRanges", "GeneOverlap")) ``` -------------------------------- ### Setup Seurat Object and Metacells for Consensus Analysis Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/consensus_wgcna.html Loads a Seurat object, prepares it for WGCNA, and constructs metacells, including 'msex' for group-specific analysis. This involves using SetupForWGCNA and MetacellsByGroups functions. ```r seurat_obj <- readRDS('data/Zhou_control.rds') seurat_obj <- SetupForWGCNA( seurat_obj, gene_select = "fraction", fraction = 0.05, wgcna_name = 'ASC_consensus' ) seurat_obj <- MetacellsByGroups( seurat_obj = seurat_obj, group.by = c("cell_type", "Sample", 'msex'), ident.group = 'cell_type' k = 25, max_shared = 12, min_cells = 50, target_metacells = 250, reduction = 'harmony' ) seurat_obj <- NormalizeMetacells(seurat_obj) ``` -------------------------------- ### ModuleUMAPPlot Example Usage Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/ModuleUMAPPlot.html An illustrative example of how to call the ModuleUMAPPlot function, demonstrating its default parameters and providing a glimpse into its internal data processing for plotting module networks. ```r ModuleUMAPPlot #> function (seurat_obj, sample_edges = TRUE, edge_prop = 0.2, label_hubs = 5, #> edge.alpha = 0.25, vertex.label.cex = 0.5, label_genes = NULL, #> return_graph = FALSE, keep_grey_edges = TRUE, wgcna_name = NULL, #> ...) #> #> if (is.null(wgcna_name)) { #> wgcna_name <- seurat_obj@misc$active_wgcna #> } #> TOM <- GetTOM(seurat_obj, wgcna_name) #> modules <- GetModules(seurat_obj, wgcna_name) #> umap_df <- GetModuleUMAP(seurat_obj, wgcna_name) #> mods <- levels(umap_df$module) #> mods <- mods[mods != "grey"] #> subset_TOM <- TOM[umap_df$gene, umap_df$gene[umap_df$hub == #> "hub"]) #> hub_list <- lapply(mods, function(cur_mod) { #> cur <- subset(modules, module == cur_mod) #> cur[, c("gene_name", paste0("kME_", cur_mod))] %>% top_n(label_hubs) %>$ #> .$gene_name #> }) #> names(hub_list) <- mods #> hub_labels <- as.character(unlist(hub_list)) #> print("hub labels") #> print(hub_labels) #> print(label_genes) #> if (is.null(label_genes)) { #> label_genes <- hub_labels #> } #> else { ``` -------------------------------- ### Example Usage of TestSoftPowersConsensus Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/TestSoftPowersConsensus.html Provides an example of how to use the TestSoftPowersConsensus function with a Seurat object. This demonstrates a basic call to the function to test soft powers for network analysis. ```R # TestSoftPowers(pbmc) ``` -------------------------------- ### Setup hdWGCNA with Metacell Genes (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/sctransform.html Initializes the Seurat object for hdWGCNA using genes obtained from metacells. This step is part of the alternative approach where SCTransform is applied after metacell construction. ```r seurat_subset <- SetupForWGCNA( seurat_subset, features = GetWGCNAGenes(seurat_subset, 'SCT'), wgcna_name = "SCT_meta" ) ``` -------------------------------- ### Setup Seurat Object for WGCNA Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/basic_tutorial.html Configures a Seurat object for WGCNA analysis using the hdWGCNA package. It allows gene selection based on variable features, expression fraction, or a custom list. ```r seurat_obj <- SetupForWGCNA( seurat_obj, gene_select = "fraction", fraction = 0.05, wgcna_name = "tutorial" ) ``` -------------------------------- ### Error Checks in SetupForWGCNA and SelectNetworkGenes (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/news/index.html Adds new error checking mechanisms to the SetupForWGCNA and SelectNetworkGenes functions. These checks are intended to improve the robustness and user feedback during WGCNA analysis setup. ```R SetupForWGCNA SelectNetworkGenes ``` -------------------------------- ### Setup hdWGCNA for SEACells Metacells in R Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/other_metacells.html Prepares a Seurat object for WGCNA analysis using SEACells metacells. It sets up the WGCNA environment, adds the metacell data, normalizes it, and defines the expression matrix. ```r # load datasets m_obj <- readRDS(paste0(data_dir, 'tutorial_seacells_metacell.rds')) # set up hdWGCNA experiment seurat_obj <- SetupForWGCNA( seurat_obj, gene_select = "fraction", fraction = 0.05, wgcna_name = 'SEACells' ) # add the seacells dataset seurat_obj <- SetMetacellObject(seurat_obj, m_obj) seurat_obj <- NormalizeMetacells(seurat_obj) # setup expression matrix seurat_obj <- SetDatExpr( seurat_obj, group_name = 'all', use_metacells=TRUE, ) ``` -------------------------------- ### Basic Network Visualization with ggraph Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/network_visualizations.html Initial network visualization setup using `ggraph`. It defines node and edge aesthetics, including alpha and color based on weight and edge color, and applies manual color scales. It also includes node labels and removes the legend. ```R ggraph(lay) + geom_edge_link(aes(alpha=weight, color=edge_color)) + geom_node_point(data=subset(lay, hub == ''), aes(color=module, size=kME)) + geom_node_point(data=subset(lay, hub != ''), aes(fill=module, size=kME), color='black', shape=21) + scale_colour_manual(values=mod_cp) + scale_fill_manual(values=mod_cp) + scale_edge_colour_manual(values=mod_cp) + geom_node_label(aes(label=hub), repel=TRUE, max.overlaps=Inf, fontface='italic') + NoLegend() ``` -------------------------------- ### Find Variable Isoforms and Setup for WGCNA (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/isoform_pbmcs.html This snippet demonstrates identifying variable isoforms across samples and setting up the Seurat object for WGCNA analysis using variable features. It involves switching to the 'iso' assay, finding variable features, intersecting them, and then using `SetupForWGCNA`. ```r # switch to isoform assay: DefaultAssay(seurat_obj) <- 'iso' # Get top 50k variable isoforms in each sample and take the intersection selected_features <- lapply(SplitObject(seurat_obj, split.by = 'Sample'), function(x){ FindVariableFeatures(x, nfeatures=50000) %>% VariableFeatures }) VariableFeatures(seurat_obj) <- Reduce(intersect, selected_features) length(VariableFeatures(seurat_obj)) ``` ```r # setup this hdWGCNA experiment seurat_obj <- SetupForWGCNA( seurat_obj, gene_select = "variable", wgcna_name = "variable", ) ``` -------------------------------- ### SetupForWGCNA Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/SetupForWGCNA.html Initializes a Seurat object for hdWGCNA analysis, allowing specification of features and metacell location. ```APIDOC ## SetupForWGCNA ### Description Initializes a Seurat object to store hdWGCNA data with a specified experiment name. This function allows for the selection of features to be used in the WGCNA analysis and optionally copies the metacell/metaspot object from an existing hdWGCNA experiment. ### Method NA (This is an R function, not a direct API endpoint) ### Endpoint NA ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **seurat_obj** (Seurat Object) - Required - The Seurat object to be modified. - **wgcna_name** (character) - Required - The name for the WGCNA experiment within the Seurat object. - **features** (list of character) - Optional - A list of features to be used for WGCNA analysis. Defaults to NULL. - **metacell_location** (character) - Optional - The name of an existing WGCNA experiment to copy the metacell object from. Defaults to NULL. - **...** - Optional - Additional parameters to pass to the `SelectNetworkGenes` function. ### Request Example ```R # Assuming 'my_seurat_object' is a Seurat object SetupForWGCNA(seurat_obj = my_seurat_object, wgcna_name = "WGCNA_Experiment_1", features = c("GeneA", "GeneB", "GeneC")) # Copying metacell location from an existing experiment SetupForWGCNA(seurat_obj = my_seurat_object, wgcna_name = "WGCNA_Experiment_2", metacell_location = "WGCNA_Experiment_1") ``` ### Response #### Success Response (200) (This function modifies the Seurat object in place and does not return a value directly, but rather updates the object with the WGCNA data structure.) #### Response Example (No direct response body as this is an R function. The Seurat object will be updated internally.) ``` -------------------------------- ### Download Tutorial Dataset Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/consensus_wgcna.html Provides commands to download the tutorial dataset ('Zhou_2020.rds') using wget. It also includes a fallback option to download the file from a Google Drive link if the direct download fails. ```bash wget https://swaruplab.bio.uci.edu/public_data/Zhou_2020.rds ``` -------------------------------- ### ModuleCorrelogram Example Usage (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/ModuleCorrelogram.html Provides an example of how to use the ModuleCorrelogram function. Note: The example code itself results in an error as the required object 'MECorrelogram' is not defined in this context. ```r MECorrelogram #> Error in eval(expr, envir, enclos): object 'MECorrelogram' not found ``` -------------------------------- ### GNU GPL Terminal Notice Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/LICENSE.html A sample notice to be displayed by a program in interactive mode, informing users about its free software status, warranty, and terms of redistribution. It includes hypothetical commands to show license details. ```plain text Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. ``` -------------------------------- ### Install NetRep Package Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/module_preservation.html Installs the NetRep R package, which is required for performing module preservation analysis. This package is not a core dependency of hdWGCNA and must be installed separately. ```r install.packages('NetRep') ``` -------------------------------- ### GNU GPL Copyright Notice Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/LICENSE.html This is the standard copyright notice to be included at the beginning of each source file when distributing software under the GNU General Public License (GPL). It declares ownership, licensing terms, and the absence of warranty. ```plain text Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . ``` -------------------------------- ### Include Mark.js for Search Highlighting Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/deps/data-deps.txt Includes the Mark.min.js script (version 1.0.0), a JavaScript library for highlighting search terms in a given context, enhancing search result readability. ```html ``` -------------------------------- ### SetupForWGCNA Function Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/index.html Initializes a Seurat object for Weighted Gene Co-expression Network Analysis (WGCNA). This function prepares the data structure required by hdWGCNA for subsequent network construction and analysis steps. ```r SetupForWGCNA(seurat_obj, ...) ``` -------------------------------- ### Example Usage of PlotDMEsVolcano Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/PlotDMEsVolcano.html Demonstrates how to use the PlotDMEsVolcano function with a Seurat object and DME results. Note that the example provided in the source has an error as the 'DMEs' object is not defined. ```r # Example usage: # Assuming `seurat_obj` is your Seurat object and `DMEs` is the output from FindDMEs PlotDMEsVolcano(seurat_obj, DMEs, wgcna_name = "MG") #> Error in h(simpleError(msg, call)): error in evaluating the argument 'object' in selecting a method for function 'na.omit': object 'DMEs' not found ``` -------------------------------- ### Prepare Seurat Object and Construct Pseudobulk (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/pseudobulk.html Prepares a Seurat object for WGCNA using `SetupForWGCNA` and then constructs a pseudobulk expression matrix using `ConstructPseudobulk`. It then computes a log2CPM normalization and sets this normalized matrix as the expression data for WGCNA using `SetDatExpr`. ```r seurat_obj <- SetupForWGCNA( seurat_obj, gene_select = "fraction", fraction = 0.05, wgcna_name = "pseudobulk" ) length(GetWGCNAGenes(seurat_obj)) # Construt the pseudobulk expression profiles datExpr <- ConstructPseudobulk( seurat_obj, group.by = 'cell_type', replicate_col = 'Sample', assay = 'RNA', slot = 'counts', # this should always be counts! min_reps = 10 ) # compute log2CPM normalization # You can substitute this with another normalization of your choosing. cpm <- t(apply(datExpr, 1, function(x){ y <- (x) / sum(x) * 1000000 log2(y + 1) })) seurat_obj <- SetDatExpr( seurat_obj, mat = cpm ) ``` -------------------------------- ### Install and Load fgsea Package Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/enrichment_analysis.html Installs the fgsea package from Bioconductor and loads it into the current R session. This package is used for performing Gene Set Enrichment Analysis (GSEA). ```r BiocManager::install("fgsea") library(fgsea) ``` -------------------------------- ### Seurat v5 Support and Network Tutorial (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/news/index.html Introduces support for Seurat v5 and updates the network visualization tutorial to include instructions for creating custom networks. This enhances compatibility with newer Seurat versions and provides more customization options. ```R Seurat v5 custom networks ``` -------------------------------- ### Include Bootstrap 5 CSS Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/deps/data-deps.txt Links to the Bootstrap 5.3.1 CSS file, providing responsive and mobile-first front-end framework for faster and easier web development. ```html ``` -------------------------------- ### ModuleTFNetwork Example Usage - R Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/ModuleTFNetwork.html An example illustrating how to use the ModuleTFNetwork function. This code snippet demonstrates calling the function with necessary parameters to generate the TF-module network plot. ```r ModuleTFNetwork #> function (seurat_obj, tf_name, tf_gene_name, edge.alpha = 0.75, #> cor_thresh = 0.25, high_color = "red", mid_color = "grey", #> low_color = "blue", slot = "data", size.scale = 30, tf_x = 0, #> tf_y = 0, wgcna_name = NULL) #> { #> if (is.null(wgcna_name)) { #> wgcna_name <- seurat_obj@misc$active_wgcna #> } #> modules <- GetModules(seurat_obj, wgcna_name) %>% subset(module != #> "grey") %>% mutate(module = droplevels(module)) #> MEs <- GetMEs(seurat_obj, TRUE, wgcna_name) %>% as.matrix #> MEs <- MEs[, colnames(MEs) != "grey"] #> mod_sizes <- table(modules$module) #> module_cor <- Hmisc::rcorr(x = MEs, type = "pearson")$r #> module_cor[lower.tri(module_cor)] <- NA #> module_cor <- reshape2::melt(module_cor) %>% na.omit #> module_cor <- subset(module_cor, abs(value) >= cor_thresh & #> Var1 != Var2) #> module_cor #> cur_exp <- GetAssayData(seurat_obj, slot = slot)[tf_gene_name, #> ] #> exp_cor <- Hmisc::rcorr(x = MEs, y = cur_exp)$r[1:ncol(MEs), #> "y"] #> exp_cor <- data.frame(mod = names(exp_cor), value = as.numeric(exp_cor)) ``` -------------------------------- ### Initialize hdWGCNA in Seurat Object Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/SetupForWGCNA.html Sets up a Seurat object to store WGCNA data. It creates a new slot for the WGCNA experiment and allows specifying features for network analysis. Optionally, it can copy metacell/metaspot objects from another WGCNA experiment in the same object. ```r SetupForWGCNA( seurat_obj, wgcna_name, features = NULL, metacell_location = NULL, ... ) ``` -------------------------------- ### ComputeROC Function Definition and Example Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/ComputeROC.html Defines the ComputeROC function from the hdWGCNA package and provides an example of its usage. The function takes a Seurat object and various parameters to compute ROC curves, potentially splitting data and projecting modules. ```R ComputeROC( seurat_obj, group.by = NULL, split_col = NULL, features = "hMEs", seurat_test = NULL, harmony_group_vars = NULL, scale_genes = TRUE, verbose = FALSE, exp_thresh = 0.75, return_seurat = TRUE, wgcna_name = NULL, wgcna_name_test = NULL ) ``` ```R ComputeROC #> function (seurat_obj, group.by = NULL, split_col = NULL, features = "hMEs", #> seurat_test = NULL, harmony_group_vars = NULL, scale_genes = TRUE, #> verbose = FALSE, exp_thresh = 0.75, return_seurat = TRUE, #> wgcna_name = NULL, wgcna_name_test = NULL) #> { #> if (is.null(wgcna_name)) { #> wgcna_name <- seurat_obj@misc$active_wgcna #> } #> modules <- GetModules(seurat_obj, wgcna_name) #> mods <- levels(modules$module) #> mods <- mods[mods != "grey"] #> if (is.null(group.by)) { #> group.by <- "roc_group" #> seurat_obj@meta.data[[group.by]] <- Idents(seurat_obj) #> } #> groups <- levels(seurat_obj@meta.data[[group.by]]) #> groups <- groups[order(groups)] #> if (is.null(seurat_test)) { #> print("splitting seurat obj") #> seurat_train <- seurat_obj[, seurat_obj@meta.data[[split_col]]] #> seurat_test <- seurat_obj[, !seurat_obj@meta.data[[split_col]]] #> wgcna_name_train <- "ROC" #> seurat_train <- ProjectModules(seurat_train, seurat_ref = seurat_obj, #> group.by.vars = harmony_group_vars, wgcna_name_proj = wgcna_name_train, #> scale_genes = scale_genes, verbose = verbose) #> } #> else { #> if (is.null(wgcna_name_test)) { #> wgcna_name_test <- seurat_test@misc$active_wgcna #> } #> if (is.null(group.by)) { #> group.by <- "roc_group" #> seurat_test@meta.data[[group.by]] <- Idents(seurat_test) #> } #> seurat_train <- seurat_obj #> wgcna_name_train <- wgcna_name #> } #> groups_test <- levels(seurat_test@meta.data[[group.by]]) #> groups_test <- groups_test[order(groups_test)] #> groups_common <- intersect(groups, as.character(unique(seurat_test@meta.data[[group.by]])))) #> if (sum(groups == groups_test) != length(groups)) { #> stop("Different groups present in train & test data. Idents likely do not match.") #> } #> if (is.null(GetModules(seurat_test, wgcna_name = wgcna_name_test))) { #> wgcna_name_test <- "ROC" #> seurat_test <- ProjectModules(seurat_test, seurat_ref = seurat_obj, #> group.by.vars = harmony_group_vars, wgcna_name_proj = wgcna_name_test, #> scale_genes = scale_genes, verbose = verbose) #> } #> if (features == "hMEs") { #> MEs <- GetMEs(seurat_train, TRUE, wgcna_name_train) #> MEs_p <- GetMEs(seurat_test, TRUE, wgcna_name_test) #> } #> else if (features == "MEs") { #> MEs <- GetMEs(seurat_train, FALSE, wgcna_name_train) #> MEs_p <- GetMEs(seurat_test, FALSE, wgcna_name_test) #> } #> else if (features == "scores") { #> MEs <- GetModuleScores(seurat_train, wgcna_name_train) ``` -------------------------------- ### RunHarmonyMetacells Seurat Wrapper Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/index.html Runs Harmony on metacells using Seurat. ```R RunHarmonyMetacells() ``` -------------------------------- ### Setup hdWGCNA for MC2 Metacells in R Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/other_metacells.html Configures a Seurat object for WGCNA analysis using MC2 metacells, ensuring that selected WGCNA genes are present in the metacell data. It then proceeds with normalization and expression matrix setup. ```r m_obj <- readRDS(paste0(data_dir, 'tutorial_MC2_metacell.rds')) # set up hdWGCNA experiment seurat_obj <- SetupForWGCNA( seurat_obj, gene_select = "fraction", fraction = 0.05, wgcna_name = 'MC2' ) # IMPORTANT: # in the MC2 code above, we had to exclude some of the genes, so here we have to # make sure the genes that we selected for WGCNA are actually in the metacell # dataset wgcna_genes <- GetWGCNAGenes(seurat_obj) wgcna_genes <- wgcna_genes[wgcna_genes %in% rownames(m_obj)] seurat_obj <- SetWGCNAGenes(seurat_obj, wgcna_genes) # add the MC2 dataset seurat_obj <- SetMetacellObject(seurat_obj, m_obj) seurat_obj <- NormalizeMetacells(seurat_obj) # setup expression matrix seurat_obj <- SetDatExpr( seurat_obj, group_name = 'all', use_metacells=TRUE, ) ``` -------------------------------- ### Pseudobulk Data Tutorial and Functions (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/news/index.html Adds a new tutorial for hdWGCNA with pseudobulk data, including the new function ConstructPseudobulk. Updates SetDatExpr and SetMultiExpr to utilize a pseudobulk expression matrix. ```R ConstructPseudobulk SetDatExpr SetMultiExpr ``` -------------------------------- ### Load Libraries and Dataset in R Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/basic_tutorial.html Loads necessary R libraries for Seurat and WGCNA analysis, sets plotting themes, seeds for reproducibility, enables multithreading, and loads a Seurat object from a file. ```r library(Seurat) library(tidyverse) library(cowplot) library(patchwork) library(WGCNA) library(hdWGCNA) theme_set(theme_cowplot()) set.seed(12345) enableWGCNAThreads(nThreads = 8) seurat_obj <- readRDS('Zhou_2020_control.rds') ``` -------------------------------- ### Install R Packages for TF Analysis Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/tf_network.html Installs essential R packages for TF motif analysis, genomic data manipulation, and database interactions. This includes packages for TF motifs, genomic coordinates, human-specific databases, and the xgboost algorithm. ```R # install packages for dealing with TF motifs and genomic coordinates BiocManager::install(c( 'motifmatchr', 'TFBSTools', 'GenomicRanges' )) # install database packages for human motifs & genomic features BiocManager::install(c( 'EnsDb.Hsapiens.v86', 'BSgenome.Hsapiens.UCSC.hg38' )) BiocManager::install(c( 'JASPAR2020', 'JASPAR2024' )) # install xgboost install.packages('xgboost') ``` ```R # load these packages into R: library(JASPAR2020) library(JASPAR2024) library(motifmatchr) library(TFBSTools) library(EnsDb.Hsapiens.v86) library(BSgenome.Hsapiens.UCSC.hg38) library(GenomicRanges) library(xgboost) ``` -------------------------------- ### Install R Packages for Network Analysis Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/network_visualizations.html Installs the fgsea, ggraph, and tidygraph R packages required for gene set enrichment analysis and network visualization. fgsea is used for Gene Ontology lists, while ggraph and tidygraph are used for creating and manipulating network graphs. ```r BiocManager::install('fgsea') install.packages(c("ggraph", "tidygraph")) library(ggraph) library(tidygraph) ``` -------------------------------- ### Add Warning in SetupForWGCNA Source: https://github.com/smorabit/hdwgcna/blob/dev/NEWS.md The `SetupForWGCNA` function now issues a warning if the user selects a very small number of genes. This aims to prevent potential issues arising from insufficient data. ```r New warning in `SetupForWGCNA` if the user selects a very small number of genes. - `MetaspotsByGroups` uses sparse matrix format internally. ``` -------------------------------- ### GetActiveWGCNAName Other Function Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/index.html Gets the active WGCNA name. ```R GetActiveWGCNAName() ``` -------------------------------- ### Include Fuse.js for Search Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/deps/data-deps.txt Includes the Fuse.min.js script (version 1.0.0), a lightweight fuzzy-玾 search library that improves search experience by matching partial or misspelled queries. ```html ``` -------------------------------- ### Include Clipboard.js Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/deps/data-deps.txt Includes the Clipboard.js library (version 2.0.11), a modern approach to copying text from DOM elements without using Flash. ```html ``` -------------------------------- ### Include Headroom JavaScript Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/deps/data-deps.txt Includes the Headroom.js library (version 0.11.0), a lightweight, high-performance widget to help users scroll to the top of a page. It's useful for sticky headers. ```html ``` -------------------------------- ### SetNetworkData Usage Example Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/SetNetworkData.html Illustrates the usage of the SetNetworkData function. It shows how to call the function with a Seurat object and network data, optionally specifying a name for the WGCNA experiment. ```R SetNetworkData(seurat_obj, net, wgcna_name = NULL) ``` -------------------------------- ### Run Standard hdWGCNA Workflow Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/sctransform.html Executes the standard hdWGCNA workflow using the 'RNA' assay. It sets up the Seurat object for WGCNA, constructs metacells, normalizes them, sets the expression data, tests soft powers, and constructs the WGCNA network. Dependencies include the Seurat and WGCNA packages. ```r # set default assay to RNA so we don't use SCTransform data DefaultAssay(seurat_subset) <- 'RNA' # setup hdWGCNA experiment seurat_subset <- SetupForWGCNA( seurat_subset, features = GetWGCNAGenes(seurat_subset, 'SCT'), wgcna_name = "RNA" ) # construct metacells seurat_subset <- MetacellsByGroups( seurat_obj = seurat_subset, group.by = c("Sample"), k = 25, max_shared=12, min_cells = 50, reduction = 'harmony', ident.group = 'Sample', slot = 'counts', assay = 'RNA' ) seurat_subset <- NormalizeMetacells(seurat_subset) seurat_subset <- SetDatExpr(seurat_subset) seurat_subset <- TestSoftPowers(seurat_subset) plot_list <- PlotSoftPowers(seurat_subset) # plot softpowers print(wrap_plots(plot_list, ncol=2)) # construct wgcna network: seurat_subset <- ConstructNetwork( seurat_subset, tom_name = "RNA", overwrite_tom = TRUE ) seurat_subset <- ModuleEigengenes(seurat_subset) seurat_subset <- ModuleConnectivity(seurat_subset) PlotDendrogram(seurat_subset, main='hdWGCNA RNA Dendrogram') ``` -------------------------------- ### ConstructPseudobulk Other Function Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/index.html Constructs a pseudobulk from metacells. ```R ConstructPseudobulk() ``` -------------------------------- ### Setup hdWGCNA with SCTransform Features (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/sctransform.html Configures a Seurat object for hdWGCNA analysis using features identified by SCTransform. This ensures that only relevant genes are used for WGCNA, aligning with the SCTransform preprocessing. ```r seurat_subset <- SetupForWGCNA( seurat_subset, features = VariableFeatures(seurat_subset), wgcna_name = "SCT" ) ``` -------------------------------- ### SetTFNetwork Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/index.html Sets the TF network. ```R SetTFNetwork() ``` -------------------------------- ### Download SEACells practice dataset Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/other_metacells.html Downloads the CD34+ hematopoietic stem and progenitor stem cells dataset provided with SEACells for the tutorial. This is a prerequisite for running the SEACells and MC2 analysis. ```bash wget https://dp-lab-data-public.s3.amazonaws.com/SEACells-multiome/cd34_multiome_rna.h5ad -O cd34_multiome_rna.h5ad ``` -------------------------------- ### Get PFM List from Seurat Object (R) Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/GetPFMList.html Retrieves the list of Position Frequency Matrix (PFM) objects from the 'misc' slot of a Seurat object. This function is part of the hdWGCNA package. ```R GetPFMList <- function (seurat_obj) { seurat_obj@misc$motifs$pfm_list } ``` -------------------------------- ### Get Module Preservation Statistics Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/module_preservation.html Retrieves the module preservation statistics from a Seurat object. This function returns tables containing Z-scores and observational data, which are crucial for interpreting module preservation. ```R # get the module preservation table mod_pres <- GetModulePreservation(seurat_query, "Zhou-INH")$Z obs_df <- GetModulePreservation(seurat_query, "Zhou-INH")$obs ``` -------------------------------- ### RunPCAMetacells Seurat Wrapper Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/index.html Runs PCA on metacells using Seurat. ```R RunPCAMetacells() ``` -------------------------------- ### Include Autocomplete.jquery.js for Search Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/deps/data-deps.txt Includes the Autocomplete.jquery.min.js script (version 1.0.0), used for providing type-ahead search suggestions, likely integrated with a search engine. ```html ``` -------------------------------- ### Plot WGCNA Dendrogram in R Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/reference/PlotDendrogram.html This function plots a WGCNA dendrogram, allowing for customization of labels, guides, and overall appearance. It requires a Seurat object containing WGCNA network data. ```R PlotDendrogram(seurat_obj, groupLabels = "Module colors", wgcna_name = NULL, dendroLabels = FALSE, hang = 0.03, addGuide = TRUE, guideHang = 0.05, main = "", ...) ``` -------------------------------- ### Load Libraries and Data for hdWGCNA Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/projecting_modules.html Loads necessary R libraries for single-cell analysis, data manipulation, plotting, WGCNA, hdWGCNA, and network analysis. It also loads reference and query Seurat objects for module projection. ```R # single-cell analysis package library(Seurat) # plotting and data science packages library(tidyverse) library(cowplot) library(patchwork) # co-expression network analysis packages: library(WGCNA) library(hdWGCNA) # network analysis & visualization package: library(igraph) # using the cowplot theme for ggplot theme_set(theme_cowplot()) # set random seed for reproducibility set.seed(12345) # load the Zhou et al snRNA-seq dataset seurat_ref <- readRDS('data/Zhou_control.rds') # load the Morabito & Miyoshi 2021 snRNA-seq dataset seurat_query <- readRDS(file=paste0(data_dir, 'Morabito_Miyoshi_2021_control.rds')) ``` -------------------------------- ### Initialize and Prepare Data Source: https://github.com/smorabit/hdwgcna/blob/dev/docs/articles/other_metacells.html Sets up the raw data and assigns observation and variable names. It also sets a name for the dataset, 'cd34', for future reference. ```python raw_ad.obs_names, raw_ad.var_names = adata.obs_names, adata.var_names adata.raw = raw_ad # name of the dataset mc.ut.set_name(adata, 'cd34') ```