@@ -107,7 +107,7 @@ def frequency_mapping2(frequencies, values, animal="mouse", transduction_efficie
107107}
108108
109109GROUPINGS = {
110- "Type Ia;Type Ib;Type Ic;Type II" : ["M_LR_000098_L" , "M_LR_N98_R" , "M_LR_N152_L" ],
110+ "Type Ia;Type Ib;Type Ic;Type II" : ["M_LR_000098_L" , "M_LR_N152_L" ], # "M_LR_N98_R"
111111 # , "M_AMD_N180_L", "M_AMD_N180_R"
112112 "Type I;Type II" : ["M_LR_000184_L" , "M_LR_000184_R" , "M_LR_000260_L" ],
113113 "Type Ib;Type Ic;inconclusive" : ["M_LR_N110_L" , "M_LR_N110_R" , "M_LR_N152_R" ],
@@ -260,8 +260,24 @@ def fig_03a(save_path, plot, plot_napari, cmap="viridis", dark_mode=False):
260260 napari .run ()
261261
262262
263- def fig_03c_length_fraction (tonotopic_data , save_path , use_alias = True , plot = False , n_bins = 10 ):
263+ def fig_03c_length_fraction (tonotopic_data , save_path , use_alias = True ,
264+ plot = False , n_bins = 10 , top_axis = False , trendline = False , trendline_std = False ,
265+ errorbar = True ):
264266 ihc_version = "ihc_counts_v4c"
267+ if trendline_std :
268+ line_alphas = {
269+ "center" : 0.6 ,
270+ "upper" : 0.08 ,
271+ "lower" : 0.08 ,
272+ "fill" : 0.05 ,
273+ }
274+ else :
275+ line_alphas = {
276+ "center" : 1 ,
277+ "upper" : 0. ,
278+ "lower" : 0. ,
279+ "fill" : 0. ,
280+ }
265281 main_label_size = 24
266282 tick_size = 16
267283 prism_style ()
@@ -321,22 +337,102 @@ def fig_03c_length_fraction(tonotopic_data, save_path, use_alias=True, plot=Fals
321337 fig , ax = plt .subplots (figsize = (6.7 , 5 ))
322338
323339 for num , (name , grp ) in enumerate (result .groupby ("cochlea" )):
324- run_length = grp ["runlength" ]
325- syn_count_running = grp ["value" ]
340+ run_length = list (grp ["runlength" ])
341+ syn_count = list (grp ["value" ])
342+ # print(run_length.shape)
343+ # print(syn_count.shape)
344+ run_length = [r for num , r in enumerate (run_length ) if not np .isnan (syn_count [num ])]
345+ syn_count = [s for s in syn_count if not np .isnan (s )]
326346 if name == "Meyer" :
327- ax .scatter (run_length , syn_count_running , label = name , facecolor = 'none' ,
328- edgecolors = color_dict [name ], marker = marker_dict [name ])
347+ ax .plot (run_length , syn_count , label = name ,
348+ markeredgecolor = color_dict [name ],
349+ color = color_dict [name ], marker = 's' , linestyle = 'solid' , linewidth = 2 )
329350 else :
330- ax .scatter (run_length , syn_count_running , label = name ,
351+ ax .scatter (run_length , syn_count , label = name ,
331352 color = color_dict [name ], marker = marker_dict [name ])
332353
354+ # calculate mean and standard deviation
355+ trend_dict = {}
356+ for num , (name , grp ) in enumerate (result .groupby ("cochlea" )):
357+ if name == "Meyer" :
358+ continue
359+ run_length = list (grp ["runlength" ])
360+ syn_count = list (grp ["value" ])
361+ for r , s in zip (run_length , syn_count ):
362+ if r in trend_dict :
363+ trend_dict [r ].append (s )
364+ else :
365+ trend_dict [r ] = [s ]
366+
367+ x_pos = [k for k in list (trend_dict .keys ())]
368+ center_line = [sum (val ) / len (val ) for _ , val in trend_dict .items ()]
369+ val_std = [np .std (val ) for _ , val in trend_dict .items ()]
370+ lower_std = [mean - std for (mean , std ) in zip (center_line , val_std )]
371+ upper_std = [mean + std for (mean , std ) in zip (center_line , val_std )]
372+
373+ if errorbar :
374+ ax .errorbar (x_pos , center_line , val_std , linestyle = 'dashed' , marker = 'D' , color = "#D63637" , linewidth = 1 )
375+
376+ if trendline :
377+ trend_center , = ax .plot (
378+ x_pos ,
379+ center_line ,
380+ linestyle = "dashed" ,
381+ color = "gray" ,
382+ alpha = line_alphas ["center" ],
383+ linewidth = 3 ,
384+ zorder = 2
385+ )
386+ trend_upper , = ax .plot (
387+ x_pos ,
388+ upper_std ,
389+ linestyle = "solid" ,
390+ color = "gray" ,
391+ alpha = line_alphas ["upper" ],
392+ zorder = 0
393+ )
394+ trend_lower , = ax .plot (
395+ x_pos ,
396+ lower_std ,
397+ linestyle = "solid" ,
398+ color = "gray" ,
399+ alpha = line_alphas ["lower" ],
400+ zorder = 0
401+ )
402+ plt .fill_between (x_pos , lower_std , upper_std ,
403+ color = "gray" , alpha = line_alphas ["fill" ], interpolate = True )
404+
405+ if top_axis :
406+ # Create second x-axis
407+ ax_top = ax .twiny ()
408+
409+ # Frequencies for ticks (kHz → convert to kHz or Hz depending on preference)
410+ freq_ticks = np .array ([2 , 4 , 8 , 16 , 32 , 64 ]) # kHz
411+
412+ # Given constants
413+ var_A = 1.46
414+ var_a = 1.77
415+
416+ # Inverse mapping length_fraction = log10(f/A) / a
417+ length_positions = np .log10 (freq_ticks / var_A ) / var_a
418+
419+ # Set ticks on top axis
420+ ax_top .set_xticks (length_positions )
421+ ax_top .set_xticklabels ([f"{ f } " for f in freq_ticks ], fontsize = tick_size )
422+
423+ # Label for the new axis
424+ ax_top .set_xlabel ("Frequency [kHz]" , fontsize = main_label_size )
425+
426+ # Ensure both axes align well
427+ ax_top .set_xlim (ax .get_xlim ())
428+
333429 ax .tick_params (axis = 'x' , labelsize = tick_size )
334430 ax .tick_params (axis = 'y' , labelsize = tick_size )
335431 ax .set_xlabel ("Length fraction" , fontsize = main_label_size )
336432 ax .set_ylabel ("Synapse per IHC" , fontsize = main_label_size )
337433 # ax.legend(title="cochlea")
338434 plt .tight_layout ()
339- prism_cleanup_axes (ax )
435+ # prism_cleanup_axes(ax)
340436
341437 if ".png" in save_path :
342438 plt .savefig (save_path , bbox_inches = "tight" , pad_inches = 0.1 , dpi = png_dpi )
@@ -428,18 +524,20 @@ def plot_legend_suppfig03(save_path, ncol=None):
428524 marker = ["o" for _ in color_dict ]
429525 label = list (color_dict .keys ())
430526
527+ # color_dict["mean"] = "#D63637"
528+ # marker.append("D")
529+ # label.append("Mean")
530+
431531 # add parameters for data from Meyer
432- edgecolors = [None for _ in color_dict ]
433532 color_dict ["Meyer" ] = MEYER_COLOR
434533 marker .append (MEYER_MARKER )
435534 label .append ("Meyer et al." )
436- edgecolors .append (MEYER_COLOR )
437535
438536 color = [color_dict [key ] for key in color_dict .keys ()]
439537 if ncol is None :
440- ncol = 2
538+ ncol = len ( label // 2 )
441539
442- handles = [get_marker_handle (c , m , e ) for (c , m , e ) in zip (color , marker , edgecolors )]
540+ handles = [get_marker_handle (c , m ) for (c , m ) in zip (color , marker )]
443541 legend = plt .legend (handles , label , loc = 3 , ncol = ncol , framealpha = 1 , frameon = False )
444542 export_legend (legend , save_path )
445543 legend .remove ()
@@ -679,7 +777,7 @@ def plot_average_tonotopic_mapping(results, save_path, plot=False, combine_IbIc=
679777 ax .set_xticklabels (bin_labels )
680778 ax .tick_params (axis = 'x' , labelsize = xtick_size )
681779 ax .tick_params (axis = 'y' , labelsize = main_tick_size )
682- ax .set_xlabel ("Octave band ( kHz) " , fontsize = main_label_size )
780+ ax .set_xlabel ("Octave band [ kHz] " , fontsize = main_label_size )
683781 ax .set_ylabel ("Fraction" , fontsize = main_label_size )
684782 ax .yaxis .set_major_formatter (mticker .FuncFormatter (custom_formatter_1 ))
685783 plt .grid (axis = "y" , linestyle = "solid" , alpha = 0.5 )
@@ -985,7 +1083,21 @@ def main():
9851083 fig_03c_length_fraction (tonotopic_data = tonotopic_data ,
9861084 save_path = os .path .join (args .figure_dir , f"figsupp_03_meyer.{ FILE_EXTENSION } " ),
9871085 plot = args .plot , n_bins = 25 )
988- plot_legend_suppfig03 (save_path = os .path .join (args .figure_dir , f"figsupp_03_meyer_legend.{ FILE_EXTENSION } " ), ncol = 1 )
1086+ # fig_03c_length_fraction(tonotopic_data=tonotopic_data,
1087+ # save_path=os.path.join(args.figure_dir, f"figsupp_03_meyer_freq.{FILE_EXTENSION}"),
1088+ # plot=args.plot, n_bins=25, top_axis=True)
1089+ # fig_03c_length_fraction(tonotopic_data=tonotopic_data,
1090+ # save_path=os.path.join(args.figure_dir, f"figsupp_03_meyer_freq_trend.{FILE_EXTENSION}"),
1091+ # plot=args.plot, n_bins=25, top_axis=True, trendline=True, trendline_std=False)
1092+ # fig_03c_length_fraction(tonotopic_data=tonotopic_data,
1093+ # save_path=os.path.join(args.figure_dir, f"figsupp_03_meyer_freq_std.{FILE_EXTENSION}"),
1094+ # plot=args.plot, n_bins=25, top_axis=True, trendline=True, trendline_std=True)
1095+ fig_03c_length_fraction (tonotopic_data = tonotopic_data ,
1096+ save_path = os .path .join (args .figure_dir , f"figsupp_03_meyer_errorbar.{ FILE_EXTENSION } " ),
1097+ plot = args .plot , n_bins = 25 , top_axis = True , errorbar = True )
1098+ # plot_legend_suppfig03(save_path=os.path.join(args.figure_dir, f"figsupp_03_meyer_lgnd1.{FILE_EXTENSION}"), ncol=1)
1099+ # plot_legend_suppfig03(save_path=os.path.join(args.figure_dir, f"figsupp_03_meyer_lgnd6.{FILE_EXTENSION}"), ncol=6)
1100+ plot_legend_suppfig03 (save_path = os .path .join (args .figure_dir , f"figsupp_03_meyer_lgnd3.{ FILE_EXTENSION } " ), ncol = 3 )
9891101
9901102 # Panel C: Spatial distribution of synapses across the cochlea (running sum per octave band)
9911103 fig_03c_octave (tonotopic_data = tonotopic_data ,
@@ -1007,7 +1119,7 @@ def main():
10071119
10081120 grouping = "Type I;Type II"
10091121 plot_legend_subtypes (save_path = os .path .join (args .figure_dir , f"fig_03_legend_I-II.{ FILE_EXTENSION } " ),
1010- grouping = grouping , ncol = 1 )
1122+ grouping = grouping )
10111123 fig_03_subtype_tonotopic (save_path = os .path .join (args .figure_dir , f"figsupp_03_tonotopic_I-II.{ FILE_EXTENSION } " ),
10121124 grouping = grouping )
10131125 fig_03_subtype_fraction (save_path = os .path .join (args .figure_dir , f"fig_03d_fraction_I-II.{ FILE_EXTENSION } " ),
0 commit comments