2828COLOR_RIGHT = "#DB0063"
2929MARKER_LEFT = "o"
3030MARKER_RIGHT = "^"
31+ COLOR_MEASUREMENT = "#9C7427"
32+ COLOR_LITERATURE = "#27339C"
33+ COLOR_UNTREATED = "#DB7B00"
3134
3235
3336def get_otof_data ():
@@ -85,6 +88,7 @@ def _load_ribbon_synapse_counts():
8588 ihc_version = "ihc_counts_v6"
8689 synapse_dir = os .path .join (SYNAPSE_DIR_ROOT , ihc_version )
8790 tables = [entry .path for entry in os .scandir (synapse_dir ) if "ihc_count_G_" in entry .name ]
91+ print (f"Synapse count for tables { tables } ." )
8892 syn_counts = []
8993 for tab in tables :
9094 x = pd .read_csv (tab , sep = "\t " )
@@ -155,11 +159,13 @@ def _get_trendline_params(trend_dict):
155159 return x_values , y_values_center , y_values_upper , y_values_lower
156160
157161
158- def fig_06e_octave (otof_data , save_path , plot = False , use_alias = True , trendline = False ):
162+ def fig_06e_octave (otof_data , save_path , plot = False , use_alias = True , trendline_mode = None ):
159163 prism_style ()
160164 label_size = 20
165+ tick_label_size = 14
161166
162167 result = {"cochlea" : [], "octave_band" : [], "value" : []}
168+ expression_eff_dic = {}
163169 for name , values in otof_data .items ():
164170 if use_alias :
165171 alias = COCHLEAE_DICT [name ]["alias" ]
@@ -168,11 +174,16 @@ def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline=F
168174
169175 freq = values ["frequency[kHz]" ].values
170176 marker_labels = values ["expression_classification" ].values
177+ marker_pos = len ([1 for i in marker_labels if i == 1 ])
178+ marker_neg = len ([1 for i in marker_labels if i == 2 ])
179+ expression_eff = marker_pos / (marker_pos + marker_neg )
180+ print (f"Cochlea { name } , efficiency { expression_eff } " )
171181 octave_binned = frequency_mapping (freq , marker_labels , animal = "mouse" , transduction_efficiency = True )
172182
173183 result ["cochlea" ].extend ([alias ] * len (octave_binned ))
174184 result ["octave_band" ].extend (octave_binned .axes [0 ].values .tolist ())
175185 result ["value" ].extend (octave_binned .values .tolist ())
186+ expression_eff_dic [alias ] = expression_eff
176187
177188 result = pd .DataFrame (result )
178189 bin_labels = pd .unique (result ["octave_band" ])
@@ -195,15 +206,15 @@ def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline=F
195206
196207 # y_values.append(list(grp["value"]))
197208
198- if trendline :
209+ if trendline_mode == "filled" :
199210 sorted_idx = np .argsort (x_positions )
200211 x_sorted = np .array (x_positions )[sorted_idx ]
201212 y_sorted = np .array (grp ["value" ])[sorted_idx ]
202213 trend_dict [name ] = {"x_sorted" : x_sorted ,
203214 "y_sorted" : y_sorted ,
204215 }
205216 # central line
206- if trendline :
217+ if trendline_mode == "filled" :
207218 #mean, std = _get_trendline_params(y_values)
208219 x_sorted , y_sorted , y_sorted_upper , y_sorted_lower = _get_trendline_params (trend_dict )
209220 trend_center , = ax .plot (
@@ -237,6 +248,26 @@ def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline=F
237248 plt .fill_between (x_sorted , y_sorted_lower , y_sorted_upper ,
238249 color = "gray" , alpha = 0.05 , interpolate = True )
239250
251+ elif trendline_mode == "mean" :
252+ xlim_left , xlim_right = ax .get_xlim ()
253+ y_offset = [0.01 , - 0.04 ]
254+ x_offset = 0.5
255+ plt .xlim (xlim_left , xlim_right )
256+ for num , key in enumerate (colors .keys ()):
257+ color = colors [key ]
258+ expression_eff = expression_eff_dic [key ]
259+
260+ ax .text (xlim_left + x_offset , expression_eff + y_offset [num ], "mean" ,
261+ color = color , fontsize = tick_label_size , ha = "center" )
262+ trend_r , = ax .plot (
263+ [xlim_left , xlim_right ],
264+ [expression_eff , expression_eff ],
265+ linestyle = "dashed" ,
266+ color = color ,
267+ alpha = 0.7 ,
268+ zorder = 0
269+ )
270+
240271 ax .set_xticks (range (len (bin_labels )))
241272 ax .set_xticklabels (bin_labels )
242273 ax .set_xlabel ("Octave band [kHz]" , fontsize = label_size )
@@ -267,15 +298,16 @@ def fig_06b(save_path, plot=False):
267298 rows = 1
268299 columns = 3
269300
270- fig , ax = plt .subplots (rows , columns , figsize = (columns * 3 , rows * 4 ))
301+ fig , ax = plt .subplots (rows , columns , figsize = (8.5 , 4.5 ))
271302
272303 sgn_values = [18541 ]
273304 ihc_values = [1180 ]
274305
275- ax [0 ].boxplot ( sgn_values )
276- ax [1 ].boxplot ( ihc_values )
306+ ax [0 ].scatter ([ 1 ], sgn_values , color = COLOR_MEASUREMENT , marker = "x" , s = 100 )
307+ ax [1 ].scatter ([ 1 ], ihc_values , color = COLOR_MEASUREMENT , marker = "x" , s = 100 )
277308
278309 # Labels and formatting
310+ ax [0 ].set_xticks ([1 ])
279311 ax [0 ].set_xticklabels (["SGN" ], fontsize = main_label_size )
280312
281313 ylim0 = 14000
@@ -293,15 +325,16 @@ def fig_06b(save_path, plot=False):
293325 xmax = 1.5
294326 ax [0 ].set_xlim (xmin , xmax )
295327 lower_y , upper_y = literature_reference_values_gerbil ("SGN" )
296- ax [0 ].hlines ([lower_y , upper_y ], xmin , xmax )
297- ax [0 ].text (1 , upper_y - 2000 , "literature" , color = 'C0' , fontsize = main_tick_size , ha = "center" )
298- ax [0 ].fill_between ([xmin , xmax ], lower_y , upper_y , color = 'C0' , alpha = 0.05 , interpolate = True )
328+ ax [0 ].hlines ([lower_y , upper_y ], xmin , xmax , color = COLOR_LITERATURE )
329+ ax [0 ].text (1 , upper_y - 2000 , "literature" , color = COLOR_LITERATURE , fontsize = main_tick_size , ha = "center" )
330+ ax [0 ].fill_between ([xmin , xmax ], lower_y , upper_y , color = COLOR_LITERATURE , alpha = 0.05 , interpolate = True )
299331
300332 ylim0 = 900
301333 ylim1 = 1400
302334 ytick_gap = 200
303335 y_ticks = [i for i in range ((((ylim0 - 1 ) // ytick_gap ) + 1 ) * ytick_gap , ylim1 + 1 , ytick_gap )]
304336
337+ ax [1 ].set_xticks ([1 ])
305338 ax [1 ].set_xticklabels (["IHC" ], fontsize = main_label_size )
306339
307340 ax [1 ].set_yticks (y_ticks )
@@ -313,16 +346,21 @@ def fig_06b(save_path, plot=False):
313346 xmax = 1.5
314347 ax [1 ].set_xlim (xmin , xmax )
315348 lower_y , upper_y = literature_reference_values_gerbil ("IHC" )
316- ax [1 ].hlines ([lower_y , upper_y ], xmin , xmax )
317- ax [1 ].fill_between ([xmin , xmax ], lower_y , upper_y , color = 'C0' , alpha = 0.05 , interpolate = True )
349+ ax [1 ].hlines ([lower_y , upper_y ], xmin , xmax , color = COLOR_LITERATURE )
350+ ax [1 ].fill_between ([xmin , xmax ], lower_y , upper_y , color = COLOR_LITERATURE , alpha = 0.05 , interpolate = True )
318351
319352 ribbon_synapse_counts = _load_ribbon_synapse_counts ()
320353 ylim0 = - 1
321354 ylim1 = 80
322355 ytick_gap = 20
323356 y_ticks = [i for i in range ((((ylim0 - 1 ) // ytick_gap ) + 1 ) * ytick_gap , ylim1 + 1 , ytick_gap )]
324357
325- ax [2 ].boxplot (ribbon_synapse_counts )
358+ box_plot = ax [2 ].boxplot (ribbon_synapse_counts , patch_artist = True )
359+ for median in box_plot ['medians' ]:
360+ median .set_color (COLOR_MEASUREMENT )
361+ for boxcolor in box_plot ['boxes' ]:
362+ boxcolor .set_facecolor ("white" )
363+
326364 ax [2 ].set_xticklabels (["Synapses per IHC" ], fontsize = main_label_size )
327365 ax [2 ].set_yticks (y_ticks )
328366 ax [2 ].set_yticklabels (y_ticks , rotation = 0 , fontsize = main_tick_size )
@@ -333,8 +371,8 @@ def fig_06b(save_path, plot=False):
333371 xmax = 1.5
334372 lower_y , upper_y = literature_reference_values_gerbil ("synapse" )
335373 ax [2 ].set_xlim (xmin , xmax )
336- ax [2 ].hlines ([lower_y , upper_y ], xmin , xmax )
337- ax [2 ].fill_between ([xmin , xmax ], lower_y , upper_y , color = "C0" , alpha = 0.05 , interpolate = True )
374+ ax [2 ].hlines ([lower_y , upper_y ], xmin , xmax , color = COLOR_LITERATURE )
375+ ax [2 ].fill_between ([xmin , xmax ], lower_y , upper_y , color = COLOR_LITERATURE , alpha = 0.05 , interpolate = True )
338376
339377 plt .tight_layout ()
340378 prism_cleanup_axes (ax )
@@ -349,6 +387,86 @@ def fig_06b(save_path, plot=False):
349387 plt .close ()
350388
351389
390+ def fig_06c (save_path , plot = False ):
391+ """Box plot showing the SGN counts of ChReef treated cochleae compared to healthy ones.
392+ """
393+ prism_style ()
394+ values_left = [11351 ]
395+ values_right = [21995 ]
396+
397+ # Plot
398+ fig , ax = plt .subplots (figsize = (4 , 5 ))
399+
400+ main_label_size = 20
401+ sub_label_size = 16
402+ main_tick_size = 16
403+
404+ offset = 0.08
405+ x_left = 1
406+ x_right = 2
407+
408+ x_pos_inj = [x_left - len (values_left ) // 2 * offset + offset * i for i in range (len (values_left ))]
409+ x_pos_non = [x_right - len (values_right ) // 2 * offset + offset * i for i in range (len (values_right ))]
410+
411+ # lines between cochleae of same animal
412+ for num , (left , right ) in enumerate (zip (values_left , values_right )):
413+ ax .plot (
414+ [x_pos_inj [num ], x_pos_non [num ]],
415+ [left , right ],
416+ linestyle = "solid" ,
417+ color = "grey" ,
418+ alpha = 0.4 ,
419+ zorder = 0
420+ )
421+ plt .scatter (x_pos_inj , values_left , label = "Injected" ,
422+ color = COLOR_LEFT , marker = MARKER_LEFT , s = 80 , zorder = 1 )
423+ plt .scatter (x_pos_non , values_right , label = "Non-Injected" ,
424+ color = COLOR_RIGHT , marker = MARKER_RIGHT , s = 80 , zorder = 1 )
425+
426+ # Labels and formatting
427+ plt .xticks ([x_left , x_right ], ["Injected" , "Non-\n Injected" ], fontsize = sub_label_size )
428+ for label in plt .gca ().get_xticklabels ():
429+ label .set_verticalalignment ('center' )
430+ ax .tick_params (axis = 'x' , which = 'major' , pad = 16 )
431+
432+ plt .ylim (10000 , 24000 )
433+ y_ticks = [i for i in range (10000 , 24000 , 4000 )]
434+
435+ plt .yticks (y_ticks , fontsize = main_tick_size )
436+ plt .ylabel ("SGN count per cochlea" , fontsize = main_label_size )
437+ xmin = 0.5
438+ xmax = 2.5
439+ plt .xlim (xmin , xmax )
440+
441+ sgn_values = [18541 ] # G_EK_000233_L
442+ sgn_value = np .mean (sgn_values )
443+ sgn_std = np .std (sgn_values )
444+
445+ upper_y = sgn_value + 1.96 * sgn_std
446+ lower_y = sgn_value - 1.96 * sgn_std
447+
448+ c_untreated = COLOR_UNTREATED
449+
450+ plt .hlines ([lower_y , upper_y ], xmin , xmax , colors = [c_untreated for _ in range (2 )], zorder = - 1 )
451+ plt .text ((xmin + xmax ) / 2 , upper_y + 200 , "untreated cochleae\n (95% confidence interval)" ,
452+ color = c_untreated , fontsize = 11 , ha = "center" )
453+ plt .fill_between ([xmin , xmax ], lower_y , upper_y , color = c_untreated , alpha = 0.05 , interpolate = True )
454+
455+ plt .tight_layout ()
456+
457+ prism_cleanup_axes (ax )
458+
459+ if ".png" in save_path :
460+ plt .savefig (save_path , bbox_inches = "tight" , pad_inches = 0.1 , dpi = png_dpi )
461+ else :
462+ plt .savefig (save_path , bbox_inches = 'tight' , pad_inches = 0 )
463+
464+ if plot :
465+ plt .show ()
466+ else :
467+ plt .close ()
468+
469+
352470def fig_06d (save_path , plot = False ):
353471 """Plot the synapse distribution measured with different markers.
354472
@@ -373,10 +491,11 @@ def main():
373491 otof_data = get_otof_data ()
374492 plot_legend_fig06e (args .figure_dir )
375493 fig_06e_octave (otof_data , save_path = os .path .join (args .figure_dir , f"fig_06e.{ FILE_EXTENSION } " ), plot = plot ,
376- trendline = False , gr )
494+ trendline_mode = "mean" )
377495
378496 fig_06b (save_path = os .path .join (args .figure_dir , f"fig_06b.{ FILE_EXTENSION } " ), plot = plot )
379- fig_06d (save_path = os .path .join (args .figure_dir , f"fig_06d.{ FILE_EXTENSION } " ), plot = plot )
497+ fig_06c (save_path = os .path .join (args .figure_dir , f"fig_06c.{ FILE_EXTENSION } " ), plot = plot )
498+ # fig_06d(save_path=os.path.join(args.figure_dir, f"fig_06d.{FILE_EXTENSION}"), plot=plot)
380499
381500
382501if __name__ == "__main__" :
0 commit comments