Discussion and changes to abstract

This commit is contained in:
nkoch1
2022-10-27 11:06:25 -04:00
parent 2b537f790a
commit 6c2ba406b8
8 changed files with 966 additions and 1050 deletions

View File

@@ -0,0 +1,153 @@
import pandas as pd
import h5py
import json
import os
import numpy as np
from ast import literal_eval
# todo: run some and test
# todo: Model fI, rheo_{}_corr, AUC_{}_corr
# %% todo: Model fI
# for each model
# | (index) | mag | alt | type | F | I |
# | 0 | -10 | m | shift | array | array |
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_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'RS pyramidal +Kv1.1', 'RS inhibitory +Kv1.1', 'FS +Kv1.1',
'Cb stellate', 'Cb stellate +Kv1.1', 'Cb stellate $\Delta$Kv1.1', 'STN', 'STN +Kv1.1',
'STN $\Delta$Kv1.1']
# for each model get csv file with all shifts, scale and g
for model_name in models:
df = pd.DataFrame(columns=['mag', 'alt', 'type', 'F', 'I'])
folder = '../Neuron_models/{}'.format(model_name)
fname = os.path.join(folder, "{}.hdf5".format(model_name))
# for each alt in model
# with h5py.File(fname, "r+") as f:
# df.loc[model_name, '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]
# df.loc[model_name, 'mag'] = var
# df.loc[model_name, 'type'] = alt_type
# df.loc[model_name, 'F'] = f['analysis']['F_inf'][:]
# I_mag = 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
# df.loc[model_name, 'I'] = I
# df.to_csv('./Model_fI/{}.csv'.format(model_name))
# %% todo: rheo/AUC_{}_corr
# | (index) | model | corr | p_value | g | color
rheo_corr = pd.DataFrame(columns=['model', 'corr', 'p_value', 'g', 'color'])
rheo_corr.to_csv('rheo_corr.csv')
AUC_corr = pd.DataFrame(columns=['model', 'corr', 'p_value', 'g', 'color'])
AUC_corr.to_csv('AUC_corr.csv')
# %% firing_values.csv,model_spiking.csv, model_F_inf.csv # DONE ####################################################
import numpy as np
import pandas as pd
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_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'RS pyramidal +Kv1.1', 'RS inhibitory +Kv1.1', 'FS +Kv1.1',
'Cb stellate', 'Cb stellate +Kv1.1', 'Cb stellate $\Delta$Kv1.1', 'STN', 'STN +Kv1.1',
'STN $\Delta$Kv1.1']
firing_values = pd.DataFrame(columns=models, index=['spike_ind', 'ramp_up', 'ramp_down'])
# firing_values.loc['spike_ind', :] = np.array(
# [0.3, 0.04375, 0.25, 0.3, 0.0875, 0.25, 0.3, 0.65, 0.375, 0.125, 0.475, 0.4])
models = ['RS_pyr', 'RS_pyr_Kv', 'RS_inhib', 'RS_inhib_Kv', 'FS', 'FS_Kv',
'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Delta_Kv',
'STN', 'STN_Kv', 'STN_Delta_Kv']
col_names = ['I', 'I_inhib']
for mod in models: col_names.append(mod)
model_F_inf = pd.DataFrame(columns=col_names)
col_names = ['t']
for mod in models: col_names.append(mod)
spiking = pd.DataFrame(columns=col_names)
# index for example trace
spike_ind = {'RS_pyramidal': 60, 'RS_inhib':25, 'FS':50, 'RS_pyramidal_Kv':60,
'RS_inhib_Kv':50, 'FS_Kv':50, 'Cb_stellate':60, 'Cb_stellate_Kv':130,
'Cb_stellate_Kv_only':75, 'STN': 25, 'STN_Kv':95, 'STN_Kv_only':80}
for model_name in models:
folder = '../Neuron_models/{}'.format(model_name)
fname = os.path.join(folder, "{}.hdf5".format(model_name)) # RS_inhib
with h5py.File(fname, "r+") as f:
I_mag = 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
start = np.int(f['data'].attrs['initial_period'] * 1 / f['data'].attrs['dt'])
stim_len = np.int((f['data'].attrs['stim_time'] - start) * f['data'].attrs['dt'])
time = np.arange(0, stim_len, f['data'].attrs['dt'])
spiking[model_name] = f['data']['V_m'][spike_ind[model_name]][start:]
model_F_inf[model_name] = f['analysis']['F_inf'][:]
firing_values.loc['spike_ind', model_name] = I_mag[spike_ind[model_name]]
firing_values.loc['ramp_down', model_name] = f['analysis']['ramp_I_down'][()]
firing_values.loc['ramp_up', model_name] = f['analysis']['ramp_I_up'][()]
firing_values.to_csv('firing_values.csv')
spiking.to_csv('model_spiking.csv')
model_F_inf.to_csv('model_F_inf.csv')
# %% model_ramp.csv # DONE #########################################################################
# | (index) | t | models ....
import numpy as np
import pandas as pd
models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN',
'STN_Kv', 'STN_Kv_only']
model_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'Cb stellate', 'Cb stellate +Kv1.1', 'Cb stellate $\Delta$Kv1.1',
'STN', 'STN +Kv1.1', 'STN $\Delta$Kv1.1']
col_names = ['t']
for mod in models: col_names.append(mod)
model_ramp = pd.DataFrame(columns=col_names)
sec = 4
dt = 0.01
ramp_len = int(sec * 1000 * 1 / dt)
t_ramp = np.arange(0, ramp_len) * dt
model_ramp.loc[:, 't'] = t_ramp
for model_name in models:
folder = '../Neuron_models/{}'.format(model_name)
fname = os.path.join(folder, "{}.hdf5".format(model_name)) # RS_inhib
with h5py.File(fname, "r+") as f:
model_ramp.loc[:, model_name] = f['analysis']['V_m_ramp'][()]
model_ramp.to_csv('model_ramp.csv')
#%% sim_mut_AUC.csv, sim_mut_rheo.csv # DONE #########################################################################
# generate mutation plot data
mutations = json.load(open("../mutations_effects_dict.json"))
keys_to_remove = ['V408L', 'T226R', 'R239S', 'R324T']
for key in keys_to_remove:
del mutations[key]
mutations_f = []
mutations_n = []
for mut in mutations:
mutations_n.append(mut)
mutations_f.append(mut.replace(" ", "_"))
models = ['RS_pyramidal_Kv', 'RS_inhib_Kv', 'FS_Kv', 'Cb_stellate', 'Cb_stellate_Kv', 'Cb_stellate_Kv_only', 'STN',
'STN_Kv', 'STN_Kv_only']
model_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'Cb stellate', 'Cb stellate +Kv1.1', 'Cb stellate $\Delta$Kv1.1',
'STN', 'STN +Kv1.1', 'STN $\Delta$Kv1.1']
AUC = pd.DataFrame(columns=mutations_n)
rheobase = pd.DataFrame(columns=mutations_n)
save_folder = '../KCNA1_mutations'
if not os.path.isdir(save_folder):
os.makedirs(save_folder)
for model_name in models:
folder = '../KCNA1_mutations/{}'.format(model_name)
for mut in list(mutations_n):
fname = os.path.join(folder, "{}.hdf5".format(mut.replace(" ", "_")))
with h5py.File(fname, "r+") as f:
rheobase.loc[mut.replace(" ", "_"), model_name] = f['analysis']['rheobase'][()]
AUC.loc[mut.replace(" ", "_"), model_name] = f['analysis']['AUC'][()]
AUC.replace(0., np.NaN, inplace=True)
rheobase.replace(0., np.NaN, inplace=True)
rheobase = (rheobase - rheobase.loc['WT', :]) /rheobase.loc['WT', :]
AUC = (AUC - AUC.loc['WT', :]) /AUC.loc['WT', :]
AUC.to_csv(os.path.join(save_folder, 'sim_mut_AUC.csv'))
rheobase.to_csv(os.path.join(save_folder, 'sim_mut_rheobase.csv'))
#########################################################################################################################

