knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(warning = FALSE)
library(magrittr)
library(knitr)
library(dplyr)
library(ggplot2)
library(ggbeeswarm)
library(beeswarm)
library(ggthemes)
library(viridis)
library(lme4)
library(schoRsch)
library(DHARMa)
library(multcomp)
library(tidyr)
library(rstanarm)
library(ggrepel)
library(rstan)
library(rstanarm)
library(MASS)
library(png)
devtools::install_github("krlmlr/here")
devtools::install_github("mikeod38/dauergut")
library(dauergut)
pathname = here::here()

dauer_ANOVA <- . %>% lm(data = ., formula = pct ~ genotype)

Intestinal mTORC2 regulates sensory neuron state{.tabset}

2A

strains<-c("N2","mg360","ft7","ft7_ges1resc", "ft7_ifb2resc", "ft7_gpa4resc")
dates<-c("10_22_16", "11_9_16", "11_23_16", "12_16_17", "12_20_17") #dropped "12_6_16" due to missingness
d7GFP<-read.csv(file.path(pathname,"extdata","2A_3A_daf7GFP.csv")) %>%
  filter(mean!=4095 & genotype %in% strains & date %in% dates & temp == "27" & food == "OP50") %>%
  mutate(genotype = factor(genotype, levels=strains), 
         ID = as.character(ID),
         date = factor(date, levels = dates),
         dataset = case_when(date %in% dates[1:3] ~ "1",
                             date %in% dates[4:5] ~ "2")) %>%
  separate(ID, c("ID.A", "ID.B"), sep = ":", extra = "drop") %>% 
  mutate(genoID = paste(date, genotype, ID.A, sep = ":"), cell.norm = mean) %>%
  filter(note == "")

df <- d7GFP %>% 
  group_by(date, genotype, genoID, dataset) %>% 
  summarise(cell.norm = mean(cell.norm)) # take mean of each worm

#normalize to mean ft7 each day
day.means <- df %>% 
  filter(genotype == "ft7") %>% 
  group_by(date) %>%
  summarise(mean_ft7 = mean(cell.norm)) %>% data.frame()

df %<>% mutate(cell.norm = case_when(
  date == dates[1] ~ cell.norm,
  date == dates[2] ~ (cell.norm * day.means[1,2]) / day.means[2,2],
  date == dates[3] ~ (cell.norm * day.means[1,2]) / day.means[3,2],
  date == dates[4] ~ (cell.norm * day.means[1,2]) / day.means[4,2],
  date == dates[5] ~ (cell.norm * day.means[1,2]) / day.means[5,2]
)) %>% data.frame()


log.tran<-lsmeans::make.tran(type="genlog", param = c(0,10))
linmod <- with(log.tran, lm(linkfun(cell.norm) ~ genotype, data = df))
df <- flag_outliers(linmod, df = df, threshold = 4, noplot = TRUE)


# ### Linear models ###
linmod <- with(log.tran, lm(linkfun(cell.norm) ~ genotype, data = df[df$outlier.status == FALSE,]))


stanlmer <- with(log.tran, rstanarm::stan_lmer(linkfun(cell.norm) ~ genotype + (1|date) + (1|genotype:date), 
                                               data = df[df$outlier.status == FALSE,], 
                                               chains = 3, 
                                               cores =4, 
                                               seed = 2000,
                                               iter=6000,
                                               control = list(adapt_delta=0.99)))

#refit stanlmer using ft7 as reference to get credible interval for ifb-2 rescue:
df2 <- df %>% mutate(genotype = factor(genotype, levels = c(strains[3],strains[1:2],strains[4:6])))
stanlmer2 <- with(log.tran, rstanarm::stan_lmer(linkfun(cell.norm) ~ genotype + (1|date) + (1|genotype:date),
                                               data = df2[df2$outlier.status == FALSE,],
                                               chains = 3,
                                               cores =4,
                                               seed = 2000,
                                               iter=6000,
                                               control = list(adapt_delta=0.99)))
# 
stanlmer3 <- with(log.tran, rstanarm::stan_lmer(linkfun(cell.norm) ~ genotype + (1 + genotype|date),
                                               data = df2[df2$outlier.status == FALSE,],
                                               chains = 3,
                                               cores =4,
                                               seed = 2000,
                                               iter=6000,
                                               control = list(adapt_delta=0.99)))

PI_ifb2 <- rstanarm::posterior_interval(stanlmer2, pars = "(Intercept)", regex_pars = "ifb", prob = 0.90)
p2 <- plot(stanlmer3, pars = "beta") #, regex_pars = "genotype")

contrasts <- tukey_contrasts(linmod, factor = "genotype")
plot.contrasts <- c("",contrasts$prange[1:5])
plot.contrasts.2 <- c("","","",contrasts$prange[10:12])

