def proto_0111(theABF): """protocol: IC ramp for AP shape analysis.""" abf = ABF(theABF) abf.log.info("analyzing as an IC ramp") # AP detection ap = AP(abf) ap.detect() firstAP = ap.APs[0]["T"] # also calculate derivative for each sweep abf.derivative = True # create the multi-plot figure plt.figure(figsize=(SQUARESIZE, SQUARESIZE)) ax1 = plt.subplot(221) plt.ylabel(abf.units2) ax2 = plt.subplot(222, sharey=ax1) ax3 = plt.subplot(223) plt.ylabel(abf.unitsD2) ax4 = plt.subplot(224, sharey=ax3) # put data in each subplot for sweep in range(abf.sweeps): abf.setsweep(sweep) ax1.plot(abf.sweepX, abf.sweepY, color='b', lw=.25) ax2.plot(abf.sweepX, abf.sweepY, color='b') ax3.plot(abf.sweepX, abf.sweepD, color='r', lw=.25) ax4.plot(abf.sweepX, abf.sweepD, color='r') # modify axis for ax in [ax1, ax2, ax3, ax4]: # everything ax.margins(0, .1) ax.grid(alpha=.5) for ax in [ax3, ax4]: # only derivative APs ax.axhline(-100, color='r', alpha=.5, ls="--", lw=2) for ax in [ax2, ax4]: # only zoomed in APs ax.get_yaxis().set_visible(False) ax2.axis([firstAP - .25, firstAP + .25, None, None]) ax4.axis([firstAP - .01, firstAP + .01, None, None]) # show message from first AP firstAP = ap.APs[0] msg = "\n".join([ "%s = %s" % (x, str(firstAP[x])) for x in sorted(firstAP.keys()) if not "I" in x[-2:] ]) plt.subplot(221) plt.gca().text(0.02, 0.98, msg, transform=plt.gca().transAxes, fontsize=10, verticalalignment='top', family='monospace') # save it plt.tight_layout() frameAndSave(abf, "AP shape") plt.close('all')
def proto_0304(theABF): """protocol: repeated IC steps.""" abf = ABF(theABF) abf.log.info("analyzing as repeated current-clamp step") # prepare for AP analysis ap = AP(abf) # calculate rest potential avgVoltagePerSweep = [] times = [] for sweep in abf.setsweeps(): avgVoltagePerSweep.append(abf.average(0, 3)) times.append(abf.sweepStart / 60) # detect only step APs M1, M2 = 3.15, 4.15 ap.detect_time1, ap.detect_time2 = M1, M2 ap.detect() apsPerSweepCos = [len(x) for x in ap.get_bySweep()] # detect all APs M1, M2 = 0, 10 ap.detect_time1, ap.detect_time2 = M1, M2 ap.detect() apsPerSweepRamp = [len(x) for x in ap.get_bySweep()] # make the plot of APs and stuff plt.figure(figsize=(8, 8)) plt.subplot(311) plt.grid(ls='--', alpha=.5) plt.plot(times, avgVoltagePerSweep, '.-') plt.ylabel("Rest Potential (mV)") comment_lines(abf) plt.subplot(312) plt.grid(ls='--', alpha=.5) plt.plot(times, apsPerSweepCos, '.-') plt.ylabel("APs in Step (#)") comment_lines(abf) plt.subplot(313) plt.grid(ls='--', alpha=.5) plt.plot(times, apsPerSweepRamp, '.-') plt.ylabel("APs in Sweep (#)") comment_lines(abf) plt.tight_layout() frameAndSave(abf, "cos ramp") plt.close('all')
def proto_gain(theABF, stepSize=25, startAt=-100): """protocol: gain function of some sort. step size and start at are pA.""" abf = ABF(theABF) abf.log.info("analyzing as an IC ramp") plot = ABFplot(abf) plot.kwargs["lw"] = .5 plot.title = "" currents = np.arange(abf.sweeps) * stepSize - startAt # AP detection ap = AP(abf) ap.detect_time1 = .1 ap.detect_time2 = .7 ap.detect() # stacked plot plt.figure(figsize=(SQUARESIZE, SQUARESIZE)) ax1 = plt.subplot(221) plot.figure_sweeps() ax2 = plt.subplot(222) ax2.get_yaxis().set_visible(False) plot.figure_sweeps(offsetY=150) # add vertical marks to graphs: for ax in [ax1, ax2]: for limit in [ap.detect_time1, ap.detect_time2]: ax.axvline(limit, color='r', ls='--', alpha=.5, lw=2) # make stacked gain function ax4 = plt.subplot(223) plt.ylabel("frequency (Hz)") plt.ylabel("seconds") plt.grid(alpha=.5) freqs = ap.get_bySweep("freqs") times = ap.get_bySweep("times") for i in range(abf.sweeps): if len(freqs[i]): plt.plot(times[i][:-1], freqs[i], '-', alpha=.5, lw=2, color=plot.getColor(i / abf.sweeps)) # make gain function graph ax4 = plt.subplot(224) ax4.grid(alpha=.5) plt.plot(currents, ap.get_bySweep("median"), 'b.-', label="median") plt.plot(currents, ap.get_bySweep("firsts"), 'g.-', label="first") plt.xlabel("applied current (pA)") plt.legend(loc=2, fontsize=10) plt.axhline(40, color='r', alpha=.5, ls="--", lw=2) plt.margins(.02, .1) # save it plt.tight_layout() frameAndSave(abf, "AP Gain %d_%d" % (startAt, stepSize)) plt.close('all')
def proto_gain(theABF, stepSize=25, startAt=-100): """protocol: gain function of some sort. step size and start at are pA.""" abf = ABF(theABF) abf.log.info("analyzing as an IC ramp") plot = ABFplot(abf) plot.kwargs["lw"] = .5 plot.title = "" currents = np.arange(abf.sweeps) * stepSize - startAt # AP detection ap = AP(abf) ap.detect_time1 = .1 ap.detect_time2 = .7 ap.detect() # stacked plot plt.figure(figsize=(SQUARESIZE, SQUARESIZE)) ax1 = plt.subplot(221) plot.figure_sweeps() ax2 = plt.subplot(222) ax2.get_yaxis().set_visible(False) plot.figure_sweeps(offsetY=150) # add vertical marks to graphs: for ax in [ax1, ax2]: for limit in [ap.detect_time1, ap.detect_time2]: ax.axvline(limit, color='r', ls='--', alpha=.5, lw=2) # make stacked gain function ax4 = plt.subplot(223) plt.ylabel("frequency (Hz)") plt.ylabel("seconds") plt.grid(alpha=.5) freqs = ap.get_bySweep("freqs") times = ap.get_bySweep("times") for i in range(abf.sweeps): if len(freqs[i]): plt.plot(times[i][:-1], freqs[i], '-', alpha=.5, lw=2, color=plot.getColor(i / abf.sweeps)) # make gain function graph ax4 = plt.subplot(224) ax4.grid(alpha=.5) plt.plot(currents, ap.get_bySweep("median"), 'b.-', label="median") plt.plot(currents, ap.get_bySweep("firsts"), 'g.-', label="first") plt.xlabel("applied current (pA)") plt.legend(loc=2, fontsize=10) plt.axhline(40, color='r', alpha=.5, ls="--", lw=2) plt.margins(.02, .1) # save it plt.tight_layout() frameAndSave(abf, "AP Gain %d_%d" % (startAt, stepSize)) plt.close('all') # make a second figure that just shows every sweep up to the first AP plt.figure(figsize=(SQUARESIZE, SQUARESIZE)) plt.grid(alpha=.5) plt.ylabel("Membrane Potential (mV)") plt.xlabel("Time (seconds)") for sweep in abf.setsweeps(): plt.plot(abf.sweepX2, abf.sweepY, color='b', alpha=.5) if np.max(abf.sweepY > 0): break plt.tight_layout() plt.margins(0, .1) plt.axis([0, 1, None, None]) plt.title("%d pA Steps from Rest" % stepSize) frameAndSave(abf, "voltage response fromRest", closeWhenDone=False) plt.axis([1.5, 2.5, None, None]) plt.title("%d pA Steps from %d pA" % (stepSize, startAt)) frameAndSave(abf, "voltage response hyperpol", closeWhenDone=False) plt.close('all')
def proto_0314(theABF): abf = ABF(theABF) abf.log.info("analyzing a cosine + ramp protocol") if len(abf.comment_sweeps > 0): # comments exist, so graph the average sweep before/after the first comment sweepsToAverage = 10 baselineSweep1 = max(0, abf.comment_sweeps[0] - sweepsToAverage) baselineSweep2 = abf.comment_sweeps[0] drugSweep1 = abf.comment_sweeps[0] + 1 drugSweep2 = min(abf.sweeps - 1, abf.comment_sweeps[0] + 1 + sweepsToAverage) plt.figure(figsize=(16, 4)) plt.grid(ls='--', alpha=.5) plt.plot(abf.sweepX2, abf.averageSweep(baselineSweep1, baselineSweep2), label="baseline (%d-%d)" % (baselineSweep1, baselineSweep2), alpha=.8) plt.plot(abf.sweepX2, abf.averageSweep(drugSweep1, drugSweep2), label="drug (%d-%d)" % (drugSweep1, drugSweep2), alpha=.8) plt.margins(0, .05) plt.legend() plt.tight_layout() frameAndSave(abf, "cos ramp avg", closeWhenDone=False) plt.axis([2.25, 4.5, None, None]) frameAndSave(abf, "cos ramp avgSine", closeWhenDone=False) plt.axis([9, 12.5, None, None]) frameAndSave(abf, "cos ramp avgRamp") # prepare for AP analysis ap = AP(abf) # calculate rest potential avgVoltagePerSweep = [] times = [] for sweep in abf.setsweeps(): avgVoltagePerSweep.append(abf.average(0, 2.25)) times.append(abf.sweepStart / 60) # detect only cos APs M1, M2 = 2.25, 4.5 ap.detect_time1, ap.detect_time2 = M1, M2 ap.detect() apsPerSweepCos = [len(x) for x in ap.get_bySweep()] # detect only ramp APs M1, M2 = 9, 12.5 ap.detect_time1, ap.detect_time2 = M1, M2 ap.detect() apsPerSweepRamp = [len(x) for x in ap.get_bySweep()] # make the plot of APs and stuff plt.figure(figsize=(8, 8)) plt.subplot(311) plt.grid(ls='--', alpha=.5) plt.plot(times, avgVoltagePerSweep, '.-') plt.ylabel("Rest Potential (mV)") comment_lines(abf) plt.subplot(312) plt.grid(ls='--', alpha=.5) plt.plot(times, apsPerSweepCos, '.-') plt.ylabel("APs in Cos (#)") comment_lines(abf) plt.subplot(313) plt.grid(ls='--', alpha=.5) plt.plot(times, apsPerSweepRamp, '.-') plt.ylabel("APs in Ramp (#)") comment_lines(abf) plt.tight_layout() frameAndSave(abf, "cos ramp") plt.close('all')
def proto_0303(theABF): """protocol: repeated IC ramps.""" abf = ABF(theABF) abf.log.info("analyzing as a halorhodopsin (2s pulse)") # show average voltage proto_avgRange(theABF, 0.2, 1.2) plt.close('all') # show stacked sweeps plt.figure(figsize=(8, 8)) for sweep in abf.setsweeps(): color = 'b' if sweep in np.array(abf.comment_sweeps, dtype=int): color = 'r' plt.plot(abf.sweepX2, abf.sweepY + 100 * sweep, color=color, alpha=.5) plt.margins(0, .01) plt.tight_layout() frameAndSave(abf, "IC ramps") plt.close('all') # do AP event detection ap = AP(abf) ap.detect_time1 = 2.3 ap.detect_time2 = 8.3 ap.detect() apCount = [] apSweepTimes = [] for sweepNumber, times in enumerate(ap.get_bySweep("times")): apCount.append(len(times)) if len(times): apSweepTimes.append(times[0]) else: apSweepTimes.append(0) # plot AP frequency vs time plt.figure(figsize=(8, 8)) ax1 = plt.subplot(211) plt.grid(alpha=.4, ls='--') plt.plot(np.arange(len(apCount)) * abf.sweepLength / 60, apCount, '.-', ms=15) comment_lines(abf) plt.ylabel("AP Count") plt.subplot(212, sharex=ax1) plt.grid(alpha=.4, ls='--') plt.plot(np.arange(len(apCount)) * abf.sweepLength / 60, apSweepTimes, '.-', ms=15) comment_lines(abf) plt.ylabel("First AP Time (s)") plt.xlabel("Experiment Duration (minutes)") plt.tight_layout() frameAndSave(abf, "IC ramp freq") plt.close('all')