This repository has been archived by the owner on Jun 9, 2020. It is now read-only.
forked from chrismayumich/May_et_al_optoFLIC
/
ParametersClass.R
193 lines (184 loc) · 7.71 KB
/
ParametersClass.R
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
## First, the short parameters class
## It is instantiated with a set of initial values
ParametersClass=function(){
Baseline.Window.Minutes=3
Signal.Threshold = 50
Feeding.Threshold.Value=100
Feeding.Interval.Minimum=20
Tasting.Threshold.Interval=c(10,80)
Use.Adaptive.Threshold=FALSE
Adaptive.Threshold.Minimum=8
Adaptive.Threshold.Window.Minutes=2
Adaptive.Threshold.Selection.Quant=0.9
Feeding.Minevents=2
Tasting.Minevents=2
Samples.Per.Second=5
Chamber.Sets=matrix(1:12,ncol=2,byrow=TRUE)
Chamber.Size=2
PI.Multiplier=1
list(Baseline.Window.Minutes=Baseline.Window.Minutes,Signal.Threshold=Signal.Threshold,Feeding.Threshold.Value=Feeding.Threshold.Value,
Feeding.Interval.Minimum=Feeding.Interval.Minimum,Tasting.Threshold.Interval.Low=Tasting.Threshold.Interval[1],
Tasting.Threshold.Interval.High=Tasting.Threshold.Interval[2],
Use.Adaptive.Threshold=Use.Adaptive.Threshold,Adaptive.Threshold.Minimum=Adaptive.Threshold.Minimum,
Adaptive.Threshold.Window.Minutes=Adaptive.Threshold.Window.Minutes,Adaptive.Threshold.Selection.Quant=Adaptive.Threshold.Selection.Quant,
Feeding.Minevents=Feeding.Minevents,Tasting.Minevents=Tasting.Minevents,Samples.Per.Second=Samples.Per.Second,Chamber.Size=Chamber.Size,
Chamber.Sets=Chamber.Sets,PI.Multiplier=PI.Multiplier)
}
ParametersClass.SingleWell=function(){
Baseline.Window.Minutes=3
Signal.Threshold = 50
Feeding.Threshold.Value=150
Feeding.Interval.Minimum=50
Tasting.Threshold.Interval=c(10,50)
Use.Adaptive.Threshold=FALSE
Adaptive.Threshold.Minimum=8
Adaptive.Threshold.Window.Minutes=2
Adaptive.Threshold.Selection.Quant=0.9
Feeding.Minevents=5
Tasting.Minevents=2
Samples.Per.Second=5
Chamber.Sets=matrix(1:12,ncol=1,byrow=TRUE)
Chamber.Size=1
PI.Multiplier=0
list(Baseline.Window.Minutes=Baseline.Window.Minutes,Signal.Threshold=Signal.Threshold,Feeding.Threshold.Value=Feeding.Threshold.Value,
Feeding.Interval.Minimum=Feeding.Interval.Minimum,Tasting.Threshold.Interval.Low=Tasting.Threshold.Interval[1],
Tasting.Threshold.Interval.High=Tasting.Threshold.Interval[2],
Use.Adaptive.Threshold=Use.Adaptive.Threshold,Adaptive.Threshold.Minimum=Adaptive.Threshold.Minimum,
Adaptive.Threshold.Window.Minutes=Adaptive.Threshold.Window.Minutes,Adaptive.Threshold.Selection.Quant=Adaptive.Threshold.Selection.Quant,
Feeding.Minevents=Feeding.Minevents,Tasting.Minevents=Tasting.Minevents,Samples.Per.Second=Samples.Per.Second,Chamber.Size=Chamber.Size,
Chamber.Sets=Chamber.Sets,PI.Multiplier=PI.Multiplier)
}
ParametersClass.TwoWell=function(){
Baseline.Window.Minutes=3
Signal.Threshold = 50
Feeding.Threshold.Value=150
Feeding.Interval.Minimum=50
Tasting.Threshold.Interval=c(10,50)
Use.Adaptive.Threshold=FALSE
Adaptive.Threshold.Minimum=8
Adaptive.Threshold.Window.Minutes=2
Adaptive.Threshold.Selection.Quant=0.9
Feeding.Minevents=5
Tasting.Minevents=2
Samples.Per.Second=5
Chamber.Sets=matrix(1:12,ncol=2,byrow=TRUE)
Chamber.Size=2
PI.Multiplier=1
list(Baseline.Window.Minutes=Baseline.Window.Minutes,Signal.Threshold=Signal.Threshold,Feeding.Threshold.Value=Feeding.Threshold.Value,
Feeding.Interval.Minimum=Feeding.Interval.Minimum,Tasting.Threshold.Interval.Low=Tasting.Threshold.Interval[1],
Tasting.Threshold.Interval.High=Tasting.Threshold.Interval[2],
Use.Adaptive.Threshold=Use.Adaptive.Threshold,Adaptive.Threshold.Minimum=Adaptive.Threshold.Minimum,
Adaptive.Threshold.Window.Minutes=Adaptive.Threshold.Window.Minutes,Adaptive.Threshold.Selection.Quant=Adaptive.Threshold.Selection.Quant,
Feeding.Minevents=Feeding.Minevents,Tasting.Minevents=Tasting.Minevents,Samples.Per.Second=Samples.Per.Second,Chamber.Size=Chamber.Size,
Chamber.Sets=Chamber.Sets,PI.Multiplier=PI.Multiplier)
}
## change the initial values using this function
SetParameter<-function(p,Baseline.Window.Minutes=NA,Feeding.Threshold.Value=NA, Feeding.Interval.Minimum=NA, Tasting.Threshold.Interval=NA,Use.Adaptive.Threshold=NA,
Adaptive.Threshold.Minimum=NA, Adaptive.Threshold.Window.Minutes=NA, Adaptive.Threshold.Selection.Quant=NA,Feeding.Minevents=NA,Tasting.Minevents=NA,
Samples.Per.Sec=NA, Chamber.Size=NA, Signal.Threshold=NA, PI.Multiplier=NA){
tmp.O<-options()
options(warn=-1)
## Change only those that are listed
if(!is.na(Baseline.Window.Minutes)) {
p$Baseline.Window.Minutes=Baseline.Window.Minutes
}
if(!is.na(Feeding.Threshold.Value)) {
p$Feeding.Threshold.Value=Feeding.Threshold.Value
}
if(!is.na(Feeding.Interval.Minimum)) {
p$Feeding.Interval.Minimum=Feeding.Interval.Minimum
}
if(!is.na(Tasting.Threshold.Interval)) {
p$Tasting.Threshold.Interval.Low=Tasting.Threshold.Interval[1]
p$Tasting.Threshold.Interval.High=Tasting.Threshold.Interval[2]
}
if(!is.na(Adaptive.Threshold.Minimum)){
p$Adaptive.Threshold.Minimum=Adaptive.Threshold.Minimum
}
if(!is.na(Adaptive.Threshold.Window.Minutes)){
p$Adaptive.Threshold.Window.Minutes=Adaptive.Threshold.Window.Minutes
}
if(!is.na(Adaptive.Threshold.Selection.Quant)){
p$Adaptive.Threshold.Selection.Quant=Adaptive.Threshold.Selection.Quant
}
if(!is.na(Use.Adaptive.Threshold)){
p$Use.Adaptive.Threshold=Use.Adaptive.Threshold
}
if(!is.na(Feeding.Minevents)){
p$Feeding.Minevents=Feeding.Minevents
}
if(!is.na(Tasting.Minevents)){
p$Tasting.Minevents=Tasting.Minevents
}
if(!is.na(Samples.Per.Sec)){
p$Samples.Per.Second=Samples.Per.Sec
}
if(!is.na(Chamber.Size)){
p$Chamber.Size=Chamber.Size
}
if(!is.na(Signal.Threshold)){
p$Signal.Threshold=Signal.Threshold
}
if(!is.na(PI.Multiplier)){
p$PI.Multiplier=PI.Multiplier
}
options(tmp.O)
p
}
Get.Parameter.Names<-function(parameters){
chambernames<-paste("Ch",1:length(parameters$Chamber.Sets),sep="")
result<-c("BaselineWindowMin","SignalThreshold","FeedingThreshold","FeedingMinimum","TastingLow","TastingHigh",
"UseAdaptiveThresh","AdapThreshMin","AdapThreshWinMin","AdapThreshSelQuant",
"FeedingMinEvents","TastingMinEvents","SamplesSec","ChamberSize",chambernames,"PI.Multiplier")
result
}
## This is used internally to return the group of parameters in vector form.
GetParameterVector<-function(parameters){
unlist(parameters)
}
AreParametersEqual<-function(p1,p2){
result<-TRUE
if(p1$Baseline.Window.Minutes!=p2$Baseline.Window.Minutes) {
result<-FALSE
}
if(p1$Feeding.Threshold.Value!=p2$Feeding.Threshold.Value) {
result<-FALSE
}
if(p1$Feeding.Interval.Minimum!=p2$Feeding.Interval.Minimum) {
result<-FALSE
}
if(p1$Tasting.Threshold.Interval.Low!=p2$Tasting.Threshold.Interval.Low) {
result<-FALSE
}
if(p1$Tasting.Threshold.Interval.High!=p2$Tasting.Threshold.Interval.High) {
result<-FALSE
}
if(p1$Use.Adaptive.Threshold!=p2$Use.Adaptive.Threshold) {
result<-FALSE
}
if(p1$Adaptive.Threshold.Minimum!=p2$Adaptive.Threshold.Minimum){
result<-FALSE
}
if(p1$Adaptive.Threshold.Window.Minutes!=p2$Adaptive.Threshold.Window.Minutes){
result<-FALSE
}
if(p1$Adaptive.Threshold.Selection.Quant!=p2$Adaptive.Threshold.Selection.Quant){
result<-FALSE
}
if(p1$Feeding.Minevents!=p2$Feeding.Minevents){
result<-FALSE
}
if(p1$Tasting.Minevents!=p2$Tasting.Minevents){
result<-FALSE
}
if(p1$Chamber.Size!=p2$Chamber.Size) {
result<-FALSE
}
if(p1$Signal.Threshold!=p2$Signal.Threshold) {
result<-FALSE
}
if(p1$PI.Multiplier!=p2$PI.Multiplier) {
result<-FALSE
}
result
}