mixed <- stanlmer %>% dauergut::getStan_CIs(type = "log", base = 10)

labels <- c("WT","rict-1(mg360)",
            "rict-1(ft7)",
            "rict-1(ft7); +ges1p::rict-1", 
            "rict-1(ft7); +ifb2p::rict-1",
            "rict-1(ft7); +gpa4p::rict-1") %>% stringr::str_wrap(width = 10)

p <- df[df$outlier.status == FALSE,] %>% 
  dauergut::plot_CIs(df = .,
                     plot.contrasts = plot.contrasts,
                     plot.contrasts.2 = plot.contrasts.2, 
                     type = "GFP",
                     title = "",
                     labels = labels,
                     ypos = 6000,
                     offset = 500)

img.path <- file.path(pathname,"figures","2A_daf7GFP.png")
``` {r, results = 'markup', eval = TRUE} include_graphics(img.path) wzxhzdk:2
**Figure 2A** Intesinal _rict-1_ regulates daf7GFP levels in ASI neurons. Daf-7::GFP fluorescence quantification shows decreased expression in _rict-1_ mutants. Intestinal expression of _rict-1_ using the intestinal _ges-1_ promoter rescues daf-7::GFP expression. (Left) Representative images of _daf-7p::gfp_ expression in one of the bilateral ASI neurons in animals of the indicated genotypes. Yellow filled and open arrowheads indicate ASI and ASJ soma, respectively. Anterior is at left. Scale bar: 5 μm. (Right) Quantification of daf-7p::gfp expression in ASI (A) and daf-28p::gfp expression in ASI and ASJ (D). Each dot is the mean fluorescence intensity in a single animal (2 neurons per animal); numbers in parentheses below indicate the number of animals examined in 3 independent experiments. Horizontal thick bar indicates median. Error bars are quartiles. Light gray thin and thick vertical bars at right indicate Bayesian 95% and 75% credible intervals, respectively. `**` and `***` - different from wild-type at P<0.01 and P<0.001, respectively; `***` - different from rict-1(ft7) at P<0.001 (ANOVA with Dunnett-type multivariate-t post-hoc adjustment). P-values of differences in means relative to wild-type and corresponding mutant animals are indicated in black and red, respectively.
library(sjPlot)
sjt.lm(linmod, depvar.labels = "log(mean GFP intensity) (AU)", show.se = TRUE, show.fstat = TRUE)
knitr::kable(contrasts, caption="Pairwise comparisons from ANOVA (Dunnett)")
knitr::kable(mixed[,c(1:6)], caption = "Bayesian credible intervals")
p2

2B

daf7FISH<-read.csv(file.path(pathname,"extdata","2B_daf7FISH_4frames.csv")) %>%
  separate(Label, c("method","group","sample"),sep = c("-"), extra = "drop") %>%
  separate(sample, c("sample", "type"),sep =":", extra = "drop") %>%
  mutate(genotype = data.frame(do.call(rbind, strsplit(as.vector(group), split = "daf7_mRNA_L1_27d_")))[,2],
         ID = interaction(genotype, sample),
         genotype = factor(genotype, levels = c("N2", "ft7", "mg360", "mg360resc")),
         group.id = dplyr::case_when(
           genotype %in% c("ft7","mg360") ~ as.character("mutant"),
           TRUE ~ as.character(genotype)))

#measured background fluorescence of each of 4 frames to normalize the sum projection of the neuron
#merge to add mean background value to each row:
background <- filter(daf7FISH, type == "background") %>% 
  dplyr::select(ID, mean)
colnames(background) <- c("ID", "background")

cells<-dplyr::filter(daf7FISH, type == "cell") %>% dplyr::select(ID, sample, mean, genotype, group.id)
colnames(cells) <- c("ID", "sample", "cell.mean", "genotype","group.id")

daf7FISH <- merge(cells, background,by="ID") %>%
  mutate(cell.norm = cell.mean - mean(background),
         cell.diffnorm = cell.mean - background,
         cell.ratioNorm = cell.mean / background)

#simple lm
lm<-lm(data=daf7FISH, formula=cell.norm~genotype)
#check for outliers
daf7FISH <- dauergut::flag_outliers(lm, daf7FISH, threshold = 4, noplot = TRUE)

lm.0<-lm(data=daf7FISH[daf7FISH$outlier.status == FALSE,], formula=cell.norm~1)
lm.1<-lm(data=daf7FISH[daf7FISH$outlier.status == FALSE,], formula=cell.norm~genotype)
#anova(lm.0, lm.1) p ~ 0.013


stanlm <- stan_glm(cell.norm ~ genotype, data = daf7FISH[daf7FISH$outlier.status == FALSE,])




#plot daf7 FISH
strains <- levels(daf7FISH$genotype)
contrasts <- dauergut::dunnett_contrasts(lm.1,ref.index = 1,"genotype")
mixed <- stanlm %>% dauergut::getStan_CIs()
rescue.test <- daf7FISH[daf7FISH$outlier.status == FALSE,] %>% subset(genotype %in% c("mg360", "mg360resc")) %$% t.test(cell.norm ~ genotype)
rescue.p <- data.frame(p.value = rescue.test$p.value) %>% dauergut::prange()

plot.contrasts <- c("", contrasts$prange[1:2],"")
plot.contrasts.2 <- c("", "", "", rescue.p$prange)

labels <- c("WT","rict-1(ft7)","rict-1(mg360)" ,"rict-1(mg360); +ges1p::rict-1") %>% stringr::str_wrap(width = 10)

dauergut::plot_CIs(daf7FISH[daf7FISH$outlier.status == FALSE,], title = "daf7 mRNA is reduced in rict-1 mutants", plot.contrasts = plot.contrasts, plot.contrasts.2 = plot.contrasts.2, ypos = 150, offset = 0, type = "expression", labels = labels)

Figure 2B daf-7 mRNA is reduced in rict-1 mutants. Intestinal expression of rict-1 using the intestinal ges-1 promoter rescues daf-7 expression. Quantification of daf-7 mRNA levels in ASI assessed via fluorescent in situ hybridization. Expression was normalized by subtracting mean background pixel values for each image. Each dot is the fluorescence intensity in a single ASI neuron; numbers in parentheses below indicate the number of neurons examined in 3 independent pooled experiments. Horizontal thick bar indicates median. Error bars are quartiles. Light gray thin and thick vertical bars at right indicate Bayesian 95% and 75% credible intervals, respectively. P-values of differences relative to wild-type and rict-1(mg360) animals are indicated in black and red, respectively. For rict-1(mg360) and rict-1(ft7), r contrasts$prange[1] and r contrasts$prange[2] compared to N2, respectively. For ges-1 rescue, r rescue.p$prange compared to rict-1(ft7). n=2 independent experiments, pooled data. r nrow(daf7FISH[daf7FISH$outlier.status == TRUE,]) outlier data points were removed in total. P-values of differences in means relative to wild-type and corresponding mutant animals are indicated in black and red, respectively.

library(sjPlot)
sjt.lm(lm.1, depvar.labels = "mean mRNA levels (AU)", show.se = TRUE, show.fstat = TRUE)
knitr::kable(contrasts, caption="Pairwise comparisons from ANOVA (Dunnett)")
knitr::kable(mixed[,c(6,1:5)], caption = "Bayesian credible intervals")

2C

#days = as.factor(8:10) # days containing N2 and ft7 27º data
dates = c("12_1_16",  "12_20_17", "12_21_17", "12_6_16",  "9_21_16" )
strains = c("N2", "ft7", "ft7exifb2", "ft7exgpa4")
foods = "OP50"
d28<-read.csv('extdata/2C_Daf28GFP_rescue.csv') %>%
separate(ID, c("ID.A", "ID.B"), sep = ":", extra = "drop") %>%
  subset(mean!=4095 & food == foods & temp == "27" & genotype %in% strains & pheromone == 0) %>%
  mutate(genotype = factor(genotype, levels = strains),
         genoID = interaction(date,genotype, ID.A)
         )

df <- d28 %>% group_by(neuron,date,genotype,genoID) %>% 
  summarise(cell.norm = mean(mean, na.rm = TRUE)) %>%
  data.frame() %>% 
  mutate(group.id = interaction(genotype, neuron),
         dataset = case_when(
           date %in% c("12_1_16","12_6_16","9_21_16") ~ "3C_3D",
           date %in% c("12_20_17", "12_21_17") ~ "_new"
         )) # take mean of each worm
day.means <- df %>%
  filter(genotype == "ft7") %>% 
  group_by(date,neuron) %>%
  summarise(mean_ft7 = mean(cell.norm)) %>% data.frame()

#normalize to mean rict-1 mutant ASJ value per day
df %<>% mutate(cell.norm = 
                 case_when(
                   neuron == "ASI" ~ case_when(
                     date == dates[1] ~ (cell.norm * day.means[2,3]) / day.means[2,3],
                     date == dates[2] ~ (cell.norm * day.means[2,3]) / day.means[4,3],
                     date == dates[3] ~ (cell.norm * day.means[2,3]) / day.means[6,3],
                     date == dates[4] ~ (cell.norm * day.means[2,3]) / day.means[8,3],
                     date == dates[5] ~ (cell.norm * day.means[2,3]) / day.means[10,3]
                   ),
                   neuron == "ASJ" ~ case_when(
                     date == dates[1] ~ cell.norm,
                     date == dates[2] ~ (cell.norm * day.means[2,3]) / day.means[4,3],
                     date == dates[3] ~ (cell.norm * day.means[2,3]) / day.means[6,3],
                     date == dates[4] ~ (cell.norm * day.means[2,3]) / day.means[8,3],
                     date == dates[5] ~ (cell.norm * day.means[2,3]) / day.means[10,3]
                   )
                 )
)



#fit simple linmod to est outliers:
log.tran<-lsmeans::make.tran(type="genlog", param = c(0,10)) #make log10 transformation
lm1 <- with(log.tran, lm(linkfun(cell.norm) ~ neuron * genotype, data = df))
df %<>% flag_outliers(lin.mod=lm1, threshold = 4, df = ., noplot=TRUE)

# linear MM
lm <- with(log.tran, lm(linkfun(cell.norm) ~ neuron * genotype, data = df[df$outlier.status==FALSE,]))
stanlmer <- with(log.tran, stan_lmer(linkfun(cell.norm) ~ 1 + group.id + (1|date) + (1:group.id:date), data = df[df$outlier.status==FALSE,]))


contrasts<-summary(lsmeans::lsmeans(lm, pairwise ~ genotype | neuron)$contrasts) %>% dauergut::prange()
mixed <- stanlmer %>% getStan_CIs(type = "log", group = "neuron", base = 10, compare_gt = TRUE) %>% 
  mutate(x.pos = rep(c(1.3,2.3,3.3,4.3),2))
plot.contrasts<-c("",contrasts$prange[1:3],
                  "",contrasts$prange[7:9])
plot.contrasts.2<-c("","",contrasts$prange[4:5],
                    "","",contrasts$prange[10:11])

labels <- c("WT",
            "rict-1(ft7)", 
            "rict-1(ft7); +ifb2p::rict-1",
            "rict-1(ft7); +gpa4p::rict-1") %>% stringr::str_wrap(width = 10)
#plot
p <- df %>% 
  ggplot(aes(x=genotype, y = cell.norm)) +
  geom_quasirandom(aes(y=cell.norm, pch = dataset),cex=1,colour = "#339900",
                           width = 0.075,size=0.3,
                           method = 'smiley') +
  theme_my +
  guides(pch=FALSE) +
  list(dauergut::add.median(width = 0.25), dauergut::add.quartiles()) +
  labs(title = "daf-28 is also reduced in rict-1 mutants",
           y = "mean GFP intensity", x="genotype") +
  stat_summary(aes(x=genotype, group = genotype, y = 3000), geom="text", fun.data=box_annot,
                    label=plot.contrasts, size = 4) +
  stat_summary(aes(x=genotype, group = genotype, y = 2800), geom="text", fun.data=box_annot,
                    label=plot.contrasts.2, size = 4, colour = "red") +
  geom_errorbar(data=mixed, aes(x=x.pos,y=mean, ymin=lower.CL, ymax=upper.CL),
                     width=0,colour ="grey", lwd=0.15) +
  geom_errorbar(data=mixed, aes(x=x.pos,y=mean, ymin = lower.25, ymax = upper.75),
                     width=0,colour = "darkgrey", lwd = 0.15+0.7) +
  stat_summary(aes(x=as.numeric(as.factor(genotype)) + 0.3,y=0,group = genotype),
                    fun.data = fun_length, geom = "text",size = 4) +
  facet_grid(.~neuron) + 
  scale_x_discrete(labels = labels) +
  theme(strip.background = element_blank(),
        strip.text = element_text(size = 16,face="bold"),
        axis.text.y = element_text(size=12),
        axis.text.x = element_text(size = 12, face = "italic"),
        axis.title = element_text(size=16),
        panel.spacing.x=unit(2,"lines"))

#image of daf-28 GFP
img.path <- file.path(pathname,"figures","2D_daf-28GFP.png")
``` {r, results = 'markup', eval = TRUE} include_graphics(img.path) wzxhzdk:8
**Figure 2C** (Left) Representative images of _daf-28p::gfp_ expression in one of the bilateral and ASI and ASJ neurons in animals of the indicated genotypes. Yellow filled and open arrowheads indicate ASI and ASJ soma, respectively. Anterior is at left. Scale bar: 5 μm. (Right) Quantification of _daf-28p::gfp_ expression in ASI and ASJ. Each dot is the mean fluorescence intensity in a single animal (2 neurons per animal); numbers in parentheses below indicate the number of animals examined in 3 independent experiments. Horizontal thick bar indicates median. Error bars are quartiles. Light gray thin and thick vertical bars at right indicate Bayesian 95% and 75% credible intervals, respectively. `**` and `***` - different from wild-type at P<0.01 and P<0.001, respectively; (ANOVA with Tukey-type multivariate-t post-hoc adjustment).
library(sjPlot)
sjt.lm(lm, depvar.labels = "log(mean GFP intensity) (AU)", show.se = TRUE, show.fstat = TRUE)
knitr::kable(mixed[,c(6,1:5)], caption = "Bayesian credible intervals")

