-
Notifications
You must be signed in to change notification settings - Fork 0
/
R_Inhibitor_Testing
480 lines (399 loc) · 17.7 KB
/
R_Inhibitor_Testing
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
---
title: "Inhibitor Testing"
author: "Nick"
date: "9/29/2021"
output: html_document
---
## Introduction
This is where we describe what we want to do in this analysis
```{r import}
library(tidyverse)
library(data.table)
library(stringr)
library(ggplot2)
library(ggpubr)
library(dplyr)
library(knitr)
```
For each compound combination tested, some things always chage:
- directory
- plot title (depends on the compounds)
- compound addition times (vary depending on when compound was added, not always the same exact)
```{r}
directory1 <- "/Volumes/arendt/Nick/Experiments/Inhibitor_Activator_Testing/..."
directory2 <- ""
directory3 <- ""
final_directory <- ""
plot_title <- ""
compound_add <-
compound_add2 <-
compound_add3 <-
```
## Triplicate 1
set the working directory to each folder containing the Results Table from FIJI
must be changed with every trial
- the results table generated by FIJI will always be called "Results"
- read in the results and make a data frame out of them
- this will include all the columns (also, "Slice" including the names)
```{r, setup, include=FALSE}
knitr::opts_knit$set(root.dir = directory1)
# Windows
# setwd("Z:/Nick/Experiments/Inhibitor_Activator_Testing/FINAL-DIRECTORY")
```
```{r}
results <- read.csv("Results.csv") %>%
tibble()
```
- exclude all unnecessary data
- just include "Area"
- select all rows that contain a certain tissue
- blue = incurrent canals --> uneven numbers
- grey25 = excurrent canals --> even numbers
```{r}
incurrent <- select(results, Area)
incurrent <- incurrent[seq_len(nrow(incurrent)) %% 2 == 1, ]
excurrent <- select(results, Area)
excurrent <- excurrent[seq_len(nrow(excurrent)) %% 2 == 0, ]
```
- adding a new column with time
- adding it here allows to set 30s steps exactly
- needs one random extra column (number)
- 'number' can be used to multiply with 30 to simulate 30s steps
- remove NAs (otherwise, this could not be plotted at the end)
```{r}
incurrent_time <- mutate(incurrent,
Area,
number = seq(1, nrow(incurrent)), # dummy
time_s = number * 30,
time_min = time_s / 60,
time_addition = time_min - compound_add
) %>%
na.omit(incurrent_time)
excurrent_time <- mutate(excurrent,
Area,
number = seq(1, nrow(excurrent)), # dummy
time_s = number * 30,
time_min = time_s / 60,
time_addition = time_min - compound_add
) %>%
na.omit(excurrent_time)
```
- normalized data from 0-1 can mistakenly make differences in area bigger than they actually are
- therefore, use the mean of each value
- get the mean of all values --> divide each row with this mean
- use this in new column
```{r}
incurrent_norm <- mutate(incurrent_time,
normalized = (Area / max(incurrent$Area))
)
excurrent_norm <- mutate(excurrent_time,
normalized = (Area / max(excurrent$Area))
)
```
- plot normalized values against time
- se = FALSE to have a clear line without the standard deviation in a gray surrounding
- use both incurrent and excurrent data in one plot
geom_vline(xintercept = 0, # min when compound was added
linetype = "dashed", # alternative: "dotted"
color = "grey25",
size = 0.9)
```{r}
plot1 <- ggplot(NULL, mapping = aes(x = time_addition, y = normalized)) +
geom_smooth(data = incurrent_norm, aes(color = "chocolate"), span = 0.2, se = FALSE) +
geom_smooth(data = excurrent_norm, aes(color = "deepskyblue"), span = 0.2, se = FALSE) +
# Plot Title and Axis Titles
ggtitle(plot_title) + #'[ Change ]
theme(plot.title = element_text(hjust = 0.5)) + # center the title in middle
xlab("Time [min]") +
# add an interval for the x-axis
# interval should start from the lowest value to the highest value
# values need to be rounded --> otherwise, they would start e.g. at -17 and would not display "0" at (1) addition
scale_x_continuous(breaks = seq(round_any(min(incurrent_norm$time_addition), 10),
round_any(max(incurrent_norm$time_addition), 10),
by = 10)) +
ylab("Normalized Area") +
ylim(0, 2) +
# Legend
scale_color_identity(name = "Canals", # name of the legend
breaks = c("deepskyblue", "chocolate"), # 'break' gives the order of the values in the legend
labels = c("Excurrent", "Incurrent"), # 'labels' changes the name of the values
guide = "legend") + # to get an identity scale
# add vertical line at the time of adding the compound
geom_vline(xintercept = 0, # min when compound was added
linetype = "dashed", # alternative: "dotted"
color = "grey25",
size = 0.9) +
geom_text(aes(x = 0, label = "compound addition", y = 2), # name the horizontal line
colour = "grey25",
hjust = 1.1, # move the title to the left so it does not cover horizontal line
text = element_text(size = 11))
# save the plot as PDF and JPEG
ggsave("Plot_Incurrent-Excurrent-Canals_x-Time_y-Normalise-Area_Replica1.pdf",
width = 20,
height = 10,
units = "cm")
ggsave("Plot_Incurrent-Excurrent-Canals_x-Time_y-Normalise-Area_Replica1.jpeg",
width = 20,
height = 10,
units = "cm")
```
## Triplicate 2
```{r, setup, include=FALSE}
knitr::opts_knit$set(root.dir = directory2)
# Windows
# setwd("Z:/Nick/Experiments/Inhibitor_Activator_Testing/FINAL-DIRECTORY")
```
```{r}
results2 <- read.csv("Results.csv") %>%
tibble()
```
```{r}
incurrent2 <- select(results2, Area)
incurrent2 <- incurrent2[seq_len(nrow(incurrent2)) %% 2 == 1, ]
excurrent2 <- select(results2, Area)
excurrent2 <- excurrent2[seq_len(nrow(excurrent2)) %% 2 == 0, ]
```
```{r}
incurrent_norm2 <- mutate(incurrent2,
Area,
number = seq(1, nrow(incurrent2)),
time_s = number * 30,
time_min = time_s / 60,
time_addition = time_min - compound_add2
) %>%
na.omit() %>%
mutate(normalized = (Area / max(incurrent2$Area)))
excurrent_norm2 <- mutate(excurrent2,
Area,
number = seq(1, nrow(excurrent2)),
time_s = number * 30,
time_min = time_s / 60,
time_addition = time_min - compound_add2
) %>%
na.omit() %>%
mutate(normalized = (Area / max(excurrent2$Area)))
```
```{r}
plot2 <- ggplot(NULL, mapping = aes(x = time_addition, y = normalized)) +
geom_smooth(data = incurrent_norm2, aes(color = "chocolate"), span = 0.2, se = FALSE) +
geom_smooth(data = excurrent_norm2, aes(color = "deepskyblue"), span = 0.2, se = FALSE) +
# Plot Title and Axis Titles
ggtitle(plot_title) + #'[ Change ]
theme(plot.title = element_text(hjust = 0.5)) + # center the title in middle
xlab("Time [min]") +
scale_x_continuous(breaks = seq(round_any(min(incurrent_norm2$time_addition), 10),
round_any(max(incurrent_norm2$time_addition), 10),
by = 10)) +
ylab("Normalized Area") +
ylim(0, 2) +
# Legend
scale_color_identity(name = "Canals", # name of the legend
breaks = c("deepskyblue", "chocolate"), # 'break' gives the order of the values in the legend
labels = c("Excurrent", "Incurrent"), # 'labels' changes the name of the values
guide = "legend") + # to get an identity scale
# add vertical line at the time of adding the compound
geom_vline(xintercept = 0, # min when compound was added
linetype = "dashed", # alternative: "dotted"
color = "grey25",
size = 0.9) +
geom_text(aes(x = 0, label = "compound addition", y = 2),
colour = "grey25",
hjust = 1.1,
text = element_text(size = 11))
# save the plot as PDF and JPEG
ggsave("Plot_Incurrent-Excurrent-Canals_x-Time_y-Normalise-Area_Replica2.pdf",
width = 20,
height = 10,
units = "cm")
ggsave("Plot_Incurrent-Excurrent-Canals_x-Time_y-Normalise-Area_Replica2.jpeg",
width = 20,
height = 10,
units = "cm")
```
## Triplicate 3
```{r, setup, include=FALSE}
knitr::opts_knit$set(root.dir = directory3)
# Windows
# setwd("Z:/Nick/Experiments/Inhibitor_Activator_Testing/FINAL-DIRECTORY")
```
```{r}
results3 <- read.csv("Results.csv") %>%
tibble()
```
```{r}
incurrent3 <- select(results3, Area)
incurrent3 <- incurrent3[seq_len(nrow(incurrent3)) %% 2 == 1, ]
excurrent3 <- select(results3, Area)
excurrent3 <- excurrent3[seq_len(nrow(excurrent3)) %% 2 == 0, ]
```
```{r}
incurrent_norm3 <- mutate(incurrent3,
Area,
number = seq(1, nrow(incurrent3)),
time_s = number * 30,
time_min = time_s / 60,
time_addition = time_min - compound_add3
) %>%
na.omit() %>%
mutate(normalized = (Area / max(incurrent3$Area)))
excurrent_norm3 <- mutate(excurrent3,
Area,
number = seq(1, nrow(excurrent3)),
time_s = number * 30,
time_min = time_s / 60,
time_addition = time_min - compound_add3
) %>%
na.omit() %>%
mutate(normalized = (Area / max(excurrent3$Area)))
```
```{r}
plot3 <- ggplot(NULL, mapping = aes(x = time_addition, y = normalized)) +
geom_smooth(data = incurrent_norm3, aes(color = "chocolate"), span = 0.2, se = FALSE) +
geom_smooth(data = excurrent_norm3, aes(color = "deepskyblue"), span = 0.2, se = FALSE) +
# Plot Title and Axis Titles
ggtitle(plot_title) + #'[ Change ]
theme(plot.title = element_text(hjust = 0.5)) + # center the title in middle
xlab("Time [min]") +
scale_x_continuous(breaks = seq(round_any(min(incurrent_norm3$time_addition), 10),
round_any(max(incurrent_norm3$time_addition), 10),
by = 10)) +
ylab("Normalized Area") +
ylim(0, 2) +
# Legend
scale_color_identity(name = "Canals", # name of the legend
breaks = c("deepskyblue", "chocolate"), # 'break' gives the order of the values in the legend
labels = c("Excurrent", "Incurrent"), # 'labels' changes the name of the values
guide = "legend") + # to get an identity scale
# add vertical line at the time of adding the compound
geom_vline(xintercept = 0, # min when compound was added
linetype = "dashed", # alternative: "dotted"
color = "grey25",
size = 0.9) +
geom_text(aes(x = 0, label = "compound addition", y = 2),
colour = "grey25",
hjust = 1.1,
text = element_text(size = 11))
# save the plot as PDF and JPEG
ggsave("Plot_Incurrent-Excurrent-Canals_x-Time_y-Normalise-Area_Replica3.pdf",
width = 20,
height = 10,
units = "cm")
ggsave("Plot_Incurrent-Excurrent-Canals_x-Time_y-Normalise-Area_Replica3.jpeg",
width = 20,
height = 10,
units = "cm")
```
## Plot everyting
```{r, setup, include=FALSE}
knitr::opts_knit$set(root.dir = final_directory)
# Windows
# setwd("Z:/Nick/Experiments/Inhibitor_Activator_Testing/FINAL-DIRECTORY")
```
- make new data frame containing time + Area from all 3 triplicates
- create mean of all the triplicates
- make plot with dots for each triplicate + line for the mean
```{r}
incurrent_triplicate <- rbind(incurrent_norm, incurrent_norm2, incurrent_norm3)
excurrent_triplicate <- rbind(excurrent_norm, excurrent_norm2, excurrent_norm3)
plot_final <- ggplot(NULL, aes(x = time_addition, y = normalized)) +
geom_smooth(data = incurrent_triplicate, size = 2, aes(color = "chocolate4"), span = 0.2, se = FALSE) +
stat_smooth(data = incurrent_norm, geom = 'line', alpha = 0.2, size = 1, aes(color = "chocolate"), span = 0.2, se = FALSE) +
geom_jitter(data = incurrent_norm, shape = 15, alpha = 0.2, aes(color = "chocolate")) +
stat_smooth(data = incurrent_norm2, geom = 'line', alpha = 0.2, size = 1, aes(color = "chocolate1"), span = 0.2, se = FALSE) +
geom_jitter(data = incurrent_norm2, shape = 16, alpha = 0.2, aes(color = "chocolate1")) +
stat_smooth(data = incurrent_norm3, geom = 'line', alpha = 0.2, size = 1, aes(color = "chocolate2"), span = 0.2, se = FALSE) +
geom_jitter(data = incurrent_norm3, shape = 17, alpha = 0.2, aes(color = "chocolate2")) +
geom_smooth(data = excurrent_triplicate, size = 2, aes(color = "deepskyblue4"), span = 0.2, se = FALSE) +
stat_smooth(data = excurrent_norm, geom = 'line', alpha = 0.2, size = 1, aes(color = "deepskyblue"), span = 0.2, se = FALSE) +
geom_jitter(data = excurrent_norm, shape= 15, alpha = 0.2, aes(color = "deepskyblue")) +
stat_smooth(data = excurrent_norm2, geom = 'line', alpha = 0.2, size = 1, aes(color = "deepskyblue1"), span = 0.2, se = FALSE) +
geom_jitter(data = excurrent_norm2, shape= 16, alpha = 0.2, aes(color = "deepskyblue1")) +
stat_smooth(data = excurrent_norm3, geom = 'line', alpha = 0.2, size = 1, aes(color = "deepskyblue2"), span = 0.2, se = FALSE) +
geom_jitter(data = excurrent_norm3, shape= 17, alpha = 0.2, aes(color = "deepskyblue2")) +
ggtitle(plot_title) + #'[ Change ]
theme(plot.title = element_text(hjust = 0.5)) +
xlab("Time [min]") +
scale_x_continuous(breaks = seq(-500,
500, # max value for x-axis
by = 10)) +
ylab("Normalized Area") +
ylim(-0.25, 1.25) +
scale_color_identity(name = "Canals",
breaks = c("deepskyblue4", "chocolate4"),
labels = c("Excurrent mean", "Incurrent mean"),
guide = "legend") +
geom_vline(xintercept = 0,
linetype = "dashed",
color = "grey25",
size = 0.9) +
geom_text(aes(x = 0, label = "compound addition", y = 1.25),
colour = "grey25",
hjust = 1.1,
text = element_text(size = 11))
ggsave("Plot_Incurrent-Excurrent-Canals_x-Time_y-Normalise-Area_Mean_Triplicate.pdf",
width = 20,
height = 10,
units = "cm")
ggsave("Plot_Incurrent-Excurrent-Canals_x-Time_y-Normalise-Area_Mean_Triplicate.jpeg",
width = 20,
height = 10,
units = "cm")
print(plot_final)
```
```{r, setup, include=FALSE}
knitr::opts_knit$set(root.dir = "/Volumes/arendt/Nick/Thesis/Figures/Pharmacological_Testing")
```
- plot for thesis
- remove title
- add legend in plot bottomleft corner
- safe in different directory, .jped is sufficient
```{r}
incurrent_triplicate <- rbind(incurrent_norm, incurrent_norm2, incurrent_norm3)
excurrent_triplicate <- rbind(excurrent_norm, excurrent_norm2, excurrent_norm3)
plot_thesis <- ggplot(NULL, aes(x = time_addition, y = normalized)) +
geom_smooth(data = incurrent_triplicate, size = 2, aes(color = "chocolate4"), span = 0.2, se = FALSE) +
stat_smooth(data = incurrent_norm, geom = 'line', alpha = 0.2, size = 1, aes(color = "chocolate"), span = 0.2, se = FALSE) +
geom_jitter(data = incurrent_norm, shape = 15, alpha = 0.2, aes(color = "chocolate")) +
stat_smooth(data = incurrent_norm2, geom = 'line', alpha = 0.2, size = 1, aes(color = "chocolate1"), span = 0.2, se = FALSE) +
geom_jitter(data = incurrent_norm2, shape = 16, alpha = 0.2, aes(color = "chocolate1")) +
stat_smooth(data = incurrent_norm3, geom = 'line', alpha = 0.2, size = 1, aes(color = "chocolate2"), span = 0.2, se = FALSE) +
geom_jitter(data = incurrent_norm3, shape = 17, alpha = 0.2, aes(color = "chocolate2")) +
geom_smooth(data = excurrent_triplicate, size = 2, aes(color = "deepskyblue4"), span = 0.2, se = FALSE) +
stat_smooth(data = excurrent_norm, geom = 'line', alpha = 0.2, size = 1, aes(color = "deepskyblue"), span = 0.2, se = FALSE) +
geom_jitter(data = excurrent_norm, shape= 15, alpha = 0.2, aes(color = "deepskyblue")) +
stat_smooth(data = excurrent_norm2, geom = 'line', alpha = 0.2, size = 1, aes(color = "deepskyblue1"), span = 0.2, se = FALSE) +
geom_jitter(data = excurrent_norm2, shape= 16, alpha = 0.2, aes(color = "deepskyblue1")) +
stat_smooth(data = excurrent_norm3, geom = 'line', alpha = 0.2, size = 1, aes(color = "deepskyblue2"), span = 0.2, se = FALSE) +
geom_jitter(data = excurrent_norm3, shape= 17, alpha = 0.2, aes(color = "deepskyblue2")) +
theme(plot.title = element_text(hjust = 0.5)) +
xlab("Time [min]") +
scale_x_continuous(breaks = seq(-500,
500,
by = 10)) +
ylab("Normalized Area") +
ylim(-0.25, 1.25) +
scale_color_identity(name = "Canals",
breaks = c("deepskyblue4", "chocolate4"),
labels = c("Excurrent mean", "Incurrent mean"),
guide = "legend") +
#theme(legend.position=c(0.2, 0.2)) +
theme(
legend.position = c(0.05, 0.05),
legend.justification = c("left", "bottom"),
legend.box.just = "left",
legend.margin = margin(6, 6, 6, 6)
) +
geom_vline(xintercept = 0,
linetype = "dashed",
color = "grey25",
size = 0.9) +
geom_text(aes(x = 0, label = "compound addition", y = 1.25),
colour = "grey25",
hjust = 1.1,
text = element_text(size = 11))
ggsave("COMPOUND.jpeg",
width = 20,
height = 10,
units = "cm")
print(plot_thesis)
```