-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path01-preprocessing.qmd
More file actions
73 lines (58 loc) · 1.85 KB
/
01-preprocessing.qmd
File metadata and controls
73 lines (58 loc) · 1.85 KB
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
---
title: "Untitled"
format: html
---
## Setup
Remember, we started with a `SummarizedExperiment` object and now we have to transform it into an object that is usable with `DESeq2`.
```{r}
#| warning: false
#| message: false
library(SummarizedExperiment)
library(tidySummarizedExperiment)
library(ggplot2)
library(DESeq2)
GSE96870 <- readRDS("data/GSE96870_se.rds")
```
## Plot
```{r norm-library}
#| echo: false
library(patchwork)
expression_plot <-
GSE96870 |>
filter(.feature == "Asl") |>
# filter(time %in% c("Day0", "Day8")) |>
ggplot(aes(x = Label, y = counts, color = time)) +
geom_point() + theme_minimal() +
theme(axis.text.x = element_blank()) +
ggtitle("Asl Expression count")
count_plot <-
GSE96870 |>
# filter(time %in% c("Day0", "Day8")) |>
group_by(Label) |>
summarise(total_counts=sum(counts)) |>
mutate(time = colData(GSE96870)[["time"]]) |>
ggplot() +
aes(x=Label, y=total_counts, fill=time) +
geom_bar(stat="identity") + theme_minimal() +
theme(axis.text.x = element_text(angle = 90)) +
ggtitle("Library Size for each Sample")
expression_plot/ count_plot
```
## Normalizing
```{r}
GSE96870_filtered <- GSE96870[rowSums(assay(GSE96870, "counts")) > 5,]
GSE96870_deseq <- DESeq2::DESeqDataSet(GSE96870_filtered, design = ~ sex + time)
GSE96870_normalized <- DESeq2::estimateSizeFactors(GSE96870_deseq)
GSE96870_normalized |>
select(.feature, .sample, counts, sizeFactor)
```
```{r}
expression_normalized <- GSE96870_normalized |>
filter(.feature == "Asl") |>
mutate(scaled = counts / sizeFactor) |>
ggplot(aes(x = Label, y = scaled, color = time)) +
geom_point() + theme_minimal() +
theme(axis.text.x = element_blank()) +
ggtitle("Asl Expression count \nnormalized by library size")
(expression_plot + theme(legend.position = "none")) + expression_normalized
```