knitr::kable(contrasts, caption = "pairwise comparisons (Tukey)")

2D

strains<-c("N2", "rict-1(mg360)", "rict-1(ft7)")
#dates<-c("12_5_14", "12_19_14", "1_19_15","3_22_14", "2_25_14", "4_11_14")
dates<-c("12_5_14", "12_19_14","3_22_14", "2_25_14", "4_11_14")
foods <- c("OP50", "HB101")
rict1.food<-read.csv(file.path(pathname, "extdata", "1B_2D_rict-1_TORC2.csv"), header=TRUE) %>% format_dauer(p.dauer = "exclude") %>%
  dplyr::filter(day %in% dates) %>% mutate(logit.p = car::logit(pct, adjust=0.01), 
                                           plate.ID = interaction(food, plateID))

# rict1.food %>% ggplot(aes(x=food, y=pct)) + geom_boxplot() + stat_summary(aes(y=pct, group=day, colour = day), fun.y = mean, geom = "line") + facet_grid(.~genotype)

#lm
lm.add <- lm(pct ~ genotype + food, data = rict1.food)
lm.int <- update(lm.add,.~. + genotype*food)
#stan
rict.food.groups <- rict1.food %>% mutate(group.id = interaction(genotype, food))
stan.glmm <- run_dauer_stan(df = rict.food.groups, type="dauer-grouped", group = "food", intercept = FALSE)
contrasts<-dauergut::dunnett_contrasts(lm.int, ref.index = 1, factor = "genotype", interaction = "food")
mixed<-dauergut::getStan_CIs(stan.glmm, type="dauer", group = "food", intercept = FALSE)

