Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add files via upload
- Loading branch information
0 parents
commit a45ad1b
Showing
6 changed files
with
715 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
by_date2<-function(file,gal4){ | ||
setwd(sprintf("~/Dropbox/lab/data sheet/%s/date",file)) | ||
source('~/Dropbox/R/filter_na.R') | ||
if(gal4=="tim"){cell=c(3,4,1,2,5) | ||
cells=5} | ||
if(gal4=="pdf"){cell=c(2,5) | ||
cells=5} | ||
if(gal4=="pdfrB"){cell=c(1,6,5) | ||
cells=6} | ||
if(gal4=="pdf80"){cell=c(3,4,1) | ||
cells=5} | ||
if(gal4=="645"){cell=c(3,4,1,5) | ||
cells=5} | ||
if(gal4=="681"){cell=c(3,4,1,2) | ||
cells=5} | ||
if(gal4=="pdfrB_pdf80"){cell=c(1,6) | ||
cells=6} | ||
if(gal4=="929"){cell=c(2) | ||
cells=5} | ||
|
||
if(is.numeric(gal4)){ | ||
cell=seq(1,gal4) | ||
cells=5} | ||
|
||
|
||
name=list.files() | ||
|
||
LNd=lLNv=DN1=DN3=sLNv=fifth_sLNv=list() | ||
for (k in 1:length(name)){ | ||
a=read.csv(name[k],header=TRUE) | ||
time=a[,1] | ||
|
||
ff=matrix(,144,cells) | ||
t=as.integer(144-time[1]/(24/144)) | ||
#row states | ||
if(grepl("Row",name[k])){ | ||
for (i in 1:cells){ if (length(a)>(i-1)*3+2){ | ||
if(sum(a[,(i-1)*3+2],na.rm=TRUE)!=0){ | ||
for (j in 1:t){ | ||
ff[j+144-t,i]=a[j,(i-1)*3+2] | ||
} | ||
if(t<144){ | ||
for (j in (t+1):length(time)){ | ||
ff[j-t,i]=a[j,(i-1)*3+2] | ||
}} | ||
ff[,i]=filter_na_2(ff[,i]) | ||
ff[,i]=filter(ff[,i], filter=rep(1/7, 7),sides=2,circular = TRUE) | ||
ff[,i]=((ff[,i])-min(ff[,i],na.rm = TRUE))/(max(ff[,i],na.rm = TRUE)-min(ff[,i],na.rm = TRUE))*100 | ||
} | ||
}} | ||
} | ||
#by_date | ||
if(!grepl("Row",name[k])){ | ||
for (i in 1:cells){ | ||
if(sum(a[,i+1],na.rm=TRUE)!=0){ | ||
for (j in 1:t){ | ||
ff[j+144-t,i]=a[j,i+1] | ||
} | ||
if(t<144){ | ||
for (j in (t+1):length(time)){ | ||
ff[j-t,i]=a[j,i+1] | ||
} | ||
} | ||
ff[,i]=filter_na_2(ff[,i]) | ||
ff[,i]=filter(ff[,i], filter=rep(1/7, 7),sides=2,circular = TRUE) | ||
ff[,i]=((ff[,i])-min(ff[,i],na.rm = TRUE))/(max(ff[,i],na.rm = TRUE)-min(ff[,i],na.rm = TRUE))*100 | ||
} | ||
} | ||
} | ||
|
||
|
||
LNd[[length(LNd)+1]]=ff[,1] | ||
lLNv[[length(lLNv)+1]]=ff[,2] | ||
DN1[[length(DN1)+1]]=ff[,3] | ||
DN3[[length(DN3)+1]]=ff[,4] | ||
sLNv[[length(sLNv)+1]]=ff[,5] | ||
|
||
if(gal4=="pdfrB"||gal4=="pdfrB_pdf80"){ | ||
fifth_sLNv[[length(fifth_sLNv)+1]]=ff[,6] | ||
} | ||
|
||
|
||
} | ||
names(LNd) <- c("LNd") | ||
names(lLNv) <- c("lLNv") | ||
names(DN1) <- c("DN1") | ||
names(DN3) <- c("DN3") | ||
names(sLNv) <- c("sLNv") | ||
|
||
save(LNd,lLNv,sLNv,DN1,DN3,file=sprintf("~/Dropbox/lab/data sheet/%s/%s_celltype.RData",file,file)) | ||
|
||
if(gal4=="pdfrB"||gal4=="pdfrB_pdf80"){ | ||
names(fifth_sLNv) <- c("fifth_sLNv") | ||
save(LNd,lLNv,sLNv,DN1,DN3,fifth_sLNv,file=sprintf("~/Dropbox/lab/data sheet/%s/%s_celltype.RData",file,file)) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,258 @@ | ||
by_date3<-function(file,gal4,light,length,cycle,drug,yrange,namecolor,legend=0){ | ||
setwd(sprintf("~/Dropbox/lab/data sheet/%s/date",file)) | ||
source('~/Dropbox/R/filter_na.R') | ||
source('~/Dropbox/R/smooth.R') | ||
name=list.files() | ||
lgd=c("LNd","lLNv","DN1","DN3","sLNv","fifth_sLNv") | ||
LNd=lLNv=DN1=DN3=sLNv=fifth_sLNv=list() | ||
if(missing(length)){length=12} | ||
if(missing(cycle)){cycle=T} | ||
#par(cex=1) | ||
if(is.numeric(gal4)){ | ||
#cell=seq(1,gal4) | ||
cell=gal4 | ||
cells=6} | ||
|
||
else{ | ||
if(gal4=="tim"){cell=c(3,4,1,2,5) | ||
cells=5} | ||
if(gal4=="pdf"){cell=c(2,5) | ||
cells=5} | ||
if(gal4=="pdfrB"){cell=c(1,6,5) | ||
cells=6} | ||
if(gal4=="pdf80"){cell=c(3,4,1) | ||
cells=5} | ||
if(gal4=="pdfrB_pdf80"){cell=c(1,6) | ||
cells=6} | ||
if(gal4=="929"){cell=c(1,2) | ||
cells=5} | ||
if(gal4=="TH"){cell=c(1,2,3,4,5) | ||
cells=5} | ||
if(gal4=="THC"){cell=c(1,2) | ||
cells=5} | ||
if(gal4=="THD"){cell=c(3,4,5) | ||
cells=5} | ||
} | ||
|
||
|
||
|
||
|
||
|
||
for (k in 1:length(name)){ | ||
a=read.csv(name[k],header=TRUE) | ||
time=a[,1] | ||
ff=matrix(,144,cells) | ||
t=as.integer(144-time[1]/(24/144)) | ||
#row states | ||
if(grepl("Row",name[k])){ | ||
for (i in cell){ | ||
if (length(a)>(i-1)*3+2){ | ||
if(sum(a[,(i-1)*3+2],na.rm=TRUE)!=0){ | ||
for (j in 1:t){ | ||
ff[j+144-t,i]=a[j,(i-1)*3+2] | ||
} | ||
if(t<144){ | ||
for (j in (t+1):length(time)){ | ||
ff[j-t,i]=a[j,(i-1)*3+2] | ||
}} | ||
#for (j in 1:dim(a)[1]){ff[j,i]=a[j,(i-1)*3+2]} | ||
#ff[,i]=filter_na_2(ff[,i],7) | ||
if(cycle){ | ||
ff[,i]=filter_na_2(ff[,i],7) | ||
ff[,i]=filter(ff[,i], filter=rep(1/7, 7),sides=2,circular = T) | ||
#ff1=filter_na_2(ff[,i],7) | ||
# if(!is.na(sum(ff1))){ | ||
# ff[,i]=filter(ff1, filter=rep(1/7, 7),sides=2,circular = TRUE)} | ||
# else{ | ||
# ff[,i]=filter(ff[,i], filter=rep(1/7, 7),sides=2,circular = F) | ||
# ff[,i]=filter(ff[,i], filter=rep(1/7, 7),sides=2,circular = F) | ||
# } | ||
} | ||
if(!cycle){ | ||
ff[,i]=filter_na_2(ff[,i],1)} | ||
#ff[,i]=((ff[,i])-min(ff[,i],na.rm = TRUE))/(max(ff[,i],na.rm = TRUE)-min(ff[,i],na.rm = TRUE))*100 | ||
} | ||
} | ||
} | ||
} | ||
#by_date | ||
if(!grepl("Row",name[k])){ | ||
for (i in cell){ | ||
if(sum(a[,i+1],na.rm=TRUE)!=0){ | ||
for (j in 1:t){ | ||
ff[j+144-t,i]=a[j,i+1] | ||
} | ||
if(t<144){ | ||
for (j in (t+1):length(time)){ | ||
ff[j-t,i]=a[j,i+1] | ||
} | ||
} | ||
ff[,i]=filter_na_2(ff[,i],7) | ||
ff[,i]=filter(ff[,i], filter=rep(1/7, 7),sides=2,circular = TRUE) | ||
} | ||
} | ||
} | ||
if(!cycle){ | ||
ff=smooth(ff) | ||
ff=smooth(ff) | ||
} | ||
LNd[[length(LNd)+1]]=ff[,1] | ||
lLNv[[length(lLNv)+1]]=ff[,2] | ||
DN1[[length(DN1)+1]]=ff[,3] | ||
DN3[[length(DN3)+1]]=ff[,4] | ||
sLNv[[length(sLNv)+1]]=ff[,5] | ||
if(gal4=="pdfrB"||gal4=="pdfrB_pdf80"||gal4==6){ | ||
fifth_sLNv[[length(fifth_sLNv)+1]]=ff[,6] | ||
} | ||
} | ||
|
||
############photoperiod | ||
off=length | ||
if (file=="LD"){off=16} | ||
if (file=="SD"){off=8} | ||
|
||
################################################################ | ||
lgd=c("LNd","lLNv","DN1","DN3","sLNv","fifth_sLNv") | ||
color=c("blue","red","green","magenta","orange","cyan") | ||
t=c(0:143)/6 | ||
library("matrixStats") | ||
meanf=stdf=matrix(,144,6) | ||
change=area=wide1=wide2=matrix(,length(LNd),6) | ||
|
||
for (k in cell){ | ||
ff=get(lgd[k]) | ||
f=matrix(,144,length(ff)) | ||
rep=0 | ||
for (j in 1:length(ff)){ | ||
#f[,j]=ff[[j]] | ||
#normalize to 0-100 | ||
#f[,j]=(ff[[j]]-min(ff[[j]]))/(max(ff[[j]])-min(ff[[j]])) | ||
#df/fmax | ||
if(!sum(ff[[j]],na.rm=T)==0){ | ||
if(cycle){ | ||
f[,j]=(ff[[j]]-min(ff[[j]],na.rm=TRUE))/min(ff[[j]],na.rm=TRUE)} | ||
#f[,j]=(ff[[j]]-min(ff[[j]],na.rm=TRUE))/max(ff[[j]],na.rm=TRUE)} | ||
#f[,j]=(ff[[j]]-min(ff[[j]],na.rm=TRUE))/mean(ff[[j]],na.rm=TRUE)} | ||
#f[,j]=(ff[[j]]-mean(ff[[j]],na.rm=TRUE))/sd(ff[[j]],na.rm=TRUE)} | ||
if(!cycle){ | ||
f[,j]=(ff[[j]]-ff[[j]][1])/max(ff[[j]],na.rm=TRUE)} | ||
|
||
change[j,k]=max(ff[[j]],na.rm=TRUE)-min(ff[[j]],na.rm=TRUE) | ||
|
||
} | ||
#f[,j]=(ff[[j]]-min(ff[[j]],na.rm=TRUE))/max(ff[[j]],na.rm=TRUE) | ||
#f[,i]=filter(f[,i], filter=rep(1/5, 5),sides=2,circular = TRUE) | ||
#f[,j]=(ff[[j]]-min(ff[[j]])) | ||
##df/f0 | ||
#f[,j]=(ff[[j]]-ff[[j]][1])/ff[[j]][1] | ||
#f[,j]=(ff[[j]]-min(ff[[j]]))/mean(ff[[j]]) | ||
if(!is.na(sum(f[,j]))){ | ||
rep=rep+1 | ||
wide1[j,k]=which.min(abs(max(f[,j])/2- f[1:which.max(f[,j]),j])) | ||
wide2[j,k]=which.min(abs(max(f[,j])/2- f[which.max(f[,j]):144,j]))+which.max(f[,j]) | ||
} | ||
change[j,k]=(max(f[,j])-min(f[,j])) | ||
area[j,k]=sum(f[,j]) | ||
} | ||
meanf[,k]=rowMeans(f,na.rm=TRUE) | ||
stdf[,k]=rowSds(f,na.rm=TRUE)/(sqrt(rep)) | ||
|
||
yy=range(f,na.rm = TRUE) | ||
par(xpd=TRUE,mai=c(1,1,1,2),cex=1) | ||
# plot(1,type='n',xlim=range(t),ylim=yy,xaxp=c(0,24,6),xlab='ZT/h',ylab='dF/F',main=lgd[k]) | ||
# polygon(c(off,24,24,off),c(yy[1],yy[1],yy[2],yy[2]),col="gray",border=NA) | ||
# matlines(t,f,type="l",lty=1,col=rainbow(length(name))) | ||
# | ||
# | ||
|
||
par(xpd=TRUE) | ||
par(mai=c(1,1,1,2)) | ||
par(oma=c(0,0,0,0)) | ||
plot(1,type='n',xlim=range(t),ylim=yy,xaxp=c(0,24,6),xlab="Circadian Time (h)",ylab='ΔF/F',mgp=c(1.5,.5,0)) | ||
polygon(c(off,24,24,off),c(yy[1],yy[1],yy[2],yy[2]),col="gray",border=NA) | ||
matlines(t,f,type="l",lty=1,col=rainbow(length(name))) | ||
legend(max(t)+1.5,max(yy)-k/30,legend=name,col=rainbow(length(name)),lty=1,cex = 0.7,,bty="n") | ||
|
||
} | ||
|
||
###############plot################################ | ||
lgd=c("LNd","l-LNv","DN1","DN3","s-LNv","5th-sLNv") | ||
if(gal4=="pdfrB"||gal4=="pdfrB_pdf80"){ | ||
lgd=c("PDFR+LNd","l-LNv","DN1","DN3","s-LNv","5th-sLNv")} | ||
|
||
if(is.numeric(gal4)||grepl("TH",gal4)){ | ||
color=c("gold","orchid2","deepskyblue2","tomato","seagreen2","deepskyblue2") | ||
lgd=c("PAL","PAM","PPL1","PPM1","PPM3") | ||
} | ||
if(!missing(namecolor)){color=namecolor} | ||
color_transparent <- adjustcolor(color, alpha.f = 0.1) | ||
bglight <- adjustcolor("yellow", alpha.f = 0.2) | ||
|
||
if(file=="PER_LDC"||grepl("per0",file)){yy=c(0,0.4)} | ||
|
||
if(missing(yrange)){yy=c(min(meanf,na.rm=TRUE)-mean(stdf,na.rm=TRUE),max(meanf,na.rm=TRUE)+max(stdf,na.rm=TRUE))} | ||
else{yy=yrange} | ||
|
||
par(xpd=TRUE,mai=c(1,1,1,2.5)) | ||
#meanf=filter(meanf, filter=rep(1/7, 7),sides=2,circular = TRUE) | ||
plot(1,type='n',xlim=range(t),ylim=yy,xaxp=c(0,24,6),xlab="",ylab='ΔF/F',mgp=c(1.5,.5,0)) | ||
if(missing(light)){ | ||
polygon(c(off,24,24,off),c(yy[1],yy[1],yy[2],yy[2]),col="gray",border=NA) | ||
polygon(c(off,0,0,off),c(yy[1],yy[1],yy[2],yy[2]),col=gray(0.95),border=NA) | ||
light=0 | ||
title(xlab="Circadian Time (h)",line=1.5) | ||
} | ||
if(light=="LD"){ | ||
polygon(c(off,24,24,off),c(yy[1],yy[1],yy[2],yy[2]),col="gray",border=NA) | ||
polygon(c(off,0,0,off),c(yy[1],yy[1],yy[2],yy[2]),col=bglight,border=NA) | ||
title(xlab="Zeitgeber Time (h)",line=1.5) | ||
} | ||
if(light=="DD"){ | ||
polygon(c(0,24,24,0),c(yy[1],yy[1],yy[2],yy[2]),col="gray",border=NA) | ||
title(xlab="Circadian Time (h)",line=1.5) | ||
} | ||
|
||
|
||
#############lines | ||
|
||
for (k in cell){ | ||
polygon(c(t, rev(t)), c(stdf[,k]+meanf[,k], rev(-stdf[,k]+meanf[,k])),col=color_transparent[k], border = NA) | ||
lines(t,meanf[,k],col=color[k],lwd=3) | ||
lines(t,stdf[,k]+meanf[,k],col=color[k],lwd=0.25) | ||
lines(t,-stdf[,k]+meanf[,k],col=color[k],lwd=0.25) | ||
#legend(max(t)+1.5,max(yy)-k/30,legend=lgd[k],col=color[k],lty=1,cex = 0.7,bty="n") | ||
} | ||
if(legend){ | ||
#legend(max(t)+1,max(yy),legend=c("",""),col=color[cell],lty=1,lwd=6,cex = 1,bty="n") | ||
legend(max(t)+1,max(yy),legend=lgd[cell],col=color[cell],lty=1,lwd=6,cex = 1.75,bty="n") | ||
} | ||
# if(!missing(namecolor)){ | ||
# legend(max(t)+1,max(yy),legend=c("",""),col=namecolor,lty=1,lwd=6,cex = 1,bty="n") | ||
# } | ||
if(!missing(drug)){polygon(c(drug,drug+0.2,drug+0.2,drug),c(yy[1],yy[1],yy[2],yy[2]),col="RED",border=NA)} | ||
|
||
#########summary | ||
name=amplitude=sem.amplitude=width=sem.width=mean.area=sem.area=n=matrix(,6,1) | ||
sum=data.frame(name,amplitude,sem.amplitude,width,sem.width,mean.area,sem.area,n) | ||
|
||
for(i in cell){ | ||
sum$name[i]=lgd[i] | ||
sum$n[i]=length(change[,i])-sum(is.na(change[,i])) | ||
sum$amplitude[i]=signif(mean(change[,i],na.rm=T),2) | ||
sum$sem.amplitude[i]=signif(sd(change[,i],na.rm=T)/sqrt(sum$n[i]),2) | ||
w=(wide1[,i]-wide2[,i])/6 | ||
w=abs(w) | ||
sum$width[i]=signif(mean(w,na.rm=T),2) | ||
sum$sem.width[i]=signif(sd(w,na.rm=T)/sqrt(sum$n[i]),2) | ||
sum$mean.area[i]=signif(mean(area[,i],na.rm=T),2) | ||
sum$sem.area[i]=signif(sd(area[,i],na.rm=T)/sqrt(sum$n[i]),2) | ||
|
||
} | ||
write.csv(sum,file=sprintf("~/Dropbox/lab/data sheet/%s/summary_wave.csv",file)) | ||
|
||
|
||
# write.csv(change,file=sprintf("~/Dropbox/lab/data sheet/%s/change.csv",file)) | ||
# write.csv(list(wide1,wide2),file=sprintf("~/Dropbox/lab/data sheet/%s/width.csv",file)) | ||
# write.csv(area,file=sprintf("~/Dropbox/lab/data sheet/%s/area.csv",file)) | ||
return(meanf) | ||
} |
Oops, something went wrong.