Beispiel #1
0
    def __init__(self, abf: pyabf.ABF, channel: int = 0):
        """
        This object contains passive cell membrane properties calculated from 
        each sweep an episodic protocol containing a voltage-clamp step.

        WARNING: These calculations are not optimized for speed or accuracy. 
        This module is experimental and included only for backward compatibility
        purposes. Users are highly encouraged to write their own analysis code.
        """
        assert isinstance(abf, pyabf.ABF)

        self.sweepCount = abf.sweepCount
        self.TimeSec = np.arange(abf.sweepCount) * abf.sweepIntervalSec
        self.TimeMin = self.TimeSec / 60.0

        Result = pyabf.tools.sweep.SweepMeasurement
        self.Ih = Result(abf.sweepCount, "Holding Current", "Ih", "pA")
        self.Rm = Result(abf.sweepCount, "Membrane Resistance", "Rm", "MOhm")
        self.Ra = Result(abf.sweepCount, "Access Resistance", "Ra", "MOhm")
        self.CmStep = Result(abf.sweepCount, "Capacitance (Step)", "Cm", "pF")
        self.CmRamp = Result(abf.sweepCount, "Capacitance (Ramp)", "Cm", "pF")

        for sweepNumber in abf.sweepList:
            abf.setSweep(sweepNumber, channel)

            # square step memtest
            Ih, Rm, Ra, CmStep = pyabf.tools.memtestMath.currentSweepStep(abf)
            self.Ih.values[sweepNumber] = Ih
            self.Rm.values[sweepNumber] = Rm
            self.Ra.values[sweepNumber] = Ra
            self.CmStep.values[sweepNumber] = CmStep

            # ramp memtest
            CmRamp = pyabf.tools.memtestMath.currentSweepRamp(abf)
            self.CmRamp.values[sweepNumber] = CmRamp
Beispiel #2
0
def restPotential(abf: pyabf.ABF, fig: pyABFauto.figure.Figure):
    pyabf.filter.gaussian(abf, 1)
    xs = abf.getAllXs()
    ys = abf.getAllYs()
    rmp = np.nanmean(ys)

    plt.grid(alpha=.5, ls='--')
    plt.plot(xs, ys, alpha=.7)
    plt.axhline(rmp, lw=3, color='r', ls='--')

    t = plt.gca().text(.97,
                       .97,
                       f"RMP = {rmp:.02f} mV",
                       transform=plt.gca().transAxes,
                       verticalalignment='top',
                       horizontalalignment='right',
                       fontsize=22,
                       family='monospace',
                       color='k')

    plt.title(abf.abfID + ".abf")
    plt.ylabel("Membrane Potential (mV)")
    plt.xlabel("Time (seconds)")
    plt.margins(0, .1)
    plt.tight_layout()
Beispiel #3
0
def plotFullAbf(abf: pyabf.ABF, ax: matplotlib.axes.Axes):
    for sweep in range(abf.sweepCount):
        abf.setSweep(sweep, absoluteTime=True)
        ax.plot(abf.sweepX / 60, abf.sweepY, 'b-')
    ax.margins(0, .1)
    ax.set_ylabel("Current (pA)")
    ax.set_xlabel("Time (minutes)")
    addTagLines(abf, ax)