plot.contrasts <- c("",contrasts$interaction$prange[1], "", contrasts$interaction$prange[2], "", contrasts$interaction$prange[3])
plot.contrasts.interaction <- summary(lm.int)$coefficients[,4][5:6] %>% data.frame() %>% mutate(p.value = c(.[[1]],.[[2]]), genotype = strains[2:3]) %>% dauergut::prange()

index<-rep(seq_len(length(strains)), each = 2)

plot.contrasts.H0 <- data.frame(cbind(food = foods, genotype = strains[index])) %>%
  mutate(prange = plot.contrasts)

(p<-ggplot(rict1.food, aes(x=food)) +
  stat_summary(aes(y=pct, group=day), colour = "black", fun.y = mean, geom = "line", alpha = 0.2, linetype = 2) +
  add.median.dauer() +
  add.Bayes.CI() +
  geom_dotplot(aes(y=pct, colour = food, fill=food),binwidth=.015, binaxis="y", position="dodge", stackdir="center", size =.3) +
    #geom_point(aes(y=pct,colour = food), size = 0.7, alpha = 0.75) +
  labs(title = "rict-1 mutants are deficient in food suppression",
           y = "proportion dauer",
           x = "food") +
  facet_grid(.~genotype, switch="both") +
  scale_colour_manual(values = c("black", "#FF9933")) +
    scale_fill_manual(values = c("black", "#FF9933")) +
      scale_y_continuous(breaks=c(0,0.25,0.5,0.75, 1.0)) +
      scale_x_discrete(labels=function(x) sub(" ","\n",x,fixed=TRUE)) +
  geom_text(data = plot.contrasts.H0, aes(x=2, label = prange, y = 1.075, group = NULL), size = 4) +
    stat_summary(aes(x=as.numeric(as.factor(food)) + 0.3, y=-0.05),
                   fun.data = fun_length, geom = "text", size = 3) +
  theme_classic() + 
    theme(strip.text.x = element_text(size = 12, face="italic"),
      axis.text.x = element_blank(),
          axis.text.y = element_text(size = 12),
          axis.line = element_line(size=0.2),
          axis.title = element_text(size=16)))

