library(car)

data=read.csv('Kinetics4.csv')

x_range=range(data$Time)
nucleotide=c('A','U','A6','G')
color=c('blue','orangered','grey','orange')

y_range=range(pretty(range(data$Pre_RISC)))
pdf('Pre_RISC_decrease.pdf',width=8,height=6)
plot(1,1,xlim=x_range,ylim=y_range,xlab='Time (min)',ylab='Pre-RISC abundance (A.U.)',type='n')
for (nt in 1:length(nucleotide))
{
par(new=T)
plot(data$Time[data$Nucleotide==nucleotide[nt]],data$Pre_RISC[data$Nucleotide==nucleotide[nt]],xlim=x_range,ylim=y_range,xlab='',ylab='',col=color[nt],axes=F)
m=c()
for (t in unique(data$Time))
m=append(m,mean(data$Pre_RISC[data$Nucleotide==nucleotide[nt] & data$Time==t]))
par(new=T)
plot(unique(data$Time),m,xlim=x_range,ylim=y_range,xlab='',ylab='',col=color[nt],axes=F,ty='l',lwd=2)
}
legend('topright',nucleotide,col=color,pch='-',lwd=2)
dev.off()

### Analysis of pre-RISC accumulation kinetics (simplified as : [pre-RISC] = A*(1-2^(-t/tau)) with t: time (expressed in minutes) and tau=10 min (according to the aspect of the curves)
variable=1-2^(-data$Time/10)
c=aov(data$Pre_RISC~data$Nucleotide+variable)
summary(c)
d=aov(data$Pre_RISC~data$Nucleotide*variable)
summary(d) # Conclusion: no significant interaction term between Nucleotide and Time
# Applicability of ANOVA:
leveneTest(data$Pre_RISC~data$Nucleotide*as.factor(data$Time)) # Variances appear to be homogeneous
shapiro.test(residuals(c)) # Residuals are hardly normally distributed (p-value=0.049); let's try log-transformation
verification_desc=c('Levene test on untransformed data','Shapiro-Wilk test on residuals from untransformed data')
verification_pval=c(signif(leveneTest(data$Pre_RISC~data$Nucleotide*as.factor(data$Time))$Pr[1],digits=3),signif(shapiro.test(residuals(c))$p.value,digits=3))
transf=log(data$Pre_RISC)
transf[!is.finite(transf)]=NA
c=aov(transf~data$Nucleotide+variable)
summary(c) # Conclusion: only time has a significant effect (hence testing interaction would be pointless, and pairwise tests too)
verification_desc=append(verification_desc,c('Levene test on log-transformed data','Shapiro-Wilk test on residuals from log-transformed data'))
verification_pval=append(verification_pval,c(signif(leveneTest(transf~data$Nucleotide*as.factor(data$Time))$Pr[1],digits=3),signif(shapiro.test(residuals(c))$p.value,digits=3)))
verification=list(verification_desc,verification_pval)
names(verification)=c('Statistical test','p-value')
write.csv(as.data.frame(verification),'ANOVA_applicability_verification_Figure_5_pre_RISC.csv')
leveneTest(transf~data$Nucleotide*as.factor(data$Time)) # Variances appear to be homogeneous after log-transformation
shapiro.test(residuals(c)) # Residuals appear to be normally distributed after log-transformation

