# abffile = "2019_08_08_0037.abf"
masterdf = pd.read_excel(os.path.join(analysisdatapath,masterfile),sheet_name=0,header=0,use_cols=4)
print(masterdf)
yy = []
for row in range(0,masterdf.shape[0]):
    abfname = str(masterdf.loc[row,"abffile"])
    cell = str(masterdf.loc[row,"cell"])
    date = str(masterdf.loc[row,"date"])
    nsweeps = int(masterdf.loc[row,"nsweeps"])
    goodsweeps = [int(item) for item in str(masterdf.loc[row,"sweeps"]).split(',')]
    badsweeps = [elm for elm in np.arange(0,nsweeps) if np.isin(elm,goodsweeps,invert=True)]
    print("goodsweeps: {}".format(goodsweeps))
    print("badsweeps: {}".format(badsweeps))
    abfnamefull = os.path.join(rawdatapath,date,cell,abfname)
    print(abfnamefull)
    ephys = EphysClass(abfnamefull,loaddata=True,badsweeps=badsweeps)
    #     ephys.show([],[])           # [channels],[sweeps]
    ephys.extract_stim_props(trgchannel)
    ephys.extract_res_props(reschannel,trgchannel)
    ephys.extract_indices_holdingsteps(vclampchannel,NstepsNeg=1,NstepsPos=1)
    ephys.info()
    t,y = ephys.extract_response(reschannel,trgchannel,tpre=-0.0,tpost=0.15)
    yy.append(y)
    # ---------------
yy = np.concatenate(yy,axis=1)
print(yy.shape)
yya = []
# align traces to peak
ipeaks = np.zeros(yy.shape[1],dtype=np.int)
for icol in np.arange(0,yy.shape[1]):
    ipeaksall,_ = find_peaks(-yy[:,icol],prominence=(0.5,None),width=(100,None),height=(15,None))
示例#2
0
 # extract date
 expdate = re.search('[0-9]{8,8}?', abffile)[0]
 # extract spineid
 spineid = re.sub("\/", "_",
                  re.search('\/[0-9]{8,8}?\/.*?\/',
                            abffile)[0][1:-1]) + "S" + str(spinecount)
 # filename
 # abffname = re.search('[^/]+.\.*$',abffile)[0] # filename without extension
 # abffname = re.sub(' ','_',abffname)
 print('ABF filename:\t', abffile)
 print('Expdate:\t', expdate)
 print('Spineid:\t', spineid)
 print('Clamp:\t', clamp)
 if (not re.search(".*CC.*", clamp)):
     continue
 ephys1 = EphysClass(abffile, loaddata=True)
 ephys1.get_stimprops(trgchannel)
 ephys1.get_signal_props(reschannel, trgchannel)
 sweeps = np.setdiff1d(np.arange(0, ephys1.nsweeps), badsweeps)
 print("Bad sweeps:\t", badsweeps)
 print("Sweeps:\t", sweeps)
 t = np.arange(0, timewindow, ephys1.si)
 y = ephys1.extract_response(reschannel, trgchannel, timewindow, min_isi)
 plotcolors = ['red', 'green', 'blue', 'gray']
 if ((len(y) > 0) and len(sweeps) > 0):
     y = y - y[0, :]
     print(y.shape)
     yy.append(y[:, sweeps])
     # fh = plt.figure()
     # ah1 = plt.subplot(111)
     # ah1.set_title(re.search("[^/]+.abf",abffile)[0])
    # generate template trace
    template_fileids = list(
        dfspine[dfspine["isi"].isin(isis_template)]["fileid"])
    template = []
    for itfile in range(len(template_fileids)):
        templateid = template_fileids[itfile]
        fileid = "".join((list(dfspine.loc[dfspine["fileid"] == templateid,
                                           "fileid"].astype(str))[0], ".abf"))
        cellfolder = list(dfspine.loc[dfspine["fileid"] == templateid,
                                      "cellfolder"].astype(str))[0]
        expdatefolder = list(
            dfspine.loc[dfspine["fileid"] == templateid,
                        "expdatefolder"].astype(int).astype(str))[0]
        print(templateid, fileid, cellfolder, expdatefolder)
        filename = os.path.join(path_ephysdata, expdatefolder, cellfolder,
                                fileid)
        print(filename)
        ephys = EphysClass(filename, loaddata=True)
        print(ephys.goodsweeps)
        ephys.extract_indices_holdingsteps(clampchannel, 1, 1)
        ephys.extract_stim_props(stimchannel)
        ephys.extract_res_props(reschannel, stimchannel)
        print(ephys.stimprop)
        # input()
        # ephys.show([0,1,3],[])           # [channels],[sweeps]
        ephys.extract_response(reschannel, stimchannel, -0.005, 0.06)
        # fh = plt.figure()
        # ah = fh.add_subplot(111)
        # ah.plot(t,y)
        # plt.show()