Figure 2D
rict-1 mutants are deficient in food suppression of dauer formation. Dauers formed by wild-type and rict-1 mutants on OP50 or HB101 at 27°C. Each black dot indicates the average number of dauers formed in a single assay. Horizontal black bar indicates median. Light gray thin and thick vertical bars at right indicate Bayesian 95% and 75% credible intervals, respectively. Numbers in parentheses below indicate the number of independent experiments with at least 19 animals scored in each. Dashed lines indicate mean change in dauer formation per experimental day. P-values are with respect to growth on OP50; *** - different from growth on OP50 at P<0.001 [two-factor ANOVA with F(r round(anova(lm.int)$F[3],2)) with r anova(lm.int)$Df[3] Df, P=r round(anova(lm.int)$Pr[3],4) for genotype*food interaction, Tukey-type multivariate-t post-hoc adjustment].

library(sjPlot)
sjt.lm(lm.int, depvar.labels = "proportion of dauers", show.fstat = TRUE)
knitr::kable(contrasts[1], caption = "pairwise comparisons by genotype (ANOVA)")
knitr::kable(contrasts[2], caption = "pairwise comparisons by food (ANOVA)")

S1A

include_graphics(file.path(pathname, "figures","S1A_daf7FISH.png"))

S1B

strains<-c("N2","mg360")
conc.adjust <-15
dates<-c("8_10_16")
d7GFP<-read.csv(file.path(pathname,"extdata","2A_3A_daf7GFP.csv")) %>% filter(mean!=4095 & genotype %in% strains & date %in% dates & temp == "25" & food == "OP50") %>% mutate(genotype = factor(genotype, levels=strains), ID = as.character(ID)) %>%
  separate(ID, c("ID.A", "ID.B"), sep = ":", extra = "drop") %>% 
  mutate(genoID = paste(date, genotype, ID.A, sep = ":"), cell.norm = mean, adj.pheromone = pheromone + conc.adjust, 
         inv.pher = 1/adj.pheromone) #genoID is animal, 2 cells per animal measured.

