Beispiel #1
0
def count_aps():
    """
    Shows a result table with the number of action potentials (i.e
    events whose potential is above 0 mV) in selected traces.  If
    no trace is selected, then the current trace is analyzed.

    Returns:
    False if document is not open.
    """
    if not stf.check_doc():
        print("Open file first")
        return False
  
    if len( stf.get_selected_indices() )==0: 
        sel_trace = [ stf.get_trace_index()]
    else: 
        sel_trace = stf.get_selected_indices()

    mytable = dict()
    for trace in sel_trace:
        tstart = 0
        tend = stf.get_size_trace(trace)*stf.get_sampling_interval()
        threshold = 0
        spikes = count_events(tstart, tend, threshold, True, trace, True)
        mytable["Trace %.3d" %trace] = spikes

    stf.show_table(mytable)

    return True
Beispiel #2
0
def count_aps():
    """
    Shows a result table with the number of action potentials (i.e
    events whose potential is above 0 mV) in selected traces.  If
    no trace is selected, then the current trace is analyzed.

    Returns:
    False if document is not open.
    """
    if not stf.check_doc():
        print("Open file first")
        return False

    if len(stf.get_selected_indices()) == 0:
        sel_trace = [stf.get_trace_index()]
    else:
        sel_trace = stf.get_selected_indices()

    mytable = dict()
    for trace in sel_trace:
        tstart = 0
        tend = stf.get_size_trace(trace) * stf.get_sampling_interval()
        threshold = 0
        spikes = count_events(tstart, tend, threshold, True, trace, True)
        mytable["Trace %.3d" % trace] = spikes

    stf.show_table(mytable)

    return True
Beispiel #3
0
def monoexpfit(optimization=True, Tn=20):
    """
    Fits monoexponential function with offset to data between the fit cursors
    in the current trace of the active channel using a Chebyshev-Levenberg-
    Marquardt hybrid algorithm. Optimization requires Scipy. Setting optimization
    to False forces this function to use just the Chebyshev algorithm. The maximum
    order of the Chebyshev polynomials can be set using Tn.
    """

    # Get data
    fit_start = stf.get_fit_start()
    fit_end = stf.get_fit_end()
    y = np.double(stf.get_trace()[fit_start:fit_end])
    si = stf.get_sampling_interval()
    l = len(y)
    t = si * np.arange(0, l, 1, np.double)

    # Define monoexponential function
    def f(t, *p):
        return p[0] + p[1] * np.exp(-t / p[2])

    # Get initial values from Chebyshev transform fit
    init = chebexp(1, Tn)
    p0 = (init.get('Offset'), )
    p0 += (init.get('Amp_0'), )
    p0 += (init.get('Tau_0'), )

    # Optimize (if applicable)
    if optimization == True:
        # Optimize fit using Levenberg-Marquardt algorithm
        options = {"ftol": 2.22e-16, "xtol": 2.22e-16, "gtol": 2.22e-16}
        [p, pcov] = optimize.curve_fit(f, t, y, p0, **options)
    elif optimization == False:
        p = list(p0)
    fit = f(t, *p)

    # Calculate SSE
    SSE = np.sum((y - fit)**2)

    # Plot fit in a new window
    matrix = np.zeros((2, stf.get_size_trace())) * np.nan
    matrix[0, :] = stf.get_trace()
    matrix[1, fit_start:fit_end] = fit
    stf.new_window_matrix(matrix)

    # Create table of results
    retval = [("p0_Offset", p[0])]
    retval += [("p1_Amp_0", p[1])]
    retval += [("p2_Tau_0", p[2])]
    retval += [("SSE", SSE)]
    retval += [("dSSE", 1.0 - np.sum((y - f(t, *p0))**2) / SSE)]
    retval += [("Time fit begins", fit_start * si)]
    retval += [("Time fit ends", fit_end * si)]
    retval = dict(retval)
    stf.show_table(
        retval, "monoexpfit, Section #%i" % float(stf.get_trace_index() + 1))

    return
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
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
Beispiel #7
0
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