import pandas as pd import numpy as np import h5py import os from ast import literal_eval #%% create JSON files for each alt type # folder top_dir = '../Sensitivity_Analysis' # for each alt_type create pd df shift_AUC = pd.DataFrame() shift_rheo = pd.DataFrame() shift_fI = pd.DataFrame(dtype=object) shift_I_mag = pd.DataFrame(dtype=object) slope_AUC = pd.DataFrame() slope_rheo = pd.DataFrame() slope_fI = pd.DataFrame(dtype=object) slope_I_mag = pd.DataFrame(dtype=object) g_AUC = pd.DataFrame() g_rheo = pd.DataFrame() g_fI = pd.DataFrame(dtype=object) g_I_mag = pd.DataFrame(dtype=object) print('SA pd gen') dir_names = ['RS_pyramidal', 'RS_inhib', 'FS','RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for dir_name in dir_names: folder = os.path.join(top_dir, dir_name) print(folder) # for each alt_type create pd df shift_AUC = pd.DataFrame() shift_rheo = pd.DataFrame() shift_fI = pd.DataFrame(dtype=object) shift_I_mag = pd.DataFrame(dtype=object) slope_AUC = pd.DataFrame() slope_rheo = pd.DataFrame() slope_fI = pd.DataFrame(dtype=object) slope_I_mag = pd.DataFrame(dtype=object) g_AUC = pd.DataFrame() g_rheo = pd.DataFrame() g_fI = pd.DataFrame(dtype=object) g_I_mag = pd.DataFrame(dtype=object) for root, dirs, files in os.walk(folder): for file in files: if file.endswith('.hdf5'): with h5py.File(os.path.join(folder, file), "r+") as f: alt = f['data'].attrs['alteration'] test = f['data'].attrs['alteration_info'].replace(' ', ',') alt_info = literal_eval(test) var = alt_info[0] alt_type = alt_info[1] if alt_type == 'shift': shift_AUC.loc[alt, var] = f['analysis']['AUC'][()] shift_rheo.loc[alt, var] = f['analysis']['rheobase'][()] shift_fI.loc[alt, var] = 0 shift_fI = shift_fI.astype(object) shift_fI.at[alt, var] = f['analysis']['F_inf'][:].tolist() shift_I_mag.loc[alt, var] = 0 shift_I_mag = shift_I_mag.astype(object) shift_I_mag.at[alt, var] = ((np.arange(f['data'].attrs['I_low'], f['data'].attrs['I_high'], (f['data'].attrs['I_high'] - f['data'].attrs['I_low']) / f['data'].attrs['stim_num'])) * 1000).tolist() # nA elif alt_type == 'slope': slope_AUC.loc[alt, var] = f['analysis']['AUC'][()] slope_rheo.loc[alt, var] = f['analysis']['rheobase'][()] slope_fI.loc[alt, var] = 0 slope_fI = slope_fI.astype(object) slope_fI.at[alt, var] = f['analysis']['F_inf'][:].tolist() slope_I_mag.loc[alt, var] = 0 slope_I_mag = slope_I_mag.astype(object) slope_I_mag.at[alt, var] = ((np.arange(f['data'].attrs['I_low'], f['data'].attrs['I_high'], (f['data'].attrs['I_high'] - f['data'].attrs['I_low']) / f['data'].attrs['stim_num'])) * 1000).tolist() elif alt_type == 'g': g_AUC.loc[alt, var] = f['analysis']['AUC'][()] g_rheo.loc[alt, var] = f['analysis']['rheobase'][()] g_fI.loc[alt, var] = 0 g_fI = g_fI.astype(object) g_fI.at[alt, var] = f['analysis']['F_inf'][:].tolist() g_I_mag.loc[alt, var] = 0 g_I_mag = g_I_mag.astype(object) g_I_mag.at[alt, var] = ((np.arange(f['data'].attrs['I_low'], f['data'].attrs['I_high'], (f['data'].attrs['I_high'] - f['data'].attrs['I_low']) / f['data'].attrs['stim_num'])) * 1000).tolist() else: print(file, 'Unknown alteration type') # save df with folder+alt_type save_folder = os.path.join(top_dir, 'SA_summary_df') if not os.path.isdir(save_folder): os.makedirs(save_folder) shift_AUC.to_json(os.path.join(save_folder, '{}_shift_AUC.json'.format(dir_name))) shift_rheo.to_json(os.path.join(save_folder, '{}_shift_rheo.json'.format(dir_name))) shift_fI.to_json(os.path.join(save_folder, '{}_shift_fI.json'.format(dir_name))) shift_I_mag.to_json(os.path.join(save_folder, '{}_shift_I_mag.json'.format(dir_name))) slope_AUC.to_json(os.path.join(save_folder, '{}_slope_AUC.json'.format(dir_name))) slope_rheo.to_json(os.path.join(save_folder, '{}_slope_rheo.json'.format(dir_name))) slope_fI.to_json(os.path.join(save_folder, '{}_slope_fI.json'.format(dir_name))) slope_I_mag.to_json(os.path.join(save_folder, '{}_slope_I_mag.json'.format(dir_name))) g_AUC.to_json(os.path.join(save_folder, '{}_g_AUC.json'.format(dir_name))) g_rheo.to_json(os.path.join(save_folder, '{}_g_rheo.json'.format(dir_name))) g_fI.to_json(os.path.join(save_folder, '{}_g_fI.json'.format(dir_name))) g_I_mag.to_json(os.path.join(save_folder, '{}_g_I_mag.json'.format(dir_name))) # requires _shift_rheo.json #%% correlation analysis ########################################################################################### models = ['RS_pyramidal', 'RS_inhib', 'FS','RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] model_labels = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal +$K_V1.1$', 'RS_inhib +$K_V1.1$', 'FS +$K_V1.1$','Cb stellate', 'Cb stellate +$K_V1.1$', 'Cb stellate $\Delta$$K_V1.1$', 'STN', 'STN +$K_V1.1$', 'STN $\Delta$$K_V1.1$'] var_dict = {} var_dict['RS_pyramidal'] = ['m', 'h', 'n'] var_dict['RS_inhib'] = ['m', 'h', 'n'] var_dict['FS'] = ['m', 'h', 'n'] var_dict['RS_pyramidal_Kv'] = ['m', 'h', 'n', 's', 'u'] var_dict['RS_inhib_Kv'] = ['m', 'h', 'n', 's', 'u'] var_dict['FS_Kv'] = ['m', 'h', 'n', 's', 'u'] var_dict['Cb_stellate'] = ['m', 'h', 'n', 'a', 'b'] var_dict['Cb_stellate_Kv'] = ['m', 'h', 'n', 'a', 'b', 's', 'u'] var_dict['Cb_stellate_Kv_only'] = ['m', 'h', 'n', 's', 'u'] var_dict['STN'] = ['m', 'h', 'n', 'n_A', 'h_A', 's', 'u'] var_dict['STN_Kv'] = ['m', 'h', 'n', 'n_A', 'h_A', 's', 'u'] var_dict['STN_Kv_only'] = ['m', 'h', 'n', 's', 'u'] folder = './Sensitivity_Analysis/corr_df' if not os.path.isdir(folder): os.makedirs(folder) # % rheo # % shift shift_m = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_m[mod] = pd.read_json(json_file)['m'].sort_index() shift_m.sort_index(inplace=True) shift_m.replace(0., np.NaN, inplace=True) shift_m = (shift_m - shift_m.loc[0, :]) shift_m.to_json(os.path.join(folder, 'shift_m_rheo.json')) shift_h = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_h[mod] = pd.read_json(json_file)['h'].sort_index() shift_h.sort_index(inplace=True) shift_h.replace(0., np.NaN, inplace=True) shift_h = (shift_h - shift_h.loc[0, :]) shift_h.to_json(os.path.join(folder, 'shift_h_rheo.json')) shift_n = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_n[mod] = pd.read_json(json_file)['n'].sort_index() shift_n.sort_index(inplace=True) shift_n.replace(0., np.NaN, inplace=True) shift_n = (shift_n - shift_n.loc[0, :]) shift_n.to_json(os.path.join(folder, 'shift_n_rheo.json')) shift_s = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_s[mod] = pd.read_json(json_file)['s'].sort_index() shift_s.sort_index(inplace=True) shift_s.replace(0., np.NaN, inplace=True) shift_s = (shift_s - shift_s.loc[0, :]) shift_s.to_json(os.path.join(folder, 'shift_s_rheo.json')) shift_u = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_u[mod] = pd.read_json(json_file)['u'].sort_index() shift_u.sort_index(inplace=True) shift_u.replace(0., np.NaN, inplace=True) shift_u = (shift_u - shift_u.loc[0, :]) shift_u.to_json(os.path.join(folder, 'shift_u_rheo.json')) shift_a = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_a[mod] = pd.read_json(json_file)['n_A'].sort_index() models = ['STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_a[mod] = pd.read_json(json_file)['a'].sort_index() shift_a.sort_index(inplace=True) shift_a.replace(0., np.NaN, inplace=True) shift_a = (shift_a - shift_a.loc[0, :]) shift_a.to_json(os.path.join(folder, 'shift_a_rheo.json')) shift_b = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_b[mod] = pd.read_json(json_file)['h_A'].sort_index() models = ['STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_shift_rheo.json'.format(mod)) as json_file: shift_b[mod] = pd.read_json(json_file)['b'].sort_index() shift_b.sort_index(inplace=True) shift_b.replace(0., np.NaN, inplace=True) shift_b = (shift_b - shift_b.loc[0, :]) shift_b.to_json(os.path.join(folder, 'shift_b_rheo.json')) # % slope slope_m = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_m[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['m'].sort_index() slope_m.index = slope_m.index.map(float) slope_m.sort_index(inplace=True) slope_m.replace(0., np.NaN, inplace=True) slope_m = (slope_m - slope_m.loc[1.0, :]) slope_m.to_json(os.path.join(folder, 'slope_m_rheo.json')) slope_h = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_h[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['h'].sort_index() slope_h.index = slope_h.index.map(float) slope_h.sort_index(inplace=True) slope_h.replace(0., np.NaN, inplace=True) slope_h = (slope_h - slope_h.loc[1.0, :]) slope_h.to_json(os.path.join(folder, 'slope_h_rheo.json')) slope_n = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_n[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['n'].sort_index() slope_n.index = slope_n.index.map(float) slope_n.sort_index(inplace=True) slope_n.replace(0., np.NaN, inplace=True) slope_n = (slope_n - slope_n.loc[1.0, :]) slope_n.to_json(os.path.join(folder, 'slope_n_rheo.json')) slope_s = pd.DataFrame() models = [ 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_s[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['s'].sort_index() slope_s.index = slope_s.index.map(float) slope_s.sort_index(inplace=True) slope_s.replace(0., np.NaN, inplace=True) slope_s = (slope_s - slope_s.loc[1.0, :]) slope_s.to_json(os.path.join(folder, 'slope_s_rheo.json')) slope_u = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_u[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['u'].sort_index() slope_u.index = slope_u.index.map(float) slope_u.sort_index(inplace=True) slope_u.replace(0., np.NaN, inplace=True) slope_u = (slope_u - slope_u.loc[1.0, :]) slope_u.to_json(os.path.join(folder, 'slope_u_rheo.json')) slope_a = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_a[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['n_A'].sort_index() models = ['STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_a[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['a'].sort_index() slope_a.index = slope_a.index.map(float) slope_a.sort_index(inplace=True) slope_a.replace(0., np.NaN, inplace=True) slope_a = (slope_a - slope_a.loc[1.0, :]) slope_a.to_json(os.path.join(folder, 'slope_a_rheo.json')) slope_b = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_b[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['h_A'].sort_index() models = ['STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_slope_rheo.json'.format(mod)) as json_file: slope_b[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['b'].sort_index() slope_b.index = slope_b.index.map(float) slope_b.sort_index(inplace=True) slope_b.replace(0., np.NaN, inplace=True) slope_b = (slope_b - slope_b.loc[1.0, :]) # slope_b.to_json(os.path.join(folder, 'slope_b_rheo.json')) # % g g_Na = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_g_rheo.json'.format(mod)) as json_file: g_Na[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['Na'].sort_index() g_Na.index = g_Na.index.map(float) g_Na.sort_index(inplace=True) g_Na.replace(0., np.NaN, inplace=True) g_Na = (g_Na - g_Na.loc[1.0, :]) g_Na.to_json(os.path.join(folder, 'g_Na_rheo.json')) g_Kd = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_g_rheo.json'.format(mod)) as json_file: g_Kd[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['Kd'].sort_index() g_Kd.index = g_Kd.index.map(float) g_Kd.sort_index(inplace=True) g_Kd.replace(0., np.NaN, inplace=True) g_Kd = (g_Kd - g_Kd.loc[1.0, :]) g_Kd.to_json(os.path.join(folder, 'g_Kd_rheo.json')) g_Kv = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_g_rheo.json'.format(mod)) as json_file: g_Kv[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['Kv'].sort_index() g_Kv.index = g_Kv.index.map(float) g_Kv.sort_index(inplace=True) g_Kv.replace(0., np.NaN, inplace=True) g_Kv = (g_Kv - g_Kv.loc[1.0, :]) g_Kv.to_json(os.path.join(folder, 'g_Kv_rheo.json')) g_A = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv', 'STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_g_rheo.json'.format(mod)) as json_file: g_A[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['A'].sort_index() g_A.index = g_A.index.map(float) g_A.sort_index(inplace=True) g_A.replace(0., np.NaN, inplace=True) g_A = (g_A - g_A.loc[1.0, :]) g_A.to_json(os.path.join(folder, 'g_A_rheo.json')) g_Leak = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_g_rheo.json'.format(mod)) as json_file: g_Leak[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['Leak'].sort_index() g_Leak.index = g_Leak.index.map(float) g_Leak.sort_index(inplace=True) g_Leak.replace(0., np.NaN, inplace=True) g_Leak = (g_Leak - g_Leak.loc[1.0, :]) g_Leak.to_json(os.path.join(folder, 'g_Leak_rheo.json')) # % AUC # % shift shift_m = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_m[mod] = pd.read_json(json_file)['m'].sort_index() shift_m.sort_index(inplace=True) shift_m.replace(0., np.NaN, inplace=True) shift_m = (shift_m - shift_m.loc[0, :]) / shift_m.loc[0, :] shift_m.to_json(os.path.join(folder, 'shift_m_AUC.json')) shift_h = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_h[mod] = pd.read_json(json_file)['h'].sort_index() shift_h.sort_index(inplace=True) shift_h.replace(0., np.NaN, inplace=True) shift_h = (shift_h - shift_h.loc[0, :]) / shift_h.loc[0, :] shift_h.to_json(os.path.join(folder, 'shift_h_AUC.json')) shift_n = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_n[mod] = pd.read_json(json_file)['n'].sort_index() shift_n.sort_index(inplace=True) shift_n.replace(0., np.NaN, inplace=True) shift_n = (shift_n - shift_n.loc[0, :]) / shift_n.loc[0, :] shift_n.to_json(os.path.join(folder, 'shift_n_AUC.json')) shift_s = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_s[mod] = pd.read_json(json_file)['s'].sort_index() shift_s.sort_index(inplace=True) shift_s.replace(0., np.NaN, inplace=True) shift_s = (shift_s - shift_s.loc[0, :]) / shift_s.loc[0, :] shift_s.to_json(os.path.join(folder, 'shift_s_AUC.json')) shift_u = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_u[mod] = pd.read_json(json_file)['u'].sort_index() shift_u.sort_index(inplace=True) shift_u.replace(0., np.NaN, inplace=True) shift_u = (shift_u - shift_u.loc[0, :]) / shift_u.loc[0, :] shift_u.to_json(os.path.join(folder, 'shift_u_AUC.json')) shift_a = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_a[mod] = pd.read_json(json_file)['n_A'].sort_index() models = ['STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_a[mod] = pd.read_json(json_file)['a'].sort_index() shift_a.sort_index(inplace=True) shift_a.replace(0., np.NaN, inplace=True) shift_a = (shift_a - shift_a.loc[0, :]) / shift_a.loc[0, :] shift_a.to_json(os.path.join(folder, 'shift_a_AUC.json')) shift_b = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_b[mod] = pd.read_json(json_file)['h_A'].sort_index() models = ['STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_shift_AUC.json'.format(mod)) as json_file: shift_b[mod] = pd.read_json(json_file)['b'].sort_index() shift_b.sort_index(inplace=True) shift_b.replace(0., np.NaN, inplace=True) shift_b = (shift_b - shift_b.loc[0, :]) / shift_b.loc[0, :] shift_b.to_json(os.path.join(folder, 'shift_b_AUC.json')) # % slope slope_m = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_m[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['m'].sort_index() slope_m.index = slope_m.index.map(float) slope_m.sort_index(inplace=True) slope_m.replace(0., np.NaN, inplace=True) slope_m = (slope_m - slope_m.loc[1.0, :]) / slope_m.loc[1.0, :] slope_m.to_json(os.path.join(folder, 'slope_m_AUC.json')) slope_h = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_h[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['h'].sort_index() slope_h.index = slope_h.index.map(float) slope_h.sort_index(inplace=True) slope_h.replace(0., np.NaN, inplace=True) slope_h = (slope_h - slope_h.loc[1.0, :]) / slope_h.loc[1.0, :] slope_h.to_json(os.path.join(folder, 'slope_h_AUC.json')) slope_n = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_n[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['n'].sort_index() slope_n.index = slope_n.index.map(float) slope_n.sort_index(inplace=True) slope_n.replace(0., np.NaN, inplace=True) slope_n = (slope_n - slope_n.loc[1.0, :]) / slope_n.loc[1.0, :] slope_n.to_json(os.path.join(folder, 'slope_n_AUC.json')) slope_s = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_s[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['s'].sort_index() slope_s.index = slope_s.index.map(float) slope_s.sort_index(inplace=True) slope_s.replace(0., np.NaN, inplace=True) slope_s = (slope_s - slope_s.loc[1.0, :]) / slope_s.loc[1.0, :] slope_s.to_json(os.path.join(folder, 'slope_s_AUC.json')) slope_u = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_u[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['u'].sort_index() slope_u.index = slope_u.index.map(float) slope_u.sort_index(inplace=True) slope_u.replace(0., np.NaN, inplace=True) slope_u = (slope_u - slope_u.loc[1.0, :]) / slope_u.loc[1.0, :] slope_u.to_json(os.path.join(folder, 'slope_u_AUC.json')) slope_a = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_a[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['n_A'].sort_index() models = ['STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_a[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['a'].sort_index() slope_a.index = slope_a.index.map(float) slope_a.sort_index(inplace=True) slope_a.replace(0., np.NaN, inplace=True) slope_a = (slope_a - slope_a.loc[1.0, :]) / slope_a.loc[1.0, :] slope_a.to_json(os.path.join(folder, 'slope_a_AUC.json')) slope_b = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_b[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['h_A'].sort_index() models = ['STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_slope_AUC.json'.format(mod)) as json_file: slope_b[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['b'].sort_index() slope_b.index = slope_b.index.map(float) slope_b.sort_index(inplace=True) slope_b.replace(0., np.NaN, inplace=True) slope_b = (slope_b - slope_b.loc[1.0, :]) / slope_b.loc[1.0, :] slope_b.to_json(os.path.join(folder, 'slope_b_AUC.json')) # % g g_Na = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_g_AUC.json'.format(mod)) as json_file: g_Na[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['Na'].sort_index() g_Na.index = g_Na.index.map(float) g_Na.sort_index(inplace=True) g_Na.replace(0., np.NaN, inplace=True) g_Na = (g_Na - g_Na.loc[1.0, :]) / g_Na.loc[1.0, :] g_Na.to_json(os.path.join(folder, 'g_Na_AUC.json')) g_Kd = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_g_AUC.json'.format(mod)) as json_file: g_Kd[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['Kd'].sort_index() g_Kd.index = g_Kd.index.map(float) g_Kd.sort_index(inplace=True) g_Kd.replace(0., np.NaN, inplace=True) g_Kd = (g_Kd - g_Kd.loc[1.0, :]) / g_Kd.loc[1.0, :] g_Kd.to_json(os.path.join(folder, 'g_Kd_AUC.json')) g_Kv = pd.DataFrame() models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_g_AUC.json'.format(mod)) as json_file: g_Kv[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['Kv'].sort_index() g_Kv.index = g_Kv.index.map(float) g_Kv.sort_index(inplace=True) g_Kv.replace(0., np.NaN, inplace=True) g_Kv = (g_Kv - g_Kv.loc[1.0, :]) / g_Kv.loc[1.0, :] g_Kv.to_json(os.path.join(folder, 'g_Kv_AUC.json')) g_A = pd.DataFrame() models = ['Cb_stellate', 'Cb_stellate_Kv', 'STN', 'STN_Kv'] for mod in models: with open('./SA_summary_df/{}_g_AUC.json'.format(mod)) as json_file: g_A[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['A'].sort_index() g_A.index = g_A.index.map(float) g_A.sort_index(inplace=True) g_A.replace(0., np.NaN, inplace=True) g_A = (g_A - g_A.loc[1.0, :]) / g_A.loc[1.0, :] g_A.to_json(os.path.join(folder, 'g_A_AUC.json')) g_Leak = pd.DataFrame() models = ['RS_pyramidal', 'RS_inhib', 'FS', 'RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN', 'STN_Kv', 'STN_Kv_only'] for mod in models: with open('./SA_summary_df/{}_g_AUC.json'.format(mod)) as json_file: g_Leak[mod] = pd.read_json(json_file, convert_axes=False, convert_dates=False)['Leak'].sort_index() g_Leak.index = g_Leak.index.map(float) g_Leak.sort_index(inplace=True) g_Leak.replace(0., np.NaN, inplace=True) g_Leak = (g_Leak - g_Leak.loc[1.0, :]) / g_Leak.loc[1.0, :] g_Leak.to_json(os.path.join(folder, 'g_Leak_AUC.json')) #%% todo: CREATE CSV FILES ################################################################################################### #% AUC # from ./Code/From_Neuronal_models/tau_analysis/AUC_corr_df_gen.py AUC_shift_df = pd.read_json('./Sensitivity_analysis/shift_box_kendall_corr_rel.json', orient='records') AUC_slope_df = pd.read_json('./Sensitivity_analysis/slope_box_kendall_corr_rel.json', orient='records') #, lines=True) AUC_g_df = pd.read_json('./Sensitivity_analysis/g_box_kendall_corr_rel.json', orient='records') # for i in np.array(['FS', 'IB', 'RS inhibitory', 'RS pyramidal']): # AUC_shift_df.loc[AUC_shift_df['model'] == i, 'model'] = i + ' +$K_V1.1$' # ''+$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$' # AUC_slope_df.loc[AUC_slope_df['model'] == i, 'model'] = i + ' +$K_V1.1$' #' +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$' # AUC_g_df.loc[AUC_g_df['model'] == i, 'model'] = i + ' +$K_V1.1$' #' +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$' AUC_shift_df_posp = pd.read_json('./Sensitivity_analysis/shift_box_kendall_corr_rel_pospischil.json', orient='records') AUC_slope_df_posp = pd.read_json('./Sensitivity_analysis/slope_box_kendall_corr_rel_pospischil.json', orient='records') #, lines=True) AUC_g_df_posp = pd.read_json('./Sensitivity_analysis/g_box_kendall_corr_rel_pospischil.json', orient='records') AUC_shift_df = AUC_shift_df.append(AUC_shift_df_posp) AUC_slope_df = AUC_slope_df.append(AUC_slope_df_posp) AUC_g_df = AUC_g_df.append(AUC_g_df_posp) AUC_shift_df.to_csv('AUC_shift_corr.csv') AUC_slope_df.to_csv('AUC_scale_corr.csv') AUC_g_df.to_csv('AUC_g_corr.csv') #% rheo rheo_shift_df = pd.read_json('./Sensitivity_analysis/rheo_shift_box_kendall_corr.json', orient='records') rheo_slope_df = pd.read_json('./Sensitivity_analysis/rheo_slope_box_kendall_corr.json', orient='records') #, lines=True) rheo_g_df = pd.read_json('./Sensitivity_analysis/rheo_g_box_kendall_corr.json', orient='records') for i in np.array(['FS', 'IB', 'RS inhibitory', 'RS pyramidal']): rheo_shift_df.loc[rheo_shift_df['model'] == i, 'model'] = i + ' +$K_V1.1$' #' +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$' rheo_slope_df.loc[rheo_slope_df['model'] == i, 'model'] = i + ' +$K_V1.1$' #' +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$' rheo_g_df.loc[rheo_g_df['model'] == i, 'model'] = i + ' +$K_V1.1$' #' +$\mathrm{K}_{\mathrm{V}}\mathrm{1.1}$' rheo_shift_df_posp = pd.read_json('./Sensitivity_analysis/rheo_shift_box_kendall_corr_pospischil.json', orient='records') rheo_slope_df_posp = pd.read_json('./Sensitivity_analysis/rheo_slope_box_kendall_corr_pospischil.json', orient='records') #, lines=True) rheo_g_df_posp = pd.read_json('./Sensitivity_analysis/rheo_g_box_kendall_corr_pospischil.json', orient='records') rheo_shift_df = rheo_shift_df.append(rheo_shift_df_posp) rheo_slope_df = rheo_slope_df.append(rheo_slope_df_posp) rheo_g_df = rheo_g_df.append(rheo_g_df_posp) rheo_shift_df.to_csv('rheo_shift_corr.csv') rheo_slope_df.to_csv('rheo_scale_corr.csv') rheo_g_df.to_csv('rheo_g_corr.csv')