df <- d7GFP %>% group_by(date, genotype, genoID, adj.pheromone) %>% summarise(cell.norm = mean(cell.norm))

log.tran<-lsmeans::make.tran(type="genlog", param = c(0,10))

#convert to proportion:
lm <- lm(cell.norm ~ genotype + adj.pheromone,  data = df)
lm1<- lm(cell.norm ~ genotype + poly(adj.pheromone,2),  data = df)
lm2 <- lm(cell.norm ~ genotype * poly(adj.pheromone, 2), data = df)

# stanlmer <- with(log.tran, rstanarm::stan_lmer(linkfun(cell.norm) ~ genotype + (1|date) + (1:genotype:date),
#                                                data = df,
#                                                chains = 3,
#                                                cores =4,
#                                                seed = 2000,
#                                                iter=6000,
#                                                control = list(adapt_delta=0.99)))


newdata = data.frame(genotype = rep(strains, each = 241), adj.pheromone = rep(seq(10,2410, by = 10),2),genoID = rep(0, 482))

### for non-interaction ### 
#glm.simple <- glm(data = rictC3, cbind(dauer, non) ~ concentration.uM. + genotype, family = binomial)
predictions <- predict(lm, newdata = newdata, type = "response", se.fit = TRUE)
predictions.2 <- predict(lm2, newdata = newdata, type = "response", se.fit = TRUE)
newdata1 <- cbind(newdata, predictions.2)
newdata1 %<>% mutate(lower = (fit - se.fit), upper = (fit + se.fit), AU = fit, genotype = factor(genotype, levels = strains))


(p<-df %>% ungroup %>% ggplot(aes(x= adj.pheromone)) +
    geom_ribbon(data = newdata1,aes(ymin=lower, ymax=upper, fill=genotype), alpha=0.3) +
    geom_line(data = newdata1,aes(x =  adj.pheromone, y = AU, colour = genotype)) +
    add.median(width = 150) +
    add.quartiles(width = 60) +
    geom_quasirandom(aes(y=cell.norm),colour = "#339900", cex=1,
                           width = 40,size=0.3,
                           method = 'smiley') +
    labs(y = "GFP intensity (AU)",
         x = "ascr#5 concentration (nM)") +
    facet_grid(.~genotype) +
    scale_fill_manual(values = c("grey", "lightblue")) +
    scale_colour_manual(values = c("grey", "lightblue")) +
  geom_text(aes(y = 1.075, x= adj.pheromone), label = "") +
  theme_classic() +
  theme(
        axis.text.x=element_text(angle=45, hjust=1, size=12),
        axis.text.y = element_text(size=16),
        axis.title.y = element_text(size =20),
        axis.title.x = element_text(size=16),
        strip.text.x = element_blank(),
        panel.spacing = unit(2,"lines")) +
    stat_summary(aes(x= adj.pheromone + 0.3, y=-.025),
                      fun.data = fun_length, geom = "text", size = 4))

Figure S1B rict-1 mutants show enhanced response to pheromone ascr#5. daf-7::GFP expression in wild-type (black) and rict-1(mg360) (blue) animals at 25°C in the presence of the indicated concentrations of ascr#5 and live OP50. Each dot indicates the average ASI GFP intensity in each each animal (2 neurons per animal). Horizontal bar indicates median, error bars indicate quartiles. The number of animals are indicated in parentheses. Lines indicate predictions from quadratic fit.

