OSCR

Distinguishing between response conflict and error expectancy in inhibitory error processing: the role of the presupplementary motor cortex.

Code ↔ Paper

The paper beside its authors' code: matches between them have not been computed for this paper yet.

Paper

Loaded from Europe PMC by your browser, not stored by OSCR: doi.org · Europe PMC

The paper is loaded when this pane is shown.

The authors' code

Jupyter notebook · 1,795 lines · 102 KB · no license

  1. # %%
  2. import pandas as pd
  3. import numpy as np
  4. import re
  5. import os
  6. import math
  7. import scipy.signal
  8. from sklearn import metrics
  9. import statsmodels.api as sm
  10. import sklearn.preprocessing
  11. import statsmodels.api as sm
  12. import statsmodels.formula.api as smf
  13. import scipy.io
  14. import nibabel as nib
  15. import matplotlib.pyplot as plt
  16. from scipy.interpolate import interp1d
  17. # %% [markdown]
  18. # # General directory operations
  19. # %%
  20. def create_list_directories(main_directory):
  21. #input: directory to the folder with log files
  22. #output: list of directories with log files
  23. return([main_directory + x for x in os.listdir(main_directory) if x[-3:]!='mat'])
  24. # %%
  25. def create_dict_values(main_directory):
  26. #input: directory to the folder with log files
  27. #output: dictionary with directory of a single log file as keys and basic SST statistics
  28. return({one_directory:collect_all_data(create_df_single_directory(one_directory)) for one_directory in create_list_directories(main_directory)})
  29. # %%
  30. def create_dict_values_trial_wise(main_directory):
  31. #input: directory to the folder with log files
  32. #output: dictionary with directory of a single log file as keys and data frames
  33. return({one_directory:create_df_single_directory(one_directory) for one_directory in create_list_directories(main_directory)})
  34. # %%
  35. def create_df_single_directory(given_directory):
  36. # Input: path to a single log file
  37. # Output: data frame with data from log files
  38. one_file = open(given_directory) # Open the log file
  39. wholesome_data = [] # Initialize list to store data rows
  40. for num, i in enumerate(one_file.readlines()):
  41. # Skip lines that contain metadata or are empty
  42. if i.split('\t')[0] != 'Nothing' and i.split('\t')[0] != 'Event Type' and i.split('\t')[0] != 'Picture' and i.split('\t')[0] != '\n':
  43. if num == 3:
  44. name_column = i.split('\t') # Line 4 contains column headers
  45. elif num > 4:
  46. data_row = i.split('\t') # Starting from line 5, get data rows
  47. # Pad missing values with 'NaN' to match header length
  48. if len(data_row) < len(name_column):
  49. zeros_row = np.zeros(len(name_column) - len(data_row))
  50. for j in zeros_row:
  51. data_row.append('NaN')
  52. wholesome_data.append(data_row) # Add cleaned row to list
  53. df = pd.DataFrame(wholesome_data) # Create DataFrame from data
  54. df.columns = name_column # Assign column names
  55. return df # Return the constructed DataFrame
  56. # %% [markdown]
  57. # # Necessary functions to compute general behavioral measures in performance
  58. # %%
  59. def num_trials(df):
  60. #input: data frame with logs data
  61. #output: the number of all trials
  62. return(num_go_trials(df) + num_stop_trials(df))
  63. # %%
  64. def num_go_trials(df):
  65. #input: data frame with logs data
  66. #output: the number of go trials
  67. return(len(select_go_trials(df)))
  68. # %%
  69. def select_go_trials(df):
  70. #input: data frame with logs data
  71. #output: list of all go trials with indices
  72. return(select_go_correct_trials(df)+select_go_incorrect_trials(df))
  73. # %%
  74. def num_stop_trials(df):
  75. #input: data frame with logs data
  76. #output: list of all stop trials with indices
  77. return(len(select_stop_trials(df)))
  78. # %%
  79. def select_go_correct_trials(df):
  80. #input: data frame with logs data
  81. #output: list of all go trials performed correclty with indices
  82. return([(num, one_stim_type) for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='hit'])
  83. # %%
  84. def select_go_incorrect_trials(df):
  85. #input: data frame with logs data
  86. #output: list of all go trials performed incorrectly with indices
  87. return([(num, one_stim_type) for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='incorrect' or one_stim_type=='miss'])
  88. # %%
  89. def compute_percent_go_correct(df):
  90. #input: data frame with logs data
  91. #output: percentage of go trials correctly performed
  92. return(float(len(select_go_correct_trials(df)))/float(len(select_go_trials(df))))
  93. # %%
  94. def compute_percent_go_incorrect(df):
  95. #input: data frame with logs data
  96. #output: percentage of go trials incorrectly performed
  97. return((float(len(select_go_trials(df))) - float(len(select_go_correct_trials(df))))/float(len(select_go_trials(df))))
  98. # %%
  99. def select_stop_trials(df):
  100. #input: data frame with logs data
  101. #output: list of all stop trials with indices
  102. return(select_stop_correct_trials(df)+select_stop_incorrect_trials(df))
  103. # %%
  104. def select_stop_correct_trials(df):
  105. #input: data frame with logs data
  106. #output: list of all stop trials with indices performed correctly (inhibited) with indices
  107. return([(num, one_stim_type) for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='other' and df['Event Type'][num]=='Nothing'])
  108. # %%
  109. def select_stop_incorrect_trials(df):
  110. #input: data frame with logs data
  111. #output: list of all stop trials with indices performed incorrectly (uninhibited) with indices
  112. return([(num, one_stim_type) for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='false_alarm'])
  113. # %%
  114. def compute_percent_stop_correct(df):
  115. #input: data frame with logs data
  116. #output: percentage of go trials incorrectly performed
  117. return(float(len(select_stop_correct_trials(df)))/float(len(select_stop_trials(df))))
  118. # %%
  119. def select_go_rt(df):
  120. #input: data frame with logs data
  121. #output: list of reaction times in go trials (if miss - reaction time is equal to 0)
  122. return([float(df['TTime'][num_trial+1])/10000 if type_trial!='miss' else 0 for num_trial, type_trial in select_go_trials(df)])
  123. # %%
  124. def select_go_correct_rt(df):
  125. #input: data frame with logs data
  126. #output: list of reaction times in go correct trials
  127. return([(num_trial, float(df['TTime'][num_trial+1])/10000) for num_trial, type_trial in select_go_correct_trials(df)])
  128. # %%
  129. def select_go_incorrect_rt(df):
  130. #input: data frame with logs data
  131. #output: list of reaction times in go incorrect trials
  132. return([(num_trial, float(df['TTime'][num_trial+1])/10000) if type_trial=='incorrect' else (num_trial, 0) for num_trial, type_trial in select_go_incorrect_trials(df)])
  133. # %%
  134. def compute_mean_rt_go_correct(df):
  135. #input: data frame with logs data
  136. #output: list of mean reaction times in go correct trials
  137. return(np.mean(np.array(select_go_correct_rt(df))[:,1]))
  138. # %%
  139. def compute_mean_rt_stop_incorrect(df):
  140. #input: data frame with logs data
  141. #output: list of mean reaction times in go incorrect trials
  142. return(np.mean(select_stop_incorrect_rt(df)))
  143. # %%
  144. def select_stop_incorrect_rt(df):
  145. #input: data frame with logs data
  146. #output: list of reaction times in stop incorrect trials
  147. return([float(df['TTime'][num_trial+1])/10000 for num_trial, type_trial in select_stop_incorrect_trials(df)])
  148. # %%
  149. def select_stop_correct_ssd(df):
  150. #input: data frame with logs data
  151. #output: list of stop signal delays in stop correct trials
  152. return([float(re.findall(r'\d{2,3}',df['Code'][num_trial])[0])/1000 for num_trial, stim_type in select_stop_correct_trials(df)])
  153. # %%
  154. def select_stop_incorrect_ssd(df):
  155. #input: data frame with logs data
  156. #output: list of stop signal delays in stop incorrect trials
  157. return([float(re.findall(r'\d{2,3}',df['Code'][num_trial])[0])/1000 for num_trial, stim_type in select_stop_incorrect_trials(df)])
  158. # %%
  159. def select_stop_ssd(df):
  160. #input: data frame with logs data
  161. #output: list of stop signal delays in stop trials
  162. return(select_stop_correct_ssd(df) + select_stop_incorrect_ssd(df))
  163. # %%
  164. def compute_mean_ssd(df):
  165. #input: data frame with logs data
  166. #output: list of mean stop signal delays in stop trials
  167. return(np.mean(select_stop_ssd(df)))
  168. # %%
  169. def compute_SSRT(df):
  170. #input: data frame with logs data
  171. #output: Stop Signal Reaction Time for a given run
  172. return(sorted(select_go_correct_rt(df))[round((1.-compute_percent_stop_correct(df))*len(select_go_correct_trials(df)))][1] - compute_mean_ssd(df))
  173. # %%
  174. def collect_all_data(df):
  175. #input: data frame with logs data
  176. #output: basic statistics in a given run
  177. return([num_trials(df),
  178. num_stop_trials(df),
  179. compute_percent_go_correct(df),
  180. compute_percent_go_incorrect(df),
  181. compute_percent_stop_correct(df),
  182. compute_mean_rt_go_correct(df),
  183. compute_mean_rt_stop_incorrect(df),
  184. compute_mean_ssd(df),
  185. compute_SSRT(df)])
  186. # %% [markdown]
  187. # # Create logfiles
  188. # %%
  189. def pulse_time_end(df):
  190. #input: data frame with logs data
  191. #output: time of the first event after turning on mri scanner
  192. return((float(df['Time'][[num for num, i in enumerate(df['Event Type']) if i=='Picture'][-1]]))/10000)
  193. # %%
  194. def select_go_correct_times(df):
  195. #input: data frame with logs data
  196. #output: list of presentation times of go signal in correctly performed trials
  197. return([float(df['Time'][num])/10000 - pulse_time_end(df) for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='hit'])
  198. # %%
  199. def select_go_correct_execution_times(df):
  200. #input: data frame with logs data
  201. #output: list of times of making decision in correctly performed go trials
  202. return([(float(df['Time'][num])/10000 - pulse_time_end(df))+float(df['TTime'][num+1])/10000 for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='hit'])
  203. # %%
  204. def select_go_incorrect_times(df):
  205. #input: data frame with logs data
  206. #output: list of presentation times of go signal in incorrectly performed trials
  207. return([float(df['Time'][num])/10000 - pulse_time_end(df) for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='incorrect' or one_stim_type=='miss'])
  208. # %%
  209. def select_stop_correct_signal_times(df):
  210. #input: data frame with logs data
  211. #output: list of presentation times of stop signal in correctly performed trials
  212. return([(float(df['Time'][num])/10000 - pulse_time_end(df))+float(re.findall(r'\d{2,3}',df['Code'][num])[0])/1000 for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='other' and df['Event Type'][num]=='Nothing'])
  213. # %%
  214. def select_stop_incorrect_signal_times(df):
  215. #input: data frame with logs data
  216. #output: list of presentation times of go signal in incorrectly performed trials
  217. return([(float(df['Time'][num])/10000 - pulse_time_end(df))+float(re.findall(r'\d{2,3}',df['Code'][num])[0])/1000 for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='false_alarm'])
  218. # %%
  219. def select_stop_incorrect_rt(df):
  220. #input: data frame with logs data
  221. #output: list of reaction times in stop incorrect trials
  222. return([float(df['TTime'][num+1])/10000 for num, one_stim_type in enumerate(df['Stim Type']) if one_stim_type=='false_alarm'])
  223. # %%
  224. def create_pmod_model_new_model(main_directory, out_dir, names):
  225. #Creating log files for spm analsysi
  226. #input: directory with log files folder, where to save, names of regressors
  227. for one_dir in create_list_directories(main_directory):
  228. print(one_dir)
  229. subj = re.findall(r'sub-\d{2}', one_dir)[0]
  230. run = re.findall(r'run-\d{2}', one_dir)[0]
  231. onsets=[sorted(select_go_correct_times(create_df_single_directory(one_dir)) + select_go_incorrect_times(create_df_single_directory(one_dir)) + select_stop_correct_times(create_df_single_directory(one_dir)) + select_stop_incorrect_times(create_df_single_directory(one_dir))),
  232. select_go_correct_execution_times(create_df_single_directory(one_dir)),
  233. select_stop_correct_signal_times(create_df_single_directory(one_dir)),
  234. select_stop_incorrect_signal_times(create_df_single_directory(one_dir))]
  235. durations = [list(np.zeros(len(i))) for i in onsets]
  236. pmods = [select_stop_incorrect_rt(create_df_single_directory(one_dir))]
  237. pmods_names = ['si_rt']
  238. dict_to_save = {'names':names, 'onsets':onsets, 'durations':durations, 'pmods':pmods, 'pmods_names':pmods_names}
  239. scipy.io.savemat(out_dir + subj+'_'+run+'.mat', dict_to_save)
  240. # %%
  241. create_pmod_model_new_model('C:/Users/443218/Documents/ProjektSSTError/logi_rejected/', 'C:/Users/443218/Documents/ProjektSSTError/new_mat_logs/', ['go_presentation','go_c','stop_c','stop_ic'])
  242. # %% [markdown]
  243. # # Summarize behavioral measures
  244. # %%
  245. def create_summary_df(main_directory):
  246. #input: directory to the folder with log files
  247. #output: data frame with basic statistics in each run
  248. return(pd.DataFrame(create_dict_values(main_directory)).transpose())
  249. # %%
  250. all_data_behavioral_summary = create_summary_df(<directory_to_logs_files>)
  251. # %%
  252. all_data_behavioral_summary.columns = ['n_trials', 'n_stop', 'percent_correct_GO', 'percent_incorrect_go', 'percent_correct_stop', 'mean_rtGo', 'mean_rtStop', 'mean_SSD', 'IRM', 'SSRT']
  253. # %%
  254. np.mean(all_data_behavioral_summary)
  255. # %% [markdown]
  256. # # Computing Post Error Adjustment
  257. # %%
  258. def take_pea_sri_2(one_df):
  259. #input: data frame with logs
  260. # output: events with times before and after committing an error, stop response interval and ssd
  261. list_of_delayed_events = []
  262. for num, list_events in enumerate(create_list_events_times(one_df)):
  263. if num!=0 and num+1!=len(create_list_events_times(one_df)) and list_events[0]=='stop_incorrect' and create_list_events_times(one_df)[num-1][0]=='go_correct' and create_list_events_times(one_df)[num+1][0]=='go_correct':
  264. list_of_delayed_events.append((create_list_events_times(one_df)[num-1][2], create_list_events_times(one_df)[num+1][2], list_events[2]-float(re.findall(r'\d{2,3}', list_events[3])[0])/1000, float(re.findall(r'\d{2,3}', list_events[3])[0])/1000))
  265. elif num!=0 and num+1!=len(create_list_events_times(one_df)) and list_events[0]=='stop_incorrect' and create_list_events_times(one_df)[num-1][0]=='go_correct' and create_list_events_times(one_df)[num+1][0]=='stop_incorrect':
  266. x=1
  267. while num+x!=len(create_list_events_times(one_df)) and create_list_events_times(one_df)[num+x][0]!='go_correct':
  268. if create_list_events_times(one_df)[num+x][0]=='stop_correct':
  269. break
  270. elif create_list_events_times(one_df)[num+x][0]=='stop_incorrect':
  271. x+=1
  272. else:
  273. break
  274. if num+x!=len(create_list_events_times(one_df)) and create_list_events_times(one_df)[num+x][0]=='go_correct':
  275. list_of_delayed_events.append((create_list_events_times(one_df)[num-1][2], create_list_events_times(one_df)[num+x][2], list_events[2]-float(re.findall(r'\d{2,3}', list_events[3])[0])/1000, float(re.findall(r'\d{2,3}', list_events[3])[0])/1000))
  276. elif num!=0 and num+1!=len(create_list_events_times(one_df)) and list_events[0]=='stop_incorrect' and create_list_events_times(one_df)[num-1][0]=='stop_incorrect' and create_list_events_times(one_df)[num+1][0]=='go_correct':
  277. x=1
  278. while num-x!=0 and create_list_events_times(one_df)[num-x][0]!='go_correct':
  279. if create_list_events_times(one_df)[num-x][0]=='stop_correct':
  280. break
  281. elif create_list_events_times(one_df)[num-x][0]=='stop_incorrect':
  282. x+=1
  283. else:
  284. break
  285. if num-x!=0 and create_list_events_times(one_df)[num-x][0]=='go_correct':
  286. list_of_delayed_events.append((create_list_events_times(one_df)[num-x][2], create_list_events_times(one_df)[num+1][2], list_events[2]-float(re.findall(r'\d{2,3}', list_events[3])[0])/1000, float(re.findall(r'\d{2,3}', list_events[3])[0])/1000))
  287. elif num!=0 and num+1!=len(create_list_events_times(one_df)) and list_events[0]=='stop_incorrect' and create_list_events_times(one_df)[num-1][0]=='stop_incorrect' and create_list_events_times(one_df)[num+1][0]=='stop_incorrect':
  288. x=1
  289. y=1
  290. while num-x!=0 and create_list_events_times(one_df)[num-x][0]!='go_correct':
  291. if create_list_events_times(one_df)[num-x][0]=='stop_correct':
  292. break
  293. elif create_list_events_times(one_df)[num-x][0]=='stop_incorrect':
  294. x+=1
  295. else:
  296. break
  297. while num+y!=len(create_list_events_times(one_df)) and create_list_events_times(one_df)[num+y][0]!='go_correct':
  298. if create_list_events_times(one_df)[num+y][0]=='stop_correct':
  299. break
  300. elif create_list_events_times(one_df)[num+y][0]=='stop_incorrect':
  301. y+=1
  302. else:
  303. break
  304. if num-x!=0 and num+y!=len(create_list_events_times(one_df)) and create_list_events_times(one_df)[num-x][0]=='go_correct' and create_list_events_times(one_df)[num+y][0]=='go_correct':
  305. list_of_delayed_events.append((create_list_events_times(one_df)[num-x][2], create_list_events_times(one_df)[num+y][2], list_events[2]-float(re.findall(r'\d{2,3}', list_events[3])[0])/1000, float(re.findall(r'\d{2,3}', list_events[3])[0])/1000))
  306. elif num!=0 and num+1!=len(create_list_events_times(one_df)) and list_events[0]=='stop_incorrect' and create_list_events_times(one_df)[num-1][0]=='miss' and create_list_events_times(one_df)[num+1][0]=='stop_incorrect':
  307. continue
  308. elif num!=0 and num+1!=len(create_list_events_times(one_df)) and list_events[0]=='stop_incorrect' and create_list_events_times(one_df)[num-1][0]=='miss' and create_list_events_times(one_df)[num+1][0]=='stop_incorrect':
  309. continue
  310. indices=[num for num, (pre,post, sri, ssd) in enumerate(list_of_delayed_events) for num2, (pre2,post2, sri2, ssd) in enumerate(list_of_delayed_events[num+1:]) if num!=num2 and pre==pre2 and post==post2]
  311. z=0
  312. print(indices)
  313. for num2, i in enumerate(indices):
  314. del(list_of_delayed_events[i+1-z])
  315. z+=1
  316. return(list_of_delayed_events)
  317. # %%
  318. def compute_pea_sri(df):
  319. #input date frame with logs
  320. #output: creating an array with post error times, relative difference post and pre error times, sri and ssd in stop incorrect trials
  321. return(np.array([[post,post-pre, sri,ssd] for (pre,post, sri, ssd) in take_pea_sri_2(df)]))
  322. # %%
  323. def array_list_pea_sri(main_directory):
  324. #input directory to folder with log files
  325. #output: dictionary with log files directories as kets and post error slowing measures as values
  326. return({one_run:compute_pea_sri(create_df_single_directory(one_run)) for one_run in [main_directory + one_dir for one_dir in os.listdir(main_directory)]})
  327. # %%
  328. def create_list_events_times(df):
  329. #input: data Frame with logs
  330. #output: list of sequence of go and stop events in order of appearing and their timings
  331. return([i for num2, i in enumerate([('go_correct', float(df['Time'][num])/10000 - pulse_time_end(df), float(df['TTime'][num+1])/10000) if event_type=='hit' else ('go_incorrect', float(df['Time'][num])/10000- pulse_time_end(df), float(df['TTime'][num+1])/10000) if event_type=='incorrect' else ('stop_correct', float(df['Time'][num])/10000- pulse_time_end(df), 0, df['Code'][num]) if event_type=='other' else ('stop_incorrect', float(df['Time'][num])/10000 - pulse_time_end(df), float(df['TTime'][num+1])/10000, df['Code'][num]) if event_type=='false_alarm' else 0 for num, event_type in enumerate(df['Stim Type'])]) if i!=0][1:])
  332. # %%
  333. all_data_pea_sri = array_list_pea_sri(<directory_to_folder_with_log_data>)
  334. # %%
  335. all_data_pea_sri_fmri={keys:values for keys, values in all_data_pea_sri.items() if keys[-26:] in os.listdir(<directory_to_folder_with_log_data_in_fmri>)}
  336. # %%
  337. all_sri_observations = [sri for logs, array_data in all_data_pea_sri.items() for [post,pea, sri,ssd] in array_data]
  338. mri_sri_observations = [sri for logs, array_data in all_data_pea_sri_fmri.items() for [post,pea, sri,ssd] in array_data]
  339. # %%
  340. dict_subj_sri_all = {}
  341. for log_key, array_data in all_data_pea_sri.items():
  342. if re.findall(r'sub-\d{2}',log_key)[0] not in dict_subj_sri_all:
  343. dict_subj_sri_all[re.findall(r'sub-\d{2}',log_key)[0]]=[array_data[:,2]]
  344. else:
  345. dict_subj_sri_all[re.findall(r'sub-\d{2}',log_key)[0]].append(array_data[:,2])
  346. dict_subj_sri_all_corrected = {}
  347. for subj, values in dict_subj_sri_all.items():
  348. if len(values)==1:
  349. dict_subj_sri_all_corrected[subj]=values
  350. else:
  351. dict_subj_sri_all_corrected[subj]=[one_sri for one_array in values for one_sri in one_array]
  352. dict_subj_sri_all_mean = {subj:[np.mean(list_sri), np.std(list_sri)] for subj, list_sri in dict_subj_sri_all_corrected.items()}
  353. mean_sri_all_subj = np.mean([mean_sri for subj, [mean_sri, std_sri] in dict_subj_sri_all_mean.items()])
  354. # %% [markdown]
  355. # # Regression of SRI on PEA¶
  356. # %%
  357. #list of all subjects
  358. subj_list = np.unique([re.findall(r'sub-\d{2}', i)[0] for i in os.listdir(<directory_to_folder_with_log_data>)])
  359. # %%
  360. #Computing the dict with post reaction times and sri
  361. dict_post_sri_4={log_name2:np.array([array_2[:,0],array_2[:,2],array_2[:,3]]) for log_name2, array_2 in all_data_pea_sri_fmri.items() if len(array_2)!=0} # and log_name not in list_pre_post_irm_not
  362. # %%
  363. #creating data frame with data for model
  364. df_post_sri = pd.DataFrame([[one_sub, post, array_pea_sri[1][num], array_pea_sri[2][num]] for one_sub in subj_list for log_name, array_pea_sri in dict_post_sri_4.items() for num, post in enumerate(array_pea_sri[0]) if re.findall(r'sub-\d{2}',log_name)[0]==one_sub])
  365. df_post_sri.columns = ['subject', 'post', 'sri', 'ssd']
  366. # %%
  367. #Mixed model without excluding
  368. md = smf.mixedlm("post ~ sri + ssd", df_post_sri.iloc[:,1:], groups=df_post_sri["subject"])
  369. mdf = md.fit()
  370. print(mdf.summary())
  371. # %% [markdown]
  372. # # Compute Time Series and SRI relations
  373. # %%
  374. #taking
  375. # %%
  376. main_directory_preprocessed = #<directory to preprocessed data>
  377. dict_sub_run_files={str(re.findall(r'sub-\d{2}', one_run)[0]) + '_' + str(re.findall(r'run-\d{2}',one_run)[0]):main_directory_preprocessed+one_run for one_run in os.listdir(main_directory_preprocessed)}
  378. # %%
  379. #taking MNI coordinates of ROIs from MRI analysis
  380. # %%
  381. mask_file_SFG = #<directory to ROI from SFG
  382. mask_array_SFG = nib.load(mask_file_SFG).get_data()
  383. coordinates_mask_SFG = [(x_coor, y_coor, z_coor) for (x_coor, x_data) in enumerate(mask_array_SFG)
  384. for (y_coor, y_data) in enumerate(x_data)
  385. for (z_coor, z_data) in enumerate(y_data) if z_data!=0]
  386. # %%
  387. mask_file_left_insula = #<directory to ROI from left insula
  388. mask_array_left_insula = nib.load(mask_file_left_insula).get_data()
  389. coordinates_mask_left_insula = [(x_coor, y_coor, z_coor) for (x_coor, x_data) in enumerate(mask_array_left_insula)
  390. for (y_coor, y_data) in enumerate(x_data)
  391. for (z_coor, z_data) in enumerate(y_data) if z_data!=0]
  392. # %%
  393. mask_file_left_SPR = #directory to ROI from left supramarginal gyrus cluster 1
  394. mask_array_left_SPR = nib.load(mask_file_left_SFG).get_data()
  395. coordinates_mask_left_SPR = [(x_coor, y_coor, z_coor) for (x_coor, x_data) in enumerate(mask_array_left_SPR)
  396. for (y_coor, y_data) in enumerate(x_data)
  397. for (z_coor, z_data) in enumerate(y_data) if z_data!=0]
  398. # %%
  399. mask_file_left_supramarginal = #directory to ROI from left supramarginal gyrus cluster 2
  400. mask_array_left_supramarginal = nib.load(mask_file_left_supramarginal).get_data()
  401. coordinates_mask_left_supramarginal = [(x_coor, y_coor, z_coor) for (x_coor, x_data) in enumerate(mask_array_left_supramarginal)
  402. for (y_coor, y_data) in enumerate(x_data)
  403. for (z_coor, z_data) in enumerate(y_data) if z_data!=0]
  404. # %%
  405. mask_file_right_insula= #directory to ROI from right insula
  406. mask_array_right_insula = nib.load(mask_file_right_insula).get_data()
  407. coordinates_mask_right_insula = [(x_coor, y_coor, z_coor) for (x_coor, x_data) in enumerate(mask_array_right_insula)
  408. for (y_coor, y_data) in enumerate(x_data)
  409. for (z_coor, z_data) in enumerate(y_data) if z_data!=0]
  410. # %%
  411. mask_file_right_lingual= #directory to ROI from right lingual gyrus
  412. mask_array_right_lingual = nib.load(mask_file_right_lingual).get_data()
  413. coordinates_mask_right_lingual = [(x_coor, y_coor, z_coor) for (x_coor, x_data) in enumerate(mask_array_right_lingual)
  414. for (y_coor, y_data) in enumerate(x_data)
  415. for (z_coor, z_data) in enumerate(y_data) if z_data!=0]
  416. # %%
  417. mask_file_right_supramarginal= #directory to ROI from right supramarginal gyrus
  418. mask_array_right_supramarginal = nib.load(mask_file_right_supramarginal).get_data()
  419. coordinates_mask_right_supramarginal = [(x_coor, y_coor, z_coor) for (x_coor, x_data) in enumerate(mask_array_right_supramarginal)
  420. for (y_coor, y_data) in enumerate(x_data)
  421. for (z_coor, z_data) in enumerate(y_data) if z_data!=0]
  422. # %%
  423. #creating average value of time series in given ROIs
  424. # %%
  425. dict_averaged_ts_in_roi_SFG = {}
  426. for (id_sub_run, directory) in dict_sub_run_files.items():
  427. print(id_sub_run)
  428. file_directory=nib.load(directory)
  429. mean_ts = np.mean([file_directory.get_data()[x,y,z,:] for (x,y,z) in coordinates_mask_SFG], axis = 0)
  430. dict_averaged_ts_in_roi_SFG[id_sub_run]=mean_ts
  431. # %%
  432. dict_averaged_ts_in_roi_left_insula = {}
  433. for (id_sub_run, directory) in dict_sub_run_files.items():
  434. print(id_sub_run)
  435. file_directory=nib.load(directory)
  436. mean_ts = np.mean([file_directory.get_data()[x,y,z,:] for (x,y,z) in coordinates_mask_left_insula], axis = 0)
  437. dict_averaged_ts_in_roi_left_insula[id_sub_run]=mean_ts
  438. # %%
  439. dict_averaged_ts_in_roi_left_supramarginal = {}
  440. for (id_sub_run, directory) in dict_sub_run_files.items():
  441. print(id_sub_run)
  442. file_directory=nib.load(directory)
  443. mean_ts = np.mean([file_directory.get_data()[x,y,z,:] for (x,y,z) in coordinates_mask_left_supramarginal], axis = 0)
  444. dict_averaged_ts_in_roi_left_supramarginal[id_sub_run]=mean_ts
  445. # %%
  446. dict_averaged_ts_in_roi_left_SPR = {}
  447. for (id_sub_run, directory) in dict_sub_run_files.items():
  448. print(id_sub_run)
  449. file_directory=nib.load(directory)
  450. mean_ts = np.mean([file_directory.get_data()[x,y,z,:] for (x,y,z) in coordinates_mask_left_SPR], axis = 0)
  451. dict_averaged_ts_in_roi_left_SPR[id_sub_run]=mean_ts
  452. # %%
  453. dict_averaged_ts_in_roi_right_insula = {}
  454. for (id_sub_run, directory) in dict_sub_run_files.items():
  455. print(id_sub_run)
  456. file_directory=nib.load(directory)
  457. mean_ts = np.mean([file_directory.get_data()[x,y,z,:] for (x,y,z) in coordinates_mask_right_insula], axis = 0)
  458. dict_averaged_ts_in_roi_right_insula[id_sub_run]=mean_ts
  459. # %%
  460. dict_averaged_ts_in_roi_right_lingual = {}
  461. for (id_sub_run, directory) in dict_sub_run_files.items():
  462. print(id_sub_run)
  463. file_directory=nib.load(directory)
  464. mean_ts = np.mean([file_directory.get_data()[x,y,z,:] for (x,y,z) in coordinates_mask_right_lingual], axis = 0)
  465. dict_averaged_ts_in_roi_right_lingual[id_sub_run]=mean_ts
  466. # %%
  467. dict_averaged_ts_in_roi_right_supramarginal = {}
  468. for (id_sub_run, directory) in dict_sub_run_files.items():
  469. print(id_sub_run)
  470. file_directory=nib.load(directory)
  471. mean_ts = np.mean([file_directory.get_data()[x,y,z,:] for (x,y,z) in coordinates_mask_right_supramarginal], axis = 0)
  472. dict_averaged_ts_in_roi_right_supramarginal[id_sub_run]=mean_ts
  473. # %%
  474. #making interpolation of time series in given ROIs
  475. # %%
  476. dict_interpolated_ts_SFG = {}
  477. for id_sub_run, ts in dict_averaged_ts_in_roi_SFG.items():
  478. original_time_points = np.arange(0, len(ts) * 1.8, 1.8)
  479. original_values = ts # Your original values here
  480. # New time points for interpolation sampled every 100 ms
  481. new_time_points = np.arange(0, original_time_points[-1], 0.1)
  482. # Perform linear interpolation
  483. f = interp1d(original_time_points, original_values, kind='linear')
  484. # Interpolate values at new time points
  485. interpolated_values = f(new_time_points)
  486. # Output the interpolated time series
  487. dict_interpolated_ts_SFG[id_sub_run] = interpolated_values
  488. # %%
  489. dict_interpolated_ts_left_insula = {}
  490. for id_sub_run, ts in dict_averaged_ts_in_roi_left_insula.items():
  491. original_time_points = np.arange(0, len(ts) * 1.8, 1.8)
  492. original_values = ts # Your original values here
  493. # New time points for interpolation sampled every 100 ms
  494. new_time_points = np.arange(0, original_time_points[-1], 0.1)
  495. # Perform linear interpolation
  496. f = interp1d(original_time_points, original_values, kind='linear')
  497. # Interpolate values at new time points
  498. interpolated_values = f(new_time_points)
  499. # Output the interpolated time series
  500. dict_interpolated_ts_left_insula[id_sub_run] = interpolated_values
  501. # %%
  502. dict_interpolated_ts_left_SPR = {}
  503. for id_sub_run, ts in dict_averaged_ts_in_roi_left_SPR.items():
  504. original_time_points = np.arange(0, len(ts) * 1.8, 1.8)
  505. original_values = ts # Your original values here
  506. # New time points for interpolation sampled every 100 ms
  507. new_time_points = np.arange(0, original_time_points[-1], 0.1)
  508. # Perform linear interpolation
  509. f = interp1d(original_time_points, original_values, kind='linear')
  510. # Interpolate values at new time points
  511. interpolated_values = f(new_time_points)
  512. # Output the interpolated time series
  513. dict_interpolated_ts_left_SPR[id_sub_run] = interpolated_values
  514. # %%
  515. dict_interpolated_ts_left_supramarginal = {}
  516. for id_sub_run, ts in dict_averaged_ts_in_roi_left_supramarginal.items():
  517. original_time_points = np.arange(0, len(ts) * 1.8, 1.8)
  518. original_values = ts # Your original values here
  519. # New time points for interpolation sampled every 100 ms
  520. new_time_points = np.arange(0, original_time_points[-1], 0.1)
  521. # Perform linear interpolation
  522. f = interp1d(original_time_points, original_values, kind='linear')
  523. # Interpolate values at new time points
  524. interpolated_values = f(new_time_points)
  525. # Output the interpolated time series
  526. dict_interpolated_ts_left_supramarginal[id_sub_run] = interpolated_values
  527. # %%
  528. dict_interpolated_ts_right_insula = {}
  529. for id_sub_run, ts in dict_averaged_ts_in_roi_right_insula.items():
  530. original_time_points = np.arange(0, len(ts) * 1.8, 1.8)
  531. original_values = ts # Your original values here
  532. # New time points for interpolation sampled every 100 ms
  533. new_time_points = np.arange(0, original_time_points[-1], 0.1)
  534. # Perform linear interpolation
  535. f = interp1d(original_time_points, original_values, kind='linear')
  536. # Interpolate values at new time points
  537. interpolated_values = f(new_time_points)
  538. # Output the interpolated time series
  539. dict_interpolated_ts_right_insula[id_sub_run] = interpolated_values
  540. # %%
  541. dict_interpolated_ts_right_lingual = {}
  542. for id_sub_run, ts in dict_averaged_ts_in_roi_right_lingual.items():
  543. original_time_points = np.arange(0, len(ts) * 1.8, 1.8)
  544. original_values = ts # Your original values here
  545. # New time points for interpolation sampled every 100 ms
  546. new_time_points = np.arange(0, original_time_points[-1], 0.1)
  547. # Perform linear interpolation
  548. f = interp1d(original_time_points, original_values, kind='linear')
  549. # Interpolate values at new time points
  550. interpolated_values = f(new_time_points)
  551. # Output the interpolated time series
  552. dict_interpolated_ts_right_lingual[id_sub_run] = interpolated_values
  553. # %%
  554. dict_interpolated_ts_right_supramarginal = {}
  555. for id_sub_run, ts in dict_averaged_ts_in_roi_right_supramarginal.items():
  556. original_time_points = np.arange(0, len(ts) * 1.8, 1.8)
  557. original_values = ts # Your original values here
  558. # New time points for interpolation sampled every 100 ms
  559. new_time_points = np.arange(0, original_time_points[-1], 0.1)
  560. # Perform linear interpolation
  561. f = interp1d(original_time_points, original_values, kind='linear')
  562. # Interpolate values at new time points
  563. interpolated_values = f(new_time_points)
  564. # Output the interpolated time series
  565. dict_interpolated_ts_right_supramarginal[id_sub_run] = interpolated_values
  566. # %%
  567. #taking onsets of stop correct and incorrect timings
  568. # %%
  569. dict_onsets = {}
  570. for one_dir in create_list_directories('C:/Users/443218/Documents/ProjektSSTError/logi_rejected/'):
  571. one_df=create_df_single_directory(one_dir)
  572. dict_stop_onsets={'stop_incorrect':[select_stop_incorrect_times(one_df), select_ssd_notinhibited(one_df), select_stop_incorrect_rt(one_df)],
  573. 'stop_correct':[select_stop_correct_times(one_df), select_ssd_inhibited(one_df)]}
  574. dict_onsets[str(re.findall(r'sub-\d{2}',one_dir)[0])+'_'+str(re.findall(r'run-\d{2}', one_dir)[0])]=dict_stop_onsets
  575. # %%
  576. #extending timings to fit interpolated time series
  577. # %%
  578. dict_onsets_100 = {id_s_r:{stop_id:[[one_elem/.1 for one_elem in one_list] for one_list in list_onsets] for stop_id, list_onsets in dict_values.items()} for id_s_r, dict_values in dict_onsets.items()}
  579. # %%
  580. #annotating BOLD values in given rois in given onset timings
  581. # %%
  582. dict_ts_s_ic_SFG = {}
  583. for id_ts, ts in dict_interpolated_ts_SFG.items():
  584. list_ts = []
  585. if id_ts in list(dict_onsets_100.keys()):
  586. for num,ind_s_i in enumerate(dict_onsets_100[id_ts]['stop_incorrect'][0]):
  587. indeks_before=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])-40)
  588. indeks_after=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])+140)
  589. if indeks_before>0 and indeks_after<len(ts):
  590. list_ts.append([ts[indeks_before:indeks_after], dict_onsets_100[id_ts]['stop_incorrect'][1], dict_onsets_100[id_ts]['stop_incorrect'][2]])
  591. dict_ts_s_ic_SFG[id_ts]=list_ts
  592. # %%
  593. dict_ts_s_ic_left_insula = {}
  594. for id_ts, ts in dict_interpolated_ts_left_insula.items():
  595. list_ts = []
  596. if id_ts in list(dict_onsets_100.keys()):
  597. for num,ind_s_i in enumerate(dict_onsets_100[id_ts]['stop_incorrect'][0]):
  598. indeks_before=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])-40)
  599. indeks_after=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])+140)
  600. if indeks_before>0 and indeks_after<len(ts):
  601. list_ts.append([ts[indeks_before:indeks_after], dict_onsets_100[id_ts]['stop_incorrect'][1], dict_onsets_100[id_ts]['stop_incorrect'][2]])
  602. dict_ts_s_ic_left_insula[id_ts]=list_ts
  603. # %%
  604. dict_ts_s_ic_left_SPR = {}
  605. for id_ts, ts in dict_interpolated_ts_left_SPR.items():
  606. list_ts = []
  607. if id_ts in list(dict_onsets_100.keys()):
  608. for num,ind_s_i in enumerate(dict_onsets_100[id_ts]['stop_incorrect'][0]):
  609. indeks_before=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])-40)
  610. indeks_after=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])+140)
  611. if indeks_before>0 and indeks_after<len(ts):
  612. list_ts.append([ts[indeks_before:indeks_after], dict_onsets_100[id_ts]['stop_incorrect'][1], dict_onsets_100[id_ts]['stop_incorrect'][2]])
  613. dict_ts_s_ic_left_SPR[id_ts]=list_ts
  614. # %%
  615. dict_ts_s_ic_left_supramarginal = {}
  616. for id_ts, ts in dict_interpolated_ts_left_supramarginal.items():
  617. list_ts = []
  618. if id_ts in list(dict_onsets_100.keys()):
  619. for num,ind_s_i in enumerate(dict_onsets_100[id_ts]['stop_incorrect'][0]):
  620. indeks_before=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])-40)
  621. indeks_after=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])+140)
  622. if indeks_before>0 and indeks_after<len(ts):
  623. list_ts.append([ts[indeks_before:indeks_after], dict_onsets_100[id_ts]['stop_incorrect'][1], dict_onsets_100[id_ts]['stop_incorrect'][2]])
  624. dict_ts_s_ic_left_supramarginal[id_ts]=list_ts
  625. # %%
  626. dict_ts_s_ic_right_insula = {}
  627. for id_ts, ts in dict_interpolated_ts_right_insula.items():
  628. list_ts = []
  629. if id_ts in list(dict_onsets_100.keys()):
  630. for num,ind_s_i in enumerate(dict_onsets_100[id_ts]['stop_incorrect'][0]):
  631. indeks_before=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])-40)
  632. indeks_after=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])+140)
  633. if indeks_before>0 and indeks_after<len(ts):
  634. list_ts.append([ts[indeks_before:indeks_after], dict_onsets_100[id_ts]['stop_incorrect'][1], dict_onsets_100[id_ts]['stop_incorrect'][2]])
  635. dict_ts_s_ic_right_insula[id_ts]=list_ts
  636. # %%
  637. dict_ts_s_ic_right_lingual = {}
  638. for id_ts, ts in dict_interpolated_ts_right_lingual.items():
  639. list_ts = []
  640. if id_ts in list(dict_onsets_100.keys()):
  641. for num,ind_s_i in enumerate(dict_onsets_100[id_ts]['stop_incorrect'][0]):
  642. indeks_before=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])-40)
  643. indeks_after=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])+140)
  644. if indeks_before>0 and indeks_after<len(ts):
  645. list_ts.append([ts[indeks_before:indeks_after], dict_onsets_100[id_ts]['stop_incorrect'][1], dict_onsets_100[id_ts]['stop_incorrect'][2]])
  646. dict_ts_s_ic_right_lingual[id_ts]=list_ts
  647. # %%
  648. dict_ts_s_ic_right_supramarginal = {}
  649. for id_ts, ts in dict_interpolated_ts_right_supramarginal.items():
  650. list_ts = []
  651. if id_ts in list(dict_onsets_100.keys()):
  652. for num,ind_s_i in enumerate(dict_onsets_100[id_ts]['stop_incorrect'][0]):
  653. indeks_before=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])-40)
  654. indeks_after=int(np.round(ind_s_i+dict_onsets_100[id_ts]['stop_incorrect'][1][num])+140)
  655. if indeks_before>0 and indeks_after<len(ts):
  656. list_ts.append([ts[indeks_before:indeks_after], dict_onsets_100[id_ts]['stop_incorrect'][1], dict_onsets_100[id_ts]['stop_incorrect'][2]])
  657. dict_ts_s_ic_right_supramarginal[id_ts]=list_ts
  658. # %%
  659. #creating averaged waves in given ROIs
  660. # %%
  661. x_time = np.arange(-40,140,1)
  662. given_ts_SFG = np.mean([one_ts[0] for id_ts, list_array in dict_ts_s_ic_SFG.items() for one_ts in list_array], axis=0)
  663. std_ts_SFG = np.std([one_ts[0] for id_ts, list_array in dict_ts_s_ic_SFG.items() for one_ts in list_array], axis=0)
  664. down_border_SFG = given_ts_SFG - 1.96*(std_ts_SFG/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_SFG.items() for one_ts in list_array])))
  665. up_border_SFG = given_ts_SFG + 1.96*(std_ts_SFG/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_SFG.items() for one_ts in list_array])))
  666. # %%
  667. x_time = np.arange(-40,140,1)
  668. given_ts_SPR = np.mean([one_ts[0] for id_ts, list_array in dict_ts_s_ic_SFG.items() for one_ts in list_array], axis=0)
  669. std_ts_SFG = np.std([one_ts[0] for id_ts, list_array in dict_ts_s_ic_SFG.items() for one_ts in list_array], axis=0)
  670. down_border_SFG = given_ts_SFG - 1.96*(std_ts_SFG/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_SFG.items() for one_ts in list_array])))
  671. up_border_SFG = given_ts_SFG + 1.96*(std_ts_SFG/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_SFG.items() for one_ts in list_array])))
  672. # %%
  673. x_time = np.arange(-40,140,1)
  674. given_ts_left_SPR = np.mean([one_ts[0] for id_ts, list_array in dict_ts_s_ic_left_SPR.items() for one_ts in list_array], axis=0)
  675. std_ts_left_SPR = np.std([one_ts[0] for id_ts, list_array in dict_ts_s_ic_left_SPR.items() for one_ts in list_array], axis=0)
  676. down_border_left_SPR = given_ts_left_SFG - 1.96*(std_ts_left_SPR/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_left_SPR.items() for one_ts in list_array])))
  677. up_border_left_SPR = given_ts_left_SPR + 1.96*(std_ts_left_SPR/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_left_SPR.items() for one_ts in list_array])))
  678. # %%
  679. x_time = np.arange(-40,140,1)
  680. given_ts_left_supramarginal = np.mean([one_ts[0] for id_ts, list_array in dict_ts_s_ic_left_supramarginal.items() for one_ts in list_array], axis=0)
  681. std_ts_left_supramarginal = np.std([one_ts[0] for id_ts, list_array in dict_ts_s_ic_left_supramarginal.items() for one_ts in list_array], axis=0)
  682. down_border_left_supramarginal = given_ts_left_supramarginal - 1.96*(std_ts_left_supramarginal/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_left_supramarginal.items() for one_ts in list_array])))
  683. up_border_left_supramarginal = given_ts_left_supramarginal + 1.96*(std_ts_left_supramarginal/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_left_supramarginal.items() for one_ts in list_array])))
  684. # %%
  685. x_time = np.arange(-40,140,1)
  686. given_ts_right_insula = np.mean([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_insula.items() for one_ts in list_array], axis=0)
  687. std_ts_right_insula = np.std([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_insula.items() for one_ts in list_array], axis=0)
  688. down_border_right_insula = given_ts_right_insula - 1.96*(std_ts_right_insula/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_insula.items() for one_ts in list_array])))
  689. up_border_right_insula = given_ts_right_insula + 1.96*(std_ts_right_insula/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_insula.items() for one_ts in list_array])))
  690. # %%
  691. x_time = np.arange(-40,140,1)
  692. given_ts_right_lingual = np.mean([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_lingual.items() for one_ts in list_array], axis=0)
  693. std_ts_right_lingual = np.std([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_lingual.items() for one_ts in list_array], axis=0)
  694. down_border_right_lingual = given_ts_right_lingual - 1.96*(std_ts_right_lingual/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_lingual.items() for one_ts in list_array])))
  695. up_border_right_lingual = given_ts_right_lingual + 1.96*(std_ts_right_lingual/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_lingual.items() for one_ts in list_array])))
  696. # %%
  697. x_time = np.arange(-40,140,1)
  698. given_ts_right_lingual = np.mean([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_lingual.items() for one_ts in list_array], axis=0)
  699. std_ts_right_lingual = np.std([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_lingual.items() for one_ts in list_array], axis=0)
  700. down_border_right_lingual = given_ts_right_lingual - 1.96*(std_ts_right_lingual/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_lingual.items() for one_ts in list_array])))
  701. up_border_right_lingual = given_ts_right_lingual + 1.96*(std_ts_right_lingual/np.sqrt(len([one_ts[0] for id_ts, list_array in dict_ts_s_ic_right_lingual.items() for one_ts in list_array])))
  702. # %%
  703. #plotting the average waves for stop incorrect trials in given ROIs
  704. # %%
  705. plt.figure(figsize=(20,10))
  706. plt.rcParams["figure.facecolor"] = "w"
  707. plt.plot(x_time/10, given_ts_SFG, color = 'blue', label='Averaged Signal', linewidth = 2.5)
  708. plt.fill_between(x_time/10, down_border_SFG, up_border_SFG, color ='lightblue', label='95% confidence interval')
  709. plt.xlabel('time around stop signal', fontsize=36)
  710. plt.xticks(fontsize = 36)
  711. plt.ylabel('BOLD units', fontsize=36)
  712. plt.yticks(fontsize = 36)
  713. plt.axvline(x=0, color='red' ,linewidth='4')
  714. plt.legend(fontsize = 36)
  715. # %%
  716. plt.figure(figsize=(20,10))
  717. plt.rcParams["figure.facecolor"] = "w"
  718. plt.plot(x_time/10, given_ts_left_insula, color = 'blue', label='Averaged Signal', linewidth = 2.5)
  719. plt.fill_between(x_time/10, down_border_left_insula, up_border_left_insula, color ='lightblue', label='95% confidence interval')
  720. plt.xlabel('time around stop signal', fontsize=36)
  721. plt.xticks(fontsize = 36)
  722. plt.ylabel('BOLD units', fontsize=36)
  723. plt.yticks(fontsize = 36)
  724. plt.axvline(x=0, color='red' ,linewidth='4')
  725. plt.legend(fontsize = 36)
  726. # %%
  727. plt.figure(figsize=(20,10))
  728. plt.rcParams["figure.facecolor"] = "w"
  729. plt.plot(x_time/10, given_ts_left_SPR, color = 'blue', label='Averaged Signal', linewidth = 2.5)
  730. plt.fill_between(x_time/10, down_border_left_SPR, up_border_left_SPR, color ='lightblue', label='95% confidence interval')
  731. plt.xlabel('time around stop signal', fontsize=36)
  732. plt.xticks(fontsize = 36)
  733. plt.ylabel('BOLD units', fontsize=36)
  734. plt.yticks(fontsize = 36)
  735. plt.axvline(x=0, color='red' ,linewidth='4')
  736. plt.legend(fontsize = 36)
  737. # %%
  738. plt.figure(figsize=(20,10))
  739. plt.rcParams["figure.facecolor"] = "w"
  740. plt.plot(x_time/10, given_ts_left_supramarginal, color = 'blue', label='Averaged Signal', linewidth = 2.5)
  741. plt.fill_between(x_time/10, down_border_left_supramarginal, up_border_left_supramarginal, color ='lightblue', label='95% confidence interval')
  742. plt.xlabel('time around stop signal', fontsize=36)
  743. plt.xticks(fontsize = 36)
  744. plt.ylabel('BOLD units', fontsize=36)
  745. plt.yticks(fontsize = 36)
  746. plt.axvline(x=0, color='red' ,linewidth='4')
  747. plt.legend(fontsize = 36)
  748. # %%
  749. plt.figure(figsize=(20,10))
  750. plt.rcParams["figure.facecolor"] = "w"
  751. plt.plot(x_time/10, given_ts_right_insula, color = 'blue', label='Averaged Signal', linewidth = 2.5)
  752. plt.fill_between(x_time/10, down_border_right_insula, up_border_right_insula, color ='lightblue', label='95% confidence interval')
  753. plt.xlabel('time around stop signal', fontsize=36)
  754. plt.xticks(fontsize = 36)
  755. plt.ylabel('BOLD units', fontsize=36)
  756. plt.yticks(fontsize = 36)
  757. plt.axvline(x=0, color='red' ,linewidth='4')
  758. plt.legend(fontsize = 36)
  759. # %%
  760. plt.figure(figsize=(20,10))
  761. plt.rcParams["figure.facecolor"] = "w"
  762. plt.plot(x_time/10, given_ts_right_insula, color = 'blue', label='Averaged Signal', linewidth = 2.5)
  763. plt.fill_between(x_time/10, down_border_right_insula, up_border_right_insula, color ='lightblue', label='95% confidence interval')
  764. plt.xlabel('time around stop signal', fontsize=36)
  765. plt.xticks(fontsize = 36)
  766. plt.ylabel('BOLD units', fontsize=36)
  767. plt.yticks(fontsize = 36)
  768. plt.axvline(x=0, color='red' ,linewidth='4')
  769. plt.legend(fontsize = 36)
  770. # %%
  771. plt.figure(figsize=(20,10))
  772. plt.rcParams["figure.facecolor"] = "w"
  773. plt.plot(x_time/10, given_ts_right_supramarginal, color = 'blue', label='Averaged Signal', linewidth = 2.5)
  774. plt.fill_between(x_time/10, down_border_right_supramarginal, up_border_right_supramarginal, color ='lightblue', label='95% confidence interval')
  775. plt.xlabel('time around stop signal', fontsize=36)
  776. plt.xticks(fontsize = 36)
  777. plt.ylabel('BOLD units', fontsize=36)
  778. plt.yticks(fontsize = 36)
  779. plt.axvline(x=0, color='red' ,linewidth='4')
  780. plt.legend(fontsize = 36)
  781. # %%
  782. #subtracting the stop correct waves from stop incorrect waves matched with SSD in given rOis
  783. # %%
  784. dict_subtraction_SFG = {}
  785. for id_s_r, dict_values_stop in dict_onsets_100.items():
  786. if id_s_r in dict_interpolated_ts_SFG:
  787. stop_incorrect_ssds=np.unique(dict_values_stop['stop_incorrect'][1])
  788. stop_correct_ssds = np.unique(dict_values_stop['stop_correct'][1])
  789. ssds=[ssd_ic for ssd_ic in stop_incorrect_ssds if ssd_ic in stop_correct_ssds]
  790. dict_waves_ic = {}
  791. dict_waves_c = {}
  792. for num_one, one_ssd in enumerate(ssds):
  793. for num,ssd_ic_pri in enumerate(dict_values_stop['stop_incorrect'][1]):
  794. if one_ssd==ssd_ic_pri:
  795. indeks_before_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)-40)
  796. indeks_after_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)+140)
  797. if indeks_before_ic>0 and indeks_after_ic<len(dict_interpolated_ts_SFG[id_s_r]):
  798. if one_ssd not in dict_waves_ic:
  799. dict_waves_ic[one_ssd]=[(dict_interpolated_ts_SFG[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num])]
  800. else:
  801. dict_waves_ic[one_ssd].append((dict_interpolated_ts_SFG[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num]))
  802. for num2,ssd_c_pri in enumerate(dict_values_stop['stop_correct'][1]):
  803. if one_ssd==ssd_c_pri:
  804. indeks_before_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)-40)
  805. indeks_after_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)+140)
  806. if indeks_after_c<len(dict_interpolated_ts_SFG[id_s_r]) and indeks_before_c>0:
  807. if one_ssd not in dict_waves_c:
  808. dict_waves_c[one_ssd]=[dict_interpolated_ts_SFG[id_s_r][indeks_before_c:indeks_after_c]]
  809. else:
  810. dict_waves_c[one_ssd].append(dict_interpolated_ts_SFG[id_s_r][indeks_before_c:indeks_after_c])
  811. new_dict_waves_c={ssd_s_ic:dict_waves_c[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  812. new_dict_waves_ic={ssd_s_ic:dict_waves_ic[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  813. dict_subtraction_SFG[id_s_r]=[new_dict_waves_ic, new_dict_waves_c]
  814. # %%
  815. dict_subtraction_left_insula = {}
  816. for id_s_r, dict_values_stop in dict_onsets_100.items():
  817. if id_s_r in dict_interpolated_ts_left_insula:
  818. stop_incorrect_ssds=np.unique(dict_values_stop['stop_incorrect'][1])
  819. stop_correct_ssds = np.unique(dict_values_stop['stop_correct'][1])
  820. ssds=[ssd_ic for ssd_ic in stop_incorrect_ssds if ssd_ic in stop_correct_ssds]
  821. dict_waves_ic = {}
  822. dict_waves_c = {}
  823. for num_one, one_ssd in enumerate(ssds):
  824. for num,ssd_ic_pri in enumerate(dict_values_stop['stop_incorrect'][1]):
  825. if one_ssd==ssd_ic_pri:
  826. indeks_before_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)-40)
  827. indeks_after_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)+140)
  828. if indeks_before_ic>0 and indeks_after_ic<len(dict_interpolated_ts_left_insula[id_s_r]):
  829. if one_ssd not in dict_waves_ic:
  830. dict_waves_ic[one_ssd]=[(dict_interpolated_ts_left_insula[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num])]
  831. else:
  832. dict_waves_ic[one_ssd].append((dict_interpolated_ts_left_insula[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num]))
  833. for num2,ssd_c_pri in enumerate(dict_values_stop['stop_correct'][1]):
  834. if one_ssd==ssd_c_pri:
  835. indeks_before_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)-40)
  836. indeks_after_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)+140)
  837. if indeks_after_c<len(dict_interpolated_ts_left_insula[id_s_r]) and indeks_before_c>0:
  838. if one_ssd not in dict_waves_c:
  839. dict_waves_c[one_ssd]=[dict_interpolated_ts_left_insula[id_s_r][indeks_before_c:indeks_after_c]]
  840. else:
  841. dict_waves_c[one_ssd].append(dict_interpolated_ts_left_insula[id_s_r][indeks_before_c:indeks_after_c])
  842. new_dict_waves_c={ssd_s_ic:dict_waves_c[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  843. new_dict_waves_ic={ssd_s_ic:dict_waves_ic[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  844. dict_subtraction_left_insula[id_s_r]=[new_dict_waves_ic, new_dict_waves_c]
  845. # %%
  846. dict_subtraction_left_SFG = {}
  847. for id_s_r, dict_values_stop in dict_onsets_100.items():
  848. if id_s_r in dict_interpolated_ts_left_SFG:
  849. stop_incorrect_ssds=np.unique(dict_values_stop['stop_incorrect'][1])
  850. stop_correct_ssds = np.unique(dict_values_stop['stop_correct'][1])
  851. ssds=[ssd_ic for ssd_ic in stop_incorrect_ssds if ssd_ic in stop_correct_ssds]
  852. dict_waves_ic = {}
  853. dict_waves_c = {}
  854. for num_one, one_ssd in enumerate(ssds):
  855. for num,ssd_ic_pri in enumerate(dict_values_stop['stop_incorrect'][1]):
  856. if one_ssd==ssd_ic_pri:
  857. indeks_before_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)-40)
  858. indeks_after_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)+140)
  859. if indeks_before_ic>0 and indeks_after_ic<len(dict_interpolated_ts_left_SFG[id_s_r]):
  860. if one_ssd not in dict_waves_ic:
  861. dict_waves_ic[one_ssd]=[(dict_interpolated_ts_left_SFG[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num])]
  862. else:
  863. dict_waves_ic[one_ssd].append((dict_interpolated_ts_left_SFG[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num]))
  864. for num2,ssd_c_pri in enumerate(dict_values_stop['stop_correct'][1]):
  865. if one_ssd==ssd_c_pri:
  866. indeks_before_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)-40)
  867. indeks_after_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)+140)
  868. if indeks_after_c<len(dict_interpolated_ts_left_SFG[id_s_r]) and indeks_before_c>0:
  869. if one_ssd not in dict_waves_c:
  870. dict_waves_c[one_ssd]=[dict_interpolated_ts_left_SFG[id_s_r][indeks_before_c:indeks_after_c]]
  871. else:
  872. dict_waves_c[one_ssd].append(dict_interpolated_ts_left_SFG[id_s_r][indeks_before_c:indeks_after_c])
  873. new_dict_waves_c={ssd_s_ic:dict_waves_c[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  874. new_dict_waves_ic={ssd_s_ic:dict_waves_ic[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  875. dict_subtraction_left_SFG[id_s_r]=[new_dict_waves_ic, new_dict_waves_c]
  876. # %%
  877. dict_subtraction_left_SPR = {}
  878. for id_s_r, dict_values_stop in dict_onsets_100.items():
  879. if id_s_r in dict_interpolated_ts_left_SPR:
  880. stop_incorrect_ssds=np.unique(dict_values_stop['stop_incorrect'][1])
  881. stop_correct_ssds = np.unique(dict_values_stop['stop_correct'][1])
  882. ssds=[ssd_ic for ssd_ic in stop_incorrect_ssds if ssd_ic in stop_correct_ssds]
  883. dict_waves_ic = {}
  884. dict_waves_c = {}
  885. for num_one, one_ssd in enumerate(ssds):
  886. for num,ssd_ic_pri in enumerate(dict_values_stop['stop_incorrect'][1]):
  887. if one_ssd==ssd_ic_pri:
  888. indeks_before_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)-40)
  889. indeks_after_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)+140)
  890. if indeks_before_ic>0 and indeks_after_ic<len(dict_interpolated_ts_left_SFG[id_s_r]):
  891. if one_ssd not in dict_waves_ic:
  892. dict_waves_ic[one_ssd]=[(dict_interpolated_ts_left_SPR[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num])]
  893. else:
  894. dict_waves_ic[one_ssd].append((dict_interpolated_ts_left_SPR[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num]))
  895. for num2,ssd_c_pri in enumerate(dict_values_stop['stop_correct'][1]):
  896. if one_ssd==ssd_c_pri:
  897. indeks_before_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)-40)
  898. indeks_after_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)+140)
  899. if indeks_after_c<len(dict_interpolated_ts_left_SFG[id_s_r]) and indeks_before_c>0:
  900. if one_ssd not in dict_waves_c:
  901. dict_waves_c[one_ssd]=[dict_interpolated_ts_left_SPR[id_s_r][indeks_before_c:indeks_after_c]]
  902. else:
  903. dict_waves_c[one_ssd].append(dict_interpolated_ts_left_SPR[id_s_r][indeks_before_c:indeks_after_c])
  904. new_dict_waves_c={ssd_s_ic:dict_waves_c[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  905. new_dict_waves_ic={ssd_s_ic:dict_waves_ic[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  906. dict_subtraction_left_SFG[id_s_r]=[new_dict_waves_ic, new_dict_waves_c]
  907. # %%
  908. dict_subtraction_right_insula = {}
  909. for id_s_r, dict_values_stop in dict_onsets_100.items():
  910. if id_s_r in dict_interpolated_ts_right_insula:
  911. stop_incorrect_ssds=np.unique(dict_values_stop['stop_incorrect'][1])
  912. stop_correct_ssds = np.unique(dict_values_stop['stop_correct'][1])
  913. ssds=[ssd_ic for ssd_ic in stop_incorrect_ssds if ssd_ic in stop_correct_ssds]
  914. dict_waves_ic = {}
  915. dict_waves_c = {}
  916. for num_one, one_ssd in enumerate(ssds):
  917. for num,ssd_ic_pri in enumerate(dict_values_stop['stop_incorrect'][1]):
  918. if one_ssd==ssd_ic_pri:
  919. indeks_before_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)-40)
  920. indeks_after_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)+140)
  921. if indeks_before_ic>0 and indeks_after_ic<len(dict_interpolated_ts_right_insula[id_s_r]):
  922. if one_ssd not in dict_waves_ic:
  923. dict_waves_ic[one_ssd]=[(dict_interpolated_ts_right_insula[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num])]
  924. else:
  925. dict_waves_ic[one_ssd].append((dict_interpolated_ts_right_insula[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num]))
  926. for num2,ssd_c_pri in enumerate(dict_values_stop['stop_correct'][1]):
  927. if one_ssd==ssd_c_pri:
  928. indeks_before_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)-40)
  929. indeks_after_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)+140)
  930. if indeks_after_c<len(dict_interpolated_ts_right_insula[id_s_r]) and indeks_before_c>0:
  931. if one_ssd not in dict_waves_c:
  932. dict_waves_c[one_ssd]=[dict_interpolated_ts_right_insula[id_s_r][indeks_before_c:indeks_after_c]]
  933. else:
  934. dict_waves_c[one_ssd].append(dict_interpolated_ts_right_insula[id_s_r][indeks_before_c:indeks_after_c])
  935. new_dict_waves_c={ssd_s_ic:dict_waves_c[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  936. new_dict_waves_ic={ssd_s_ic:dict_waves_ic[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  937. dict_subtraction_right_insula[id_s_r]=[new_dict_waves_ic, new_dict_waves_c]
  938. # %%
  939. dict_subtraction_right_lingual = {}
  940. for id_s_r, dict_values_stop in dict_onsets_100.items():
  941. if id_s_r in dict_interpolated_ts_right_lingual:
  942. stop_incorrect_ssds=np.unique(dict_values_stop['stop_incorrect'][1])
  943. stop_correct_ssds = np.unique(dict_values_stop['stop_correct'][1])
  944. ssds=[ssd_ic for ssd_ic in stop_incorrect_ssds if ssd_ic in stop_correct_ssds]
  945. dict_waves_ic = {}
  946. dict_waves_c = {}
  947. for num_one, one_ssd in enumerate(ssds):
  948. for num,ssd_ic_pri in enumerate(dict_values_stop['stop_incorrect'][1]):
  949. if one_ssd==ssd_ic_pri:
  950. indeks_before_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)-40)
  951. indeks_after_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)+140)
  952. if indeks_before_ic>0 and indeks_after_ic<len(dict_interpolated_ts_right_lingual[id_s_r]):
  953. if one_ssd not in dict_waves_ic:
  954. dict_waves_ic[one_ssd]=[(dict_interpolated_ts_right_lingual[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num])]
  955. else:
  956. dict_waves_ic[one_ssd].append((dict_interpolated_ts_right_lingual[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num]))
  957. for num2,ssd_c_pri in enumerate(dict_values_stop['stop_correct'][1]):
  958. if one_ssd==ssd_c_pri:
  959. indeks_before_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)-40)
  960. indeks_after_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)+140)
  961. if indeks_after_c<len(dict_interpolated_ts_right_lingual[id_s_r]) and indeks_before_c>0:
  962. if one_ssd not in dict_waves_c:
  963. dict_waves_c[one_ssd]=[dict_interpolated_ts_right_lingual[id_s_r][indeks_before_c:indeks_after_c]]
  964. else:
  965. dict_waves_c[one_ssd].append(dict_interpolated_ts_right_lingual[id_s_r][indeks_before_c:indeks_after_c])
  966. new_dict_waves_c={ssd_s_ic:dict_waves_c[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  967. new_dict_waves_ic={ssd_s_ic:dict_waves_ic[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  968. dict_subtraction_right_lingual[id_s_r]=[new_dict_waves_ic, new_dict_waves_c]
  969. # %%
  970. dict_subtraction_right_supramarginal = {}
  971. for id_s_r, dict_values_stop in dict_onsets_100.items():
  972. if id_s_r in dict_interpolated_ts_right_supramarginal:
  973. stop_incorrect_ssds=np.unique(dict_values_stop['stop_incorrect'][1])
  974. stop_correct_ssds = np.unique(dict_values_stop['stop_correct'][1])
  975. ssds=[ssd_ic for ssd_ic in stop_incorrect_ssds if ssd_ic in stop_correct_ssds]
  976. dict_waves_ic = {}
  977. dict_waves_c = {}
  978. for num_one, one_ssd in enumerate(ssds):
  979. for num,ssd_ic_pri in enumerate(dict_values_stop['stop_incorrect'][1]):
  980. if one_ssd==ssd_ic_pri:
  981. indeks_before_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)-40)
  982. indeks_after_ic=int(np.round(dict_values_stop['stop_incorrect'][0][num]+one_ssd)+140)
  983. if indeks_before_ic>0 and indeks_after_ic<len(dict_interpolated_ts_right_supramarginal[id_s_r]):
  984. if one_ssd not in dict_waves_ic:
  985. dict_waves_ic[one_ssd]=[(dict_interpolated_ts_right_supramarginal[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num])]
  986. else:
  987. dict_waves_ic[one_ssd].append((dict_interpolated_ts_right_supramarginal[id_s_r][indeks_before_ic:indeks_after_ic],dict_values_stop['stop_incorrect'][2][num]))
  988. for num2,ssd_c_pri in enumerate(dict_values_stop['stop_correct'][1]):
  989. if one_ssd==ssd_c_pri:
  990. indeks_before_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)-40)
  991. indeks_after_c=int(np.round(dict_values_stop['stop_correct'][0][num2]+one_ssd)+140)
  992. if indeks_after_c<len(dict_interpolated_ts_right_supramarginal[id_s_r]) and indeks_before_c>0:
  993. if one_ssd not in dict_waves_c:
  994. dict_waves_c[one_ssd]=[dict_interpolated_ts_right_supramarginal[id_s_r][indeks_before_c:indeks_after_c]]
  995. else:
  996. dict_waves_c[one_ssd].append(dict_interpolated_ts_right_supramarginal[id_s_r][indeks_before_c:indeks_after_c])
  997. new_dict_waves_c={ssd_s_ic:dict_waves_c[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  998. new_dict_waves_ic={ssd_s_ic:dict_waves_ic[ssd_s_ic] for ssd_s_ic in dict_waves_ic if ssd_s_ic in dict_waves_c}
  999. dict_subtraction_right_supramarginal[id_s_r]=[new_dict_waves_ic, new_dict_waves_c]
  1000. # %%
  1001. #averaging subtraction waves in given ROis
  1002. # %%
  1003. dict_subtraction_mean_SFG = {id_s_r:[list_dicts_stops[0],{ssd:np.mean(list_ts,axis=0) for ssd, list_ts in list_dicts_stops[1].items()}] for id_s_r, list_dicts_stops in dict_subtraction_SFG.items()}
  1004. # %%
  1005. dict_subtraction_mean_left_insula = {id_s_r:[list_dicts_stops[0],{ssd:np.mean(list_ts,axis=0) for ssd, list_ts in list_dicts_stops[1].items()}] for id_s_r, list_dicts_stops in dict_subtraction_left_insula.items()}
  1006. # %%
  1007. dict_subtraction_mean_left_SPR = {id_s_r:[list_dicts_stops[0],{ssd:np.mean(list_ts,axis=0) for ssd, list_ts in list_dicts_stops[1].items()}] for id_s_r, list_dicts_stops in dict_subtraction_left_SPR.items()}
  1008. # %%
  1009. dict_subtraction_mean_left_supramarginal = {id_s_r:[list_dicts_stops[0],{ssd:np.mean(list_ts,axis=0) for ssd, list_ts in list_dicts_stops[1].items()}] for id_s_r, list_dicts_stops in dict_subtraction_left_supramarginal.items()}
  1010. # %%
  1011. dict_subtraction_mean_right_insula = {id_s_r:[list_dicts_stops[0],{ssd:np.mean(list_ts,axis=0) for ssd, list_ts in list_dicts_stops[1].items()}] for id_s_r, list_dicts_stops in dict_subtraction_right_insula.items()}
  1012. # %%
  1013. dict_subtraction_mean_right_lingual = {id_s_r:[list_dicts_stops[0],{ssd:np.mean(list_ts,axis=0) for ssd, list_ts in list_dicts_stops[1].items()}] for id_s_r, list_dicts_stops in dict_subtraction_right_lingual.items()}
  1014. # %%
  1015. dict_subtraction_mean_right_supramarginal = {id_s_r:[list_dicts_stops[0],{ssd:np.mean(list_ts,axis=0) for ssd, list_ts in list_dicts_stops[1].items()}] for id_s_r, list_dicts_stops in dict_subtraction_right_supramarginal.items()}
  1016. # %%
  1017. # preapring subtraction waves for visualization
  1018. # %%
  1019. dict_subtraction_wave_SFG = {id_s_r:{ssd_s_ic:[(one_ts[0] - list_dics_stop[1][ssd_s_ic],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_SFG.items()}
  1020. dict_subtraction_wave2_SFG = {id_s_r:{ssd_s_ic:[([one_ts[0],list_dics_stop[1][ssd_s_ic]],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_SFG.items()}
  1021. list_subtraction_all_waves_SFG = [one_ts[0] for id_s_r, dict_ssd in dict_subtraction_wave_SFG.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1022. list_subtraction_all_waves2_SFG = [[one_ts[0][0],one_ts[0][1]] for id_s_r, dict_ssd in dict_subtraction_wave2_SFG.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1023. # %%
  1024. dict_subtraction_wave_left_insula = {id_s_r:{ssd_s_ic:[(one_ts[0] - list_dics_stop[1][ssd_s_ic],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_left_insula.items()}
  1025. dict_subtraction_wave2_left_insula = {id_s_r:{ssd_s_ic:[([one_ts[0],list_dics_stop[1][ssd_s_ic]],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_left_insula.items()}
  1026. list_subtraction_all_waves_left_insula = [one_ts[0] for id_s_r, dict_ssd in dict_subtraction_wave_left_insula.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1027. list_subtraction_all_waves2_left_insula = [[one_ts[0][0],one_ts[0][1]] for id_s_r, dict_ssd in dict_subtraction_wave2_left_insula.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1028. # %%
  1029. dict_subtraction_wave_left_SPR = {id_s_r:{ssd_s_ic:[(one_ts[0] - list_dics_stop[1][ssd_s_ic],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_left_SPR.items()}
  1030. dict_subtraction_wave2_left_SPR = {id_s_r:{ssd_s_ic:[([one_ts[0],list_dics_stop[1][ssd_s_ic]],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_left_SPR.items()}
  1031. list_subtraction_all_waves_left_SPR = [one_ts[0] for id_s_r, dict_ssd in dict_subtraction_wave_left_SPR.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1032. list_subtraction_all_waves2_left_SPR = [[one_ts[0][0],one_ts[0][1]] for id_s_r, dict_ssd in dict_subtraction_wave2_left_SPR.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1033. # %%
  1034. dict_subtraction_wave_left_supramarginal = {id_s_r:{ssd_s_ic:[(one_ts[0] - list_dics_stop[1][ssd_s_ic],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_left_supramarginal.items()}
  1035. dict_subtraction_wave2_left_supramarginal = {id_s_r:{ssd_s_ic:[([one_ts[0],list_dics_stop[1][ssd_s_ic]],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_left_supramarginal.items()}
  1036. list_subtraction_all_waves_left_supramarginal = [one_ts[0] for id_s_r, dict_ssd in dict_subtraction_wave_left_supramarginal.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1037. list_subtraction_all_waves2_left_supramarginal = [[one_ts[0][0],one_ts[0][1]] for id_s_r, dict_ssd in dict_subtraction_wave2_left_supramarginal.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1038. # %%
  1039. dict_subtraction_wave_right_insula = {id_s_r:{ssd_s_ic:[(one_ts[0] - list_dics_stop[1][ssd_s_ic],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_right_insula.items()}
  1040. dict_subtraction_wave2_right_insula = {id_s_r:{ssd_s_ic:[([one_ts[0],list_dics_stop[1][ssd_s_ic]],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_right_insula.items()}
  1041. list_subtraction_all_waves_right_insula = [one_ts[0] for id_s_r, dict_ssd in dict_subtraction_wave_right_insula.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1042. list_subtraction_all_waves2_right_insula = [[one_ts[0][0],one_ts[0][1]] for id_s_r, dict_ssd in dict_subtraction_wave2_right_insula.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1043. # %%
  1044. dict_subtraction_wave_right_lingual = {id_s_r:{ssd_s_ic:[(one_ts[0] - list_dics_stop[1][ssd_s_ic],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_right_lingual.items()}
  1045. dict_subtraction_wave2_right_lingual = {id_s_r:{ssd_s_ic:[([one_ts[0],list_dics_stop[1][ssd_s_ic]],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_right_lingual.items()}
  1046. list_subtraction_all_waves_right_lingual = [one_ts[0] for id_s_r, dict_ssd in dict_subtraction_wave_right_lingual.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1047. list_subtraction_all_waves2_right_lingual = [[one_ts[0][0],one_ts[0][1]] for id_s_r, dict_ssd in dict_subtraction_wave2_right_lingual.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1048. # %%
  1049. dict_subtraction_wave_right_supramarginal = {id_s_r:{ssd_s_ic:[(one_ts[0] - list_dics_stop[1][ssd_s_ic],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_right_supramarginal.items()}
  1050. dict_subtraction_wave2_right_supramarginal = {id_s_r:{ssd_s_ic:[([one_ts[0],list_dics_stop[1][ssd_s_ic]],one_ts[1]) for one_ts in list_ts] for (ssd_s_ic, list_ts) in list_dics_stop[0].items()} for id_s_r, list_dics_stop in dict_subtraction_mean_right_supramarginal.items()}
  1051. list_subtraction_all_waves_right_supramarginal = [one_ts[0] for id_s_r, dict_ssd in dict_subtraction_wave_right_supramarginal.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1052. list_subtraction_all_waves2_right_supramarginal = [[one_ts[0][0],one_ts[0][1]] for id_s_r, dict_ssd in dict_subtraction_wave2_right_supramarginal.items() for ssd, list_ts in dict_ssd.items() for one_ts in list_ts]
  1053. # %%
  1054. #additional measurments of subtraction waves
  1055. # %%
  1056. mean_ts_SFG = np.mean(list_subtraction_all_waves_SFG,axis=0)
  1057. std_ts_SFG = np.std(list_subtraction_all_waves_SFG,axis=0)
  1058. down_ts_SFG = mean_ts_SFG - 1.96*(std_ts_SFG/np.sqrt(len(list_subtraction_all_waves_SFG)))
  1059. up_ts_SFG = mean_ts_SFG + 1.96*(std_ts_SFG/np.sqrt(len(list_subtraction_all_waves_SFG)))
  1060. # %%
  1061. mean_ts_left_insula = np.mean(list_subtraction_all_waves_left_insula,axis=0)
  1062. std_ts_left_insula = np.std(list_subtraction_all_waves_left_insula,axis=0)
  1063. down_ts_left_insula = mean_ts_left_insula - 1.96*(std_ts_left_insula/np.sqrt(len(list_subtraction_all_waves_left_insula)))
  1064. up_ts_left_insula = mean_ts_left_insula + 1.96*(std_ts_left_insula/np.sqrt(len(list_subtraction_all_waves_left_insula)))
  1065. # %%
  1066. mean_ts_left_SPR = np.mean(list_subtraction_all_waves_left_SPR,axis=0)
  1067. std_ts_left_SPR = np.std(list_subtraction_all_waves_left_SPR,axis=0)
  1068. down_ts_left_SPR = mean_ts_left_SPR - 1.96*(std_ts_left_SPR/np.sqrt(len(list_subtraction_all_waves_left_SPR)))
  1069. up_ts_left_SPR = mean_ts_left_SPr + 1.96*(std_ts_left_SPR/np.sqrt(len(list_subtraction_all_waves_left_SPR)))
  1070. # %%
  1071. mean_ts_left_supramarginal = np.mean(list_subtraction_all_waves_left_supramarginal,axis=0)
  1072. std_ts_left_supramarginal = np.std(list_subtraction_all_waves_left_supramarginal,axis=0)
  1073. down_ts_left_supramarginal = mean_ts_left_supramarginal - 1.96*(std_ts_left_supramarginal/np.sqrt(len(list_subtraction_all_waves_left_supramarginal)))
  1074. up_ts_left_supramarginal = mean_ts_left_supramarginal + 1.96*(std_ts_left_supramarginal/np.sqrt(len(list_subtraction_all_waves_left_supramarginal)))
  1075. # %%
  1076. mean_ts_right_insula = np.mean(list_subtraction_all_waves_right_insula,axis=0)
  1077. std_ts_right_insula = np.std(list_subtraction_all_waves_right_insula,axis=0)
  1078. down_ts_right_insula = mean_ts_right_insula - 1.96*(std_ts_right_insula/np.sqrt(len(list_subtraction_all_waves_right_insula)))
  1079. up_ts_right_insula = mean_ts_right_insula + 1.96*(std_ts_right_insula/np.sqrt(len(list_subtraction_all_waves_right_insula)))
  1080. # %%
  1081. mean_ts_right_lingual = np.mean(list_subtraction_all_waves_right_lingual,axis=0)
  1082. std_ts_right_lingual = np.std(list_subtraction_all_waves_right_lingual,axis=0)
  1083. down_ts_right_lingual = mean_ts_right_lingual - 1.96*(std_ts_right_lingual/np.sqrt(len(list_subtraction_all_waves_right_lingual)))
  1084. up_ts_right_lingual = mean_ts_right_lingual + 1.96*(std_ts_right_lingual/np.sqrt(len(list_subtraction_all_waves_right_lingual)))
  1085. # %%
  1086. mean_ts_right_supramarginal = np.mean(list_subtraction_all_waves_right_supramarginal,axis=0)
  1087. std_ts_right_supramarginal = np.std(list_subtraction_all_waves_right_supramarginal,axis=0)
  1088. down_ts_right_supramarginal = mean_ts_right_supramarginal - 1.96*(std_ts_right_supramarginal/np.sqrt(len(list_subtraction_all_waves_right_supramarginal)))
  1089. up_ts_right_supramarginal = mean_ts_right_supramarginal + 1.96*(std_ts_right_supramarginal/np.sqrt(len(list_subtraction_all_waves_right_supramarginal)))
  1090. # %%
  1091. #stop incorrect and correct waves
  1092. # %%
  1093. mean_ts_sic_SFG = np.mean(np.array(list_subtraction_all_waves2_SFG)[:,0,:], axis=0)
  1094. std_ts_sic_SFG = np.std(np.array(list_subtraction_all_waves2_SFG)[:,0,:], axis=0)
  1095. down_ts_sic_SFG = mean_ts_sic_SFG - 1.96*(std_ts_sic_SFG/np.sqrt(len(list_subtraction_all_waves2_SFG)))
  1096. up_ts_sic_SFG = mean_ts_sic_SFG + 1.96*(std_ts_sic_SFG/np.sqrt(len(list_subtraction_all_waves2_SFG)))
  1097. mean_ts_sc_SFG = np.mean(np.array(list_subtraction_all_waves2_SFG)[:,1,:], axis=0)
  1098. std_ts_sc_SFG = np.std(np.array(list_subtraction_all_waves2_SFG)[:,1,:], axis=0)
  1099. down_ts_sc_SFG = mean_ts_sc_SFG - 1.96*(std_ts_sc_SFG/np.sqrt(len(list_subtraction_all_waves2_SFG)))
  1100. up_ts_sc_SFG = mean_ts_sc_SFG + 1.96*(std_ts_sc_SFG/np.sqrt(len(list_subtraction_all_waves2_SFG)))
  1101. # %%
  1102. mean_ts_sic_left_insula = np.mean(np.array(list_subtraction_all_waves2_left_insula)[:,0,:], axis=0)
  1103. std_ts_sic_left_insula = np.std(np.array(list_subtraction_all_waves2_left_insula)[:,0,:], axis=0)
  1104. down_ts_sic_left_insula = mean_ts_sic_left_insula - 1.96*(std_ts_sic_left_insula/np.sqrt(len(list_subtraction_all_waves2_left_insula)))
  1105. up_ts_sic_left_insula = mean_ts_sic_left_insula + 1.96*(std_ts_sic_left_insula/np.sqrt(len(list_subtraction_all_waves2_left_insula)))
  1106. mean_ts_sc_left_insula = np.mean(np.array(list_subtraction_all_waves2_left_insula)[:,1,:], axis=0)
  1107. std_ts_sc_left_insula = np.std(np.array(list_subtraction_all_waves2_left_insula)[:,1,:], axis=0)
  1108. down_ts_sc_left_insula = mean_ts_sc_left_insula - 1.96*(std_ts_sc_left_insula/np.sqrt(len(list_subtraction_all_waves2_left_insula)))
  1109. up_ts_sc_left_insula = mean_ts_sc_left_insula + 1.96*(std_ts_sc_left_insula/np.sqrt(len(list_subtraction_all_waves2_left_insula)))
  1110. # %%
  1111. mean_ts_sic_left_SPR = np.mean(np.array(list_subtraction_all_waves2_left_SPR)[:,0,:], axis=0)
  1112. std_ts_sic_left_SPR = np.std(np.array(list_subtraction_all_waves2_left_SPR)[:,0,:], axis=0)
  1113. down_ts_sic_left_SPR = mean_ts_sic_left_SPR - 1.96*(std_ts_sic_left_SPR/np.sqrt(len(list_subtraction_all_waves2_left_SPR)))
  1114. up_ts_sic_left_SPR = mean_ts_sic_left_SPR + 1.96*(std_ts_sic_left_SPR/np.sqrt(len(list_subtraction_all_waves2_left_SPR)))
  1115. mean_ts_sc_left_SPR = np.mean(np.array(list_subtraction_all_waves2_left_SPR)[:,1,:], axis=0)
  1116. std_ts_sc_left_SPR = np.std(np.array(list_subtraction_all_waves2_left_SPr)[:,1,:], axis=0)
  1117. down_ts_sc_left_SPR = mean_ts_sc_left_SPR - 1.96*(std_ts_sc_left_SPR/np.sqrt(len(list_subtraction_all_waves2_left_SPR)))
  1118. up_ts_sc_left_SPR = mean_ts_sc_left_SPr + 1.96*(std_ts_sc_left_SPR/np.sqrt(len(list_subtraction_all_waves2_left_SPR)))
  1119. # %%
  1120. mean_ts_sic_left_supramarginal = np.mean(np.array(list_subtraction_all_waves2_left_supramarginal)[:,0,:], axis=0)
  1121. std_ts_sic_left_supramarginal = np.std(np.array(list_subtraction_all_waves2_left_supramarginal)[:,0,:], axis=0)
  1122. down_ts_sic_left_supramarginal = mean_ts_sic_left_supramarginal - 1.96*(std_ts_sic_left_supramarginal/np.sqrt(len(list_subtraction_all_waves2_left_supramarginal)))
  1123. up_ts_sic_left_supramarginal = mean_ts_sic_left_supramarginal + 1.96*(std_ts_sic_left_supramarginal/np.sqrt(len(list_subtraction_all_waves2_left_supramarginal)))
  1124. mean_ts_sc_left_supramarginal = np.mean(np.array(list_subtraction_all_waves2_left_supramarginal)[:,1,:], axis=0)
  1125. std_ts_sc_left_supramarginal = np.std(np.array(list_subtraction_all_waves2_left_supramarginal)[:,1,:], axis=0)
  1126. down_ts_sc_left_supramarginal = mean_ts_sc_left_supramarginal - 1.96*(std_ts_sc_left_supramarginal/np.sqrt(len(list_subtraction_all_waves2_left_supramarginal)))
  1127. up_ts_sc_left_supramarginal = mean_ts_sc_left_supramarginal + 1.96*(std_ts_sc_left_supramarginal/np.sqrt(len(list_subtraction_all_waves2_left_supramarginal)))
  1128. # %%
  1129. mean_ts_sic_right_insula = np.mean(np.array(list_subtraction_all_waves2_right_insula)[:,0,:], axis=0)
  1130. std_ts_sic_right_insula = np.std(np.array(list_subtraction_all_waves2_right_insula)[:,0,:], axis=0)
  1131. down_ts_sic_right_insula = mean_ts_sic_right_insula - 1.96*(std_ts_sic_right_insula/np.sqrt(len(list_subtraction_all_waves2_right_insula)))
  1132. up_ts_sic_right_insula = mean_ts_sic_right_insula + 1.96*(std_ts_sic_right_insula/np.sqrt(len(list_subtraction_all_waves2_right_insula)))
  1133. mean_ts_sc_right_insula = np.mean(np.array(list_subtraction_all_waves2_right_insula)[:,1,:], axis=0)
  1134. std_ts_sc_right_insula = np.std(np.array(list_subtraction_all_waves2_right_insula)[:,1,:], axis=0)
  1135. down_ts_sc_right_insula = mean_ts_sc_right_insula - 1.96*(std_ts_sc_right_insula/np.sqrt(len(list_subtraction_all_waves2_right_insula)))
  1136. up_ts_sc_right_insula = mean_ts_sc_right_insula + 1.96*(std_ts_sc_right_insula/np.sqrt(len(list_subtraction_all_waves2_right_insula)))
  1137. # %%
  1138. mean_ts_sic_right_lingual = np.mean(np.array(list_subtraction_all_waves2_right_lingual)[:,0,:], axis=0)
  1139. std_ts_sic_right_lingual = np.std(np.array(list_subtraction_all_waves2_right_lingual)[:,0,:], axis=0)
  1140. down_ts_sic_right_lingual = mean_ts_sic_right_lingual - 1.96*(std_ts_sic_right_lingual/np.sqrt(len(list_subtraction_all_waves2_right_lingual)))
  1141. up_ts_sic_right_lingual = mean_ts_sic_right_lingual + 1.96*(std_ts_sic_right_lingual/np.sqrt(len(list_subtraction_all_waves2_right_lingual)))
  1142. mean_ts_sc_right_lingual = np.mean(np.array(list_subtraction_all_waves2_right_lingual)[:,1,:], axis=0)
  1143. std_ts_sc_right_lingual = np.std(np.array(list_subtraction_all_waves2_right_lingual)[:,1,:], axis=0)
  1144. down_ts_sc_right_lingual = mean_ts_sc_right_lingual - 1.96*(std_ts_sc_right_lingual/np.sqrt(len(list_subtraction_all_waves2_right_lingual)))
  1145. up_ts_sc_right_lingual = mean_ts_sc_right_lingual + 1.96*(std_ts_sc_right_lingual/np.sqrt(len(list_subtraction_all_waves2_right_lingual)))
  1146. # %%
  1147. mean_ts_sic_right_supramarginal = np.mean(np.array(list_subtraction_all_waves2_right_supramarginal)[:,0,:], axis=0)
  1148. std_ts_sic_right_supramarginal = np.std(np.array(list_subtraction_all_waves2_right_supramarginal)[:,0,:], axis=0)
  1149. down_ts_sic_right_supramarginal = mean_ts_sic_right_supramarginal - 1.96*(std_ts_sic_right_supramarginal/np.sqrt(len(list_subtraction_all_waves2_right_supramarginal)))
  1150. up_ts_sic_right_supramarginal = mean_ts_sic_right_supramarginal + 1.96*(std_ts_sic_right_supramarginal/np.sqrt(len(list_subtraction_all_waves2_right_supramarginal)))
  1151. mean_ts_sc_right_supramarginal = np.mean(np.array(list_subtraction_all_waves2_right_supramarginal)[:,1,:], axis=0)
  1152. std_ts_sc_right_supramarginal = np.std(np.array(list_subtraction_all_waves2_right_supramarginal)[:,1,:], axis=0)
  1153. down_ts_sc_right_supramarginal = mean_ts_sc_right_supramarginal - 1.96*(std_ts_sc_right_supramarginal/np.sqrt(len(list_subtraction_all_waves2_right_supramarginal)))
  1154. up_ts_sc_right_supramarginal = mean_ts_sc_right_supramarginal + 1.96*(std_ts_sc_right_supramarginal/np.sqrt(len(list_subtraction_all_waves2_right_supramarginal)))
  1155. # %%
  1156. #plotting difference wave
  1157. # %%
  1158. plt.figure(figsize=(20,10), facecolor = 'white')
  1159. plt.plot(x_time/10, mean_ts_SFG, color = 'green', label='Mean difference', linewidth = 2.5)
  1160. plt.fill_between(x_time/10, down_ts_SFG, up_ts_SFG, color ='lightgreen', label='95% confidence interval')
  1161. plt.xlabel('time around stop signal', fontsize=36)
  1162. plt.xticks(fontsize = 36)
  1163. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1164. plt.yticks(fontsize = 36)
  1165. plt.axvline(x=0, color='red' ,linewidth='4')
  1166. plt.axvspan(5, 7, alpha=0.1, color='blue', label = 'target activity')
  1167. plt.legend(fontsize = 36)
  1168. # %%
  1169. plt.figure(figsize=(20,10))
  1170. plt.plot(x_time/10, mean_ts_left_insula, color = 'green', label='Mean difference', linewidth = 2.5)
  1171. plt.fill_between(x_time/10, down_ts_left_insula, up_ts_left_insula, color ='lightgreen', label='95% confidence interval')
  1172. plt.xlabel('time around stop signal', fontsize=36)
  1173. plt.xticks(fontsize = 36)
  1174. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1175. plt.yticks(fontsize = 36)
  1176. plt.axvline(x=0, color='red' ,linewidth='4')
  1177. plt.axvspan(5, 7, alpha=0.1, color='blue', label = 'target activity')
  1178. plt.legend(fontsize = 36)
  1179. # %%
  1180. plt.figure(figsize=(20,10))
  1181. plt.plot(x_time/10, mean_ts_left_SPR, color = 'green', label='Mean difference', linewidth = 2.5)
  1182. plt.fill_between(x_time/10, down_ts_left_SPR, up_ts_left_SPR, color ='lightgreen', label='95% confidence interval')
  1183. plt.xlabel('time around stop signal', fontsize=36)
  1184. plt.xticks(fontsize = 36)
  1185. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1186. plt.yticks(fontsize = 36)
  1187. plt.axvline(x=0, color='red' ,linewidth='4')
  1188. plt.axvspan(5, 7, alpha=0.1, color='blue', label = 'target activity')
  1189. plt.legend(fontsize = 36)
  1190. # %%
  1191. plt.figure(figsize=(20,10))
  1192. plt.plot(x_time/10, mean_ts_left_supramarginal, color = 'green', label='Mean difference', linewidth = 2.5)
  1193. plt.fill_between(x_time/10, down_ts_left_supramarginal, up_ts_left_supramarginal, color ='lightgreen', label='95% confidence interval')
  1194. plt.xlabel('time around stop signal', fontsize=36)
  1195. plt.xticks(fontsize = 36)
  1196. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1197. plt.yticks(fontsize = 36)
  1198. plt.axvline(x=0, color='red' ,linewidth='4')
  1199. plt.axvspan(5, 7, alpha=0.1, color='blue', label = 'target activity')
  1200. plt.legend(fontsize = 36)
  1201. # %%
  1202. plt.figure(figsize=(20,10))
  1203. plt.plot(x_time/10, mean_ts_right_insula, color = 'green', label='Mean difference', linewidth = 2.5)
  1204. plt.fill_between(x_time/10, down_ts_right_insula, up_ts_right_insula, color ='lightgreen', label='95% confidence interval')
  1205. plt.xlabel('time around stop signal', fontsize=36)
  1206. plt.xticks(fontsize = 36)
  1207. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1208. plt.yticks(fontsize = 36)
  1209. plt.axvline(x=0, color='red' ,linewidth='4')
  1210. plt.axvspan(5, 7, alpha=0.1, color='blue', label = 'target activity')
  1211. plt.legend(fontsize = 36)
  1212. # %%
  1213. plt.figure(figsize=(20,10))
  1214. plt.plot(x_time/10, mean_ts_right_insula, color = 'green', label='Mean difference', linewidth = 2.5)
  1215. plt.fill_between(x_time/10, down_ts_right_insula, up_ts_right_insula, color ='lightgreen', label='95% confidence interval')
  1216. plt.xlabel('time around stop signal', fontsize=36)
  1217. plt.xticks(fontsize = 36)
  1218. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1219. plt.yticks(fontsize = 36)
  1220. plt.axvline(x=0, color='red' ,linewidth='4')
  1221. plt.axvspan(5, 7, alpha=0.1, color='blue', label = 'target activity')
  1222. plt.legend(fontsize = 36)
  1223. # %%
  1224. plt.figure(figsize=(20,10))
  1225. plt.plot(x_time/10, mean_ts_right_supramarginal, color = 'green', label='Mean difference', linewidth = 2.5)
  1226. plt.fill_between(x_time/10, down_ts_right_supramarginal, up_ts_right_supramarginal, color ='lightgreen', label='95% confidence interval')
  1227. plt.xlabel('time around stop signal', fontsize=36)
  1228. plt.xticks(fontsize = 36)
  1229. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1230. plt.yticks(fontsize = 36)
  1231. plt.axvline(x=0, color='red' ,linewidth='4')
  1232. plt.axvspan(5, 7, alpha=0.1, color='blue', label = 'target activity')
  1233. plt.legend(fontsize = 36)
  1234. # %%
  1235. #plotting stop correct and stop incorrect waves
  1236. # %%
  1237. plt.figure(figsize=(20,10), facecolor='white')
  1238. plt.plot(x_time/10, mean_ts_sic_SFG, color = 'blue', label ='averaged time series of stop incorrect', linewidth = 2.5)
  1239. plt.fill_between(x_time/10, down_ts_sic_SFG, up_ts_sic_SFG, color='lightblue', label = '95% confidence interval of stop incorrect trials')
  1240. plt.plot(x_time/10, mean_ts_sc_SFG, color = '#DD4800', label = ' averaged time series of stop correct', linewidth = 2.5)
  1241. plt.fill_between(x_time/10, down_ts_sc_SFG, up_ts_sc_SFG, color=(1.0, 0.5, 0.0, 0.5), label = '95% confidence interval of stop correct trials')
  1242. plt.xlabel('time around stop signal', fontsize=36)
  1243. plt.xticks(fontsize = 36)
  1244. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1245. plt.yticks(fontsize = 36)
  1246. plt.axvline(x=0, color='red' ,linewidth='4')
  1247. plt.legend(fontsize = 24)
  1248. plt.rcParams["figure.facecolor"] = "w"
  1249. # %%
  1250. plt.figure(figsize=(20,10))
  1251. plt.plot(x_time/10, mean_ts_sic_left_insula, color = 'blue', label ='averaged time series of stop incorrect', linewidth = 2.5)
  1252. plt.fill_between(x_time/10, down_ts_sic_left_insula, up_ts_sic_left_insula, color='lightblue', label = '95% confidence interval of stop incorrect trials')
  1253. plt.plot(x_time/10, mean_ts_sc_left_insula, color = '#DD4800', label = ' averaged time series of stop correct', linewidth = 2.5)
  1254. plt.fill_between(x_time/10, down_ts_sc_left_insula, up_ts_sc_left_insula, color=(1.0, 0.5, 0.0, 0.5), label = '95% confidence interval of stop correct trials')
  1255. plt.xlabel('time around stop signal', fontsize=36)
  1256. plt.xticks(fontsize = 36)
  1257. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1258. plt.yticks(fontsize = 36)
  1259. plt.axvline(x=0, color='red' ,linewidth='4')
  1260. plt.legend(fontsize = 24)
  1261. # %%
  1262. plt.figure(figsize=(20,10))
  1263. plt.plot(x_time/10, mean_ts_sic_left_SPR, color = 'blue', label ='averaged time series of stop incorrect', linewidth = 2.5)
  1264. plt.fill_between(x_time/10, down_ts_sic_left_SPR, up_ts_sic_left_SPR, color='lightblue', label = '95% confidence interval of stop incorrect trials')
  1265. plt.plot(x_time/10, mean_ts_sc_left_SPR, color = '#DD4800', label = ' averaged time series of stop correct', linewidth = 2.5)
  1266. plt.fill_between(x_time/10, down_ts_sc_left_SPR, up_ts_sc_left_SPR, color=(1.0, 0.5, 0.0, 0.5), label = '95% confidence interval of stop correct trials')
  1267. plt.xlabel('time around stop signal', fontsize=36)
  1268. plt.xticks(fontsize = 36)
  1269. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1270. plt.yticks(fontsize = 36)
  1271. plt.axvline(x=0, color='red' ,linewidth='4')
  1272. plt.legend(fontsize = 24)
  1273. # %%
  1274. plt.figure(figsize=(20,10))
  1275. plt.plot(x_time/10, mean_ts_sic_left_supramarginal, color = 'blue', label ='averaged time series of stop incorrect', linewidth = 2.5)
  1276. plt.fill_between(x_time/10, down_ts_sic_left_supramarginal, up_ts_sic_left_supramarginal, color='lightblue', label = '95% confidence interval of stop incorrect trials')
  1277. plt.plot(x_time/10, mean_ts_sc_left_supramarginal, color = '#DD4800', label = ' averaged time series of stop correct', linewidth = 2.5)
  1278. plt.fill_between(x_time/10, down_ts_sc_left_supramarginal, up_ts_sc_left_supramarginal, color=(1.0, 0.5, 0.0, 0.5), label = '95% confidence interval of stop correct trials')
  1279. plt.xlabel('time around stop signal', fontsize=36)
  1280. plt.xticks(fontsize = 36)
  1281. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1282. plt.yticks(fontsize = 36)
  1283. plt.axvline(x=0, color='red' ,linewidth='4')
  1284. plt.legend(fontsize = 24)
  1285. # %%
  1286. plt.figure(figsize=(20,10))
  1287. plt.plot(x_time/10, mean_ts_sic_right_insula, color = 'blue', label ='averaged time series of stop incorrect', linewidth = 2.5)
  1288. plt.fill_between(x_time/10, down_ts_sic_right_insula, up_ts_sic_right_insula, color='lightblue', label = '95% confidence interval of stop incorrect trials')
  1289. plt.plot(x_time/10, mean_ts_sc_right_insula, color = '#DD4800', label = ' averaged time series of stop correct', linewidth = 2.5)
  1290. plt.fill_between(x_time/10, down_ts_sc_right_insula, up_ts_sc_right_insula, color=(1.0, 0.5, 0.0, 0.5), label = '95% confidence interval of stop correct trials')
  1291. plt.xlabel('time around stop signal', fontsize=36)
  1292. plt.xticks(fontsize = 36)
  1293. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1294. plt.yticks(fontsize = 36)
  1295. plt.axvline(x=0, color='red' ,linewidth='4')
  1296. plt.legend(fontsize = 24)
  1297. # %%
  1298. plt.figure(figsize=(20,10))
  1299. plt.plot(x_time/10, mean_ts_sic_right_lingual, color = 'blue', label ='averaged time series of stop incorrect', linewidth = 2.5)
  1300. plt.fill_between(x_time/10, down_ts_sic_right_lingual, up_ts_sic_right_lingual, color='lightblue', label = '95% confidence interval of stop incorrect trials')
  1301. plt.plot(x_time/10, mean_ts_sc_right_lingual, color = '#DD4800', label = ' averaged time series of stop correct', linewidth = 2.5)
  1302. plt.fill_between(x_time/10, down_ts_sc_right_lingual, up_ts_sc_right_lingual, color=(1.0, 0.5, 0.0, 0.5), label = '95% confidence interval of stop correct trials')
  1303. plt.xlabel('time around stop signal', fontsize=36)
  1304. plt.xticks(fontsize = 36)
  1305. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1306. plt.yticks(fontsize = 36)
  1307. plt.axvline(x=0, color='red' ,linewidth='4')
  1308. plt.legend(fontsize = 18)
  1309. # %%
  1310. plt.figure(figsize=(20,10))
  1311. plt.plot(x_time/10, mean_ts_sic_right_supramarginal, color = 'blue', label ='averaged time series of stop incorrect', linewidth = 2.5)
  1312. plt.fill_between(x_time/10, down_ts_sic_right_supramarginal, up_ts_sic_right_supramarginal, color='lightblue', label = '95% confidence interval of stop incorrect trials')
  1313. plt.plot(x_time/10, mean_ts_sc_right_supramarginal, color = '#DD4800', label = ' averaged time series of stop correct', linewidth = 2.5)
  1314. plt.fill_between(x_time/10, down_ts_sc_right_supramarginal, up_ts_sc_right_supramarginal, color=(1.0, 0.5, 0.0, 0.5), label = '95% confidence interval of stop correct trials')
  1315. plt.xlabel('time around stop signal', fontsize=36)
  1316. plt.xticks(fontsize = 36)
  1317. plt.ylabel('BOLD units \n difference between conditions', fontsize=36)
  1318. plt.yticks(fontsize = 36)
  1319. plt.axvline(x=0, color='red' ,linewidth='4')
  1320. plt.legend(fontsize = 24)
  1321. # %%
  1322. # testing difference between stop incorrect and stop correct waves
  1323. # %%
  1324. scipy.stats.ttest_rel(np.mean(np.array(list_subtraction_all_waves2_SFG)[:,0,:][:,90:110], axis = 1), np.mean(np.array(list_subtraction_all_waves2_SFG)[:,1,:][:,90:110], axis = 1))
  1325. # %%
  1326. scipy.stats.ttest_rel(np.mean(np.array(list_subtraction_all_waves2_left_insula)[:,0,:][:,90:110], axis = 1), np.mean(np.array(list_subtraction_all_waves2_left_insula)[:,1,:][:,90:110], axis = 1))
  1327. # %%
  1328. scipy.stats.ttest_rel(np.mean(np.array(list_subtraction_all_waves2_left_supramarginal)[:,0,:][:,90:110], axis = 1), np.mean(np.array(list_subtraction_all_waves2_left_supramarginal)[:,1,:][:,90:110], axis = 1))
  1329. # %%
  1330. scipy.stats.ttest_rel(np.mean(np.array(list_subtraction_all_waves2_left_SPR)[:,0,:][:,90:110], axis = 1), np.mean(np.array(list_subtraction_all_waves2_left_SPR)[:,1,:][:,90:110], axis = 1))
  1331. # %%
  1332. scipy.stats.ttest_rel(np.mean(np.array(list_subtraction_all_waves2_right_insula)[:,0,:][:,90:110], axis = 1), np.mean(np.array(list_subtraction_all_waves2_right_insula)[:,1,:][:,90:110], axis = 1))
  1333. # %%
  1334. scipy.stats.ttest_rel(np.mean(np.array(list_subtraction_all_waves2_right_supramarginal)[:,0,:][:,90:110], axis = 1), np.mean(np.array(list_subtraction_all_waves2_right_supramarginal)[:,1,:][:,90:110], axis = 1))
  1335. # %%
  1336. scipy.stats.ttest_rel(np.mean(np.array(list_subtraction_all_waves2_right_lingual)[:,0,:][:,90:110], axis = 1), np.mean(np.array(list_subtraction_all_waves2_right_lingual)[:,1,:][:,90:110], axis = 1))
  1337. # %%
  1338. #Computing variables for models of relationship between BOLD and sri and sst
  1339. # %%
  1340. def create_df_for_region(dict_region,dict_interpolated_ts_region, start_time, stop_time, baseline_long_start, baseline_long_end, SSRT_dict, directory_save):
  1341. all_events_list_region = []
  1342. for id_s_r, dict_ssd_subtract_wave in dict_region.items():
  1343. for ssd_value, list_ts in dict_ssd_subtract_wave.items():
  1344. for num, (ts, rt) in enumerate(list_ts):
  1345. indices_peaks = [x for x in scipy.signal.find_peaks(ts)[0] if x>start_time and x<stop_time]
  1346. peak_value=[sorted([ts[y] for y in indices_peaks])[0] if len(indices_peaks)>0 else []][0]
  1347. print([abs((start_time + (start_time-stop_time)/2)-y) for y in indices_peaks])
  1348. peak_value_closest=[ts[sorted([int(abs((start_time + (start_time-stop_time)/2)-y)) for y in indices_peaks])[0]] if len(indices_peaks)>0 else []][0]
  1349. general_baseline = np.mean((dict_interpolated_ts_region[id_s_r]))
  1350. valueBOLD = np.mean(ts[start_time:stop_time])
  1351. amplitudeBOLD = valueBOLD - np.mean(ts[baseline_long_start:baseline_long_end])
  1352. amplitudeBOLD_peak = peak_value -np.mean(ts[baseline_long_start:baseline_long_end])
  1353. amplitudeBOLD_peak_closest = peak_value_closest -np.mean(ts[baseline_long_start:baseline_long_end])
  1354. amplitudeBOLD2 = valueBOLD - general_baseline
  1355. amplitudeBOLD2_peak = peak_value - general_baseline
  1356. amplitudeBOLD2_peak_closest = peak_value_closest - general_baseline
  1357. list_events = [re.findall(r'sub-\d{2}', id_s_r)[0], re.findall(r'run-\d{2}', id_s_r)[0], ssd_value, rt, valueBOLD, np.mean(ts[:40]), general_baseline, amplitudeBOLD, amplitudeBOLD2, amplitudeBOLD_peak, amplitudeBOLD2_peak, amplitudeBOLD_peak_closest, amplitudeBOLD2_peak_closest, rt - ssd_value]
  1358. all_events_list_region.append(list_events)
  1359. df_data_region = pd.DataFrame(all_events_list_region)
  1360. df_data_region.columns = ['subject', 'run', 'ssd', 'rt', 'BOLD_value_in_peak', 'baseline1', 'general_baseline','amplitude_eeg', 'amplitude_general', 'amplitude_eeg_peak', 'amplitude_general_peak', 'amplitude_eeg_peak_closest', 'amplitude_general_peak_closest', 'sri']
  1361. df_data_region['SSRT'] = [SSRT_dict[one_sub + '_' + df_data_region['run'][num]]*10 for num, one_sub in enumerate(list(df_data_region['subject']))]
  1362. df_data_region['rtSSRT'] = df_data_region['rt']-df_data_region['SSRT']
  1363. df_data_region['slower_than_SSRT'] = df_data_region['rt']>df_data_region['SSRT']
  1364. df_data_region.to_csv(directory_save)
  1365. # %%
  1366. def create_files_with_data(dict_directories, start_time, stop_time, baseline_start, baseline_stop, SSRT_dict):
  1367. for keys, values in dict_directories.items():
  1368. create_df_for_region(values[0], values[1], start_time, stop_time, baseline_start, baseline_stop, SSRT_dict, keys+'_'+str(start_time)+'_'+str(stop_time)+'_'+str(baseline_start)+'_'+str(baseline_stop)+'.csv')
  1369. # %%
  1370. dvs=['amplitude_general']
  1371. ivs=['sri' ,'ssd', 'sri+ssd']
  1372. # %%
  1373. def create_model(dv,iv, df_data, variant):
  1374. import statsmodels.api as sm
  1375. import statsmodels.formula.api as smf
  1376. if variant == 1:
  1377. pd.to_numeric(df_data[iv])
  1378. pd.to_numeric(df_data[dv])
  1379. df_data[dv] = [float(i) for i in df_data[dv]]
  1380. md = smf.mixedlm(dv + "~" + iv, df_data, groups=df_data["subject"])
  1381. mdf = md.fit()
  1382. print(mdf.summary())
  1383. plt.scatter(df_data[iv]*100, df_data[dv], color='blue')
  1384. plt.xticks(fontsize = 20, rotation = 90)
  1385. plt.yticks(fontsize = 20)
  1386. iv_vals = np.linspace(df_data[iv].min(), df_data[iv].max(), 100)
  1387. intercept = mdf.params['Intercept']
  1388. slope = mdf.params[iv]
  1389. regression_line = intercept + slope * iv_vals
  1390. plt.plot(iv_vals*100, regression_line, color='red', label='Regression line', linewidth = 6)
  1391. plt.xlabel('stop response interval (SRI)', fontsize = 20) # Replace with your x-axis label
  1392. plt.ylabel('BOLD amplitude', fontsize = 20) # Replace with your y-axis label
  1393. plt.title('Relationship between BOLD and SRI', fontsize = 20)
  1394. plt.show()
  1395. elif variant==2:
  1396. iv_1=re.findall(r'sri',iv)[0]
  1397. iv_2=re.findall(r'ssd',iv)[0]
  1398. pd.to_numeric(df_data[dv])
  1399. pd.to_numeric(df_data[iv_1])
  1400. pd.to_numeric(df_data[iv_2])
  1401. df_data[dv] = [float(i) for i in df_data[dv]]
  1402. md = smf.mixedlm(dv + "~" + iv, df_data, groups=df_data["subject"])
  1403. mdf = md.fit()
  1404. print(mdf.summary())
  1405. elif variant==3:
  1406. iv_1=re.findall(r'rtSSRT',iv)[0]
  1407. iv_2=re.findall(r'ssd',iv)[0]
  1408. pd.to_numeric(df_data[dv])
  1409. pd.to_numeric(df_data[iv_1])
  1410. pd.to_numeric(df_data[iv_2])
  1411. df_data[dv] = [float(i) for i in df_data[dv]]
  1412. md = smf.mixedlm(dv + "~" + iv, df_data, groups=df_data["subject"])
  1413. mdf = md.fit()
  1414. print(mdf.summary())
  1415. elif variant==4:
  1416. iv_1=re.findall(r'ssd',iv)[0]
  1417. iv_2=re.findall(r'STAI',iv)[0]
  1418. pd.to_numeric(df_data[dv])
  1419. pd.to_numeric(df_data[iv_1])
  1420. pd.to_numeric(df_data[iv_2])
  1421. df_data[dv] = [float(i) for i in df_data[dv]]
  1422. md = smf.mixedlm(dv + "~" + iv, df_data, groups=df_data["subject"])
  1423. mdf = md.fit()
  1424. print(mdf.summary())
  1425. # %%
  1426. def create_models(directory_data, dvs, ivs, both_rtSSRT):
  1427. for one_dir in [directory_data + i for i in os.listdir(directory_data) if i[0]!='c']:
  1428. for one_dv in dvs:
  1429. df_data_region=pd.read_csv(one_dir)
  1430. df_data_region['STAI']=[dict_STAI[x] for num, x in enumerate(df_data_region['subject'])]
  1431. print(one_dv)
  1432. if one_dv == 'amplitude_eeg_peak':
  1433. df_data_region = df_data_region.iloc[[num for num, i in enumerate(df_data_region['amplitude_eeg_peak']) if len(re.findall(r'\[',i))==0]]
  1434. elif one_dv == 'amplitude_general_peak':
  1435. df_data_region = df_data_region.iloc[[num for num, i in enumerate(df_data_region['amplitude_general_peak']) if len(re.findall(r'\[',i))==0]]
  1436. elif one_dv == 'amplitude_eeg_peak_closest':
  1437. df_data_region = df_data_region.iloc[[num for num, i in enumerate(df_data_region['amplitude_eeg_peak_closest']) if len(re.findall(r'\[',i))==0]]
  1438. elif one_dv == 'amplitude_general_peak_closest':
  1439. df_data_region = df_data_region.iloc[[num for num, i in enumerate(df_data_region['amplitude_general_peak_closest']) if len(re.findall(r'\[',i))==0]]
  1440. for one_iv in ivs:
  1441. print(one_dir)
  1442. if one_iv == 'sri':
  1443. df_data_region = df_data_region.iloc[[num for num, i in enumerate(list(df_data_region['sri'])) if i<9],:]
  1444. create_model(one_dv, one_iv, df_data_region,1)
  1445. elif one_iv == 'ssd':
  1446. df_data_region = df_data_region.iloc[[num for num, i in enumerate(list(df_data_region['ssd'])) if i<6],:] #abs(i - np.mean(list(df_data_region['ssd'])))<3*np.std(list(df_data_region['ssd']))],:] #
  1447. create_model(one_dv, one_iv, df_data_region,1)
  1448. elif one_iv =='rtSSRT' and both_rtSSRT == True:
  1449. df_data_region_rtSSRT_whole = df_data_region.iloc[[num for num, i in enumerate(list(df_data_region['rtSSRT'])) if i<7.5 and i>-4],:]
  1450. df_data_region_rtSSRT_non_zero = df_data_region.iloc[[num for num, i in enumerate(list(df_data_region['rtSSRT'])) if i>0 and i<7.5],:]
  1451. print("Whole rtSSRT")
  1452. create_model(one_dv, one_iv, df_data_region_rtSSRT_whole,1)
  1453. print("Non zero rtSSRT")
  1454. create_model(one_dv, one_iv, df_data_region_rtSSRT_non_zero,1)
  1455. elif one_iv =='rtSSRT' and both_rtSSRT == False:
  1456. df_data_region_rtSSRT_non_zero = df_data_region.iloc[[num for num, i in enumerate(list(df_data_region['rtSSRT'])) if i>0 and i<7.5],:]
  1457. print("Non zero rtSSRT")
  1458. create_model(one_dv, one_iv, df_data_region_rtSSRT_non_zero,1)
  1459. elif len(re.findall(r'sri',one_iv))!=0 and re.findall(r'sri',one_iv)[0]=='sri' and re.findall(r'ssd',one_iv)[0]=='ssd':
  1460. df_data_region = df_data_region.iloc[[num for num, i in enumerate(list(df_data_region['sri'])) if i<9 and list(df_data_region['ssd'])[num]<6],:]
  1461. create_model(one_dv, one_iv, df_data_region, 2)
  1462. elif len(re.findall(r'rtSSRT',one_iv))!=0 and re.findall(r'rtSSRT',one_iv)[0]=='rtSSRT' and re.findall(r'ssd',one_iv)[0]=='ssd':
  1463. df_data_region = df_data_region.iloc[[num for num, i in enumerate(list(df_data_region['rtSSRT'])) if i>0 and i<7.5 and i>-4 and list(df_data_region['ssd'])[num]>0 and list(df_data_region['ssd'])[num]<6],:]
  1464. create_model(one_dv, one_iv, df_data_region, 3)
  1465. elif len(re.findall(r'ssd',one_iv))!=0 and re.findall(r'ssd',one_iv)[0]=='ssd' and re.findall(r'STAI',one_iv)[0]=='STAI':
  1466. print('tutaj')
  1467. df_data_region = df_data_region.iloc[[num for num, i in enumerate(list(df_data_region['ssd'])) if abs(i - np.mean(list(df_data_region['ssd'])))<3*np.std(list(df_data_region['ssd']))],:]
  1468. df_data_region = df_data_region.iloc[[num for num, i in enumerate(df_data_region['STAI']) if math.isnan(i)==False],:]
  1469. create_model(one_dv, one_iv, df_data_region, 4)
  1470. # %%
  1471. dict_STAI={'sub-01':float('NaN'),
  1472. 'sub-02':float('NaN'),
  1473. 'sub-03':float('NaN'),
  1474. 'sub-04':float('NaN'),
  1475. 'sub-05':float('NaN'),
  1476. 'sub-06':float('NaN'),
  1477. 'sub-07':33,
  1478. 'sub-08':43,
  1479. 'sub-09':49,
  1480. 'sub-10':31,
  1481. 'sub-11':30,
  1482. 'sub-12':35,
  1483. 'sub-13':38,
  1484. 'sub-14':44,
  1485. 'sub-15':42,
  1486. 'sub-16':57,
  1487. 'sub-17':24,
  1488. 'sub-18':39,
  1489. 'sub-19':49,
  1490. 'sub-20':33,
  1491. 'sub-21':40,
  1492. 'sub-22':37,
  1493. 'sub-23':52,
  1494. 'sub-24':42,
  1495. 'sub-25':46,
  1496. 'sub-26':42,
  1497. 'sub-27':44,
  1498. 'sub-28':65,
  1499. 'sub-29':35,
  1500. 'sub-30':32,
  1501. 'sub-31':29,
  1502. 'sub-32':34,
  1503. 'sub-33':43,
  1504. 'sub-34':55,
  1505. 'sub-35':39,
  1506. 'sub-36':50,
  1507. 'sub-37':35,
  1508. 'sub-38':50,
  1509. 'sub-39':43,
  1510. 'sub-40':38,
  1511. 'sub-41':38,
  1512. 'sub-42':35,
  1513. 'sub-43':32,
  1514. 'sub-44':40,
  1515. 'sub-45':36,
  1516. 'sub-46':36,
  1517. 'sub-47':34,
  1518. 'sub-48':33,
  1519. 'sub-49':50,
  1520. 'sub-50':49}
  1521. # %%
  1522. dict_STAI={'sub-01':float('NaN'),
  1523. 'sub-02':float('NaN'),
  1524. 'sub-03':float('NaN'),
  1525. 'sub-04':float('NaN'),
  1526. 'sub-05':float('NaN'),
  1527. 'sub-06':float('NaN'),
  1528. 'sub-07':33,
  1529. 'sub-08':43,
  1530. 'sub-09':49,
  1531. 'sub-10':31,
  1532. 'sub-11':30,
  1533. 'sub-12':35,
  1534. 'sub-13':38,
  1535. 'sub-14':44,
  1536. 'sub-15':42,
  1537. 'sub-16':57,
  1538. 'sub-17':24,
  1539. 'sub-18':39,
  1540. 'sub-19':49,
  1541. 'sub-20':33,
  1542. 'sub-21':40,
  1543. 'sub-22':37,
  1544. 'sub-23':52,
  1545. 'sub-24':42,
  1546. 'sub-25':46,
  1547. 'sub-26':42,
  1548. 'sub-27':44,
  1549. 'sub-28':65,
  1550. 'sub-29':35,
  1551. 'sub-30':32,
  1552. 'sub-31':29,
  1553. 'sub-32':34,
  1554. 'sub-33':43,
  1555. 'sub-34':55,
  1556. 'sub-35':39,
  1557. 'sub-36':50,
  1558. 'sub-37':35,
  1559. 'sub-38':50,
  1560. 'sub-39':43,
  1561. 'sub-40':38,
  1562. 'sub-41':38,
  1563. 'sub-42':35,
  1564. 'sub-43':32,
  1565. 'sub-44':40,
  1566. 'sub-45':36,
  1567. 'sub-46':36,
  1568. 'sub-47':34,
  1569. 'sub-48':33,
  1570. 'sub-49':50,
  1571. 'sub-50':49}
  1572. # %%
  1573. create_models(<directory_to_ROIS results>n, dvs, ivs, True)

Behavioral & fMRI analysis.ipynb, no license · at the source

Overview

Authors: Krzysztof Bielski1,2, Szymon Wichary1, Edward Nęcka3, Magdalena Senderecka4
  1. Institute of Psychology, Jagiellonian University, 6 Ingarden Street, 30-060 Cracow, Poland
  2. Doctoral School of Social Sciences, Jagiellonian University, 34 Main Square, 31-010 Cracow, Poland
  3. Department of Psychology, SWPS University, 39a Jan Paweł II Avenue, 31-864 Cracow, Poland
  4. Centre for Cognitive Science, Jagiellonian University, 3 Ingarden Street, 30-060 Cracow, Poland
Institutions: Jagiellonian University (Poland); Uniwersytet SWPS (Poland)
Journal: Scientific reports, volume 16, issue 1, article 12321
Dates: received 25 June 2025; accepted 27 February 2026; published online 6 March 2026
Type: Research article · Language: English
License: CC BY-NC-ND
Identifiers: DOI 10.1038/s41598-026-42784-6 · PMID 41792218 · PMCID PMC13079758 · OpenAlex W7134076220
Open access: gold, a free copy (OpenAlex)
Status: code verified
Categories: fMRI (modality), human (organism)
Methods: Spectral & time-frequency, Statistics, Connectivity, fMRI & imaging
Keywords: Conflict detection, Error processing, Functional magnetic resonance imaging, Pre-supplementary motor area, Reinforcement learning, Cognitive neuroscience, Cognitive control
MeSH: Conflict, Psychological*, Inhibition, Psychological*, Motor Cortex*, Adult, Brain Mapping, Female, Humans, Magnetic Resonance Imaging, Male, Reaction Time, Young Adult (* major topic)
Topic: Neural and Behavioral Psychology Studies (Cognitive Neuroscience, Neuroscience), according to OpenAlex
Funding: Narodowe Centrum Nauki (2020/38/E/HS6/00490, 2019/35/B/HS6/01173); John Templeton Foundation (The Limits of Scientific Explanation)
Citations: not cited yet (Europe PMC); 67 references in the paper

Abstract

The abstract is not reproduced here: the paper's license (CC BY-NC-ND) does not allow it. Read it in the paper, at the publisher or on Europe PMC.

Repository

Its files are read in the Code ↔ Paper reader above.

OSF aum96

License: none: the authors keep all their rights
State: the link answers, verified on 30 September 2026
Evidence: files inventoried
Languages: MATLAB (3), Jupyter (1)
Size: 88 files, 4 scripts
Software Heritage: not checked
Found in: “Data availability”
Holds: 1 notebook
Not found: README, license file, CITATION.cff, environment file, tests, continuous integration, documentation
Tools: SPM (3 files), Matplotlib (1 file), NiBabel (1 file), NumPy (1 file), pandas (1 file), scikit-learn (1 file), SciPy (1 file), statsmodels (1 file)
Availability: 1 check, the latest on 30 September 2026: the link answers (HTTP 200)
  • 30 September 2026: the link answers (HTTP 200)
4 files
At the source: osf.io/aum96/

The paper's code and data availability statement is in the Data section.

Tracing map

Proposed by the machine: these links were found in the paper and verified at the source, without human review. The map will receive a Zenodo DOI once one of the paper's authors has validated it with their ORCID.

What the map holds:

  • 1 repository of the authors' code, each at its verified commit, with its license and how the link was found in the paper;
  • 4 scripts, each with its path and the digest of its content;
  • no match between paragraphs and code yet;
  • neither the text of the paper nor the code itself.

Its JSON (tracing-map.json) is deposited on Zenodo with its DOI once the map is validated.

Data

No dataset and no data link were found in the paper.

Code and data availability statement

The paper has a code and data availability statement. Its license (CC BY-NC-ND) does not allow reproducing it here; in short, from what the harvester recognized in it:

Read it in the paper: doi.org/10.1038/s41598-026-42784-6.

Versions

The history of this record: each version stored by the harvester or made by a correction of its authors or of the maintainers of its code, and what changed in its facts. The texts of the paper (its abstract, its availability statements) are not part of it; versions that changed only those are not listed.

Version 1, 30 September 2026: the first record

Recorded: type, language, journal, volume, issue, pages, dates, 4 authors, 7 keywords, 11 MeSH terms, 2 funders, 59 references.

Cite

This paper

Bielski, K., Wichary, S., Nęcka, E., & Senderecka, M. (2026). Distinguishing between response conflict and error expectancy in inhibitory error processing: the role of the presupplementary motor cortex. Scientific reports, 16(1), 12321. https://doi.org/10.1038/s41598-026-42784-6

BibTeX

@article{bielski2026distinguishing,
author = {Bielski, Krzysztof and Wichary, Szymon and Nęcka, Edward and Senderecka, Magdalena},
title = {{Distinguishing between response conflict and error expectancy in inhibitory error processing: the role of the presupplementary motor cortex}},
journal = {Scientific reports},
year = {2026},
month = mar,
volume = {16},
number = {1},
pages = {12321},
publisher = {Nature Publishing Group},
issn = {2045-2322},
doi = {10.1038/s41598-026-42784-6},
url = {https://doi.org/10.1038/s41598-026-42784-6},
pmid = {41792218},
pmcid = {PMC13079758}
}

RIS

TY - JOUR
AU - Bielski, Krzysztof
AU - Wichary, Szymon
AU - Nęcka, Edward
AU - Senderecka, Magdalena
TI - Distinguishing between response conflict and error expectancy in inhibitory error processing: the role of the presupplementary motor cortex
T2 - Scientific reports
J2 - Sci Rep
PY - 2026
DA - 2026/03/06
VL - 16
IS - 1
SP - 12321
SN - 2045-2322
PB - Nature Publishing Group
DO - 10.1038/s41598-026-42784-6
UR - https://doi.org/10.1038/s41598-026-42784-6
LA - en
ER -

CSL-JSON

{
"id": "10.1038/s41598-026-42784-6",
"type": "article-journal",
"title": "Distinguishing between response conflict and error expectancy in inhibitory error processing: the role of the presupplementary motor cortex",
"container-title": "Scientific reports",
"author": [
{
"family": "Bielski",
"given": "Krzysztof"
},
{
"family": "Wichary",
"given": "Szymon"
},
{
"family": "Nęcka",
"given": "Edward"
},
{
"family": "Senderecka",
"given": "Magdalena"
}
],
"container-title-short": "Sci Rep",
"volume": "16",
"issue": "1",
"page": "12321",
"DOI": "10.1038/s41598-026-42784-6",
"PMID": "41792218",
"PMCID": "PMC13079758",
"ISSN": "2045-2322",
"publisher": "Nature Publishing Group",
"URL": "https://doi.org/10.1038/s41598-026-42784-6",
"language": "en",
"issued": {
"date-parts": [
[
2026,
3,
6
]
]
}
}

The tracing map gets a citation of its own once an author has validated it and it has a DOI.

Similar papers

The papers with a page that share the most with this one: the tools found in their code, their categories, datasets, cited references and authors, the rarest counting most.

[1] doi:10.1371/journal.pbio.3003856 [code]
Aging and metabolism contribute separately to brain-body health.
Journal: PLoS biology
In common: SPM, NiBabel, statsmodels, 5 other tools, 1 reference
[2] doi:10.1038/s41467-026-76452-0 [code]
Music evokes shared neural representations of imagined narratives across sensory modalities.
Journal: Nature communications
In common: SPM, NiBabel, statsmodels, 5 other tools, 1 reference
[3] doi:10.1038/s41467-026-71963-2 [code]
Spinal cord structural and functional architecture and its shared organization with the brain across the adult lifespan.
Journal: Nature communications
In common: SPM, NiBabel, statsmodels, 5 other tools, 1 reference
[4] doi:10.1038/s41467-026-71568-9 [code]
Convergent and selective representations of pain, appetitive processes, aversive processes, and cognitive control in the insula.
Journal: Nature communications
In common: SPM, NiBabel, statsmodels, 5 other tools, 1 reference
[5] doi:10.1038/s41467-026-71151-2 [code]
Common and distinct neural correlates of social interaction processing and theory of mind in narratives.
Journal: Nature communications
In common: SPM, NiBabel, statsmodels, 5 other tools, 1 reference
[6] doi:10.1016/j.neuron.2026.04.011 [code]
Precision fMRI reveals densely interdigitated network patches with conserved motifs in the lateral prefrontal cortex.
Journal: Neuron
In common: SPM, NiBabel, scikit-learn, 3 other tools, fMRI, 2 references
[7] doi:10.1038/s41598-026-56688-y [code]
On the value of radiomics in addition to clinical measures in emotional conflict fMRI for predicting sertraline response in major depressive disorder.
Journal: Scientific reports
In common: SPM, NiBabel, statsmodels, 5 other tools, fMRI
[8] doi:10.1016/j.nicl.2026.104012 [code]
Structural-functional multilayer brain network properties and outcome of combined repetitive transcranial magnetic stimulation and psychotherapy for obsessive-compulsive disorder.
Journal: NeuroImage. Clinical
In common: SPM, NiBabel, statsmodels, 5 other tools, fMRI
[9] doi:10.1038/s41597-026-07377-y [code]
An open-access multi-site fMRI dataset for investigating conscious visual perception.
Journal: Scientific data
In common: SPM, NiBabel, statsmodels, 5 other tools, fMRI
[10] doi:10.7554/elife.107933 [code]
Modality-agnostic decoding of vision and language from fMRI.
Journal: eLife
In common: SPM, NiBabel, statsmodels, 5 other tools, fMRI

Contribute

The authors of this paper can claim it, correct its record and validate its tracing map, and the maintainers of its code (its owner, or a public member of its organization) correct what it says of their repository; anyone signed in can ask for its removal. Every request goes to OSCR's own machine, which answers it; your account page follows them.

Sign in with ORCID to claim this paper as one of its authors, correct its record or validate its tracing map: when the paper's metadata lists your ORCID iD, you are recognized at once. Maintainers of its code: sign in with GitHub, then claim the repository on your account page.

Request its removal

To ask OSCR to remove this record, the copies of its authors' scripts or its tracing map, use the removal request page: signed in, you say who you are, what to remove and why, then review and confirm the request. Published rules decide every request (how).

Discussion, reproductions, activity

Discussion: questions and error reports about this paper and its code, from signed-in readers and its authors. It opens with sign-in.

Reproductions: reports from readers who ran the authors' code: what they reproduced, with which environment, commit and data. It opens with sign-in.

Activity: what happens around this paper: new versions of its record, its map's validation, discussions and reproductions. It opens with sign-in.