diff --git a/config.json b/config.json new file mode 100644 index 0000000..5063425 --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "datasource": "/tmp/data", + "results": "/tmp/Graded_Remapping" +} diff --git a/iso_dist_hist.py b/iso_dist_hist.py index 4f1a1af..f53a75f 100644 --- a/iso_dist_hist.py +++ b/iso_dist_hist.py @@ -11,6 +11,7 @@ """ import os import glob +import json import numpy as np import matplotlib.pyplot as pl from scipy.io import loadmat @@ -36,10 +37,12 @@ ['g2784_d3'] ] -# Load data from this folder -hdf5Dir = '/home/fetterhoff/Graded_Remapping/' +with open("config.json") as f: + config = json.load(f) -combinedResultDir = hdf5Dir+'waveform_stats/' # Save in subdirectory +# Load data from this folder +hdf5Dir = config['datasource'] +combinedResultDir = os.path.join(config['results'], 'waveform_stats') # Save in subdirectory if not os.path.exists(combinedResultDir): os.makedirs(combinedResultDir) @@ -53,9 +56,9 @@ session = s[0] print(session) # current session - sd = hdf5Dir+session+'/' # session directory + sd = os.path.join(hdf5Dir, session) # session directory - for mat_name in glob.glob(sd+'*TT*.mat'): # loop through all neuron files + for mat_name in glob.glob(os.path.join(sd, '*TT*.mat')): # loop through all neuron files m = loadmat(mat_name) iso_dist = np.append(iso_dist, m['isolation_distance'][0][0]) # save isolation distances @@ -73,5 +76,5 @@ pl.ylabel('Cumulative Distribution') pl.xlim([0,100]) -pl.savefig(combinedResultDir+'Fig_S1B_IsolationDistance.pdf',format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.05) +pl.savefig(os.path.join(combinedResultDir, 'Fig_S1B_IsolationDistance.pdf'),format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.05) pl.close() diff --git a/maximum_likelihood_estimation.py b/maximum_likelihood_estimation.py index abc6adf..3c6057c 100644 --- a/maximum_likelihood_estimation.py +++ b/maximum_likelihood_estimation.py @@ -12,6 +12,7 @@ import os import glob +import json import numpy as np import matplotlib.pyplot as pl import pandas as pd @@ -84,11 +85,12 @@ def bin_spikes(spike_times, dT, wdw_start, wdw_end): colors = ('r', 'b', 'm', 'c') # Colors for each maze-type mazeSegList = ['Entire Maze', 'First Hallway', 'First Corner', 'Middle Hallway', 'Last Corner', 'Last Hallway'] -# Load data from this folder -hdf5Dir = '/home/fetterhoff/Graded_Remapping/' +with open("config.json") as f: + config = json.load(f) -# Create a results subfolder inside the data folder -combinedResultDir = hdf5Dir+'mle_results_{}gamma/'.format(gamma) # Save in subdirectory +# Load data from this folder +hdf5Dir = config['datasource'] +combinedResultDir = os.path.join(config['results'], 'mle_results_{}gamma/'.format(gamma)) # Save in subdirectory if not os.path.exists(combinedResultDir): os.makedirs(combinedResultDir) @@ -119,11 +121,11 @@ def bin_spikes(spike_times, dT, wdw_start, wdw_end): session = s[0] print(session) # current session - sd = hdf5Dir+session+'/' # session directory + sd = os.path.join(hdf5Dir, session) # session directory # Build a DataFrame using all tetrode (TT) files spikeDF = pd.DataFrame() - for mat_name in glob.glob(sd+'*TT*.mat'): + for mat_name in glob.glob(os.path.join(sd, '*TT*.mat')): # loop through all neuron files m = loadmat(mat_name) frame = pd.DataFrame([[m['file'][0], m['times'][0], m['vr_x'][0], m['vr_y'][0], m['real_cm'][0], m['speed_cms'][0], m['lap_num'][0], @@ -134,7 +136,7 @@ def bin_spikes(spike_times, dT, wdw_start, wdw_end): spikeDF = spikeDF.append(frame) spikeDF.sort_index(inplace=True) - f2 = sd+session+'_laps_traj.h5' + f2 = os.path.join(sd, session+'_laps_traj.h5') trajDF = pd.read_hdf(f2, 'trj') # DataFrame of times/places/speed for each lap in VR # LapsDF maze_type dictionary: {1:R, -1:L, 2: R*, -2: L*} lapsDF = pd.read_hdf(f2, 'lapsDF') @@ -363,7 +365,7 @@ def get_log_likelihood(z_source_dat, z_pattern_dat, Gamma): ax[0].set_yticklabels(mazeTypeList) ax[0].set_xticks([0, xlim0/20, xlim0/10]) - fig.savefig(combinedResultDir+'Fig3A_mle_timesteps_{}.pdf'.format(session), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + fig.savefig(os.path.join(combinedResultDir, 'Fig3A_mle_timesteps_{}.pdf'.format(session)), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close(fig) #%% MLE while excuding the same maze as pattern (ex = excluding same maze-type) @@ -427,7 +429,7 @@ def get_log_likelihood(z_source_dat, z_pattern_dat, Gamma): #%% Plot MLE over all sessions if toPlotAllSessions: - df_count.to_csv(combinedResultDir+'table_S1_place_cell_field_counts.csv') + df_count.to_csv(os.path.join(combinedResultDir, 'table_S1_place_cell_field_counts.csv')) # plot as percentages pctAll = [mle_sess.mean(axis=0), mle_sess_fh.mean(axis=0), mle_sess_fc.mean(axis=0), mle_sess_mh.mean(axis=0), mle_sess_lc.mean(axis=0), mle_sess_lh.mean(axis=0)] @@ -457,7 +459,7 @@ def get_log_likelihood(z_source_dat, z_pattern_dat, Gamma): pl.ylabel("Maximum Likelihood Estimate from Pattern Data", labelpad=1) pl.xlabel("Maximum Likelihood Estimate from Source Data", labelpad=0) - fig.savefig(combinedResultDir+'Fig3B_allSessions_withReal_mle_gamma{}.pdf'.format(gamma), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + fig.savefig(os.path.join(combinedResultDir,'Fig3B_allSessions_withReal_mle_gamma{}.pdf'.format(gamma)), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close(fig) #%% Plot MLE excluding same maze-type @@ -486,5 +488,5 @@ def get_log_likelihood(z_source_dat, z_pattern_dat, Gamma): pl.ylabel("Maximum Likelihood Estimate from Pattern Data", labelpad=1) pl.xlabel("Maximum Likelihood Estimate from Source Data", labelpad=0) - fig.savefig(combinedResultDir+'Fig3C_allSessions_noReal_mle_gamma{}.pdf'.format(gamma), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + fig.savefig(os.path.join(combinedResultDir, 'Fig3C_allSessions_noReal_mle_gamma{}.pdf'.format(gamma)), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close(fig) diff --git a/plot_place_cells.py b/plot_place_cells.py index 9713b34..fe2cf90 100644 --- a/plot_place_cells.py +++ b/plot_place_cells.py @@ -10,6 +10,7 @@ """ import os import glob +import json import numpy as np import matplotlib.pyplot as pl import pandas as pd @@ -40,10 +41,12 @@ fileList = fileList speedThresh = 5 # cm/s, to discard spikes during stillness -# Load data from this folder -hdf5Dir = '/home/fetterhoff/Graded_Remapping/' +with open("config.json") as f: + config = json.load(f) -combinedResultDir = hdf5Dir+'place_cells/' # Save in subdirectory +# Load data from this folder +hdf5Dir = config['datasource'] +combinedResultDir = os.path.join(config['results'], 'place_cells') # Save in subdirectory if not os.path.exists(combinedResultDir): os.makedirs(combinedResultDir) @@ -63,11 +66,11 @@ session = s[0] print(session) # current session - sd = hdf5Dir+session+'/' # session directory + sd = os.path.join(hdf5Dir, session) # session directory # Build a DataFrame using all tetrode (TT) files spikeDF = pd.DataFrame() - for mat_name in glob.glob(sd+'*TT*.mat'): + for mat_name in glob.glob(os.path.join(sd, '*TT*.mat')): # loop through all neuron files m = loadmat(mat_name) frame = pd.DataFrame([[m['file'][0], m['times'][0], m['vr_x'][0], m['vr_y'][0], m['real_cm'][0], m['speed_cms'][0], m['lap_num'][0], @@ -78,13 +81,13 @@ spikeDF = spikeDF.append(frame) spikeDF.sort_index(inplace=True) - f3 = sd+session+'_PCresultsDB.h5' + f3 = os.path.join(sd, session+'_PCresultsDB.h5') cellResultsDB = pd.read_hdf(f3, 'cellResultsDB') #%% Plot neurons as examples for q, cell_id in enumerate(spikeDF.T): sp = spikeDF.loc[cell_id] - title = combinedResultDir + session + '_' + sp.file[:-2] + title = os.path.join(combinedResultDir, session + '_' + sp.file[:-2]) session_list.append(session) maze_seg_code.append(sp.segment_types) if toPlotAllNeurons: @@ -202,7 +205,7 @@ box.x0, box.y0, box.y1 = 0.7, 0.26, 0.5 ax[5].set_position(box) -pl.savefig(combinedResultDir+'fig_1HI_pieChart.pdf', format='pdf', bbox_inches='tight', pad_inches=0.01) +pl.savefig(os.path.join(combinedResultDir, 'fig_1HI_pieChart.pdf'), format='pdf', bbox_inches='tight', pad_inches=0.01) pl.close() #%% Pie for each gerbil @@ -264,5 +267,5 @@ ax[5].legend(['RR*-dir', 'LL*-dir', 'RL*-im', 'LR*-im'], loc='upper right') ax[1].legend(labels, loc='upper left', bbox_to_anchor=(0.3, 0.83)) - pl.savefig(combinedResultDir+'fig_S3_pieChartByGerbil_{}.pdf'.format(gid), format='pdf', bbox_inches='tight', pad_inches=0.01) + pl.savefig(os.path.join(combinedResultDir, 'fig_S3_pieChartByGerbil_{}.pdf'.format(gid)), format='pdf', bbox_inches='tight', pad_inches=0.01) pl.close() diff --git a/pop_vec_analysis.py b/pop_vec_analysis.py index 5ba62f2..bf1f259 100644 --- a/pop_vec_analysis.py +++ b/pop_vec_analysis.py @@ -13,6 +13,7 @@ """ import os import glob +import json import itertools as it import numpy as np import matplotlib.pyplot as pl @@ -49,10 +50,12 @@ ['g2784_ss1'] ] -# Load data from this folder -hdf5Dir = '/home/fetterhoff/Graded_Remapping/' +with open("config.json") as f: + config = json.load(f) -combinedResultDir = hdf5Dir+'pop_vec_analysis/' # Save in subdirectory +# Load data from this folder +hdf5Dir = config['datasource'] +combinedResultDir = os.path.join(config['results'], 'pop_vec_analysis') # Save in subdirectory if not os.path.exists(combinedResultDir): os.makedirs(combinedResultDir) @@ -97,11 +100,11 @@ session = s[0] print(session) # current session - sd = hdf5Dir+session+'/' # session directory + sd = os.path.join(hdf5Dir, session) # session directory # Build a DataFrame using all tetrode (TT) files spikeDF = pd.DataFrame() - for mat_name in glob.glob(sd+'*TT*.mat'): + for mat_name in glob.glob(os.path.join(sd, '*TT*.mat')): # loop through all neuron files m = loadmat(mat_name) frame = pd.DataFrame([[m['file'][0], m['times'][0], m['vr_x'][0], m['vr_y'][0], m['real_cm'][0], m['speed_cms'][0], m['lap_num'][0], @@ -112,13 +115,13 @@ spikeDF = spikeDF.append(frame) spikeDF.sort_index(inplace=True) - f2 = sd+session+'_laps_traj.h5' + f2 = os.path.join(sd, session+'_laps_traj.h5') trajDF = pd.read_hdf(f2, 'trj') # DataFrame of times/places/speed for each lap in VR # LapsDF maze_type dictionary: {1:R, -1:L, 2: R*, -2: L*} lapsDF = pd.read_hdf(f2, 'lapsDF') lapsDB = np.array(lapsDF) # Keep values as matrix - f3 = sd+session+'_PCresultsDB.h5' + f3 = os.path.join(sd, session+'_PCresultsDB.h5') cellResultsDB = pd.read_hdf(f3, 'cellResultsDB') nPlaceFields = 0 # Count the number of place fields @@ -214,8 +217,8 @@ #%% Plot place field matrices sorted by maze R if not (simSwap or best6 or toExcludeImageCells): - - pop_dir = combinedResultDir + 'population_plots/' + + pop_dir = os.path.join(combinedResultDir, 'population_plots') if not os.path.exists(pop_dir): os.makedirs(pop_dir) @@ -241,7 +244,7 @@ axm3.set_xlabel('Track Position (cm)'); axm4.set_xlabel('Track Position (cm)') axm1.set_ylabel('Neuron #'); axm3.set_ylabel('Neuron #') - pl.savefig(pop_dir+'all_neural_pop_viridis_Rsort_{}.png'.format(session), format='png', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(pop_dir, 'all_neural_pop_viridis_Rsort_{}.png'.format(session)), format='png', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close() # Plot place field matrices sorted by maze L @@ -268,13 +271,13 @@ axm3.set_xlabel('Track Position (cm)'); axm4.set_xlabel('Track Position (cm)') axm1.set_ylabel('Neuron #'); axm3.set_ylabel('Neuron #') - pl.savefig(pop_dir+'all_neural_pop_viridis_Lsort_{}.png'.format(session), format='png', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(pop_dir, 'all_neural_pop_viridis_Lsort_{}.png'.format(session)), format='png', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close() #%% pop_vec correlation - all vs shuffled if not (simSwap or best6 or toExcludeImageCells): - df_count.to_csv(combinedResultDir+'table_S1_place_cell_counts_pop_vec.csv') + df_count.to_csv(os.path.join(combinedResultDir, 'table_S1_place_cell_counts_pop_vec.csv')) if (best6 or simSwap): fig, axx = pl.subplots(1, 2, figsize=(3.4, 1.4), sharey=True) @@ -402,13 +405,13 @@ axx[1].legend() if toExcludeImageCells: - pl.savefig(combinedResultDir+'fig_4B_pop_vec_correlation_noImageCells.pdf', format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_4B_pop_vec_correlation_noImageCells.pdf'), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) elif simSwap: - pl.savefig(combinedResultDir+'fig_S5A_pop_vec_correlation.pdf', format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_S5A_pop_vec_correlation.pdf'), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) elif best6: - pl.savefig(combinedResultDir+'fig_S5C_pop_vec_correlation.pdf', format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_S5C_pop_vec_correlation.pdf'), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) else: - pl.savefig(combinedResultDir+'fig_4A_pop_vec_correlation.pdf', format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_4A_pop_vec_correlation.pdf'), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close(fig) #%% pop_vec correlation - all vs shuffled for each gerbil @@ -472,7 +475,7 @@ aq[ai].fill_between([bd[0], bd[1]], -.2, 1, facecolor='k', alpha=0.2) aq[ai].fill_between([bd[2], bd[3]], -.2, 1, facecolor='k', alpha=0.2) - pl.savefig(combinedResultDir+'fig_S5E_pop_vec_correlation_g{}.pdf'.format(gid), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_S5E_pop_vec_correlation_g{}.pdf'.format(gid)), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close(fig) #%% Plot the matrix for the poulation vector correlation divided by maze segment @@ -527,7 +530,7 @@ cbar_ax.tick_params(labelsize=6) cbar_ax.set_ylabel("r", rotation=0, labelpad=-13) - pl.savefig(combinedResultDir+'fig_4C_population_vector_correlation_bySegment_v.pdf', format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_4C_population_vector_correlation_bySegment_v.pdf'), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close() #%% Plot the matrix for the poulation vector correlation divided by maze segment @@ -582,8 +585,8 @@ axw[i].grid(False) if simSwap: - pl.savefig(combinedResultDir+'fig_S5B_population_vector_correlation_bySegment_simSwap.pdf', format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_S5B_population_vector_correlation_bySegment_simSwap.pdf'), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close() if best6: - pl.savefig(combinedResultDir+'fig_S5D_population_vector_correlation_bySegment_best6.pdf', format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_S5D_population_vector_correlation_bySegment_best6.pdf'), format='pdf', dpi=300, bbox_inches='tight', pad_inches=0.05) pl.close() diff --git a/rate_remapping.py b/rate_remapping.py index 820fa9b..b3d1ab1 100644 --- a/rate_remapping.py +++ b/rate_remapping.py @@ -12,6 +12,7 @@ import os import glob +import json import itertools as it import numpy as np import matplotlib.pyplot as pl @@ -59,10 +60,12 @@ itmp.append(Nbins-1) iparts = [i+1 for i in itmp] -# Load data from this folder -hdf5Dir = '/home/fetterhoff/Graded_Remapping/' +with open("config.json") as f: + config = json.load(f) -combinedResultDir = hdf5Dir+'rate_remapping/' # Save in subdirectory +# Load data from this folder +hdf5Dir = config['datasource'] +combinedResultDir = os.path.join(config['results'], 'rate_remapping') # Save in subdirectory if not os.path.exists(combinedResultDir): os.makedirs(combinedResultDir) @@ -78,11 +81,11 @@ session = s[0] print(session) # current session - sd = hdf5Dir+session+'/' # session directory + sd = os.path.join(hdf5Dir, session) # session directory # Build a DataFrame using all tetrode (TT) files spikeDF = pd.DataFrame() - for mat_name in glob.glob(sd+'*TT*.mat'): + for mat_name in glob.glob(os.path.join(sd, '*TT*.mat')): # loop through all neuron files m = loadmat(mat_name) frame = pd.DataFrame([[m['file'][0], m['times'][0], m['vr_x'][0], m['vr_y'][0], m['real_cm'][0], m['speed_cms'][0], m['lap_num'][0], @@ -93,13 +96,13 @@ spikeDF = spikeDF.append(frame) spikeDF.sort_index(inplace=True) - f2 = sd+session+'_laps_traj.h5' + f2 = os.path.join(sd, session+'_laps_traj.h5') trajDF = pd.read_hdf(f2, 'trj') # DataFrame of times/places/speed for each lap in VR # LapsDF maze_type dictionary: {1:R, -1:L, 2: R*, -2: L*} lapsDF = pd.read_hdf(f2, 'lapsDF') lapsDB = np.array(lapsDF) # Keep values as matrix - f3 = sd+session+'_PCresultsDB.h5' + f3 = os.path.join(sd, session+'_PCresultsDB.h5') cellResultsDB = pd.read_hdf(f3, 'cellResultsDB') nPlaceFields = 0 # Count the number of place fields @@ -197,7 +200,7 @@ #%% Save to csv files if plotSummary: - df_count.to_csv(combinedResultDir+'table_S1_place_cell_field_counts.csv') + df_count.to_csv(os.path.join(combinedResultDir, 'table_S1_place_cell_field_counts.csv')) #%% Peak comparison data to assess rate remapping df_ci_rateRemapping = pd.DataFrame([]) @@ -274,7 +277,7 @@ def r_confidence_interval(r_, n_, alpha=0.05): ax[15].set_xlabel('L*', labelpad=0) df_ci_rateRemapping.to_csv(combinedResultDir+'table_S2_rate_remapping_single_peaks_CI.csv') - pl.savefig(combinedResultDir+'fig_2A_rate_remapping_single_peaks.pdf', format='pdf', bbox_inches='tight', pad_inches=0.05) + pl.savefig(os.path.join(combinedResultDir, 'fig_2A_rate_remapping_single_peaks.pdf'), format='pdf', bbox_inches='tight', pad_inches=0.05) pl.close() #%% Overlap summary figure @@ -437,6 +440,6 @@ def r_confidence_interval(r_, n_, alpha=0.05): ax[i].spines['bottom'].set_visible(False) ax[i].tick_params(axis=u'both', which=u'both', length=0) - df_overlap_stats.to_csv(combinedResultDir+'table_S3_overlap_KW_MWU_stats.csv') - pl.savefig(combinedResultDir+'fig_2BCD_rate_remap_overlap_summary_.pdf', format='pdf', bbox_inches='tight', pad_inches=0.05) + df_overlap_stats.to_csv(os.path.join(combinedResultDir, 'table_S3_overlap_KW_MWU_stats.csv')) + pl.savefig(os.path.join(combinedResultDir, 'fig_2BCD_rate_remap_overlap_summary_.pdf'), format='pdf', bbox_inches='tight', pad_inches=0.05) pl.close() diff --git a/trajectory_plots.py b/trajectory_plots.py index c83e7a2..d054eea 100644 --- a/trajectory_plots.py +++ b/trajectory_plots.py @@ -11,6 +11,7 @@ """ import os +import json import numpy as np import matplotlib.pyplot as pl import pandas as pd @@ -38,10 +39,12 @@ speedThresh = 5 # cm/s, to discard spikes during stillness -# Load data from this folder -hdf5Dir = '/home/fetterhoff/Graded_Remapping/' +with open("config.json") as f: + config = json.load(f) -combinedResultDir = hdf5Dir+'trajectory_plots/' # Save in subdirectory +# Load data from this folder +hdf5Dir = config['datasource'] +combinedResultDir = os.path.join(config['results'], 'trajectory_plots') # Save in subdirectory if not os.path.exists(combinedResultDir): os.makedirs(combinedResultDir) @@ -66,9 +69,9 @@ session = s[0] print(session) # current session - sd = hdf5Dir+session+'/' # session directory + sd = os.path.join(hdf5Dir, session) # session directory - f2 = sd+session+'_laps_traj.h5' + f2 = os.path.join(sd, session+'_laps_traj.h5') lapsDF = pd.read_hdf(f2, 'lapsDF') trajDF = pd.read_hdf(f2, 'trj') lapsDB = np.array(lapsDF) @@ -156,7 +159,7 @@ ax[3,1].legend(['First Hall','First Corner','Middle Hall','Last Corner','Last Hall']) - pl.savefig(combinedResultDir+'fig_S2A_lap_trajectories_{}.pdf'.format(session),format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.01) + pl.savefig(os.path.join(combinedResultDir, 'fig_S2A_lap_trajectories_{}.pdf'.format(session)),format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.01) pl.close() all_vr_y = np.append(all_vr_y, places_xy[1,:] * -1) @@ -206,7 +209,7 @@ ax[0].set_ylabel('PDF') pl.setp(ax, xticks=[-0.5,0.5], xticklabels=['Left','Right']) -pl.savefig(combinedResultDir+'fig_S2C_y_position_hist.pdf',format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.01) +pl.savefig(os.path.join(combinedResultDir, 'fig_S2C_y_position_hist.pdf'), format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.01) pl.close() #%% average speed by maze segment @@ -230,5 +233,5 @@ pl.xticks(np.arange(5), ('First Hall', 'First Corner', 'Middle Hall', 'Last Corner', 'Last Hall'),rotation=45) pl.ylabel('Average Speed (cm/s)') -pl.savefig(combinedResultDir+'fig_S2B_avg_speed_by_maze_segment.pdf',format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.05) +pl.savefig(os.path.join(combinedResultDir, 'fig_S2B_avg_speed_by_maze_segment.pdf'),format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.05) pl.close() diff --git a/waveform_stats.py b/waveform_stats.py index 63ef86c..b4de248 100644 --- a/waveform_stats.py +++ b/waveform_stats.py @@ -11,19 +11,22 @@ """ import os +import json import pandas as pd import numpy as np import matplotlib.pyplot as pl import seaborn as sns -# Load data from this folder -hdf5Dir = '/home/fetterhoff/Graded_Remapping/' +with open("config.json") as f: + config = json.load(f) -combinedResultDir = hdf5Dir+'waveform_stats/' # Save in subdirectory +# Load data from this folder +hdf5Dir = config['datasource'] +combinedResultDir = os.path.join(config['results'], 'waveform_stats') # Save in subdirectory if not os.path.exists(combinedResultDir): os.makedirs(combinedResultDir) -wavedf = pd.read_csv(hdf5Dir+'allwavecombined_final.csv') +wavedf = pd.read_csv(os.path.join(hdf5Dir, 'allwavecombined_final.csv')) wavedf['neuron_type'] = 0 fil=(wavedf.spike_ratio < 1.5) wavedf.loc[fil, 'neuron_type'] = 'INT' @@ -44,7 +47,7 @@ ajp.ax_joint.set_ylabel('Log of Mean Firing Rate (Hz)') ajp.ax_marg_x.axvline(1.5,color='C1',alpha=0.5) ajp.ax_joint.set_ylim(yl1, yl2) -ajp.savefig(combinedResultDir+'fig_S1C_mfr_spike_ratio.pdf',format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.05) +ajp.savefig(os.path.join(combinedResultDir, 'fig_S1C_mfr_spike_ratio.pdf'),format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.05) pl.close() perc_lost = (wavedf.spike_ratio > 10).sum() / float(len(wavedf)) *100 print('{}% of neurons not shown (SR > 10)'.format(perc_lost)) @@ -54,5 +57,5 @@ ax = sns.catplot(x='neuron_type', y='spike_width_ms', kind='boxen', data=wavedf, height=2.2) ax.set_ylabels('Spike Width (ms)') ax.set_xlabels('Neuron Type') -ax.savefig(combinedResultDir+'fig_S1D_spike_width.pdf',format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.05) +ax.savefig(os.path.join(combinedResultDir, 'fig_S1D_spike_width.pdf'),format='pdf', dpi=300, bbox_inches = 'tight', pad_inches = 0.05) pl.close()