Mercurial > repos > mingchen0919 > rmarkdown_deseq2_count_matrix
comparison rmarkdown_deseq2_count_matrix.Rmd @ 1:629323b5fc0c draft
update tool
author | mingchen0919 |
---|---|
date | Sat, 30 Dec 2017 16:39:39 -0500 |
parents | c1f718dd6c7a |
children | 8ceda5896765 |
comparison
equal
deleted
inserted
replaced
0:c1f718dd6c7a | 1:629323b5fc0c |
---|---|
14 error = TRUE | 14 error = TRUE |
15 ) | 15 ) |
16 ``` | 16 ``` |
17 | 17 |
18 | 18 |
19 ## User input | 19 # User input |
20 | 20 |
21 ```{r 'user input'} | 21 ```{r 'user input'} |
22 df = data.frame(name = names(opt)[-1], | 22 df = data.frame(name = names(opt)[-1], |
23 value = unlist(opt)) | 23 value = unlist(opt)) |
24 df | 24 datatable(df, rownames = FALSE) |
25 ``` | 25 ``` |
26 | 26 |
27 | 27 |
28 ## Count Matrix | 28 # Count Matrix |
29 | |
30 Display the first 100 rows of count data matrix. | |
29 | 31 |
30 ```{r 'count matrix'} | 32 ```{r 'count matrix'} |
31 count_data = read.table(opt$count_data) | 33 count_data = read.table(opt$count_data) |
32 head(count_data, 10) | 34 col_names = trimws(strsplit(opt$count_matrix_column_names, ',')[[1]])[1:ncol(count_data)] |
35 col_names = col_names[!is.na(col_names)] | |
36 colnames(count_data)[1:length(col_names)] = col_names | |
37 datatable(head(count_data, 100)) | |
33 ``` | 38 ``` |
34 | 39 |
35 ```{r 'ste[ 2'} | 40 # Column Data |
36 | 41 |
42 ```{r 'column data'} | |
43 col_data = read.table(opt$col_data, | |
44 stringsAsFactors = FALSE, sep=',', header = TRUE, row.names = 1) | |
45 datatable(col_data) | |
46 ``` | |
47 | |
48 # Match sample names | |
49 | |
50 The goal of this step is to rearrange the rows of the column data matrix so that the samples rows in the count data matrix and the sample columns in the count data matrix are in the same order. | |
51 | |
52 ```{r 'match sample names'} | |
53 col_data = col_data[col_names, ] | |
54 datatable(col_data) | |
55 ``` | |
56 | |
57 # DESeqDataSet | |
58 | |
59 ```{r 'DeseqDataSet'} | |
60 dds = DESeqDataSetFromMatrix(countData = count_data, | |
61 colData = col_data, | |
62 design = formula(opt$design_formula)) | |
63 dds | |
64 ``` | |
65 | |
66 Pre-filter low count genes | |
67 | |
68 ```{r 'pre-filtering'} | |
69 keep = rowSums(counts(dds)) >= 10 | |
70 dds = dds[keep, ] | |
71 dds | |
72 ``` | |
73 | |
74 # Differential expression analysis | |
75 | |
76 ```{r 'differential expression analysis'} | |
77 dds = DESeq(dds) | |
78 # res = results(dds, contrast = c(opt$contrast_condition, opt$treatment, opt$control)) | |
79 res = results(dds) | |
80 resultsNames(dds) | |
81 if(nrow(res) > 500) { | |
82 cat('The result table has more than 500 rows. Only 500 rows are randomly selected to dispaly.') | |
83 datatable(as.data.frame(res)[sample(1:nrow(res), 500), ]) | |
84 } else { | |
85 datatable(as.data.frame(res)) | |
86 } | |
37 ``` | 87 ``` |
38 | 88 |
39 | 89 |
90 | |
91 ```{r 'write results into csv'} | |
92 #Write results into a CSV file. | |
93 write.csv(res, 'differential_genes.csv') | |
94 ``` | |
95 | |
96 # MAplot | |
97 | |
98 ```{r} | |
99 plotMA(res) | |
100 ``` | |
101 | |
102 | |
103 ```{r 'save R objects'} | |
104 # Save R objects to a file | |
105 save(dds, opt, file = 'deseq2.RData') | |
106 ``` | |
107 |