library(sjPlot)
sjt.lm(lm2, depvar.labels = "proportion of dauers", show.se = TRUE, show.fstat = TRUE)

S1C

strains <- c("N2", "rict-1(ft7)")
foods <- "OP50"
rictC3 <- read.csv(file.path(pathname, 'extdata','S1C_rict1Pheromone.csv')) %>% format_dauer(p.dauer = "exclude") %>% mutate(plateID = interaction(plateID,concentration.uM.)) 

# for glm fit
glm <- glm(data = rictC3, cbind(dauer, non) ~ concentration.uM. + genotype + concentration.uM. * genotype, family = binomial)

newdata = data.frame(genotype = rep(strains, each = 241), concentration.uM. = rep(seq(0,2.4, by = 0.01),2),plateID = rep(0, 482), n = rep(60, 482))

### for non-interaction ### 
glm.simple <- glm(data = rictC3, cbind(dauer, non) ~ concentration.uM. + genotype, family = binomial)
predictions <- predict(glm, newdata = newdata, type = "response", se.fit = TRUE)
newdata1 <- cbind(newdata, predictions)
newdata1 %<>% mutate(lower = (fit - se.fit), upper = (fit + se.fit), pct = fit)


(p<-rictC3 %>% ggplot(aes(x=concentration.uM.,y = pct)) +
  geom_ribbon(data = newdata1,aes(ymin=lower, ymax=upper,fill=genotype), alpha=0.3) +
  geom_line(data = newdata1,aes(x = concentration.uM., y = pct, colour = genotype)) +
  geom_point(aes(y=pct), size = 0.6, alpha = 0.75) +
  add.median.dauer() +
  labs(y = "proportion dauer", 
       x = "ascr#5 concentration (uM)") +
  facet_grid(.~genotype) +
  scale_fill_manual(values = c("grey", "lightblue")) +
  scale_colour_manual(values = c("grey", "lightblue")) +
  geom_text(aes(y = 1.075, x=concentration.uM.), label = "") +
    coord_cartesian(ylim = c(-.005,1.075)) +
      scale_y_continuous(breaks=c(0,0.25,0.5,0.75,1)) +
  theme_classic() +
  theme(
        axis.text.x = element_text(size=16),
        axis.text.y = element_text(size=16),
        axis.title.y = element_text(size =20),
        axis.title.x = element_text(size=16),
        strip.text.x = element_blank(),
        panel.spacing = unit(2,"lines")) +
    stat_summary(aes(x=concentration.uM. + 0.3, y=-.025),
                      fun.data = fun_length, geom = "text", size = 4)
)

Figure S1C rict-1 mutants show enhanced response to pheromone ascr#5. Dauers formed by wild-type (black) and rict-1(ft7) (blue) animals at 25°C in the presence of the indicated concentrations of ascr#5. Each dot indicates the proportion of dauers formed in a single assay. Horizontal bar indicates median. Numbers in parentheses below indicate the number of independent experiments with at least 27 animals each. Lines indicate predictions from GLM fit, corresponding to an odds ratio of as.numeric(round(exp(coef(glm))[3],1)) for rict-1 across this range of ascr#5 concentrations.

library(sjPlot)
sjt.glm(glm, depvar.labels = "proportion of dauers", show.se = TRUE, show.chi2 = TRUE)

S1D

foods <- "OP50"
strains<-c("N2","rict-1(ft7)","rict-1(ft7); ex[ASI::daf7]","rict-1(ft7); ex[ASI::daf28]","rict-1(ft7); ex[ASJ::daf28]")
daf7supp<-read.csv(file.path(pathname, "extdata","S1D_daf7_daf28_suppression.csv")) %>% format_dauer(p.dauer = "non")

# daf7supp$genotype<- factor(daf7supp$genotype, levels = strains)
# daf7supp$pct<-as.numeric(paste(daf7supp$dauer/(daf7supp$dauer+daf7supp$pd + daf7supp$non))) #omitted arrest
# daf7supp$non.dauer<-as.numeric(paste(daf7supp$pd+daf7supp$non))

lm <- daf7supp %>% dauer_ANOVA()
#stan
stan.glmm <- daf7supp %>% dauergut::run_dauer_stan()
foods <- "OP50"
contrasts<-dauergut::tukey_contrasts(lm, "genotype")
mixed<-stan.glmm %>% dauergut::getStan_CIs(type = "dauer")
plot.contrasts<-c("",contrasts$prange[1],"","","")
plot.contrasts.2<-c("", "", contrasts$prange[5:7]) #for rescue vs rict-1

