-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAnalisis.qmd
353 lines (269 loc) · 11.2 KB
/
Analisis.qmd
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
---
title: "RNASeq Navarra"
format:
html:
toc: true
toc-location: left
editor: visual
---
<https://irycisbioinfo.github.io/ReportNavarraRNASeq/>
# RNASeq Report
All the data of this analysis can be found in <https://github.com/irycisBioinfo/ReportNavarraRNASeq>
```{r message=FALSE, warning=FALSE}
library(DESeq2)
library(tidyverse)
library(ggrepel)
library(ggsci)
```
# Load Data
Data from primary analisis workflow <https://nf-co.re/rnaseq/3.14.0/> are loaded among metadata.
```{r message=FALSE, warning=FALSE}
reads_genes <- read_tsv("/storage2/Hincode/S-60-47-61-2024-RNASeq_0240725_LH00206_0043_A22MLN2LT3/navarra/results_strand/star_salmon/salmon.merged.gene_counts_length_scaled.tsv")
reads_transcripts <- read_tsv("/storage2/Hincode/S-60-47-61-2024-RNASeq_0240725_LH00206_0043_A22MLN2LT3/navarra/results_strand/star_salmon/salmon.merged.transcript_counts.tsv")
ids <- read_tsv("/storage2/Hincode/S-60-47-61-2024-RNASeq_0240725_LH00206_0043_A22MLN2LT3/navarra/results_strand/star_salmon/salmon_tx2gene.tsv", col_names = c("Transcrip_ID","Gene_ID","Gene_Name"))
metadata <- read_csv("/storage2/Hincode/S-60-47-61-2024-RNASeq_0240725_LH00206_0043_A22MLN2LT3/navarra/metadata.csv")
```
```{r}
mart <- biomaRt::useMart(biomart = "ENSEMBL_MART_ENSEMBL",
dataset = "hsapiens_gene_ensembl",
host = 'https://www.ensembl.org')
ttg <- biomaRt::getBM(
attributes = c("ensembl_transcript_id","ensembl_gene_id","external_gene_name", "description",
"entrezgene_id","gene_biotype","transcript_biotype"),
mart = mart)
```
Quality Control from the primary analysis could be found <https://irycisbioinfo.github.io/ReportNavarraRNASeq/multiqc/star_salmon/multiqc_report.html>
The analysis workflow aligns the reads to the reference genome's transcripts. This allows us to perform analysis at two levels: the transcript level and the gene level, which provides a summary of all transcripts associated with each gene.
# Transcript Level
Preparing data format
```{r warning=FALSE, message=FALSE}
table_sum <- reads_transcripts %>%
pivot_longer(names_to = "Sample", values_to = "counts", -(tx:gene_id)) %>%
group_by(tx,gene_id) %>%
mutate(TotalGeneCounts = sum(counts),
TotalZerosCounts = sum(counts==0))
table_sum %>% ggplot(aes(x = TotalGeneCounts)) + geom_histogram() + geom_vline(xintercept = 10)+scale_x_log10()
```
Seen the distribution of the read counts we decide to filter those transcript with less than 10 reads or that are 0 in more than 3 samples.
```{r}
table_counts <- table_sum %>%
ungroup() %>%
filter(TotalGeneCounts > 10) %>%
filter(TotalZerosCounts < 3) %>%
dplyr::select(tx,Sample,counts) %>%
pivot_wider(names_from = Sample, values_from = counts, values_fill = 0) %>%
column_to_rownames("tx") %>%
round() %>%
as.matrix()
```
Creating a regression model and performing Differential Expression Analysis
```{r}
dds_transcript <-DESeqDataSetFromMatrix(countData = table_counts,
colData = metadata %>% column_to_rownames("Sample"),
design = ~Grupo)
dds_transcript <- DESeq(dds_transcript,sfType = "poscounts", fitType = "mean")
```
## Quality Control
Check the normalization and DE results
```{r}
reads_transcripts %>% pivot_longer(names_to = "Sample", values_to = "counts", -(tx:gene_id)) %>%
group_by(Sample) %>%
summarise(TotalCounts = sum(counts)) %>%
full_join(metadata) %>%
ggplot(aes(x= Sample, y = TotalCounts, fill = Grupo)) + geom_col() + coord_flip() + theme_light()+ labs(title = "Raw Data")
```
```{r}
counts(dds_transcript, normalized = T) %>% as_tibble(rownames = "tx") %>% pivot_longer(names_to = "Sample", values_to = "counts", -tx) %>%
group_by(Sample) %>%
summarise(TotalCounts = sum(counts)) %>%
full_join(metadata) %>%
ggplot(aes(x= Sample, y = TotalCounts, fill = Grupo)) + geom_col() + coord_flip() + theme_light() + labs(title = "Normalize Data")
```
```{r}
mds <- vegan::metaMDS(counts(dds_transcript, normalized = T) %>% t())
mds$points %>%
as.data.frame() %>%
rownames_to_column("Sample") %>%
inner_join(metadata) %>%
ggplot(aes(x = MDS1, y = MDS2, fill = Grupo, label =Sample)) + geom_label() +
theme_light()
```
The X Group seens more heteregenous than the group P. This get worse the quality of the Differential Expression Test.
## Differential Expression Test
```{r}
resultsNames(dds_transcript)
de_test <- results(dds_transcript) %>%
as_tibble(rownames = "Transcrip_ID") %>% inner_join(ids)
de_test%>%
mutate(sig = ifelse(padj < 0.005,"Significative","No-Significative")) %>%
mutate(label = ifelse(sig == "Significative",Gene_Name,NA)) %>%
ggplot(aes(x= log2FoldChange,
y = -log10(padj),
color = sig,
size = sqrt(baseMean),
label = label)) +
geom_point(alpha = 0.5) +
geom_text_repel(size = 2)+
scale_color_d3() +
theme_light() +
labs(title = "Volcano Plot Grupo_X_vs_P")
de_test%>%
mutate(sig = ifelse(padj < 0.005,"Significative","No-Significative")) %>%
mutate(label = ifelse(sig == "Significative",Gene_Name,NA)) %>%
ggplot(aes(x= baseMean,
y = log2FoldChange,
color = sig,
size = sqrt(baseMean),
label = label)) +
geom_point(alpha = 0.5) +
geom_text_repel(size = 1)+
scale_color_d3() +
scale_x_log10()+
theme_light() +
labs(title = "MA Plot Grupo_X_vs_P")
```
Volcano and MA plot shown several transcript differential expressed. In order to see better this differences we plot all the comparison individually.
```{r fig.width=20, fig.height=20}
significativos <- de_test%>%
filter(padj < 0.005) %>% pull(Transcrip_ID)
counts(dds_transcript, normalized = T) %>%
as.data.frame() %>%
rownames_to_column("tx") %>%
filter(tx %in% significativos) %>%
pivot_longer(names_to = "Sample",values_to = "counts", -tx) %>%
inner_join(metadata) %>%
ggplot(aes(x = Grupo, y = counts, fill = Grupo)) + geom_boxplot() + facet_wrap(~tx, scales = "free_y") + scale_fill_d3() + theme_light()
```
## Funtional Annotation
To create a biological context for the differential expressed transcript we are traying to infer if there are some funtional annotation (GO Terms) or pathway (KEGG) over-represented in the transcript-set.
```{r}
library(clusterProfiler)
library(org.Hs.eg.db)
```
```{r}
sig_transcripts <- de_test %>%
inner_join(ttg, by = c("Transcrip_ID" = "ensembl_transcript_id")) %>% filter(padj < 0.005) %>%
dplyr::select(entrezgene_id) %>%
distinct() %>%
drop_na() %>%
pull(entrezgene_id)
GO_enrichment <- enrichGO(gene =sig_transcripts,
OrgDb = org.Hs.eg.db,
ont = "ALL",
pAdjustMethod = "BH",
pvalueCutoff = 0.01,
qvalueCutoff = 0.05,
readable = TRUE)
if ((GO_enrichment %>% as.data.frame() %>% nrow()) > 0 )
{
barplot(GO_enrichment, showCategory = 20)
} else{
print("No enriched Pathways")
}
KEGG_enrichment <- enrichKEGG(gene = sig_transcripts,
organism = 'hsa',
pvalueCutoff = 0.05)
if ((KEGG_enrichment %>% as.data.frame() %>% nrow()) > 0 )
{
barplot(KEGG_enrichment, showCategory = 20)
} else{
print("No enriched Pathways")
}
```
There are not over-represented funtional annotation or pathway.
# Gene Level
At this point we repeat de analysis but at Gene Level.
```{r}
table_sum <- reads_genes %>%
pivot_longer(names_to = "Sample", values_to = "counts", -(gene_id:gene_name)) %>%
group_by(gene_id) %>%
mutate(TotalGeneCounts = sum(counts),
TotalZerosCounts = sum(counts==0))
table_sum %>% ggplot(aes(x = TotalGeneCounts)) + geom_histogram() + geom_vline(xintercept = 10)+scale_x_log10()
table_counts <- table_sum %>%
ungroup() %>%
filter(TotalGeneCounts > 10) %>%
filter(TotalZerosCounts < 3) %>%
dplyr::select(gene_id,Sample,counts) %>%
pivot_wider(names_from = Sample, values_from = counts, values_fill = 0) %>%
column_to_rownames("gene_id") %>%
round() %>%
as.matrix()
```
We use the same criteria to filter low quality genes.
```{r}
dds_genes <-DESeqDataSetFromMatrix(countData = table_counts,
colData = metadata %>% column_to_rownames("Sample"),
design = ~Grupo)
dds_genes <- DESeq(dds_genes,sfType = "poscounts", fitType = "mean")
```
## Quality Control
```{r}
reads_genes %>% pivot_longer(names_to = "Sample", values_to = "counts", -(gene_id:gene_name)) %>%
group_by(Sample) %>%
summarise(TotalCounts = sum(counts)) %>%
full_join(metadata) %>%
ggplot(aes(x= Sample, y = TotalCounts, fill = Grupo)) + geom_col() + coord_flip() + theme_light()+ labs(title = "Raw Data")
```
```{r}
counts(dds_genes, normalized = T) %>% as_tibble(rownames = "genes_id") %>% pivot_longer(names_to = "Sample", values_to = "counts", -genes_id) %>%
group_by(Sample) %>%
summarise(TotalCounts = sum(counts)) %>%
full_join(metadata) %>%
ggplot(aes(x= Sample, y = TotalCounts, fill = Grupo)) + geom_col() + coord_flip() + theme_light() + labs(title = "Normalize Data")
```
```{r}
pca <- vegan::metaMDS(counts(dds_genes, normalized = T) %>% t())
pca$points %>%
as.data.frame() %>%
rownames_to_column("Sample") %>%
inner_join(metadata) %>%
ggplot(aes(x = MDS1, y = MDS2, fill = Grupo, label =Sample)) + geom_label() +
theme_light()
```
We obtain the same results at heterogeneity level of the samples.
## Differential Expression Test
```{r}
resultsNames(dds_genes)
de_test <- results(dds_genes) %>%
as_tibble(rownames = "Gene_ID") %>% inner_join(ids)
de_test%>%
mutate(sig = ifelse(padj < 0.01,"Significative","No-Significative")) %>%
mutate(label = ifelse(sig == "Significative",Gene_Name,NA)) %>%
ggplot(aes(x= log2FoldChange,
y = -log10(padj),
color = sig,
size = sqrt(baseMean),
label = label)) +
geom_point(alpha = 0.5) +
geom_text_repel(size = 1)+
scale_color_d3() +
theme_light() +
labs(title = "Volcano Plot Grupo_X_vs_P")
de_test%>%
mutate(sig = ifelse(padj < 0.01,"Significative","No-Significative")) %>%
mutate(label = ifelse(sig == "Significative",Gene_Name,NA)) %>%
ggplot(aes(x= baseMean,
y = log2FoldChange,
color = sig,
size = sqrt(baseMean),
label = label)) +
geom_point(alpha = 0.5) +
geom_text_repel(size = 1)+
scale_color_d3() +
scale_x_log10()+
theme_light() +
labs(title = "MA Plot Grupo_X_vs_P")
```
```{r }
significativos <- de_test%>%
filter(padj < 0.01) %>% pull(Gene_Name)
counts(dds_genes, normalized = T) %>%
as.data.frame() %>%
rownames_to_column("Gene_Name") %>%
filter( Gene_Name %in% significativos) %>%
pivot_longer(names_to = "Sample",values_to = "counts", -Gene_Name) %>%
inner_join(metadata) %>%
ggplot(aes(x = Grupo, y = counts, fill = Grupo)) + geom_boxplot() + facet_wrap(~Gene_Name, scales = "free_y") + scale_fill_d3() + theme_light()
```
In this case we only see two genes deferentially expresed.