-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbonsplot.jl
103 lines (95 loc) · 3.84 KB
/
bonsplot.jl
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
using Gadfly,Color,NeuroAnalysis.NABase
function bonsplot(bons;path="./figure/bons")
dfile = bons["datafile"]
# if !contains(dfile,"29j")
# return
# end
spike = bons["spike"]
fl = bons["fl"]
factors = collect(keys(fl))
minconddur = bons["minconddur"]
dataset = bons["dataset"]
figon = bons["figon"]
figoff = bons["figoff"]
binwidth = 10 # ms
figonex = 100 # ms
figoffex = 200 # ms
minrepeat = 5
ps = []
ispsth=true
if ispsth
st,sn,ws,is = subrv(spike,figon-figonex,figoff+figoffex,isminzero=true)
st = map(x->x-figonex,st)
bin = -figonex:binwidth:minconddur+figoffex
onoff=[0,minconddur]
for f=keys(fl)
is,ss = findcond(dataset,flcond(fl,f))
if isempty(is) || any(map(length,is).<minrepeat)
print("$dfile: level of \"$f\" do not exist or repeats < $minrepeat.\n")
continue
end
df = psth(map(x->st[x],is),bin,ss)
df[:ymin] = df[:y]-df[:ysd]./sqrt(df[:n])
df[:ymax] = df[:y]+df[:ysd]./sqrt(df[:n])
t = "$dfile - $(f)"
p = plot(df,x=:x,y=:y,ymin=:ymin,ymax=:ymax,color=:condition,xintercept=onoff,
Geom.line,Geom.ribbon,Geom.vline(color="gray",size=1pt),
Coord.Cartesian(xmin=bin[1],xmax=bin[end],ymin=0),Guide.xlabel("Time (ms)"),Guide.ylabel("Response (spike/s)"),Guide.title(t))
ps = [ps,(t,p)]
end
f1 = "FigSide"
for f2=filter(x->x!=f1,factors)
is,ss = findcond(dataset,flcond(fl,f1,f2))
if isempty(is) || any(map(length,is).<minrepeat)
print("$dfile: level of \"$f1-$f2\" do not exist or repeats < $minrepeat.\n")
continue
end
df = psth(map(x->st[x],is),bin,ss)
df[:ymin] = df[:y]-df[:ysd]./sqrt(df[:n])
df[:ymax] = df[:y]+df[:ysd]./sqrt(df[:n])
t = "$dfile - $(f1)-$(f2)"
p = plot(df,x=:x,y=:y,ymin=:ymin,ymax=:ymax,color=:condition,xintercept=onoff,
Geom.line,Geom.ribbon,Geom.vline(color="gray",size=1pt),
Coord.Cartesian(xmin=bin[1],xmax=bin[end],ymin=0),Guide.xlabel("Time (ms)"),Guide.ylabel("Response (spike/s)"),Guide.title(t))
ps = [ps,(t,p)]
end
f2 = "EdgeContrast"
for f3=filter(x->x!=f2 && x!=f1,factors)
is,ss = findcond(dataset,flcond(fl,f2,f3))
if isempty(is) || any(map(length,is).<minrepeat)
print("$dfile: level of \"$f2-$f3\" do not exist or repeats < $minrepeat.\n")
continue
end
df = psth(map(x->st[x],is),bin,ss)
df[:ymin] = df[:y]-df[:ysd]./sqrt(df[:n])
df[:ymax] = df[:y]+df[:ysd]./sqrt(df[:n])
t = "$dfile - $(f2)-$(f3)"
p = plot(df,x=:x,y=:y,ymin=:ymin,ymax=:ymax,color=:condition,xintercept=onoff,
Geom.line,Geom.ribbon,Geom.vline(color="gray",size=1pt),
Coord.Cartesian(xmin=bin[1],xmax=bin[end],ymin=0),Guide.xlabel("Time (ms)"),Guide.ylabel("Response (spike/s)"),Guide.title(t))
ps = [ps,(t,p)]
end
f3 = "xRFSize"
for f4=filter(x->x!=f3 && x!=f2 && x!=f1,factors)
is,ss = findcond(dataset,flcond(fl,f3,f4))
if isempty(is) || any(map(length,is).<minrepeat)
print("$dfile: level of \"$f3-$f4\" do not exist or repeats < $minrepeat.\n")
continue
end
df = psth(map(x->st[x],is),bin,ss)
df[:ymin] = df[:y]-df[:ysd]./sqrt(df[:n])
df[:ymax] = df[:y]+df[:ysd]./sqrt(df[:n])
t = "$dfile - $(f3)-$(f4)"
p = plot(df,x=:x,y=:y,ymin=:ymin,ymax=:ymax,color=:condition,xintercept=onoff,
Geom.line,Geom.ribbon,Geom.vline(color="gray",size=1pt),
Coord.Cartesian(xmin=bin[1],xmax=bin[end],ymin=0),Guide.xlabel("Time (ms)"),Guide.ylabel("Response (spike/s)"),Guide.title(t))
ps = [ps,(t,p)]
end
end
if !isempty(ps)
for p in ps
NeuroAnalysis.NAVisualization.savefig(p[2],p[1],path=path,format="svg")
NeuroAnalysis.NAVisualization.savefig(p[2],p[1],path=path,format="png")
end
end
end