View File

@@ -0,0 +1,297 @@
import numpy as np
import h5py
import pandas as pd
import os
from ast import literal_eval
import json
import scipy.stats as stats
# folder
top_dir = '../Sensitivity_Analysis'
#%% create JSON files for each alt type
for dir_name in next(os.walk(top_dir))[1]:
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'][()]
try:
shift_rheo.loc[alt, var] = f['analysis']['rheobase'][()]
except:
print('shift', var, alt)
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'][()]
try:
slope_rheo.loc[alt, var] = f['analysis']['rheobase'][()]
except:
print('slope', var, alt)
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'][()]
try:
g_rheo.loc[alt, var] = f['analysis']['rheobase'][()]
except:
print('g', var, alt)
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)))
#%% AUC Correlation analysis
alt_dict = {}
alt_dict['m'] = 'Na activation'
alt_dict['h'] = 'Na inactivation'
alt_dict['n'] = 'K activation'
alt_dict['s'] = '$K_V1.1$ activation'
alt_dict['u'] = '$K_V1.1$inactivation'
alt_dict['a'] = 'A activation'
alt_dict['b'] = 'A inactivation'
alt_dict['n_A'] = 'A activation'
alt_dict['h_A'] = 'A inactivation'
alt_dict['Na'] = 'Na'
alt_dict['Kd'] = 'K'
alt_dict['Kv'] = '$K_V1.1$'
alt_dict['A'] = 'A'
alt_dict['Leak'] = 'Leak'
models =['RS_pyramidal', 'RS_inhib', 'FS', 'IB','Cb_stellate','Cb_stellate_Kv','Cb_stellate_Kv_only','STN','STN_Kv','STN_Kv_only']
model_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'IB','Cb stellate','Cb stellate +$K_V1.1$','Cb stellate $\Delta$$K_V1.1$','STN','STN +$K_V1.1$','STN $\Delta$$K_V1.1$']
shift_df = pd.DataFrame(columns=['model', 'corr', 'p_value', 'local corr', 'local p_value', 'ratio', '$\Delta V_{1/2}$', 'color']) # for boxplots
for mod in range(len(models)):
with open('./SA_summary_df/{}_shift_AUC.json'.format(models[mod])) as json_file:
df = pd.read_json(json_file)
df.sort_index(inplace=True)
df.replace(0., np.NaN, inplace=True)
df = (df - df.loc[0, :]) / df.loc[0, :]
zero_ind = np.argwhere(df.index == 0)[0][0]
ind = [df.index[zero_ind - 1], df.index[zero_ind], df.index[zero_ind + 1]]
df2 = df.loc[ind, :]
for c in df.keys():
tau, p = stats.kendalltau(df.index, df[c], nan_policy='omit')
tau_l, p_l = stats.kendalltau(df2.index, df2[c], nan_policy='omit')
ratio_tau = tau_l / tau
shift_df = shift_df.append(pd.Series([model_names[mod], tau, p,tau_l, p_l, ratio_tau, alt_dict[c],clr_dict[models[mod]]], index=shift_df.columns), ignore_index=True)
models =['RS_pyramidal', 'RS_inhib', 'FS', 'IB','Cb_stellate','Cb_stellate_Kv','Cb_stellate_Kv_only','STN','STN_Kv','STN_Kv_only']
model_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'IB','Cb stellate','Cb stellate +$K_V1.1$','Cb stellate $\Delta$$K_V1.1$','STN','STN +$K_V1.1$','STN $\Delta$$K_V1.1$']
slope_df = pd.DataFrame(columns=['model', 'corr', 'p_value','local corr', 'local p_value', 'ratio', 'Slope (k)', 'color']) # for boxplots
for mod in range(len(models)):
with open('./SA_summary_df/{}_slope_AUC.json'.format(models[mod])) as json_file:
df = pd.read_json(json_file, convert_dates=False, convert_axes=False)
df.index = df.index.map(float)
df.sort_index(inplace=True)
df.replace(0., np.NaN, inplace=True)
df = (df - df.loc[1.0, :]) / df.loc[1.0, :]
zero_ind = np.argwhere(df.index == 1)[0][0]
ind = [df.index[zero_ind - 1], df.index[zero_ind], df.index[zero_ind + 1]]
df2 = df.loc[ind, :]
for c in df.keys():
tau, p = stats.kendalltau(df.index, df[c], nan_policy='omit')
tau_l, p_l = stats.kendalltau(df2.index, df2[c], nan_policy='omit')
ratio_tau = tau_l/tau
slope_df = slope_df.append(pd.Series([model_names[mod], tau, p, tau_l, p_l, ratio_tau, alt_dict[c],clr_dict[models[mod]]], index=slope_df.columns), ignore_index=True)
models =['RS_pyramidal', 'RS_inhib', 'FS', 'IB','Cb_stellate','Cb_stellate_Kv','Cb_stellate_Kv_only','STN','STN_Kv','STN_Kv_only']
model_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'IB','Cb stellate','Cb stellate +$K_V1.1$','Cb stellate $\Delta$$K_V1.1$','STN','STN +$K_V1.1$','STN $\Delta$$K_V1.1$']
g_df = pd.DataFrame(columns=['model', 'corr', 'p_value', 'local corr', 'local p_value', 'ratio', 'g', 'color']) # for boxplots
for mod in range(len(models)):
with open('./SA_summary_df/{}_g_AUC.json'.format(models[mod])) as json_file:
df = pd.read_json(json_file, convert_dates=False, convert_axes=False)
df.index = df.index.map(float)
df.sort_index(inplace=True)
df.replace(0., np.NaN, inplace=True)
df = (df - df.loc[1.0, :]) / df.loc[1.0, :]
zero_ind = np.argwhere(df.index == 1)[0][0]
ind = [df.index[zero_ind - 1], df.index[zero_ind], df.index[zero_ind + 1]]
df2 = df.loc[ind, :]
for c in df.keys():
tau, p = stats.kendalltau(df.index, df[c], nan_policy='omit')
tau_l, p_l = stats.kendalltau(df2.index, df2[c], nan_policy='omit')
ratio_tau = tau_l / tau
g_df = g_df.append(pd.Series([model_names[mod], tau, p,tau_l, p_l, ratio_tau, alt_dict[c],clr_dict[models[mod]]], index=g_df.columns), ignore_index=True)
shift_df.to_json('./Sensitivity_analysis/shift_box_kendall_corr.json')
slope_df.to_json('./Sensitivity_analysis/slope_box_kendall_corr.json')
g_df.to_json('./Sensitivity_analysis/g_box_kendall_corr.json')
#%% rheobase correlation analysis
models =['RS_pyramidal', 'RS_inhib', 'FS', 'IB','Cb_stellate','Cb_stellate_Kv','Cb_stellate_Kv_only','STN','STN_Kv','STN_Kv_only']
model_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'IB','Cb stellate','Cb stellate +$K_V1.1$','Cb stellate $\Delta$$K_V1.1$','STN','STN +$K_V1.1$','STN $\Delta$$K_V1.1$']
shift_df = pd.DataFrame(columns=['model', 'corr', 'p_value', 'local corr', 'local p_value', 'ratio', '$\Delta V_{1/2}$', 'color']) # for boxplots
for mod in range(len(models)):
with open('./SA_summary_df/{}_shift_rheo.json'.format(models[mod])) as json_file:
df = pd.read_json(json_file)
df.sort_index(inplace=True)
df.replace(0., np.NaN, inplace=True)
df = (df - df.loc[0, :]) / df.loc[0, :]
zero_ind = np.argwhere(df.index == 0)[0][0]
ind = [df.index[zero_ind - 1], df.index[zero_ind], df.index[zero_ind + 1]]
df2 = df.loc[ind, :]
for c in df.keys():
tau, p = stats.kendalltau(df.index, df[c], nan_policy='omit')
tau_l, p_l = stats.kendalltau(df2.index, df2[c], nan_policy='omit')
ratio_tau = tau_l / tau
shift_df = shift_df.append(pd.Series([model_names[mod], tau, p,tau_l, p_l, ratio_tau, alt_dict[c],clr_dict[models[mod]]], index=shift_df.columns), ignore_index=True)
models =['RS_pyramidal', 'RS_inhib', 'FS', 'IB','Cb_stellate','Cb_stellate_Kv','Cb_stellate_Kv_only','STN','STN_Kv','STN_Kv_only']
model_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'IB','Cb stellate','Cb stellate +$K_V1.1$','Cb stellate $\Delta$$K_V1.1$','STN','STN +$K_V1.1$','STN $\Delta$$K_V1.1$']
slope_df = pd.DataFrame(columns=['model', 'corr', 'p_value','local corr', 'local p_value', 'ratio', 'Slope (k)', 'color']) # for boxplots
for mod in range(len(models)):
with open('./SA_summary_df/{}_slope_rheo.json'.format(models[mod])) as json_file:
df = pd.read_json(json_file, convert_dates=False, convert_axes=False)
df.index = df.index.map(float)
df.sort_index(inplace=True)
df.replace(0., np.NaN, inplace=True)
df = (df - df.loc[1.0, :]) / df.loc[1.0, :]
zero_ind = np.argwhere(df.index == 1)[0][0]
ind = [df.index[zero_ind - 1], df.index[zero_ind], df.index[zero_ind + 1]]
df2 = df.loc[ind, :]
for c in df.keys():
tau, p = stats.kendalltau(df.index, df[c], nan_policy='omit')
tau_l, p_l = stats.kendalltau(df2.index, df2[c], nan_policy='omit')
ratio_tau = tau_l/tau
slope_df = slope_df.append(pd.Series([model_names[mod], tau, p, tau_l, p_l, ratio_tau, alt_dict[c],clr_dict[models[mod]]], index=slope_df.columns), ignore_index=True)
models =['RS_pyramidal', 'RS_inhib', 'FS', 'IB','Cb_stellate','Cb_stellate_Kv','Cb_stellate_Kv_only','STN','STN_Kv','STN_Kv_only']
model_names = ['RS pyramidal', 'RS inhibitory', 'FS', 'IB','Cb stellate','Cb stellate +$K_V1.1$','Cb stellate $\Delta$$K_V1.1$','STN','STN +$K_V1.1$','STN $\Delta$$K_V1.1$']
g_df = pd.DataFrame(columns=['model', 'corr', 'p_value', 'local corr', 'local p_value', 'ratio', 'g', 'color']) # for boxplots
for mod in range(len(models)):
with open('./SA_summary_df/{}_g_rheo.json'.format(models[mod])) as json_file:
df = pd.read_json(json_file, convert_dates=False, convert_axes=False)
df.index = df.index.map(float)
df.sort_index(inplace=True)
df.replace(0., np.NaN, inplace=True)
df = (df - df.loc[1.0, :]) / df.loc[1.0, :]
zero_ind = np.argwhere(df.index == 1)[0][0]
ind = [df.index[zero_ind - 1], df.index[zero_ind], df.index[zero_ind + 1]]
df2 = df.loc[ind, :]
for c in df.keys():
tau, p = stats.kendalltau(df.index, df[c], nan_policy='omit')
tau_l, p_l = stats.kendalltau(df2.index, df2[c], nan_policy='omit')
ratio_tau = tau_l / tau
g_df = g_df.append(pd.Series([model_names[mod], tau, p,tau_l, p_l, ratio_tau, alt_dict[c],clr_dict[models[mod]]], index=g_df.columns), ignore_index=True)
shift_df.to_json('./Sensitivity_analysis/rheo_shift_box_kendall_corr.json')
slope_df.to_json('./Sensitivity_analysis/rheo_slope_box_kendall_corr.json')
g_df.to_json('./Sensitivity_analysis/rheo_g_box_kendall_corr.json')
#%% todo: CREATE CSV FILES ###################################################################################################
# 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')