-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathNM_SpikeTab.ipf
More file actions
6472 lines (4451 loc) · 166 KB
/
NM_SpikeTab.ipf
File metadata and controls
6472 lines (4451 loc) · 166 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma rtGlobals=3 // Use modern global access method and strict wave access.
#pragma hide = 1
//****************************************************************
//****************************************************************
//
// NeuroMatic: data aquisition, analyses and simulation software that runs with the Igor Pro environment
// Copyright (C) 2024 The Silver Lab, UCL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//
// Contact [email protected]
// www.NeuroMatic.ThinkRandom.com
//
//****************************************************************
//****************************************************************
//
// Spike Analysis
//
// Compute spike rasters, PST histograms, interspike interval histograms, avg rates
//
// Set and Get functions:
//
// NMSpikeSet( [ threshold, xbgn, xend, review, rasterSelect ] )
// NMConfigVarSet( "Spike", varName, value )
// NMConfigStrSet( "Spike", strVarName, strValue )
// NMSpikeVarGet( varName )
// NMSpikeStrGet( strVarName )
//
// Useful functions:
//
// NMSpikeRasterComputeAll( [ chanSelectList, waveSelectList, displayMode, delay, plot, table, history ] )
// NMSpikeRasterCompute( [ chanNum, waveNum, threshold, xbgn, xend, xRaster, yRaster, displayMode, delay ] )
// NMSpikeRasterPlot( [ folder, xRasterList, yRasterList, xbgn, xend, history ] )
// NMSpikeTable( [ subfolder, history ] )
// NMSpikePSTH( [ folder, xRasterList, yRasterList, xbgn, xend, binSize, yUnits, noGraph, history ] )
// NMSpikePSTHJoint( [ folder, xRasterList, yRasterList, xbgn, xend, binSize, yUnits, noGraph, history ] )
// NMSpikeISIH( [ folder, xRasterList, xbgn, xend, minInterval, maxInterval, binSize, yUnits, noGraph, history ] )
// NMSpikeISIHJoint( [ folder, xRasterList, xbgn, xend, minInterval, maxInterval, binSize, yUnits, noGraph, history ] )
// NMSpikeRate( [ folder, xRasterList, yRasterList, xbgn, xend, noGraph, history ] )
// NMSpikesToWaves( [ folder, xRaster, yRaster, xwinBefore, xwinAfter, stopAtNextSpike, chanNum, wavePrefix, history ] )
//
//****************************************************************
//****************************************************************
//
// Default Values
//
//****************************************************************
//****************************************************************
//****************************************************************
Static Constant Threshold = 10 // arbitrary units
Static Constant UseSubfolders = 1 // ( 0 ) no ( 1 ) yes
Static Constant OverwriteMode = 1 // ( 0 ) no ( 1 ) yes
Static Constant AutoSpike = 1 // ( 0 ) no ( 1 ) yes, auto spike detection after wave change
Static Constant AutoRaster = 1 // create raster plot after executing All Waves ( 0 ) no ( 1 ) yes
Static Constant AutoTable = 0 // create raster table after executing All Waves ( 0 ) no ( 1 ) yes
Static Constant ReviewAlert1 = 1 // ( 0 ) no ( 1 ) yes
Static Constant ReviewAlert2 = 1 // ( 0 ) no ( 1 ) yes
Static Constant PositiveSpikes = 1 // ( 0 ) negative ( 1 ) positive spike deflections
Static Constant RasterNaNs = 1 // ( 0 ) no NaNs ( 1 ) use NaNs
Static Constant DisplaySpikesLimit = 2000 // limit for display spikes (displaying 1000s of spikes can be slow)
Static StrConstant WaveNamingFormat = "prefix" // "prefix" or "suffix"
//****************************************************************
//****************************************************************
//****************************************************************
Static StrConstant SELECTED = "_selected_"
StrConstant NMSpikeDF = "root:Packages:NeuroMatic:Spike:"
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMTabPrefix_Spike()
return "SP_"
End // NMTabPrefix_Spike
//****************************************************************
//****************************************************************
//****************************************************************
Function SpikeTab( enable )
Variable enable // ( 0 ) disable ( 1 ) enable tab
if ( enable )
CheckNMPackage( "Spike", 1 ) // declare globals if necessary
CheckNMSpikeThresh()
CheckNMSpikeWindows()
NMSpikeMake( 0 ) // make controls if necessary
NMSpikeUpdate()
NMChannelGraphDisable( channel = -2, all = 0 )
endif
NMSpikeDisplay( -1, enable )
if ( enable )
NMSpikeAuto()
endif
End // SpikeTab
//****************************************************************
//****************************************************************
//****************************************************************
Function SpikeTabKill( what )
String what
strswitch( what )
case "waves":
return 0
case "folder":
if ( DataFolderExists( NMSpikeDF ) )
KillDataFolder $NMSpikeDF
if ( DataFolderExists( NMSpikeDF ) )
return -1
else
return 0
endif
endif
endswitch
return -1
End // SpikeTabKill
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeCheck()
if ( !DataFolderExists( NMSpikeDF ) )
return NM2Error( 30, "SpikeDF", NMSpikeDF )
endif
CheckNMwave( NMSpikeDF + "SP_SpikeX", 0, NaN ) // waves for display graphs
CheckNMwave( NMSpikeDF + "SP_SpikeY", 0, NaN )
return 0
End // NMSpikeCheck
//****************************************************************
//****************************************************************
//****************************************************************
Static Function zCheck_NMSpikeVar( varName )
String varName
return CheckNMvar( NMSpikeDF+varName, NMSpikeVarGet( varName ) )
End // zCheck_NMSpikeVar
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeConfigs()
NMConfigVar( "Spike", "UseSubfolders", UseSubfolders, "use subfolders when creating Spike waves ( uncheck for previous NM formatting )", "boolean" )
NMConfigVar( "Spike", "OverwriteMode", OverwriteMode, "overwrite existing waves, tables and graphs if their is a name conflict", "boolean" )
NMConfigVar( "Spike", "AutoSpike", AutoSpike, "auto spike detection after wave change", "boolean" )
NMConfigVar( "Spike", "AutoRaster", AutoRaster, "create raster plot after executing All Waves", "boolean" )
NMConfigVar( "Spike", "AutoTable", AutoTable, "create raster table after executing All Waves", "boolean" )
NMConfigVar( "Spike", "ReviewAlert1", ReviewAlert1, "alert user once about Review checkbox when selecting All Waves", "boolean" )
NMConfigVar( "Spike", "ReviewAlert2", ReviewAlert2, "alert user once how to use Review square marquee", "boolean" )
NMConfigVar( "Spike", "PositiveSpikes", PositiveSpikes, "detect spikes on positive deflections (uncheck for negative deflections)", "boolean" )
NMConfigVar( "Spike", "RasterNaNs", RasterNaNs, "use NaNs to seperate wave # results in raster waves", "boolean" )
NMConfigVar( "Spike", "DisplaySpikesLimit", DisplaySpikesLimit, "upper limit for display spike times on channel graphs", "" )
NMConfigStr( "Spike", "WaveNamingFormat", WaveNamingFormat, "attach new wave identifier as \"prefix\" or \"suffix\" ( use \"suffix\" for previous NM formatting )", "prefix;suffix;" )
End // NMSpikeConfigs
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeVarGet( varName )
String varName
Variable defaultVal = NaN
strswitch( varName )
case "UseSubfolders":
defaultVal = UseSubfolders
break
case "OverwriteMode":
defaultVal = OverwriteMode
break
case "AutoSpike":
defaultVal = AutoSpike
break
case "AutoRaster":
defaultVal = AutoRaster
break
case "AutoTable":
defaultVal = AutoTable
break
case "Thresh":
defaultVal = Threshold
break
case "Xbgn":
defaultVal = -inf
break
case "Xend":
defaultVal = inf
break
case "PositiveSpikes":
defaultVal = PositiveSpikes
break
case "RasterNaNs":
defaultVal = RasterNaNs
break
case "DisplaySpikesLimit":
defaultVal = 2000
break
case "ChanSelect":
defaultVal = 0
break
case "Spikes":
defaultVal = 0
break
case "Rate":
defaultVal = 0
break
case "NumSpikes":
defaultVal = 0
break
case "Review":
return NMSpikeReviewGet()
case "ReviewAlert1":
defaultVal = ReviewAlert1
break
case "ReviewAlert2":
defaultVal = ReviewAlert2
break
case "ComputeAllDisplay":
defaultVal = 1
break
case "ComputeAllDelay":
defaultVal = 0
break
case "ComputeAllFormat":
defaultVal = 0
break
case "ComputeAllPlot":
defaultVal = 1
break
case "ComputeAllTable":
defaultVal = 0
break
case "PSTHdelta":
defaultVal = 1
break
case "ISIHdelta":
defaultVal = 1
break
case "S2W_XwinBefore":
defaultVal = 2
break
case "S2W_XwinAfter":
defaultVal = 5
break
case "S2W_StopAtNextSpike":
defaultVal = 0
break
case "S2W_chan":
defaultVal = CurrentNMChannel()
break
case "S2W_SelectAsCurrent":
defaultVal = 1
break
case "S2W_SetGroups":
defaultVal = 0
break
default:
NMDoAlert ( "NMSpikeVar Error: no variable called " + NMQuotes( varName ) )
return NaN
endswitch
return NumVarOrDefault( NMSpikeDF+varName, defaultVal )
End // NMSpikeVarGet
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMSpikeStrGet( strVarName )
String strVarName
String defaultStr = ""
strswitch( strVarName )
case "WaveNamingFormat":
defaultStr = WaveNamingFormat
break
case "PSTHyaxis":
defaultStr = "Spikes/bin"
break
case "ISIHyaxis":
defaultStr = "Intervals/bin"
break
case "S2W_WavePrefix":
//defaultStr = "SP_Rstr"
defaultStr = "Spike"
break
default:
NMDoAlert( "NMSpikeStr Error: no variable called " + NMQuotes( strVarName ) )
return ""
endswitch
return StrVarOrDefault( NMSpikeDF + strVarName, defaultStr )
End // NMSpikeStrGet
//****************************************************************
//****************************************************************
//****************************************************************
Function CheckNMSpikeThresh()
Variable minThresh = 5
String wname = ChanDisplayWave( -1 )
Variable thresh = NMSpikeVarGet( "Thresh" )
if ( ( numtype( thresh ) == 0 ) || !WaveExists( $wname ) )
return 0
endif
WaveStats /Q/Z $wname
thresh = ( V_max - 0.2*abs( V_max - V_avg ) )
thresh = ceil( 10 * thresh ) / 10
if ( V_avg < minThresh )
thresh = max( thresh, minThresh )
endif
SetNMvar( NMSpikeDF + "Thresh", thresh )
return 0
End // CheckNMSpikeThresh
//****************************************************************
//****************************************************************
//****************************************************************
Function CheckNMSpikeWindows()
if ( numtype( NMSpikeVarGet( "Xbgn" ) ) > 0 )
SetNMvar( NMSpikeDF + "Xbgn", -inf )
endif
if ( numtype( NMSpikeVarGet( "Xend" ) ) > 0 )
SetNMvar( NMSpikeDF + "Xend", inf )
endif
End // CheckNMSpikeWindows
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeReviewGet()
String xWaveOrFolder
Variable review = NumVarOrDefault( NMSpikeDF + "Review", 0 )
if ( review )
xWaveOrFolder = CurrentNMSpikeRasterXSelect()
if ( strlen( xWaveOrFolder ) > 0 )
return 1
endif
endif
return 0
End // NMSpikeReviewGet
//****************************************************************
//****************************************************************
//****************************************************************
//
// Channel Graph Functions
//
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeDisplay( chanNum, appnd ) // append/remove spike wave from channel graph
Variable chanNum // channel number ( -1 ) for current channel
Variable appnd // ( 0 ) remove wave ( 1 ) append wave
Variable ccnt, drag = appnd
String gName
if ( !DataFolderExists( NMSpikeDF ) )
return 0 // spike has not been initialized yet
endif
if ( !NMVarGet( "DragOn" ) || !StringMatch( CurrentNMTabName(), "Spike" ) )
drag = 0
endif
if ( !appnd )
SetNMwave( NMSpikeDF+"SP_SpikeX", -1, NaN )
SetNMwave( NMSpikeDF+"SP_SpikeY", -1, NaN )
endif
chanNum = ChanNumCheck( chanNum )
for ( ccnt = 0 ; ccnt < NMNumChannels() ; ccnt += 1 )
gName = ChanGraphName( ccnt )
if ( Wintype( gName ) == 0 )
continue // window does not exist
endif
RemoveFromGraph /Z/W=$gName SP_SpikeY
RemoveFromGraph /Z/W=$gName DragBgnY, DragEndY
endfor
gName = ChanGraphName( chanNum )
if ( appnd && ( WinType( gName ) == 1 ) )
AppendToGraph /W=$gName $NMSpikeDF+"SP_SpikeY" vs $NMSpikeDF+ "SP_SpikeX"
ModifyGraph /W=$gName mode( SP_SpikeY )=3, marker( SP_SpikeY )=9
ModifyGraph /W=$gName mrkThick( SP_SpikeY )=2, rgb( SP_SpikeY )=( 65535,0,0 )
endif
NMSpikeDisplayUpdate()
NMDragEnable( drag, "DragBgn", "", NMSpikeDF+"Xbgn", "", gName, "bottom", "min", 65535, 0, 0 )
NMDragEnable( drag, "DragEnd", "", NMSpikeDF+"Xend", "", gName, "bottom", "max", 65535, 0, 0 )
KillWaves /Z $NMDF + "DragTbgnX" // old waves
KillWaves /Z $NMDF + "DragTbgnY"
End // NMSpikeDisplay
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeDisplayUpdate()
Variable review = NMSpikeReviewGet()
String gName = ChanGraphName( -1 )
String wList
if ( WinType( gName ) == 0 )
return 0
endif
wList = TraceNameList( gName, ";", 1 )
if ( WhichListItem( "SP_SpikeY", wList ) < 0 )
return 0
endif
if ( review )
ModifyGraph /W=$gName rgb(SP_SpikeY)=(0,0,65280)
else
ModifyGraph /W=$gName rgb(SP_SpikeY)=(65280,0,0)
endif
End // NMSpikeDisplayUpdate
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeDisplayClear()
SetNMwave( NMSpikeDF+"SP_SpikeX", -1, NaN )
SetNMwave( NMSpikeDF+"SP_SpikeY", -1, NaN )
NMDragClear( "DragBgn" )
NMDragClear( "DragEnd" )
End // NMSpikeDisplayClear
//****************************************************************
//****************************************************************
//****************************************************************
//
// Tab Controls Functions
//
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeMake( force ) // create Spike tab controls
Variable force
Variable x0 = 40, y0 = 195, xinc = 120, yinc = 35, fs = NMPanelFsize
y0 = NMPanelTabY + 40
ControlInfo /W=$NMPanelName SP_Thresh
if ( ( V_Flag != 0 ) && !force )
return 0 // Spike tab has already been created, return here
endif
if ( !DataFolderExists( NMSpikeDF ) )
return 0 // spike has not been initialized yet
endif
zCheck_NMSpikeVar( "Thresh" )
zCheck_NMSpikeVar( "Xbgn" )
zCheck_NMSpikeVar( "Xend" )
zCheck_NMSpikeVar( "Spikes" )
zCheck_NMSpikeVar( "Rate" )
zCheck_NMSpikeVar( "NumSpikes" )
DoWindow /F $NMPanelName
GroupBox SP_Grp1, title = "Spike Detection", pos={20,y0}, size={260,150}, fsize=fs, win=$NMPanelName
xinc = 145
yinc = 26
SetVariable SP_Thresh, title="threshold", pos={x0,y0+1*yinc}, limits={-inf,inf,0}, size={130,20}, frame=1, value=$( NMSpikeDF+"Thresh" ), proc=NMSpikeSetVariable, fsize=fs, win=$NMPanelName
SetVariable SP_Xbgn, title="xbgn", pos={x0,y0+2*yinc}, limits={-inf,inf,0}, size={130,20}, frame=1, value=$( NMSpikeDF+"Xbgn" ), proc=NMSpikeSetVariable, fsize=fs, win=$NMPanelName
SetVariable SP_Xend, title="xend", pos={x0,y0+3*yinc}, limits={-inf,inf,0}, size={130,20}, frame=1, value=$( NMSpikeDF+"Xend" ), proc=NMSpikeSetVariable, fsize=fs, win=$NMPanelName
Checkbox SP_Auto, title="auto", pos={x0+xinc,y0+1*yinc+1}, size={16,18}, value=NumVarOrDefault( NMSpikeDF+"AutoSpike", 0 ) , proc = NMSpikeCheckBox, win=$NMPanelName
SetVariable SP_Count, title="spikes : ", pos={x0+xinc,y0+2*yinc}, limits={0,inf,0}, size={90,20}, frame=0, value=$( NMSpikeDF+"Spikes" ), fsize=fs, win=$NMPanelName
SetVariable SP_WRate, title="rate : ", pos={x0+xinc,y0+3*yinc}, limits={0,inf,0}, size={90,20}, frame=0, value=$( NMSpikeDF+"Rate" ), fsize=fs, win=$NMPanelName
yinc = 35
y0 += 10
Button SP_All, title = "All Waves", pos={x0+30,y0+3*yinc}, size={100,20}, proc = NMSpikeButton, fsize=fs, win=$NMPanelName
Checkbox SP_Review, title="review", pos={x0+40+105,y0+3*yinc+3}, size={16,18}, value=0, proc = NMSpikeCheckBox, win=$NMPanelName
y0 = 380
yinc = 30
GroupBox SP_Grp2, title = "Spike Analysis", pos={20,y0}, size={260,215}, fsize=fs, win=$NMPanelName
PopupMenu SP_RasterSelect, pos={x0+120,y0+1*yinc}, bodywidth=170, fsize=fs, win=$NMPanelName
PopupMenu SP_RasterSelect, value="Spike Raster Select", proc=NMSpikePopup
SetVariable SP_NumSpikes, title=":", pos={x0+180,y0+1*yinc+2}, limits={0,inf,0}, size={55,20}
SetVariable SP_NumSpikes, value=$( NMSpikeDF+"NumSpikes" ), frame=0, fsize=fs, noedit=0
xinc = 120
yinc = 35
Button SP_Raster, title="Raster Plot", pos={x0,y0+2*yinc}, size={100,20}, proc=NMSpikeAnalysisButton, fsize=fs, win=$NMPanelName
Button SP_Table, title = "Table", pos={x0+xinc,y0+2*yinc}, size={100,20}, proc = NMSpikeAnalysisButton, fsize=fs, win=$NMPanelName
Button SP_PSTH, title="PST Histo", pos={x0,y0+3*yinc}, size={100,20}, proc=NMSpikeAnalysisButton, fsize=fs, win=$NMPanelName
Button SP_Rate, title="Count / Rate", pos={x0+xinc,y0+3*yinc}, size={100,20}, proc=NMSpikeAnalysisButton, fsize=fs, win=$NMPanelName
Button SP_ISIH, title="ISI Histo", pos={x0,y0+4*yinc}, size={100,20}, proc=NMSpikeAnalysisButton, fsize=fs, win=$NMPanelName
Button SP_Joint, title="Joint", pos={x0+xinc,y0+4*yinc}, size={100,20}, proc=NMSpikeAnalysisButton, fsize=fs, win=$NMPanelName
Button SP_2Waves, title="Spikes 2 Waves", pos={x0+xinc/2,y0+5*yinc}, size={100,20}, proc=NMSpikeAnalysisButton, fsize=fs, win=$NMPanelName
return 0
End // NMSpikeMake
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeUpdate()
Variable dis
String txt
String spikeMenu = NMSpikeRasterSelectMenu()
String xWaveOrFolder = CurrentNMSpikeRasterOrFolder()
String xRaster = CheckNMSpikeRasterXPath( SELECTED )
Variable spikeCount = SpikeRasterCountSpikes( xRaster )
Variable review = NMSpikeReviewGet()
if ( NMVarGet( "ConfigsDisplay" ) > 0 )
return 0
endif
SetNMvar( NMSpikeDF + "NumSpikes", spikeCount )
Variable md = 1 + WhichListItem( xWaveOrFolder, SpikeMenu, ";", 0, 0 )
if ( review )
txt = "Spike Review"
else
txt = "Spike Detection"
endif
GroupBox SP_Grp1, win=$NMPanelName, title=txt
PopupMenu SP_RasterSelect, win=$NMPanelName, mode=max(md,1), value=NMSpikeRasterSelectMenu()
dis = 2
if ( strlen( xWaveOrFolder ) > 0 )
dis = 0
endif
if ( review )
Checkbox SP_Review, win=$NMPanelName, disable=dis, value=review, fColor=(0,0,65280)
else
Checkbox SP_Review, win=$NMPanelName, disable=dis, value=review, fColor=(0,0,0)
endif
dis = 0
if ( review )
dis = 2
endif
SetVariable SP_Thresh, win=$NMPanelName, disable=dis
//SetVariable SP_Xbgn, win=$NMPanelName, disable=dis
//SetVariable SP_Xend, win=$NMPanelName, disable=dis
Checkbox SP_Auto, win=$NMPanelName, value=NumVarOrDefault( NMSpikeDF+"AutoSpike", 0 ), disable=dis
Button SP_All, win=$NMPanelName, disable=dis
SetNMvar( NMSpikeDF + "ChanSelect", CurrentNMChannel() )
NMSpikeDisplayUpdate()
End // NMSpikeUpdate
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMSpikeRasterSelectMenu()
String menuStr = "Spike Raster Select;"
String folderList = NMSubfolderList2( "", "Spike_", 0, 1 )
String xWaveOrFolder = CurrentNMSpikeRasterOrFolder()
String oldRasterList = SpikeRasterList()
if ( ItemsInList( folderList ) > 0 )
menuStr += "---;" + folderList
endif
if ( ItemsInList( oldRasterList ) > 0 )
menuStr += "---;" + oldRasterList
endif
menuStr += "---;Other...;Clear;"
if ( WhichListItem( xWaveOrFolder, folderList ) >= 0 )
menuStr += "Delete Spike Subfolder;"
endif
return menuStr
End // NMSpikeRasterSelectMenu
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeSetVariable( ctrlName, varNum, varStr, varName ) : SetVariableControl
String ctrlName; Variable varNum; String varStr; String varName
ctrlName = ReplaceString( "SP_", ctrlName, "" )
NMSpikeCall( ctrlName, varStr )
End // NMSpikeSetVariable
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikePopup( ctrlName, popNum, popStr ) : PopupMenuControl
String ctrlName; Variable popNum; String popStr
ctrlName = ReplaceString( "SP_", ctrlName, "" )
String xWaveOrFolder = popStr
strswitch( popStr )
case "---":
break
case "Delete Spike Subfolder":
NMSpikeAnalysisCall( popStr )
break
case "Clear":
NMSpikeRasterClearCall()
return 0
case "Other...":
xWaveOrFolder = zRasterSelectPrompt()
if ( strlen( xWaveOrFolder ) == 0 )
break
endif
default:
if ( strlen( xWaveOrFolder ) > 0 )
NMSpikeSet( raster = xWaveOrFolder, history = 1 )
endif
endswitch
NMSpikeUpdate()
End // NMSpikePopup
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeButton( ctrlName ) : ButtonControl
String ctrlName
ctrlName = ReplaceString( "SP_", ctrlName, "" )
NMSpikeCall( ctrlName, "" )
End // NMSpikeButton
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeAnalysisButton( ctrlName ) : ButtonControl
String ctrlName
ctrlName = ReplaceString( "SP_", ctrlName, "" )
NMSpikeAnalysisCall( ctrlName )
End // NMSpikeAnalysisButton
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeCheckBox(ctrlName, checked) : CheckBoxControl
String ctrlName; Variable checked
ctrlName = ctrlName[ 3, inf ]
NMSpikeCall( ctrlName, num2str( checked ) )
End // NMSpikeCheckBox
//****************************************************************
//****************************************************************
//****************************************************************
Function /S NMSpikeCall( fxn, select )
String fxn, select
Variable snum = str2num( select )
strswitch( fxn )
case "Auto":
NMSpikeSet( auto = snum, history = 1 )
return ""
case "Thresh":
NMSpikeSet( threshold = snum, history = 1 )
return ""
case "Xbgn":
NMSpikeSet( xbgn = snum, history = 1 )
return ""
case "Xend":
NMSpikeSet( xend = snum, history = 1 )
return ""
case "All":
case "All Waves":
return NMSpikeRasterComputeAllCall()
case "Review":
NMSpikeSet( review = snum, history = 1 )
return ""
default:
NMDoAlert( "NMSpikeCall: unrecognized function call: " + fxn )
endswitch
return ""
End // NMSpikeCall
//****************************************************************
//****************************************************************
//****************************************************************
//
// Global Variable Functions
//
//****************************************************************
//****************************************************************
//****************************************************************
Function NMSpikeSet( [ threshold, xbgn, xend, auto, review, raster, update, history ] )
Variable threshold // threshold trigger level
Variable xbgn, xend // x-axis window begin and end, use ( -inf, inf ) for all
Variable auto // auto spike detection afer wave change ( 0 ) off ( 1 ) on
Variable review // spike detection review mode ( 0 ) off ( 1 ) on
String raster // spike raster select
Variable update
Variable history // print function command to history ( 0 ) no ( 1 ) yes
Variable autoSpike, updateTab
String wName, path, subfolder, paramList = ""
if ( ParamIsDefault( update ) )
update = 1
endif
if ( !ParamIsDefault( auto ) )
paramList = NMCmdNumOptional( "auto", auto, paramList )
if ( numtype( auto ) > 0 )
return NM2Error( 10, "auto", num2str( auto ) )
endif
NMConfigVarSet( "Spike", "AutoSpike", auto )
autoSpike = auto
endif
if ( !ParamIsDefault( threshold ) )
paramList = NMCmdNumOptional( "threshold", threshold, paramList )
if ( numtype( threshold ) > 0 )
return NM2Error( 10, "threshold", num2str( threshold ) )
endif
SetNMvar( NMSpikeDF + "Thresh", threshold )
autoSpike = 1
endif
if ( !ParamIsDefault( xbgn ) )
paramList = NMCmdNumOptional( "xbgn", xbgn, paramList )
SetNMvar( NMSpikeDF + "Xbgn", zCheck_Xbgn( xbgn ) )
autoSpike = 1
endif
if ( !ParamIsDefault( xend ) )
paramList = NMCmdNumOptional( "xend", xend, paramList )
SetNMvar( NMSpikeDF + "Xend", zCheck_Xend( xend ) )
autoSpike = 1
endif
if ( !ParamIsDefault( review ) )
paramList = NMCmdNumOptional( "review", review, paramList, integer = 1 )
review = BinaryCheck( review )
SetNMvar( NMSpikeDF + "Review", review )
autoSpike = 1
updateTab = 1
if ( review )
zReviewAlertUser2()
endif
endif
if ( !ParamIsDefault( raster ) && ( strlen( raster ) > 0 ) )
paramList = NMCmdStrOptional( "raster", raster, paramList )
if ( !WaveExists( $raster ) && !DataFolderExists( raster ) )
return NM2Error( 20, "raster", raster )
endif
subfolder = NMParent( raster, noPath = 1 )
if ( ( strlen( subfolder ) > 0 ) && DataFolderExists( subfolder ) )
wName = NMChild( raster )
path = NMParent( raster )
SetNMstr( path + "RasterXSelect", wName )
raster = subfolder
endif
SetNMstr( CurrentNMPrefixFolder() + "SpikeRasterXSelect", raster )
autoSpike = 1
updateTab = 1
endif
if ( history )
NMCommandHistory( paramList )
endif