22title : " Weighted Gene Co-Expression Network Analysis (WGCNA)"
33author : " Harvard Chan Bioinformatics Core"
44date : " `r Sys.Date()`"
5- output :
6- html_document :
7- code_folding : hide
8- df_print : paged
9- highlights : pygments
10- number_sections : true
11- self_contained : true
12- theme : default
13- toc : true
14- toc_float :
15- collapsed : true
16- smooth_scroll : true
17- editor_options :
18- chunk_output_type : inline
5+ format :
6+ html :
7+ code-fold : true
8+ code-tools : true
9+ code-overflow : wrap
10+ df-print : paged
11+ highlight-style : pygments
12+ number-sections : true
13+ self-contained : true
14+ theme : default
15+ toc : true
16+ toc-location : right
17+ toc-expand : false
18+ lightbox : true
1919params :
2020 minModuleSize : 30
2121 maxBlockSize : 4000
@@ -29,11 +29,12 @@ params:
2929 functions_file : ../00_libs
3030---
3131
32- ``` {r, message=FALSE, warning=FALSE}
32+ ``` {r}
33+ #| message: FALSE
34+ #| warning: FALSE
3335# This set up the working directory to this file so all files can be found
3436library(rstudioapi)
3537library(tidyverse)
36- setwd(fs::path_dir(getSourceEditorContext()$path))
3738# NOTE: This code will check version, this is our recommendation, it may work
3839# . other versions
3940stopifnot(R.version$major >= 4) # requires R4
@@ -44,7 +45,10 @@ stopifnot(compareVersion(as.character(BiocManager::version()), "3.18") >= 0)
4445This code is in this ![ ] ( https://img.shields.io/badge/status-alpha-yellow ) revision.
4546
4647
47- ``` {r load_params, cache = FALSE, message = FALSE, warning=FALSE}
48+ ``` {r load_params}
49+ #| cache: FALSE
50+ #| message: FALSE
51+ #| warning: FALSE
4852source(params$project_file)
4953source(params$params_file)
5054map(list.files(params$functions_file, pattern = "*.R$", full.names = T), source) %>% invisible()
@@ -65,7 +69,10 @@ sanitize_datatable <- function(df, ...) {
6569```
6670
6771
68- ``` {r load_libraries, cache = FALSE, message = FALSE, warning=FALSE}
72+ ``` {r load_libraries}
73+ #| cache: FALSE
74+ #| message: FALSE
75+ #| warning: FALSE
6976library(WGCNA)
7077library(tidyverse)
7178library(DESeq2)
@@ -163,7 +170,10 @@ WGCNA creates a weighted network to define which genes are near each other. The
163170
164171The choice of power parameter will affect the number of modules identified. WGCNA has a function called pickSoftThreshold() to help determine the soft power threshold.
165172
166- ``` {r, message=FALSE, warning=FALSE,fig.align='center'}
173+ ``` {r}
174+ #| message: FALSE
175+ #| warning: FALSE
176+ #| fig-align: 'center'
167177# determine parameters for WGCNA
168178sft <- pickSoftThreshold(normalized_counts,
169179 dataIsExpr = TRUE,
@@ -193,7 +203,9 @@ It is recommend to use a power that has an signed R2 above 0.80, otherwise the r
193203
194204We will use the blockwiseModules() with power threshold of 20 to find co-expressed genes. It will construct modules with group of genes that are highly correlated.
195205
196- ``` {r, message=FALSE, warning=FALSE}
206+ ``` {r}
207+ #| message: FALSE
208+ #| warning: FALSE
197209# picking a soft threshold power near the curve of the plot
198210picked_power <- 20 ## pick a power here based on the above plot and instruction
199211temp_cor <- cor
@@ -234,14 +246,20 @@ readr::write_rds(bwnet,
234246
235247A module eigengene is the standardized gene expression profile for a given module. An eigengene is the gene whose expression is representative of the majority of the genes within a module.
236248
237- ``` {r, message=FALSE, warning=FALSE}
249+ ``` {r}
250+ #| message: FALSE
251+ #| warning: FALSE
238252module_eigengens <- bwnet$MEs
239253datatable(module_eigengens, options = list(pageLength = 10, scrollX = TRUE))
240254```
241255
242256## Dendogram for the modules
243257
244- ``` {r, fig.align='center', fig.width=12, message=FALSE, warning=FALSE}
258+ ``` {r}
259+ #| fig-align: 'center'
260+ #| fig-width: 12
261+ #| message: FALSE
262+ #| warning: FALSE
245263# Convert labels to colors for plotting
246264mergedColors <- labels2colors(bwnet$colors)
247265# Plot the dendrogram and the module colors underneath
@@ -258,7 +276,9 @@ plotDendroAndColors(bwnet$dendrograms[[1]],
258276### Relating modules (Clusters) to geneIds.
259277GeneIds with their module color and number are given on the table below.
260278
261- ``` {r, message=FALSE, warning=FALSE}
279+ ``` {r}
280+ #| message: FALSE
281+ #| warning: FALSE
262282# Relating modules (Clusters) to genotypes
263283module_df <- data.frame(
264284 gene_id = names(bwnet$colors),
@@ -274,7 +294,9 @@ write_delim(module_df, file = "List_of_genes_with_modules.txt", delim = "\t")
274294
275295WGCNA calcualtes and Eigengene (hypothetical central gene) for each module which makes it easier to associate sample groups with module cluster.
276296
277- ``` {r, message=FALSE, warning=FALSE}
297+ ``` {r}
298+ #| message: FALSE
299+ #| warning: FALSE
278300# Get Module Eigengens per cluster
279301MEs0 <- moduleEigengenes(normalized_counts, mergedColors)$eigengenes
280302
@@ -294,7 +316,11 @@ mME <- MEs0 %>%
294316 )
295317```
296318
297- ``` {r, fig.align='center', fig.height=8, message=FALSE, warning=FALSE}
319+ ``` {r}
320+ #| fig-align: 'center'
321+ #| fig-height: 8
322+ #| message: FALSE
323+ #| warning: FALSE
298324mME %>% ggplot(., aes(x = samples, y = name, fill = value)) +
299325 geom_tile() +
300326 theme_bw() +
@@ -317,7 +343,9 @@ We can also use another approach to extract only the modules with biggest differ
317343## Modules with biggest differences across treatments
318344We will create a design matrix using ` sample_type ` in our metadata and run linear model on each module.
319345
320- ``` {r, message=FALSE, warning=FALSE}
346+ ``` {r}
347+ #| message: FALSE
348+ #| warning: FALSE
321349# to confirm our eigengens relate to our metadata from deseq object run the line below
322350# all.equal(colnames(dds), rownames(module_eigengens))
323351
0 commit comments