-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDEG_analysis20181107.R
140 lines (103 loc) · 5.85 KB
/
DEG_analysis20181107.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
### Differential Gene Expression analysis for RNA-seq samples ###
### Hanna Schilbert ###
### hschilbe@cebitec.uni-bielefeld.de ###
### Boas Pucker ###
### bpucker@cebitec.uni-bielefeld.de ###
# --- loading DESeq --- #
library("DESeq2")
# --- loading sampleTable (generated by Python script) --- #
csvfile <- "clean_sample_table.txt"
sampleTable <- read.csv(csvfile, row.names=1, sep="\t")
sampleTable$diet <- as.factor( sampleTable$diet )
sampleTable$genotype <- as.factor( sampleTable$genotype )
genotype <- sampleTable$genotype
diet <- sampleTable$diet
group <- factor(paste(genotype, diet, sep="."))
sampleTable <- cbind(sampleTable, group=group)
summary(sampleTable)
# --- loading the data matrix --- #
count_data_file <- "clean_data_matrix.txt"
countdata <- read.csv(count_data_file,row.names=1, header=T, sep="\t")
summary(countdata)
# --- set working dir where all files will be saved later --- #
"working dir set to:"
(working_dir = "xxx")
setwd( working_dir )
# -- removal of not or low expressed genes --- #
# Current option: removal of genes if less than 50 percent of all samples show expression above cutoff
thres = 2
nzIndex = as.vector(which(apply(countdata,1,function(x){sum(x>thres)/length(x)})>=0.5))
head(nzIndex)
countdata1 = countdata[nzIndex,]
"number of genes after eliminating low expressed genes:"
nrow(countdata1)
"amount of eliminated genes:"
(nr_eliminated_genes <- nrow(countdata) - nrow(countdata1))
# --- construction of DESeqDataSet --- #
dds <- DESeqDataSetFromMatrix( countData=countdata1, colData=sampleTable, design = ~ group )
"number of genes in matrix:"
nrow(dds)
# --- differential expression analysis --- #
dds <- DESeq(dds)
resultsNames(dds)
# --- analyze diet effect for each genotype --- #
"diet effect on genotype I = WT:"
WaldresultsWT <- results(dds, contrast=c("group","WT.HFD45.","WT.Chow"))
summary(WaldresultsWT)
"diet effect on genotype II = HET:"
WaldresultsHET <- results(dds, contrast=c("group","HET.HFD45.","HET.Chow"))
summary(WaldresultsHET)
"diet effect on genotype III = KO:"
WaldresultsKO <- results(dds, contrast=c("group","KO.HFD45.","KO.Chow"))
summary(WaldresultsKO)
# --- Extraction of significantly differentially expressed genes ordered by adjusted p value -- #
WaldresultsWTOrdered = WaldresultsWT[order(WaldresultsWT$padj),]
write.table(WaldresultsWTOrdered, file='diff_genes_HFD45_effect_WT_padj1_all.txt',sep='\t',quote=FALSE)
WaldresultsHETOrdered = WaldresultsHET[order(WaldresultsHET$padj),]
write.table(WaldresultsHETOrdered, file='diff_genes_HFD45_effect_HET_all.txt',sep='\t',quote=FALSE)
WaldresultsKOOrdered = WaldresultsKO[order(WaldresultsKO$padj),]
write.table(WaldresultsKOOrdered, file='diff_genes_HFD45_effect_KO_all.txt',sep='\t',quote=FALSE)
# --- identificaiton of differentially expressed genes between genotypes due to diet effect --- #
dWT_HET <- results(dds, contrast=list(c("groupWT.HFD45.", "groupHET.Chow"),c("groupWT.Chow","groupHET.HFD45.")))
summary(dWT_HET)
dWT_KO <- results(dds, contrast=list(c("groupWT.HFD45.", "groupKO.Chow"),c("groupWT.Chow","groupKO.HFD45.")))
summary(dWT_KO)
dKO_HET <- results(dds, contrast=list(c("groupKO.HFD45.", "groupHET.Chow"),c("groupKO.Chow","groupHET.HFD45.")))
summary(dKO_HET)
# --- extraction of significantly differentially expressed genes ordered by adjusted p value --- #
dWT_HETOrdered = dWT_HET[order(dWT_HET$padj),]
write.table(dWT_HETOrdered, file='diff_genes_between_genotypes_due_to_HFD45_dWT_HET_all.txt',sep='\t',quote=FALSE)
dWT_KOOrdered = dWT_KO[order(dWT_KO$padj),]
write.table(dWT_KOOrdered, file='diff_genes_between_genotypes_due_to_HFD45_dWT_KO_all.txt',sep='\t',quote=FALSE)
dKO_HETOrdered = dKO_HET[order(dKO_HET$padj),]
write.table(dKO_HETOrdered, file='diff_genes_between_genotypes_due_to_HFD45_dKO_HET_all.txt',sep='\t',quote=FALSE)
# --- identification of DEG due to genotype effect and without diet effect --- #
wo_de_KO_WT <- results(dds, contrast=c("group","KO.Chow","WT.Chow"))
summary(wo_de_KO_WT)
wo_de_WT_HET <- results(dds, contrast=c("group","HET.Chow","WT.Chow"))
summary(wo_de_WT_HET)
wo_de_KO_HET <- results(dds, contrast=c("group","KO.Chow","HET.Chow"))
summary(wo_de_KO_HET)
# --- extraction of significantly differentially expressed genes ordered by adjusted p value --- #
wo_de_KO_WTOrdered = wo_de_KO_WT[order(wo_de_KO_WT$padj),]
write.table(wo_de_KO_WTOrdered, file='diff_genes_genotype_effect_in_chow_WT_KO_all.txt',sep='\t',quote=FALSE)
wo_de_WT_HETOrdered = wo_de_WT_HET[order(wo_de_WT_HET$padj),]
write.table(wo_de_WT_HETOrdered, file='diff_genes_genotype_effect_in_chow_WT_HET_all.txt',sep='\t',quote=FALSE)
wo_de_KO_HETOrdered = wo_de_KO_HET[order(wo_de_KO_HET$padj),]
write.table(wo_de_KO_HETOrdered, file='diff_genes_genotype_effect_in_chow_KO_HET_all.txt',sep='\t',quote=FALSE)
# --- identification of DEGs due to genotype effect and with diet effect --- #
w_de_KO_WT <- results(dds, contrast=c("group","KO.HFD45.","WT.HFD45."))
summary(w_de_KO_WT)
w_de_WT_HET <- results(dds, contrast=c("group","HET.HFD45.","WT.HFD45."))
summary(w_de_WT_HET)
w_de_KO_HET <- results(dds, contrast=c("group","KO.HFD45.","HET.HFD45."))
summary(w_de_KO_HET)
# --- extraction of significantly differentially expressed genes ordered by adjusted p value --- #
w_de_KO_WTOrdered = w_de_KO_WT[order(w_de_KO_WT$padj),]
write.table(w_de_KO_WTOrdered, file='diff_genes_genotype_effect_in_HFD45_WT_KO_all.txt',sep='\t',quote=FALSE)
w_de_WT_HETOrdered = w_de_WT_HET[order(w_de_WT_HET$pval),]
write.table(w_de_WT_HETOrdered, file='diff_genes_genotype_effect_in_HFD45_WT_HET_all.txt',sep='\t',quote=FALSE)
w_de_KO_HETOrdered = w_de_KO_HET[order(w_de_KO_HET$padj),]
write.table(w_de_KO_HETOrdered, file='diff_genes_genotype_effect_in_HFD45_KO_HET_all.txt',sep='\t',quote=FALSE)
# --- print session information --- #
sessionInfo()