annotate DESeq.Rmd @ 13:b50f1063a621 draft

Uploaded
author mingchen0919
date Mon, 07 Aug 2017 20:52:38 -0400
parents a5fdd120b2c7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
1 ---
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
2 title: 'DESeq2: Perform DESeq analysis'
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
3 output:
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
4 html_document:
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
5 number_sections: true
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
6 toc: true
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
7 theme: cosmo
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
8 highlight: tango
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
9 ---
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
10
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
11 ```{r setup, include=FALSE, warning=FALSE, message=FALSE}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
12 knitr::opts_chunk$set(
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
13 echo = ECHO
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
14 )
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
15
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
16 library(stringi)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
17 library(DESeq2)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
18 library(pheatmap)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
19 library(PoiClaClu)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
20 library(RColorBrewer)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
21 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
22
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
23 # `DESeqDataSet` object
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
24
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
25 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
26 count_files = strsplit(opt$count_files, ',')[[1]]
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
27 sample_table = read.table(opt$sample_table, header = TRUE)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
28
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
29 ## copy count files into working directory
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
30 file_copy = file.copy(count_files, sample_table$fileName, overwrite = TRUE)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
31
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
32 ## DESeqDataSet object
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
33 dds = DESeqDataSetFromHTSeqCount(sampleTable = sample_table,
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
34 directory = './',
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
35 design = DESIGN_FORMULA)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
36 dds
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
37 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
38
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
39 # Pre-filtering the dataset.
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
40
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
41 We can remove the rows that have 0 or 1 count to reduce object size and increase the calculation speed.
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
42
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
43 * Number of rows before pre-filtering
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
44 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
45 nrow(dds)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
46 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
47
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
48 * Number of rows after pre-filtering
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
49 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
50 dds = dds[rowSums(counts(dds)) > 1, ]
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
51 nrow(dds)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
52 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
53
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
54 # Peek at data {.tabset}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
55
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
56 ## Count Data
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
57
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
58 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
59 datatable(head(counts(dds), 100), style="bootstrap",
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
60 class="table-condensed", options = list(dom = 'tp', scrollX = TRUE))
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
61 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
62
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
63 ## Sample Table
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
64
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
65 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
66 datatable(sample_table, style="bootstrap",
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
67 class="table-condensed", options = list(dom = 'tp', scrollX = TRUE))
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
68 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
69
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
70 # Sample distance on variance stabilized data {.tabset}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
71
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
72 ## `rlog` Stabilizing transformation
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
73
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
74 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
75 rld = rlog(dds, blind = FALSE)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
76 datatable(head(assay(rld), 100), style="bootstrap",
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
77 class="table-condensed", options = list(dom = 'tp', scrollX = TRUE))
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
78 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
79
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
80 ## Sample distance
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
81
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
82 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
83 sampleDists <- dist(t(assay(rld)))
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
84 sampleDists
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
85 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
86
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
87 # Differential expression analysis
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
88
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
89 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
90 dds <- DESeq(dds)
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
91 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
92
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
93 ```{r}
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
94 rm("opt")
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
95 save(list=ls(all.names = TRUE), file='DESEQ_WORKSPACE')
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
96 ```
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
97
a5fdd120b2c7 Uploaded
mingchen0919
parents:
diff changeset
98