Beispiel #4
0
def measureTau(abf: pyabf.ABF,
               sweep: int,
               epoch: int = 3,
               percentile: float = .05,
               ax: plt.Axes = None):

    abf.setSweep(sweep)

    # use epoch table to determine puff times
    puffTimeStart = abf.sweepEpochs.p1s[epoch] / abf.sampleRate
    puffTimeEnd = abf.sweepEpochs.p2s[epoch] / abf.sampleRate

    # calculate baseline level
    baselineStart = puffTimeStart - .1
    baselineEnd = puffTimeStart
    baselineMean = getMean(abf, baselineStart, baselineEnd)

    # find antipeak
    antipeakIndex = getAntiPeakIndex(abf.sweepY, abf.sampleRate, puffTimeStart,
                                     puffTimeStart + .5)
    antipeakLevel = abf.sweepY[antipeakIndex]

    # find portion of curve to fit
    curveIndex1, curveIndex2 = getCurveIndexes(abf.sweepY, antipeakIndex,
                                               baselineMean, percentile)
    curveYs = -abf.sweepY[curveIndex1:curveIndex2]
    curveXs = np.arange(len(curveYs)) / abf.sampleRate

    try:
        p0 = (500, 15, 0)  # start with values near those we expect
        params, cv = scipy.optimize.curve_fit(monoExp, curveXs, curveYs, p0)
    except:
        print(f"FIT FAILED (sweep {sweep})")
        return None
    m, t, b = params
    curveYsIdeal = monoExp(curveXs, m, t, b)
    tauMS = 1000 / t
    if (tauMS < 0):
        return None

    if ax:
        yPad = abs(antipeakLevel - baselineMean) * .1
        ax.plot(abf.sweepX, abf.sweepY, alpha=.5)
        ax.grid(alpha=.5, ls='--')
        ax.axhline(baselineMean, ls='--', color='k')
        ax.plot(abf.sweepX[curveIndex1:curveIndex2], -curveYsIdeal, color='k')
        ax.set(title=f"first sweep tau = {tauMS:.02f} ms")
        ax.axis([
            baselineStart - .1, baselineStart + 1, antipeakLevel - yPad,
            baselineMean + yPad
        ])
        ax.axvspan(puffTimeEnd, puffTimeEnd + .5, color='g', alpha=.1)
        ax.axvspan(puffTimeEnd + .5, puffTimeEnd + .6, color='m', alpha=.1)

    return tauMS
Beispiel #5
0
def plotPeakBySweep(abf: pyabf.ABF, ax: matplotlib.axes.Axes, epoch: int = 3):

    puffTimeStart = abf.sweepEpochs.p1s[epoch] / abf.sampleRate
    puffTimeEnd = abf.sweepEpochs.p2s[epoch] / abf.sampleRate

    values = []
    for i in range(abf.sweepCount):
        abf.setSweep(i)
        baselineStart = puffTimeStart - .1
        baselineEnd = puffTimeStart
        baselineMean = getMean(abf, baselineStart, baselineEnd)
        antipeak = getMin(abf, puffTimeEnd, puffTimeEnd + .5)
        values.append(abs(antipeak - baselineMean))

    ax.plot(abf.sweepTimesMin, values, '.-', color='k')
    ax.set_ylabel("Peak Response (pA)")
    ax.set_xlabel("Time (minutes)")
    ax.grid(alpha=.5, ls='--')
    addTagLines(abf, ax)
Beispiel #6
0
def plotTimeAfterBySweep(abf: pyabf.ABF,
                         ax: matplotlib.axes.Axes,
                         epoch: int = 3):

    puffTimeStart = abf.sweepEpochs.p1s[epoch] / abf.sampleRate
    puffTimeEnd = abf.sweepEpochs.p2s[epoch] / abf.sampleRate

    values = []
    for i in range(abf.sweepCount):
        abf.setSweep(i)

        baselineStart = puffTimeStart - .1
        baselineEnd = puffTimeStart
        baselineMean = getMean(abf, baselineStart, baselineEnd)

        mean = getMean(abf, puffTimeEnd + .5, puffTimeEnd + .6) - baselineMean
        values.append(mean)

    ax.plot(abf.sweepTimesMin, values, '.-', color='m')
    ax.set_ylabel("pA after 1s")
    ax.set_xlabel("Time (minutes)")
    ax.grid(alpha=.5, ls='--')
    addTagLines(abf, ax)
Beispiel #7
0
def getFullTrace(abf: pyabf.ABF):
    sweeps = [None] * abf.sweepCount
    for sweepIndex in range(abf.sweepCount):
        abf.setSweep(sweepIndex)
        sweeps[sweepIndex] = abf.sweepY
    return np.concatenate(sweeps)
"""
Created on Aug 14, 2018

@author: jwhite
"""

from pyabf import ABF

if __name__ == '__main__':
    a = ABF(
        abfFilePath=
        '/Volumes/external/hnl/incoming/PD_surgery_data/2017_08_25/2017_08_25_0004.abf',
        loadData=False)