def ppr_peak(): # Get function values decay_func = stf.leastsq(0) # Create time from fit start to next peak x = np.arange(stf.get_fit_start(), stf.peak_index()) # Create fitted curve up until peak trace = [(decay_func['Offset'] + decay_func['Amp_0'] * np.exp(-(ind/10.0)/decay_func['Tau_0'])) for ind, val in enumerate(x)] # Find peak value peak_val = stf.get_peak()-stf.get_base() print('The measured peak is {0} pA'.format(peak_val)) # Find value of fit at peak fit_peak = trace[-1] - stf.get_base() print('Tau is {0} pA'.format(decay_func['Tau_0'])) print('The fitted peak is {0} pA'.format(fit_peak)) print('The baseline is {0} pA'.format(stf.get_base())) # stf.new_window(trace) final_peak = peak_val - fit_peak print('The final peak is {0} pA'.format(final_peak)) return True
def fexpbde(p,x): tpeak = p[3]*p[1]*np.log(p[3]/p[1])/(p[3]-p[1]) adjust = 1.0/((1.0-np.exp(-tpeak/p[3]))-(1.0-np.exp(-tpeak/p[1]))); e1=np.exp((p[0]-x)/p[1]); e2=np.exp((p[0]-x)/p[3]); # normalize the amplitude so that the peak really is the peak: ret = adjust*p[2]*e1 - adjust*p[2]*e2 + stf.get_base(); start_index = 0 for elem in x: if ( elem < p[0] ): start_index = start_index+1 else: break ret[ 0 : start_index ] = stf.get_base() return ret
def peakscale(): """ Scale the selected traces in the currently active channel to their mean peak amplitude. """ # Measure baseline in selected traces base = [] for i in stf.get_selected_indices(): stf.set_trace(i) base.append(stf.get_base()) # Subtract baseline from selected traces stf.subtract_base() # Measure peak amplitudes in baseline-subtracted traces stf.select_all() peak = [] for i in stf.get_selected_indices(): stf.set_trace(i) peak.append(stf.get_peak()) # Calculate scale factor to make peak equal to the mean peak amplitude scale_factor = peak / np.mean(peak) # Scale the traces and apply offset equal to the mean baseline scaled_traces = [ stf.get_trace(i) / scale_factor[i] + np.mean(base) for i in stf.get_selected_indices() ] # Close window of baseline-subtracted traces stf.close_this() return stf.new_window_list(scaled_traces)
def jjm_resistance(baseline_start, baseline_end, cap_trans_start, cap_trans_end, amplitude): #time arguments in msec, amplitude argument in mV stf.set_channel(0) stf.set_base_start(baseline_start, True) stf.set_base_end(baseline_end, True) stf.set_peak_start(cap_trans_start, True) stf.set_peak_end(cap_trans_end, True) stf.measure() baseline = float(stf.get_base()) peak = float(stf.get_peak()) real_peak = baseline - peak amplitude = float(amplitude) amplitude_V = amplitude / (10**(3)) real_peak_A = real_peak / (10**(12)) Rs_Ohm = amplitude_V / abs(real_peak_A) Rs = Rs_Ohm / (10**(6)) return (real_peak, Rs)
def fexpbde(p, x): tpeak = p[3] * p[1] * np.log(p[3] / p[1]) / (p[3] - p[1]) adjust = 1.0 / ((1.0 - np.exp(-tpeak / p[3])) - (1.0 - np.exp(-tpeak / p[1]))) e1 = np.exp((p[0] - x) / p[1]) e2 = np.exp((p[0] - x) / p[3]) # normalize the amplitude so that the peak really is the peak: ret = adjust * p[2] * e1 - adjust * p[2] * e2 + stf.get_base() start_index = 0 for elem in x: if (elem < p[0]): start_index = start_index + 1 else: break ret[0:start_index] = stf.get_base() return ret
def SBR(): """ Calculate signal-to-baseline ratio (SBR) or delta F / F0 for traces in the active window. The result is expressed as a %. Useful for imaging data. Ensure that the baseline cursors are positioned appropriately. """ SBR_traces = [ 100 * (stf.get_trace(i) - stf.get_base()) / stf.get_base() for i in range(stf.get_size_channel()) ] stf.new_window_list(SBR_traces) stf.set_yunits('%') return
def subtract_base(): """ """ subtracted_traces = [] for i in range(stf.get_size_channel()): stf.set_trace(i) subtracted_traces.append(stf.get_trace() - stf.get_base()) stf.new_window_list(subtracted_traces) return
def resistance( base_start, base_end, peak_start, peak_end, amplitude): """Calculates the resistance from a series of voltage clamp traces. Keyword arguments: base_start -- Starting index (zero-based) of the baseline cursors. base_end -- End index (zero-based) of the baseline cursors. peak_start -- Starting index (zero-based) of the peak cursors. peak_end -- End index (zero-based) of the peak cursors. amplitude -- Amplitude of the voltage command. Returns: The resistance. """ if not stf.check_doc(): print('Couldn\'t find an open file; aborting now.') return 0 #A temporary array to calculate the average: array = np.empty( (stf.get_size_channel(), stf.get_size_trace()) ) for n in range( 0, stf.get_size_channel() ): # Add this trace to set: array[n] = stf.get_trace( n ) # calculate average and create a new section from it: stf.new_window( np.average(set, 0) ) # set peak cursors: # -1 means all points within peak window. if not stf.set_peak_mean(-1): return 0 if not stf.set_peak_start(peak_start): return 0 if not stf.set_peak_end(peak_end): return 0 # set base cursors: if not stf.set_base_start(base_start): return 0 if not stf.set_base_end(base_end): return 0 # measure everything: stf.measure() # calculate r_seal and return: return amplitude / (stf.get_peak()-stf.get_base())
def get_amplitude(base, peak, delta, trace=None): """ Calculates the amplitude deviation (peak-base) in units of the Y-axis Arguments: base -- Starting point (in ms) of the baseline cursor. peak -- Starting point (in ms) of the peak cursor. delta -- Time interval to calculate baseline/find the peak. trace -- Zero-based index of the trace to be processed, if None then current trace is computed. Returns: A float with the variation of the amplitude. False if Example: get_amplitude(980,1005,10,i) returns the variation of the Y unit of the trace i between peak value (10050+10) msec and baseline (980+10) msec """ # sets the current trace or the one given in trace if trace is None: sweep = stf.get_trace_index() else: if type(trace) != int: print('trace argument admits only intergers') return False sweep = trace # set base cursors: if not(stf.set_base_start(base, True)): return False # out-of range if not(stf.set_base_end(base+delta, True)): return False # set peak cursors: if not(stf.set_peak_start(peak, True)): return False # out-of range if not(stf.set_peak_end(peak+delta, True)): return False # update measurements stf.set_trace(sweep) amplitude = stf.get_peak()-stf.get_base() return amplitude
def jjm_peak(baseline_start, baseline_end, p_start, p_end): #time arguments in msec, amplitude argument in mV stf.set_channel(0) stf.set_base_start(baseline_start, True) stf.set_base_end(baseline_end, True) stf.set_peak_start(p_start, True) stf.set_peak_end(p_end, True) stf.measure() baseline = float(stf.get_base()) peak = float(stf.get_peak()) real_peak = abs(baseline - peak) return (real_peak)
def resistance(base_start, base_end, peak_start, peak_end, amplitude): """Calculates the resistance from a series of voltage clamp traces. Keyword arguments: base_start -- Starting index (zero-based) of the baseline cursors. base_end -- End index (zero-based) of the baseline cursors. peak_start -- Starting index (zero-based) of the peak cursors. peak_end -- End index (zero-based) of the peak cursors. amplitude -- Amplitude of the voltage command. Returns: The resistance. """ if not stf.check_doc(): print('Couldn\'t find an open file; aborting now.') return 0 #A temporary array to calculate the average: array = np.empty((stf.get_size_channel(), stf.get_size_trace())) for n in range(0, stf.get_size_channel()): # Add this trace to set: array[n] = stf.get_trace(n) # calculate average and create a new section from it: stf.new_window(np.average(set, 0)) # set peak cursors: # -1 means all points within peak window. if not stf.set_peak_mean(-1): return 0 if not stf.set_peak_start(peak_start): return 0 if not stf.set_peak_end(peak_end): return 0 # set base cursors: if not stf.set_base_start(base_start): return 0 if not stf.set_base_end(base_end): return 0 # measure everything: stf.measure() # calculate r_seal and return: return amplitude / (stf.get_peak() - stf.get_base())
def get_amplitude(base, peak, delta, trace=None): """ Calculates the amplitude deviation (peak-base) in units of the Y-axis Arguments: base -- Starting point (in ms) of the baseline cursor. peak -- Starting point (in ms) of the peak cursor. delta -- Time interval to calculate baseline/find the peak. trace -- Zero-based index of the trace to be processed, if None then current trace is computed. Returns: A float with the variation of the amplitude. False if Example: get_amplitude(980,1005,10,i) returns the variation of the Y unit of the trace i between peak value (10050+10) msec and baseline (980+10) msec """ # sets the current trace or the one given in trace if trace is None: sweep = stf.get_trace_index() else: if type(trace) != int: print('trace argument admits only intergers') return False sweep = trace # set base cursors: if not (stf.set_base_start(base, True)): return False # out-of range if not (stf.set_base_end(base + delta, True)): return False # set peak cursors: if not (stf.set_peak_start(peak, True)): return False # out-of range if not (stf.set_peak_end(peak + delta, True)): return False # update measurements stf.set_trace(sweep) amplitude = stf.get_peak() - stf.get_base() return amplitude
def return_base_for_file(start_sweep, end_sweep): #dict_to_return = {} baselines = [] for sweep in range(start_sweep, end_sweep): stf.set_trace(sweep) stf.set_base_start(100, is_time=True) stf.set_base_end(125, is_time=True) baselines.append(stf.get_base()) file_baseline = np.mean(baselines) #dict_to_return[stf.get_filename()] = file_baseline #df_out = pd.DataFrame(dict_to_return) #file_name = stf.get_filename() #df_out.to_excel('/Users/johnmarshall/Documents/Analysis/eCB_paper/'+str(file_name)+'holding_current.xlsx') return (file_baseline)
def get_amplitude_select_NMDA(amplithresh): stf.unselect_all() stf.set_peak_direction('both') # total number of traces traces = stf.get_size_channel() selectedtraces, i = 0, 0 while i < traces: stf.set_trace(i) amplitude = stf.get_peak() - stf.get_base() if amplitude < amplithresh and amplitude > 0: # print(i) stf.select_trace(i) i += 1 selectedtraces += 1 else: i += 1 return selectedtraces
def trainpeaks(): """ Measure a 20 Hz train of peaks starting at 260 ms into the trace """ pk = [] for i in range(5): stf.set_base_start( int(255 / stf.get_sampling_interval()) + (50 / stf.get_sampling_interval()) * i) stf.set_base_end( int(259 / stf.get_sampling_interval()) + (50 / stf.get_sampling_interval()) * i) stf.set_peak_start( int(260.5 / stf.get_sampling_interval()) + (50 / stf.get_sampling_interval()) * i) stf.set_peak_end( int(270.5 / stf.get_sampling_interval()) + (50 / stf.get_sampling_interval()) * i) stf.measure() pk.append(stf.get_peak() - stf.get_base()) # Create table of results dictlist = [("Peak 1", pk[0])] dictlist += [("Peak 2", pk[1])] dictlist += [("Peak 3", pk[2])] dictlist += [("Peak 4", pk[3])] dictlist += [("Peak 5", pk[4])] retval = dict(dictlist) stf.show_table(retval, "peaks, Section #%i" % float(stf.get_trace_index() + 1)) # Create table of results dictlist = [("Peak 1", pk[0] / pk[0] * 100)] dictlist += [("Peak 2", pk[1] / pk[0] * 100)] dictlist += [("Peak 3", pk[2] / pk[0] * 100)] dictlist += [("Peak 4", pk[3] / pk[0] * 100)] dictlist += [("Peak 5", pk[4] / pk[0] * 100)] retval = dict(dictlist) stf.show_table( retval, "norm peaks, Section #%i" % float(stf.get_trace_index() + 1)) return
def batch_integration(): """ Perform batch integration between the decay/fit cursors of all traces in the active window """ n = int(stf.get_fit_end() + 1 - stf.get_fit_start()) x = [i * stf.get_sampling_interval() for i in range(n)] dictlist = [] for i in range(stf.get_size_channel()): stf.set_trace(i) y = stf.get_trace()[int(stf.get_fit_start()):int(stf.get_fit_end() + 1)] auc = np.trapz(y - stf.get_base(), x) dictlist += [("%i" % (i + 1), auc)] retval = dict(dictlist) stf.show_table(retval, "Area Under Curve") stf.set_trace(0) return
def Train10AP(): """ An example function to perform peak measurements of a train of evoked fluorescence signals in the active window """ # Setup offset = 40 stf.set_base_start(0) stf.set_peak_start(offset - 2) stf.measure() base = stf.get_base() stf.set_peak_mean(1) stf.set_peak_direction("up") peak = [] # Get peak measurements for i in range(10): stf.set_peak_start(offset + (i * 4) - 2) stf.set_peak_end(offset + (i * 4) + 2) stf.measure() peak.append(stf.get_peak()) # Plot fit in a new window matrix = np.zeros((2, stf.get_size_trace())) * np.nan matrix[0, :] = stf.get_trace() for i in range(10): matrix[1, offset + (i * 4) - 1:offset + (i * 4) + 2] = peak[i] stf.new_window_matrix(matrix) # Create table of results retval = [] for i in range(10): retval += [("Peak %d" % (i), peak[i] - base)] retval = dict(retval) stf.show_table(retval, "Train10AP, Section #%i" % float(stf.get_trace_index() + 1)) return
def fit_experiment(params, pulse_length, function_to_fit): num_sweeps = stf.get_size_channel() stf.set_channel(0) stf.set_trace(0) #jjm_analysis.set_params(params); #stf.measure(); #this is in samples #peak_index = stf.peak_index(); #stf.set_fit_start(peak_index, is_time=False); #fit_start_time = peak_index*stf.get_sampling_interval(); #stf.set_fit_end(fit_start_time+pulse_length-(10*stf.get_sampling_interval()), is_time=True); #fit_func = stf.leastsq(function_to_fit); #fit_func['Baseline(pA)']=stf.get_base(); #fit_df = pd.DataFrame(fit_func, index=[0]); fits = [] traces = [] for x in range(0, num_sweeps): stf.set_trace(x) jjm_analysis.set_params(params) stf.measure() #this is in samples peak_index = stf.peak_index() stf.set_fit_start(peak_index, is_time=False) fit_start_time = peak_index * stf.get_sampling_interval() stf.set_fit_end(fit_start_time + pulse_length - (10 * stf.get_sampling_interval()), is_time=True) sweep_fit = stf.leastsq(function_to_fit) sweep_fit['Baseline(pA)'] = stf.get_base() fits.append(sweep_fit) traces.append(x) fit_df = pd.DataFrame(fits) return (fit_df)
def glu_iv(pulses=13, subtract_base=True): """Calculates an iv from a repeated series of fast application and voltage pulses. Keyword arguments: pulses -- Number of pulses for the iv. subtract_base -- If True (default), baseline will be subtracted. Returns: True if successful. """ # Some ugly definitions for the time being # Cursors are in ms here. gFitEnd = 330.6 # fit end cursor is variable gFSelect = 0 # Monoexp gDictSize = stf.leastsq_param_size( gFSelect) + 2 # Parameters, chisqr, peak value gBaseStart = 220.5 # Start and end of the baseline before the control pulse, in ms gBaseEnd = 223.55 gPeakStart = 223.55 # Start and end of the peak cursors for the control pulse, in ms gPeakEnd = 253.55 if (gDictSize < 0): print('Couldn\'t retrieve function id=%d, aborting now.' % gFSelect) return False if (not (stf.check_doc())): print('Couldn\'t find an open file; aborting now.') return False # analyse iv, subtract baseline if requested: ivtools.analyze_iv(pulses) if (subtract_base == True): if (not (stf.set_base_start(gBaseStart, True))): return False if (not (stf.set_base_end(gBaseEnd, True))): return False stf.measure() stf.select_all() stf.subtract_base() # set cursors: if (not (stf.set_peak_start(gPeakStart, True))): return False if (not (stf.set_peak_end(gPeakEnd, True))): return False if (not (stf.set_base_start(gBaseStart, True))): return False if (not (stf.set_base_end(gBaseEnd, True))): return False if (not (stf.set_fit_end(gFitEnd, True))): return False if (not (stf.set_peak_mean(3))): return False if (not (stf.set_peak_direction("both"))): return False # A list for dictionary keys and values: dict_keys = [] dict_values = np.empty((gDictSize, stf.get_size_channel())) firstpass = True for n in range(0, stf.get_size_channel()): if (stf.set_trace(n) == False): print('Couldn\'t set a new trace; aborting now.') return False print('Analyzing trace %d of %d' % (n + 1, stf.get_size_channel())) # set the fit window cursors: if (not (stf.set_fit_start(stf.peak_index()))): return False # Least-squares fitting: p_dict = stf.leastsq(gFSelect) if (p_dict == 0): print('Couldn\'t perform a fit; aborting now.') return False # Create an empty list: tempdict_entry = [] row = 0 for k, v in p_dict.iteritems(): if (firstpass == True): dict_keys.append(k) dict_values[row][n] = v row = row + 1 if (firstpass): dict_keys.append("Peak amplitude") dict_values[row][n] = stf.get_peak() - stf.get_base() firstpass = False retDict = dict() # Create the dictionary for the table: entry = 0 for elem in dict_keys: retDict[elem] = dict_values[entry].tolist() entry = entry + 1 return stf.show_table_dictlist(retDict)
def return_holding_current(selected_wb, raw_wb): wb_ = xlrd.open_workbook(selected_wb) sheets = [ str(sheet.name) for sheet in wb_.sheets() if 'normalized' in str(sheet.name) ] sheets_to_load_from_raw = [ sheet.strip('normalized') + 'iled_files' for sheet in sheets ] wb_raw = xlrd.open_workbook(raw_wb) raw_sheets = [ str(sheet.name) for sheet in wb_raw.sheets() if 'compiled_files' in str(sheet.name) ] baseline_files = [] exp_files = [] for raw_sheet in raw_sheets: try: df = pd.read_excel(wb_raw, engine='xlrd', sheetname=str(raw_sheet), index_col=[0, 1]) files_in_experiment = df.index.levels[0].values[:2] baseline_files.append(files_in_experiment[0]) exp_files.append(files_in_experiment[1]) except: pass print(baseline_files) baseline_files_to_load = [] exp_files_to_load = [] rootsearchdir = '/Users/johnmarshall/Documents/Analysis/RecordingData/' for fname, efname in zip(baseline_files, exp_files): try: if 'TSeries' in fname: dir_data = search_dir_iterative_for_extension_tupleoutput( rootsearchdir, str(fname + 'vrecd_loaded.csv')) else: dir_data = search_dir_iterative_for_extension_tupleoutput( rootsearchdir, fname) baseline_files_to_load.append(dir_data[1][1] + '/' + dir_data[1][0]) dir_data = search_dir_iterative_for_extension_tupleoutput( rootsearchdir, efname) exp_files_to_load.append(dir_data[1][1] + '/' + dir_data[1][0]) except IndexError: print('could not find:', fname) pass print(baseline_files_to_load) dict_to_return = {} holding_current_time_series = {} for f, ef in zip(baseline_files_to_load, exp_files_to_load): currents = [] print(f) if f.endswith('.abf'): stf.file_open(f) else: if 'TSeries' in f: sweeps_compiled_from_pv_tseries = pv.import_t_series_episodic( f.strip('vrecd_loaded.csv')) pv.plot_episodic_array(sweeps_compiled_from_pv_tseries) baselines = [] for sweep in range((stf.get_size_channel() - 30), stf.get_size_channel()): stf.set_trace(sweep) stf.set_base_start(100, is_time=True) stf.set_base_end(100, is_time=True) baselines.append(stf.get_base()) file_baseline = np.mean(baselines) currents.append(file_baseline) holding_current_time_series[f] = baselines stf.file_open(ef) baselines = [] for sweep in range((stf.get_size_channel() - 15), stf.get_size_channel()): stf.set_trace(sweep) stf.set_base_start(100, is_time=True) stf.set_base_end(100, is_time=True) baselines.append(stf.get_base()) file_baseline = np.mean(baselines) currents.append(file_baseline) dict_to_return[f] = currents df_out = pd.DataFrame(dict_to_return) time_series_df = pd.DataFrame(holding_current_time_series) df_out.to_excel( '/Users/johnmarshall/Documents/Analysis/eCB_paper/holding_current.xlsx' ) time_series_df.to_excel( '/Users/johnmarshall/Documents/Analysis/eCB_paper/holding_current_time_series.xlsx' ) return (df_out)
def EPSPtrains(latency=200, numStim=4, intvlList=[1, 0.8, 0.6, 0.4, 0.2, 0.1, 0.08, 0.06, 0.04, 0.02]): # Initialize numTrains = len(intvlList) # Number of trains intvlArray = np.array(intvlList) * 1000 # Units in ms si = stf.get_sampling_interval() # Units in ms # Background subtraction traceBaselines = [] subtractedTraces = [] k = 1e-4 x = [i * stf.get_sampling_interval() for i in range(stf.get_size_trace())] for i in range(numTrains): stf.set_trace(i) z = x y = stf.get_trace() traceBaselines.append(y) ridx = [] if intvlArray[i] > 500: for j in range(numStim): ridx += range( int(round(((intvlArray[i] * j) + latency - 1) / si)), int(round( ((intvlArray[i] * (j + 1)) + latency - 1) / si)) - 1) else: ridx += range( int(round((latency - 1) / si)), int( round(((intvlArray[i] * (numStim - 1)) + latency + 500) / si)) - 1) ridx += range(int(round(4999 / si)), int(round(5199 / si))) z = np.delete(z, ridx, 0) y = np.delete(y, ridx, 0) yi = np.interp(x, z, y) yf = signal.symiirorder1(yi, (k**2), 1 - k) traceBaselines.append(yf) subtractedTraces.append(stf.get_trace() - yf) stf.new_window_list(traceBaselines) stf.new_window_list(subtractedTraces) # Measure depolarization # Initialize variables a = [] b = [] # Set baseline start and end cursors stf.set_base_start(np.round( (latency - 50) / si)) # Average during 50 ms period before stimulus stf.set_base_end(np.round(latency / si)) # Set fit start cursor stf.set_fit_start(np.round(latency / si)) stf.set_fit_end( np.round(((intvlArray[1] * (numStim - 1)) + latency + 1000) / si)) # Include a 1 second window after last stimulus # Start AUC calculations for i in range(numTrains): stf.set_trace(i) stf.measure() b.append(stf.get_base()) n = int(stf.get_fit_end() + 1 - stf.get_fit_start()) x = np.array([k * stf.get_sampling_interval() for k in range(n)]) y = stf.get_trace()[int(stf.get_fit_start()):int(stf.get_fit_end() + 1)] a.append(np.trapz(y - b[i], x)) # Units in V.s return a
def glu_iv( pulses = 13, subtract_base=True ): """Calculates an iv from a repeated series of fast application and voltage pulses. Keyword arguments: pulses -- Number of pulses for the iv. subtract_base -- If True (default), baseline will be subtracted. Returns: True if successful. """ # Some ugly definitions for the time being # Cursors are in ms here. gFitEnd = 330.6 # fit end cursor is variable gFSelect = 0 # Monoexp gDictSize = stf.leastsq_param_size( gFSelect ) + 2 # Parameters, chisqr, peak value gBaseStart = 220.5 # Start and end of the baseline before the control pulse, in ms gBaseEnd = 223.55 gPeakStart = 223.55 # Start and end of the peak cursors for the control pulse, in ms gPeakEnd = 253.55 if ( gDictSize < 0 ): print('Couldn\'t retrieve function id=%d, aborting now.'%gFSelect) return False if ( not(stf.check_doc()) ): print('Couldn\'t find an open file; aborting now.') return False # analyse iv, subtract baseline if requested: ivtools.analyze_iv( pulses ) if ( subtract_base == True ): if ( not(stf.set_base_start( gBaseStart, True )) ): return False if ( not(stf.set_base_end( gBaseEnd, True )) ): return False stf.measure() stf.select_all() stf.subtract_base() # set cursors: if ( not(stf.set_peak_start( gPeakStart, True )) ): return False if ( not(stf.set_peak_end( gPeakEnd, True )) ): return False if ( not(stf.set_base_start( gBaseStart, True )) ): return False if ( not(stf.set_base_end( gBaseEnd, True )) ): return False if ( not(stf.set_fit_end( gFitEnd, True )) ): return False if ( not(stf.set_peak_mean( 3 )) ): return False if ( not(stf.set_peak_direction( "both" )) ): return False # A list for dictionary keys and values: dict_keys = [] dict_values = np.empty( (gDictSize, stf.get_size_channel()) ) firstpass = True for n in range( 0, stf.get_size_channel() ): if ( stf.set_trace( n ) == False ): print('Couldn\'t set a new trace; aborting now.') return False print('Analyzing trace %d of %d'%( n+1, stf.get_size_channel() ) ) # set the fit window cursors: if ( not(stf.set_fit_start( stf.peak_index() )) ): return False # Least-squares fitting: p_dict = stf.leastsq( gFSelect ) if ( p_dict == 0 ): print('Couldn\'t perform a fit; aborting now.') return False # Create an empty list: tempdict_entry = [] row = 0 for k, v in p_dict.iteritems(): if ( firstpass == True ): dict_keys.append( k ) dict_values[row][n] = v row = row+1 if ( firstpass ): dict_keys.append( "Peak amplitude" ) dict_values[row][n] = stf.get_peak()-stf.get_base() firstpass = False retDict = dict() # Create the dictionary for the table: entry = 0 for elem in dict_keys: retDict[ elem ] = dict_values[entry].tolist() entry = entry+1 return stf.show_table_dictlist( retDict )
def wcp(V_step=-5, step_start=10, step_duration=20): """ Measures whole cell properties. Specifically, this function returns the voltage clamp step estimates of series resistance, input resistance, cell membrane resistance, cell membrane capacitance, cell surface area and specific membrane resistance. The series (or access) resistance is obtained my dividing the voltage step by the peak amplitude of the current transient (Ogden, 1994): Rs = V / Ip The input resistance is obtained by dividing the voltage step by the average amplitude of the steady-state current (Barbour, 2014): Rin = V / Iss The cell membrane resistance is calculated by subtracting the series resistance from the input resistance (Barbour, 1994): Rm = Rin - Rs The cell membrane capacitance is estimated by dividing the transient charge by the size of the voltage-clamp step (Taylor et al. 2012): Cm = Q / V The cell surface area is estimated by dividing the cell capacitance by the specific cell capacitance, c (1.0 uF/cm^2; Gentet et al. 2000; Niebur, 2008): Area = Cm / c The specific membrane resistance is calculated by multiplying the cell membrane resistance with the cell surface area: rho = Rm * Area Users should be aware of the approximate nature of determining cell capacitance and derived parameters from the voltage-clamp step method (Golowasch, J. et al., 2009) References: Barbour, B. (2014) Electronics for electrophysiologists. Microelectrode Techniques workshop tutorial. www.biologie.ens.fr/~barbour/electronics_for_electrophysiologists.pdf Gentet, L.J., Stuart, G.J., and Clements, J.D. (2000) Direct measurement of specific membrane capacitance in neurons. Biophys J. 79(1):314-320 Golowasch, J. et al. (2009) Membrane Capacitance Measurements Revisited: Dependence of Capacitance Value on Measurement Method in Nonisopotential Neurons. J Neurophysiol. 2009 Oct; 102(4): 2161-2175. Niebur, E. (2008), Scholarpedia, 3(6):7166. doi:10.4249/scholarpedia.7166 www.scholarpedia.org/article/Electrical_properties_of_cell_membranes (revision #13938, last accessed 30 April 2018) Ogden, D. Chapter 16: Microelectrode electronics, in Ogden, D. (ed.) Microelectrode Techniques. 1994. 2nd Edition. Cambridge: The Company of Biologists Limited. Taylor, A.L. (2012) What we talk about when we talk about capacitance measured with the voltage-clamp step method J Comput Neurosci. 32(1):167-175 """ # Error checking if stf.get_yunits() != "pA": raise ValueError('The recording is not voltage clamp') # Prepare variables from input arguments si = stf.get_sampling_interval() t0 = step_start / si l = step_duration / si # Set cursors and update measurements stf.set_base_start((step_start - 1) / si) stf.set_base_end(t0 - 1) stf.set_peak_start(t0) stf.set_peak_end((step_start + 1) / si) stf.set_fit_start(t0) stf.set_fit_end(t0 + l - 1) stf.set_peak_direction("both") stf.measure() # Calculate series resistance (Rs) from initial transient b = stf.get_base() Rs = 1000 * V_step / (stf.get_peak() - b) # in Mohm # Calculate charge delivered during the voltage clamp step n = int(stf.get_fit_end() + 1 - stf.get_fit_start()) x = [i * stf.get_sampling_interval() for i in range(n)] y = stf.get_trace()[int(stf.get_fit_start()):int(stf.get_fit_end() + 1)] Q = np.trapz(y - b, x) # Set cursors and update measurements stf.set_base_start(t0 + l - 1 - (step_duration / 4) / si) stf.set_base_end(t0 + l - 1) stf.measure() # Measure steady state current and calculate input resistance I = stf.get_base() - b Rin = 1000 * V_step / I # in Mohm # Calculate cell membrane resistance Rm = Rin - Rs # in Mohm # Calculate voltage-clamp step estimate of the cell capacitance t = x[-1] - x[0] Cm = (Q - I * t) / V_step # in pF # Estimate membrane surface area, where the capacitance per unit area is 1.0 uF/cm^2 A = Cm * 1e-06 / 1.0 # in cm^2 # Calculate specific membrane resistance rho = 1e+03 * Rm * A # in kohm.cm^2; usually 10 at rest # Create table of results retval = [] retval += [("Holding current (pA)", b)] retval += [("Series resistance (Mohm)", Rs)] retval += [("Input resistance (Mohm)", Rin)] retval += [("Cell resistance (Mohm)", Rm)] retval += [("Cell capacitance (pF)", Cm)] retval += [("Surface area (um^2)", A * 1e+04**2)] retval += [("Membrane resistivity (kohm.cm^2)", rho)] retval = dict(retval) stf.show_table(retval, "Whole-cell properties") return retval