3636
3737COCHLEAE_ALIAS = {
3838 "M_LR_000143_L" : "M0L" ,
39- "M_LR_000144_L" : "M1L " ,
40- "M_LR_000145_L" : "M2L " ,
41- "M_LR_000153_L" : "M3L " ,
42- "M_LR_000155_L" : "M4L " ,
43- "M_LR_000189_L" : "M5L " ,
39+ "M_LR_000144_L" : "M05L " ,
40+ "M_LR_000145_L" : "M06L " ,
41+ "M_LR_000153_L" : "M07L " ,
42+ "M_LR_000155_L" : "M08L " ,
43+ "M_LR_000189_L" : "M09L " ,
4444 "M_LR_000143_R" : "M0R" ,
45- "M_LR_000144_R" : "M1R " ,
46- "M_LR_000145_R" : "M2R " ,
47- "M_LR_000153_R" : "M3R " ,
48- "M_LR_000155_R" : "M4R " ,
49- "M_LR_000189_R" : "M5R " ,
45+ "M_LR_000144_R" : "M05R " ,
46+ "M_LR_000145_R" : "M06R " ,
47+ "M_LR_000153_R" : "M07R " ,
48+ "M_LR_000155_R" : "M08R " ,
49+ "M_LR_000189_R" : "M09R " ,
5050 "G_EK_000049_L" : "G1L" ,
5151 "G_EK_000049_R" : "G1R" ,
5252}
@@ -126,17 +126,20 @@ def group_lr(names_lr, values):
126126 return names , values_left , values_right
127127
128128
129- def fig_04c (chreef_data , save_path , plot = False , plot_by_side = False ):
129+ def fig_04c (chreef_data , save_path , plot = False , plot_by_side = False , use_alias = True ):
130130 """Box plot showing the SGN counts of ChReef treated cochleae compared to healthy ones.
131131 """
132132 # Previous version with hard-coded values.
133133 # cochlea = ["M_LR_000144_L", "M_LR_000145_L", "M_LR_000151_R"]
134134 # alias = ["c01", "c02", "c03"]
135135 # sgns = [7796, 6119, 9225]
136136
137- # TODO map the cochlea name to its alias
138- # alias = [name.replace("_", "").replace("0", "") for name in chreef_data.keys()]
139- alias = [COCHLEAE_ALIAS [k ] for k in chreef_data .keys ()]
137+ # TODO have central function for alias for all plots?
138+ if use_alias :
139+ alias = [COCHLEAE_ALIAS [k ] for k in chreef_data .keys ()]
140+ else :
141+ alias = [name .replace ("_" , "" ).replace ("0" , "" ) for name in chreef_data .keys ()]
142+
140143 sgns = [len (vals ) for vals in chreef_data .values ()]
141144
142145 if plot_by_side :
@@ -199,12 +202,13 @@ def fig_04c(chreef_data, save_path, plot=False, plot_by_side=False):
199202 plt .close ()
200203
201204
202- def fig_04d (chreef_data , save_path , plot = False , plot_by_side = False , intensity = False , gerbil = False ):
205+ def fig_04d (chreef_data , save_path , plot = False , plot_by_side = False , intensity = False , gerbil = False , use_alias = True ):
203206 """Transduction efficiency per cochlea.
204207 """
205- # TODO map the cochlea name to its alias
206- # alias = [name.replace("_", "").replace("0", "") for name in chreef_data.keys()]
207- alias = [COCHLEAE_ALIAS [k ] for k in chreef_data .keys ()]
208+ if use_alias :
209+ alias = [COCHLEAE_ALIAS [k ] for k in chreef_data .keys ()]
210+ else :
211+ alias = [name .replace ("_" , "" ).replace ("0" , "" ) for name in chreef_data .keys ()]
208212
209213 values = []
210214 for vals in chreef_data .values ():
@@ -265,13 +269,14 @@ def fig_04d(chreef_data, save_path, plot=False, plot_by_side=False, intensity=Fa
265269 plt .close ()
266270
267271
268- def fig_04e (chreef_data , save_path , plot , intensity = False , gerbil = False ):
272+ def fig_04e (chreef_data , save_path , plot , intensity = False , gerbil = False , use_alias = True ):
269273
270274 result = {"cochlea" : [], "octave_band" : [], "value" : []}
271275 for name , values in chreef_data .items ():
272- # TODO map name to alias
273- # alias = name.replace("_", "").replace("0", "")
274- alias = COCHLEAE_ALIAS [name ]
276+ if use_alias :
277+ alias = COCHLEAE_ALIAS [name ]
278+ else :
279+ alias = name .replace ("_" , "" ).replace ("0" , "" )
275280
276281 freq = values ["frequency[kHz]" ].values
277282 if intensity :
@@ -375,9 +380,11 @@ def fig_04e(chreef_data, save_path, plot, intensity=False, gerbil=False):
375380def main ():
376381 parser = argparse .ArgumentParser (description = "Generate plots for Fig 4 of the cochlea paper." )
377382 parser .add_argument ("--figure_dir" , "-f" , type = str , help = "Output directory for plots." , default = "./panels/fig4" )
383+ parser .add_argument ("--no_alias" , action = "store_true" )
378384 parser .add_argument ("--plot" , action = "store_true" )
379385 args = parser .parse_args ()
380386
387+ use_alias = not args .no_alias
381388 os .makedirs (args .figure_dir , exist_ok = True )
382389
383390 # Get the chreef data as a dictionary of cochlea name to measurements.
@@ -391,21 +398,30 @@ def main():
391398
392399 # C: The SGN count compared to reference values from literature and healthy
393400 # Maybe remove literature reference from plot?
394- fig_04c (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04c" ), plot = args .plot , plot_by_side = True )
401+ fig_04c (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04c" ),
402+ plot = args .plot , plot_by_side = True , use_alias = use_alias )
395403
396404 # D: The transduction efficiency. We also plot GFP intensities.
397- fig_04d (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04d_transduction" ), plot = args .plot , plot_by_side = True ) # noqa
398- fig_04d (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04d_intensity" ), plot = args .plot , plot_by_side = True , intensity = True ) # noqa
405+ fig_04d (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04d_transduction" ),
406+ plot = args .plot , plot_by_side = True , use_alias = use_alias )
407+ fig_04d (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04d_intensity" ),
408+ plot = args .plot , plot_by_side = True , intensity = True , use_alias = use_alias )
399409
400- fig_04e (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04e_transduction" ), plot = args .plot )
401- fig_04e (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04e_intensity" ), plot = args .plot , intensity = True )
410+ fig_04e (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04e_transduction" ),
411+ plot = args .plot , use_alias = use_alias )
412+ fig_04e (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04e_intensity" ),
413+ plot = args .plot , intensity = True , use_alias = use_alias )
402414
403415 chreef_data_gerbil = get_chreef_data (animal = "gerbil" )
404- fig_04d (chreef_data_gerbil , save_path = os .path .join (args .figure_dir , "fig_04d_gerbil_transduction" ), plot = args .plot , plot_by_side = True , gerbil = True ) # noqa
405- fig_04d (chreef_data_gerbil , save_path = os .path .join (args .figure_dir , "fig_04d_gerbil_intensity" ), plot = args .plot , plot_by_side = True , intensity = True ) # noqa
406-
407- fig_04e (chreef_data_gerbil , save_path = os .path .join (args .figure_dir , "fig_04e_gerbil_transduction" ), plot = args .plot , gerbil = True ) # noqa
408- fig_04e (chreef_data_gerbil , save_path = os .path .join (args .figure_dir , "fig_04e_gerbil_intensity" ), plot = args .plot , intensity = True ) # noqa
416+ fig_04d (chreef_data_gerbil , save_path = os .path .join (args .figure_dir , "fig_04d_gerbil_transduction" ),
417+ plot = args .plot , plot_by_side = True , gerbil = True , use_alias = use_alias )
418+ fig_04d (chreef_data_gerbil , save_path = os .path .join (args .figure_dir , "fig_04d_gerbil_intensity" ),
419+ plot = args .plot , plot_by_side = True , intensity = True , use_alias = use_alias )
420+
421+ fig_04e (chreef_data_gerbil , save_path = os .path .join (args .figure_dir , "fig_04e_gerbil_transduction" ),
422+ plot = args .plot , gerbil = True , use_alias = use_alias )
423+ fig_04e (chreef_data_gerbil , save_path = os .path .join (args .figure_dir , "fig_04e_gerbil_intensity" ),
424+ plot = args .plot , intensity = True , use_alias = use_alias )
409425
410426
411427if __name__ == "__main__" :
0 commit comments