labels <- c("WT","rict-1(ft7)","rict-1(ft7); +ASIp::daf-7","rict-1(ft7); +ASIp::daf-28","rict-1(ft7); +ASJp::daf-28") %>% stringr::str_wrap(width = 10)


p<-dauergut::plot_CIs(daf7supp, title='daf-7 expression in ASI suppresses rict-1 dauer phenotype', plot.contrasts, plot.contrasts.2, ypos = 1.075, offset = 0, type = "dauer", labels = labels)
wzxhzdk:20




Figure 2C Expression of daf-7 in ASI or daf-28 in ASI or ASJ suppressed aberrent dauer formation in rict-1 mutants. Dauers formed by animals of the indicated genotypes at 27°C. Each black dot indicates the average number of dauers formed in a single assay. Horizontal black bar indicates median. Light gray thin and thick vertical bars at right indicate Bayesian 95% and 75% credible intervals, respectively. Numbers in parentheses below indicate the number of independent experiments with at least 36 and 9 animals each scored for non-transgenic and transgenic animals, respectively. Promoters driving expression in ASI and ASJ were srg-47p and trx-1p, respectively. One transgenic line was tested for each condition. *** - different from wild-type at P<0.001; ** and *** - different from rict-1(ft7) at P<0.01 and P<0.001, respectively (ANOVA with Tukey-type multivariate-t post-hoc adjustment). P-values of differences in means relative to wild-type and corresponding mutant animals are indicated in black and red, respectively.

library(sjPlot)
sjt.lm(lm, depvar.labels = "proportion of dauers", show.se = TRUE, show.fstat = TRUE)
knitr::kable(contrasts, caption="Pairwise comparisons from ANOVA (Tukey)")
knitr::kable(mixed[,c(6,1:5)], caption = "Bayesian credible intervals")

S1E

strains<-c("N2","rict-1(mg360)","rict-1;daf-16")
foods <- "OP50"
daf16supp<-read.csv(file.path(pathname, "extdata","S1E_daf16_suppression.csv")) %>% format_dauer(.,p.dauer = "dauer")

# daf28supp$genotype<- factor(daf28supp$genotype, levels = strains)
# daf28supp$pct<-as.numeric(paste(daf28supp$dauer/(daf28supp$dauer+daf28supp$pd + daf28supp$non))) #omitted arrest
# daf28supp$non.dauer<-as.numeric(paste(daf28supp$pd+daf28supp$non))
lm <- daf16supp %>% dauer_ANOVA()
#stan
stan.glmm <- daf16supp %>% stan_glmer(formula = cbind((dauer+pd), (n-(dauer+pd))) ~ genotype + (1|day) + (1|strainDate) + (1|plateID),
                       data=.,
                       family = binomial(link="logit"),
                       chains = 3, cores =4, seed = 2000,iter=6000,
                       control = list(adapt_delta=0.99))
contrasts<-dauergut::tukey_contrasts(lm, "genotype")
mixed<-stan.glmm %>% getStan_CIs(type="dauer")
plot.contrasts<-c("",contrasts$prange[1],"")
plot.contrasts.2<-c("", "", contrasts$prange[3]) #for rescue vs rict-1

labels <- c("WT","rict-1(mg360)","daf-16(mu86; rict-1(mg360)") %>% stringr::str_wrap(width = 10)

p<-dauergut::plot_CIs(daf16supp, title='rict-1 acts in the insulin pathway to inhibit dauer formation', plot.contrasts, plot.contrasts.2, ypos = 1.075, offset = 0, type = "dauer", labels = labels)
wzxhzdk:24




Figure S1E Mutations in rict-1 modulate dauer formation via downregulation of neuroendocrine signaling. daf-16 mutations partially suppress the dauer formation phenotype of rict-1 mutants. Dauers formed by animals of the indicated genotypes at 27°C. Each dot indicates the proportion of dauers formed in a single assay. Horizontal bar indicates median. Light gray thin and thick vertical bars at right indicate Bayesian 95% and 75% credible intervals, respectively. Numbers in parentheses below indicate the number of independent experiments with at least 26 animals each. *** - different from wild-type at P<0.001, *** - different from rict-1(mg360) at P<0.001 (ANOVA with Tukey-type multivariate-t post-hoc adjustments). P-values of differences in means relative to wild-type and corresponding mutant animals are indicated in black and red, respectively.

library(sjPlot)
sjt.lm(lm, depvar.labels = "proportion of dauers", show.se = TRUE, show.fstat = TRUE)
knitr::kable(contrasts, caption="Pairwise comparisons from ANOVA (Tukey)")
knitr::kable(mixed[,c(6,1:5)], caption = "Bayesian credible intervals")


mikeod38/dauergut documentation built on May 30, 2019, 7:16 p.m.