library(dplyr)
library(ggplot2)
library(effsize)
library(forcats)
library(ggpubr)
library(ggplotgui)

# Set working directory
setwd("/set/path/to/directory/")

# Read data IN and PN
data <- read.table("./Figure1A1_data.csv", header = TRUE, sep = ",")


# Calculate the 5th and 95th percentiles of NeuronCyto_Area 
percentiles <- quantile(data$NeuronCyto_Area, probs = c(0.5, 0.95))

# Filter data by 5th and 95th percentile
flt.595.data <- data %>%
  filter(NeuronCyto_Area > percentiles[1] & NeuronCyto_Area < percentiles[2])

# Boxplot CTRL VS siRNA Nuclear Polk Mean Intensity
graph1 <- ggplot(flt.595.data, aes(x = '', y = NeuronNuc_MeanIntensity_POLK, fill = Treatment)) +
  geom_boxplot(notch = TRUE, alpha = 0.25) +
  scale_fill_manual(values = c("CTRL" = "cyan", "siPolk" = "purple")) +
  stat_compare_means(method = "t.test", aes(label = ..p.signif..), label.y = 0.25) + #adds signif at position y.axis
  stat_compare_means(method = "t.test", aes(label = ..p.format..), label.y = 0.24) + #adds p-val at position y.axis
  theme_bw()
graph1

# Boxplot CTRL VS siRNA Nuclear Polk Median Intensity
graph2 <- ggplot(flt.595.data, aes(x = '', y = NeuronNuc_MedianIntensity_POLK, fill = Treatment)) +
  geom_boxplot(notch = TRUE, alpha = 0.25) +
  scale_fill_manual(values = c("CTRL" = "cyan", "siPolk" = "purple")) +
  stat_compare_means(method = "t.test", aes(label = ..p.signif..), label.y = 0.25) + #adds signif at position y.axis
  stat_compare_means(method = "t.test", aes(label = ..p.format..), label.y = 0.24) + #adds p-val at position y.axis
  theme_bw()
graph2

# Boxplot CTRL VS siRNA Nuclear Polk Integrated Intensity
graph3 <- ggplot(flt.595.data, aes(x = '', y = NeuronNuc_IntegratedIntensity_POLK, fill = Treatment)) +
  geom_boxplot(notch = TRUE, alpha = 0.25) +
  scale_fill_manual(values = c("CTRL" = "cyan", "siPolk" = "purple")) +
  stat_compare_means(method = "t.test", aes(label = ..p.signif..), label.y = 1200) + #adds signif at position y.axis
  stat_compare_means(method = "t.test", aes(label = ..p.format..), label.y = 1100) + #adds p-val at position y.axis
  theme_bw()
graph3
