You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lessons/wk6_lesson05_deseq2_analysis.md
+26-1Lines changed: 26 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Gene-level differential expression analysis with DESeq2"
3
3
author: "Harvard HPC Staff, Adapted by Sally Chang at NICHD"
4
-
date: "Last Modified March 2025"
4
+
date: "Last Modified May 2025"
5
5
---
6
6
7
7
Approximate time: 60 minutes
@@ -13,6 +13,31 @@ Approximate time: 60 minutes
13
13
- Inspect gene-level dispersion estimates
14
14
- Recognize the importance of dispersion during differential expression analysis
15
15
16
+
## Catch-Up Script
17
+
18
+
If you need to be completely caught up, you can copy and paste the following into an R Script and run it. If you don't already have the files in your `/data` directory, please see [Wk 5 Lesson 01](../wk5_lesson01_introR_Rstudio.md) for instructions on where to obtain the input files.
19
+
20
+
```r
21
+
# Setup
22
+
# Bioconductor and CRAN libraries used - already installed on Biowulf
Copy file name to clipboardExpand all lines: lessons/wk7_lesson01_hypothesis_testing.md
+57-2Lines changed: 57 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Hypothesis testing and multiple testing"
3
3
author: "Harvard HPC Staff, Adapted by Sally Chang @ NICHD"
4
-
date: "Last Modified February 2025"
4
+
date: "Last Modified May 2025"
5
5
---
6
6
7
7
Approximate time: 60 minutes
@@ -13,13 +13,40 @@ Approximate time: 60 minutes
13
13
- Recognize the importance of multiple test correction
14
14
- Identify different methods for multiple test correction
15
15
16
+
## Catch-Up Script
17
+
18
+
If you need to be completely caught up, you can copy and paste the following into an R Script and run it. If you don't already have the files in your `/data` directory, please see [Wk 5 Lesson 01](../wk5_lesson01_introR_Rstudio.md) for instructions on where to obtain the input files.
19
+
20
+
```r
21
+
# Setup
22
+
# Bioconductor and CRAN libraries used - already installed on Biowulf
Remember to get your HPC On Demand session going, if applicable, and open your `DEAnalysis` R project!
42
+
16
43
# DESeq2: Model fitting and Hypothesis testing
17
44
18
45
The final step in the DESeq2 workflow is taking the counts for each gene and fitting it to the model and testing for differential expression.
19
46
20
47
<palign="center">
21
48
22
-
<imgsrc="../img/deseq_workflow_full_2018.png"width="385"alt="deseq full workflow"/>
49
+
<imgsrc="../img/deseq_workflow_full_2018.png"alt="deseq full workflow"width="385"/>
23
50
24
51
</p>
25
52
@@ -151,6 +178,34 @@ DESeq2 helps reduce the number of genes tested by removing those genes unlikely
151
178
152
179
By setting the FDR cutoff to \< 0.05, we're saying that the proportion of false positives we expect amongst our differentially expressed genes is 5%. For example, if you call 500 genes as differentially expressed with an FDR cutoff of 0.05, you expect 25 of them to be false positives.
153
180
181
+
## Your DE script
182
+
183
+
In this lesson, we took the additional step of running an additional DESeq2 analysis using a Likelihood Ratio Test to create the `dds_lrt` object . Your `de_script.R` should now contain the following commands to re-create necessary data objects (click to show):
184
+
185
+
```r
186
+
# Setup
187
+
# Bioconductor and CRAN libraries used - already installed on Biowulf
*This lesson has been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.*
Copy file name to clipboardExpand all lines: lessons/wk7_lesson02_wald_test.md
+51-58Lines changed: 51 additions & 58 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "Exploring DESeq2 results: Wald test"
3
3
author: "Harvard HPC Staff, adapted by Sally Chang at NICHD"
4
-
edited: "Last Modified March 2025"
4
+
edited: "Last Modified May 2025"
5
5
---
6
6
7
7
Approximate time: 60 minutes
@@ -12,6 +12,36 @@ Approximate time: 60 minutes
12
12
- Summarize the different levels of gene filtering
13
13
- Explain log fold change shrinkage
14
14
15
+
## Catch-Up Script
16
+
17
+
If you need to be completely caught up, you can copy and paste the following into an R Script and run it. If you don't already have the files in your `/data` directory, please see [Wk 5 Lesson 01](../wk5_lesson01_introR_Rstudio.md) for instructions on where to obtain the input files.
18
+
19
+
```r
20
+
# Setup
21
+
# Bioconductor and CRAN libraries used - already installed on Biowulf
Remember to get your HPC On Demand session going, if applicable, and open your `DEAnalysis` R project!
44
+
15
45
# Exploring Results (Wald test)
16
46
17
47
By default DESeq2 uses the Wald test to identify genes that are differentially expressed between two sample classes. Given the factor(s) used in the design formula, and how many factor levels are present, we can extract results for a number of different comparisons. Here, we will walk through how to obtain results from the `dds` object and provide some explanations on how to interpret them.
@@ -56,28 +86,14 @@ Alternatively, if you **only had two factor levels you could do nothing** and no
56
86
To start, we want to evaluate **expression changes between the MOV10 overexpression samples and the control samples**. As such we will use the first method for specifying contrasts and create a character vector:
57
87
58
88
```r
59
-
## Define contrasts for MOV10 overexpression
89
+
## Define contrasts for MOV10 overexpression - please run this!
> ### Does it matter what I choose to be my base level?
64
94
>
65
95
> Yes, it does matter. **Deciding what level is the base level will determine how to interpret the fold change that is reported.** So for example, if we observe a log2 fold change of -2 this would mean the gene expression is lower in factor level of interest relative to the base level. Thus, if leaving it up to DESeq2 to decide on the contrasts be sure to check that the alphabetical order coincides with the fold change direction you are anticipating.
66
96
67
-
## Getting Ready to work in R
68
-
69
-
1.Get your HPC On Demand session going:
70
-
71
-
- Opening up RStudio using [HPC on Demand](https://hpcondemand.nih.gov/pun/sys/dashboard/), using default values except for Starting Directory: `/data/Bspc-training/YOUR_USERNAME/rnaseq`
72
-
73
-
- To check whether or not you are in the correct working directory, use `getwd()`. Something like `/vf/users/Bspc-training/changes/rnaseq` should come up.
74
-
75
-
- Using the Project menu in the top right corner, or the Files Pane window (clicking rnaseq -\> DEanalysis), to navigate to and open `DEanalysis.Rproj`
76
-
77
-
2. We are assuming that you have the `dds` object in your environment and your packages are loaded - run your `de_setup.R` script if needed!
78
-
79
-
3. Run the actual DESeq2 analysis if needed `dds <- DESeq(dds)`.
80
-
81
97
## The results table
82
98
83
99
Now that we have our contrast created, we can use it as input to the `results()` function. Let's take a quick look at the help manual for the function:
@@ -102,17 +118,13 @@ The results table that is returned to us is **a `DESeqResults` object**, which i
102
118
class(res_tableOE)
103
119
```
104
120
105
-
Now let's take a look at **what information is stored** in the results:
121
+
Now let's take a look at **what information is stored** in the results, using nested functions that convert `res_table0E` into a data frame that we can then View:
106
122
107
123
```r
108
124
# What is stored in results?
109
-
res_tableOE %>%
110
-
data.frame() %>%
111
-
View()
125
+
View(data.frame(res_tableOE))
112
126
```
113
127
114
-
> **Discussion:** The `%>%` acts as a pipe symbol in R. This functionality comes as part of the [`dplyr`](https://dplyr.tidyverse.org/) package, which was loaded as part of the `tidyverse` that we loaded at the beginning of our lessons. Knowing this, what exactly is the code above doing?
115
-
116
128
We have six columns of information reported for each gene (row). We can use the `mcols()` function to extract information on what the values stored in each column represent:
117
129
118
130
```r
@@ -151,13 +163,14 @@ The missing values represent genes that have undergone filtering as part of the
151
163
If within a row, all samples have zero counts there is no expression information and therefore these genes are not tested.
152
164
153
165
```r
154
-
# Filter genes by zero expression
155
-
res_tableOE[which(res_tableOE$baseMean==0),] %>%
156
-
data.frame() %>%
157
-
View()
166
+
# Filter genes by zero expression and view using the same type of nested command as above
> **The baseMean column for these genes will be zero, and the log2 fold change estimates, p-value and adjusted p-value will all be set to NA.*How would you adjust the command above to count the number of rows matching this condition*?**
173
+
> **The baseMean column for these genes will be zero, and the log2 fold change estimates, p-value and adjusted p-value will all be set to NA.**
161
174
162
175
**2. Genes with an extreme count outlier**
163
176
@@ -166,11 +179,9 @@ The `DESeq()` function calculates, for every gene and for every sample, a diagno
166
179
```r
167
180
# Filter genes that have an extreme outlier by looking for those rows that have a non-zero base mean but no values for p-value and adjusted p-value. Do we actually have any of these?
The problem is, these fold change estimates are not entirely accurate as they do not account for the large dispersion we observe with low read counts. To address this, the **log2 fold changes need to be adjusted**.
220
229
221
-
**This is where we stopped on Tuesday of Week 7!**
### More accurate LFC estimates: Picking up again from Tuesday
226
-
227
-
1.Get your HPC On Demand session going:
228
-
229
-
- Opening up RStudio using [HPC on Demand](https://hpcondemand.nih.gov/pun/sys/dashboard/), using default values except for Starting Directory and **INCREASE MEMORY TO 8G**: `/data/Bspc-training/YOUR_USERNAME/rnaseq`
230
-
231
-
- To check whether or not you are in the correct working directory, use `getwd()`. Something like `/vf/users/Bspc-training/changes/rnaseq` should come up.
232
-
233
-
- Using the Project menu in the top right corner, or the Files Pane window (clicking rnaseq -\> DEanalysis), to navigate to and open `DEanalysis.Rproj`
234
-
235
-
2. We are assuming that you have the `dds` object in your environment and your packages are loaded - run your `de_setup.R` script if needed!
236
-
237
-
3. Run the actual DESeq2 analysis if needed `dds <- DESeq(dds)`.
232
+
## More accurate LFC estimates
238
233
239
234
To generate more accurate log2 foldchange (LFC) estimates, DESeq2 allows for the **shrinkage of the LFC estimates toward zero** when the information for a gene is low, which could include:
240
235
@@ -329,11 +324,11 @@ Now that we have results for the overexpression results, do the same for the **C
329
324
3. Shrink the LFC estimates using `lfcShrink()` and assign it back to `res_tableKD`.
330
325
4. Store the code you used to do the above exercises in an RScript named `control_vs_kd.R` .
331
326
332
-
## R Script updates:
327
+
## R Script updates:
333
328
334
329
Here is what your `de_setup.R` script should look like now to regenerate all the R objects we will need to the next lesson:
335
330
336
-
```r
331
+
```r
337
332
# Gene-level differential expression analysis using DESeq2
*This lesson has been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.*
374
-
375
-
*Some materials and hands-on activities were adapted from [RNA-seq workflow](http://www.bioconductor.org/help/workflows/rnaseqGene/#de) on the Bioconductor website*
|*This lesson has been developed by members of the teaching team at the [Harvard Chan Bioinformatics Core (HBC)](http://bioinformatics.sph.harvard.edu/). These are open access materials distributed under the terms of the [Creative Commons Attribution license](https://creativecommons.org/licenses/by/4.0/) (CC BY 4.0), which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited.*|
370
+
|*Some materials and hands-on activities were adapted from [RNA-seq workflow](http://www.bioconductor.org/help/workflows/rnaseqGene/#de) on the Bioconductor website*|
0 commit comments