#pragma rtGlobals=1 // Use modern global access method. #include Menu "Macros" "PAT" End //Please see accompaning manual for operation and caveats //Copyright (C) 2002-5 Jeremy Bergsman //jeremy@bergsman.org // //These programs are free software; you can redistribute them and/or modify //them under the terms of the GNU General Public License as published by //the Free Software Foundation; either version 2 of the License, or any later version. // //These programs are distributed in the hope that they 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: //http://www.gnu.org/licenses/gpl.html //or write to the Free Software Foundation, Inc. //59 Temple Place, Suite 330 //Boston, MA 02111-1307 //USA //Revision history: //2.9 4/20/05 Changed baselinestart and end names so as not to conflict with Batch Image Processing routines. //2.8 1/12/05 Changed settings wave folder to special packages directory //2.73 1/18/04 Fixed bug in setting data units in result waves //2.72 10/10/03 Added PULSE compatibility to wave browser and made PAT default to mode 2 in PULSE settings //2.71 10/1/03 Fixed bug in toggle channel in wave browser //2.7 2/24/03 Fixed harmless bugs which caused error messages if you 1) used average by train or sweep (Peak measures were // divided by PeakN even though it didn't exist) or 2) used incremental mode, due to failure to initialize variable tempstr. Also added // Record Wave Name action. Numerous small changes of $XWaveName to XWave variety. Other minor cosmetic code changes. //2.62 2/19/03 Fixed wavebrowser for HEKA waves, added feature to retain cursors //2.61 10/30/02 Fixed bug that affected some new things as well as Average Waves where if an Anal # was reused the old result was incorporated into the new one //2.6 10/1-7/02 Tabs on panel, Huge expansion of wave ranging, Generalized trains to any numerical analysis type (including rewriting PPR and art stripper and just about everything else!) //2.51 Continuing Bugs, Artifact stripper, Train wave X units, PPR //2.5 8/20/02 Easier installation/updating with version checking //2.4 8/13/02 Constants for action #s, better saving of settings //2.3 6/27/02 Train analysis, curve fitting //2.2 6/17/02 Average waves, constant for # of actions, contend with missing settings waves, minor bugs, recover raw HEKA wave //2.1 6/4/02 Rudimentary HEKA support added, ability to save settings added, numerous tweaks including making it easy to reorg panel with PanelPos //Version 2.0 started 5/14/02 convert old Macro-based style (1.X) to Panel, many, many changes and additions, mainly to make it easy to add new actions //Still need to/could implement: //Suppress graphing? //Plot against extracted wave note //Choose graph style //Display results on analyzed waves? //settings waves in their own path //Mode where anal # isn't used, nothing is written to history Static Strconstant sDataSource="AXON"// Choose AXON, HEKA, or PULSE as appropriate (case sensitive) Static Constant kThisVersion=2.9 //Only 0.1 accuracy. Smaller version increments don't demand updates. Static Constant kNumActions=19 //Must set to number of actions Static Constant kMin=0 //Order in which to display actions Static Constant kMax=1 Static Constant kBig=2 Static Constant kAvg=3 Static Constant kNum=4 Static Constant kPPR=5 Static Constant kArtX=6 Static Constant kPeak=7 Static Constant kFit=8 Static Constant kDup=9 Static Constant kBLSub=10 Static Constant kSmooth=11 Static Constant kConcat=12 Static Constant kAvgWave=13 Static Constant kRawHEKA=14 Static Constant kExtWN=15 Static Constant kUserFunc=16 Static Constant kWaveName=17 Static Constant kBlank=18 //Storage for unused ones, set to 32 Static Constant kMinVsFit=32 Function PAT() //Version check: if (wintype("AnalPanel")==7) //If window already exists (7=it's a panel) if (exists("AnalVersion")!=2) //Is it a variable? VARIABLE/G AnalVersion=kThisVersion //If not make it and redo the panel DoWindow/K AnalPanel else //If the variable exists if (AnalVersion==kThisVersion) //and it's set to this version # Dowindow/F AnalPanel //Bring to front and quit return 0 else NVAR AnalVersion AnalVersion=kThisVersion //Update value and panel DoWindow/K AnalPanel endif endif else VARIABLE/G AnalVersion=kThisVersion endif VARIABLE/G StartTime=-1, EndTime=-1, UseBL=0, GraphBL=0, PATBaseLineStart=-1, PATBaseLineEnd=-1, TrialIncrement=1, SweepIncrement=1, TopWindow=0 VARIABLE/G SaveCS, SaveCE, SaveFS, SaveFE, SetFitZero=0, ExtrapolateFit=0, PeakThreshold, PeakLength, MVFFitNum=1, WhichTab=0, RangeType=1 VARIABLE/G SaveTS=0, SaveTE=10, SaveSS=0, SaveSE=1, SaveAN=1, NewGuess=0, DupTweenCursors=0, SmoothNumber=0, GraphAnalyzedWaves=0, GetCursorsLater=0, TrainNum=1, TrainFreq=100 STRING/G DupLetter="D", ExWaveNote="", AnalSettings, FitFlags="/H=\"000\"", PatternToMatch="", IncrementString="" VARIABLE Temp1, Temp2, PanelPos, Top, Right STRING TempStr if (waveexists(OverWriteProtect)==0) Make /B/U/N=500 OverWriteProtect //keep track of completed anal #'s so you don't overwrite by accident NewPath /O/Q/C SettingsPath SpecialDirPath("Packages", 0, 0, 0)+"PAT:" //C:\Documents and Settings\Jeremy\Application Data\WaveMetrics\Igor Pro 5\Packages\PAT endif //Load settings waves or create them //.ibw needs to be changed to .bwav for macintosh Temp1=OpenOrMake("SetPTSetting.ibw",0,0) OpenOrMake("SetAREnd.ibw",0,Temp1) OpenOrMake("SetARStart.ibw",0,Temp1) OpenOrMake("SetBLEnd.ibw",0,Temp1) OpenOrMake("SetBLStart.ibw",0,Temp1) OpenOrMake("SetDupAR.ibw",0,Temp1) OpenOrMake("SetDupLetter.ibw",1,Temp1) OpenOrMake("SetEWN.ibw",1,Temp1) OpenOrMake("SetGetCurLater.ibw",0,Temp1) OpenOrMake("SetGraphAW.ibw",0,Temp1) OpenOrMake("SetPlotStyle.ibw",0,Temp1) OpenOrMake("SetSmoothing.ibw",0,Temp1) OpenOrMake("SetUseBL.ibw",0,Temp1) OpenOrMake("SetGraphBL.ibw",0,Temp1) OpenOrMake("SetSStart.ibw",0,Temp1) OpenOrMake("SetSEnd.ibw",0,Temp1) OpenOrMake("SetSInc.ibw",0,Temp1) OpenOrMake("SetFitType.ibw",0,Temp1) OpenOrMake("SetFitFlags.ibw",1,Temp1) OpenOrMake("SetSetFitZero.ibw",0,Temp1) OpenOrMake("SetExtFit.ibw",0,Temp1) OpenOrMake("SetFStart.ibw",0,Temp1) OpenOrMake("SetFEnd.ibw",0,Temp1) OpenOrMake("SetTrNum.ibw",0,Temp1) OpenOrMake("SetTrFreq.ibw",0,Temp1) OpenOrMake("SetPeakTh.ibw",0,Temp1) OpenOrMake("SetPeakL.ibw",0,Temp1) OpenOrMake("SettingName.ibw",1,Temp1) OpenOrMake("SetMVF.ibw",0,Temp1) OpenOrMake("SetTopWindow.ibw",0,Temp1) OpenOrMake("SetRangeType.ibw",0,Temp1) OpenOrMake("SetPatternToMatch.ibw",1,Temp1) OpenOrMake("SetIncrementString.ibw",1,Temp1) OpenOrMake("SetWCF.ibw",1,Temp1) WAVE/T SettingName AnalSettings="" //Used only for popup for (Temp1=1;Temp1<=numpnts(SettingName);Temp1+=1) AnalSettings+=num2str(Temp1)+" "+SettingName[Temp1-1]+";" endfor //Call SaveAP to load default settings? //Actions: May have up to 32, if you update lines below and kNumActions and appropriate location constant at the top. Obviously you must implement any new features. //Names of actions: Make /O/N=(kNumActions)/T PlotType PlotType[kMax]="Maximum (Absolute)" PlotType[kMin]="Minimum (Absolute)" PlotType[kBig]="Bigger (Absolute)" PlotType[kAvg]="Average (Absolute)" PlotType[kDup]="Duplicate" PlotType[kBLSub]="Baseline Subtract Duplicate" PlotType[kSmooth]="Smooth Duplicate" PlotType[kConcat]="Concatenate" PlotType[kUserFunc]="Call UserFunc1" PlotType[kNum]="Number in Averages" PlotType[kExtWN]="Extract Wave Note" PlotType[kAvgWave]="Average Waves" PlotType[kRawHEKA]="Recover Raw HEKA Wave" PlotType[kFit]="Fit" PlotType[kArtX]="Artifact Stripper" PlotType[kPPR]="PPR" PlotType[kPeak]="Peak Discriminator" PlotType[kMinVsFit]="Minimum Vs. Fit" PlotType[kWaveName]="Record Wave Names" PlotType[kBlank]="Blank (Original Data!!!!)" //Checkbox value of actions: Make /O/N=(kNumActions) PTSelection PTSelection=32 //checkbox (48 (32+16)) for checked checkbox TempStr=StringByKey("SCREEN1", IgorInfo(0)) Temp1=StrSearch(TempStr,"RECT",0) Temp1=StrSearch(TempStr,",",Temp1) Temp2=StrSearch(TempStr,",",Temp1+1) Top=Str2Num(TempStr[Temp1+1,Temp2-1]) Temp1=StrSearch(TempStr,",",Temp2+1) Right=Str2Num(TempStr[Temp2+1,Temp1-1]) NewPanel /W=(Right-340,Top+20,Right-20,Top+385) as "PAT" Dowindow/C AnalPanel SetVariable SAN size={95,20}, pos={5,7}, disable=0, noproc, value=SaveAN, title="Analysis #", win=AnalPanel PopupMenu SAP size={135,20}, pos={110,5}, disable=0, proc=SaveAP, value=#"\"Save Settings;Delete Settings;\"+AnalSettings", mode=1, title="Settings", win=AnalPanel Button DoIt size={42,20}, pos={10,340}, disable=0, proc=DoAnal, title="Do It!", win=AnalPanel TabControl AnalTab size={300, 300}, pos={10, 35}, disable=0, fsize=9, proc=TabHandler, tabLabel(0)="Wave Range", tabLabel(1)="Anal Ranges", tabLabel(2)="Actions", tabLabel(3)="Options", value=0, win=AnalPanel //Tab 0=Wave Range PanelPos=65 //Keeps track of Y position to add next control. To shuffle controls just move the whole paragraph to where you want it. PopupMenu RT size={220,20}, pos={20,PanelPos}, disable=0, proc=RTHandler, value="Hierarchical;Pattern Matching;Incremental;User Func", mode=1, title="Mode", win=AnalPanel If (cmpstr(sDataSource,"PULSE")==0)//for pulse PopupMenu RT mode=3//for pulse RangeType=3//for pulse endif CheckBox TOP size={100,20}, pos={190,PanelPos}, disable=0, noproc, variable=TopWindow, title="Only From Target", win=AnalPanel PanelPos+=30 //Range Type 2--Pattern SetVariable PTM size={280,20}, pos={20,PanelPos}, disable=1, noproc, value=PatternToMatch, title="Pattern to Match", win=AnalPanel //Range Type 3--Increment SetVariable INC size={280,20}, pos={20,PanelPos}, disable=1, noproc, value=IncrementString, title="Generic Wave", win=AnalPanel TitleBox ITB size={60,100}, pos={15,PanelPos+20}, disable=1, frame=0, title="Use the % character where you want the number substituted", win=AnalPanel SetVariable ISS size={90,20}, pos={20,PanelPos+50}, disable=1, noproc, value=SaveSS, title="Start", win=AnalPanel SetVariable ISE size={80,20}, pos={120,PanelPos+50}, disable=1, noproc, value=SaveSE, title="End", win=AnalPanel SetVariable ISI size={60,20}, pos={240,PanelPos+50}, disable=1, noproc, value=SweepIncrement, title="By", win=AnalPanel //Range Type 4--Function PopupMenu WCF size={220,20}, pos={20,PanelPos}, disable=1, noproc, value=("Choose your function;"+FunctionList("*",";","KIND:2,NPARAMS:0,VALTYPE:4")), mode=1, title="Wave Choosing Function", win=AnalPanel //Range Type 1--Hierarchical PopupMenu PS size={220,20}, pos={20,PanelPos}, disable=0, noproc, value="All in Order; Average by Trial; Average by Sweep; Group Trial+Sweep; vs. Time", mode=1, title="Hierarchical Mode", win=AnalPanel PanelPos+=30 PopupMenu WavePrototype size={120,20}, pos={20,PanelPos}, disable=0, noproc, value=(WAVEList ("*_*",";", "DIMS:1")+" "), mode=1, title="Wave Prototype", win=AnalPanel PanelPos+=30 if (cmpstr(sDataSource,"AXON")==0) SetVariable STS size={110,20}, pos={30,PanelPos}, disable=0, noproc, value=SaveTS, title="Trial: Start ", win=AnalPanel SetVariable STE size={80,20}, pos={150,PanelPos}, disable=0, noproc, value=SaveTE, title="End", win=AnalPanel SetVariable STI size={50,20}, pos={240,PanelPos}, disable=0, noproc, value=TrialIncrement, title="By", win=AnalPanel PanelPos+=30 SetVariable SSS size={110,20}, pos={30,PanelPos}, disable=0, noproc, value=SaveSS, title="Sweep: St", win=AnalPanel SetVariable SSE size={80,20}, pos={150,PanelPos}, disable=0, noproc, value=SaveSE, title="End", win=AnalPanel SetVariable SSI size={50,20}, pos={240,PanelPos}, disable=0, noproc, value=SweepIncrement, title="By", win=AnalPanel PanelPos+=30 PopupMenu SCS size={120,20}, pos={20,PanelPos}, disable=0, noproc, value="Channel 0; Channel 1; Both Channels", mode=1, title="Channels", win=AnalPanel CheckBox GUE size={100,20}, pos={223,PanelPos}, disable=0, noproc, variable=NewGuess, title="Guess next", win=AnalPanel PanelPos+=30 else SetVariable SCS size={110,20}, pos={30,PanelPos}, disable=0, noproc, value=SaveCS, title="Recording: St", win=AnalPanel SetVariable SCE size={65,20}, pos={150,PanelPos}, disable=0, noproc, value=SaveCE, title="End", win=AnalPanel CheckBox GUE size={100,20}, pos={223,PanelPos}, disable=0, noproc, variable=NewGuess, title="Guess next", win=AnalPanel PanelPos+=30 SetVariable STS size={110,20}, pos={30,PanelPos}, disable=0, noproc, value=SaveTS, title="Trial: Start ", win=AnalPanel SetVariable STE size={80,20}, pos={150,PanelPos}, disable=0, noproc, value=SaveTE, title="End", win=AnalPanel SetVariable STI size={50,20}, pos={240,PanelPos}, disable=0, noproc, value=TrialIncrement, title="By", win=AnalPanel PanelPos+=30 SetVariable SSS size={110,20}, pos={30,PanelPos}, disable=0, noproc, value=SaveSS, title="Sweep: St", win=AnalPanel SetVariable SSE size={80,20}, pos={150,PanelPos}, disable=0, noproc, value=SaveSE, title="End", win=AnalPanel SetVariable SSI size={50,20}, pos={240,PanelPos}, disable=0, noproc, value=SweepIncrement, title="By", win=AnalPanel PanelPos+=30 endif //End of Tab 0 //Tab 1=Analysis Ranges PanelPos=65 GroupBox AR size={280, 95}, pos={20,PanelPos+5}, disable=1, title="Action Range", win=AnalPanel Button GetAR size={100,20}, pos={30,PanelPos+25}, disable=1, proc=GetCursorsHandler, title="Get Cursor Values", win=AnalPanel Button FixAR size={100,20}, pos={190,PanelPos+25}, disable=1, proc=FixTimeHandler, title="Time-->Points", win=AnalPanel SetVariable ST size={110,20}, pos={30,PanelPos+55}, disable=1, noproc, value=StartTime, title="Start", win=AnalPanel SetVariable ET size={100,20}, pos={190,PanelPos+55}, disable=1, noproc, value=EndTime, title="End", win=AnalPanel CheckBox GCL size={100,20}, pos={30,PanelPos+80}, disable=1, noproc, variable=GetCursorsLater, title="Get Cursors at Run Time", win=AnalPanel //****************************should add anal by experiment's epochs PanelPos+=105 GroupBox BL size={280, 95}, pos={20,PanelPos+5}, disable=1, title="Baseline Range", win=AnalPanel CheckBox UBL size={100,20}, pos={30,PanelPos+25}, disable=1, proc=UBLHandler, variable=UseBL, title="Use Baseline", win=AnalPanel CheckBox GBL size={100,20}, pos={130,PanelPos+25}, disable=1, noproc, variable=GraphBL, title="Graph Baseline", win=AnalPanel Button GetBR size={100,20}, pos={30,PanelPos+48}, disable=1, proc=GetCursorsHandler, title="Get Cursor Values", win=AnalPanel Button FixBR size={100,20}, pos={190,PanelPos+48}, disable=1, proc=FixTimeHandler, title="Time-->Points", win=AnalPanel SetVariable BLS size={110,20}, pos={30,PanelPos+78}, disable=1, noproc, value=PATBaseLineStart, title="Start", win=AnalPanel SetVariable BLE size={100,20}, pos={190,PanelPos+78}, disable=1, noproc, value=PATBaseLineEnd, title="End", win=AnalPanel PanelPos+=105 SetVariable TRN size={90,20}, pos={20,PanelPos}, disable=1, noproc, value=TrainNum, title="Train: #", win=AnalPanel SetVariable TRF size={110,20}, pos={120,PanelPos}, disable=1, noproc, value=TrainFreq, title="Frequency", win=AnalPanel PanelPos+=25 PopupMenu TRW size={50,20}, pos={15,PanelPos}, disable=1, noproc, value=("Choose Delay Wave;"+WAVEList ("Delay*",";", "DIMS:1")+WAVEList ("!Delay*",";", "DIMS:1")), mode=1, title="Delay Wave", win=AnalPanel PanelPos+=30 //Tab 2=Actions PanelPos=65 ListBox PT size={260,255}, pos={30,PanelPos}, disable=1, listwave=PlotType, selwave=PTSelection, mode=4, proc=PTHandler, win=AnalPanel PanelPos+=265 //Tab 3=Options PanelPos=65 SetVariable SN size={135,20}, pos={20,PanelPos}, disable=1, noproc, value=SmoothNumber, title="Smoothing Number", win=AnalPanel CheckBox GAW size={100,20}, pos={167,PanelPos}, disable=1, noproc, variable=GraphAnalyzedWaves, title="Graph Analyzed Waves", win=AnalPanel PanelPos+=25 GroupBox DOB size={280, 40}, pos={20,PanelPos+5}, disable=1, title="Duplicating Options", win=AnalPanel SetVariable DL size={152,20}, pos={28,PanelPos+25}, disable=1, noproc, value=DupLetter, title="New First Letter/Suffix", win=AnalPanel CheckBox DC size={100,20}, pos={190,PanelPos+25}, disable=1, noproc, variable=DupTweenCursors, title="Only Dup Act Rng", win=AnalPanel PanelPos+=55 SetVariable EWN size={130,20}, pos={20,PanelPos}, disable=1, noproc, value=ExWaveNote, title="Wave Note", win=AnalPanel SetVariable MVF size={130,20}, pos={160,PanelPos}, disable=1, noproc, value=MVFFitNum, title="Fit Anal #", win=AnalPanel PanelPos+=25 GroupBox FIT size={280, 70}, pos={20,PanelPos}, disable=1, title="Fit", win=AnalPanel PopupMenu CFT size={80,20}, pos={28,PanelPos+20}, disable=1, noproc, value=("gauss;lor;exp;dblexp;sin;line;poly;hillequation;sigmoid;power;lognormal"), mode=3, title="Type", win=AnalPanel SetVariable HC size={110,20}, pos={158,PanelPos+23}, disable=1, noproc, value=FitFlags, title="Flags", win=AnalPanel CheckBox SFZ size={80,20}, pos={28,PanelPos+50}, disable=1, noproc, variable=SetFitZero, title="Cursor=0", win=AnalPanel CheckBox EXF size={20,20}, pos={100,PanelPos+50}, disable=1, noproc, variable=ExtrapolateFit, title="", win=AnalPanel SetVariable SFS size={102,20}, pos={115,PanelPos+50}, disable=1, noproc, value=SaveFS, title="Extrp Fit: St", win=AnalPanel SetVariable SFE size={68,20}, pos={225,PanelPos+50}, disable=1, noproc, value=SaveFE, title="End", win=AnalPanel PanelPos+=80 SetVariable PTH size={140,20}, pos={20,PanelPos}, disable=1, noproc, value=PeakThreshold, title="Peak: Threshold", win=AnalPanel SetVariable PLN size={110,20}, pos={170,PanelPos}, disable=1, noproc, value=PeakLength, title="Length (Pts)", win=AnalPanel PanelPos+=25 PTHandler("",0,0,0)//for pulse end Function TabHandler(Dummy, Tab) String Dummy //not used Variable Tab NVAR WhichTab WhichTab=Tab PTHandler("",0,0,0) end Function RTHandler (ctrlName,popNum,popStr) : PopupMenuControl String ctrlName Variable popNum // which item is currently selected (1-based) String popStr // contents of current popup item as string NVAR RangeType RangeType=popNum PTHandler("",0,0,0) End Function PTHandler(ctrlName,row,col,event) String ctrlName // not used Variable row, col, event NVAR UseBl, GraphBL, GraphAnalyzedWaves, WhichTab, RangeType WAVE PTSelection WAVE /T PlotType //We don't care what was clicked, we'll just set everything everytime if (WhichTab==0) PopupMenu RT disable=0, win=AnalPanel CheckBox TOP disable=0, win=AnalPanel SetVariable PTM disable=(RangeType!=2), win=AnalPanel SetVariable INC disable=(RangeType!=3), win=AnalPanel TitleBox ITB disable=(RangeType!=3), win=AnalPanel SetVariable ISS disable=(RangeType!=3), win=AnalPanel SetVariable ISE disable=(RangeType!=3), win=AnalPanel SetVariable ISI disable=(RangeType!=3), win=AnalPanel PopupMenu WCF disable=(RangeType!=4), win=AnalPanel PopupMenu PS disable=(RangeType!=1), win=AnalPanel PopupMenu WavePrototype disable=(RangeType!=1), win=AnalPanel SetVariable STS disable=(RangeType!=1), win=AnalPanel SetVariable STE disable=(RangeType!=1), win=AnalPanel SetVariable STI disable=(RangeType!=1), win=AnalPanel SetVariable SSS disable=(RangeType!=1), win=AnalPanel SetVariable SSE disable=(RangeType!=1), win=AnalPanel SetVariable SSI disable=(RangeType!=1), win=AnalPanel CheckBox GUE disable=(RangeType!=1), win=AnalPanel if (cmpstr(sDataSource,"AXON")==0) PopupMenu SCS disable=(RangeType!=1), win=AnalPanel else SetVariable SCS disable=(RangeType!=1), win=AnalPanel SetVariable SCE disable=(RangeType!=1), win=AnalPanel endif else PopupMenu RT disable=1, win=AnalPanel CheckBox TOP disable=1, win=AnalPanel SetVariable PTM disable=1, win=AnalPanel SetVariable INC disable=1, win=AnalPanel TitleBox ITB disable=1, win=AnalPanel SetVariable ISS disable=1, win=AnalPanel SetVariable ISE disable=1, win=AnalPanel SetVariable ISI disable=1, win=AnalPanel PopupMenu WCF disable=1, win=AnalPanel PopupMenu PS disable=1, win=AnalPanel PopupMenu WavePrototype disable=1, win=AnalPanel SetVariable STS disable=1, win=AnalPanel SetVariable STE disable=1, win=AnalPanel SetVariable STI disable=1, win=AnalPanel SetVariable SSS disable=1, win=AnalPanel SetVariable SSE disable=1, win=AnalPanel SetVariable SSI disable=1, win=AnalPanel CheckBox GUE disable=1, win=AnalPanel if (cmpstr(sDataSource,"AXON")==0) PopupMenu SCS disable=1, win=AnalPanel else SetVariable SCS disable=1, win=AnalPanel SetVariable SCE disable=1, win=AnalPanel endif endif if (WhichTab==1) GroupBox AR disable=0, win=AnalPanel CheckBox GCL disable=0, win=AnalPanel Button GetAR disable=0, win=AnalPanel Button FixAR disable=0, win=AnalPanel SetVariable ST disable=0, win=AnalPanel SetVariable ET disable=0, win=AnalPanel GroupBox BL disable=0, win=AnalPanel CheckBox UBL disable=0, win=AnalPanel CheckBox GBL disable=0, win=AnalPanel Button GetBR disable=0, win=AnalPanel Button FixBR disable=0, win=AnalPanel SetVariable BLS disable=0, win=AnalPanel SetVariable BLE disable=0, win=AnalPanel SetVariable TRN disable=0, win=AnalPanel SetVariable TRF disable=0, win=AnalPanel PopupMenu TRW disable=0, win=AnalPanel else GroupBox AR disable=1, win=AnalPanel CheckBox GCL disable=1, win=AnalPanel Button GetAR disable=1, win=AnalPanel Button FixAR disable=1, win=AnalPanel SetVariable ST disable=1, win=AnalPanel SetVariable ET disable=1, win=AnalPanel GroupBox BL disable=1, win=AnalPanel CheckBox UBL disable=1, win=AnalPanel CheckBox GBL disable=1, win=AnalPanel Button GetBR disable=1, win=AnalPanel Button FixBR disable=1, win=AnalPanel SetVariable BLS disable=1, win=AnalPanel SetVariable BLE disable=1, win=AnalPanel SetVariable TRN disable=1, win=AnalPanel SetVariable TRF disable=1, win=AnalPanel PopupMenu TRW disable=1, win=AnalPanel endif if (WhichTab==2) ListBox PT disable=0, win=AnalPanel else ListBox PT disable=1, win=AnalPanel endif if (WhichTab==3) CheckBox GAW disable=0, win=AnalPanel SetVariable SN disable=0, win=AnalPanel else CheckBox GAW disable=1, win=AnalPanel SetVariable SN disable=1, win=AnalPanel endif if (((PTSelection[kBLSub]&16)==16)||((PTSelection[kSmooth]&16)==16)) //Baseline subtract and/or smooth checked PTSelection[kDup]=PTSelection[kDup]|16 //Check duplicate PlotType[kDup]="Must Duplicate" else PlotType[kDup]="Duplicate" endif if (((PTSelection[kDup]&16)==16)&&(WhichTab==3)) //Duplicate checked GroupBox DOB disable=0, win=AnalPanel SetVariable DL disable=0, win=AnalPanel CheckBox DC disable=0, win=AnalPanel else GroupBox DOB disable=1, win=AnalPanel SetVariable DL disable=1, win=AnalPanel CheckBox DC disable=1, win=AnalPanel endif if (((PTSelection[kExtWN]&16)==16)&&(WhichTab==3)) //Extract Wave Note checked SetVariable EWN disable=0, win=AnalPanel else SetVariable EWN disable=1, win=AnalPanel endif if (((PTSelection[kMinVsFit]&16)==16)&&(WhichTab==3)) //Min vs. fit checked SetVariable MVF disable=0, win=AnalPanel else SetVariable MVF disable=1, win=AnalPanel endif if (((PTSelection[kBLSub]&16)==16)||((PTSelection[kPeak]&16)==16)||((PTSelection[kArtX]&16)==16)||((PTSelection[kPPR]&16)==16))//Baseline subtract or Peak Discriminator UseBl=1 UBLHandler("",0)//Update other controls endif if ((PTSelection[kFit]&16)==16)//fit GraphAnalyzedWaves=1 //Will want them graphed so we can overlay fits endif if (((PTSelection[kFit]&16)==16)&&(WhichTab==3))//fit PopupMenu CFT disable=0, win=AnalPanel CheckBox SFZ disable=0, win=AnalPanel SetVariable SFS disable=0, win=AnalPanel SetVariable SFE disable=0, win=AnalPanel GroupBox FIT disable=0, win=AnalPanel SetVariable HC disable=0, win=AnalPanel CheckBox EXF disable=0, win=AnalPanel else PopupMenu CFT disable=1, win=AnalPanel CheckBox SFZ disable=1, win=AnalPanel SetVariable SFS disable=1, win=AnalPanel SetVariable SFE disable=1, win=AnalPanel GroupBox FIT disable=1, win=AnalPanel SetVariable HC disable=1, win=AnalPanel CheckBox EXF disable=1, win=AnalPanel endif if (((PTSelection[kPeak]&16)==16)&&(WhichTab==3))//Peak SetVariable PTH disable=0, win=AnalPanel SetVariable PLN disable=0, win=AnalPanel else SetVariable PTH disable=1, win=AnalPanel SetVariable PLN disable=1, win=AnalPanel endif return 0 // other return values reserved End Function UBLHandler(ctrlName,checked) : CheckBoxControl String ctrlName Variable checked VARIABLE DisableValue STRING ActionMode NVAR UseBL, WhichTab WAVE /T PlotType WAVE PTSelection if ((((PTSelection[kBLSub]&16)==16)||((PTSelection[kPeak]&16)==16)||((PTSelection[kArtX]&16)==16)||((PTSelection[kPPR]&16)==16))&&(UseBL==0)) //Baseline subtract unchecked but can't turn off baseline beep UseBL=1 endif if (UseBL==0) //Update controls based on UseBL value DisableValue=2 //disabled (but visible--undocumented, might want to change to 1) ActionMode=" (Absolute)" //update Action names else DisableValue=0 //enabled ActionMode=" (vs. Baseline)" endif if (WhichTab!=1) DisableValue=1 endif SetVariable BLS disable=DisableValue, win=AnalPanel SetVariable BLE disable=DisableValue, win=AnalPanel PlotType[kMax]="Maximum"+ActionMode PlotType[kMin]="Minimum"+ActionMode PlotType[kBig]="Bigger"+ActionMode PlotType[kAvg]="Average"+ActionMode End Function GetCursorsHandler(ctrlName) : ButtonControl String ctrlName NVAR StartTime, EndTime, PATBaseLineStart, PATBaseLineEnd if (cmpstr(ctrlName,"GetAR")==0)//Which range control are we dealing with? StartTime=min(PCSR(A),PCSR(B)) EndTime=max(PCSR(A),PCSR(B)) else PATBaseLineStart=min(PCSR(A),PCSR(B)) PATBaseLineEnd=max(PCSR(A),PCSR(B)) endif End Function FixTimeHandler(ctrlName) : ButtonControl //Converts time to points in appropriate controls //Based on first wave in top graph STRING ctrlName NVAR StartTime, EndTime, PATBaseLineStart, PATBaseLineEnd STRING WaveNameForX2PNT WaveNameForX2PNT=StringFromList(0, wavelist("*",";","WIN:")) if (cmpstr(ctrlName,"FixAR")==0)//Which range control are we dealing with? StartTime=X2PNT($WaveNameForX2PNT,StartTime) EndTime=X2PNT($WaveNameForX2PNT,EndTime) elseif (cmpstr(ctrlName,"FixBR")==0) PATBaseLineStart=X2PNT($WaveNameForX2PNT,PATBaseLineStart) PATBaseLineEnd=X2PNT($WaveNameForX2PNT,PATBaseLineEnd) else // endif end Function OpenOrMake(OOMWaveName,IsText,DesiredLen) STRING OOMWaveName VARIABLE IsText, DesiredLen VARIABLE RefNum Open /Z/R/P=SettingsPath RefNum as OOMWaveName //To test if it's there if (V_Flag==0) //file exists Close RefNum LoadWave /P=SettingsPath /O /Q OOMWaveName else OOMWaveName=OOMWaveName[0,strlen(OOMWaveName)-5] //remove extension--change for macintosh if (IsText) Make /N=(DesiredLen)/O/T $OOMWaveName else Make /N=(DesiredLen)/O $OOMWaveName endif SetScale/P x, 3, 1, $OOMWaveName endif return (numpnts($OOMWaveName)) end Function SaveAP (ctrlName,popNum,popStr) : PopupMenuControl //Saves current settings or loads previously saved ones //Trial ranges not saved since I see this as independent of the type of analysis, at least the way I do my experiments //Delay Wave not saved due to difficulty in dealing with it if it isn't present, although this was solved for the WCF popup //Sorry--poorly written. Settings waves have (of course) point values from 0 to N-1, where N=number of settings saved, they have X values //of 3 to N+2 (these numbers correspond to popNum which is why I did it), and the user sees numbers from 1 to N. I use different ways to //index in different places. String ctrlName Variable popNum // which item is currently selected (1-based) String popStr // contents of current popup item as string NVAR SmoothNumber, StartTime, EndTime, UseBL, GraphBL, PATBaseLineStart, PATBaseLineEnd, DupTweenCursors, GraphAnalyzedWaves, GetCursorsLater NVAR SaveSS, SaveSE, SweepIncrement, SetFitZero, ExtrapolateFit, SaveFS, SaveFE, TrainNum, TrainFreq, PeakThreshold, PeakLength NVAR MVFFitNum, TopWindow, RangeType SVAR DupLetter, ExWaveNote, AnalSettings, FitFlags, PatternToMatch, IncrementString WAVE PTSelection, SetAREnd, SetARStart, SetBLEnd, SetBLStart, SetDupAR, SetGraphAW, SetSmoothing, SetUseBL, SetGraphBL, SetPlotStyle, SetPTSetting, SetGetCurLater WAVE SetSStart, SetSEnd, SetSInc, SetFitType, SetSetFitZero, SetExtFit, SetFStart, SetFEnd, SetTrNum, SetTrFreq, SetPeakTh, SetPeakL, SetMVF, SetTopWindow, SetRangeType WAVE/T SetDupLetter, SettingName, SetEWN, SetFitFlags, SetPatternToMatch, SetIncrementString, SetWCF Variable/G LastSettingNum Variable Temp1 String NewSettingName, TempStr ControlUpdate /A/W=AnalPanel //Update any unentered values in panel if (popNum>2) //Copy settings from selected set EndTime=SetAREnd(popNum) StartTime=SetARStart(popNum) PATBaseLineEnd=SetBLEnd(popNum) PATBaseLineStart=SetBLStart(popNum) DupTweenCursors=SetDupAR(popNum) DupLetter=SetDupLetter(popNum) ExWaveNote=SetEWN(popNum) GetCursorsLater=SetGetCurLater(popNum) GraphAnalyzedWaves=SetGraphAW(popNum) SmoothNumber=SetSmoothing(popNum) NewSettingName=SettingName(popNum) UseBL=SetUseBL(popNum) GraphBL=SetGraphBL(popNum) FitFlags=SetFitFlags(popNum) SetFitZero=SetSetFitZero(popNum) ExtrapolateFit=SetExtFit(popNum) SaveFS=SetFStart(popNum) SaveFE=SetFEnd(popNum) TrainNum=SetTrNum(popNum) TrainFreq=SetTrFreq(popNum) PeakThreshold=SetPeakTh(popNum) PeakLength=SetPeakL(popNum) PopupMenu PS mode=SetPlotStyle(popNum), win=AnalPanel for (Temp1=0;Temp1<=(kNumActions-1);Temp1+=1) //Store all the values as bits in one variable if ((SetPTSetting(popNum)&2^Temp1)==2^Temp1) PTSelection[Temp1]=48 else PTSelection[Temp1]=32 endif endfor SaveSS=SetSStart(popNum) SaveSE=SetSEnd(popNum) SweepIncrement=SetSInc(popNum) MVFFitNum=SetMVF(popNum) TopWindow=SetTopWindow(popNum) RangeType=SetRangeType(popNum) PatternToMatch=SetPatternToMatch(popNum) IncrementString=SetIncrementString(popNum) if (Exists(SetWCF(popNum))==6) //If the saved function name exists, find which item it should be in list and select that TempStr="Choose your function;"+FunctionList("*",";","KIND:2,NPARAMS:0,VALTYPE:4") PopupMenu WCF mode=(WhichLIstItem(SetWCF(popNum),TempStr)+1), win=AnalPanel elseif (RangeType==4) //if it's needed and doesn't exist, alert user DoAlert 0, "This setting needs a wave choosing function which doesn't seem to exist" endif PopupMenu CFT mode=SetFitType(popNum), win=AnalPanel PopupMenu RT mode=RangeType, win=AnalPanel //Update panel PTHandler("",0,0,0) UBLHandler("",0) LastSettingNum=popNum else if (popNum==1) //Save current settings Prompt NewSettingName, "New Setting Name" DoPrompt "Enter Name for Current Settings", NewSettingName if (V_flag==1) return -1 endif LastSettingNum=numpnts(SettingName)+3 //Add one to size of waves and fill with current settings Redimension/N=(LastSettingNum-2) SetAREnd, SetARStart, SetBLEnd, SetBLStart, SetDupAR, SetDupLetter, SetEWN, SetGetCurLater, SetGraphAW, SetPlotStyle, SetPTSetting, SetSmoothing, SettingName, SetUseBL, SetGraphBL Redimension/N=(LastSettingNum-2) SetSStart, SetSEnd, SetSInc, SetFitType, SetFitFlags, SetSetFitZero, SetExtFit, SetFStart, SetFEnd, SetTrNum, SetTrFreq, SetPeakTh, SetPeakL, SetMVF, SetTopWindow, SetRangeType, SetPatternToMatch, SetIncrementString, SetWCF SetAREnd[LastSettingNum-2]=EndTime SetARStart[LastSettingNum-2]=StartTime SetBLEnd[LastSettingNum-2]=PATBaseLineEnd SetBLStart[LastSettingNum-2]=PATBaseLineStart SetDupAR[LastSettingNum-2]=DupTweenCursors SetDupLetter[LastSettingNum-2]=DupLetter SetEWN[LastSettingNum-2]=ExWaveNote SetGetCurLater[LastSettingNum-2]=GetCursorsLater SetGraphAW[LastSettingNum-2]=GraphAnalyzedWaves SetSmoothing[LastSettingNum-2]=SmoothNumber SettingName[LastSettingNum-2]=NewSettingName SetUseBL[LastSettingNum-2]=UseBL SetGraphBL[LastSettingNum-2]=GraphBL SetSStart[LastSettingNum-2]=SaveSS SetSEnd[LastSettingNum-2]=SaveSE SetSInc[LastSettingNum-2]=SweepIncrement SetFitFlags[LastSettingNum-2]=FitFlags SetSetFitZero[LastSettingNum-2]=SetFitZero SetExtFit[LastSettingNum-2]=ExtrapolateFit SetFStart[LastSettingNum-2]=SaveFS SetFEnd[LastSettingNum-2]=SaveFE SetTrNum[LastSettingNum-2]=TrainNum SetTrFreq[LastSettingNum-2]=TrainFreq SetPeakTh[LastSettingNum-2]=PeakThreshold SetPeakL[LastSettingNum-2]=PeakLength SetMVF[LastSettingNum-2]=MVFFitNum SetTopWindow[LastSettingNum-2]=TopWindow SetRangeType[LastSettingNum-2]=RangeType SetPatternToMatch[LastSettingNum-2]=PatternToMatch SetIncrementString[LastSettingNum-2]=IncrementString ControlInfo /W=AnalPanel CFT SetFitType[LastSettingNum-2]=V_Value ControlInfo /W=AnalPanel PS SetPlotStyle[LastSettingNum-2]=V_Value ControlInfo /W=AnalPanel WCF SetWCF[LastSettingNum-2]=S_Value SetPTSetting[LastSettingNum-2]=0 for (Temp1=0;Temp1<=(kNumActions-1);Temp1+=1) //Store all the values as bits in one variable if ((PTSelection[Temp1]&16)==16) SetPTSetting[LastSettingNum-2]+=2^Temp1 endif endfor else //popnum=2, delete one Prompt Temp1, "Setting to delete" DoPrompt "Setting to delete", Temp1 if (V_flag==1) return -1 endif DeletePoints Temp1-1, 1, SetAREnd, SetARStart, SetBLEnd, SetBLStart, SetDupAR, SetDupLetter, SetEWN, SetGetCurLater, SetGraphAW, SetPlotStyle, SetPTSetting, SetSmoothing, SettingName, SetUseBL, SetGraphBL DeletePoints Temp1-1, 1, SetSStart, SetSEnd, SetSInc, SetFitType, SetFitFlags, SetSetFitZero, SetExtFit, SetFStart, SetFEnd, SetTrNum, SetTrFreq, SetPeakTh, SetPeakL, SetMVF, SetTopWindow, SetRangeType, SetPatternToMatch, SetIncrementString, SetWCF if (LastSettingNum>Temp1+2)//Lots of effort just to make the display right after deleting LastSettingNum-=1 elseif (LastSettingNum==Temp1+2) LastSettingNum=numpnts(SettingName)+3 endif endif //Save the updated waves on disk (if one deleted or created) Save /P=SettingsPath /O SetMVF Save /P=SettingsPath /O SetTopWindow Save /P=SettingsPath /O SetRangeType Save /P=SettingsPath /O SetPatternToMatch Save /P=SettingsPath /O SetIncrementString Save /P=SettingsPath /O SetWCF Save /P=SettingsPath /O SetAREnd Save /P=SettingsPath /O SetARStart Save /P=SettingsPath /O SetBLEnd Save /P=SettingsPath /O SetBLStart Save /P=SettingsPath /O SetDupAR Save /P=SettingsPath /O SetDupLetter Save /P=SettingsPath /O SetEWN Save /P=SettingsPath /O SetGetCurLater Save /P=SettingsPath /O SetGraphAW Save /P=SettingsPath /O SetPlotStyle Save /P=SettingsPath /O SetPTSetting Save /P=SettingsPath /O SetSmoothing Save /P=SettingsPath /O SettingName Save /P=SettingsPath /O SetUseBL Save /P=SettingsPath /O SetGraphBL Save /P=SettingsPath /O SetSStart Save /P=SettingsPath /O SetSEnd Save /P=SettingsPath /O SetSInc Save /P=SettingsPath /O SetFitType Save /P=SettingsPath /O SetFitFlags Save /P=SettingsPath /O SetSetFitZero Save /P=SettingsPath /O SetExtFit Save /P=SettingsPath /O SetFStart Save /P=SettingsPath /O SetFEnd Save /P=SettingsPath /O SetTrNum Save /P=SettingsPath /O SetTrFreq Save /P=SettingsPath /O SetPeakTh Save /P=SettingsPath /O SetPeakL AnalSettings="" //Used only for popup for (Temp1=1;Temp1<=numpnts(SettingName);Temp1+=1) AnalSettings+=num2str(Temp1)+" "+SettingName[Temp1-1]+";" endfor PopupMenu SAP mode=LastSettingNum, win=AnalPanel endif End Function Graph2DWave(WaveToGraph,AxisToSplit,GraphWindowName) //Graphs a 2D wave as a series of 1D waves //Can split either dimension into a series of waves //Only appends to an existing window. Note: you pass the *name*, not the *title* of the window //I don't see any way to do it without making a series of waves, so look out! //As written will break if points on broken axis are not integers on that axis because wave names //can't have decimal points. You will have to change the wave naming scheme as shown //A clever person might add a SetWindow hook to cause these waves to be killed if the window is killed //Might also let function decide which axis to split based on which has fewer points STRING WaveToGraph,GraphWindowName VARIABLE AxisToSplit //0=x, 1=Y WAVE WTG=$WaveToGraph VARIABLE SplitVal, EndVal, OtherAxis, ColorNumber STRING OneDWaveName, SplitAxisName EndVal=DimSize($WaveToGraph, AxisToSplit) if (AxisToSplit) OtherAxis=0 SplitAxisName="X" else OtherAxis=1 SplitAxisName="Y" endif for (SplitVal=0;SplitVal0) //otherwise there wasn't one and there is no valid suffix AnalWaveSuffix=AnalWaveBase[Temp3-1,strlen(AnalWaveBase)-1] else AnalWaveSuffix="" endif //Reduce down to the invariate part at the beginning AnalWaveBase=AnalWaveBase[0,Temp1] //Set up looping and indexing variables if (cmpstr(sDataSource,"AXON")==0) ControlInfo /W=AnalPanel SCS ChanStyle=V_Value-1 if (ChanStyle==2) ChanStart=0 ChanEnd=1 else ChanStart=ChanStyle ChanEnd=ChanStyle endif Print "Anal",AnalNum," Hierarchical Mode:", PlotStyleName, " Trial",TrialStart,"to",TrialEnd,"by",TrialIncrement," Sweep",SweepStart,"to",SweepEnd, "by", SweepIncrement, " Channels", ChanStart, "to", ChanEnd else //HEKA ChanStart=SaveCS ChanEnd=SaveCE Print "Anal",AnalNum," Hierarchical Mode:", PlotStyleName,": Recording", ChanStart, "to", ChanEnd, " Trial",TrialStart,"to",TrialEnd,"by",TrialIncrement," Sweep",SweepStart,"to",SweepEnd, "by", SweepIncrement endif if ((PlotStyle==1)||(PlotStyle==5))//Plot all vs. time or sweep XRange=ceil((SweepEnd-SweepStart+1)/SweepIncrement)*ceil((TrialEnd-TrialStart+1)/TrialIncrement) YRange=1 endif if ((PlotStyle==2)||(PlotStyle==4))//Average comparable sweeps between trials or Group XRange=ceil((SweepEnd-SweepStart+1)/SweepIncrement) //Number of results per channel YRange=ceil((TrialEnd-TrialStart+1)/TrialIncrement) //Number of sweeps which will be averaged together endif if (PlotStyle==3)//Average comparable trials between sweeps XRange=ceil((TrialEnd-TrialStart+1)/TrialIncrement) YRange=ceil((SweepEnd-SweepStart+1)/SweepIncrement) endif else //Not hierarchical mode if (TopWindow) TempStr=" From Target" else TempStr="" endif switch (RangeType) case 2: //Pattern Waves4Anal=WaveList(PatternToMatch,";",WindowString) XRange=ItemsInList(Waves4Anal) if (XRange==0) DoAlert 0, "No matching waves found" OverWriteProtect[AnalNum]=0//unprotect Return -1 endif SweepStart=1 SweepEnd=XRange SweepIncrement=1 Print "Anal",AnalNum,": Pattern mode:",PatternToMatch,TempStr, " Waves Processed:" break case 3: //Incremental Temp1=strsearch(IncrementString,"%",0) // check for % symbol if (Temp1==-1) DoAlert 0, "You entered: "+IncrementString+" as the generic wave. You must input at least one % to be substituted" OverWriteProtect[AnalNum]=0//unprotect Return -1 endif XRange=ceil((SweepEnd-SweepStart+1)/SweepIncrement) Print "Anal",AnalNum,": Incremental mode:",IncrementString,"From",SweepStart,"to",SweepEnd, "by", SweepIncrement,TempStr, " Waves Processed:" break case 4: //User Function String /G UWNFReturnStr //User function must use this global to return wave name ControlInfo /W=AnalPanel WCF Print "Anal",AnalNum, "User function:", S_Value UserWaveNameFunction=S_Value+"()" SweepStart=1 SweepEnd=2//Will be incremented as we go SweepIncrement=1 XRange=1//Result waves will start at 1 and be redimensioned as needed endswitch PlotStyle=1 YRange=1 ChanStart=0 ChanEnd=0 TrialStart=0 TrialEnd=0 TrialIncrement=1 endif ControlInfo /W=AnalPanel CFT CurvefitType=S_Value if (((PTSelection[kFit]&16)==16)&&(PlotStyle==4))//fit on group DoAlert 0, "Sorry, I'm too lazy to program fits for grouped data, please choose another mode" OverWriteProtect[AnalNum]=0//unprotect return -1 endif if (((PTSelection[kPPR]&16)==16)&&(TrainNum<2)) DoAlert 0, "Train Number must be at least 2 for PPR" OverWriteProtect[AnalNum]=0//unprotect return -1 endif if (GetCursorsLater) SaveST=min(PCSR(A),PCSR(B)) SaveET=max(PCSR(A),PCSR(B)) endif //****************************should add anal by experiment's epochs //Some windows you might need: if (GraphAnalyzedWaves) Display as ("Waves"+num2str(AnalNum)) DoWindow /C $("Waves"+num2str(AnalNum)) endif if (TrainNum>1) //Train if (PlotStyle==4) DoAlert 0, "Cannot do trains in group mode" OverWriteProtect[AnalNum]=0//unprotect return -1 endif Display as "Train"+num2str(AnalNum) DoWindow /C $("Train"+num2str(AnalNum)) elseif (TrainNum<1) TrainNum=1 endif //************Run the range: for (ChanLoop=ChanStart;ChanLoop<=ChanEnd;ChanLoop+=1) //Each Channel (AXON)/Recording (HEKA) (essentially totally separate operations) if (ChanStart!=ChanEnd) ChanLoopStr=num2str(ChanLoop)//Will be used to differentiate results from different channels if (cmpstr(sDataSource,"AXON")==0) ChanTitleStr=" Ch" ChanNameStr="Ch" else ChanTitleStr=" Rec" ChanNameStr="Rec" endif UseWaveName="" else ChanLoopStr="" //keep names cleaner if not required ChanTitleStr="" ChanNameStr="" endif //Here's where you'll put the answers: //Make result waves--can add plenty more if you like! //Create them all, then just kill them at the end if you don't want them. These may be the basis for other calculations even if not ultimately wanted. if (TrainNum<2) //Train waves created for each analyzed wave MaxWaveName="Max"+ChanLoopStr+"_"+num2str(AnalNum) MinWaveName="Min"+ChanLoopStr+"_"+num2str(AnalNum) BLWaveName="BL"+ChanLoopStr+"_"+num2str(AnalNum) AvgWaveName="Avg"+ChanLoopStr+"_"+num2str(AnalNum) BigWaveName="Big"+ChanLoopStr+"_"+num2str(AnalNum) endif NWaveName="Num"+ChanLoopStr+"_"+num2str(AnalNum) EWNWaveName="EWN"+ChanLoopStr+"_"+num2str(AnalNum) PeakWaveName="Peak"+ChanLoopStr+"_"+num2str(AnalNum) PeakTimeWaveName="PeakTime"+ChanLoopStr+"_"+num2str(AnalNum) PPRWaveName="PPR"+ChanLoopStr+"_"+num2str(AnalNum) WaveNameWaveName="AnalyzedWaves"+ChanLoopStr+"_"+num2str(AnalNum) if (PlotStyle==4)//Group, results will be XY make/O /N=(XRange,YRange) $MaxWaveName, $MinWaveName, $BLWaveName, $AvgWaveName, $BigWaveName, $NWaveName, $EWNWaveName, $PeakWaveName, $PeakTimeWaveName, $PPRWaveName, $WaveNameWaveName make/O /T /N=(XRange,YRange) $WaveNameWaveName else if (TrainNum<2) make/O /N=(XRange) $MaxWaveName, $MinWaveName, $BLWaveName, $AvgWaveName, $BigWaveName endif make/O /N=(XRange) $NWaveName, $EWNWaveName, $PeakWaveName, $PeakTimeWaveName, $PPRWaveName make/O /T /N=(XRange) $WaveNameWaveName endif if ((PTSelection[kConcat]&16)==16) //Concatenate CatWaveName="Concat"+ChanLoopStr+"_"+num2str(AnalNum) make/O /N=0 $CatWaveName endif if (PlotStyle==5) //vs. time TimeWaveName="Time"+ChanLoopStr+"_"+num2str(AnalNum) make/O /N=(XRange) $TimeWaveName WAVE TimeWave=$TimeWaveName TimeWave=NaN endif if((PTSelection[kFit]&16)==16)//fit FitWaveName="Fit"+ChanLoopStr+"_"+num2str(AnalNum) make/O /N=(XRange,5) $FitWaveName, W_Coef WAVE FitWave=$FitWaveName if ((PlotStyle==1)||(PlotStyle==5)) //These aren't averaged together, make them NaN so it's obvious if they're skipped FitWave=NaN else FitWave=0 endif endif if((PTSelection[kPeak]&16)==16)//Peak Discriminator if ((PlotStyle==2)||(PlotStyle==3)) //averages make/O /N=(XRange) PeakN PeakN=0 endif endif if((PTSelection[kMinVsFit]&16)==16)//Min vs. fit MVFWaveName="MVF"+ChanLoopStr+"_"+num2str(AnalNum) make/O /N=(XRange) $MVFWaveName WAVE MVFWave=$MVFWaveName MVFWave=NaN endif if (TrainNum<2) WAVE MaxWave=$MaxWaveName WAVE MinWave=$MinWaveName WAVE BLWave=$BLWaveName WAVE AvgWave=$AvgWaveName WAVE BigWave=$BigWaveName endif WAVE NWave=$NWaveName WAVE EWNWave=$EWNWaveName WAVE PeakWave=$PeakWaveName WAVE PeakTimeWave=$PeakTimeWaveName WAVE PPRWave=$PPRWaveName WAVE /T WaveNameWave=$WaveNameWaveName WaveNameWave="" NWave=0 if ((PlotStyle==1)||(PlotStyle==4)||(PlotStyle==5)) //These aren't averaged together, make them NaN so it's obvious if they're skipped if (TrainNum<2) MaxWave=NaN MinWave=NaN BLWave=NaN AvgWave=NaN BigWave=NaN endif EWNWave=NaN PeakWave=NaN PeakTimeWave=NaN PPRWave=NaN else if (TrainNum<2) MaxWave=0 MinWave=0 BLWave=0 AvgWave=0 BigWave=0 endif EWNWave=0 PeakWave=0 PeakTimeWave=0 PPRWave=0 endif if ((PTSelection[kUserFunc]&16)==16) //Call UserFunc1 InitUserFunc1(XRange, YRange, ChanLoop, AnalNum) endif MakeWAW=1 MasterIndex=-1 for (TrialLoop=TrialStart;TrialLoop<=TrialEnd;TrialLoop+=TrialIncrement) for (SweepLoop=SweepStart;SweepLoop<=SweepEnd;SweepLoop+=SweepIncrement) //**********The sweeps--The INNER LOOP //Index for answers: if ((PlotStyle==1)||(PlotStyle==5))//Plot all vs. time or sweep (if it's vs. time then the x value is in the corresponding X wave) MasterIndex+=1 elseif (PlotStyle==2)//Average comparable sweeps between trials MasterIndex=(SweepLoop-SweepStart)/SweepIncrement elseif (PlotStyle==3)//Average comparable trials between sweeps MasterIndex=(TrialLoop-TrialStart)/TrialIncrement elseif (PlotStyle==4)//Group, results will be X(sweep) and Y(trial) XIndex=(SweepLoop-SweepStart)/SweepIncrement YIndex=(TrialLoop-TrialStart)/TrialIncrement Endif //Analysis ranges: StartTime=SaveST EndTime=SaveET BaseLineStart=SaveBLS BaseLineEnd=SaveBLE if (DoOffset) // do it with a sweep-dependent offset from the action range StartTime+=TrainOffset(SweepLoop)//SweepLoop corresponds to X value to be as flexible as possible in what sweeps can be accomodated. EndTime+=TrainOffset(SweepLoop) BaseLineStart+=TrainOffset(SweepLoop) BaseLineEnd+=TrainOffset(SweepLoop) endif //Figure out the name of the wave to analyze, put in CurrentWaveName switch (RangeType) case 1: //Hierachy if (cmpstr(sDataSource,"AXON")==0) //CurrentWaveName="0000"+num2str(TrialLoop) //This part is left padded with 0s to 4 digits, will strip off excess next //CurrentWaveName=AnalWaveBase+CurrentWaveName[strlen(CurrentWaveName)-4,strlen(CurrentWaveName)]+"_Ch"+num2str(ChanLoop)+"_"+num2str(SweepLoop)+AnalWaveSuffix sprintf CurrentWaveName, "%.4u", mod(TrialLoop,10000) CurrentWaveName=AnalWaveBase+CurrentWaveName+"_Ch"+num2str(ChanLoop)+"_"+num2str(SweepLoop)+AnalWaveSuffix else //HEKA CurrentWaveName=AnalWaveBase+num2str(ChanLoop)+"_"+num2str(TrialLoop)+"_"+num2str(SweepLoop)+AnalWaveSuffix endif //See if wave exists and fix things if it doesn't if (waveexists($CurrentWaveName)==0) print CurrentWaveName, "doesn't exist" if ((PlotStyle==1)||(PlotStyle==5))//Plot all vs. time or sweep (Don't really need to test) MasterIndex-=1 //Don't create empty spaces for waves that don't exist. endif continue endif break case 2: //Pattern CurrentWaveName=StringFromList(SweepLoop-1,Waves4Anal) print CurrentWaveName break case 3: //Incremental CurrentWaveName=IncrementString // will substitute the numbers into copy of IncrementString Temp1=strsearch(CurrentWaveName,"%",0) // find % symbol do // Replace % and find the next one or stop if the last one CurrentWaveName[Temp1,Temp1]=num2str(SweepLoop) // Remarkable igor string sub feature will expand the space in string as much as required (see pg III-18 in ver 3.1 manual) Temp2=Temp1+1 //move on to the bit after the % Temp1=strsearch(CurrentWaveName,"%",Temp2) while (Temp1!=-1) // if strsearch returned -1 we're done, works even if pointed past the end of the string (% was the last char) //See if wave exists and fix things if it doesn't if (waveexists($CurrentWaveName)==0) MasterIndex-=1 //Don't create empty spaces for waves that don't exist. continue endif print CurrentWaveName break case 4: //User Function Execute UserWaveNameFunction CurrentWaveName=UWNFReturnStr if (cmpstr(CurrentWaveName,"")==0) //User function is telling us we're done SweepEnd=SweepLoop-1//In case this is used later to keep track of how many were done if (SweepLoop==SweepStart) //None processed Print "No Waves Returned by",UserWaveNameFunction Return 0 //Don't bother with display etc. endif MasterIndex-=1 continue else SweepEnd+=1 //So we'll try another after this redimension /N=(SweepLoop) $MaxWaveName, $MinWaveName, $BLWaveName, $AvgWaveName, $BigWaveName, $NWaveName, $EWNWaveName, $PeakWaveName, $PeakTimeWaveName, $PPRWaveName //***Others to redimension?**** //Not a bug, waves are made /O if (WaveExists($TimeWaveName)!=0) redimension /N=(SweepLoop) $TimeWaveName endif if (WaveExists($FitWaveName)!=0) redimension /N=(SweepLoop,5) $FitWaveName, W_Coef endif if (WaveExists(PeakN)!=0) redimension /N=(SweepLoop) PeakN endif if (WaveExists($MVFWaveName)!=0) redimension /N=(SweepLoop) $MVFWaveName endif endif //User function may print wave names as desired endswitch if (TopWindow) //Test for presence in top window if (FindListItem(CurrentWaveName,WaveList("*",";",WindowString))==-1) print CurrentWaveName, "not in top window" if ((PlotStyle==1)||(PlotStyle==5))//Plot all vs. time or sweep (Don't really need to test) MasterIndex-=1 //Don't create empty spaces for waves that don't exist. endif //Might want to play with SweepLoop if RangeType is 4 (or even 3) or could call the user func repeatedly above until it returns one on the target continue endif endif //Now we have the wave to analyze WAVE CurrentWave=$CurrentWaveName //Keep track if it's the first time for this result storage position (in case we have to make waves the first time through) if (NWave[MasterIndex]>0) FirstTime=0 else FirstTime=1 endif //Make temp wave (for smoothing) from which to extract data UseWaveName=CurrentWaveName+"_Dup" duplicate/O $CurrentWaveName, $UseWaveName if (SmoothNumber>0) smooth SmoothNumber, $UseWaveName endif WAVE UseWave=$UseWaveName //Actions: //Duplicate if ((PTSelection[kDup]&16)==16) DupWaveName=CurrentWaveName if (StrSearch(DupLetter, "_",0)==-1) DupWaveName[0,0]=DupLetter else DupWaveName+=DupLetter endif if (DupTweenCursors) duplicate/O/R=[StartTime, EndTime] $CurrentWaveName, $DupWaveName else duplicate/O $CurrentWaveName, $DupWaveName endif WAVE DupWave=$DupWaveName endif //Accumulate the results for max, min, BL, avg, and big //These are the special ones--can be trains //Setup: if (TrainNum>1) //Make train versions of result waves if needed if ((PlotStyle==1)||(PlotStyle==5))//Plot all vs. time or sweep (if it's vs. time then the x value is in the corresponding X wave) TrainInfoStr="_T"+num2str(TrialLoop)+"_S"+num2str(SweepLoop)+"_" elseif (PlotStyle==2)//Average comparable sweeps between trials TrainInfoStr="_S"+num2str(SweepLoop)+"_" elseif (PlotStyle==3)//Average sweeps within each trial TrainInfoStr="_T"+num2str(TrialLoop)+"_" Endif TrainInfoStr=ChanLoopStr+TrainInfoStr+num2str(AnalNum) MaxWaveName="Max"+TrainInfoStr MinWaveName="Min"+TrainInfoStr BLWaveName="BL"+TrainInfoStr AvgWaveName="Avg"+TrainInfoStr BigWaveName="Big"+TrainInfoStr if (FirstTime) make /O /N=(TrainNum) $MaxWaveName, $MinWaveName, $BLWaveName, $AvgWaveName, $BigWaveName endif WAVE MaxWave=$MaxWaveName WAVE MinWave=$MinWaveName WAVE BLWave=$BLWaveName WAVE AvgWave=$AvgWaveName WAVE BigWave=$BigWaveName If (FirstTime) if ((PlotStyle==1)||(PlotStyle==5)) //These aren't averaged together, make them NaN so it's obvious if they're skipped MaxWave=NaN MinWave=NaN BLWave=NaN AvgWave=NaN BigWave=NaN else MaxWave=0 MinWave=0 BLWave=0 AvgWave=0 BigWave=0 endif SetScale /P x, 1, 1, "Stim #", MaxWave, MinWave, BLWave, AvgWave, BigWave SetScale d -1,1,StringByKey("DUNITS", WaveInfo(CurrentWave,0)), MaxWave, MinWave, BLWave, AvgWave, BigWave if ((PTSelection[kMax]&16)==16) AppendtoGraph /W=$("Train"+num2str(AnalNum)) MaxWave endif if ((PTSelection[kMin]&16)==16) AppendtoGraph /W=$("Train"+num2str(AnalNum)) MinWave endif if ((PTSelection[kAvg]&16)==16) AppendtoGraph /W=$("Train"+num2str(AnalNum)) AvgWave endif if ((PTSelection[kBig]&16)==16) AppendtoGraph /W=$("Train"+num2str(AnalNum)) BigWave endif if ((UseBL==1)&&(GraphBL==1)) AppendtoGraph /W=$("Train"+num2str(AnalNum)) BLWave endif ModifyGraph /W=$("Train"+num2str(AnalNum)) mode=4,marker=19,rgb=(0,0,0)//set traces black, lines between points endif endif TrainSR=deltaX(CurrentWave) TrainPointOffset=0 //Number of points offset for this stim in train. Do it this way in case TrainFreq was 0 when TrainNum is 1 //Do train anal (even for "trains" of 1) for (TrainLoop=0;TrainLoop1) TempIndex=TrainLoop TrainPointOffset=round((TrainLoop/TrainFreq)/TrainSR) else TempIndex=MasterIndex endif if (UseBL==1) wavestats /Q /R=[BaseLineStart+TrainPointOffset, BaseLineEnd+TrainPointOffset] UseWave CurrentBaseLine=V_avg //Baseline for this element in train BLSD=V_sdev*3 //For ArtX else CurrentBaseLine=0 endif wavestats /Q /R=[StartTime+TrainPointOffset, EndTime+TrainPointOffset] UseWave MinLoc=V_minloc MaxLoc=V_maxloc if (PlotStyle==4)//Group MaxWave[XIndex][YIndex]=V_max-CurrentBaseLine MinWave[XIndex][YIndex]=V_min-CurrentBaseLine AvgWave[XIndex][YIndex]=V_avg-CurrentBaseLine BLWave[XIndex][YIndex]=CurrentBaseLine if (abs(MaxWave[XIndex][YIndex])>abs(MinWave[XIndex][YIndex])) BigWave[XIndex][YIndex]=MaxWave[XIndex][YIndex] else BigWave[XIndex][YIndex]=MinWave[XIndex][YIndex] endif elseif ((PlotStyle==1)||(PlotStyle==5))//Plot all vs. time or sweep MaxWave[TempIndex]=V_max-CurrentBaseLine MinWave[TempIndex]=V_min-CurrentBaseLine AvgWave[TempIndex]=V_avg-CurrentBaseLine BLWave[TempIndex]=CurrentBaseLine if (abs(MaxWave[TempIndex])>abs(MinWave[TempIndex])) BigWave[TempIndex]=MaxWave[TempIndex] else BigWave[TempIndex]=MinWave[TempIndex] endif else MaxWave[TempIndex]+=V_max-CurrentBaseLine MinWave[TempIndex]+=V_min-CurrentBaseLine AvgWave[TempIndex]+=V_avg-CurrentBaseLine BLWave[TempIndex]+=CurrentBaseLine if (abs(V_max-CurrentBaseLine)>abs(V_min-CurrentBaseLine)) BigWave[TempIndex]+=V_max-CurrentBaseLine else BigWave[TempIndex]+=V_min-CurrentBaseLine endif endif //Artifact Stripper (Also a train capable procedure) if ((PTSelection[kArtX]&16)==16) NumOver=0 NumOK=0 ASLoop=StartTime+TrainPointOffset do //Find first 2 out of 3 points diff from baseline to detect start of artifact if ((CurrentWave[ASLoop]>CurrentBaseLine+BLSD)||(CurrentWave[ASLoop]CurrentBaseLine+BLSD)||(CurrentWave[ASLoop]0)) smooth SmoothNumber, DupWave endif //EWN Depending on PlotStyle you either add to the right place or just assign it (for ones that aren't averaged). Also you must reference a 2D wave for PlotStyle 4 if (cmpstr(sDataSource,"AXON")==0) Temp1=NumberByKey(ExWaveNote,note($CurrentWaveName)) else //HEKA Temp1=NaN //must set Temp1 here according to HEKA data format endif if (PlotStyle==4)//Group EWNWave[XIndex][YIndex]=Temp1 elseif ((PlotStyle==1)||(PlotStyle==5))//Plot all vs. time or sweep EWNWave[MasterIndex]=Temp1 else EWNWave[MasterIndex]+=Temp1 endif //Time if (PlotStyle==5)//vs. time if (cmpstr(sDataSource,"AXON")==0) TimeWave[MasterIndex]=NumberByKey("SWStartTime",note($CurrentWaveName))+NumberByKey("SweepStartTime",note($CurrentWaveName)) //Notes: stopwatch time, can be easily changed to clock time; possibility of rounding error causing an overlap or false gap of times of waves in different trials since axon only gives the whole number of seconds at the start of the trial else //HEKA //Must set TimeWave here according to HEKA data format endif endif //Concatenate if ((PTSelection[kConcat]&16)==16) ConcatenateWaves(CatWaveName, CurrentWaveName) endif //Call UserFunc1 if ((PTSelection[kUserFunc]&16)==16) UserFunc1(CurrentWaveName, MasterIndex) endif //Average Waves if((PTSelection[kAvgWave]&16)==16) if ((PlotStyle==1)||(PlotStyle==4)||(PlotStyle==5)) //Non averaging modes (may be counterintuitive to average in group mode, but otherwise what does the user intend?) WaveAvgWaveName="WaveAvg"+ChanLoopStr+"_"+num2str(AnalNum) else if (PlotStyle==2) //by trial WaveAvgWaveName="WaveAvg"+ChanLoopStr+"_S"+num2str(SweepLoop)+"_"+num2str(AnalNum) else //by sweep WaveAvgWaveName="WaveAvg"+ChanLoopStr+"_T"+num2str(TrialLoop)+"_"+num2str(AnalNum) endif MakeWAW=FirstTime endif if (MakeWAW) duplicate/O $CurrentWaveName, $WaveAvgWaveName MakeWAW=0 else WAVE WaveAvgWave=$WaveAvgWaveName WaveAvgWave+=CurrentWave endif endif //Recover raw HEKA wave if((PTSelection[kRawHEKA]&16)==16) if (cmpstr(AnalWaveSuffix,"_leak")==0) WAVE HEKALeakWave=$CurrentWaveName WAVE HEKATotalWave=$(CurrentWaveName[0,strlen(CurrentWaveName)-6]) HEKARawWaveName=CurrentWaveName[0,strlen(CurrentWaveName)-6]+"_raw" else WAVE HEKALeakWave=$(CurrentWaveName+"_leak") WAVE HEKATotalWave=$CurrentWaveName HEKARawWaveName=CurrentWaveName+"_raw" endif Duplicate/O HEKATotalWave, $HEKARawWaveName WAVE HEKARawWave=$HEKARawWaveName HEKARawWave+=HEKALeakWave endif //Fit if((PTSelection[kFit]&16)==16) Duplicate /O $UseWaveName, WavetoFit OrigLeftX=leftx(WavetoFit) if (SetFitZero)//Need to shift WavetoFit so that the beginning of the fit range is 0, will have to shift the dest wave back SetScale /P x, (OrigLeftX-Pnt2X(WavetoFit,StartTime)), deltax(WavetoFit), WavetoFit endif FitDestWaveName="fit_"+CurrentWaveName+"_"+num2str(AnalNum) Duplicate /O WavetoFit, $FitDestWaveName WAVE FitDestWave=$FitDestWaveName FitDestWave=NaN CurvefitFunc="Curvefit /N/Q "+FitFlags+CurvefitType+", WavetoFit["+num2str(StartTime)+","+num2str(EndTime)+"] /D="+FitDestWaveName execute/Z CurvefitFunc if (V_flag!=0) print "Fit error on wave", CurrentWaveName Killwaves FitDestWave else NumFitTerms=numpnts(W_Coef) //Save number of coefficients so that later we can strip out unused columns if (ExtrapolateFit) strswitch (CurvefitType) //I'm too lazy to put all these in. case "exp": for (Temp1=SaveFS;Temp1<=SaveFE;Temp1+=1) FitDestWave[Temp1]=W_coef[0]+W_coef[1]*exp(-W_coef[2]*PNT2X(WavetoFit,Temp1)) endfor break case "line": for (Temp1=SaveFS;Temp1<=SaveFE;Temp1+=1) FitDestWave[Temp1]=W_coef[0]+W_coef[1]*PNT2X(WavetoFit,Temp1) endfor break default: print "Sorry, that fit type doesn't have the extrapolate function typed in yet. Help yourself" endswitch endif SetScale /P x, OrigLeftX, deltax(WavetoFit), FitDestWave //Shift destination wave back AppendtoGraph /W=$("Waves"+num2str(AnalNum)) $FitDestWaveName if ((PlotStyle==1)||(PlotStyle==5))//Plot all vs. time or sweep FitWave[MasterIndex][]=W_Coef[q] else FitWave[MasterIndex][]+=W_Coef[q] endif endif Killwaves WavetoFit endif //PPR if ((PTSelection[kPPR]&16)==16) if ((PlotStyle==1)||(PlotStyle==4)||(PlotStyle==5)) PPRWave[MasterIndex]=MinWave[1]/MinWave[0] else PPRWave[MasterIndex]+=MinWave[1]/MinWave[0] endif endif //Peak discriminator (might rewrite for train) if ((PTSelection[kPeak]&16)==16) //Looks for PeakLength points in a row less than PeakThreshold away from baseline, allows for 2 noise points that don't fit Temp2=0 Temp3=0 for (Temp1=StartTime;Temp1<=EndTime;Temp1+=1) if (UseWave[Temp1]1) //Clean up unwanted trains for (TrialLoop=TrialStart;TrialLoop<=TrialEnd;TrialLoop+=TrialIncrement) for (SweepLoop=SweepStart;SweepLoop<=SweepEnd;SweepLoop+=SweepIncrement) TrainInfoStr="_T"+num2str(TrialLoop)+"_S"+num2str(SweepLoop)+"_"+num2str(AnalNum) if ((PTSelection[kMin]&16)!=16) KillWaves /Z $("Min"+ChanLoopStr+TrainInfoStr) endif if ((PTSelection[kMax]&16)!=16) KillWaves /Z $("Max"+ChanLoopStr+TrainInfoStr) endif if ((PTSelection[kAvg]&16)!=16) KillWaves /Z $("Avg"+ChanLoopStr+TrainInfoStr) endif if ((PTSelection[kBig]&16)!=16) KillWaves /Z $("Big"+ChanLoopStr+TrainInfoStr) endif if (UseBL==0) KillWaves /Z $("BL"+ChanLoopStr+TrainInfoStr) endif endfor endfor endif endif if((PTSelection[kAvgWave]&16)==16) //Average waves, divide by N and graph Display as ("AnalWaveAvg"+num2str(AnalNum)+ChanTitleStr+ChanLoopStr) DoWindow/C $("AnalWaveAvg"+num2str(AnalNum)+ChanNameStr+ChanLoopStr) //Give it a name in case we want to refer to it systematically later if ((PlotStyle==1)||(PlotStyle==4)||(PlotStyle==5)) //Non averaging modes WaveAvgWave/=(masterindex+1) //already should have right reference since there's only the one result wave per channel (+1 because it's 0 based) AppendToGraph /W=$("AnalWaveAvg"+num2str(AnalNum)+ChanNameStr+ChanLoopStr) $WaveAvgWaveName//6/17 else Temp1=0 if (PlotStyle==2) //by trial for (SweepLoop=SweepStart;SweepLoop<=SweepEnd;SweepLoop+=SweepIncrement) WaveAvgWaveName="WaveAvg"+ChanLoopStr+"_S"+num2str(SweepLoop)+"_"+num2str(AnalNum) WAVE WaveAvgWave=$WaveAvgWaveName WaveAvgWave/=NWave[Temp1] AppendToGraph /W=$("AnalWaveAvg"+num2str(AnalNum)+ChanNameStr+ChanLoopStr) $WaveAvgWaveName//6/17 Temp1+=1 endfor else //by sweep for (TrialLoop=TrialStart;TrialLoop<=TrialEnd;TrialLoop+=TrialIncrement) WaveAvgWaveName="WaveAvg"+ChanLoopStr+"_T"+num2str(TrialLoop)+"_"+num2str(AnalNum) WAVE WaveAvgWave=$WaveAvgWaveName WaveAvgWave/=NWave[Temp1] AppendToGraph /W=$("AnalWaveAvg"+num2str(AnalNum)+ChanNameStr+ChanLoopStr) $WaveAvgWaveName//6/17 Temp1+=1 endfor endif endif endif if ((PTSelection[kFit]&16)==16) //Fit if (NumFitTerms!=0) Redimension /N=(-1,NumFitTerms) FitWave//Get rid of unused columns else //all failed KillWaves FitWave endif endif if((PTSelection[kPeak]&16)==16) //Peak Discrim if (PlotStyle!=4) Display PeakWave vs $PeakTimeWaveName as ("Peak vs Time "+num2str(AnalNum)+ChanTitleStr+ChanLoopStr) endif else KillWaves $PeakTimeWaveName endif if((PTSelection[kWaveName]&16)!=16) //Wave Name KillWaves $WaveNameWaveName endif //kill unwanted result waves, display wanted waves //Create empty graph window if (PlotStyle!=4) //If it's group then we're going to do each one below so don't do it here Display as ("Anal"+num2str(AnalNum)+ChanTitleStr+ChanLoopStr+" T"+num2str(TrialStart)+"-"+num2str(TrialEnd)+" S"+num2str(SweepStart)+"-"+num2str(SweepEnd)) DoWindow/C $("Anal"+num2str(AnalNum)+ChanNameStr+ChanLoopStr) //Give it a name in case we want to refer to it systematically later endif //Plot the baseline if appropriate if (TrainNum<2) //if a train we deal with it with other train waves if (UseBL==1) if (GraphBL==1) //and supposed to be graphed if (PlotStyle==5) //vs. time AppendToGraph $BLWaveName vs $TimeWaveName elseif (PlotStyle==4) //Group Display as ("AnalBL"+num2str(AnalNum)+ChanTitleStr+ChanLoopStr+" T"+num2str(TrialStart)+"-"+num2str(TrialEnd)+" S"+num2str(SweepStart)+"-"+num2str(SweepEnd)) DoWindow/C $("AnalBL"+num2str(AnalNum)+ChanNameStr+ChanLoopStr) //Give it a name in case we want to refer to it systematically later Graph2DWave(BLWaveName,1,"AnalBL"+num2str(AnalNum)+ChanNameStr+ChanLoopStr) else AppendToGraph BLWave endif endif else killwaves BLWave endif endif ActionList="" KillWindow=1 for (ActionLoop=0;ActionLoop<=(kNumActions-1);ActionLoop+=1) ActionWaveName="" switch (ActionLoop) //Which wave to plot case kMax: //Max if (TrainNum<2)//These are already plotted if it's a train ActionWaveName=MaxWaveName endif break case kMin: //Min if (TrainNum<2) ActionWaveName=MinWaveName endif break case kBig: //Big if (TrainNum<2) ActionWaveName=BigWaveName endif break case kAvg: //Avg if (TrainNum<2) ActionWaveName=AvgWaveName endif break case kNum: //N ActionWaveName=NWaveName break case kExtWN: //Extract wave note ActionWaveName=EWNWaveName break case kPeak: //Peak ActionWaveName=PeakWaveName break case kPPR: //PPR ActionWaveName=PPRWaveName break endswitch if ((PTSelection[ActionLoop]&16)==16) //If it's checked plot it if (cmpstr(ActionWaveName,"")!=0)//if appropriate for that action type if (PlotStyle==5) //vs. time AppendToGraph $ActionWaveName vs $TimeWaveName elseif (PlotStyle==4) //Group Display as ("Anal"+ActionWaveName[0,2]+num2str(AnalNum)+ChanTitleStr+ChanLoopStr+" T"+num2str(TrialStart)+"-"+num2str(TrialEnd)+" S"+num2str(SweepStart)+"-"+num2str(SweepEnd)) DoWindow/C $("Anal"+ActionWaveName[0,2]+num2str(AnalNum)+ChanNameStr+ChanLoopStr) //Give it a name in case we want to refer to it systematically later Graph2DWave(ActionWaveName,1,("Anal"+ActionWaveName[0,2]+num2str(AnalNum)+ChanNameStr+ChanLoopStr)) else AppendToGraph $ActionWaveName endif KillWindow=0 endif //For history output: if (ActionLoop==kExtWN) ActionList+="("+ExWaveNote+")" endif if (ActionLoop==kFit) ActionList+=CurvefitType+" " endif if (ActionLoop==kMinVsFit) ActionList+="Anal "+Num2Str(MVFFitNum)+" used for " endif ActionList+=PlotType[ActionLoop]+", " else //if not checked kill it killwaves/Z $ActionWaveName endif endfor If (SmoothNumber>0) ActionList+="Smoothing="+num2str(SmoothNumber) else ActionList=ActionList[0,strlen(ActionList)-3]//remove final ", " endif if (KillWindow) DoWindow /K $("Anal"+num2str(AnalNum)+ChanNameStr+ChanLoopStr) elseif (PlotStyle!=4) ModifyGraph mode=4,marker=19,rgb=(0,0,0)//set all traces black, lines with solid circle markers endif if ((PTSelection[kConcat]&16)==16) Display $CatWaveName ModifyGraph mode=0,rgb=(0,0,0)//set all traces black, lines between points endif if ((PTSelection[kUserFunc]&16)==16) //Call UserFunc1 EndUserFunc1(AnalNum) endif endfor //ChanLoop //************* And you're done //Print record to history Print "Action on", SaveST, "to", SaveET, "pts, x=", Pnt2X(UseWave,SaveST), "to", Pnt2X(UseWave,SaveET) If (UseBL==1) Print "Baseline from", SaveBLS, "to", SaveBLE, "pts, x=", Pnt2X(UseWave,SaveBLS), "to", Pnt2X(UseWave,SaveBLE) endif if (TrainNum>1) Print "Train of",Num2Str(Trainnum),"at",Num2Str(TrainFreq),"Hz" endif if (DoOffset) Print "Delay Wave:",TrainOffsetName endif Print ActionList Print"------------------------------------------------------------------------------------------------------------------------------------------------------------" If (NewGuess) //Update guess for starting next time SaveTS=TrialEnd+1 SaveTE=TrialEnd*2-TrialStart+1 endif SaveAN=AnalNum+1 //Based on AnalNum in case it was fixed to avoid an overwrite End //of DoAnal Function AvgOrKill(TrainWave, AvgNotKill, N) String TrainWave Variable AvgNotKill, N if (AvgNotKill) WAVE TempWave=$TrainWave TempWave/=N else KillWaves/Z $TrainWave endif End //********************************************************************************************************************************** //********************************************************************************************************************************** //**********************************Sample user-added action functions************************************ Function InitUserFunc1(XRange, YRange, ChanLoop, AnalNum) VARIABLE XRange, YRange, ChanLoop, AnalNum //Put anything you want here to set up for your function //For example: //Print "Analysis #", AnalNum, " had UserFunc1 activated" End Function UserFunc1(CurrentWaveName, MasterIndex) VARIABLE MasterIndex STRING CurrentWaveName //Put anything you want here as your function string NewWaveName //For example: //Print "I could modify", CurrentWaveName, " if I wanted to" NewWaveName="WT"+CurrentWaveName[2,strlen(CurrentWaveName)-1] Duplicate $CurrentWaveName, $NewWaveName End Function EndUserFunc1(AnalNum) VARIABLE AnalNum //Put anything you want here to clean up or graph your results or write to the history //For example: //Print AnalNum, "finished" End //**********************************Sample user function for wave picking************************************ Function/S SelectedWavesOnTable() //Written for PAT //Returns the names of the waves selected on the top table, one at a time, and then an empty string when it's done //Return is done through global string UWNFReturnStr to avoid problem of non-local execution with execute command //No provision for the problem that SWOTList might be old if a previous set of executions was aborted--user must manually kill it if a run is interrupted SVAR UWNFReturnStr if (exists("SWOTList")==0) //First time through, set things up Variable/G WhereAreWe, HowMany String/G SWOTList GetSelection table,$WinName(0,2), 3 if (V_flag==1) HowMany=V_endCol-V_startCol+1 WhereAreWe=-1 SWOTList=S_selection Print "Waves processed:" else print "No waves selected or no table found" UWNFReturnStr="" Return "" endif else NVAR WhereAreWe, HowMany SVAR SWOTList endif WhereAreWe+=1 if (WhereAreWe==HowMany) //Done KillVariables WhereAreWe, HowMany KillStrings SWOTList UWNFReturnStr="" Return "" else UWNFReturnStr=StringFromList(WhereAreWe, SWOTList) UWNFReturnStr=UWNFReturnStr[0,strsearch(UWNFReturnStr,".",0)-1] // remove .d, .x etc. print UWNFReturnStr return "" endif end //****************************************************************************************************************************** //****************************************************************************************************************************** //****************************************************************************************************************************** //Wave Browser for hierarchically named waves //****************************************************************************************************************************** Function HierarchicalWaveBrowser() if (wintype("Wavebrowser")==0) //If window doesn't exist STRING/G BrowsedWaveName VARIABLE/G scaletrk=1 STRING TempWaveName PROMPT TempWaveName, " Starting Wave", popup, WAVEList ("*",";", "") DoPrompt "Hierarchical Wave Browser", TempWaveName BrowsedWaveName=TempWaveName Display /W=(1,1,950,400) $BrowsedWaveName DoWindow /C Wavebrowser ModifyGraph rgb($BrowsedWaveName)=(0,0,0) CheckBox trkscale size={40,20}, pos={620,5}, noproc, title="Keep scale", value=1, variable=scaletrk Button lastsweep size={40,20}, pos={415,1}, proc=pluswave, title="-Sweep" Button nextsweep size={40,20}, pos={455,1}, proc=pluswave, title="+Sweep" If (cmpstr(sDataSource,"PULSE")!=0) Button lasttrial size={40,20}, pos={335,1}, proc=pluswave, title="-Trial" Button nexttrial size={40,20}, pos={375,1}, proc=pluswave, title="+Trial" If (cmpstr(sDataSource,"AXON")==0) Button togglechannel size={40,20}, pos={495,1}, proc=pluswave, title="Tog Ch." PopupMenu jumpwave mode=0, pos={550,1}, proc=jumpwv, title="Jump", value=WAVEList ("*_Ch*",";", "") else Button lastrec size={40,20}, pos={255,1}, proc=pluswave, title="-Rec" Button nextrec size={40,20}, pos={295,1}, proc=pluswave, title="+Rec" PopupMenu jumpwave mode=0, pos={500,1}, proc=jumpwv, title="Jump", value=WAVEList ("*_*_*_*",";", "") endif else PopupMenu jumpwave mode=0, pos={500,1}, proc=jumpwv, title="Jump", value=WAVEList ("*",";", "") endif ShowInfo else //Bring to front DoWindow /F Wavebrowser endif END Function pluswave(callingbutton) //replace wave according to which button was pressed //For wave names with the following form: //HEKA: X_Rec_Trial_Sweep[_Suffix] each any number of digits //AXON: wDDDDDD_TTTT_ChN_Sweep[_Suffix] Sweep and Suffix and number of digits, Date, Trial, and Channel fixed length //PULSE: wNNNNN[_Suffix] where N and Suffix are any length, N is a number STRING callingbutton SVAR BrowsedWaveName NVAR scaletrk=scaletrk STRING numstr, oldwavename=BrowsedWaveName Variable Rec1, Rec2, Sweep1, Sweep2, Trial1, Trial2 //first and last positions of the numeric portions of the wave name //HEKA first Rec1=StrSearch(BrowsedWaveName, "_",0)+1 Rec2=StrSearch(BrowsedWaveName, "_",Rec1)-1 Trial1=Rec2+2 Trial2=StrSearch(BrowsedWaveName, "_",Trial1)-1 Sweep1=Trial2+2 Sweep2=StrSearch(BrowsedWaveName, "_",Sweep1)-1 if (Sweep2==-2) //didn't find a suffix _ Sweep2=strlen(BrowsedWaveName)-1 endif If (cmpstr(sDataSource,"AXON")==0) Trial1=Rec1 Trial2=Trial1+3 endif If (cmpstr(sDataSource,"PULSE")==0) Sweep1=1 Sweep2=StrSearch(BrowsedWaveName, "_",0)-1 if (Sweep2==-2) Sweep2=strlen(BrowsedWaveName)-1 endif endif //The main deal, figure out new BrowsedWaveName: strswitch(callingbutton) case "lastsweep": BrowsedWaveName=BrowsedWaveName[0,Sweep1-1]+num2str(str2num(BrowsedWaveName[Sweep1,Sweep2])-1)+BrowsedWaveName[Sweep2+1,strlen(BrowsedWaveName)-1] break case "nextsweep": BrowsedWaveName=BrowsedWaveName[0,Sweep1-1]+num2str(str2num(BrowsedWaveName[Sweep1,Sweep2])+1)+BrowsedWaveName[Sweep2+1,strlen(BrowsedWaveName)-1] break case "lasttrial": If (cmpstr(sDataSource,"AXON")==0) numstr="0000"+num2str(str2num(BrowsedWaveName[Trial1,Trial2])-1) numstr=numstr[strlen(numstr)-4,strlen(numstr)] BrowsedWaveName=BrowsedWaveName[0,Trial1-1]+numstr+BrowsedWaveName[Trial2+1,strlen(BrowsedWaveName)-1] else BrowsedWaveName=BrowsedWaveName[0,Trial1-1]+num2str(str2num(BrowsedWaveName[Trial1,Trial2])-1)+BrowsedWaveName[Trial2+1,strlen(BrowsedWaveName)-1] endif break case "nexttrial": If (cmpstr(sDataSource,"AXON")==0) numstr="0000"+num2str(str2num(BrowsedWaveName[Trial1,Trial2])+1) numstr=numstr[strlen(numstr)-4,strlen(numstr)] BrowsedWaveName=BrowsedWaveName[0,Trial1-1]+numstr+BrowsedWaveName[Trial2+1,strlen(BrowsedWaveName)-1] else BrowsedWaveName=BrowsedWaveName[0,Trial1-1]+num2str(str2num(BrowsedWaveName[Trial1,Trial2])+1)+BrowsedWaveName[Trial2+1,strlen(BrowsedWaveName)-1] endif break case "lastrec": BrowsedWaveName=BrowsedWaveName[0,Rec1-1]+num2str(str2num(BrowsedWaveName[Rec1,Rec2])-1)+BrowsedWaveName[Rec2+2,strlen(BrowsedWaveName)-1] break case "nextrec": BrowsedWaveName=BrowsedWaveName[0,Rec1-1]+num2str(str2num(BrowsedWaveName[Rec1,Rec2])+1)+BrowsedWaveName[Rec2+2,strlen(BrowsedWaveName)-1] break case "togglechannel": if (cmpstr(BrowsedWaveName[Sweep1-2],"0")==0) BrowsedWaveName[Sweep1-2,Sweep1-2]="1" else BrowsedWaveName[Sweep1-2,Sweep1-2]="0" endif endswitch if (waveexists($BrowsedWaveName)==1) if (scaletrk==1) AppendToGraph $BrowsedWaveName RemoveFromGraph $oldwavename else RemoveFromGraph $oldwavename AppendToGraph $BrowsedWaveName endif ModifyGraph rgb($BrowsedWaveName)=(0,0,0) ReplaceCursors(BrowsedWaveName) else //no such wave if (cmpstr(callingbutton[4,8],"trial")==0) //possibly we can find another one in the trial requested BrowsedWaveName=StringFromList(0, wavelist(BrowsedWaveName[0,Trial2+1]+"*"+BrowsedWaveName[Sweep2+1,strlen(BrowsedWaveName)-1],";","")) //just take the first one you find if (waveexists($BrowsedWaveName)==0) //if we failed then just go back to the old one BrowsedWaveName=oldwavename else if (scaletrk==1) AppendToGraph $BrowsedWaveName RemoveFromGraph $oldwavename else RemoveFromGraph $oldwavename AppendToGraph $BrowsedWaveName endif ModifyGraph rgb($BrowsedWaveName)=(0,0,0) ReplaceCursors(BrowsedWaveName) endif else BrowsedWaveName=oldwavename endif beep //requested wave not found, even if we found one let the user know we did something funny endif END Function jumpwv(callingpopup, popNum, popStr) // Jump to arbitrary wave selected by popup STRING callingpopup, popStr VARIABLE popNum SVAR BrowsedWaveName NVAR scaletrk // Replace wave if (scaletrk==1) AppendToGraph $popStr RemoveFromGraph $BrowsedWaveName BrowsedWaveName=popStr else //These different ways of replacing the wave result in either keeping or not keeping the scaling RemoveFromGraph $BrowsedWaveName BrowsedWaveName=popStr AppendToGraph $BrowsedWaveName endif ModifyGraph rgb=(0,0,0) ReplaceCursors(BrowsedWaveName) END Function ReplaceCursors(Temp) String Temp if (exists("CursA")==2) NVAR CursA, CursB Cursor /P A $Temp CursA Cursor /P B $Temp CursB endif END