-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3_mMAB_migration_2.Rmd
132 lines (118 loc) · 3.67 KB
/
3_mMAB_migration_2.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
---
title: "3_mMAB_migration_2"
author: "Jordi Camps"
date: "2019 M01 9"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Load packages
```{r message=FALSE}
library(readxl)
library(tidyr)
library(dplyr)
library(ggplot2)
library(qpcrviia7)
library(ggpubr)
```
## Load data
```{r}
qpcr <- read_excel("data/fig3-4_qPCR_cells/2016-08-17 125944 Muscle progenitors migration2-ViiA7-export.xls", sheet = 1, col_names = TRUE, skip = 35)
head(qpcr)
```
## Include sample
Check lab book for correct sample names
```{r}
qpcr$Sample <- qpcr$`Sample Name`
qpcr <- separate(qpcr, `Sample Name`, c("Celltype", "Mouse"), sep = " ")
```
## Creating numeric CT column and change undetermined values into 40
```{r}
qpcr$CT <- as.numeric(qpcr$CT)
qpcr[is.na(qpcr$CT), "CT"] <- 40
```
## Quality control
### Samples
```{r fig.height=4, fig.width=6}
ggplot(qpcr, aes(Sample, CT)) +
geom_boxplot() +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.4, hjust = 1)) +
ggtitle("CT values per sample")
```
### Genes
```{r fig.height=4, fig.width=6}
ggplot(qpcr, aes(`Target Name`, CT)) +
geom_boxplot() +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.4, hjust = 1)) +
ggtitle("CT values per primer")
```
## Remove blanc
```{r}
qpcr <- filter(qpcr, Celltype != "Blanc")
```
## Change low CT values to NA
```{r}
qpcr[qpcr$CT < 10, "CT"] <- NA
```
## Check HKG over samples
```{r}
qpcr %>%
filter(`Target Name` == "Psma3" | `Target Name` == "Rab35" | `Target Name` == "Rpl13a") %>%
ggplot(aes(y = CT, x = Celltype)) +
#geom_histogram(bins = 6) +
geom_boxplot() +
facet_wrap(~`Target Name`, scales = "free_x")
```
## Normalize to HKG
normalize_hkg function
```{r}
normalize_hkg <- function(df, hkg, sample_col = "Sample Name", target_col = "Target Name") {
temp <- NULL
temp2 <- NULL
#create df with average hkg per sample
temp <- df[which(df[[target_col]] %in% hkg), ]
temp <- temp %>%
select_(sample_col, "CT") %>%
group_by_(sample_col) %>%
summarize(CT_hkg = gm_mean(CT, na.rm = TRUE))
#add avg hkg to df and calculate delta ct and rel expr
temp2 <- df[-which(df[[target_col]] %in% hkg), ]
print(temp2 %>%
group_by_(sample_col) %>%
left_join(temp) %>%
mutate(Delta_ct = CT_hkg - CT, Rel_expr = 2^Delta_ct)
)
}
```
gm_mean function
```{r}
gm_mean = function(x, na.rm=TRUE){
exp(sum(log(x[x > 0]), na.rm=na.rm) / length(x))
}
```
```{r}
qpcr <- normalize_hkg(df = qpcr, hkg = "Rpl13a", sample_col = "Sample", target_col = "Target Name")
```
## Plot
```{r fig.height=5, fig.width=10}
qpcr %>%
filter(`Target Name` != "Psma3" & `Target Name` != "Rab35") %>%
ggplot(aes(x = Celltype, y = Rel_expr, col = Celltype, fill = Celltype)) +
#geom_point() +
geom_dotplot(binaxis = "y", stackdir = "center", dotsize = 3) +
stat_summary(fun.y = mean, fun.ymax = mean, fun.ymin = mean, col = "black", geom = "Crossbar") +
facet_wrap(~`Target Name`, scales = "free") +
scale_y_continuous("Relative expression to Rpl13a") +
scale_fill_brewer(type = "qual", palette = "Set1") +
scale_color_brewer(type = "qual", palette = "Set1") +
theme_bw(base_size = 12) +
theme(panel.border = element_blank(), panel.grid = element_blank(), axis.line = element_line(colour = "black"),
axis.ticks.x = element_blank(), axis.ticks.y = element_line(colour = "black"), axis.text.x = element_blank(),
axis.text.y = element_text(colour = "black", size = 8), axis.title.x = element_blank(), strip.background = element_blank(),
strip.text = element_text(face = "italic"))
#ggsave("plots/cells/mMAB_migration_receptors.pdf", dpi = 600)
#ggsave("plots/cells/mMAB_migration_receptors.png", dpi = 600)
```