-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMB_plotting_treatments.R
More file actions
86 lines (62 loc) · 2.91 KB
/
MB_plotting_treatments.R
File metadata and controls
86 lines (62 loc) · 2.91 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
73
74
75
76
77
78
79
80
81
82
83
84
rm(list = ls()) # clearing the global work environment
library("readr")
library("ggplot2")
library("dplyr")
library("ggpubr")
library("rstatix")
library("psych")
# reading in csv file produced by 'MB_thresholding_treatments.ipynb'
# wherein all blobs have been categorised as one of the two antibodies or both
# replace /path/to/folder/ below with path to experiment folder
dir_path <- "/path/to/folder/"
expt_name <- "Ecad-bcat_TGFb" # name of experiment folder
root_dir <- paste(dir_path, expt_name, "/", sep="")
mydata <- read_csv(paste(root_dir, expt_name, "_IntegratedIntensity.csv", sep=""))
# adding Treatment as a factor made from Condition
mydata$Treatment[mydata$Condition =="Treatment"] <- "Treatment"
mydata$Treatment[mydata$Condition == "Control"] <- "Control"
# putting levels in the right order for plotting
mydata$Treatment <-factor(mydata$Treatment, levels = c("Treatment", "Control"))
title_plot <- expt_name
class(mydata$Treatment)
levels(mydata$Treatment)
mydata$Categorization[mydata$Category =="Both"] <- "Interaction"
mydata$Categorization[mydata$Category == "TexRed"] <- "Free E-cadherin"
mydata$Categorization[mydata$Category == "Atto647"] <- "Free b-catenin"
# putting levels in the right order for plotting
mydata$Categorization <-factor(mydata$Categorization, levels = c("Interaction", "Free E-cadherin", "Free b-catenin"))
class(mydata$Categorization)
levels(mydata$Categorization)
# make boxplots with significance added
p <- ggplot(mydata, aes(x=Treatment,y=BlobCount,color=Categorization, fill=Categorization)) +
geom_boxplot(colour = 'black') +
facet_grid(. ~ Categorization) +
labs(fill = "", x= "", y="RCP proportion/cell", title=title_plot )
p
stat.test <- mydata %>%
group_by(Categorization) %>%
dunn_test(BlobCount ~ Treatment, p.adjust.method = "bonferroni")%>%
add_significance()
stat.test
save_name <- paste(root_dir, title_plot, "_Significance.csv", sep="")
write.table(stat.test, file=save_name, sep=",", row.names=FALSE)
stat.test <- stat.test %>% add_xy_position(x = "Treatment")
p + stat_pvalue_manual(stat.test, step.group.by = "Categorization") +
theme_classic() +
scale_fill_grey(start=0.3, end=0.9) +
theme(strip.text = element_blank(), plot.title = element_text(hjust = 0.5))
save_name <- paste(root_dir, title_plot, ".pdf", sep="")
ggsave(save_name, device="pdf", width=7, height=5)
# compute and save summary stats
mydataTreated <- mydata %>%
filter(Condition == "Treatment")
x <- describeBy(mydataTreated$BlobCount, mydataTreated$Categorization, quant=c(0.25,0.75), mat=TRUE)
x
save_name <- paste(root_dir, title_plot, "_Treated.csv", sep="")
write.table(x, file=save_name, sep=",", row.names=FALSE)
mydataControl <- mydata %>%
filter(Condition == "Control")
x <- describeBy(mydataControl$BlobCount, mydataControl$Categorization, quant=c(0.25,0.75), mat=TRUE)
x
save_name <- paste(root_dir, title_plot, "_Control.csv", sep="")
write.table(x, file=save_name, sep=",", row.names=FALSE)