@@ -594,11 +594,16 @@ def var_explained_by_experience(results_pivoted, run_params,threshold = 0):
594
594
plt .tick_params (axis = 'both' ,labelsize = 14 )
595
595
plt .tight_layout ()
596
596
if threshold != 0 :
597
- plt . savefig ( run_params ['figure_dir' ]+ '/variance_explained_by_experience_filtered.svg' )
597
+ filename = run_params ['figure_dir' ]+ '/variance_explained_by_experience_filtered.svg'
598
598
plt .savefig (run_params ['figure_dir' ]+ '/variance_explained_by_experience_filtered.png' )
599
+ print ('Figure saved to: ' + filename )
600
+ plt .savefig (filename )
599
601
else :
600
- plt . savefig ( run_params ['figure_dir' ]+ '/variance_explained_by_experience.svg' )
602
+ filename = run_params ['figure_dir' ]+ '/variance_explained_by_experience.svg'
601
603
plt .savefig (run_params ['figure_dir' ]+ '/variance_explained_by_experience.png' )
604
+ print ('Figure saved to: ' + filename )
605
+ plt .savefig (filename )
606
+ return results_pivoted .groupby (['cell_type' ,'experience_level' ])['variance_explained_percent' ].describe ()
602
607
603
608
def compare_var_explained_by_version (results = None , fig = None , ax = None , test_data = True , figsize = (9 ,5 ), use_violin = True ,cre = None ,metric = 'Full' ,show_equipment = True ,zoom_xlim = True ,sort_by_signal = True ):
604
609
'''
@@ -1850,13 +1855,19 @@ def plot_kernel_comparison_by_experience(weights_df, run_params, kernel,threshol
1850
1855
fig_f .savefig (run_params ['fig_kernels_dir' ]+ '/' + kernel + '_familiar_kernel' + extra + '.svg' )
1851
1856
fig_n .savefig (run_params ['fig_kernels_dir' ]+ '/' + kernel + '_novel1_kernel' + extra + '.svg' )
1852
1857
fig_np .savefig (run_params ['fig_kernels_dir' ]+ '/' + kernel + '_novelp1_kernel' + extra + '.svg' )
1858
+ print ('Figure saved to: ' + run_params ['fig_kernels_dir' ]+ '/' + kernel + '_familiar_kernel' + extra + '.svg' )
1859
+ print ('Figure saved to: ' + run_params ['fig_kernels_dir' ]+ '/' + kernel + '_novel1_kernel' + extra + '.svg' )
1860
+ print ('Figure saved to: ' + run_params ['fig_kernels_dir' ]+ '/' + kernel + '_novelp1_kernel' + extra + '.svg' )
1853
1861
1854
1862
k , fig_v , ax_v = plot_kernel_comparison (weights_df ,run_params ,kernel ,save_results = False ,session_filter = ['Familiar' ,'Novel 1' ,'Novel >1' ],cell_filter = 'Vip-IRES-Cre' ,compare = ['experience_level' ],threshold = threshold ,drop_threshold = drop_threshold )
1855
1863
k , fig_s , ax_s = plot_kernel_comparison (weights_df ,run_params ,kernel ,save_results = False ,session_filter = ['Familiar' ,'Novel 1' ,'Novel >1' ],cell_filter = 'Sst-IRES-Cre' ,compare = ['experience_level' ],threshold = threshold ,drop_threshold = drop_threshold )
1856
1864
k , fig_e , ax_e = plot_kernel_comparison (weights_df ,run_params ,kernel ,save_results = False ,session_filter = ['Familiar' ,'Novel 1' ,'Novel >1' ],cell_filter = 'Slc17a7-IRES2-Cre' ,compare = ['experience_level' ],threshold = threshold ,drop_threshold = drop_threshold )
1857
1865
fig_v .savefig (run_params ['fig_kernels_dir' ]+ '/' + kernel + '_vip_kernel' + extra + '.svg' )
1858
1866
fig_s .savefig (run_params ['fig_kernels_dir' ]+ '/' + kernel + '_sst_kernel' + extra + '.svg' )
1859
1867
fig_e .savefig (run_params ['fig_kernels_dir' ]+ '/' + kernel + '_exc_kernel' + extra + '.svg' )
1868
+ print ('Figure saved to: ' + run_params ['fig_kernels_dir' ]+ '/' + kernel + '_vip_kernel' + extra + '.svg' )
1869
+ print ('Figure saved to: ' + run_params ['fig_kernels_dir' ]+ '/' + kernel + '_sst_kernel' + extra + '.svg' )
1870
+ print ('Figure saved to: ' + run_params ['fig_kernels_dir' ]+ '/' + kernel + '_exc_kernel' + extra + '.svg' )
1860
1871
1861
1872
def plot_kernel_comparison_by_omission_excitation (weights_df , run_params ):
1862
1873
plot_kernel_comparison (weights_df ,run_params ,'omissions' ,session_filter = ['Familiar' ],cell_filter = 'Slc17a7-IRES2-Cre' ,compare = ['omissions_excited' ])
@@ -2884,6 +2895,7 @@ def plot_kernel_heatmap_with_dropout(vip_table, sst_table, slc_table, time_vec,k
2884
2895
#dax3.set_xticklabels(['Coding\n Score'],rotation=-70,fontsize=16)
2885
2896
filename = os .path .join (run_params ['fig_kernels_dir' ],kernel + '_heatmap_with_dropout' + extra + '.svg' )
2886
2897
plt .savefig (filename )
2898
+ print ('Figure saved to: ' + filename )
2887
2899
filename = os .path .join (run_params ['fig_kernels_dir' ],kernel + '_heatmap_with_dropout' + extra + '.png' )
2888
2900
plt .savefig (filename )
2889
2901
return zlims
@@ -3497,6 +3509,7 @@ def plot_population_averages_by_depth(results_pivoted, run_params, dropouts_to_s
3497
3509
experience_levels = np .sort (results_pivoted .experience_level .unique ())
3498
3510
colors = project_colors ()
3499
3511
3512
+ summary = {}
3500
3513
# Iterate cell types and make a plot for each
3501
3514
for cell_type in cell_types :
3502
3515
if len (dropouts_to_show ) == 3 :
@@ -3505,9 +3518,11 @@ def plot_population_averages_by_depth(results_pivoted, run_params, dropouts_to_s
3505
3518
fig , ax = plt .subplots (1 ,len (dropouts_to_show ),figsize = (10.8 ,4 ), sharey = sharey )
3506
3519
all_data = results_pivoted .query ('cell_type ==@cell_type' )
3507
3520
stats = {}
3521
+ summary [cell_type + ' data' ] = {}
3508
3522
# Iterate dropouts and plot each by experience
3509
3523
for index , feature in enumerate (dropouts_to_show ):
3510
3524
stats [feature ] = test_significant_dropout_averages_by_depth (all_data ,feature )
3525
+ summary [cell_type + ' data' ][feature ] = all_data .groupby (['experience_level' ,'coarse_binned_depth' ])[feature ].describe ()
3511
3526
# Plot all cells in active sessions
3512
3527
ax [index ] = sns .pointplot (
3513
3528
data = all_data ,
@@ -3560,10 +3575,12 @@ def plot_population_averages_by_depth(results_pivoted, run_params, dropouts_to_s
3560
3575
ax [0 ].set_ylabel ('Coding Score' ,fontsize = 20 )
3561
3576
plt .suptitle (cell_type + ', ' + area ,fontsize = 20 )
3562
3577
fig .tight_layout ()
3563
- plt . savefig ( run_params ['figure_dir' ]+ '/dropout_average_by_depth_' + cell_type [0 :3 ]+ extra + '.svg' )
3578
+ filename = run_params ['figure_dir' ]+ '/dropout_average_by_depth_' + cell_type [0 :3 ]+ extra + '.svg'
3564
3579
plt .savefig (run_params ['figure_dir' ]+ '/dropout_average_by_depth_' + cell_type [0 :3 ]+ extra + '.png' )
3565
-
3566
-
3580
+ print ('Figure saved to: ' + filename )
3581
+ plt .savefig (filename )
3582
+ summary [cell_type + ' stats' ] = stats
3583
+ return summary
3567
3584
3568
3585
def plot_population_averages_by_area (results_pivoted , run_params , dropouts_to_show = ['all-images' ,'omissions' ,'behavioral' ,'task' ],sharey = False ,include_zero_cells = True ,add_stats = True ,extra = '' ,equipment = "mesoscope" ):
3569
3586
'''
@@ -3609,7 +3626,7 @@ def plot_population_averages_by_area(results_pivoted, run_params, dropouts_to_sh
3609
3626
cell_types = results_pivoted .cell_type .unique ()
3610
3627
experience_levels = np .sort (results_pivoted .experience_level .unique ())
3611
3628
colors = project_colors ()
3612
-
3629
+ summary = {}
3613
3630
# Iterate cell types and make a plot for each
3614
3631
for cell_type in cell_types :
3615
3632
if len (dropouts_to_show ) == 3 :
@@ -3618,10 +3635,12 @@ def plot_population_averages_by_area(results_pivoted, run_params, dropouts_to_sh
3618
3635
fig , ax = plt .subplots (1 ,len (dropouts_to_show ),figsize = (10.8 ,4 ), sharey = sharey )
3619
3636
all_data = results_pivoted .query ('cell_type ==@cell_type' )
3620
3637
stats = {}
3638
+ summary [cell_type + ' data' ] = {}
3621
3639
# Iterate dropouts and plot each by experience
3622
3640
for index , feature in enumerate (dropouts_to_show ):
3623
3641
stats [feature ] = test_significant_dropout_averages_by_area (all_data ,feature )
3624
3642
# Plot all cells in active sessions
3643
+ summary [cell_type + ' data' ][feature ] = all_data .groupby (['experience_level' ,'targeted_structure' ])[feature ].describe ()
3625
3644
ax [index ] = sns .pointplot (
3626
3645
data = all_data ,
3627
3646
x = 'experience_level' ,
@@ -3672,9 +3691,12 @@ def plot_population_averages_by_area(results_pivoted, run_params, dropouts_to_sh
3672
3691
ax [0 ].set_ylabel ('Coding Score' ,fontsize = 20 )
3673
3692
plt .suptitle (cell_type ,fontsize = 20 )
3674
3693
fig .tight_layout ()
3675
- plt . savefig ( run_params ['figure_dir' ]+ '/dropout_average_by_area_' + cell_type [0 :3 ]+ extra + '.svg' )
3694
+ filename = run_params ['figure_dir' ]+ '/dropout_average_by_area_' + cell_type [0 :3 ]+ extra + '.svg'
3676
3695
plt .savefig (run_params ['figure_dir' ]+ '/dropout_average_by_area_' + cell_type [0 :3 ]+ extra + '.png' )
3677
-
3696
+ plt .savefig (filename )
3697
+ print ('Figure saved to: ' + filename )
3698
+ summary [cell_type + ' stats' ] = stats
3699
+ return summary
3678
3700
3679
3701
3680
3702
def plot_population_averages (results_pivoted , run_params , dropouts_to_show = ['all-images' ,'omissions' ,'behavioral' ,'task' ],sharey = True ,include_zero_cells = True ,boxplot = False ,add_stats = True ,extra = '' ,strict_experience_matching = False ,plot_by_cell_type = False ):
@@ -3755,7 +3777,9 @@ def plot_population_averages(results_pivoted, run_params, dropouts_to_show = ['a
3755
3777
ax [index ].tick_params (axis = 'y' ,labelsize = 16 )
3756
3778
ax [0 ].set_ylabel ('Coding Score' ,fontsize = 20 )
3757
3779
plt .tight_layout ()
3758
- plt .savefig (run_params ['figure_dir' ]+ '/dropout_average_combined' + extra + '.svg' )
3780
+ filename = run_params ['figure_dir' ]+ '/dropout_average_combined' + extra + '.svg'
3781
+ print ('Figure saved to: ' + filename )
3782
+ plt .savefig (filename )
3759
3783
#plt.savefig(run_params['figure_dir']+'/dropout_average_combined'+extra+'.png')
3760
3784
3761
3785
# Iterate cell types and make a plot for each
@@ -3862,11 +3886,14 @@ def plot_population_averages(results_pivoted, run_params, dropouts_to_show = ['a
3862
3886
ax [index ].set_ylim (0 ,ytop * 1.2 )
3863
3887
ax [0 ].set_ylabel ('Coding Score' ,fontsize = 18 )
3864
3888
plt .suptitle (cell_type ,fontsize = 18 )
3865
- fig .tight_layout ()
3866
- plt .savefig (run_params ['figure_dir' ]+ '/dropout_average_' + cell_type [0 :3 ]+ extra + '.svg' )
3889
+ fig .tight_layout ()
3890
+ filename = run_params ['figure_dir' ]+ '/dropout_average_' + cell_type [0 :3 ]+ extra + '.svg'
3891
+ plt .savefig (filename )
3892
+ print ('Figure saved to: ' + filename )
3867
3893
3868
3894
# Repeat the plots but transposed
3869
3895
# Iterate cell types and make a plot for each
3896
+ summary_data = {}
3870
3897
for index , feature in enumerate (dropouts_to_show ):
3871
3898
fig , ax = plt .subplots (1 ,4 ,figsize = (10.8 ,4 ), sharey = sharey )
3872
3899
@@ -3893,6 +3920,7 @@ def plot_population_averages(results_pivoted, run_params, dropouts_to_show = ['a
3893
3920
ax [3 ].spines ['top' ].set_visible (False )
3894
3921
ax [3 ].spines ['right' ].set_visible (False )
3895
3922
3923
+ summary_data [feature + ' data' ] = {}
3896
3924
stats = {}
3897
3925
# Iterate dropouts and plot each by experience
3898
3926
for cindex , cell_type in enumerate (cell_types ):
@@ -3902,6 +3930,8 @@ def plot_population_averages(results_pivoted, run_params, dropouts_to_show = ['a
3902
3930
strict_matched_data = all_data .query ('cell_specimen_id in @strict_matched_cells' )
3903
3931
anova , tukey = test_significant_dropout_averages (all_data ,feature )
3904
3932
stats [cell_type ]= (anova , tukey )
3933
+ summary_data [feature + ' data' ][cell_type + ' all data' ] = all_data .groupby (['experience_level' ])[feature ].describe ()
3934
+ summary_data [feature + ' data' ][cell_type + ' matched data' ] = matched_data .groupby (['experience_level' ])[feature ].describe ()
3905
3935
# Plot all cells in active sessions
3906
3936
if boxplot :
3907
3937
ax [cindex ] = sns .boxplot (
@@ -3945,6 +3975,7 @@ def plot_population_averages(results_pivoted, run_params, dropouts_to_show = ['a
3945
3975
3946
3976
if strict_experience_matching :
3947
3977
# Plot cells in matched active sessions
3978
+ summary_data [feature + ' data' ][cell_type + ' strict matched data' ] = strict_matched_data .groupby (['experience_level' ])[feature ].describe ()
3948
3979
ax [cindex ] = sns .pointplot (
3949
3980
data = strict_matched_data ,
3950
3981
x = 'experience_level' ,
@@ -4002,8 +4033,12 @@ def plot_population_averages(results_pivoted, run_params, dropouts_to_show = ['a
4002
4033
ax [2 ].set_ylim (bottom = 0 )
4003
4034
ax [3 ].set_ylim (bottom = 0 )
4004
4035
fig .tight_layout ()
4005
- plt .savefig (run_params ['figure_dir' ]+ '/dropout_average_' + clean_feature .replace (' ' ,'_' )+ extra + '.svg' )
4036
+ filename = run_params ['figure_dir' ]+ '/dropout_average_' + clean_feature .replace (' ' ,'_' )+ extra + '.svg'
4037
+ plt .savefig (filename )
4038
+ print ('Figure saved to: ' + filename )
4039
+ summary_data [feature + ' stats' ] = stats
4006
4040
4041
+ return summary_data
4007
4042
4008
4043
4009
4044
def test_significant_dropout_averages (data ,feature ):
@@ -4166,13 +4201,16 @@ def plot_dropout_individual_population(results, run_params,ax=None,palette=None,
4166
4201
if add_title :
4167
4202
plt .title (run_params ['version' ])
4168
4203
if use_violin :
4169
- plt . savefig ( run_params ['figure_dir' ]+ '/dropout_individual.svg' )
4204
+ filename = run_params ['figure_dir' ]+ '/dropout_individual.svg'
4170
4205
elif use_single :
4171
- plt . savefig ( run_params ['figure_dir' ]+ '/dropout_individual_boxplot_single.svg' )
4206
+ filename = run_params ['figure_dir' ]+ '/dropout_individual_boxplot_single.svg'
4172
4207
else :
4173
- plt . savefig ( run_params ['figure_dir' ]+ '/dropout_individual_boxplot.svg' )
4208
+ filename = run_params ['figure_dir' ]+ '/dropout_individual_boxplot.svg'
4174
4209
plt .savefig (run_params ['figure_dir' ]+ '/dropout_individual_boxplot.png' )
4175
4210
4211
+ plt .savefig (filename )
4212
+ print ('Figure saved to: ' + filename )
4213
+ return data_to_plot .groupby (['cre_line' ,'dropout' ])['explained_variance' ].describe ()
4176
4214
4177
4215
def plot_dropout_summary_population (results , run_params ,dropouts_to_show = ['all-images' ,'omissions' ,'behavioral' ,'task' ],ax = None ,palette = None ,use_violin = False ,add_median = True ,include_zero_cells = True ,add_title = False ):
4178
4216
'''
@@ -4281,8 +4319,11 @@ def plot_dropout_summary_population(results, run_params,dropouts_to_show = ['al
4281
4319
if use_violin :
4282
4320
plt .savefig (run_params ['figure_dir' ]+ '/dropout_summary.svg' )
4283
4321
else :
4284
- plt .savefig (run_params ['figure_dir' ]+ '/dropout_summary_boxplot.svg' )
4322
+ filename = run_params ['figure_dir' ]+ '/dropout_summary_boxplot.svg'
4323
+ print ('Figure saved to: ' + filename )
4324
+ plt .savefig (filename )
4285
4325
plt .savefig (run_params ['figure_dir' ]+ '/dropout_summary_boxplot.png' )
4326
+ return data_to_plot .groupby (['cre_line' ,'dropout' ])['explained_variance' ].describe ()
4286
4327
4287
4328
def plot_fraction_summary_population (results_pivoted , run_params ,sharey = True ,omissions_excitation = False ):
4288
4329
# compute coding fractions
@@ -4352,12 +4393,16 @@ def plot_fraction_summary_population(results_pivoted, run_params,sharey=True,omi
4352
4393
ax [0 ].set_ylabel ('Fraction of cells \n coding for ' ,fontsize = 20 )
4353
4394
plt .tight_layout ()
4354
4395
if omissions_excitation :
4355
- plt .savefig (run_params ['figure_dir' ]+ '/coding_fraction_omissions_summary.svg' )
4356
- plt .savefig (run_params ['figure_dir' ]+ '/coding_fraction_omissions_summary.png' )
4396
+ filename = run_params ['figure_dir' ]+ '/coding_fraction_omissions_summary.svg'
4397
+ plt .savefig (filename )
4398
+ plt .savefig (run_params ['figure_dir' ]+ '/coding_fraction_omissions_summary.png' )
4399
+ print ('Figure saved to: ' + filename )
4357
4400
else :
4358
- plt .savefig (run_params ['figure_dir' ]+ '/coding_fraction_summary.svg' )
4401
+ filename = run_params ['figure_dir' ]+ '/coding_fraction_summary.svg'
4402
+ plt .savefig (filename )
4359
4403
plt .savefig (run_params ['figure_dir' ]+ '/coding_fraction_summary.png' )
4360
-
4404
+ print ('Figure saved to: ' + filename )
4405
+ return summary_df
4361
4406
4362
4407
def make_cosyne_schematic (glm ,cell = 1028768972 ,t_range = 5 ,time_to_plot = 3291 ,alpha = .25 ):
4363
4408
'''
0 commit comments