:param i: number of days analyzing :return: data frame of all analysis extracted from file (one animal) """ (timecode, eventcode) = extract_info_from_file(loaded_file, 500) (left_presses, right_presses, total_presses) = lever_pressing(eventcode, 'LPressOn', 'RPressOn') pressing_across_test = bin_by_time(timecode, eventcode, (5 * 60), ['LPressOn', 'RPressOn']) df2 = pd.DataFrame([[ loaded_file['Subject'], loaded_file['Sex'], int(i + 1), loaded_file['Training'], float(total_presses), pressing_across_test ]], columns=column_list) bins_df = df2['Bins'].apply(pd.Series) bins_df = bins_df.rename(columns=lambda x: (x + 1) * 5) df2 = pd.concat([df2[:], bins_df[:]], axis=1) return df2 (days, df) = loop_over_days(column_list, habit_extinction_function) binned_columns = [col for col in df.columns if type(col) == int] dfnew = pd.melt(df, id_vars=['Subject', 'Sex', 'Day', 'Training', 'Lever Presses'], value_vars=binned_columns, var_name='Bin', value_name='Lever_Pressing_During_Bin')
""" (timecode, eventcode) = extract_info_from_file(loaded_file, 500) (dippers, dippers_retrieved, retrieval_latency) = reward_retrieval(timecode, eventcode) (A_responding, A_iti) = cue_iti_responding(timecode, eventcode, 'ExcitorATrialStart', 'ExcitorATrialEnd', 'PokeOn1') (B_responding, B_iti) = cue_iti_responding(timecode, eventcode, 'ExcitorBTrialStart', 'ExcitorBTrialEnd', 'PokeOn1') df2 = pd.DataFrame([[ loaded_file['Subject'], loaded_file['MSN'], int(i + 1), float(A_responding), float(A_iti), float(B_responding), float(B_iti), float(dippers), float(dippers_retrieved), float(retrieval_latency) ]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, CI_training_function) print(df.to_string()) df.to_excel("output.xlsx")
from operantanalysis import loop_over_days, extract_info_from_file, cue_responding_duration import pandas as pd column_list = ['Subject', 'Condition', 'Day', 'Light Poke Duration', 'LightITI'] def CI_retardation_function(loaded_file, i): """ :param loaded_file: file output from operant box :param i: number of days analyzing :return: data frame of all analysis extracted from file (one animal) """ (timecode, eventcode) = extract_info_from_file(loaded_file, 500) (X_dur_individual, X_dur_total, XITI_dur_individual, XITI_dur_total) = cue_responding_duration(timecode, eventcode, 'InhibitorTrialStart', 'InhibitorTrialEnd', 'PokeOn1', 'PokeOff1') df2 = pd.DataFrame([[loaded_file['Subject'], loaded_file['MSN'], int(i + 1), float(X_dur_total), float(XITI_dur_total)]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, CI_retardation_function) print(df.to_string()) df.to_excel("output.xlsx")
(go_trials, nogo_trials) = count_go_nogo_trials(eventcode) (successful_go_trials, successful_nogo_trials) = num_successful_go_nogo_trials(eventcode) df2 = pd.DataFrame([[ loaded_file['Subject'], loaded_file['tts'], int(i + 1), float(dippers), float(go_trials), float(successful_go_trials) ]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, Go_NoGo) print(df.to_string()) df.to_excel("output.xlsx") group_means = df.groupby(['Day', 'tts'])['Dippers', 'Successful Go Trials'].mean() group_sems = df.groupby(['Day', 'tts'])['Dippers', 'Successful Go Trials'].sem() print( df.groupby(['Day', 'tts'])['Dippers', 'Successful Go Trials'].mean().unstack().to_string()) print( df.groupby(['Day', 'tts'])['Dippers',
def crf_function(loaded_file, i): """ :param loaded_file: file output from operant box :param i: number of days analyzing :return: data frame of all analysis extracted from file (one animal) """ (timecode, eventcode) = extract_info_from_file(loaded_file, 500) (dippers, dippers_retrieved, retrieval_latency) = reward_retrieval(timecode, eventcode) (large_rewards, small_rewards) = num_switch_trials(eventcode) (forced_latency) = lever_press_latency_Switch(timecode, eventcode) df2 = pd.DataFrame([[ loaded_file['Subject'], loaded_file['MSN'], int(i + 1), float(dippers), float(large_rewards), float(small_rewards), float(forced_latency) ]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, crf_function) print(df.to_string()) df.to_excel("output.xlsx")
float(total_presses) ]], columns=column_list) return df2 # If user provided an argument at execution, use this to find data. try: data_directory = argv[1] # Otherwise, store it as an empty string so loop_over_days knows to use GUI. except IndexError: data_directory = '' (days, df) = loop_over_days(column_list, crf_function, master_data_folder=data_directory) print(df.to_string()) # If user provided multiple arguments at execution, use the second one as the save path for the output folder. try: save_path = os.path.join(argv[2], 'output.xlsx') df.to_excel(save_path) # Otherwise, save the DataFrame to the current working directory. except IndexError: df.to_excel("output.xlsx") graph_toggle = input( 'Would you like to see graphs of dipper retrieval, latency, and lever presses (Y/n)? ' )
['Paired_ES_' + str(i + 1) for i in range(len(paired_length_poke_rates))] + \ ['Unpaired_' + str(i + 1) for i in range(len(paired_length_poke_rates))] + \ ['Unpaired_ITI_' + str(i + 1) for i in range(len(paired_length_poke_rates))] + \ ['Unpaired_ES_' + str(i + 1) for i in range(len(paired_length_poke_rates))] across_cue_df = pd.DataFrame( [([loaded_file['Subject']] + paired_length_poke_rates + paired_iti_length_poke_rates + paired_subtracted_poke_rates + unpaired_length_poke_rates + unpaired_iti_length_poke_rates + unpaired_subtracted_poke_rates)], columns=new_cols) df2 = pd.DataFrame([[ loaded_file['Subject'], int(i + 1), float(dippers), float(dippers_retrieved), float(retrieval_latency), float(ind_dur), float(tot_dur), float(total_pokes) ]], columns=column_list) df2 = pd.merge(df2, across_cue_df, how='left', on=['Subject']) return df2 (days, df) = loop_over_days(column_list, PCER_P2_function) print(df.to_string()) df.to_excel("output.xlsx")
float(B_responding - B_iti), *group_ids ]], columns=column_list + file_keys) return df2 # If user provided an argument at execution, use this to find data. try: data_directory = argv[1] # Otherwise, store it as an empty string so loop_over_days knows to use GUI. except IndexError: data_directory = '' (days, df) = loop_over_days(column_list, PIT_training_function, master_data_folder=data_directory) print(df.to_string()) # If user provided multiple arguments at execution, use the second one as the save path for the output folder. try: save_path = os.path.join(argv[2], 'output.xlsx') df.to_excel(save_path) # Otherwise, save the DataFrame to the current working directory. except IndexError: df.to_excel("output.xlsx") graph_toggle = input( 'Would you like to see graphs of CS+ Responding (Y/n)? ') if graph_toggle == 'Y':
'BInhibitorTrialEnd', 'PokeOn1', 'PokeOff1') df2 = pd.DataFrame([[ loaded_file['Subject'], loaded_file['tts'], loaded_file['CI'], int(i + 1), float(B_dur_total), float(BITI_dur_total), float(BX_dur_total), float(BXITI_dur_total) ]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, CI_summation_function) print(df.to_string()) df.to_excel("output.xlsx") group_means = df.groupby(['Day', 'Condition'])['Noise Poke Duration', 'Noise ITI', 'Inhibitor Poke Duration', 'Inhibitor ITI'].mean() group_sems = df.groupby(['Day', 'Condition'])['Noise Poke Duration', 'Noise ITI', 'Inhibitor Poke Duration', 'Inhibitor ITI'].sem() print( df.groupby(['Day', 'tts', 'Condition'])['Noise Poke Duration', 'Noise ITI',
if loaded_file['MSN'] == 'PavCA_LeftUnpaired_2020' or loaded_file['MSN'] == 'PavCA_RightUnpaired_2020': (inactive_poke, inactive_iti_poke, trials_w_poke) = cue_iti_responding_PavCA(timecode, eventcode, 'NoRewardTrialStart', 'NoRewardTrialEnd', 'PokeOn1') (inactive_press, inactive_iti_press, trials_w_press) = cue_iti_responding_PavCA(timecode, eventcode, 'NoRewardTrialStart', 'NoRewardTrialEnd', 'InactivePress') poke_lat = lever_press_latency_PavCA(timecode, eventcode, 'NoRewardTrialStart', 'PokeOn1', 10) press_lat = lever_press_latency_PavCA(timecode, eventcode, 'NoRewardTrialStart', 'InactivePress', 10) poke = inactive_poke press = inactive_press prob_poke = trials_w_poke / 35 prob_press = trials_w_press / 35 iti_poke = inactive_iti_poke elif loaded_file['MSN'] == 'PavCA_LeftPaired_2020' or loaded_file['MSN'] == 'PavCA_RightPaired_2020': (active_poke, active_iti_poke, trials_w_poke) = cue_iti_responding_PavCA(timecode, eventcode, 'RewardTrialStart', 'RewardTrialEnd', 'PokeOn1') (active_press, active_iti_press, trials_w_press) = cue_iti_responding_PavCA(timecode, eventcode, 'RewardTrialStart', 'RewardTrialEnd', 'ActivePress') poke_lat = lever_press_latency_PavCA(timecode, eventcode, 'RewardTrialStart', 'PokeOn1', 10) press_lat = lever_press_latency_PavCA(timecode, eventcode, 'RewardTrialStart', 'ActivePress', 10) poke = active_poke press = active_press prob_poke = trials_w_poke / 35 prob_press = trials_w_press / 35 iti_poke = active_iti_poke df2 = pd.DataFrame([[loaded_file['Subject'], int(i + 1), float(dippers), float(iti_poke), float(poke), float(press), float(prob_poke), float(prob_press), float(poke_lat), float(press_lat)]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, pavCA) print(df.to_string()) df.to_excel("output.xlsx")
'NoRewardTrialEnd', 'PokeOn1') (inactive_press, inactive_iti_press) = cue_iti_responding( timecode, eventcode, 'NoRewardTrialStart', 'NoRewardTrialEnd', 'InactivePress') (active_poke, active_iti_poke) = cue_iti_responding(timecode, eventcode, 'RewardTrialStart', 'RewardTrialEnd', 'PokeOn1') (active_press, active_iti_press) = cue_iti_responding(timecode, eventcode, 'RewardTrialStart', 'RewardTrialEnd', 'ActivePress') df2 = pd.DataFrame([[ loaded_file['Subject'], int(i + 1), float(dippers), float(inactive_poke), float(inactive_press), float(active_poke), float(active_press) ]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, signtracking) print(df.to_string()) df.to_excel("output.xlsx")
(dippers, dippers_retrieved, retrieval_latency) = reward_retrieval(timecode, eventcode) df2 = pd.DataFrame([[ loaded_file['Subject'], int(i + 1), float(dippers), float(dippers_retrieved), float(retrieval_latency) ]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, trough_train_function) print(df) group_means = df.groupby(['Day'])['Dippers Retrieved', 'Retrieval Latency'].mean() group_sems = df.groupby(['Day'])['Dippers Retrieved', 'Retrieval Latency'].sem() plt.subplot(221) group_means['Dippers Retrieved'].plot(legend=True, yerr=group_sems['Dippers Retrieved'], ylim=[0, 60], xlim=[0, days + 1], xticks=(range(1, days + 1, 1)), marker='o',
(small_go_trials, large_go_trials, small_go_success, large_go_success) = (eventcode.count('GoTrialBegSmallReward'), eventcode.count('GoTrialBegLargeReward'), eventcode.count('GoTrialSuccessSmallReward'), eventcode.count('GoTrialSuccessLargeReward')) small_go_latency = lever_press_latency(timecode, eventcode, 'GoTrialBegSmallReward', 'GoTrialSuccessSmallReward') large_go_latency = lever_press_latency(timecode, eventcode, 'GoTrialBegLargeReward', 'GoTrialSuccessLargeReward') df2 = pd.DataFrame([[ loaded_file['Subject'], int(i + 1), float(small_go_trials), float(large_go_trials), float(small_go_success), float(large_go_success), float(small_go_latency), float(large_go_latency) ]], columns=column_list) return df2 (days, df) = loop_over_days(column_list, RVI_Go_NoGo_P1) print(df.to_string()) df.to_excel("output.xlsx")
matplotlib.use("TkAgg") from matplotlib import pyplot as plt # noqa column_list = ['Subject', 'Sex', 'Day', 'Training', 'Lever Presses', 'Bins'] def habit_reacquisition_function(loaded_file, i): """ :param loaded_file: file output from operant box :param i: number of days analyzing :return: data frame of all analysis extracted from file (one animal) """ (timecode, eventcode) = extract_info_from_file(loaded_file, 500) (left_presses, right_presses, total_presses) = lever_pressing(eventcode, 'LPressOn', 'RPressOn') pressing_across_test = bin_by_time(timecode, eventcode, (5 * 60), ['LPressOn', 'RPressOn']) df2 = pd.DataFrame([[loaded_file['Subject'], loaded_file['Sex'], int(i + 1), loaded_file['Training'], float(total_presses), pressing_across_test]], columns=column_list) bins_df = df2['Bins'].apply(pd.Series) bins_df = bins_df.rename(columns=lambda x: (x + 1) * 5) df2 = pd.concat([df2[:], bins_df[:]], axis=1) return df2 (days, df) = loop_over_days(column_list, habit_reacquisition_function) binned_columns = [col for col in df.columns if type(col) == int] dfnew = pd.melt(df, id_vars=['Subject', 'Sex', 'Day', 'Training', 'Lever Presses'], value_vars=binned_columns, var_name='Bin', value_name='Lever_Pressing_During_Bin')
group_ids.append(loaded_file[group]) df2 = pd.DataFrame([[loaded_file['Subject'], int(i + 1), float(dippers), float(dippers_retrieved), float(retrieval_latency), float(ind_dur), float(tot_dur), float(total_pokes), *group_ids]], columns=column_list+file_keys) return df2 # If user provided an argument at execution, use this to find data. try: data_directory = argv[1] # Otherwise, store it as an empty string so loop_over_days knows to use GUI. except IndexError: data_directory = '' (days, df) = loop_over_days(column_list, trough_train_function, master_data_folder=data_directory) print(df.to_string()) # If user provided multiple arguments at execution, use the second one as the save path for the output folder. try: save_path = os.path.join(argv[2], 'output.xlsx') df.to_excel(save_path) # Otherwise, save the DataFrame to the current working directory. except IndexError: df.to_excel("output.xlsx") graph_toggle = input('Would you like to see graphs of dipper retrieval and latency (Y/n)? ')
float(retrieval_latency), *group_ids ]], columns=column_list + file_keys) return df2 # If user provided an argument at execution, use this to find data. try: data_directory = argv[1] # Otherwise, store it as an empty string so loop_over_days knows to use GUI. except IndexError: data_directory = '' (days, df) = loop_over_days(column_list, Go_NoGo, master_data_folder=data_directory) print(df.to_string()) # If user provided multiple arguments at execution, use the second one as the save path for the output folder. try: save_path = os.path.join(argv[2], 'output.xlsx') df.to_excel(save_path) # Otherwise, save the DataFrame to the current working directory. except IndexError: df.to_excel("output.xlsx") df.to_excel("output.xlsx") graph_toggle = input( 'Would you like to see graphs of Succesful Go Trials and Retrieval Latency (Y/n)? '