-
Notifications
You must be signed in to change notification settings - Fork 1
/
CORDUROY_ANALYSIS_library.ipf
executable file
·1359 lines (1129 loc) · 46.4 KB
/
CORDUROY_ANALYSIS_library.ipf
1
#pragma rtGlobals=2 // Use modern global access method./////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// CORDUROY_ANALYSIS_library// Contains the code for the analysis functions//// Written by Joshua Dudman, Columbia University// Development begun January 2005////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_CreateFunctionList()/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// SetDataFolder root:Analysis:Panels:AnalysisPanel string/G AnalysisFunctionList = "None;STATS;EVENTPEAK;SLOPE;KINETICS;SPIKES;WCSPK;XSPIKES;DUPLICATE;EMFREQ;EVENTS"End//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// RULES FOR THE CLASS OF ANALYSIS FUNCTIONS// 1. Take two variables as input representing the left and right point of an ROI// 2. Are handed a wave to analyze (i.e. do not control the indexing of serial analysis).// 3. Take a variable representing the index (in a series of sequentially analyzed waves) of the handed wave// 4. Create a folder for the analysis function which stores associated variables// 5. Each function has a prefix used to identify output waves// 6. Output is a multidimensional wave of the form "Wavename_PREFIX [num_vars;num_waves]"// 7. Follows the template strucure shown below/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_TEMPLATE_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// This is a template function that can be followed for users who are interested in creating their own plug-in analysis routines string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = "" // String needs to be converted to a wave reference WAVE local = TraceNameToWaveRef("",wave_name) // MOVE to analysis directory? // Duplicate the wave within the roi to facilitate analysis// ANALYSIS variable VAR Make/N=1 ANALYSIS_WAVE//END ANALYSIS// Store the respective calculations in waves for subsequent analysis string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string newName = baseName + ""// If the analysis creates a single variables per ROI, something like this would work: variable numanalyses if(index==0) Make/N=(numwaves,numanalyses) $newName endif string ex_string ex_string = newName+"[index,1]="+num2str(VAR) Execute ex_string// If the analysis creates a wave of values for each analyzed wave and each ROI, use something like this: string newName2 = baseName+"_"+num2str(index)+"WAVE_SUFFIX" Duplicate /O ANALYSIS_WAVE, $newName2 SetDataFolder thisDF End // TemplateFunc///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_EVENTPEAK_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1)// String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local = TraceNameToWaveRef("",wave_name) else WAVE local = $wave_name endif // Create some local variables string prefix = "", thisWave="" Variable maxflag=1 variable left0, right0 string basenameL = "baseL"+num2str(roi_num), basenameR = "baseR"+num2str(roi_num) // Guess baseline and use a panel to ask if correct if(index==0) CORD_DisplayCheckCursorPanel((roi_tstart - 0.006),(roi_tstart - 0.001)) variable/G $basenameL, $basenameR NVAR baseL = $basenameL NVAR baseR = $basenameR NVAR cursorcheckL = root:Analysis:CheckCursorDialogue:CheckCursorLeft NVAR cursorcheckR = root:Analysis:CheckCursorDialogue:CheckCursorRight baseL = cursorcheckL baseR = cursorcheckR endif NVAR baseL = $basenameL NVAR baseR = $basenameR // Initialize all the global variables to be created by the function NewDataFolder/O/S PeakAnalysisGlobals Variable/G baseline=0 Variable/G meanpeak=0 Variable/G netpeak=0 Variable/G peaktime=0 Variable/G lefthalf=0 Variable/G righthalf=0 Variable/G left20=0 Variable/G right80=0 Variable/G slope2080=0 Variable/G totalarea=0 SetDataFolder thisDF // Subtract baseline offset to get net peak baseline = mean(local,baseL,baseR)// Find the peak of the passed wave if(maxflag==0) FindPeak/B=(50)/P/Q/R=(roi_tstart,roi_tstop) $wave_name peaktime = V_PeakLoc else WaveStats/Q/R=(roi_tstart,roi_tstop) local // Decide if it is a negative or positive peak to look for... if(abs(V_max-baseline)>abs(V_min-baseline)) peaktime = V_maxloc else peaktime = V_minloc endif endif meanpeak = mean(local,(peaktime-0.0001),(peaktime+0.0001)) netpeak = meanpeak - baseline// Get halfwidth FindLevel/Q/R=(peaktime,-1) $wave_name, (baseline + (netpeak/2)) lefthalf = V_LevelX FindLevel/Q/R=(peaktime) $wave_name, (baseline + (netpeak/2)) righthalf = V_LevelX// Get 20-80 rise time FindLevel/Q/R=(peaktime,-1) $wave_name, (baseline+(netpeak*0.2)) left20 = V_LevelX FindLevel/Q/R=(peaktime,-1) $wave_name, (baseline+(netpeak*0.8)) right80 = V_LevelX// Get 20-80 slope if((right80-left20) < 0.0001) // 0.1 ms defines the shortest possible 20 80 rise time (prevents error is neg) slope2080 = 0 else CurveFit/N/Q/W=0 line $wave_name (left20,right80) slope2080 = K1 endif// Get area (from 10% to 10%) FindLevel/Q/R=(peaktime,-1) $wave_name, (baseline+(netpeak*0.1)) left0 = V_LevelX FindLevel/Q/R=(peaktime) $wave_name, (baseline+(netpeak*0.1)) if(V_flag==0) right0 = V_LevelX else right0 = roi_tstop endif variable basebox = baseline * (right0 - left0) variable tmparea = area($wave_name,left0,right0) totalarea = tmparea - basebox // otherwise have to baseline traces to get area// Store the respective calculations in waves for subsequent analysis string ChanName = "" if( stringmatch(wave_name,"Record*") ) sscanf wave_name, "Record%1s", ChanName else ChanName = "X" endif // need a check on total string length string folderName if(strlen(GetDataFolder(0))>11) sscanf GetDataFolder(0), "%15s", folderName else folderName = GetDataFolder(0) endif string baseName = folderName + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string peakName = baseName + "peak" string kinName = baseName + "kinetics" string assignstring WAVE outputWave = $peakName if(!WaveExists(outputWave)) Make/N=(numwaves,5)/O $peakName Make/N=(numwaves,5)/O $kinName endif WAVE output1 = $peakName WAVE output2 = $kinName output1[index][0]=netpeak output1[index][1]=peaktime output1[index][2]=meanpeak output1[index][3]=totalarea output1[index][4]=left0 output2[index][0]=righthalf - lefthalf output2[index][1]=slope2080 output2[index][2]=right80-left20 output2[index][3]=totalarea output2[index][4]=left20 if(index==(numwaves-1)) KillDataFolder :PeakAnalysisGlobals variable numoutput=4 Make/T/N=(numoutput)/O EVENTPEAK_outputlabels_peak = {"Net depolarization (V)","Time of peak(ms)","Peak potential (V)","Area (mV.ms)","Onset"} Make/T/N=(numoutput)/O EVENTPEAK_outputlabels_kinetics = {"Halfwidth (ms)","20-80 Rise Slope (V/ms) ","20-80 Rise Time (V/ms) ","Area ","Onset"} if(roi_num==1) print EVENTPEAK_outputlabels_peak print EVENTPEAK_outputlabels_kinetics endif endif if(index==0) // confirm that the various analysis values are correctly calculated DoWindow/K OnLineDisp Make/O/N=2 areaPnts areaPnts[0] = left0 areaPnts[1] = right0 Make/O/N=2 areaLev = baseline+(netpeak*0.1) Make/O/N=2 risePnts risePnts[0] = left20 risePnts[1] = right80 Make/O/N=2 riseLev riseLev[0] = local(left20) riseLev[1] = local(right80) Display/W=(0,0,400,400)/K=1 local DoWindow/C OnLineDisp AppendToGraph areaLev vs areaPnts AppendToGraph riseLev vs risePnts ModifyGraph live=1, mode(areaLev)=4,marker(areaLev)=43,msize(areaLev)=6,mode(riseLev)=3,marker(riseLev)=43,msize(riseLev)=6,rgb(areaLev)=(0,43690,65535),rgb(riseLev)=(0,0,0) thisWave = wave_name elseif(index<(numwaves-1)) RemoveFromGraph /W=OnLineDisp $thisWave RemoveFromGraph /W=OnLineDisp areaLev RemoveFromGraph /W=OnLineDisp riseLev areaPnts[0] = left0 areaPnts[1] = right0 areaLev[] = baseline+(netpeak*0.1) risePnts[0] = left20 risePnts[1] = right80 riseLev[0] = local(left20) riseLev[1] = local(right80) AppendToGraph /W=OnLineDisp local AppendToGraph areaLev vs areaPnts AppendToGraph riseLev vs risePnts ModifyGraph live=1, mode(areaLev)=3,marker(areaLev)=43,msize(areaLev)=6,mode(riseLev)=3,marker(riseLev)=43,msize(riseLev)=6,mode(areaLev)=4,rgb(areaLev)=(0,43690,65535),rgb(riseLev)=(0,0,0) thisWave = wave_name else DoWindow/K OnLineDisp endif DoUpdate /W=OnLineDisp SetDataFolder thisDFEnd // EVENTPEAK ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_KINETICS_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = "" // Create all the global variables to be created by the function NewDataFolder/O/S PeakAnalysisGlobals Variable/G tau=0 Variable/G RbError=0 SetDataFolder thisDF// String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local = TraceNameToWaveRef("",wave_name) else WAVE local = $wave_name endif// ANALYSIS variable VAR CurveFit/N/Q/W=0 exp, $wave_name (roi_tstart,roi_tstop) WAVE W_coef RbError = W_coef[0] tau = 1 / W_coef[2]// END ANALYSIS// STORE ANALYSIS RESULTS string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string ex_string string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string stepkinName = baseName + "stepkin" if(index==0) Make/O/N=(numwaves,2) $stepkinName endif ex_string = stepkinName+"["+num2str(index)+"][0]="+num2str(tau) Execute ex_string ex_string = stepkinName+"["+num2str(index)+"][1]="+num2str(RbError) Execute ex_string SetDataFolder thisDF End // KINETICS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_SLOPE_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = "" // String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local = TraceNameToWaveRef("",wave_name) else WAVE local = $wave_name endif // ANALYSIS variable/G slope CurveFit/N/Q/W=0 line $wave_name (roi_tstart,roi_tstop) WAVE W_coef slope = W_coef[1]// END ANALYSIS// STORE ANALYSIS RESULTS string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string ex_string string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string newName = baseName + "fslope" if(index==0)// KillWaves $newName Make/O/N=(numwaves,1) $newName endif ex_string = newName+"["+num2str(index)+"][0]="+num2str(slope) Execute ex_string SetDataFolder thisDF End // SLOPE//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_STATS_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = "" // String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local = TraceNameToWaveRef("",wave_name) else WAVE local = $wave_name endif // ANALYSIS variable/G average, minval, maxval, stdev WaveStats /M=2 /Q/R=(roi_tstart,roi_tstop) local average = V_avg minval = V_min maxval = V_max stdev = V_sdev// END ANALYSIS// STORE ANALYSIS RESULTS string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string ex_string string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string newName = baseName + "stats" if(index==0) Make/O/N=(numwaves,4) $newName endif WAVE local2 = $newName local2[index][0]= average local2[index][1]= minval local2[index][2]= maxval local2[index][3]= stdev SetDataFolder thisDF End // STATS//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_SPIKES_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = ""// String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local1 = TraceNameToWaveRef("",wave_name) else WAVE local1 = $wave_name endif // Get the time scaling of the wave variable dt = DimDelta(local1, 0) variable raster_bin = 0.001 // make a 1ms bin for the display of raster plots Duplicate /O/R=(roi_tstart,roi_tstop) local1, local Make /D/O/N=(numpnts(local1)) raster = 0 Make /D/O/N=(numpnts(local1)/(raster_bin/dt)) raster_disp = 0 variable numspikes = 0 WaveStats/Q local if(V_max>-0.02)// ANALYSIS// Ultimately this should be updated to allow parameterization Differentiate local WaveStats/Q local variable ThreshMaxAccel = V_max*0.25 // loop through the entire wave finding ThreshMaxAccel crossings variable count=0 //, spindex=0 variable/G spindex=0 FindLevels/Q /EDGE=1 /M=0.002 /R=(0,) local, ThreshMaxAccel numspikes = V_LevelsFound Duplicate/O W_FindLevels, times Duplicate/O W_FindLevels, indices indices[] = index //END ANALYSIS endif// STORE ANALYSIS RESULTS string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string newName1 = baseName+"nspikes" string newName2 = baseName+"delta" string newName3 = baseName+num2str(index)+"_t" string newName4 = baseName+"r_x" string newName5 = baseName+"r_y" if(index==0) Make/O/N=(numwaves,1) $newName1 = numspikes Make/O/N=(numpnts(raster),numwaves) $newName2 SetScale /P x, 0, dt, "s", $newName2 Make/D/O/N=(0) $newName4 Make/D/O/N=(0) $newName5 else Wave local3 = $newName1 local3[index] = numspikes endif string exstr = newName2+"[*]["+num2str(index)+"] = raster[p]" Execute exstr string exstr2 = "" variable cindex=0, pntcount=0 Wave local4 = $newName4 Wave local5 = $newName5 if(numspikes>0) Concatenate "times;", local4 Concatenate "indices;", local5 endif KillWaves raster, times, raster_disp if(index==numwaves-1) // For raster display DoWindow/K RasterPlot Display/K=1/W=(0,0,500,300) local5 vs local4 as "RasterPlot" DoWindow/C RasterPlot ModifyGraph mode=3,marker=10,mrkThick=2,rgb=(0,0,0) ModifyGraph noLabel(left)=2,axRGB(left)=(65535,65535,65535) SetAxis /W=RasterPlot bottom, 0, (numpnts(local1)*dt) SetAxis /W=RasterPlot left, 0, numwaves endif SetDataFolder thisDF End // SPIKES//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_WCSPK_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = ""// String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local1 = TraceNameToWaveRef("",wave_name) else WAVE local1 = $wave_name endif // Get the time scaling of the wave variable dt = DimDelta(local1, 0) variable raster_bin = 0.001 // make a 1ms bin for the display of raster plots Duplicate /O/R=(roi_tstart,roi_tstop) local1, local Make /D/O/N=(numpnts(local1)) raster = 0 Make /D/O/N=(numpnts(local1)/(raster_bin/dt)) raster_disp = 0 variable numspikes = 0 WaveStats/Q local if(V_max>-0.02)// ANALYSIS// Ultimately this should be updated to allow parameterization Differentiate local WaveStats/Q local variable ThreshMaxAccel = V_max*0.25 // loop through the entire wave finding ThreshMaxAccel crossings variable count=0 //, spindex=0 variable/G spindex=0 FindLevels/Q /EDGE=1 /M=0.002 /R=(0,) local, ThreshMaxAccel numspikes = V_LevelsFound Duplicate/O W_FindLevels, times Duplicate/O W_FindLevels, indices indices[] = index //END ANALYSIS endif// STORE ANALYSIS RESULTS string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string newName1 = baseName+"nspikes" string newName2 = baseName+"delta" string newName3 = baseName+num2str(index)+"_t" string newName4 = baseName+"r_x" string newName5 = baseName+"r_y" if(index==0) Make/O/N=(numwaves,1) $newName1 = numspikes Make/O/N=(numpnts(raster),numwaves) $newName2 SetScale /P x, 0, dt, "s", $newName2 Make/D/O/N=(0) $newName4 Make/D/O/N=(0) $newName5 else Wave local3 = $newName1 local3[index] = numspikes endif string exstr = newName2+"[*]["+num2str(index)+"] = raster[p]" Execute exstr string exstr2 = "" variable cindex=0, pntcount=0 Wave local4 = $newName4 Wave local5 = $newName5 if(numspikes>0) Concatenate "times;", local4 Concatenate "indices;", local5 endif KillWaves raster, times, raster_disp if(index==numwaves-1) // For raster display DoWindow/K RasterPlot Display/K=1/W=(0,0,500,300) local5 vs local4 as "RasterPlot" DoWindow/C RasterPlot ModifyGraph mode=3,marker=10,mrkThick=2,rgb=(0,0,0) ModifyGraph noLabel(left)=2,axRGB(left)=(65535,65535,65535) SetAxis /W=RasterPlot bottom, 0, (numpnts(local1)*dt) SetAxis /W=RasterPlot left, 0, numwaves endif SetDataFolder thisDF End // WCSPK//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_XSPIKES_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = ""// String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local1 = TraceNameToWaveRef("",wave_name) else WAVE local1 = $wave_name endif // Get the time scaling of the wave variable dt = DimDelta(local1, 0) variable raster_bin = 0.001 // make a 1ms bin for the display of raster plots Duplicate /O/R=(roi_tstart,roi_tstop) local1, local Make /I/O/N=(0) times Make /I/O/N=(1) tmp Make /D/O/N=(numpnts(local1)) raster = 0 Make /D/O/N=(numpnts(local1)/(raster_bin/dt)) raster_disp = 0 variable numspikes = 0 WaveStats/Q local // ANALYSIS Differentiate local WaveStats/Q local variable ThreshMaxAccel = ((V_min-V_avg)/2)+V_avg print ThreshMaxAccel // loop through the entire wave finding ThreshMaxAccel crossings variable count=0, spindex=0 FindLevels/Q /EDGE=2 /M=0.003 /P /R=[0,numpnts(local)] local, ThreshMaxAccel numspikes = V_LevelsFound Duplicate/O W_FindLevels, raster WAVE pnt_levels = W_FindLevels Duplicate/O W_FindLevels, time_levels time_levels *= dt// END ANALYSIS// STORE ANALYSIS RESULTS string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string newName1 = baseName+"nspikes" string newName2 = baseName+"delta" string newName3 = baseName+num2str(index)+"_t" string newName4 = baseName+"r_x" string newName5 = baseName+"r_y" if(index==0) Make/O/N=(numwaves,1) $newName1 = numspikes Make/O/N=(numpnts(local)/(0.001/dt),numwaves) $newName2 Make/D/O/N=(0) $newName4 Make/D/O/N=(0) $newName5 else Wave local3 = $newName1 local3[index] = numspikes endif string exstr="" variable jindex=0, curr_pnt = 0 WAVE local_delta = $newName2 local_delta = 0 for(jindex=0;jindex<numpnts(pnt_levels);jindex+=1) curr_pnt = round(time_levels[jindex]*1000) local_delta[curr_pnt][index] = 1 endfor SetScale /P x, x, 1e-3 , "s", local_delta string exstr2 = "" variable cindex=0, pntcount=0 Wave local4 = $newName4 Wave local5 = $newName5 if(numspikes>0) for(cindex=0;cindex<numspikes;cindex+=1) pntcount = numpnts(local4) exstr2 = newName4+"["+num2str(pntcount)+"] = {"+num2str(time_levels[cindex])+"}" Execute exstr2 exstr2 = newName5+"["+num2str(pntcount)+"] = {"+num2str(index)+"}" Execute exstr2 endfor endif KillWaves raster, times, raster_disp if(index==numwaves-1) // For raster display DoWindow/K RasterPlot Display/K=1/W=(0,0,500,300) local5 vs local4 as "RasterPlot" DoWindow/C RasterPlot ModifyGraph mode=3,marker=10,mrkThick=2,rgb=(0,0,0) ModifyGraph noLabel(left)=2,axRGB(left)=(65535,65535,65535) SetAxis /W=RasterPlot bottom, 0, (numpnts(local1)*dt) SetAxis /W=RasterPlot left, 0, numwaves endif SetDataFolder thisDF End // XSPIKES//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_DUPLICATE_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = "" // String needs to be converted to a wave reference WAVE local = TraceNameToWaveRef("",wave_name) // Store the respective calculations in waves for subsequent analysis string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" string newName = baseName + "DPL"// ANALYSIS Duplicate /O/R=(roi_tstart,roi_tstop) $wave_name, $newName variable OldDelta = DimDelta($wave_name, 0) SetScale /P x, 0, OldDelta, $newName//END ANALYSIS SetDataFolder thisDF End // duplicate//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_EMFREQ_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = "" // String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local1 = TraceNameToWaveRef("",wave_name) else WAVE local1 = $wave_name endif // ANALYSIS Duplicate /O/R=(roi_tstart,roi_tstop) local1, local variable/G average WaveStats /M=2 /Q/R=(roi_tstart,roi_tstop) local average = V_avg local = local - average variable padd_init=numpnts(local), pad_final FFT /Z /MAGS /DEST=W_FFT local // END ANALYSIS// STORE ANALYSIS RESULTS string ChanName = "A" if( stringmatch(wave_name,"RecordB*") ) ChanName = "B" elseif( !(stringmatch(wave_name,"Record*")) ) ChanName = "X" endif string name_string string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_" name_string = baseName+"fft"+num2str(index) Rename W_FFT, $name_string SetDataFolder thisDFEnd // EMFREQ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// USE THESE FUNCTIONS IN YOUR EXECUTABLE FILES IN ORDER TO PROMPT FOR SETTINGS OR DISPLAY SOME OUTPUT///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_SETTINGS_execute(value1,name1,value2,name2,value3,name3,value4,name4,analysisfunction)///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// The purpose of this function will be to create a default panel that allows the user to make settings that are used by the current analysis function// Each analysis function will have a dedicated folder that holds default settings. variable value1 string name1 variable value2 string name2 variable value3 string name3 variable value4 string name4 string analysisfunction String thisDF = GetDataFolder(1) NewDataFolder/O/S root:Analysis string/G CurrentFunc = analysisfunction string tmp_name = "root:Analysis:"+analysisfunction NewDataFolder/O/S $tmp_name variable/G parameter1=value1 variable/G parameter2=value2 variable/G parameter3=value3 variable/G parameter4=value4 NVAR default_set=default_set if(!NVAR_exists(default_set)) variable/G default_set=0 endif DoWindow/F ParameterPanel if (V_Flag!=0) DoWindow/K ParameterPanel endif string ex_str = "CORD_ParameterPanel(\""+name1+"\",\""+name2+"\",\""+name3+"\",\""+name4+"\",\""+analysisfunction+"\")" print ex_str Execute ex_str Execute "ModifyPanel cbRGB = (32125,33410,39321)" SetDataFolder thisDFEnd//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Window CORD_ParameterPanel(name1,name2,name3,name4,analysisfunction) : Panel/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string name1,name2,name3,name4,analysisfunction PauseUpdate; Silent 1 NewPanel/W=(40,500,350,700)/K=1 as "ParameterPanel" DoWindow/C ParameterPanel SetVariable var1 size={250,20}, disable=0, font="Verdana", fsize=10, pos= {20,40}, value=$("root:Analysis:"+analysisfunction+":parameter1"), title=name1 SetVariable var2 size={250,20}, disable=0, font="Verdana", fsize=10, pos= {20,70}, value=$("root:Analysis:"+analysisfunction+":parameter2"), title=name2 SetVariable var3 size={250,20}, disable=0, font="Verdana", fsize=10, pos={20,100}, value=$("root:Analysis:"+analysisfunction+":parameter3"), title=name3 SetVariable var4 size={250,20}, disable=0, font="Verdana", fsize=10, pos={20,130}, value=$("root:Analysis:"+analysisfunction+":parameter4"), title=name4 PopupMenu def1 size={250,20}, bodywidth=100, disable=0, font="Verdana", fsize=10, mode=1, pos={20,160},proc=CORD_SetDefaultParameterPanel, title="Make setting default? ", value="No;Yes"End///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_SetDefaultParameterPanel(cntrlName,popNum,popStr) : PopupMenuControl/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// String cntrlName Variable popNum // which item is currently selected (1-based) String popStr // contents of current popup item as string SVAR CurrentFunc = root:Analysis:CurrentFunc SetDataFolder $("root:Analysis:"+CurrentFunc) NVAR default_set = default_set if( stringmatch(popStr, "Yes") ) default_set = 1 endif End///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_PANELDISP_execute(value1,name1,value2,name2,value3,name3,value4,name4,analysisfunction)///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// The purpose of this function will be to create a default panel that allows the user to make settings that are used by the current analysis function// Each analysis function will have a dedicated folder that holds default settings. variable value1 string name1 variable value2 string name2 variable value3 string name3 variable value4 string name4 string analysisfunction String thisDF = GetDataFolder(1) string tmp_name = "root:Analysis:"+analysisfunction NewDataFolder/O/S root:Analysis variable/G output1=value1 variable/G output2=value2 variable/G output3=value3 variable/G output4=value4 DoWindow/F OutputPanel if (V_Flag!=0) DoWindow/K OutputPanel endif string ex_str = "CORD_OutputPanel(\""+name1+"\",\""+name2+"\",\""+name3+"\",\""+name4+"\",\""+analysisfunction+"\")" Execute ex_str Execute "ModifyPanel cbRGB = (32125,33410,39321)" SetDataFolder thisDF End//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Window CORD_OutputPanel(name1,name2,name3,name4,analysisfunction) : Panel/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string name1,name2,name3,name4,analysisfunction PauseUpdate; Silent 1 NewPanel/W=(40,500,350,700)/K=1 as "OutputPanel" DoWindow/C OutputPanel ValDisplay/Z var1 size={250,20}, barmisc={0, 350}, disable=0, font="Verdana", frame=0, fsize=10, pos= {20,40}, value=root:Analysis:output1, title=name1 ValDisplay/Z var2 size={250,20}, barmisc={0, 350}, disable=0, font="Verdana", frame=0, fsize=10, pos= {20,70}, value=root:Analysis:output2, title=name2 ValDisplay/Z var3 size={250,20}, barmisc={0, 350}, disable=0, font="Verdana", frame=0, fsize=10, pos={20,100}, value=root:Analysis:output3, title=name3 ValDisplay/Z var4 size={250,20}, barmisc={0, 350}, disable=0, font="Verdana", frame=0, fsize=10, pos={20,130}, value=root:Analysis:output4, title=name4End/// IN DEVELOPMENT BELOW HERE ---------------///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_EVENTS_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name variable roi_tstart,roi_tstop,index,numwaves,roi_num String thisDF = GetDataFolder(1) string prefix = "" // String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel if( stringmatch(wave_name,"RecordA*") ) WAVE local = TraceNameToWaveRef("",wave_name) else WAVE local = $wave_name endif // ANALYSIS// Duplicate the wave region Duplicate /O/R=(roi_tstart,roi_tstop) local, MT_Heuristic// FInd the template WAVE template = template if(!WaveExists(template)) Abort "Please create a wave named 'template' before re-running..." endif// Run the Template Matching algorithm if(RunningWindows()) Execute /Z "MatchTemplate /C Template, MT_Heuristic"// else// MatchTemplate /C Template, MT_Heuristic endif// Threshold the results Duplicate /O MT_Heuristic, MT_Threshold variable detectthresh=25 // If you want to change threshold to that suggested by Clements And Bekkers (i.e. 4) do so here MT_Threshold = (MT_Threshold(x)>detectthresh) ? MT_Threshold(x) : 0 // Find the event times variable HowLong = numpnts(MT_Threshold) variable jindex=0, count=0 string wavebase = "" do if(MT_Threshold[jindex]>0) FindPeak/B=4/M=(detectthresh)/Q/R=(pnt2x(MT_Threshold, jindex), ) MT_Threshold if((V_PeakLoc+pnt2x(local,numpnts(template)))<roi_tstop) wavebase = wave_name+"_e"+num2str(count) Duplicate /O/R=(V_PeakLoc,(V_PeakLoc+pnt2x(local,numpnts(template)))) local, $wavebase SetScale/P x 0,5e-05,"s", $wavebase endif count+=1 jindex+=numpnts(template) else jindex+=1 endif while (jindex<HowLong)// END ANALYSIS// STORE ANALYSIS RESULTS// string ChanName = "A"// if( stringmatch(wave_name,"RecordB*") )// ChanName = "B"// elseif( !(stringmatch(wave_name,"Record*")) )// ChanName = "X"// endif//// if(index==0)//// endif SetDataFolder thisDF End // EVENTS///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_EVENTPEAKB_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// This function is essentially a batch version of eventpeak that uses the first 10ms of the trace as a baseline to avoid the cursor dialogue//// string wave_name// variable roi_tstart,roi_tstop,index,numwaves,roi_num// // String thisDF = GetDataFolder(1)////// String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel// if( stringmatch(wave_name,"RecordA*") )// WAVE local = TraceNameToWaveRef("",wave_name) // else// WAVE local = $wave_name// endif// //// Create some local variables// string prefix = ""// variable maxflag=1// variable left0, right0// string basenameL = "baseL"+num2str(roi_num), basenameR = "baseR"+num2str(roi_num)// //// Initialize all the global variables to be created by the function// NewDataFolder/O/S PeakAnalysisGlobals// Variable/G baseline=0// Variable/G meanpeak=0// Variable/G netpeak=0// Variable/G peaktime=0// Variable/G lefthalf=0// Variable/G righthalf=0// Variable/G left20=0// Variable/G right80=0// Variable/G slope2080=0// Variable/G totalarea=0// SetDataFolder thisDF// //// Assume first 10 ms of trace is the baseline to use// baseline = mean(local,0.0001,0.0101)// //// Find the peak of the passed wave// if(maxflag==0)// FindPeak/B=(50)/P/Q/R=(roi_tstart,roi_tstop) $wave_name// peaktime = round(V_PeakLoc)// else// WaveStats/Q/R=(roi_tstart,roi_tstop) local// peaktime = V_maxloc// endif////// Subtract baseline offset to get net peak// meanpeak = mean(local,(peaktime-0.001),(peaktime+0.001))// print peaktime// print meanpeak// print baseline// netpeak = meanpeak - baseline//// Get halfwidth// FindLevel/Q/R=(peaktime,0) $wave_name, (baseline + (netpeak/2))// lefthalf = V_LevelX// FindLevel/Q/R=(peaktime) $wave_name, (baseline + (netpeak/2))// righthalf = V_LevelX//// Get 20-80 rise time// FindLevel/Q/R=(peaktime,0) $wave_name, (baseline+(netpeak*0.2))// left20 = V_LevelX// FindLevel/Q/R=(peaktime,0) $wave_name, (baseline+(netpeak*0.8))// right80 = V_LevelX//// Get 20-80 slope// if((right80-left20) < 0.0005) // 0.5 ms defines about the shortest possible 20 80 rise time observed (prevents error if neg)// slope2080 = 0// else// CurveFit/N/Q/W=0 line $wave_name (left20,right80)// slope2080 = K1// endif//// Get area (from 10% to 10%)// FindLevel/Q/R=(peaktime,0) $wave_name, (baseline+(netpeak*0.1))// left0 = V_LevelX// FindLevel/Q/R=(peaktime) $wave_name, (baseline+(netpeak*0.1))// right0 = V_LevelX// variable basebox = baseline * (right0 - left0)// variable tmparea = area($wave_name,left0,right0)// totalarea = tmparea - basebox // otherwise have to baseline traces to get area////// Store the respective calculations in waves for subsequent analysis// string ChanName = "A"// if( stringmatch(wave_name,"RecordB*") )// ChanName = "B"// elseif( !(stringmatch(wave_name,"Record*")) )// ChanName = "X"// endif// string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_"// string peakName = baseName + "peak"// string kinName = baseName + "kinetics" // string assignstring// // if(index==0)// Make/N=(numwaves,4)/O $peakName// Make/N=(numwaves,4)/O $kinName// endif// // assignstring = peakName+"["+num2str(index)+"][0]="+num2str(netpeak)// Execute assignstring// assignstring = peakName+"["+num2str(index)+"][1]="+num2str(peaktime)// Execute assignstring// assignstring = peakName+"["+num2str(index)+"][2]="+num2str(meanpeak)// Execute assignstring// assignstring = peakName+"["+num2str(index)+"][3]="+num2str(baseline)// Execute assignstring// // assignstring = kinName+"["+num2str(index)+"][0]="+num2str((righthalf - lefthalf))// Execute assignstring// assignstring = kinName+"["+num2str(index)+"][1]="+num2str(slope2080)// Execute assignstring// assignstring = kinName+"["+num2str(index)+"][2]="+num2str((right80-left20))// Execute assignstring// assignstring = kinName+"["+num2str(index)+"][3]="+num2str(totalarea)// Execute assignstring//// if(index==(numwaves-1))// KillDataFolder :PeakAnalysisGlobals// variable numoutput=4// Make/T/N=(numoutput)/O EVENTPEAK_outputlabels_peak = {"Net depolarization (V)","Time of peak(ms)","Peak potential (V)","Baseline potential (V)"}// Make/T/N=(numoutput)/O EVENTPEAK_outputlabels_kinetics = {"Halfwidth (ms)","20-80 Rise Slope (V/ms) ","20-80 Rise Time (V/ms) ","Area "}//// if(roi_num==1)// print EVENTPEAK_outputlabels_peak// print EVENTPEAK_outputlabels_kinetics// endif// endif// // SetDataFolder thisDF//End // EVENTPEAKB////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_EVENTPEAKD_execute(wave_name,roi_tstart,roi_tstop,index,numwaves,roi_num)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// This function is essentially a batch version of eventpeak that uses the first 10ms of the trace as a baseline to avoid the cursor dialogue//// string wave_name// variable roi_tstart,roi_tstop,index,numwaves,roi_num// // String thisDF = GetDataFolder(1)////// String needs to be converted to a wave reference, but is either a trace reference or a name reference depending on channel// if( stringmatch(wave_name,"RecordA*") )// WAVE local = TraceNameToWaveRef("",wave_name) // else// WAVE local = $wave_name// endif// //// Create some local variables// string prefix = ""// variable maxflag=1// variable left0, right0// string basenameL = "baseL"+num2str(roi_num), basenameR = "baseR"+num2str(roi_num)// //// Initialize all the global variables to be created by the function// NewDataFolder/O/S PeakAnalysisGlobals// Variable/G baseline=0// Variable/G meanpeak=0// Variable/G netpeak=0// Variable/G peaktime=0// Variable/G righthalf=0// Variable/G right20=0// Variable/G right80=0// Variable/G slope2080=0// Variable/G totalarea=0// SetDataFolder thisDF// //// Assume first 10 ms of trace is the baseline to use// baseline = mean(local,0.0001,0.0101)// //// Find the peak of the passed wave// if(maxflag==0)// FindPeak/B=(50)/P/Q/R=(roi_tstart,roi_tstop) $wave_name// peaktime = round(V_PeakLoc)// else// WaveStats/Q/R=(roi_tstart,roi_tstop) local// peaktime = V_maxloc// endif////// Subtract baseline offset to get net peak// meanpeak = mean(local,(peaktime-0.001),(peaktime+0.001))// print peaktime// print meanpeak// print baseline// netpeak = meanpeak - baseline//// Get halfdecay// FindLevel/Q/R=(peaktime) $wave_name, (baseline + (netpeak/2))// righthalf = V_LevelX//// Get 20-80 decay// FindLevel/Q/R=(peaktime) $wave_name, (baseline+(netpeak*0.2))// right20 = V_LevelX// FindLevel/Q/R=(peaktime) $wave_name, (baseline+(netpeak*0.8))// right80 = V_LevelX//// Get 20-80 slope// if((right20-right80) < 0.0005) // 0.5 ms defines about the shortest possible 20 80 rise time observed (prevents error if neg)// slope2080 = 0// else// CurveFit/N/Q/W=0 line $wave_name (right80,right20)// slope2080 = K1// endif//// Get area (from 80% to 20%)// variable basebox = baseline * (right20 - right80)// variable tmparea = area($wave_name,right80,right20)// totalarea = tmparea - basebox // otherwise have to baseline traces to get area////// Store the respective calculations in waves for subsequent analysis// string ChanName = "A"// if( stringmatch(wave_name,"RecordB*") )// ChanName = "B"// elseif( !(stringmatch(wave_name,"Record*")) )// ChanName = "X"// endif// string baseName = GetDataFolder(0) + "_roi" + num2str(roi_num) +"_"+ChanName+"_"// string peakName = baseName + "peak"// string kinName = baseName + "kinetics" // string assignstring// // if(index==0)// Make/N=(numwaves,4)/O $peakName// Make/N=(numwaves,4)/O $kinName// endif// // assignstring = peakName+"["+num2str(index)+"][0]="+num2str(netpeak)// Execute assignstring// assignstring = peakName+"["+num2str(index)+"][1]="+num2str(peaktime)// Execute assignstring// assignstring = peakName+"["+num2str(index)+"][2]="+num2str(meanpeak)// Execute assignstring// assignstring = peakName+"["+num2str(index)+"][3]="+num2str(baseline)// Execute assignstring// // assignstring = kinName+"["+num2str(index)+"][0]="+num2str((righthalf - peaktime))// Execute assignstring// assignstring = kinName+"["+num2str(index)+"][1]="+num2str(slope2080)// Execute assignstring// assignstring = kinName+"["+num2str(index)+"][2]="+num2str((right20-right80))// Execute assignstring// assignstring = kinName+"["+num2str(index)+"][3]="+num2str(totalarea)// Execute assignstring//// if(index==(numwaves-1))// KillDataFolder :PeakAnalysisGlobals// variable numoutput=4// Make/T/N=(numoutput)/O EVENTPEAK_outputlabels_peak = {"Net depolarization (V)","Time of peak(ms)","Peak potential (V)","Baseline potential (V)"}// Make/T/N=(numoutput)/O EVENTPEAK_outputlabels_kinetics = {"Half decay time (s)","20-80 Decay Slope (mV/s) ","20-80 Decay Time (mV/s) ","Area "}//// if(roi_num==1)// print EVENTPEAK_outputlabels_peak// print EVENTPEAK_outputlabels_kinetics// endif// endif// // SetDataFolder thisDF//End // EVENTPEAKD//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////