def new_db(self, mice): ''' Sets self.db to a new database built from a list of mice (uses their inforec files) ''' dbs = [] for mouse in mice: db = celldatabase.generate_cell_database( self.inforecFolderFormat.format(mouse, mouse)) dbs.append(db) self.db = pandas.concat(dbs, ignore_index=True)
from jaratoolbox import celldatabase from jaratoolbox import spikesanalysis import numpy as np from numpy import inf import pandas from jaratest.nick.reports import pinp_report from jaratest.nick.database import dataloader_v3 as dataloader from jaratest.nick.stats import am_funcs from scipy import stats inforecFn = '/home/nick/src/jaratest/common/inforecordings/pinp024_inforec.py' db = celldatabase.generate_cell_database(inforecFn) #Calculate shape quality allShapeQuality = np.empty(len(db)) for indCell, cell in db.iterrows(): peakAmplitudes = cell['clusterPeakAmplitudes'] spikeShapeSD = cell['clusterSpikeSD'] shapeQuality = abs(peakAmplitudes[1]/spikeShapeSD.mean()) allShapeQuality[indCell] = shapeQuality allShapeQuality[allShapeQuality==inf]=0 db['shapeQuality'] = allShapeQuality #Calculate noiseburst response #TODO: Response to things other than noise as well?? noiseZscore = np.empty(len(db)) noisePval = np.empty(len(db)) baseRange = [-0.2,0] responseRange = [0, 0.2] for indCell, cell in db.iterrows(): spikeData, eventData = dataloader.get_session_ephys(cell, 'noiseburst')
animal = 'gosi008' inforecFullPath = os.path.join(settings.INFOREC_PATH, '{}_inforec.py'.format(animal)) databaseFullPath = os.path.join(settings.DATABASE_PATH, animal, '{}_database.h5'.format(animal)) key = 'reward_change' baseRange = [-0.1, 0] #Range of baseline period, in sec respRange = [0, 0.1] #Range of sound response period, in sec timeRange = [-0.5, 1] movementTimeRange = [0.05, 0.15] soundTriggerChannel = 0 if not os.path.isfile(databaseFullPath): gosi008db = celldatabase.generate_cell_database(inforecFullPath) gosi008db['animalName'] = animal gosi008db.to_hdf(databaseFullPath, key=key) else: gosi008db = pd.read_hdf(databaseFullPath, key=key) if not ('shapeQaulity' in gosi008db.columns): #Waveform analysis allShapeQuality = np.empty(len(gosi008db)) for indCell, cell in gosi008db.iterrows(): peakAmplitudes = cell['clusterPeakAmplitudes'] spikeShapeSD = cell['clusterSpikeSD'] shapeQuality = abs(peakAmplitudes[1] / spikeShapeSD.mean()) allShapeQuality[indCell] = shapeQuality allShapeQuality[allShapeQuality == np.inf] = 0
from jaratoolbox import behavioranalysis from jaratoolbox import loadbehavior from jaratoolbox import loadopenephys reload(loadopenephys) from jaratoolbox import settings import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec import numpy as np from scipy import stats import os import pdb subject = 'dapa003' #Generate cell database db = celldatabase.generate_cell_database( '/home/jarauser/src/jaratest/common/inforecordings/dapa003_inforec.py') #Calculate shape quality allShapeQuality = np.empty(len(db)) for indCell, cell in db.iterrows(): peakAmplitudes = cell['clusterPeakAmplitudes'] spikeShapeSD = cell['clusterSpikeSD'] thisShapeQuality = abs(peakAmplitudes[1] / spikeShapeSD.mean()) allShapeQuality[indCell] = thisShapeQuality allShapeQuality[allShapeQuality == np.inf] = 0 db['shapeQuality'] = allShapeQuality #Select good cells goodCells = db.query('isiViolations<0.02 and shapeQuality>2') ''' #Cell 15
bestBehavIndex = None octavesFromBest = None return bestBehavIndex, octavesFromBest if __name__=='__main__': if len(sys.argv[1:]): subjects = sys.argv[1:] else: subjects = subjects_info.PV_ARCHT_MICE + subjects_info.SOM_ARCHT_MICE for subject in subjects: inforec = '/home/jarauser/src/jaratest/common/inforecordings/{0}_inforec.py'.format(subject) #inforec = os.path.join(settings.INFOREC_PATH,'{0}_inforec.py'.format(subject)) db = celldatabase.generate_cell_database(inforec) # # NOTE: this way to remove bad cells seems too convoluted # #db = db.drop(db[(db['isiViolations'] > 0.05) | (db['spikeShapeQuality'] < 2)].index).reset_index(drop=True) # # --- Keep only good cells --- # db = db[(db['isiViolations'] < 0.05) | (db['spikeShapeQuality'] > 2)] # # --- compute statistics used for selection for each cell --- # laserTestStatistic = np.empty(len(db)) # laserPVal = np.empty(len(db)) # laserTrainTestStatistic = np.empty(len(db)) # laserTrainPVal = np.empty(len(db)) # soundResponseTestStatistic = np.empty(len(db)) # soundResponsePVal = np.empty(len(db))
from jaratoolbox import celldatabase import pandas import subprocess from jaratest.nick.analysis import pinp_report reload(pinp_report) from jaratest.nick.analysis.pinp_report import * from numpy import inf from jaratest.nick.stats import eventresponse from jaratest.nick.stats import am_funcs pinp016db = celldatabase.generate_cell_database('/home/nick/src/jaratest/nick/inforecordings/pinp016/pinp016_inforec.py') #Waveform analysis allShapeQuality = np.empty(len(pinp016db)) for indCell, cell in pinp016db.iterrows(): peakAmplitudes = cell['clusterPeakAmplitudes'] spikeShapeSD = cell['clusterSpikeSD'] shapeQuality = abs(peakAmplitudes[1]/spikeShapeSD.mean()) allShapeQuality[indCell] = shapeQuality allShapeQuality[allShapeQuality==inf]=0 pinp016db['shapeQuality'] = allShapeQuality #Noise response, new version noiseZscore = np.empty(len(pinp016db)) noisePval = np.empty(len(pinp016db)) baseRange = [-0.2,0] responseRange = [0, 0.2] for indCell, cell in pinp016db.iterrows(): zScore, pVal = eventresponse.event_response_score(cell, 'noiseburst', responseRange=responseRange, baseRange=baseRange)
from jaratoolbox import celldatabase from jaratoolbox import spikesanalysis from jaratoolbox import spikesorting from jaratoolbox import ephyscore from jaratoolbox import extraplots from jaratoolbox import colorpalette as cp from jaratoolbox import settings from scipy import stats STUDY_NAME = '2018thstr' SAVE = 1 inforecPath = '/home/nick/src/jaratest/common/inforecordings/pinp031_inforec.py' dbPath = os.path.join(settings.FIGURES_DATA_PATH, STUDY_NAME, 'celldatabase_NBQX.h5') dataframe = celldatabase.generate_cell_database(inforecPath) dataframe['autoTagged'] = 0 dataframe['autoTagged'] = dataframe['autoTagged'].astype(int) dataframe['survivedNBQX'] = 0 dataframe['washout'] = 0 for indIter, (indRow, dbRow) in enumerate(dataframe.iterrows()): cell = ephyscore.Cell(dbRow) try: pulseData, _ = cell.load('laserpulse_pre') except (IndexError, ValueError): print "Cell has no laserpulse session, loading laser train session for pulse data" try:
from jaratoolbox import behavioranalysis from jaratoolbox import loadbehavior from jaratoolbox import loadopenephys reload(loadopenephys) from jaratoolbox import settings import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec import numpy as np from scipy import stats import os import pdb subject = 'dapa003' #Generate cell database db = celldatabase.generate_cell_database('/home/jarauser/src/jaratest/common/inforecordings/dapa003_inforec.py') #Calculate shape quality allShapeQuality = np.empty(len(db)) for indCell, cell in db.iterrows(): peakAmplitudes = cell['clusterPeakAmplitudes'] spikeShapeSD = cell['clusterSpikeSD'] thisShapeQuality = abs(peakAmplitudes[1]/spikeShapeSD.mean()) allShapeQuality[indCell] = thisShapeQuality allShapeQuality[allShapeQuality==np.inf]=0 db['shapeQuality'] = allShapeQuality #Select good cells goodCells = db.query('isiViolations<0.02 and shapeQuality>2') '''
import pandas as pd from jaratoolbox import ephyscore from jaratoolbox import celldatabase reload(ephyscore) reload(celldatabase) # dbPath = '/home/nick/data/jarahubdata/figuresdata/2018thstr/celldatabase.h5' # db = pd.read_hdf(dbPath, key='dataframe') db = celldatabase.generate_cell_database( '/home/nick/src/jaratest/common/inforecordings/pinp025_inforec.py') dbRow = db.ix[0] oneCell = ephyscore.Cell(dbRow) amInd = oneCell.get_session_inds('am') behavData = oneCell.load_behavior_by_index(amInd[0]) ephysData = oneCell.load_ephys_by_index(amInd[0]) allData = oneCell.load('am')
from jaratoolbox import celldatabase from jaratoolbox import spikesorting import band_ephys_analysis as bandan reload(bandan) CASE=1 if CASE==1: #currentdb = pd.read_hdf('/home/jarauser/src/jaratest/anna/analysis/all_clusters.h5','database',index_col=0) currentdb = pd.DataFrame() db = pd.DataFrame() subjects = ['band002','band003','band004','band005','band015','band016','band022','band023','band025','band026','band027','band028','band029','band030','band031','band033','band034'] for subject in subjects: inforec = '/home/jarauser/src/jaratest/common/inforecordings/{0}_inforec.py'.format(subject) db = db.append(celldatabase.generate_cell_database(inforec),ignore_index=True) db = db.reindex(columns=np.concatenate((db.columns.values,['clusterQuality','bestFreq','bestBandIndex','laserResponse','nBandSpikes','suppressionIndex','facilitationIndex','preferedBandwidth','gaussFit']))) db['suppressionIndex'] = db['suppressionIndex'].astype('object') db['facilitationIndex'] = db['facilitationIndex'].astype('object') db['preferedBandwidth'] = db['preferedBandwidth'].astype('object') db['gaussFit'] = db['gaussFit'].astype('object') for indCell, cell in db.iterrows(): peakAmplitudes = cell['clusterPeakAmplitudes'] spikeShapeSD = cell['clusterSpikeSD'] shapeQuality = abs(peakAmplitudes[1]/spikeShapeSD.mean()) db.set_value(indCell, 'clusterQuality', shapeQuality) laserResponse = bandan.laser_response(cell) db.set_value(indCell, 'laserResponse', laserResponse)
CASE = 1 if CASE == 1: #currentdb = pd.read_hdf('/home/jarauser/src/jaratest/anna/analysis/all_clusters.h5','database',index_col=0) currentdb = pd.DataFrame() db = pd.DataFrame() subjects = [ 'band002', 'band003', 'band004', 'band005', 'band015', 'band016', 'band022', 'band023', 'band025', 'band026', 'band027', 'band028', 'band029', 'band030', 'band031', 'band033', 'band034' ] for subject in subjects: inforec = '/home/jarauser/src/jaratest/common/inforecordings/{0}_inforec.py'.format( subject) db = db.append(celldatabase.generate_cell_database(inforec), ignore_index=True) db = db.reindex(columns=np.concatenate((db.columns.values, [ 'clusterQuality', 'bestFreq', 'bestBandIndex', 'laserResponse', 'nBandSpikes', 'suppressionIndex', 'facilitationIndex', 'preferedBandwidth', 'gaussFit' ]))) db['suppressionIndex'] = db['suppressionIndex'].astype('object') db['facilitationIndex'] = db['facilitationIndex'].astype('object') db['preferedBandwidth'] = db['preferedBandwidth'].astype('object') db['gaussFit'] = db['gaussFit'].astype('object') for indCell, cell in db.iterrows(): peakAmplitudes = cell['clusterPeakAmplitudes'] spikeShapeSD = cell['clusterSpikeSD'] shapeQuality = abs(peakAmplitudes[1] / spikeShapeSD.mean())
from jaratoolbox import celldatabase from jaratoolbox import spikesorting reload(celldatabase) import bandwidths_analysis_v2 as bandan reload(bandan) #subjects = ['band022','band023'] currentdb = db = pd.read_hdf('/home/jarauser/src/jaratest/anna/analysis/all_clusters.h5','database',index_col=0) db = pd.DataFrame() subjects = ['band025'] for subject in subjects: inforec = '/home/jarauser/src/jaratest/common/inforecordings/{0}_inforec.py'.format(subject) ci = spikesorting.ClusterInforec(inforec) ci.cluster_all_experiments() db = db.append(celldatabase.generate_cell_database(inforec),ignore_index=True) #db = db[db['isiViolations']<2.0] db = db.reindex(columns=np.concatenate((db.columns.values,['clusterQuality','atBestFreq','bestFreq']))) for indCell, cell in db.iterrows(): peakAmplitudes = cell['clusterPeakAmplitudes'] spikeShapeSD = cell['clusterSpikeSD'] shapeQuality = abs(peakAmplitudes[1]/spikeShapeSD.mean()) db.set_value(indCell, 'clusterQuality', shapeQuality) bestBand, atBestFreq, bestFreq = bandan.best_band_index(cell) db.set_value(indCell, 'atBestFreq', atBestFreq) if atBestFreq: db.set_value(indCell, 'bestFreq', bestFreq) suppressionStats, laserResponse = bandan.suppression_stats(cell, bestBand) if suppressionStats is not None: db.set_value(indCell, 'laserResponse', laserResponse)