-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathComp_DEG.Rmd
executable file
·240 lines (168 loc) · 6.8 KB
/
Comp_DEG.Rmd
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE, warning = FALSE, message = FALSE)
```
##Purpose:
Figure 3 -- DGE Analysis prime/TruSeq
#Protocol:
###1. Load the following packages:
```{r packages}
library(tidyverse)
library(ggsignif)
library(ggrepel)
library(edgeR)
library(genefilter)
library(grid)
library(gridExtra)
library(ggsci)
library(UpSetR)
library(cowplot)
library(Seurat)
library(DESeq2)
library(biomaRt)
library(EnhancedVolcano)
```
###2. Load following functions:
```{r functions}
## all necessary custom functions are in the following script
source("/data/share/htp/prime-seq_Paper/Scripts/custom_functions.R")
#prevent scientific notation
options(scipen=999)
theme_pub <- theme_bw() + theme(
plot.title = element_text(hjust = 0.5, size=18, face="bold"),
axis.text = element_text(colour="black", size=14),
axis.title=element_text(size=16,face="bold"),
legend.text=element_text(size=14),
legend.position="right",
axis.line.x = element_line(colour = "black"),
axis.line.y = element_line(colour = "black"),
strip.background=element_blank(),
strip.text=element_text(size=16))
fig_path<-"/data/share/htp/prime-seq_Paper/Fig_maqc_comparison/"
```
###4. tru vs prime-seq
```{r tru_vs_prime}
counts_prime <- readRDS(paste0(fig_path,"/zUMIs/prime-seq/zUMIs_output/expression/prime-seq.dgecounts.rds"))
counts_tru <- readRDS(paste0(fig_path,"/zUMIs/SEQC_PE/zUMIs_output/expression/SEQC_PE.dgecounts.rds"))
inf <- read.csv(paste0(fig_path,"/sample_info.csv"), header = T, stringsAsFactors = F)
##subset data
#inex
inex_prime <- as.matrix(counts_prime$readcount$inex$downsampling$downsampled_10000000) %>% remove_Geneversion()
inex_tru <- as.matrix(counts_tru$readcount$inex$downsampling$downsampled_10000000) %>% remove_Geneversion()
#combine count tables
inex <- merge(inex_prime, inex_tru, by = "row.names", all = TRUE)
inex[is.na(inex)] <- 0
rownames(inex) <- inex[,1]
inex$Row.names <- NULL
#remove ERCCs
inex <- inex[grep("ERCC", row.names(inex), invert = TRUE) ,]
inex <- inex[whichgenes_reproducible(exprtable = inex,exprcutoff = 5,reproducecutoff = 0.24),]
##DESeq2
des <- DESeqDataSetFromMatrix( countData = inex,
colData = inf,
design = ~ 0 + Method)
des <- DESeq(des, test = "Wald")
tru_vs_prime <- results(des, contrast = c("Method", "tru", "prime"), alpha = 0.05)
tru_vs_prime <- na.omit(tru_vs_prime)
summary(tru_vs_prime)
tru_vs_prime_a <- as.data.frame(tru_vs_prime)
table(abs(tru_vs_prime_a$log2FoldChange)>1 &tru_vs_prime_a$padj<0.05)
plot(density(tru_vs_prime_a$log2FoldChange))
saveRDS(tru_vs_prime_a,"/data/share/htp/prime-seq_Paper/Fig_maqc_comparison/Analysis/UHRR_Comparison/tru_vs_prime_lfcs.rds")
##volcano plot
# create custom key-value pairs for 'high', 'low', 'mid' expression by fold-change
# set the base colour as 'black'
keyvals <- rep('black', nrow(tru_vs_prime))
# set the base name/label as 'Neither'
names(keyvals) <- rep('Neither', nrow(tru_vs_prime))
# modify keyvals for variables with fold change > 1
keyvals[which((tru_vs_prime$log2FoldChange > 1) & (tru_vs_prime$padj < 10e-6))] <- 'gray70'
names(keyvals)[which((tru_vs_prime$log2FoldChange > 1) & (tru_vs_prime$padj < 10e-6))] <- 'Upregulated in TruSeq'
# modify keyvals for variables with fold change < -1
keyvals[which((tru_vs_prime$log2FoldChange < -1) & (tru_vs_prime$padj < 10e-6))] <- '#008080'
names(keyvals)[which((tru_vs_prime$log2FoldChange < -1) & (tru_vs_prime$padj < 10e-6))] <- 'Upregulated in prime-seq'
unique(names(keyvals))
Fig3_volcano <- EnhancedVolcano(tru_vs_prime,
lab = rownames(tru_vs_prime),
selectLab = "",
x = 'log2FoldChange',
y = 'padj',
xlab = bquote(~Log[2]~ 'fold change'),
ylab = bquote(~-Log[10]~adjusted~italic(P)),
pCutoff = 10e-6,
FCcutoff = 1,
title = "prime-seq vs. TruSeq",
subtitle = element_blank(),
colCustom = keyvals,
colAlpha = 1,
legendPosition = "none")
## length and gc
#df with genes and which cond it is upregulated in
tru_vs_prime_a$ENSEMBL <- row.names(tru_vs_prime_a)
tru_vs_prime_a_filt <- tru_vs_prime_a %>% filter(padj >0.05) %>% filter(abs(log2FoldChange) > 2)
tru_vs_prime_a_tru <- tru_vs_prime_a_filt %>% filter(log2FoldChange > 2)
tru_vs_prime_a_prime <- tru_vs_prime_a_filt %>% filter(log2FoldChange < -2)
tru_vs_prime_a_tru$Upregulated <- "TruSeq"
tru_vs_prime_a_prime$Upregulated <- "prime-seq"
tru_vs_prime_a_filt <- bind_rows(tru_vs_prime_a_tru, tru_vs_prime_a_prime)
#BM length and gc
ensembl<-useMart("ensembl",
dataset="hsapiens_gene_ensembl", host="uswest.ensembl.org")
info_L_GC <- getBM(attributes = c("ensembl_gene_id", "external_gene_name",
"transcript_length",
"percentage_gene_gc_content"),
filters = "ensembl_gene_id",
values = tru_vs_prime_a_filt$ENSEMBL,
mart = ensembl) %>%
group_by(ensembl_gene_id) %>%
summarise(length= round(mean( transcript_length )),
gc = round(mean(percentage_gene_gc_content)))
colnames(info_L_GC) <- c("ENSEMBL", "Length", "GC")
tru_vs_prime_a_filt <- left_join(tru_vs_prime_a_filt, info_L_GC, by = "ENSEMBL")
plot_length_a <- ggplot(tru_vs_prime_a_filt, aes(x=Length, fill = Upregulated)) +
geom_density(alpha=0.5) +
scale_x_continuous(trans = "log10",expand = c(0, 0)) +
ylim(0,1.5)+
xlab(bquote(~Log[10]~length)) +
theme_pub+
scale_fill_manual(values =c("#008080","gray70"))+
theme(legend.title = element_blank(),
legend.position="none",
strip.text.y = element_text(angle = 360))
plot_gc_a <- ggplot(tru_vs_prime_a_filt, aes(x=GC, fill = Upregulated)) +
geom_density(alpha=0.5) +
scale_x_continuous(trans = "log10",expand = c(0, 0)) +
ylim(0,10)+
xlab("Percent GC Content") +
theme_pub+
scale_fill_manual(values =c("#008080","gray70"))+
theme(legend.title = element_blank(),
legend.position="bottom",
strip.text.y = element_text(angle = 360))
```
###7. Figures
```{r}
Fig3_density <- cowplot::plot_grid(plot_length_a, plot_gc_a,
ncol = 1,
nrow = 2,
rel_heights = c(5,6)
)
```
###8. Save
```{r}
ggsave(Fig3_density,
device = "pdf",
path = fig_path,
width = 125,
height=125,
units = "mm",
filename = "Fig3_length_gc.pdf"
)
ggsave(Fig3_volcano,
device = "pdf",
path = fig_path,
width = 125,
height=125,
units = "mm",
filename = "Fig3_volcano.pdf"
)
```