示例#4
0
    cellfolder = str(masterdf.loc[row, "cellfolder"])
    ephysfile = str(masterdf.loc[row, "ephysfile"])
    abffile = os.path.join(ephysdatapath, datefolder, cellfolder, ephysfile)
    # ophysfile = os.path.join(ophysdatapath,datefolder,cellfolder,str(masterdf.loc[row,"imagefile"]))
    print(ephysfile)
    neuronid = int(masterdf.loc[row, "neuronid"])
    dendriteid = int(masterdf.loc[row, "dendriteid"])
    badsweeps = masterdf.loc[row, "badsweeps"]
    if (math.isnan(badsweeps)):
        badsweeps = []
    print("badsweeps: ", badsweeps)
    spineid = masterdf.loc[row, "spineid"]
    clampmode = str(masterdf.loc[row, "clampmode"])
    stimpower = masterdf.loc[row, "laserstimpower"]
    dob = masterdf.loc[row, "dob"]
    ephys = EphysClass(abffile, loaddata=True, badsweeps=badsweeps)
    ephys.info()

    ephys.extract_stim_props(trgch)
    ephys.extract_res_props(resch, trgch)
    # input()
    if ((clampmode == "vc") or (selectfile == 0)):
        continue
    if (clampmode == "cc"):
        ephys.get_clampprop(resch, clampch)
        tau, accessres = ephys.estimate_tau_access_res_from_epsp(
            resch, clampch)
        peaks, fh, ah = ephys.deconvolve_crop_reconvolve(resch, clampch, trgch)
        isi = ephys.isi
        nstims = int(ephys.nstim)
        nsweeps = int(ephys.nsweeps)
示例#5
0
masterdf = pd.read_excel(masterdfpath,header=0,use_cols=10)
masterdf["datefolder"] = masterdf["datefolder"].astype(int)
masterdf["date"] = pd.to_datetime(masterdf["datefolder"],format="%Y%m%d")
masterdf["dob"] = pd.to_datetime(masterdf["dob"],format="%Y%m%d")
masterdf["age"] = (masterdf["date"]-masterdf["dob"]).dt.days
print(masterdf)
channels =  ['ImLEFT', 'IN1', 'IN7']
resch = "ImLEFT"
clampch = "IN1"
trgch = "IN7"
for row in range(0,masterdf.shape[0]):
# for row in range(20,30):
    datefolder = str(masterdf.loc[row,"datefolder"])
    cellfolder = str(masterdf.loc[row,"cellfolder"])
    ephysfile = os.path.join(ephysdatapath,datefolder,cellfolder,str(masterdf.loc[row,"ephysfile"]))
    ophysfile = os.path.join(ophysdatapath,datefolder,cellfolder,str(masterdf.loc[row,"imagefile"]))
    print(ephysfile,"\n",ophysfile)
    neuronid = masterdf.loc[row,"neuronid"]
    branchid = masterdf.loc[row,"neuronid"]
    spineid = masterdf.loc[row,"neuronid"]
    clampmode = masterdf.loc[row,"clampmode"]
    stimmode = masterdf.loc[row,"stim-mode"]
    ephys = EphysClass(ephysfile,loaddata=True)
    # ephys.info()
    ephys.extract_stim_props(trgch)
    ephys.extract_res_props(resch,trgch)
    if(clampmode == "cc"):
        # ephys.estimate_tau_access_res_from_epsp(resch,clampch)
        ephys.deconvolve_crop_reconvolve(resch,clampch,trgch)
        input()
     print("sweep labels: ",labels)
     # extract successes alone (can contain '1','0','b' for success, failure and bad
     isuccess = [label == '1' for label in labels]
     # get success sweeps
     success_sweeps = np.arange(1,len(labels)+1)[isuccess]
     print("success sweeps: ",success_sweeps)
 else:
     print("!!!! Label file not found !!!!!!")
     break
 try:
     badsweeps = np.array([float(elm)-1 for elm in badsweeps],dtype=np.int)
 except:
     badsweeps = None
 print("Opening: ",abffullpath)
 print(badsweeps)
 ephys = EphysClass(abffullpath,loaddata=True,badsweeps=badsweeps,vclamp = int(vclamp), cclamp = None,fid=fileid)
 ephys.extract_stim_props(trgchannel)
 ephys.extract_res_props(reschannel,trgchannel)
 ephys.extract_indices_holdingsteps(vclampchannel,NstepsNeg=1,NstepsPos=1)
 ephys.info()    
 # ephys.show([0],[])           # [channels],[sweeps]
 # create folder for each cell
 figpath = mainpath + os.path.splitext(os.path.basename(abfname))[0] +'/'
 print("Figure path: ",figpath)
 if(not os.path.exists(figpath)):
     os.mkdir(figpath)
 # ----------------    
 lags,betas,peaks = ephys.findpeaks_template_match(reschannel,trgchannel,success_sweeps,figpath)
 nsweeps = len(ephys.sweeps)
 isi = ephys.isi
 for isweep in np.arange(0,betas.shape[0]):
     continue
 # extract date
 # expdate = datetime.datetime.strptime(re.search('[0-9]{8,8}?',abffile)[0],"%Y%m%d")
 expdate = re.search('[0-9]{8,8}?', abffile)[0]
 # extract spineid
 spineid = re.sub("\/", "_",
                  re.search('\/[0-9]{8,8}?\/.*?\/',
                            abffile)[0][1:-1]) + "S" + str(spinecount)
 # abffname = re.search('[^/]+.\.*$',abffile)[0] # filename without extension
 # abffname = re.sub(' ','_',abffname)
 print('ABF filename:\t', abffile)
 print('Expdate:\t', expdate)
 print('Spineid:\t', spineid)
 print('Clamp:\t', clamp)
 # create ephys object
 ephys1 = EphysClass(abffile, loaddata=True, badsweeps=badsweeps)
 ephys1.info()
 ephys1.get_stimprops(trgchannel)
 ephys1.get_signal_props(reschannel, trgchannel)
 fh = None
 fht = None
 # skip if no good sweeps found
 if (len(ephys1.sweeps) == 0):
     print('No good sweeps in the file!')
     continue
 if (re.search(".*CC.*", clamp)):
     ephys1.seriesres_currentclamp(reschannel, clampchannel)
     [tlags, ypeaks, fh, ah] = ephys1.find_peaks(reschannel,
                                                 trgchannel,
                                                 plotdata=False,
                                                 peakdir="+")
