-
Notifications
You must be signed in to change notification settings - Fork 0
/
SynapseCounter_Homer_Syn.r
168 lines (141 loc) · 7.19 KB
/
SynapseCounter_Homer_Syn.r
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
library(ggplot2)
library(ncar)
library(tidyverse)
library(DescTools)
library(ggridges)
#clean environment of old items
rm(list = ls())
#identify all files in result folder
Result_Folder <- "D:/Martin_KI/RunningProjects/CASK/ImmunoFluorescence/Puncta_quantification/Homer_Syn_Quantification/ResultFiles/" #Change this path to the folder with your result .csv files from ImageJ macro
Files <- list.files(Result_Folder, pattern = "\\.csv$")
#read sample to cell line code
sample_code <- read.table("D:/Martin_KI/RunningProjects/CASK/ImmunoFluorescence/Puncta_quantification/Puncta_quantification/Sample_code.txt", sep = "\t", header = TRUE)
#Set up empty data frame to contain data
summary_Homer <- data.frame()
summary_Syn <- data.frame()
summary_Nuclei <- data.frame()
#for loop to populate data frame with individual puncti from each image one-by-one
for (i in 1:length(Files)){
this_file <- Files[i]
print(this_file)
this_cell <- unlist(strsplit(this_file,"_"))
this_sample <- this_cell[1]
this_cellLine <- sample_code[as.integer(this_sample),2]
this_time <- sample_code[as.integer(this_sample),4]
this_replicate <- this_cell[3]
Punctae <- read.table(paste("D:/Martin_KI/RunningProjects/CASK/ImmunoFluorescence/Puncta_quantification/Homer_Syn_Quantification/ResultFiles/", this_file, sep = ""), sep = ",", header = TRUE)
this_cell_puncta <- data.frame(CellLine = this_cellLine, Time = this_time, Sample = this_sample, Replicate = this_replicate, puncti = Punctae$Area, Circularity = Punctae$Circ., IntDen = Punctae$IntDen)
if (startsWith(this_cell[length(this_cell)], "H")){
summary_Homer<- rbind(summary_Homer,this_cell_puncta)
}
else if (startsWith(this_cell[length(this_cell)], "S")){
summary_Syn<- rbind(summary_Syn,this_cell_puncta)
}
else if (startsWith(this_cell[length(this_cell)], "N")){
summary_Nuclei<- rbind(summary_Nuclei,this_cell_puncta)
}
else {
next()
}
}
#Set boundary (area) for nuclei
lower_Nuclei <- 1000
summary_Nuclei_interest <- summary_Nuclei[(summary_Nuclei$puncti > lower_Nuclei),]
summary_Nuclei_interest$CellLine <- factor(summary_Nuclei_interest$CellLine, c("CTRL9II", "AF22", "ASD17AII", "AFA0I"))
p <- ggplot(data = summary_Nuclei_interest, aes(x = CellLine, y = puncti, color = Replicate, fill = Sample)) +
geom_boxplot() +
theme_classic() +
ggtitle("Nuclei_Size")#+
#ylim(0,40000) #+
#coord_cartesian(ylim = c(0,10))
p
p <- ggplot(summary_Nuclei_interest, aes(x = CellLine, y = puncti))+
geom_boxplot() +
theme_classic() +
coord_cartesian(ylim = c(0,8000))
p
#compute summary statistics for Nuclei
summary_stats_Nuclei <- summary_Nuclei_interest %>%
group_by(Replicate, Sample, CellLine) %>%
summarise(average = mean(puncti), medianNuc = median(puncti), sd = sd(puncti), count = length(puncti), sum_of_area = sum(puncti))
summary_stats_Nuclei
summary_stats_Nuclei$CellLine <- factor(summary_stats_Nuclei$CellLine, c("CTRL9II", "AF22", "ASD17AII", "AFA0I"))
p <- ggplot(summary_stats_Nuclei, aes(x = CellLine, y = average))+
geom_boxplot() +
theme_classic() +
ylim(0,9000) +
ggtitle("NucleiSize")
p
p <- ggplot(data = summary_stats_Nuclei, aes(x = CellLine, y = count, color = CellLine)) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(shape= 16, position = position_jitter(0.2), size = 2)+
theme_classic() +
ggtitle("Nuclei_Count")#+
#ylim(0,20)
p
summary_stats_Nuclei_NoReplicate <- summary_Nuclei_interest %>%
group_by(Sample, CellLine) %>%
summarise(average = mean(puncti), medianNuc = median(puncti), sd = sd(puncti), count = length(puncti), sum_of_area = sum(puncti))
res.Nucleiaov <- aov(average ~ CellLine, data = summary_stats_Nuclei_NoReplicate)
summary(res.Nucleiaov)
TukeyHSD(res.Nucleiaov)
#identify all files in result folder
Synapse_Folder <- "D:/Martin_KI/RunningProjects/CASK/ImmunoFluorescence/Puncta_quantification/Homer_Syn_Quantification/ResultFiles/Synapse" #Change this path to the folder with your result .csv files from ImageJ macro
Synapse_Files <- list.files(Synapse_Folder, pattern = "SynapseCounterResults\\.csv$")
#Set up empty data frame to contain data
summary_Synapses <- data.frame()
#for loop to populate data frame with individual puncti from each image one-by-one
for (i in 1:length(Synapse_Files)){
this_file <- Synapse_Files[i]
print(this_file)
this_cell <- unlist(strsplit(this_file,"_"))
this_sample <- this_cell[1]
this_cellLine <- sample_code[as.integer(this_sample),2]
this_time <- sample_code[as.integer(this_sample),4]
this_replicate <- this_cell[3]
Synapse <- read.table(paste("D:/Martin_KI/RunningProjects/CASK/ImmunoFluorescence/Puncta_quantification/Homer_Syn_Quantification/ResultFiles/Synapse/", this_file, sep = ""), sep = ",", header = TRUE)
this_cell_puncta <- data.frame(CellLine = this_cellLine, Time = this_time, Sample = this_sample, Replicate = this_replicate, PreSynapseNo = Synapse$Presyn..N, PreSynapseSize = Synapse$Presyn..mean.size, PostSynapseNo = Synapse$Postsyn..N, PostSynapseSize = Synapse$Postsyn..mean.size, ColoNo = Synapse$Coloc..N, ColoSize = Synapse$Coloc..mean.size)
summary_Synapses<- rbind(summary_Synapses,this_cell_puncta)
}
summary_Synapses <- merge(summary_Synapses, summary_stats_Nuclei, by = c("Sample", "Replicate"))
summary_Synapses <- summary_Synapses %>%
rename(
CellLine = CellLine.x
)
summary_Synapses <- summary_Synapses %>%
mutate(PostSynapsePerNuclei = PostSynapseNo/count)
summary_Synapses <- summary_Synapses %>%
mutate(PreSynapsePerNuclei = PreSynapseNo/count)
summary_Synapses <- summary_Synapses %>%
mutate(ColocSynapse = ColoNo/count)
#this part needs to be changed dynamically to test:
#PreSynapseNo, PreSynapseSize, PostSynapseNo, PostSynapseSize, ColoNo or ColoSize
#PostSynapsePerNuclei, PreSynapsePerNuclei or ColocSynapsePerNuclei
testthis <- "PostSynapsePerNuclei"
summary_Synapses$Status <- ifelse(summary_Synapses$CellLine == "ASD17AII", "ASD", ifelse(summary_Synapses$CellLine == "AFA0I", "MICPCH", "Control"))
res.Synapseaov <- aov(get(testthis) ~ CellLine, data = summary_Synapses)
TukeyHSD(res.Synapseaov)
summary_stats_Synapses <- summary_Synapses %>%
group_by(Sample, Status) %>%
summarise(average = mean(get(testthis)), sd = sd(get(testthis)))
#summary_stats_Synapses
res.Synapseaov <- aov(average ~ Status, data = summary_stats_Synapses)
TukeyHSD(res.Synapseaov)
summary_stats_Synapses <- summary_Synapses %>%
group_by(Sample, CellLine) %>%
summarise(average = mean(get(testthis)), sd = sd(get(testthis)))
#summary_stats_Synapses
res.Synapseaov <- aov(average ~ CellLine, data = summary_stats_Synapses)
reportStatistics <- TukeyHSD(res.Synapseaov)
reportStatistics <- as.data.frame(reportStatistics[1:1])
#write.csv(reportStatistics, paste("Homer1_Syn_", testthis, ".csv", sep=""))
summary_stats_Synapses$CellLine <- factor(summary_stats_Synapses$CellLine, c("CTRL9II", "AF22", "ASD17AII", "AFA0I"))
p <- ggplot(data = summary_stats_Synapses, aes(x = CellLine, y = average, color = CellLine)) +
geom_boxplot(outlier.shape = NA) +
theme_classic() +
geom_jitter()+
ggtitle(testthis)
p
#ggsave(paste(testthis,"Homer_Syn.svg", sep = ""), height = 5, width = 5, dpi = 600)
#ggsave(paste(testthis,"Homer_Syn.svg", sep = ""), height = 5, width = 5, dpi = 600)
#ggsave(paste(testthis,"Homer_Syn.svg", sep = ""), height = 5, width = 5, dpi = 600)