#pragma rtGlobals=1 // ____________________________________________ // // Amperometric Spike Analysis // Version 8.15 06/12/2005 // // Eugene Mosharov, PhD // Columbia University, Dpt. of Neurology // em706@columbia.edu or johnmosh@yahoo.com // ____________________________________________ // To start: // 1. Hide or Minimize this window // 2. Choose * Prepare for Quanta Analysis * from Macros menu Menu "Macros" "-" "* Prepare for Quanta Analysis! *",Prepare_for_Trace_Analysis() End Macro Prepare_for_Trace_Analysis() String Existing_windows=WinList("*", ";","WIN:83") // A list of all windows, panels and notebooks String One_win=StringFromList(0, Existing_windows) If(strlen(One_win)) DoAlert 1,"Delete existing Windows?" If(V_Flag==1) Variable i=0 Do One_win=StringFromList(i, Existing_windows) If(strlen(One_win)==0) break endif DoWindow/K $One_win i+=1 while(1) endif endif if (DataFolderExists("root:Quanta")) SetDataFolder $"root:Quanta" else NewDataFolder/S root:Quanta endif // Default values of global variables if (CheckName("Bkg_noise_I", 3)==0) Variable/G Bkg_noise_I=0 // Standard Deviation of the noise on non-differentiated trace. Used during foot detection. endif if (CheckName("Bkg_noise_dI", 3)==0) Variable/G Bkg_noise_dI=0 // Standard Deviation of the noise on differentiated trace. Used for spike detection endif if (CheckName("Bkg_noise_Start", 3)==0) Variable/G Bkg_noise_Start=0 // Beginning of the segment used to calculate SD of the noise. endif if (CheckName("Bkg_noise_End", 3)==0) Variable/G Bkg_noise_End=0 // End of the segment used to calculate SD of the noise. endif if (CheckName("Detection_Mult", 3)==0) Variable/G Detection_Mult=5 // Theshold for spike detection endif if (CheckName("Detection_Foot_Mult", 3)==0) Variable/G Detection_Foot_Mult=2 // Theshold for foot detection endif if (CheckName("Smoothing_Factor", 3)==0) Variable/G Smoothing_Factor=600 // Cutoff of the filter used on non-differentiated trace. Can be changed from the main window. endif if (CheckName("Smoothing_Factor_diff1", 3)==0) Variable/G Smoothing_Factor_diff1=300 // Cutoff of Gaussian filter used on differentiated trace. Can be changed from Filters/Scales panel. endif if (CheckName("Smoothing_Factor_Add", 3)==0) Variable/G Smoothing_Factor_Add=150 // Cutoff of additional Gaussian filter used on non-differentiated trace. Can be changed from Filters/Scales panel. endif if (CheckName("Smooth_Derivative", 3)==0) Variable/G Smooth_Derivative=1 // Allows filtering of differentiated trace. endif if (CheckName("Smooth_more", 3)==0) Variable/G Smooth_more=0 // Allows additional filtering of non-differentiated trace. endif if (CheckName("Overall_Filter", 3)==0) Variable/G Overall_Filter=0 // Overall additive filtering (except additional) applied to non-differentiated trace. endif if (CheckName("Spike_Min_Imax", 3)==0) Variable/G Spike_Min_Imax=0 // I(max) cutoff endif if (CheckName("Spike_Min_Imax_Last", 3)==0) Variable/G Spike_Min_Imax_Last=3 // Last used I(max) cutoff endif if (CheckName("Spike_Max_T05", 3)==0) Variable/G Spike_Max_T05=0 // t(1/2) cutoff endif if (CheckName("Spike_Max_T05_Last", 3)==0) Variable/G Spike_Max_T05_Last=1 // Last used t(1/2) cutoff endif if (CheckName("Spike_Max_Trise", 3)==0) Variable/G Spike_Max_Trise=0 // t(rise) cutoff endif if (CheckName("Spike_Max_Trise_Last", 3)==0) Variable/G Spike_Max_Trise_Last=2 // Last used t(rise) cutoff endif if (CheckName("Foot_Min_W", 3)==0) Variable/G Foot_Min_W=0 // T(foot) cutoff endif if (CheckName("Foot_Min_W_Last", 3)==0) Variable/G Foot_Min_W_Last=2 // Last used T(foot) cutoff endif if (CheckName("SSFoot_Do", 3)==0) Variable/G SSFoot_Do=0 // Delete feet without steady states endif if (CheckName("Native_Foot_Del", 3)==0) Variable/G Native_Foot_Del=0 // Delete feet longer that 0.33*t(rise 50-90%) endif if (CheckName("Foot_Min_H", 3)==0) Variable/G Foot_Min_H=0 // I(foot) cutoff endif if (CheckName("Foot_Min_H_Last", 3)==0) Variable/G Foot_Min_H_Last=1 // Last used I(foot) cutoff endif if (CheckName("Peak_ID", 3)==0) Variable/G Peak_ID=0 // The ID of the currently active spike endif if (CheckName("Total_peaks_number", 3)==0) Variable/G Total_peaks_number=0 // Total number of detected spikes endif if (CheckName("Rise_Low_Prc", 3)==0) Variable/G Rise_Low_Prc=25 // The lower point (% of Imax) on spike rising phase used to calculate r(rise). endif if (CheckName("Rise_Hi_Prc", 3)==0) Variable/G Rise_Hi_Prc=75 // The upper point (% of Imax) on spike rising phase used to calculate r(rise). endif if (CheckName("Fit_method", 4)==0) String/G Fit_method="DblExp" // Function used to fit the falling phase of the spikes endif if (CheckName("Fall_ChiRatio_Cutoff", 3)==0) variable/G Fall_ChiRatio_Cutoff=2 // Chi^2(double exp) to Chi^2(single exp) ratio threshold for the DblExp fit. endif if (CheckName("Gain", 3)==0) variable/G Gain=1 // Trace Y scaling gain. endif if (CheckName("Gain_Temp", 3)==0) variable/G Gain_Temp=1 // Trace Y scaling gain. Additional variable used to determine if the gain has been changed. endif if (CheckName("Zoom_On", 4)==0) String/G Zoom_On="Off" // Zooms in and out of the currently active spike in the main window. endif if (CheckName("Show_Legend", 3)==0) variable/G Show_Legend=1 // Enables the legend on top of the main window. endif if (CheckName("T_Start_orig", 3)==0) Variable/G T_Start_orig=0 // X value of the first datapoint in the original trace. endif if (CheckName("T_Delta_orig", 3)==0) variable/G T_Delta_orig=0.1 // Sampling interval (microS) of the original trace. endif if (CheckName("T_Start", 3)==0) Variable/G T_Start=0 // X value of the first datapoint in the working trace copy. endif if (CheckName("T_End", 3)==0) Variable/G T_End=0 // X value of the last datapoint in the working trace copy. endif if (CheckName("T_Delta", 3)==0) variable/G T_Delta=0.1 // Sampling interval (microS) of the working trace copy. endif if (CheckName("X_min", 3)==0) Variable/G X_min=0 // X value of the first datapoint displayed in the main window. endif if (CheckName("X_max", 3)==0) Variable/G X_max=0 // X value of the last datapoint displayed in the main window. endif if (CheckName("Y_min", 3)==0) Variable/G Y_min=0 // Minimal Y value displayed in the main window. endif if (CheckName("Y_max", 3)==0) Variable/G Y_max=0 // Maximal Y value displayed in the main window. endif if (CheckName("Population_Center", 4)==0) String/G Population_Center="Median" // Calculate a Mean or a Median of spike parameters during statistical analysis endif if (CheckName("Norm_point", 4)==0) String/G Norm_point="Rise" // Uses spike Tmax ('Max') or the midpoint of the linear segment of the rising phase ('Rise') during spike averaging endif if (CheckName("Baseline_Drift", 3)==0) Variable/G Baseline_Drift=50 // Maximal allowed baseline drift. If higher, the spike is deleted. endif if (CheckName("Overlap_Prc", 3)==0) Variable/G Overlap_Prc=50 // Maximal allowed degree of spike overlap. If higher, both spikes are deleted. endif if (CheckName("Overlaps", 4)==0) String/G Overlaps="Separate" // The remaining overlaps are either 'Ignored', 'Separated' or 'Split'. endif if (CheckName("File_list", 4)==0) String/G File_list="" // The list of recently opened recordings endif if (CheckName("Loaded_file_path", 4)==0) String/G Loaded_file_path="" // The name of the last opened recording endif if (CheckName("Fall_Tau_Extrap", 3)==0) Variable/G Fall_Tau_Extrap=0 // Exponential Tau used for falling phase extrapolasion of overlapping spikes. endif // The list of parameters that will be displayed (not calculated) by default. To set new default settings change "0" to "1". Variable/G Show_Time=1 // T_Max Variable/G Show_Base=0 // Peak_Base Variable/G Show_Width=1 // Peak_t05 Variable/G Show_H=1 // Peak_Imax Variable/G Show_Q=0 // Peak_Q Variable/G Show_Molec=1 // Peak_Molec Variable/G Show_Rise_t=1 // Rise_time Variable/G Show_Rise_r=1 // Rise_slope Variable/G Show_Fall_t=1 // Fall_time Variable/G Show_Fall_r=1 // Fall_slope Variable/G Show_Ft_H=1 // Foot_I Variable/G Show_Ft_width=1 // Foot_W Variable/G Show_Ft_Q=0 // Foot_Q Variable/G Show_Ft_molec=1 // Foot_Molec String/G Values_to_show String/G Stats_names // Build new windows if (CheckName("Working_trace_copy", 1)==0) Make/O/N=1 Working_trace_copy,Orig_trace_copy,diff1 Make/O/N=1 Zoomed_peak, Fall_phase,Rise_phase Make/O/N=0 Avg_peak endif if (CheckName("Peak_Num", 1)==0) Change_waves("Make",0) endif if (CheckName("File_Q", 6)==0) File_Q() else Dowindow/F File_Q endif Variable Resolution=ScreenResolution String scrn=StringByKey("SCREEN1", IgorInfo(0)) Variable Scrn_width=str2num(StringFromList(3, scrn,",")) Variable Scrn_hight=str2num(StringFromList(4, scrn,",")) Variable/G Scrn_width_Points=Scrn_width*0.74609375*96/Resolution Variable/G Scrn_hight_Points= Scrn_hight*0.74609375*96/Resolution Variable Zoom_Win_width=220*96/Resolution Variable Table_Win_hight=180*96/Resolution if (CheckName("Main_window", 6)==0) execute "Main_window()" SetVariable ID,limits={1,(Total_peaks_number),1} PauseUpdate; Silent 1 Movewindow 0,80,Scrn_width_Points-Zoom_Win_width,Scrn_hight_Points-Table_Win_hight AutoPositionWindow/E/M=1/R=File_Q Main_window Dowindow/F File_Q Show_Extras("Zoom_off") MoveWindow /C Scrn_width_Points-Zoom_Win_width,320*96/Resolution,Scrn_width_Points,Scrn_hight_Points-75*96/Resolution endif if (CheckName("Peak_stats_Table1", 6)==0) Change_Table ("ctrlName",1) Dowindow/F Peak_stats_Table1 AutoPositionWindow/E/M=0/R=Main_window Peak_stats_Table1 endif Endmacro //___________________________________ //_______Spike Detection and Analysis______ //___________________________________ Function Bkg_noise_Set(ctrlName) : ButtonControl String ctrlname SetDataFolder $"root:Quanta" NVAR Bkg_noise_Start=Bkg_noise_Start NVAR Bkg_noise_End=Bkg_noise_End Wave Working_trace_copy=Working_trace_copy If(numpnts(Working_trace_copy)<2) abort "No trace loaded or the wave is too short." endif Bkg_noise_Start=min(xcsr(A), xcsr(B)) Bkg_noise_End=max(xcsr(A), xcsr(B)) Bkg_noise_Calc() End Function Bkg_noise_Calc() SetDataFolder $"root:Quanta" Wave Working_trace_copy=Working_trace_copy NVAR Bkg_noise_I=Bkg_noise_I NVAR Bkg_noise_dI=Bkg_noise_dI NVAR Bkg_noise_Start=Bkg_noise_Start NVAR Bkg_noise_End=Bkg_noise_End NVAR Smoothing_Factor_diff1=Smoothing_Factor_diff1 NVAR Smooth_more=Smooth_more NVAR Smooth_Derivative=Smooth_Derivative NVAR Smoothing_Factor_Add=Smoothing_Factor_Add If (Bkg_noise_Start==Bkg_noise_End) String Note="Background level of noise is not set!\r" Note+="Use cursors A and B to select an area of your trace\r" Note+="that does not have any spikes and press 'Bkg' button" abort Note endif wavestats/Q/R = (Bkg_noise_Start, Bkg_noise_End ) Working_trace_copy Bkg_noise_I=V_sdev Duplicate/O/R=(Bkg_noise_Start,Bkg_noise_End) Working_trace_copy, Bkg_diff1 Variable Binomial_coeff If (Smooth_more==1) Binomial_coeff=Gaussian_to_Binomial_Calc(Smoothing_Factor_Add) Smooth Binomial_coeff, Bkg_diff1 endif Differentiate Bkg_diff1 If (Smooth_Derivative==1) Binomial_coeff=Gaussian_to_Binomial_Calc(Smoothing_Factor_diff1) Smooth Binomial_coeff, Bkg_diff1 endif wavestats/Q Bkg_diff1 Bkg_noise_dI=V_sdev Killwaves/Z Bkg_diff1 GroupBox Bkg_HiLt, win=Main_window,disable=1 End Function Peak_finder(ctrlName) : ButtonControl String ctrlname SetDataFolder $"root:Quanta" Wave Working_trace_copy=Working_trace_copy NVAR Detection_Mult=Detection_Mult NVAR Total_peaks_number=Total_peaks_number NVAR Peak_ID=Peak_ID NVAR Bkg_noise_dI=Bkg_noise_dI NVAR Bkg_noise_Start=Bkg_noise_Start NVAR Bkg_noise_End=Bkg_noise_End NVAR Smoothing_Factor=Smoothing_Factor NVAR Smoothing_Factor_diff1=Smoothing_Factor_diff1 NVAR Smooth_Derivative=Smooth_Derivative NVAR Smooth_more=Smooth_more NVAR Smoothing_Factor_Add=Smoothing_Factor_Add NVAR Baseline_Drift=Baseline_Drift Wave Peak_Num=Peak_Num Wave T_Max=T_Max Wave Peak_Imax=Peak_Imax Wave Peak_Half_H2=Peak_Half_H2 Wave Peak_Q=Peak_Q Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Working_trace_copy=Working_trace_copy If(numpnts(Working_trace_copy)<2) abort "No trace loaded or the wave is too short." endif If(Total_peaks_number) DoAlert 1, "All existing spikes will be deleted! \rPress 'Yes' to continue or 'No' to cancel." If (V_Flag==1) De_novo() else abort endif endif Bkg_noise_Calc() Getaxis/Q bottom Variable Left_X=V_min Variable Start_X=V_min Variable End_X=min(V_max, pnt2x(Working_trace_copy,(numpnts(Working_trace_copy)-1))) if (CheckName("Peak_stats_Table1", 6)==0) execute "Peak_stats_Table()" else Dowindow/F Peak_stats_Table1 MoveWindow 1, 1, 1, 1 endif Variable Binomial_coeff,Real_cutoff If (Smooth_more==1) Duplicate/O/R=(Start_X,End_X) Working_trace_copy, diff1, diff1_nosmooth Binomial_coeff=Gaussian_to_Binomial_Calc(Smoothing_Factor_Add) Smooth Binomial_coeff, diff1 Real_cutoff=Binomial_to_Gaussian_Calc(Binomial_coeff) Print "Trace was additionally filtered with "+num2str(Real_cutoff)+"Hz (Binomial "+num2str(Binomial_coeff)+") -3dB Gaussian filter." else Duplicate/O/R=(Start_X,End_X) Working_trace_copy, diff1, diff1_nosmooth endif Differentiate diff1, diff1_nosmooth If (Smooth_Derivative==1) Binomial_coeff=Gaussian_to_Binomial_Calc(Smoothing_Factor_diff1) Smooth Binomial_coeff, diff1, diff1_nosmooth endif Variable Detection_level_diff1=Bkg_noise_dI*Detection_Mult Total_peaks_number=0 Variable Kapec=0 Variable dI_zero_L, dI_zero_R,Limit_R,Limit_L do If (cmpnum(Start_X,End_X,18)!=0) FindPeak/Q/M=(Detection_level_diff1)/R=(Start_X,End_X) diff1 else Kapec=1 endif if ((V_Flag==0)%&(Kapec!=1)) If(V_TrailingEdgeLoc>0) Total_peaks_number+=1 Change_waves("Redimension",Total_peaks_number) Peak_Num[Total_peaks_number-1]=Total_peaks_number Start_X=V_PeakLoc dI_zero_R=V_TrailingEdgeLoc dI_zero_L=V_PeakLoc Limit_L=max(Left_X,T_Bkg2[Total_peaks_number-2]) // temporary Tmax FindLevel/Q/R=(Start_X,End_X) diff1, 0 T_Max[Total_peaks_number-1]=V_LevelX // next spike Tmax or the end of the trace FindPeak/Q/M=(Detection_level_diff1)/R=(T_Max[Total_peaks_number-1],End_X) diff1 if (V_Flag==0) Limit_R=V_PeakLoc else Limit_R=End_X endif // final Tmax FindLevel/Q/R=(T_Max[Total_peaks_number-1],Limit_R) Working_trace_copy, Working_trace_copy(dI_zero_L) If(V_flag==0) dI_zero_R=V_LevelX wavestats/Q/R=(dI_zero_L,dI_zero_R) Working_trace_copy T_Max[Total_peaks_number-1]=V_maxloc endif Cursor /W=Main_window A Working_trace_copy T_Max[Total_peaks_number-1] // temporary Tbkg1 FindLevel/Q/R=(dI_zero_L,Limit_L) diff1, 0 If(V_flag==1) T_Bkg1[Total_peaks_number-1]=Limit_L else T_Bkg1[Total_peaks_number-1]=max(V_LevelX,T_Bkg2[Total_peaks_number-2]) endif // final Tbkg1 Variable SteadyState=Find_SteadyState(dI_zero_L, Limit_L, 2*(dI_zero_R-dI_zero_L)) If(SteadyState) Variable SteadyState4=Find_SteadyState(dI_zero_L, Limit_L, 4*(dI_zero_R-dI_zero_L)) If(SteadyState4) FindLevel/Q/R=(dI_zero_L,Limit_L) Working_trace_copy, SteadyState4 else FindLevel/Q/R=(dI_zero_L,Limit_L) Working_trace_copy, SteadyState endif T_Bkg1[Total_peaks_number-1]=V_LevelX endif Start_X=dI_zero_R // Tbkg2 FindLevel /Q/R=(T_Max[Total_peaks_number-1],Limit_R) diff1, 0 If (V_Flag) Peak_Q[Total_peaks_number-1]=0 else T_Bkg2[Total_peaks_number-1]=V_LevelX Variable Flat_Peak_End=Find_level_plus_2SD(T_Max[Total_peaks_number-1],Limit_R,T_Bkg1[Total_peaks_number-1]) If(Flat_Peak_End) T_Bkg2[Total_peaks_number-1]=max(Flat_Peak_End,T_Bkg2[Total_peaks_number-1]) else wavestats/Q/R=(T_Max[Total_peaks_number-1],Limit_R) Working_trace_copy T_Bkg2[Total_peaks_number-1]=V_minloc endif If ((T_Max[Total_peaks_number-1]-T_Max[Total_peaks_number-2]>0)%|(Total_peaks_number==1)) Calc_Peak_Parameters(Total_peaks_number,T_Bkg1[Total_peaks_number-1],T_Bkg2[Total_peaks_number-1]) else Peak_Q[Total_peaks_number-1]=0 endif Wavestats/Q Peak_Q If(V_numNans!=0) Peak_Q[Total_peaks_number-1]=0 endif If ((T_Bkg1[Total_peaks_number-1]>=T_Max[Total_peaks_number-1])%|(T_Bkg2[Total_peaks_number-1]<=T_Max[Total_peaks_number-1])) Peak_Q[Total_peaks_number-1]=0 endif // Check for spikes on uneven baseline Variable Spike_Min_Imax=Working_trace_copy(T_Max[Total_peaks_number-1])-max(Working_trace_copy(T_Bkg1[Total_peaks_number-1]),Working_trace_copy(T_Bkg2[Total_peaks_number-1])) Variable Spike_Max_Imax=Working_trace_copy(T_Max[Total_peaks_number-1])-min(Working_trace_copy(T_Bkg1[Total_peaks_number-1]),Working_trace_copy(T_Bkg2[Total_peaks_number-1])) If(Spike_Min_Imax<(Spike_Max_Imax*(100-Baseline_Drift)/100)) Peak_Q[Total_peaks_number-1]=0 endif endif Variable Next_Start_X=0 If(Detection_limits(Total_peaks_number)) If(Total_peaks_number>1) Next_Start_X=Peak_Half_H2[Total_peaks_number-1] endif Change_waves("Delete",(Total_peaks_number-1)) Total_peaks_number=Total_peaks_number-1 endif Start_X=max(Start_X,Next_Start_X) else Start_X=V_PeakLoc endif else SVAR Overlaps if((cmpstr(Overlaps,"Ignore")!=0)&(Total_peaks_number>1)) Check_for_Overlaps() endif if(Total_peaks_number==0) Peak_ID=0 SetVariable ID,limits={0,0,0},win=Main_window if (CheckName("Zoom_Win", 6)!=0) SetVariable ID,limits={0,0,0},win=Zoom_Win endif SetDrawLayer /K UserFront abort "No amperometric events found!" else Peak_ID=1 SetVariable ID,limits={1,(Total_peaks_number),1},win=Main_window if (CheckName("Zoom_Win", 6)!=0) SetVariable ID,limits={1,(Total_peaks_number),1},win=Zoom_Win endif Peak_locator(0) print "Found "+num2str(Total_peaks_number)+" spikes." Abort endif endif while (1) End Function Check_for_Overlaps() SetDataFolder $"root:Quanta" Wave Working_trace_copy=Working_trace_copy Wave T_Max=T_Max Wave Peak_Num=Peak_Num Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Peak_t05=Peak_t05 Wave/T Fall_fit=Fall_fit NVAR Overlap_Prc=Overlap_Prc SVAR Overlaps=Overlaps NVAR Bkg_noise_I=Bkg_noise_I NVAR Total_peaks_number=Total_peaks_number // Two spikes are considered overlapping if the distance between the end of the 1st spike and the beginning of the 2nd one is less than the average t1/2 * 2. Variable i=1, ii=1 Variable Last_overlapping_peak Variable Peak_limit Variable Same_level Make/O/N=(Total_peaks_number) Peak_Delta Peak_Delta[1,]=((T_Bkg1[p]-T_Bkg2[p-1])-2*(mean(Peak_t05, 0, Total_peaks_number)/1000))*1000 do if((Working_trace_copy(T_Bkg2[i-1])>(Working_trace_copy(T_Bkg1[i-1])+2*Bkg_noise_I))&(Peak_Delta[i]<0)) FindLevel /P/Q/R=[i,Total_peaks_number] Peak_Delta, 0 If(V_LevelX) Last_overlapping_peak=trunc(V_LevelX)+1 else Last_overlapping_peak=Total_peaks_number endif If((Last_overlapping_peak+1)<=Total_peaks_number) Peak_limit=T_Bkg1[Last_overlapping_peak] else Getaxis/W=Main_Window/Q bottom Peak_limit=min(V_max, pnt2x(Working_trace_copy,(numpnts(Working_trace_copy)-1))) endif Same_level=Find_level_plus_2SD(T_Max[Last_overlapping_peak-1],Peak_limit,T_Bkg1[i-1]) Variable Final_level if(Same_level) Final_level=Same_level else Final_level=T_Bkg2[Last_overlapping_peak-1] endif T_Bkg2[i-1,Last_overlapping_peak-1]=Final_level ii=i-1 Variable Seddle, Min_Tmax, Kill_it=0 do Wavestats/Q/R=(T_max[ii],T_max[ii+1]) Working_trace_copy Seddle=V_min-Working_trace_copy(Final_level) Min_Tmax=min(Working_trace_copy(T_max[ii])-Working_trace_copy(Final_level),Working_trace_copy(T_max[ii+1])-Working_trace_copy(Final_level)) If((Seddle/Min_Tmax*100)>Overlap_Prc) Kill_it=1 endif ii+=1 while (ii=R)) abort "Splitting point (round coursor) has to be between the Start and the End of the spike." endif Variable Split_pnt=xcsr(A) String Split_Where Variable Common_bkg1=T_Bkg1[Peak_pnt] Variable Common_bkg2=T_Bkg2[Peak_pnt] Variable Start_X, End_X If (T_Max[Peak_pnt]=0) Variable ii ii=First_Overlapp_peak+1 Do If (T_Max[ii]T_Max[Peak_pnt])) String First_and_Last=num2str(First_Overlapp_peak)+";"+num2str(Last_Overlapp_peak) return First_and_Last else return "0;0" endif End Function Calc_Separated_Peak_Param(First_Overlapp_pnt,Last_Overlapp_pnt) Variable First_Overlapp_pnt Variable Last_Overlapp_pnt SetDataFolder $"root:Quanta" Wave Peak_Half_H1=Peak_Half_H1 Wave Peak_Half_H2=Peak_Half_H2 Wave T_Max=T_Max Wave Peak_Base=Peak_Base Wave Peak_Imax=Peak_Imax Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave Peak_t05=Peak_t05 Wave Peak_Q=Peak_Q Wave Peak_Molec=Peak_Molec Wave Fall_slope=Fall_slope Wave Fall_slope2=Fall_slope2 Wave Working_trace_copy=Working_trace_copy Wave/T Fall_Fit=Fall_Fit NVAR Total_peaks_number=Total_peaks_number SVAR Fit_method=Fit_method Wave/T Fall_fit_Extrap=Fall_fit_Extrap String Extrapolation_name="" Variable A0, A1, tau1,Slope String Extrap_Exists Variable Half_Height, Max_X, Start_X, End_X, End_Common Variable Area_total, Area_bkg, Area_Extra=0 End_Common=T_Bkg2[First_Overlapp_pnt] Variable i=First_Overlapp_pnt // First peak pnt Do If(cmpstr(Fall_fit_Extrap[i],"")==0) Fall_fit_Extrap[i]="N:;Total:;Fit:;Tau:" endif If(cmpstr(StringByKey("N", Fall_fit_Extrap[i]),"")==0) Fall_fit_Extrap[i] = ReplaceStringByKey("N", Fall_fit_Extrap[i], num2str(1+i-First_Overlapp_pnt)) Fall_fit_Extrap[i] = ReplaceStringByKey("Total", Fall_fit_Extrap[i], num2str(1+Last_Overlapp_pnt-First_Overlapp_pnt)) endif Max_X=T_Max[i] Start_X=T_Bkg1[i] T_Bkg2[i]=End_Common If(i==Last_Overlapp_pnt) End_X=T_Bkg2[i] else End_X=T_Bkg1[i+1] endif If(i==First_Overlapp_pnt) Variable Bkg_under_the_Max=Working_trace_copy(T_Bkg1[i]) Bkg_under_the_Max=Bkg_under_the_Max+(Working_trace_copy(T_Bkg2[i])-Working_trace_copy(T_Bkg1[i]))*(T_Max[i]-T_Bkg1[i])/(T_Bkg2[i]-T_Bkg1[i]) Peak_Imax[i]=Working_trace_copy(T_Max[i])-Bkg_under_the_Max else Extrapolation_name="Extrap_"+num2str(i) // extrap curve for the previous peak Wave Extrap_prev=$Extrapolation_name Peak_Imax[i]=Working_trace_copy(Max_X)-Extrap_prev(Max_X) endif Half_Height=Working_trace_copy(Max_X)-Peak_Imax[i]/2 FindLevel /Q/R=(Max_X,Start_X) Working_trace_copy, Half_Height Peak_Half_H1[i]=min(V_LevelX,Max_X) If(i!=First_Overlapp_pnt) FindLevel /Q/R=(Max_X,Start_X) Extrap_prev, Half_Height if(V_Flag==0) Peak_Half_H1[i]=max(V_LevelX,Peak_Half_H1[i]) endif endif Calc_Rise_Fall(i) Extrapolation_name="Extrap_"+num2str(i+1) If(exists(Extrapolation_name)==1) if (CheckName("Zoom_Win", 6)!=0) RemoveFromGraph/Z/W=Zoom_Win $Extrapolation_name endif RemoveFromGraph/Z/W=Main_window $Extrapolation_name KillWaves /Z $Extrapolation_name endif If(i!=Last_Overlapp_pnt) Duplicate/O/R=(T_Bkg1[i+1],T_Bkg2[i]) Working_trace_copy qqq SetScale/I x 0,(T_Bkg2[i]-T_Bkg1[i+1]),"s", qqq A1=Working_trace_copy(T_Bkg1[i+1])-Working_trace_copy(T_Bkg2[i]) A0=Working_trace_copy(T_Bkg2[i]) String FitFunction=StringByKey("Fit", Fall_fit_Extrap[i]) If(strlen(FitFunction)==0) FitFunction=Fall_Fit[i] Fall_fit_Extrap[i] = ReplaceStringByKey("Fit", Fall_fit_Extrap[i], FitFunction) endif If((A1>0)&(cmpstr(FitFunction,"Line")!=0)) String ExpTau=StringByKey("Tau", Fall_fit_Extrap[i]) If(strlen(ExpTau)!=0) tau1=str2num(ExpTau) else tau1=max(Fall_slope[i],Fall_slope2[i]) endif Fall_fit_Extrap[i] = ReplaceStringByKey("Tau", Fall_fit_Extrap[i], num2str(tau1)) tau1=1/tau1*1000 qqq=A0+A1*exp(-x*tau1) SetScale/I x T_Bkg1[i+1],T_Bkg2[i],"s", qqq Duplicate/O qqq $Extrapolation_name else Slope=A1/(T_Bkg2[i]-T_Bkg1[i+1]) qqq=Working_trace_copy(T_Bkg1[i+1])-Slope*x SetScale/I x T_Bkg1[i+1],T_Bkg2[i],"s", qqq Duplicate/O qqq $Extrapolation_name // If(cmpstr(StringByKey("Fit", Fall_fit_Extrap[i]),"")==0) Fall_fit_Extrap[i] = ReplaceStringByKey("Fit", Fall_fit_Extrap[i], "Line") Fall_fit_Extrap[i] = ReplaceStringByKey("Tau", Fall_fit_Extrap[i], num2str(-1)) // endif endif KillWaves /Z qqq endif FindLevel /Q/R=(Max_X, End_X) Working_trace_copy, Half_Height If (V_flag==1) If(i==Last_Overlapp_pnt) Peak_Half_H2[i]=End_X else Extrapolation_name="Extrap_"+num2str(i+1) // extrap curve for the current peak Wave Extrap_current=$Extrapolation_name FindLevel /Q/R=(T_Bkg1[i+1], T_Bkg2[i]) Extrap_current, Half_Height If (V_flag==0) Peak_Half_H2[i]=V_LevelX else Peak_Half_H2[i]=End_X endif endif else Peak_Half_H2[i]=max(V_LevelX,Max_X) endif Peak_Base[i]=(T_Bkg2[i]-T_Bkg1[i])*1000 Peak_t05[i]=(Peak_Half_H2[i]-Peak_Half_H1[i])*1000 i+=1 while (i<=Last_Overlapp_pnt) i=Last_Overlapp_pnt // Last peak pnt Do Area_total=area(Working_trace_copy,T_Bkg1[i],T_Bkg2[i]) If(i==First_Overlapp_pnt) Area_bkg=(T_Bkg2[i]-T_Bkg1[i])*(Working_trace_copy(T_Bkg1[i])+Working_trace_copy(T_Bkg2[i]))/2 Peak_Q[i]=Area_total-Area_bkg-Area_Extra else Extrapolation_name="Extrap_"+num2str(i) // extrap curve for the previous peak Wave Extrap_prev=$Extrapolation_name Area_bkg=area(Extrap_prev,T_Bkg1[i],T_Bkg2[i]) Peak_Q[i]=Area_total-Area_bkg-Area_Extra Area_Extra+=Peak_Q[i] endif Peak_Molec[i]=(Peak_Q[i])*3.121*10^6 i-=1 while (i>=First_Overlapp_pnt) End Function New_Peak_Position(New_T_Max) Variable New_T_Max SetDataFolder $"root:Quanta" Wave T_Max=T_Max NVAR Total_peaks_number=Total_peaks_number If (Total_peaks_number==1) If (T_Max[Total_peaks_number-1]==0) // no peaks exists yet Change_waves("Make",0) return 0 endif endif Variable Delta=CmpNum((T_Max[Total_peaks_number-1]),New_T_Max,18) If (Delta==0) // peak already exists If (Total_peaks_number==1) // and an existing peak is the only one return -1 else return (-(Total_peaks_number-1)) endif endif If (Delta==-1) return (Total_peaks_number) // new peak will be the last one endif Variable Peak_pnt=0 Do Delta=CmpNum((T_Max[Peak_pnt]),New_T_Max,18) If (Delta>=0) If (Delta==0) // peak already exists if (Peak_pnt==0) return (-0.5) else return (-Peak_pnt) endif else return (Peak_pnt) endif endif Peak_pnt+=1 while(Total_peaks_number) End Function Calc_Peak_Parameters(Peak_pnt,Start_X,End_X) Variable Peak_pnt Variable Start_X Variable End_X Variable Max_X SetDataFolder $"root:Quanta" Wave T_Max=T_Max Wave Peak_Imax=Peak_Imax Wave Peak_t05=Peak_t05 Wave Peak_Q=Peak_Q Wave Peak_Base=Peak_Base Wave Peak_Half_H1=Peak_Half_H1 Wave Peak_Half_H2=Peak_Half_H2 Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Working_trace_copy=Working_trace_copy Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave/T Fall_fit_Extrap=Fall_fit_Extrap T_Bkg1[Peak_pnt]=Start_X T_Bkg2[Peak_pnt]=End_X // check for split overlapping spikes If((Peak_Split1[Peak_pnt]!=0)%|(Peak_Split2[Peak_pnt]!=0)) Calc_split_peak_param(Peak_pnt) return 0 endif // check for separated overlapping spikes String First_and_Last=Check_for_Separated_peaks(Peak_pnt) Variable First_separated_pnt=str2num(StringFromList(0,First_and_Last)) Variable Last_separated_pnt=str2num(StringFromList(1,First_and_Last)) If(First_separated_pnt!=Last_separated_pnt) Variable i=First_separated_pnt Do Fall_fit_Extrap[i]="" i+=1 while(i<=Last_separated_pnt) Calc_Separated_peak_param(First_separated_pnt,Last_separated_pnt) return 0 endif // find Imax, pA Max_X=T_Max[Peak_pnt] Variable Bkg_under_the_Max=Working_trace_copy(T_Bkg1[Peak_pnt])+(Working_trace_copy(T_Bkg2[Peak_pnt])-Working_trace_copy(T_Bkg1[Peak_pnt]))*(Max_X-T_Bkg1[Peak_pnt])/(T_Bkg2[Peak_pnt]-T_Bkg1[Peak_pnt]) Peak_Imax[Peak_pnt]=Working_trace_copy(Max_X)-Bkg_under_the_Max // find t(1/2), ms Variable Half_Height=Working_trace_copy(Max_X) - (Working_trace_copy(Max_X)-Bkg_under_the_Max)/2 FindLevel /Q/R=(Max_X,Start_X) Working_trace_copy, Half_Height Peak_Half_H1[Peak_pnt]=min(V_LevelX,Max_X) FindLevel /Q/R=(Max_X, End_X) Working_trace_copy, Half_Height If (V_flag==1) Peak_Half_H2[Peak_pnt]=End_X else Peak_Half_H2[Peak_pnt]=max(V_LevelX,Max_X) endif Peak_t05[Peak_pnt]=(Peak_Half_H2[Peak_pnt]-Peak_Half_H1[Peak_pnt])*1000 Peak_Base[Peak_pnt]=(T_Bkg2[Peak_pnt]-T_Bkg1[Peak_pnt])*1000 // find Q, pC, molecules Calc_Peak_Q(Peak_pnt,T_Bkg1[Peak_pnt],T_Bkg2[Peak_pnt]) // find rise and fall parameters If ((Peak_Q[Peak_pnt]>0)%|(Peak_t05[Peak_pnt]>0)) Calc_Rise_Fall(Peak_pnt) endif // If ((Detection_limits(Peak_pnt)!=1)) // Calc_Rise_Fall(Peak_pnt) // endif End Function Fall_fit_PopMenu(theTag,popNum,popStr) : PopupMenuControl String theTag Variable popNum String popStr SetDataFolder $"root:Quanta" SVAR Fit_method=Fit_method NVAR Peak_ID=Peak_ID // Wave/T Fall_fit=Fall_fit Variable Current_Peak=Peak_ID If(cmpstr(popStr,Fit_method)!=0) Fit_method=popStr Change_Table ("q",0) If(cmpstr(Fit_method,"DblExp")==0) SetVariable Results_Fall_Chi, win=Options_Tab_Panels, disable=0 else SetVariable Results_Fall_Chi, win=Options_Tab_Panels, disable=1 endif endif End Function Fall_Extrap_PopMenu_Single(theTag,popNum,popStr) : PopupMenuControl String theTag Variable popNum String popStr SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID Wave/T Fall_fit_Extrap=Fall_fit_Extrap Variable Peak_pnt=Peak_ID-1 String First_and_Last=Check_for_Separated_peaks(Peak_pnt) Variable First_separated_pnt=str2num(StringFromList(0,First_and_Last)) Variable Last_separated_pnt=str2num(StringFromList(1,First_and_Last)) Fall_fit_Extrap[Peak_pnt] = ReplaceStringByKey("Fit", Fall_fit_Extrap[Peak_pnt], popStr) Fall_fit_Extrap[Peak_pnt] = ReplaceStringByKey("Tau", Fall_fit_Extrap[Peak_pnt], "") Calc_Separated_peak_param(First_separated_pnt,Last_separated_pnt) Draw_lines_All(Peak_pnt) End Function Fall_fit_PopMenu_Single(theTag,popNum,popStr) : PopupMenuControl String theTag Variable popNum String popStr SetDataFolder $"root:Quanta" NVAR Total_peaks_number=Total_peaks_number NVAR Peak_ID=Peak_ID Wave Fall_ChiRatio=Fall_ChiRatio Wave Fall_time=Fall_time Wave Fall_slope=Fall_slope Wave Fall_slope2=Fall_slope2 Wave/T Fall_fit=Fall_fit Wave/T Fall_fit_Extrap=Fall_fit_Extrap Variable Peak_pnt=Peak_ID-1 String Fit_Function=Fall_fit[Peak_pnt] If((cmpstr(popStr,Fit_Function)!=0)&(Total_peaks_number!=0)) Fall_fit[Peak_pnt]=popStr String Slope_coeffs=Fit_Fall_Decay(Peak_pnt,popStr) If(cmpstr(popStr,"DblExp")==0) String Slope_coeffs_Exp=Fit_Fall_Decay(Peak_pnt,"Exp") Variable Ratio=str2num(StringFromList(3,Slope_coeffs_Exp))/str2num(StringFromList(3,Slope_coeffs)) Fall_ChiRatio[Peak_pnt]=Ratio else Fall_ChiRatio[Peak_pnt]=1 endif Fall_time[Peak_pnt]=str2num(StringFromList(0,Slope_coeffs)) Fall_slope[Peak_pnt]=str2num(StringFromList(1,Slope_coeffs)) Fall_slope2[Peak_pnt]=str2num(StringFromList(2,Slope_coeffs)) String First_and_Last=Check_for_Separated_peaks(Peak_pnt) Variable First_separated_pnt=str2num(StringFromList(0,First_and_Last)) Variable Last_separated_pnt=str2num(StringFromList(1,First_and_Last)) If(First_separated_pnt!=Last_separated_pnt) Fall_fit_Extrap[Peak_pnt] = ReplaceStringByKey("Fit", Fall_fit_Extrap[Peak_pnt], "") Fall_fit_Extrap[Peak_pnt] = ReplaceStringByKey("Tau", Fall_fit_Extrap[Peak_pnt], "") Calc_Separated_peak_param(First_separated_pnt,Last_separated_pnt) endif Draw_lines_All(Peak_pnt) endif End Function Calc_Rise_Fall(Peak_pnt) Variable Peak_pnt SetDataFolder $"root:Quanta" Wave T_Max=T_Max Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave Peak_Half_H1=Peak_Half_H1 Wave Peak_Imax=Peak_Imax Wave Rise_time=Rise_time Wave Rise_Midpoint=Rise_Midpoint Wave Rise_Lowpnt_X=Rise_Lowpnt_X Wave Rise_Hipnt_X=Rise_Hipnt_X Wave Rise_slope=Rise_slope Wave Fall_time=Fall_time Wave Fall_slope=Fall_slope Wave Fall_slope2=Fall_slope2 Wave Fall_ChiRatio=Fall_ChiRatio Wave Working_trace_copy=Working_trace_copy Wave Foot_W=Foot_W Wave Foot_end=Foot_end Wave diff1_nosmooth=diff1_nosmooth NVAR Rise_Low_Prc=Rise_Low_Prc NVAR Rise_Hi_Prc=Rise_Hi_Prc NVAR Total_peaks_number=Total_peaks_number NVAR Fall_ChiRatio_Cutoff=Fall_ChiRatio_Cutoff SVAR Fit_method=Fit_method Variable Start_X=T_Bkg1[Peak_pnt] Variable End_X=T_Bkg2[Peak_pnt] Variable dI_max_Y,dI_max_X Variable Half_Hight_L=(Working_trace_copy(T_Max[Peak_pnt])-Working_trace_copy(Start_X))/2 FindLevel/Q/R=(T_Max[Peak_pnt],Start_X) Working_trace_copy, (Working_trace_copy(Start_X)+Half_Hight_L ) Variable Half_Hight_L_X=V_LevelX // Check for overlaps If ((T_Max[Peak_pnt-1]!=T_Max[Peak_pnt])&(T_Max[Peak_pnt-1])>(T_Bkg1[Peak_pnt])) Start_X=T_Bkg2[Peak_pnt-1] endif If ((T_Max[Peak_pnt+1]!=T_Max[Peak_pnt])&(T_Max[Peak_pnt+1])<(T_Bkg2[Peak_pnt])) End_X=T_Bkg1[Peak_pnt+1] endif If(Peak_Split1[Peak_pnt]) Start_X=Peak_Split1[Peak_pnt] endif If(Peak_Split2[Peak_pnt]) End_X=Peak_Split2[Peak_pnt] endif If(Rise_Midpoint[Peak_pnt]==0) If((pnt2x(diff1_nosmooth,0)>Start_X)%|(pnt2x(diff1_nosmooth,numpnts(diff1_nosmooth))=T_Max[Peak_pnt])%|(End_X<=T_Bkg1[Peak_pnt])) abort "The coursors have to be between spike's Start and Maximum!" endif Variable Rise_B_coeff=Fit_Rise(Start_X,End_X) Rise_slope[Peak_pnt]=Rise_B_coeff/1000 Rise_Lowpnt_X[Peak_pnt]=Start_X Rise_Hipnt_X[Peak_pnt]=End_X Rise_Midpoint[Peak_pnt]=pnt2x(Rise_phase, round(numpnts(Rise_phase)/2)) Foot_End[Peak_pnt]=Extrapolate_to_Baseline(Peak_pnt) Variable Rise_Segment=(Rise_Hi_Prc-Rise_Low_Prc)/100 Rise_time[Peak_pnt]=(T_max[Peak_pnt]-Foot_end[Peak_pnt])*1000*Rise_Segment Calc_Foot_Parameters(Peak_pnt) Draw_lines_All(Peak_pnt) End Function/S Fit_Fall_Decay(Peak_pnt,Fit_Function) Variable Peak_pnt String Fit_Function SetDataFolder $"root:Quanta" Wave T_Max=T_Max Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave Fall_time=Fall_time Wave Fall_slope=Fall_slope Wave Fall_slope2=Fall_slope2 Wave Working_trace_copy=Working_trace_copy NVAR Total_peaks_number=Total_peaks_number NVAR Fall_ChiRatio_Cutoff=Fall_ChiRatio_Cutoff Make/O/N=0 W_coef Variable End_X=T_Bkg2[Peak_pnt] If ((T_Max[Peak_pnt+1]!=T_Max[Peak_pnt])&(T_Max[Peak_pnt+1])<(T_Bkg2[Peak_pnt])) End_X=T_Bkg1[Peak_pnt+1] endif If(Peak_Split2[Peak_pnt]) End_X=Peak_Split2[Peak_pnt] endif Variable Hight_R=Working_trace_copy(T_Max[Peak_pnt])-Working_trace_copy(End_X) Variable One_fouth_Height_Y_R=Working_trace_copy(End_X)+Hight_R*0.25 Variable Three_fouth_Height_Y_R=Working_trace_copy(End_X)+Hight_R*0.75 Variable One_fouth_Height_X_R, Three_fouth_Height_X_R FindLevel /Q/R=(T_Max[Peak_pnt],End_X) Working_trace_copy, Three_fouth_Height_Y_R Three_fouth_Height_X_R=V_LevelX FindLevel /Q/R=(T_Max[Peak_pnt],End_X) Working_trace_copy, One_fouth_Height_Y_R One_fouth_Height_X_R=V_LevelX Variable Fall_DeltaT=(One_fouth_Height_X_R-Three_fouth_Height_X_R)*1000 Variable Fall_Slope_coeff, Fall_Slope_coeff2=0,Fall_Chi=1 If(x2pnt(Working_trace_copy,End_X)-x2pnt(Working_trace_copy,Three_fouth_Height_X_R)<5) return "0,0,0,0" endif If(cmpstr(Fit_Function,"DblExp")==0) PauseUpdate Duplicate/O/R=(Three_fouth_Height_X_R,End_X) Working_trace_copy, Fall_phase SetScale/I x 0,(End_X-Three_fouth_Height_X_R),"s", Fall_phase CurveFit/Q/N dblexp Fall_phase /D=Fall_phase Fall_Chi=V_chisq Fall_Slope_coeff=min((1/(W_coef[4]/1000)),(1/(W_coef[2]/1000))) Fall_Slope_coeff2=max((1/(W_coef[4]/1000)),(1/(W_coef[2]/1000))) SetScale/I x Three_fouth_Height_X_R,End_X,"s", Fall_phase else If(cmpstr(Fit_Function,"Exp")==0) PauseUpdate Duplicate/O/R=(Three_fouth_Height_X_R,End_X) Working_trace_copy, Fall_phase SetScale/I x 0,(End_X-Three_fouth_Height_X_R),"s", Fall_phase CurveFit/Q/N exp Fall_phase /D=Fall_phase Fall_Chi=V_chisq SetScale/I x Three_fouth_Height_X_R,End_X,"s", Fall_phase Fall_Slope_coeff=1/(W_coef[2]/1000) else PauseUpdate Duplicate/O/R=(Three_fouth_Height_X_R,One_fouth_Height_X_R) Working_trace_copy, Fall_phase CurveFit/Q/N line Fall_phase /D=Fall_phase Fall_Slope_coeff=-W_coef[1]/1000 endif endif String Formated_String, Slope_coeffs sprintf Formated_String, "%.12f", Fall_DeltaT Slope_coeffs=Formated_String+";" sprintf Formated_String, "%.12f", Fall_Slope_coeff Slope_coeffs=Slope_coeffs+Formated_String+";" sprintf Formated_String, "%.12f", Fall_Slope_coeff2 Slope_coeffs=Slope_coeffs+Formated_String+";" sprintf Formated_String, "%.18f", Fall_Chi Slope_coeffs=Slope_coeffs+Formated_String+";" return Slope_coeffs End Function Calc_Peak_Q(Peak_pnt,Start_X,End_X) Variable Peak_pnt Variable Start_X Variable End_X SetDataFolder $"root:Quanta" Wave Peak_Q=Peak_Q Wave Peak_Molec=Peak_Molec Wave Working_trace_copy=Working_trace_copy Variable Area_total=area(Working_trace_copy,Start_X,End_X) Variable Area_bkg=(End_X-Start_X)*(Working_trace_copy(Start_X)+Working_trace_copy(End_X))/2 Peak_Q[Peak_pnt]=Area_total-Area_bkg Peak_Molec[Peak_pnt]=(Peak_Q[Peak_pnt])*3.121*10^6 End Function Calc_Foot_Parameters(Peak_pnt) : ButtonControl Variable Peak_pnt SetDataFolder $"root:Quanta" Wave T_Max=T_Max Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Foot_Q=Foot_Q Wave Foot_Molec=Foot_Molec Wave Foot_W=Foot_W Wave Foot_end=Foot_end Wave Rise_Lowpnt_X=Rise_Lowpnt_X Wave Foot_I= Foot_I Wave Peak_Split1=Peak_Split1 Wave Rise_time=Rise_time Wave Working_trace_copy=Working_trace_copy NVAR Bkg_noise_I=Bkg_noise_I NVAR Detection_Foot_Mult=Detection_Foot_Mult NVAR SSFoot_Do=SSFoot_Do NVAR Native_Foot_Del=Native_Foot_Del NVAR Foot_Min_W=Foot_Min_W NVAR Rise_Hi_Prc=Rise_Hi_Prc NVAR Rise_Low_Prc=Rise_Low_Prc Variable Start_X=T_Bkg1[Peak_pnt] Variable Foot_End_X_low=Foot_end[Peak_pnt] Variable Foot_End_X_hi=Rise_Lowpnt_X[Peak_pnt] If((Peak_Split1(Peak_pnt)!=0)%|(Foot_End_X_low<=Start_X)) Foot_Q[Peak_pnt]=0 Foot_Molec[Peak_pnt]=0 Foot_W[Peak_pnt]=0 Foot_I[Peak_pnt]=0 return 0 endif // calculate foot duration FindLevel/Q/R=(Start_X,T_Max[Peak_pnt]) Working_trace_copy, (Working_trace_copy(Start_X)+Detection_Foot_Mult*Bkg_noise_I) If((Foot_End_X_low-V_LevelX)>0) Foot_W[Peak_pnt]=(Foot_End_X_low-Start_X)*1000 else Foot_W[Peak_pnt]=0 endif // delete 'native' PSF If((Native_Foot_Del==1)&(Foot_W[Peak_pnt]>Foot_Min_W)) Variable Native_foot_W=Rise_time[Peak_pnt]*13.2/(Rise_Hi_Prc-Rise_Low_Prc) If (Foot_W[Peak_pnt]<=Native_foot_W) Foot_W[Peak_pnt]=0 endif endif // calculate foot current If((SSFoot_Do==1)&(Foot_W[Peak_pnt]>Foot_Min_W)) // find PSF with steady states Variable SteadyState=Find_SteadyState(Foot_End_X_low, Start_X, Foot_Min_W/1000) If(SteadyState) Foot_I[Peak_pnt]=SteadyState-Working_trace_copy(Start_X) endif else Foot_I[Peak_pnt]=mean(Working_trace_copy, Start_X, Foot_End_X_low)-Working_trace_copy(Start_X) endif // calculate foot charge If(Foot_W[Peak_pnt]>0) Variable Area_total=area(Working_trace_copy,Start_X,Foot_End_X_hi) Variable Ft_Bkg2_Y=Y_offset(Start_X, T_Bkg2[Peak_pnt], Foot_End_X_hi) Variable Foot_W_all=Foot_End_X_hi-Start_X Variable Area_bkg=Foot_W_all*(Working_trace_copy(Start_X)+Ft_Bkg2_Y)/2 Area_total=Area_total-Area_bkg Variable Tr_Area=(Foot_End_X_hi-Foot_End_X_low)*(Working_trace_copy(Foot_End_X_hi)-Ft_Bkg2_Y)/2 Foot_Q[Peak_pnt]=Area_total-Tr_Area Foot_Molec[Peak_pnt]=(Foot_Q[Peak_pnt])*3.121*10^6 endif // check the validity of PSF values If(Detection_limits_Foot(Peak_pnt)) Foot_W[Peak_pnt]=0 Foot_I[Peak_pnt]=0 Foot_Q[Peak_pnt]=0 Foot_Molec[Peak_pnt]=0 endif End // All in seconds Function Find_SteadyState (Start_X, End_X, Itteration) Variable Start_X Variable End_X Variable Itteration Wave Working_trace_copy=Working_trace_copy NVAR Bkg_noise_I=Bkg_noise_I Variable Delta=Start_X-End_X If(Delta<0) // The search is toward trace's end Itteration=0-Itteration endif If(abs(Delta)Lower_lim)) Steady_State=mean(Working_trace_copy, Step_back_1, Step_back_1-Itteration) return Steady_State break endif Step_back_1-=Itteration/2 Steady_State1=mean(Working_trace_copy, Step_back_1, Step_back_1-Itteration/2) Steady_State2=mean(Working_trace_copy, Step_back_1-Itteration/2, Step_back_1-Itteration) Upper_lim=Steady_State1+Bkg_noise_I Lower_lim=Steady_State1-Bkg_noise_I while(abs(Step_back_1-End_X)>abs(Itteration)) End Function New_Foot_I(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID Wave T_Bkg1=T_Bkg1 Wave Foot_I=Foot_I Wave Working_trace_copy=Working_trace_copy Variable Peak_pnt=Peak_ID-1 Foot_I[Peak_pnt]=Working_trace_copy(xcsr(A))-Working_trace_copy(T_Bkg1[Peak_pnt]) Draw_lines_All(Peak_pnt) End Function Delete_Foot(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID Wave T_Max=T_Max Wave T_Bkg1=T_Bkg1 Wave Peak_Half_H1=Peak_Half_H1 Wave Foot_Q=Foot_Q Wave Foot_Molec=Foot_Molec Wave Foot_W=Foot_W Wave Foot_end=Foot_end Wave Rise_Lowpnt_X=Rise_Lowpnt_X Wave Rise_Hipnt_X=Rise_Hipnt_X Wave Foot_I=Foot_I Wave Rise_Midpoint=Rise_Midpoint Wave Rise_slope=Rise_slope Wave Rise_time=Rise_time Wave Working_Trace_Copy=Working_Trace_Copy NVAR Rise_Hi_Prc=Rise_Hi_Prc NVAR Rise_Low_Prc=Rise_Low_Prc Variable Peak_pnt=Peak_ID-1 Rise_Midpoint[Peak_pnt]=Peak_Half_H1[Peak_pnt] Variable Hight_L=Working_trace_copy(T_Max[Peak_pnt])-Working_trace_copy(T_Bkg1[Peak_pnt]) Variable Upper_Y=Working_trace_copy(T_Bkg1[Peak_pnt])+Hight_L*Rise_Hi_Prc/100 Variable Lower_Y=Working_trace_copy(T_Bkg1[Peak_pnt])+Hight_L*Rise_Low_Prc/100 FindLevel/P/Q/R=(T_Max[Peak_pnt],T_Bkg1[Peak_pnt]) Working_trace_copy, Upper_Y Rise_Hipnt_X[Peak_pnt]=pnt2x(Working_trace_copy, V_LevelX ) FindLevel/P/Q/R=(T_Max[Peak_pnt],T_Bkg1[Peak_pnt]) Working_trace_copy, Lower_Y Rise_Lowpnt_X[Peak_pnt]=pnt2x(Working_trace_copy, V_LevelX ) Variable Rise_B_coeff=Fit_Rise(Rise_Lowpnt_X[Peak_pnt],Rise_Hipnt_X[Peak_pnt]) Rise_slope[Peak_pnt]=Rise_B_coeff/1000 Foot_End[Peak_pnt]=Extrapolate_to_Baseline(Peak_pnt) Variable Rise_Segment=(Rise_Hi_Prc-Rise_Low_Prc)/100 Rise_time[Peak_pnt]=(T_max[Peak_pnt]-Foot_end[Peak_pnt])*1000*Rise_Segment Foot_Q[Peak_pnt]=0 Foot_W[Peak_pnt]=0 Foot_Molec[Peak_pnt]=0 Foot_I[Peak_pnt]=0 Draw_lines_All(Peak_pnt) End Function New_Baseline(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID NVAR Total_peaks_number=Total_peaks_number Wave T_Max=T_Max Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave Rise_time=Rise_time Wave Rise_Midpoint=Rise_Midpoint Wave Rise_Lowpnt_X=Rise_Lowpnt_X Wave Rise_Hipnt_X=Rise_Hipnt_X Wave Rise_slope=Rise_slope Wave Foot_end=Foot_end Wave/T Fall_fit=Fall_fit Wave Working_Trace_Copy=Working_Trace_Copy Variable Peak_pnt=Peak_ID-1 If(Total_peaks_number==0) abort endif Variable Start_X=min(xcsr(A),xcsr(B)) Variable End_X=max(xcsr(A),xcsr(B)) If((T_Bkg1[Peak_pnt]>T_Bkg2[Peak_pnt-1])%|(Peak_pnt==0)) FindLevel /Q/R=(T_Max[Peak_pnt],Start_X ) Working_Trace_Copy, Working_Trace_Copy(Start_X) If(V_flag==0) Start_X=V_LevelX endif endif If ((Start_X>=T_Max[Peak_pnt])%|(End_X<=T_Max[Peak_pnt])) abort "Spike Maximum has to be between the coursors!" endif If ((Peak_Split1[Peak_pnt]!=0)%|(Peak_Split2[Peak_pnt]!=0)) T_Bkg1[Peak_pnt]=Start_X T_Bkg2[Peak_pnt]=End_X Calc_split_peak_param(Peak_pnt) else Fall_fit[Peak_pnt]="" Rise_Lowpnt_X[Peak_pnt]=0 Rise_Hipnt_X[Peak_pnt]=0 Foot_end[Peak_pnt]=0 Rise_slope[Peak_pnt]=0 Rise_Midpoint[Peak_pnt]=0 Calc_Peak_Parameters(peak_pnt,Start_X,End_X) endif Draw_lines_All(Peak_pnt) End Function New_T_Max(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID NVAR Total_peaks_number=Total_peaks_number Variable Peak_pnt=Peak_ID-1 Wave T_Max=T_Max Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Rise_Midpoint=Rise_Midpoint Wave Rise_Lowpnt_X=Rise_Lowpnt_X Wave Rise_Hipnt_X=Rise_Hipnt_X Wave Rise_slope=Rise_slope Wave Foot_End=Foot_End Wave/T Fall_fit=Fall_fit If(Total_peaks_number==0) abort endif If ((xcsr(A)<=T_Bkg1[Peak_pnt])%|(xcsr(A)>=T_Bkg2[Peak_pnt])) abort "C'mon, the Maximum has to be between the Start and the End on a spike!" endif T_Max[Peak_pnt]=xcsr(A) Fall_fit[Peak_pnt]="" Rise_Lowpnt_X[Peak_pnt]=0 Rise_Hipnt_X[Peak_pnt]=0 Rise_slope[Peak_pnt]=0 Rise_Midpoint[Peak_pnt]=0 Foot_end[Peak_pnt]=0 Calc_Peak_Parameters(Peak_pnt,T_Bkg1[Peak_pnt],T_Bkg2[Peak_pnt]) Draw_lines_All(Peak_pnt) End Function Delete_Peak(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID NVAR Total_peaks_number=Total_peaks_number Variable Peak_pnt=Peak_ID-1 Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave Peak_Num=Peak_Num Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave T_Max=T_Max Wave/T Fall_fit_Extrap=Fall_fit_Extrap If(Total_peaks_number==0) abort endif Wavestats/Q Peak_Num If( V_npnts==1) De_novo() else Variable Over=0 String First_and_Last=Check_for_Separated_peaks(Peak_pnt) Variable First_separated_pnt=str2num(StringFromList(0,First_and_Last)) Variable Last_separated_pnt=str2num(StringFromList(1,First_and_Last)) If(First_separated_pnt!=Last_separated_pnt) Variable i=First_separated_pnt Do Fall_fit_Extrap[i]="" i+=1 while(i<=Last_separated_pnt) Over=1 endif String TagName="Max"+num2str(Total_peaks_number-1) Tag/K/N=$TagName If (Peak_Split1[Peak_pnt]) Peak_Split2[Peak_pnt-1]=Peak_Split2[Peak_pnt] Over=1 endif If ((Peak_Split1[Peak_pnt]==0)&(Peak_Split2[Peak_pnt]!=0)) Peak_Split1[Peak_pnt+1]=0 Over=1 endif Change_waves("Delete",Peak_pnt) Wavestats/Q Peak_Num Total_peaks_number=V_npnts If(Over==1) Calc_Peak_Parameters(Peak_pnt,T_Bkg1[Peak_pnt],T_Bkg2[Peak_pnt]) Calc_Peak_Parameters(Peak_pnt-1,T_Bkg1[Peak_pnt-1],T_Bkg2[Peak_pnt-1]) endif endif If (Peak_ID>=Total_peaks_number) Peak_ID=Total_peaks_number else Peak_Num[Peak_pnt,]-=1 endif SetVariable ID,limits={1,(Total_peaks_number),1},win=Main_window if (CheckName("Zoom_Win", 6)!=0) SetVariable ID,limits={1,(Total_peaks_number),1},win=Zoom_Win endif if(Total_peaks_number) Draw_lines_All(Peak_ID-1) endif End Function Delete_All_Peaks(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" NVAR Total_peaks_number=Total_peaks_number If(Total_peaks_number==0) abort endif DoAlert 1, "Do you really want to kill them all!" If (V_Flag==1) De_novo() else abort endif End ///___________________________________ //____________Displaying the data________ //___________________________________ Function Peak_surf(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID NVAR Total_peaks_number=Total_peaks_number If(Total_peaks_number>0) If(cmpstr(ctrlName, "Next")==0) Peak_ID+=1 If (Peak_ID>Total_peaks_number) Peak_ID=Total_peaks_number endif else Peak_ID-=1 If (Peak_ID<1) Peak_ID=1 endif endif else abort endif Peak_locator(Peak_ID-1) End Function Peak_locator_ID(ctrlName,varNum,varStr,varName) : SetVariableControl String ctrlName Variable varNum String varStr String varName SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID Peak_locator(Peak_ID-1) End Function Peak_locator(Peak_pnt) Variable Peak_pnt SetDataFolder $"root:Quanta" SVAR Zoom_On=Zoom_On Wave Peak_Half_H1=Peak_Half_H1 Wave T_Max=T_Max Wave Peak_Imax=Peak_Imax Wave Peak_Half_H2=Peak_Half_H2 Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Working_trace_copy=Working_trace_copy Variable Max_location=T_Max[Peak_pnt] NVAR Total_peaks_number=Total_peaks_number If(Total_peaks_number==0) abort endif Variable Bkg1_location=T_Bkg1[Peak_pnt] Variable Tail_location=T_Bkg2[Peak_pnt] If ((T_Max[Peak_pnt])<(T_Bkg2[Peak_pnt-1])) Bkg1_location=T_Bkg1[Peak_pnt-1] endif If ((T_Max[Peak_pnt])>(T_Bkg1[Peak_pnt+1])) Tail_location=T_Bkg2[Peak_pnt+1] endif Variable Bottom_Y=min(Working_trace_copy(Bkg1_location),Working_trace_copy(Tail_location)) wavestats/Q/R=(Bkg1_location,Tail_location) Working_trace_copy Variable Highest_point_X=V_maxloc Variable Highest_point_Y=Working_trace_copy(Highest_point_X)-Bottom_Y If(cmpstr(Zoom_On,"On")==0) SetAxis left (Bottom_Y-0.2*Highest_point_Y),(Working_trace_copy(Highest_point_X)+0.2*Highest_point_Y) SetAxis bottom (Bkg1_location-1*(Tail_location-Highest_point_X)),(Tail_location+1*(Tail_location-Highest_point_X)) endif Cursor/W=Main_window A Working_trace_copy T_Bkg1[Peak_pnt] Cursor/W=Main_window B Working_trace_copy T_Bkg2[Peak_pnt] Draw_lines_All(Peak_pnt) Slider_Reset("qqq") End Function Generate_annotation(Current_Peak) Variable Current_Peak SetDataFolder $"root:Quanta" Wave T_Max=T_Max Wave Peak_Base=Peak_Base Wave Peak_t05=Peak_t05 Wave Peak_Imax=Peak_Imax Wave Peak_Q=Peak_Q Wave Peak_Molec=Peak_Molec Wave Rise_time=Rise_time Wave Rise_slope=Rise_slope Wave/T Fall_fit=Fall_fit Wave Fall_time=Fall_time Wave Fall_slope=Fall_slope Wave Fall_slope2=Fall_slope2 Wave Foot_I=Foot_I Wave Foot_W=Foot_W Wave Foot_Q=Foot_Q Wave Foot_Molec=Foot_Molec NVAR Rise_Low_Prc=Rise_Low_Prc NVAR Rise_Hi_Prc=Rise_Hi_Prc NVAR Total_peaks_number=Total_peaks_number SVAR Values_to_show=Values_to_show String Peak_Parameters_list="",Peak_Parameters_One String One_wave If(Total_peaks_number==0) return 0 endif Variable i=1 do One_wave=StringFromList(i, Values_to_show ,",") if(strlen(One_wave) == 0 ) break endif If(cmpstr(One_wave,"T_Max")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\K(0,0,0) Time= %.2W1Ps\K(0,0,52224)", T_Max[Current_Peak] Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Peak_Base")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rBase= %.1W1Ps", Peak_Base[Current_Peak]/1000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Peak_t05")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rt1/2= %.1W1Ps", Peak_t05[Current_Peak]/1000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Peak_Imax")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rImax= %.1W1PA", Peak_Imax[Current_Peak]/1000000000000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Peak_Q")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rQ= %.1W1PC", Peak_Q[Current_Peak]/1000000000000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Peak_Molec")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rQ= %.3g Molec", Peak_Molec[Current_Peak] Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Rise_time")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rrise ("+num2str(Rise_Low_Prc)+"-"+num2str(Rise_Hi_Prc)+")= %.1W1Ps", Rise_time[Current_Peak]/1000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Rise_slope")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rrise= %.1W1PA/ms", Rise_slope[Current_Peak]/1000000000000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Fall_time")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rfall (75-25)= %.1W1Ps", Fall_time[Current_Peak]/1000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Fall_slope")==0) SVAR Fit_method=Fit_method Peak_Parameters_list+="\K(0,0,0)\r Fit: "+Fall_fit[Current_Peak]+"\K(0,0,52224)" If (cmpstr(Fit_method,"Line")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rfall= %.1W1PA/ms", Fall_slope[Current_Peak]/1000000000000 endif If (cmpstr(Fit_method,"Exp")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rfall (\F'Symbol't\F'Arial'1)= %.1W1Ps", Fall_slope[Current_Peak]/1000 endif If (cmpstr(Fit_method,"DblExp")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rfall (\F'Symbol't\F'Arial'1)= %.1W1Ps \rfall (\F'Symbol't\F'Arial'2)= %.1W1Ps", Fall_slope[Current_Peak]/1000, Fall_slope2[Current_Peak]/1000 endif Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Foot_I")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rFoot H= %.1W1PA", Foot_I[Current_Peak]/1000000000000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Foot_W")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rFoot W= %.1W1Ps", Foot_W[Current_Peak]/1000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Foot_Q")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rFoot Q= %.1W1PC", Foot_Q[Current_Peak]/1000000000000 Peak_Parameters_list+=Peak_Parameters_One endif If(cmpstr(One_wave,"Foot_Molec")==0) sprintf Peak_Parameters_One, "\Z09\F'Arial'\rFoot Q= %.3g Molec", Foot_Molec[Current_Peak] Peak_Parameters_list+=Peak_Parameters_One endif i+=1 while(1) TextBox/W=Main_window/A=RT/C/N=Peak_data/F=1/G=(0,0,52224) Peak_Parameters_list End Function Draw_lines_All(Current_Peak) Variable Current_Peak SetDataFolder $"root:Quanta" SVAR Zoom_On=Zoom_On NVAR Total_peaks_number=Total_peaks_number Wave Working_trace_copy=Working_trace_copy Wave T_Max=T_Max Wave Peak_Half_H1=Peak_Half_H1 Wave Peak_Half_H2=Peak_Half_H2 Wave Peak_Imax=Peak_Imax Wave T_Bkg1=T_Bkg1 Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave Peak_t05=Peak_t05 Wave T_Bkg2=T_Bkg2 Wave Rise_Midpoint=Rise_Midpoint Wave Foot_Q=Foot_Q Wave Foot_W=Foot_W Wave Foot_end=Foot_end Wave Rise_Lowpnt_X=Rise_Lowpnt_X Wave Rise_Hipnt_X=Rise_Hipnt_X DoWindow/F Main_Window PauseUpdate; Silent 1 GetAxis /Q left Variable Mark_Height=(V_max-V_min)*0.04 SetDrawLayer /K UserFront Delete_Tags() Variable Peak_pnt=0 String TagName NVAR Show_Legend=Show_Legend if(Show_Legend==1) Generate_annotation(Current_Peak) endif Do Variable Max_X=T_Max[Peak_pnt] Variable Start_X=Peak_Half_H1[Peak_pnt] Variable End_X=Peak_Half_H2[Peak_pnt] Variable Bkg1_location=T_Bkg1[Peak_pnt] Variable Tail_location=T_Bkg2[Peak_pnt] Variable Bottom_Y=min(Working_trace_copy(Bkg1_location),Working_trace_copy(Tail_location)) TagName="Max"+num2str(Peak_pnt) Tag/C/N=$TagName Working_trace_copy, (Max_X), num2str(Peak_pnt+1) Tag/C/N=$TagName /F=0 /X=0.00/Y=8 If(Peak_pnt==Current_Peak) Tag/C/N=$TagName/G=(0,15872,65280) else Tag/C/N=$TagName /G=(0,0,0)/I=1 endif String First_and_Last=Check_for_Separated_peaks(Peak_pnt) Variable First_separated_pnt=str2num(StringFromList(0,First_and_Last)) Variable Last_separated_pnt=str2num(StringFromList(1,First_and_Last)) String Extrap_Wave="Extrap_"+num2str(Peak_pnt+1) String Extrap_Trace=TraceNameList("Main_window", ";", 1 ) If(First_separated_pnt!=Last_separated_pnt) If(strsearch(Extrap_Trace,Extrap_Wave,0)==-1) If(WaveExists($Extrap_Wave)) AppendToGraph/W=Main_window $Extrap_Wave ModifyGraph lstyle($Extrap_Wave)=2,lsize($Extrap_Wave)=0.5,rgb($Extrap_Wave)=(0,15872,65280) endif endif If(Peak_pnt==First_separated_pnt) SetDrawEnv xcoord=bottom, ycoord=left, linefgc= (0,15872,65280), dash= 2 DrawLine Bkg1_location,Working_trace_copy(Bkg1_location),Tail_location,Working_trace_copy(Tail_location) endif else If(WaveExists($Extrap_Wave)) if (CheckName("Zoom_Win", 6)!=0) RemoveFromGraph/Z/W=Zoom_Win $Extrap_Wave endif RemoveFromGraph/Z/W=Main_window $Extrap_Wave KillWaves/Z $Extrap_Wave endif SetDrawEnv xcoord=bottom, ycoord=left, linefgc= (0,15872,65280), dash= 2 DrawLine Bkg1_location,Working_trace_copy(Bkg1_location),Tail_location,Working_trace_copy(Tail_location) endif SetDrawEnv xcoord=bottom, ycoord=left, linefgc= (0,15872,65280), dash= 2 DrawLine Start_X,(Working_trace_copy(Max_X)-Peak_Imax[Peak_pnt]/2),End_X,(Working_trace_copy(Max_X)-Peak_Imax[Peak_pnt]/2) if(cmpstr(Zoom_On,"On")==0 ) SetDrawEnv xcoord=bottom, ycoord=left, linefgc= (34816,34816,34816), arrow= 1 DrawLine Bkg1_location,(Working_trace_copy(Bkg1_location)-Mark_Height),Bkg1_location,(Working_trace_copy(Bkg1_location)) SetDrawEnv xcoord=bottom, ycoord=left, linefgc= (34816,34816,34816), arrow= 1 DrawLine Tail_location,(Working_trace_copy(Tail_location)-Mark_Height),Tail_location,(Working_trace_copy(Tail_location)) endif If (Foot_Q[Peak_pnt]!=0) Variable Low_Rise_Pnt_X=Rise_Lowpnt_X[Peak_pnt] Variable Low_Rise_Pnt_Y=Working_trace_copy(Rise_Lowpnt_X[Peak_pnt]) Variable Offset_Foot=Y_offset(T_Bkg1[Peak_pnt], T_Bkg2[Peak_pnt], Foot_end[Peak_pnt]) SetDrawEnv xcoord=bottom, ycoord=left, linefgc= (0,39168,0), dash= 2 DrawLine Low_Rise_Pnt_X,Low_Rise_Pnt_Y,Foot_end[Peak_pnt],Offset_Foot endif If (Peak_Split1[Peak_pnt]!=0) Variable Offset_Split1=Y_offset(T_Bkg1[Peak_pnt], T_Bkg2[Peak_pnt], Peak_Split1[Peak_pnt]) SetDrawEnv xcoord=bottom, ycoord=left, linefgc=(24576,24576,65280), dash=0 DrawLine Peak_Split1[Peak_pnt],Working_trace_copy(Peak_Split1[Peak_pnt]),Peak_Split1[Peak_pnt],Offset_Split1 endif If (Peak_Split2[Peak_pnt]!=0) Variable Offset_Split2=Y_offset(T_Bkg1[Peak_pnt], T_Bkg2[Peak_pnt], Peak_Split2[Peak_pnt]) SetDrawEnv xcoord=bottom, ycoord=left, linefgc=(24576,24576,65280), dash=0 DrawLine Peak_Split2[Peak_pnt],Working_trace_copy(Peak_Split2[Peak_pnt]),Peak_Split2[Peak_pnt],Offset_Split2 endif Peak_pnt+=1 while(Peak_pnt40) Loaded_file_name=Long_Name_Cut(Loaded_file_name) endif DoWindow/T Main_window, Loaded_file_name If (CheckName("See_zoomed", 15)!=0) Button See_zoomed rename=See_all, title="Zoom In" Zoom_On ="Off" endif If(Check_files_list_Q(Loaded_file_path)==0) String/G File_list=File_list+";"+Loaded_file_path String Too_much=StringFromList(21,File_list) if( strlen(Too_much) != 0 ) string First_item=StringFromList(1,File_list) File_list=RemoveFromList(First_item, File_list) endif if (CheckName("File",9)!=0) PopupMenu Recent_files,mode=0,value= root:Quanta:File_list,win=File endif endif Endmacro Function/S Long_Name_Cut(Name) String Name Prompt Name, "New name (less than 40 characters)" DoPrompt "Window name is too long!", Name Return Name End Function Copy_Orig_Wave() SetDataFolder $"root:Quanta" NVAR Gain=Gain NVAR Gain_Temp=Gain_Temp NVAR T_Start_orig=T_Start_orig NVAR T_Delta_orig=T_Delta_orig NVAR T_Start=T_Start NVAR T_End=T_End NVAR T_Delta=T_Delta NVAR X_min=X_min NVAR X_max=X_max NVAR Y_min=Y_min NVAR Y_max=Y_max NVAR Bkg_noise_I=Bkg_noise_I NVAR Bkg_noise_dI=Bkg_noise_dI NVAR Bkg_noise_Start=Bkg_noise_Start NVAR Bkg_noise_End=Bkg_noise_End NVAR Overall_Filter=Overall_Filter SVAR Zoom_On=Zoom_On Wave Orig_trace_copy=Orig_trace_copy Overall_Filter=0 Orig_trace_copy*=Gain If(numpnts(Orig_trace_copy)==0) abort "The trace you are trying to load has 0 datapoints!" endif Duplicate/O Orig_trace_copy Working_trace_copy Make/O/N=1 Zoomed_peak, Fall_phase,Rise_phase If(cmpstr(Zoom_On,"On")==0) Button See_zoomed win=Main_window, rename=See_all, title="Zoom In" Zoom_On ="Off" RemoveFromGraph/W=Main_window/Z Rise_phase,Fall_phase endif T_Start=T_Start_orig T_Delta=T_Delta_orig SetScale/P x T_Start,T_Delta/1000,"s", Working_trace_copy SetScale d 0,0,"pA", Working_trace_copy T_End=pnt2x(Working_trace_copy, (numpnts(Working_trace_copy)-1)) X_min=T_Start X_max=T_End SetAxis/W=Main_window/A DoUpdate GetAxis/W=Main_window/Q left Y_min=V_min Y_max=V_max Slider X_Slider, win=Main_window,value=0.5 GroupBox Bkg_HiLt, win=Main_window,disable=0 Filter_Limits() Bkg_noise_I=0 Bkg_noise_dI=0 Bkg_noise_Start=0 Bkg_noise_End=0 End Function File_macro_Q(theTag) : ButtonControl String theTag SetDataFolder $"root:Quanta" NVAR Total_peaks_number=Total_peaks_number NVAR Smoothing_Factor_diff1=Smoothing_Factor_diff1 NVAR Gain=Gain NVAR T_Start_orig=T_Start_orig NVAR T_delta_orig=T_delta_orig if( cmpstr(theTag,"Load_File")==0 ) execute "load_single_file_Q(0)" endif if( cmpstr(theTag,"Reuse")==0 ) Wave Orig_trace_copy=Orig_trace_copy Wave Working_trace_copy=Working_trace_copy if(Total_peaks_number) DoAlert 1, "All detected spikes will be deleted!!! \rDo you really wanna to kill them all!?" If (V_Flag==2) abort endif else If(numpnts(Working_trace_copy)<2) abort "No trace loaded or the wave is too short." endif endif SetScale/P x T_Start_orig,T_Delta_orig/1000,"s", Orig_trace_copy Orig_trace_copy/=Gain De_novo() Copy_Orig_Wave() endif End Function Check_files_list_Q(File_name) String File_name SetDataFolder $"root:Quanta" SVAR File_list=File_list String File Variable i=1 do File=StringFromList(i,File_list) if( strlen(File) == 0 ) return 0 break else If (cmpstr(File_name,File)==0) return 1 break endif endif i += 1 while (1) End Function Recent_files_list_Q(ctrlName,popNum,popStr) : PopupMenuControl String ctrlName Variable popNum String popStr SetDataFolder $"root:Quanta" SVAR File_list=File_list String/G File_to_load File_to_load=popStr execute "Load_single_file_Q(1)" End Function Save_zoomed_trace(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" Wave Working_trace_copy=Working_trace_copy If(numpnts(Working_trace_copy)<2) abort "No trace loaded or the wave is too short." endif SVAR Loaded_file_name=Loaded_file_name String Name_to_save=Loaded_file_name[0,(strsearch(Loaded_file_name, ".", 0)-1)] If(cmpstr(ctrlName,"Save_Avg")==0) NVAR Avg_Spike_Weight=Avg_Spike_Weight Duplicate/O Avg_peak Avg_peak_saved Name_to_save+="_Avg_N"+num2str(Avg_Spike_Weight) Save/C/I Avg_peak_saved as Name_to_save KillWaves/Z Avg_peak_saved return 0 endif GetAxis /Q bottom variable Start_X=V_min variable End_X=V_max Duplicate/O/R=(Start_X,End_X) Working_trace_copy zoomed_trace Name_to_save+="_Zoom" Save/C/I zoomed_trace as Name_to_save End Function De_novo() SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID NVAR Total_peaks_number=Total_peaks_number Delete_Tags() TextBox/W=Main_window/N=Peak_data/K Change_waves("Make",0) Total_peaks_number=0 Peak_ID=0 Dowindow/F Main_window RemoveFromGraph/Z/W=Main_window Rise_phase,Fall_phase Make/O/N=1 Zoomed_peak, Fall_phase,Rise_phase SetVariable ID,limits={1,(Total_peaks_number),1},win=Main_window SetDrawLayer /K UserFront if (CheckName("Zoom_Win", 6)!=0) SetVariable ID,limits={1,(Total_peaks_number),1},win=Zoom_Win endif String Extrap_ String Extrap_waves=WaveList("Extrap*",";","") Variable q=0 Do Extrap_=Stringfromlist(q,Extrap_waves) If(strlen(Extrap_)==0) break endif if (CheckName("Zoom_Win", 6)!=0) RemoveFromGraph/Z/W=Zoom_Win $Extrap_ endif RemoveFromGraph/Z/W=Main_window $Extrap_ KillWaves /Z $Extrap_ q+=1 while(1) End Function Change_Waves(ToDo,pnt) String ToDo Variable pnt SetDataFolder $"root:Quanta" String/G All_waves=" Peak_Num,T_Max,Peak_Base,Peak_Imax,Peak_t05,Peak_Q,Peak_Molec,Rise_slope,Fall_slope,Fall_slope2," All_waves+="Peak_Half_H1,Peak_Half_H2, T_Bkg1,T_Bkg2,Rise_Midpoint,Rise_time,Fall_time,Interspike_interval," All_waves+="Peak_Split2, Peak_Split1,Foot_Q,Foot_Molec,Foot_W,Foot_end, Rise_Lowpnt_X, Rise_Hipnt_X, Foot_I, Fall_ChiRatio" String Exe if( cmpstr(ToDo,"Make")==0) Exe="Make/O/N="+num2str(pnt)+All_waves execute Exe Exe="Make/O/T/N="+num2str(pnt)+"Fall_fit, Fall_Fit_Extrap" execute Exe endif if( cmpstr(ToDo,"Redimension")==0 ) Exe="Redimension/N="+num2str(pnt)+All_waves execute Exe Exe="Redimension/N="+num2str(pnt)+"Fall_fit, Fall_Fit_Extrap" execute Exe endif String New_Name="", Extrap_waves="" Variable Name_Ln, Extrap_Num,q if( cmpstr(ToDo,"Delete")==0 ) String Extrap_Exists="Extrap_"+num2str(pnt+1) If(exists(Extrap_Exists)==1) if (CheckName("Zoom_Win", 6)!=0) RemoveFromGraph/Z/W=Zoom_Win $Extrap_Exists endif RemoveFromGraph/Z/W=Main_window $Extrap_Exists KillWaves/Z $Extrap_Exists endif Extrap_Exists="Extrap_"+num2str(pnt) If(exists(Extrap_Exists)==1) if (CheckName("Zoom_Win", 6)!=0) RemoveFromGraph/Z/W=Zoom_Win $Extrap_Exists endif RemoveFromGraph/Z/W=Main_window $Extrap_Exists KillWaves/Z $Extrap_Exists endif Exe="DeletePoints "+num2str(pnt)+",1, "+All_waves execute Exe Exe="DeletePoints "+num2str(pnt)+",1, Fall_fit, Fall_Fit_Extrap" execute Exe Extrap_waves=WaveList("Extrap*",";","") q=0 Do Extrap_Exists=Stringfromlist(q,Extrap_waves) Name_Ln=strlen(Extrap_Exists) If(Name_Ln==0) break endif Extrap_Num=str2num(Extrap_Exists[7,Name_Ln]) If(Extrap_Num>=pnt+1) New_Name="Extrap_"+num2str(Extrap_Num-1) Rename $Extrap_Exists, $New_Name endif q+=1 while(1) endif if(cmpstr(ToDo,"Insert")==0 ) Exe="InsertPoints "+num2str(pnt)+",1, "+All_waves execute Exe Exe="InsertPoints "+num2str(pnt)+",1, Fall_fit, Fall_Fit_Extrap" execute Exe Extrap_waves=WaveList("Extrap*",";","") q=ItemsInList(Extrap_waves)-1 Do Extrap_Exists=Stringfromlist(q,Extrap_waves) Name_Ln=strlen(Extrap_Exists) If(Name_Ln==0) break endif Extrap_Num=str2num(Extrap_Exists[7,Name_Ln]) If(Extrap_Num>=pnt+1) New_Name="Extrap_"+num2str(Extrap_Num+1) Rename $Extrap_Exists, $New_Name endif q-=1 while(1) endif End //__________________________________ //___________Averaged Spike _________ //__________________________________ Function Stats_PopMenu(theTag,popNum,popStr) : PopupMenuControl String theTag Variable popNum String popStr SetDataFolder $"root:Quanta" SVAR Norm_point=Norm_point SVAR Population_Center=Population_Center strswitch(theTag) case "Stats_Population": Population_Center=popStr break case "Stats_AvePeak": Norm_point=popStr break endswitch End Function Average_peaks(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" NVAR Total_peaks_number=Total_peaks_number Wave Rise_Midpoint=Rise_Midpoint Wave T_Max=T_Max Wave T_Bkg1=T_Bkg1 Wave T_Bkg2=T_Bkg2 Wave Peak_Split1=Peak_Split1 Wave Peak_Split2=Peak_Split2 Wave Fall_slope=Fall_slope Wave Fall_slope2=Fall_slope2 Wave Working_Trace_Copy=Working_Trace_Copy NVAR Bkg_noise_I=Bkg_noise_I NVAR T_Delta=T_Delta NVAR Overall_Filter=Overall_Filter Variable/G Avg_Spike_Weight if (CheckName("Avg_peak_graph", 6)==0) execute "Avg_peak_graph()" else Dowindow/F Avg_peak_graph MoveWindow 1, 1, 1, 1 endif if (CheckName("Avg_peak_pnts", 6)==0) PauseUpdate; Silent 1 Edit/K=1/W=(420,259.25,580.5,482.75) Avg_peak.xy as "Averaged wave" String command="ModifyTable width(Point)=0,size(Avg_peak.xy)=9,width(Avg_peak.xy)=68" execute command DoWindow/C Avg_peak_pnts AutoPositionWindow/E/M=1/R=Avg_peak_graph Avg_peak_pnts else Dowindow/F Avg_peak_pnts MoveWindow 1, 1, 1, 1 endif SetWindow Avg_peak_graph, hook=$"Killer_of_Hookers" SetWindow Avg_peak_pnts, hook=Killer_of_Hookers if(Total_peaks_number==0) abort endif If(numpnts(Avg_peak)!=0) DoAlert 1, "Discard existing averaged spike?" if(V_flag==1) Make/O/N=0 Avg_peak else abort endif endif Variable Binomial_coeff=Gaussian_to_Binomial_Calc(Overall_Filter) Variable S=0 SVAR Norm_point=Norm_point If(cmpstr(Norm_point,"Max")==0) Wave Norm_data=T_Max else Wave Norm_data=Rise_Midpoint endif Variable Start_P_longest, End_P_longest Duplicate/O T_Max, Limit_L, Limit_R Do If(Peak_Split1[S]) Limit_L[S]=x2pnt(Working_Trace_Copy,Norm_data[S])-x2pnt(Working_Trace_Copy,Peak_Split1[S]) else Limit_L[S]=x2pnt(Working_Trace_Copy,Norm_data[S])-x2pnt(Working_Trace_Copy,T_Bkg1[S]) endif Start_P_longest=max(Start_P_longest,Limit_L[S]) If(Peak_Split2[S]) Limit_R[S]=x2pnt(Working_Trace_Copy,Peak_Split2[S])-x2pnt(Working_Trace_Copy,Norm_data[S]) else If(S==Total_peaks_number-1) Limit_R[S]=x2pnt(Working_Trace_Copy,T_Bkg2[S])-x2pnt(Working_Trace_Copy,Norm_data[S]) else Limit_R[S]=x2pnt(Working_Trace_Copy,min(T_Bkg2[S], T_Bkg1[S+1]))-x2pnt(Working_Trace_Copy,Norm_data[S]) endif endif End_P_longest=max(End_P_longest,Limit_R[S]) S+=1 while(SBinomial_coeff+1) Smooth Binomial_coeff, Noizy_Inset endif Temp_wave[0,Start_P_longest-1-Limit_L[S]]+=Noizy_Inset(x) Temp_wave[Start_P_longest-1+Limit_R[S],numpnts(Temp_wave)]=0 Duplicate/O/R=[Start_P_longest-1+Limit_R[S],numpnts(Temp_wave)] Temp_wave Noizy_Inset Noizy_Inset+=gnoise(Bkg_noise_I*2) if(numpnts(Noizy_Inset)>Binomial_coeff+1) Smooth Binomial_coeff, Noizy_Inset endif Temp_wave[Start_P_longest-1+Limit_R[S],numpnts(Temp_wave)]+=Noizy_Inset(x) Extrap_Name="Extrap_"+num2str(S+1) If(exists(Extrap_Name)==1) Duplicate/O $Extrap_Name, qqq qqq-=Bkg_level SetScale/P x pnt2x(Temp_wave,(Start_P_longest-1+Limit_R[S])),(T_Delta/1000), "s", qqq Temp_wave[Start_P_longest-1+Limit_R[S],Start_P_longest-1+Limit_R[S]+numpnts(qqq)]+=qqq(x) endif CopyScales/P Avg_peak Temp_wave Extrap_Name="Extrap_"+num2str(S) If(exists(Extrap_Name)==1) Duplicate/O $Extrap_Name, qqq Bkg_level=max(qqq(0),qqq(numpnts(qqq))) qqq-=Bkg_level CopyScales/P Temp_wave qqq Temp_wave[0,numpnts(qqq)]-=qqq(x) endif // string namen="Temp_wave"+num2str(S) // Duplicate/O Temp_wave $namen Avg_peak+=Temp_wave(x) S+=1 While(SAdded_Npnts) SetScale/P x pnt2x(Avg_peak,0)+(Org_Npnts-Added_Npnts)*Org_DeltaT,Org_DeltaT, "s", Avg_peak DeletePoints 0,(Org_Npnts-Added_Npnts), Avg_peak else SetScale/P x pnt2x(Added_wave,0)+(Added_Npnts-Org_Npnts)*Added_DeltaT,Added_DeltaT, "s", Added_wave DeletePoints 0,(Added_Npnts-Org_Npnts), Added_wave endif Org_Npnts=numpnts(Avg_peak)-x2pnt(Avg_peak,0) Added_Npnts=numpnts(Added_wave)-x2pnt(Added_wave,0) If(Org_Npnts>Added_Npnts) DeletePoints numpnts(Added_wave),(Org_Npnts-Added_Npnts), Avg_peak else DeletePoints numpnts(Avg_peak),(Added_Npnts-Org_Npnts), Added_wave endif Avg_peak+=Added_wave Avg_peak/=(Avg_Spike_Weight+gWeight_Added) Avg_Spike_Weight+=gWeight_Added KillWaves/Z Added_wave End Function Killer_of_Hookers(infoStr) String infoStr Variable somethingDone=0 String win = StringByKey("WINDOW",infoStr) String event = StringByKey("EVENT",infoStr) if (CmpStr(event, "kill") != 0) return 0 endif if (CmpStr(win, "Avg_peak_graph") != 0) DoWindow/K Avg_peak_graph somethingDone=1 endif if (CmpStr(win, "Avg_peak_pnts") != 0) DoWindow/K Avg_peak_pnts somethingDone=1 endif return somethingDone end //__________Stats Notebook____________ Function Show_stats(ctrlName) : ButtonControl String ctrlName if (CheckName("Stats", 10)==0) NewNotebook/N=Stats/F=1/V=1/W=(2.4,121.4,604.2,305) as "Data analysis" Generate_notebook() else DoWindow /F Stats MoveWindow 1,1,1,1 Notebook Stats selection={startOfFile, endOfFile} Generate_notebook() endif End Function Generate_notebook() SetDataFolder $"root:Quanta" Wave T_Max=T_Max SVAR Loaded_file_path=Loaded_file_path String Row_to_Print String/G One_wave String Stat_result NVAR Total_peaks_number=Total_peaks_number NVAR Overall_Filter=Overall_Filter NVAR Bkg_noise_I=Bkg_noise_I NVAR Bkg_noise_dI=Bkg_noise_dI NVAR Detection_Mult=Detection_Mult NVAR Detection_Foot_Mult=Detection_Foot_Mult NVAR Smoothing_Factor_Add=Smoothing_Factor_Add NVAR Smoothing_Factor_diff1=Smoothing_Factor_diff1 NVAR Smooth_more=Smooth_more NVAR Smooth_Derivative=Smooth_Derivative NVAR Spike_Min_Imax=Spike_Min_Imax NVAR Spike_Max_T05=Spike_Max_T05 NVAR Spike_Max_Trise=Spike_Max_Trise NVAR Foot_Min_W=Foot_Min_W NVAR Foot_Min_H=Foot_Min_H NVAR SSFoot_Do=SSFoot_Do NVAR Native_Foot_Del=Native_Foot_Del NVAR Baseline_Drift=Baseline_Drift NVAR Overlap_Prc=Overlap_Prc SVAR Overlaps=Overlaps SVAR Values_to_show=Values_to_show SVAR Stats_names=Stats_names SVAR Population_Center=Population_Center String nb = "Stats" Notebook $nb defaultTab=36, statusWidth=238, pageMargins={72,72,72,72} Notebook $nb showRuler=1, rulerUnits=1, updating={1, 3600} Notebook $nb newRuler=Normal, justification=0, margins={0,0,468}, spacing={0,0,0}, tabs={}, rulerDefaults={"Arial",7,0,(0,0,0)} Notebook $nb ruler=Normal, specialChar={3,0,""} Notebook $nb text="\r" Notebook $nb text=Loaded_file_path+"\r" Notebook $nb text="Trace filtering (-3dB Gaussian):\r" Notebook $nb text="\tCurrent trace - "+num2str(Overall_Filter)+" Hz\r" If(Smooth_more) Notebook $nb text="\tAdditional trace filtering - "+num2str(Smoothing_Factor_Add)+" Hz\r" endif If(Smooth_Derivative) Notebook $nb text="\tDifferentiated trace filtering - "+num2str(Smoothing_Factor_diff1)+" Hz\r" endif Notebook $nb text="Noise level: SD(I) = "+num2str(Bkg_noise_I)+"; SD(dI/dt) = "+num2str(Bkg_noise_dI) Notebook $nb text="\rDetection threshold: Spikes - SD(dI/dt)*"+num2str(Detection_Mult)+"; Foot - SD(I)*"+num2str(Detection_Foot_Mult) Notebook $nb text="\rCutoffs used:\r" If(Spike_Min_Imax) Notebook $nb text="\tMin I(max) - "+num2str(Spike_Min_Imax)+" pA\r" endif If(Spike_Max_T05) Notebook $nb text="\tMax T(1/2) - "+num2str(Spike_Max_T05)+" ms\r" endif If(Spike_Max_Trise) Notebook $nb text="\tMax T(rise) - "+num2str(Spike_Max_Trise)+" ms\r" endif If(Foot_Min_H) Notebook $nb text="\tMin I(foot) - "+num2str(Foot_Min_H)+" pA\r" endif If(SSFoot_Do) Notebook $nb text="\tOnly PSF with steady states longer than "+num2str(Foot_Min_W)+" ms were analized\r" else If(Foot_Min_W) Notebook $nb text="\tMin T(foot) - "+num2str(Foot_Min_W)+" ms\r" endif endif If(Native_Foot_Del) Notebook $nb text="\t'Native' PSF were deleted\r" endif Notebook $nb text="\tAllowed baseline drift - "+num2str(Baseline_Drift)+"%\r" Notebook $nb text="\tAllowed maximal overlap - "+num2str(Overlap_Prc)+"%\r" Notebook $nb text="\tThe remaining overlaps - "+Overlaps Notebook $nb text="\r_______________________________________" Notebook $nb text="\r\rFound "+num2str(Total_peaks_number)+" events\r" Notebook $nb ruler=Normal; Notebook $nb margins={0,0,720}, rulerDefaults={"Arial",7,1,(0,0,0)}, tabs={36,72,108,144,180,216,252,288,324,360,396,432,468,504,541,576} Notebook $nb text=Stats_names If(Total_peaks_number==0) abort endif String Waves_to_show="Interspike_interval,"+Values_to_show Make/O/N=(Total_peaks_number-1) Interspike_interval Variable i=0 do If(i>0) Interspike_interval[i-1]=(T_Max[i]-T_Max[i-1])*1000 endif i+=1 while (i0)&(Rise_time[Peak_pnt]>Spike_Max_Trise)) return 2 endif If ((Spike_Max_T05>0)&(Peak_t05[Peak_pnt]>Spike_Max_T05)) return 2 endif If (Peak_Imax[Peak_pnt]0) CheckBox Detection_Spike_Imax,value=1 else CheckBox Detection_Spike_Imax,value=0 endif break case "Spike_Max_T05": If(Spike_Max_T05>0) CheckBox Detection_Spike_t05,value=1 else CheckBox Detection_Spike_t05,value=0 endif break case "Spike_Max_Trise": If(Spike_Max_Trise>0) CheckBox Detection_Spike_Trise,value=1 else CheckBox Detection_Spike_Trise,value=0 endif break case "Foot_Min_H": If(Foot_Min_H>0) CheckBox Detection_Foot_H,value=1 else CheckBox Detection_Foot_H,value=0 endif break case "Foot_Min_W": If(Foot_Min_W>0) CheckBox Detection_Foot_W,value=1 else CheckBox Detection_Foot_W,value=0 CheckBox Detection_SSFoot_Chk,value= 0 endif break endswitch End Function Close_Options(ctrlName) : ButtonControl String ctrlName SetDataFolder $"root:Quanta" String Win_name=WinName(0,64) NVAR T_Start=T_Start NVAR T_End=T_End WAVE Working_trace_copy=Working_trace_copy NVAR T_Delta=T_Delta NVAR Gain=Gain NVAR Gain_Temp=Gain_Temp T_Start=pnt2x(Working_trace_copy,0) T_End=pnt2x(Working_trace_copy,(numpnts(Working_trace_copy)-1)) T_Delta=(pnt2x(Working_trace_copy,1)-pnt2x(Working_trace_copy,0))*1000 Gain_Temp=Gain Dowindow/K $Win_name End Function Show_Extras(theTag) : ButtonControl String theTag SetDataFolder $"root:Quanta" NVAR Peak_ID=Peak_ID NVAR Show_Legend=Show_Legend NVAR Total_peaks_number=Total_peaks_number Variable Peak_pnt=Peak_ID-1 strswitch (theTag) case "Zoom_Off": Button Zoom_Off rename=Zoom_On, title="Hide Zoom" // MoveWindow /W=Main_window 3,80,549,394.25 execute "Zoom_Win()" AutoPositionWindow/E/M=0/R=Main_window Zoom_Win SetVariable ID,limits={1,(Total_peaks_number),1},win=Zoom_Win If(Peak_ID) Draw_lines_zoom_window(Peak_pnt) endif Dowindow/F Zoom_Win break case "Zoom_On": Button Zoom_On rename=Zoom_Off, title="Zoom Win" Dowindow/K Zoom_Win // MoveWindow /W=Main_window 3,80,762,394.25 break case "Legend_Off": Show_Legend=1 Button Legend_Off rename=Legend_On, title="Hide Legend" Generate_annotation(Peak_pnt) break case "Legend_On": Show_Legend=0 TextBox/W=Main_window/N=Peak_data/K Button Legend_On rename=Legend_Off, title="Show Legend" break endswitch End Function Show_options_panel(ctrlName) : ButtonControl String ctrlName if (CheckName("Options_Tab_Panels", 6)==0) execute "Options_Tab_Panels(0)" else Dowindow/F Options_Tab_Panels endif strswitch (ctrlName) case "Menu_FiltersScales": Redraw_Tabs(ctrlName,0) break case "Menu_Cutoffs": TabControl Tab_thing, value= 1 Redraw_Tabs(ctrlName,1) break case "Menu_Results": TabControl Tab_thing, value= 2 Redraw_Tabs(ctrlName,2) break case "Menu_Stats": TabControl Tab_thing, value= 3 Redraw_Tabs(ctrlName,3) break endswitch End Function Redraw_Tabs(name,tabNumber) String name Variable tabNumber SetDataFolder $"root:Quanta" String Existing_controls=ControlNameList("") NVAR T_Start=T_Start NVAR T_End=T_End WAVE Working_trace_copy=Working_trace_copy NVAR T_Delta=T_Delta NVAR Gain=Gain NVAR Gain_Temp=Gain_Temp T_Start=pnt2x(Working_trace_copy,0) T_End=pnt2x(Working_trace_copy,(numpnts(Working_trace_copy)-1)) T_Delta=(pnt2x(Working_trace_copy,1)-pnt2x(Working_trace_copy,0))*1000 Gain_Temp=Gain Options_Tab_Panels_controls(tabNumber) Button Recalculate_btn,win=Options_Tab_Panels, fColor=(0,0,0) If(tabNumber==0) NVAR Smooth_more=Smooth_more If(Smooth_more==1) CheckBox Scales_Smooth_Add,value=1 endif NVAR Smooth_Derivative=Smooth_Derivative If(Smooth_Derivative==1) CheckBox Scales_Smooth_Diff,value=1 endif endif If(tabNumber==1) NVAR Spike_Min_Imax=Spike_Min_Imax NVAR Spike_Max_T05=Spike_Max_T05 NVAR Spike_Max_Trise=Spike_Max_Trise NVAR Foot_Min_W=Foot_Min_W NVAR SSFoot_Do=SSFoot_Do NVAR Native_Foot_Del=Native_Foot_Del NVAR Foot_Min_H=Foot_Min_H SVAR Overlaps=Overlaps If(Spike_Min_Imax>0) CheckBox Detection_Spike_Imax,value=1 endif If(Spike_Max_T05>0) CheckBox Detection_Spike_t05,value=1 endif If(Spike_Max_Trise>0) CheckBox Detection_Spike_Trise,value=1 endif If(Foot_Min_H>0) CheckBox Detection_Foot_H,value=1 endif If(Foot_Min_W>0) CheckBox Detection_Foot_W,value=1 endif If(SSFoot_Do==1) CheckBox Detection_SSFoot_Chk,value=1 endif If(Native_Foot_Del==1) CheckBox Detection_Native_Foot_Chk,value=1 endif If(cmpstr(Overlaps,"Ignore")==0) PopupMenu Detection_Overlaps,mode=1, win=Options_Tab_Panels else If(cmpstr(Overlaps,"Separate")==0) PopupMenu Detection_Overlaps,mode=2, win=Options_Tab_Panels else PopupMenu Detection_Overlaps,mode=3, win=Options_Tab_Panels endif endif endif If(tabNumber==2) NVAR Show_Time=Show_Time NVAR Show_Base=Show_Base NVAR Show_Width=Show_Width NVAR Show_H=Show_H NVAR Show_Q=Show_Q NVAR Show_Molec=Show_Molec NVAR Show_Rise_t=Show_Rise_t NVAR Show_Rise_r=Show_Rise_r NVAR Show_Fall_t=Show_Fall_t NVAR Show_Fall_r=Show_Fall_r NVAR Show_Ft_H=Show_Ft_H NVAR Show_Ft_width=Show_Ft_width NVAR Show_Ft_Q=Show_Ft_Q NVAR Show_Ft_molec=Show_Ft_molec SVAR Fit_method=Fit_method SetDrawEnv fname= "Arial" DrawText 115,191,"%" If(Show_Time==1) CheckBox Results_Show1,value=1 endif If(Show_Base==1) CheckBox Results_Show2,value=1 endif If(Show_Width==1) CheckBox Results_Show4,value=1 endif If(Show_H==1) CheckBox Results_Show5,value=1 endif If(Show_Q==1) CheckBox Results_Show6,value=1 endif If(Show_Molec==1) CheckBox Results_Show7,value=1 endif If(Show_Rise_t==1) CheckBox Results_Show8,value=1 endif If(Show_Rise_r==1) CheckBox Results_Show9,value=1 endif If(Show_Fall_t==1) CheckBox Results_Show10,value=1 endif If(Show_Fall_r==1) CheckBox Results_Show11,value=1 endif If(Show_Ft_H==1) CheckBox Results_Show12,value=1 endif If(Show_Ft_width==1) CheckBox Results_Show13,value=1 endif If(Show_Ft_Q==1) CheckBox Results_Show14,value=1 endif If(Show_Ft_molec==1) CheckBox Results_Show15,value=1 endif If(cmpstr(Fit_method,"Line")==0) PopupMenu Results_Fallfit,mode=1,popvalue="Line", win=Options_Tab_Panels else If(cmpstr(Fit_method,"Exp")==0) PopupMenu Results_Fallfit,mode=2,popvalue="Exp", win=Options_Tab_Panels else PopupMenu Results_Fallfit,mode=3,popvalue="DblExp", win=Options_Tab_Panels SetVariable Results_Fall_Chi, win=Options_Tab_Panels, disable=0 endif endif endif If(tabNumber==3) SVAR Population_Center=Population_Center SVAR Norm_point=Norm_point If(cmpstr(Population_Center,"Mean")==0) PopupMenu Stats_Population,mode=2,popvalue="Mean", win=Options_Tab_Panels endif If(cmpstr(Norm_point,"Rise")==0) PopupMenu Stats_AvePeak,mode=2,popvalue="Rise", win=Options_Tab_Panels endif endif end Function Overlaps_PopMenu(theTag,popNum,popStr) : PopupMenuControl String theTag Variable popNum String popStr SetDataFolder $"root:Quanta" SVAR Overlaps=Overlaps Overlaps=popStr Redraw_Tabs(theTag,1) End Function Scales_Switch(ctrlName,checked) : CheckBoxControl String ctrlName Variable checked SetDataFolder $"root:Quanta" Variable Radio_On=1 strswitch (ctrlName) case "Scales_Change_Delta": Radio_On= 1 SetVariable Scales_End_time,disable=2 SetVariable Scales_Delta_Time,disable=0 break case "Scales_Change_End": Radio_On= 2 Set