from ephys_class import EphysClass
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd
import os
import re

datapath="/home/anup/gdrive-beiquelabdata/Ephys Data/Olympus 2P/Anup/"
expdate = "20201218"
cellid = "C1"
channels =  ['ImLEFT', 'IN1', 'IN7']
reschannel = "ImLEFT"
clampchannel = "IN1"
print(os.listdir(datapath))
print(os.listdir(os.path.join(datapath,expdate)))
files = os.listdir(os.path.join(datapath,expdate,cellid))
abffiles = [f for f in files if re.search(".*.abf",f)]
abffiles.sort()
print(abffiles)
for abffile in abffiles:
    print("Opening %s"%abffile)
    ephys = EphysClass(os.path.join(datapath,expdate,cellid,abffile),loaddata=True)
    EphysClass.seriesres_voltageclamp(ephys,reschannel,clampchannel)
    ephys.info()
    ephys.show([0,1,3],[])           # [channels],[sweeps]
    # input()


from ephys_class import EphysClass
import os
import re

datapath = "/home/pi/ephys/"

expdate = "2021-02-16"

cellid = "C1"
# channels =  ['ImLEFT', 'IN1', 'IN7'] # olympus Rig
channels = ['ImRightP', 'VmRightS', 'IN6']  # LSM880
reschannel = [channels[1]]
clampchannel = [channels[0]]
print(os.listdir(datapath))
print(os.listdir(os.path.join(datapath, expdate)))
files = os.listdir(os.path.join(datapath, expdate))
abffiles = [f for f in files if re.search(".*.abf", f)]
abffiles.sort()
print(abffiles)
for abffile in abffiles:
    print("Opening %s" % abffile)
    ephys = EphysClass(os.path.join(datapath, expdate, abffile), loaddata=True)
    # EphysClass.seriesres_voltageclamp(ephys,'ImRightP',clampchannel)
    # ephys.info()
    ephys.show([0, 2], [])  # [channels],[sweeps]
    # input()
示例#10
0
 exp = str(masterdf.loc[row, "exp"])
 badsweeps = str(masterdf.loc[row, "badsweeps"]).split(",")
 fileid = re.search(
     ".*[^.abf]", abfname
 )[0] + '_' + "neuron" + neuron + '_' + "vc" + vclamp + '_' + "exp" + exp
 print('fileid: ', fileid)
 try:
     badsweeps = np.array([float(elm) - 1 for elm in badsweeps],
                          dtype=np.int)
 except:
     badsweeps = None
 # ------------------
 print("Opening: ", abffullpath)
 ephys = EphysClass(abffullpath,
                    loaddata=True,
                    badsweeps=None,
                    vclamp=int(vclamp),
                    cclamp=None,
                    fid=fileid)
 ephys.extract_stim_props(trgchannel)
 ephys.extract_res_props(reschannel, trgchannel)
 ephys.extract_indices_holdingsteps(vclampchannel, NstepsNeg=1, NstepsPos=1)
 ephys.info()
 # ephys.show([],[1,2,3,4,5])           # [channels],[sweeps]
 t, y = ephys.extract_response(reschannel,
                               trgchannel,
                               -0.01,
                               0.1,
                               min_isi=0)
 # fh = plt.figure()
 # ah = fh.add_subplot(111)
 # ah.plot(t,y)