-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCORDUROY_ANALYSIS_metalib.ipf
executable file
·511 lines (387 loc) · 15.4 KB
/
CORDUROY_ANALYSIS_metalib.ipf
1
#pragma rtGlobals=1 // Use modern global access method./////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// CORDUROY_ANALYSIS_metalib// Contains the code for "meta"-analysis functions//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_BOXCAR_execute(wave_name,number)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name,number String thisDF = GetDataFolder(1) if( strlen(wave_name)==0 ) Abort "You must declare an analysis wave in order to normalize." endif if( stringmatch(number,"1") ) SVAR AnDF = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 else SVAR AnDF = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2 endif// Define the size of the boxcar window or grab the default window size NVAR boxcarwin = root:Analysis:Panels:MetaAnalysisPanel:boxcarwin if( !(NVAR_exists(boxcarwin)) ) variable boxcarwinL=0, makedefault=0 prompt boxcarwinL, "Number of samples in window:" prompt makedefault, "Make this the default setting?", popup "No;Yes" DoPrompt "What is the width of the boxcar window?", boxcarwinL, makedefault if( V_Flag ) return -1 endif if(makedefault==1) SetDataFolder root:Analysis:Panels:MetaAnalysisPanel variable/g boxcarwin = boxcarwinL print "Default window size set to: "+num2str(boxcarwin) SetDataFolder thisDF else boxcarwin = boxcarwinL endif endif// Need to find out the wave name and dimensions to create the output wave SetDataFolder AnDF WAVE local = $wave_name Make/O/N=( (numpnts(local) / boxcarwin) ) temp_output Make/O/N=( (numpnts(local) / boxcarwin) ) temp_output2// Create the boxcar average by stepping through the wave variable wavelength = numpnts(local), index=0, count=0 for(index=0;index<wavelength;index+=boxcarwin) WaveStats /Q /R=[index,(index+(boxcarwin-1))]/Z local temp_output[count] = V_avg temp_output2[count] = V_sdev count+=1 endfor// Get the original scaling and set an appropriate scaling for the output wave// Rename the output wave MoveWave temp_output, root:MetaAnalysis: MoveWave temp_output2, root:MetaAnalysis: SetDataFolder root:MetaAnalysis string temp = wave_name+"_B", temp2 = wave_name+"_Be" MoveWave temp_output, $temp MoveWave temp_output2, $temp2 CORD_MetaAddSuffix("_B") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_NORMALIZE_execute(wave_name1,wave_name2)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name1, wave_name2 String thisDF = GetDataFolder(1) // USE THE DIMSIZE COMMAND TO GET MULTIDIMENSIONAL WAVE INFO if( (strlen(wave_name1)==0) || (strlen(wave_name2)==0) ) Abort "You must declare two analysis waves in order to normalize." endif SVAR AnDF1 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 SVAR AnDF2 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2 // Get waves to analyze into local environment WAVE local=$wave_name1 WAVE local2=$wave_name2 // Set the break between baseline and conditioned wave NVAR indgap = root:Analysis:Panels:MetaAnalysisPanel:indgap if( !(NVAR_exists(indgap)) ) variable indgapL, makedefault, howmanydimensions prompt indgapL, "Number of samples" prompt makedefault, "Make this the deault setting?", popup "Yes;No" prompt howmanydimensions, "Do you want to normalize all columns, or only primary?", popup "Primary;2;3;4;5" DoPrompt "Enter the length of the induction protocol", indgapL, makedefault, howmanydimensions if( V_Flag ) variable/G cancelled = 1 abort endif if(makedefault==1) SetDataFolder root:Analysis:Panels:MetaAnalysisPanel variable/g indgap = indgapL SetDataFolder thisDF endif endif// Duplicate the input waves and use as the output waves string dupl_wave1, dupl_wave2 dupl_wave1 = "root:MetaAnalysis:"+wave_name1 dupl_wave2 = "root:MetaAnalysis:"+wave_name2 SetDataFolder AnDF1 Duplicate/O/R=[0,*][0,0] $wave_name1, $dupl_wave1 SetDataFolder AnDF2 Duplicate/O/R=[0,*][0,0] $wave_name2, $dupl_wave2 SetDataFolder root:MetaAnalysis Make/O/N=(indgap) induction Wave local = $wave_name1 if( !(WaveExists(local)) ) Abort "Cannot find the baseline wave" endif Wave local2 = $wave_name2 // Normalize values to the basline mean WaveStats/Q local print V_avg local = local / V_avg local2 = local2 / V_avg print numpnts(local) print numpnts(local2) string output = wave_name1+"_N" Make/O/N=( numpnts(local)+numpnts(induction) + numpnts(local2) -1 ) w1 w1[0,numpnts(local)-1] = local[x] w1[numpnts(local),numpnts(local)+numpnts(induction)-1] = induction[x-numpnts(local)] w1[numpnts(local)+numpnts(induction),] = local2[x-(numpnts(local)+numpnts(induction))] KillWaves/Z $output MoveWave w1, $output //CORD_DisplayOutput(output,"normalize") //SetAxis left 0.1,8 //DoUpdate CORD_MetaAddSuffix("_N") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_SPIKETIMES_execute(wave_name1,wave_name2)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name1, wave_name2 String thisDF = GetDataFolder(1)Abort "Not yet implemented..." if( (strlen(wave_name1)==0) || (strlen(wave_name2)==0) ) Abort "You must declare two analysis waves in order to normalize." endif SVAR AnDF1 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 SVAR AnDF2 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2// CORD_MetaAddSuffix("_ISI")// CORD_MetaAddSuffix("_PSTH") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_SPIKEKIN_execute(wave_name1,wave_name2)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name1, wave_name2 String thisDF = GetDataFolder(1)Abort "Not yet implemented..." if( (strlen(wave_name1)==0) || (strlen(wave_name2)==0) ) Abort "You must declare two analysis waves in order to normalize." endif SVAR AnDF1 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 SVAR AnDF2 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2 SetDataFolder $AnDF1 CORD_MetaAddSuffix("_ISI") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_SPIKEISI_execute(wave_name1,wave_name2)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name1, wave_name2 String thisDF = GetDataFolder(1) if( (strlen(wave_name1)==0) || (strlen(wave_name2)==0) ) Abort "You must declare two analysis waves in order to normalize." endif SVAR AnDF1 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 SVAR AnDF2 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2 SetDataFolder $AnDF1// Get waves to analyze into local environment WAVE local=$wave_name1 WAVE local2=$wave_name2 variable TotalSpikes = numpnts(local) variable index=0, CurrTrig=0,LastTrig=0,windex=0,CurrWave=0 print TotalSpikes WaveStats/Q local2 print V_max Make/O/N=(1,V_max) tmp Make/O/N=(0) tmp_mean Make/O/N=(0) tmp3 for(index=1;index<TotalSpikes;index+=1) if(local2[index]==local2[index-1]) CurrWave = local2[index] CurrTrig = local[index] LastTrig = local[index-1] tmp[windex][CurrWave] = {CurrTrig-LastTrig} tmp3[windex] = {CurrTrig-LastTrig} windex+=1 else tmp_mean[CurrWave] = {1/mean(tmp3)} Make/O/N=(0) tmp3 windex=0 endif endfor tmp_mean[CurrWave] = {1/mean(tmp3)} string tmp2 = RemoveFromList("r_x", wave_name1,"_") tmp2+="ISI" KillWaves /Z $tmp2 MoveWave tmp $tmp2 tmp2+="m" KillWaves /Z $tmp2 MoveWave tmp_mean $tmp2 CORD_MetaAddSuffix("_ISI") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_SPIKEWIN_execute(wave_name1,wave_name2)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name1, wave_name2 String thisDF = GetDataFolder(1)Abort "Not yet implemented..." if( (strlen(wave_name1)==0) || (strlen(wave_name2)==0) ) Abort "You must declare two analysis waves in order to normalize." endif SVAR AnDF1 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 SVAR AnDF2 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2 SetDataFolder $AnDF1 //// Get waves to analyze into local environment// WAVE local=$wave_name1// WAVE local2=$wave_name2//// variable TotalSpikes = numpnts(local)// variable index=0, CurrTrig=0,BeginL=0,EndR=0// // string WaveA="", WaveB="", tmpA="", tmpB=""// // for(index=0;index<TotalSpikes;index+=1)// // WaveA = "RecordA"+num2str(local2[index])// WaveB = "RecordB"+num2str(local2[index])// WAVE WaveAW = $WaveA// WAVE WaveBW = $WaveB// // CurrTrig = local[index]// BeginL = CurrTrig - WindowLeft// EndR = CurrTrig + WindowRight// // tmpA = "WinA"+num2str(local2[index])+num2str(index)// tmpB = "WinB"+num2str(local2[index])+num2str(index)//// Duplicate /O/R=(BeginL,EndR) WaveAW, $tmpA// SetScale /I x, (-1*WindowLeft), WindowRight, "s" $tmpA// Duplicate /O/R=(BeginL,EndR) WaveBW, $tmpB// SetScale /I x, (-1*WindowLeft), WindowRight, "s" $tmpB// // endfor// CORD_MetaAddSuffix("_ISI")// CORD_MetaAddSuffix("_PSTH") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_CLUSTERS_execute(wave_name1,wave_name2)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name1, wave_name2 String thisDF = GetDataFolder(1) if( (strlen(wave_name1)==0) || (strlen(wave_name2)==0) ) Abort "You must declare two analysis waves in order to normalize." endif SVAR AnDF1 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 SVAR AnDF2 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2 SetDataFolder $AnDF1// Get waves to analyze into local environment WAVE local=$wave_name1 WAVE local2=$wave_name2 Duplicate/O local, ClusterMarkers ClusterMarkers=NaN variable TotalSpikes = numpnts(local) variable index=0, CurrWave=0,LastTrig=0,t0=0,tm1=0,tm2=0,thisISI=0,prevISI=0,ClusterOn=0,ClusterAcc=0,CurrSpike=0,SpPerClusterCI=0 variable intra = 0.25, inter=0.5 Make/O/N=0 tmp Make/O/N=0 SpPerClusterCount for(index=1;index<TotalSpikes;index+=1) if(local2[index]==local2[index-1]) CurrWave = local2[index] CurrSpike +=1 t0 = local[index] tm1 = local[index-1] tm2 = local[index-2] thisISI = t0-tm1 prevISI = tm1-tm2 if(ClusterOn==1) if(thisISI<intra) ClusterAcc+=1 ClusterMarkers[index]=-30 SpPerClusterCount[SpPerClusterCI]+=1 else ClusterOn=0 SpPerClusterCI+=1 endif else if(thisISI<intra &&prevISI>inter) ClusterOn = 1 SpPerClusterCount[SpPerClusterCI]={2} ClusterAcc+=2 ClusterMarkers[index]=-30 ClusterMarkers[index-1]=-30 elseif(index==1&&prevISI<intra) ClusterOn = 1 SpPerClusterCount[SpPerClusterCI]={2} ClusterAcc+=2 ClusterMarkers[index]=-30 ClusterMarkers[index-1]=-30 endif endif else CurrSpike+=1 tmp[CurrWave] = {ClusterAcc/CurrSpike} print CurrSpike ClusterAcc=0 ClusterOn=0 CurrSpike=0 endif endfor CurrSpike+=1 tmp[CurrWave] = {ClusterAcc/CurrSpike} WaveStats/Q SpPerClusterCount tmp[CurrWave+1] = {V_Avg} string tmp2 = RemoveFromList("r_x", wave_name1,"_") tmp2+="CL" KillWaves /Z $tmp2 MoveWave tmp $tmp2 CORD_MetaAddSuffix("_CL") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_PETH_execute(wave_name1,wave_name2)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name1, wave_name2 String thisDF = GetDataFolder(1)Abort "Not yet implemented..." if( (strlen(wave_name1)==0) || (strlen(wave_name2)==0) ) Abort "You must declare two analysis waves in order to normalize." endif SVAR AnDF1 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 SVAR AnDF2 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2 SetDataFolder $AnDF1 CORD_MetaAddSuffix("_ISI") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_PSTH_execute(wave_name1,wave_name2)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string wave_name1, wave_name2 String thisDF = GetDataFolder(1)Abort "Not yet implemented..." if( (strlen(wave_name1)==0) || (strlen(wave_name2)==0) ) Abort "You must declare two analysis waves in order to normalize." endif SVAR AnDF1 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF1 SVAR AnDF2 = root:Analysis:Panels:MetaAnalysisPanel:CurrAnDF2 SetDataFolder $AnDF1 CORD_MetaAddSuffix("_ISI") SetDataFolder thisDFEnd///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_MetaNameOuptut(passedname,analysistype)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string passedname, analysistypeEnd//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////Function CORD_DisplayOutput(datawave,datatype)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// string datawave string datatype strswitch(datatype) case "timecourse": Display/K=1 $datawave as "Time course data : "+datawave DoWindow/C TempDataWindow break case "wcio": break case "fio": break case "normalize": Display/K=1 $datawave as "Normalized Time Course : "+datawave ModifyGraph mode($datawave)=3,marker($datawave)=8,opaque($datawave)=1 Make/O/N=(numpnts($datawave)) basedisplay=1 AppendToGraph basedisplay ModifyGraph lstyle(basedisplay)=1,rgb(basedisplay)=(0,0,0) break endswitchEnd