88import pandas as pd
99from flamingo_tools .s3_utils import BUCKET_NAME , create_s3_target
1010
11- from util import frequency_mapping , literature_reference_values
11+ from util import frequency_mapping # , literature_reference_values
1212
13- INTENSITY_ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/mobie_project/cochlea-lightsheet/tables/measurements " # noqa
13+ INTENSITY_ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/mobie_project/cochlea-lightsheet/tables/measurements2 " # noqa
1414
1515# The cochlea for the CHReef analysis.
1616COCHLEAE = [
2828 "M_LR_000189_R" ,
2929]
3030
31+ COCHLEAE_GERBIL = [
32+ "G_EK_000049_L" ,
33+ "G_EK_000049_R" ,
34+ ]
35+
36+
37+ COCHLEAE_ALIAS = {
38+ "M_LR_000143_L" : "M0L" ,
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" ,
44+ "M_LR_000143_R" : "M0R" ,
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" ,
50+ "G_EK_000049_L" : "G1L" ,
51+ "G_EK_000049_R" : "G1R" ,
52+ }
53+
3154png_dpi = 300
3255
3356
34- def get_chreef_data ():
57+ def get_chreef_data (animal = "mouse" ):
3558 s3 = create_s3_target ()
3659 source_name = "SGN_v2"
3760
38- cache_path = "./chreef_data.pkl"
61+ if animal == "mouse" :
62+ cache_path = "./chreef_data.pkl"
63+ cochleae = COCHLEAE
64+ else :
65+ cache_path = "./chreef_data_gerbil.pkl"
66+ cochleae = COCHLEAE_GERBIL
67+
3968 if os .path .exists (cache_path ):
4069 with open (cache_path , "rb" ) as f :
4170 return pickle .load (f )
4271
4372 chreef_data = {}
44- for cochlea in COCHLEAE :
73+ for cochlea in cochleae :
4574 print ("Processsing cochlea:" , cochlea )
4675 content = s3 .open (f"{ BUCKET_NAME } /{ cochlea } /dataset.json" , mode = "r" , encoding = "utf-8" )
4776 info = json .loads (content .read ())
@@ -97,16 +126,20 @@ def group_lr(names_lr, values):
97126 return names , values_left , values_right
98127
99128
100- 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 ):
101130 """Box plot showing the SGN counts of ChReef treated cochleae compared to healthy ones.
102131 """
103132 # Previous version with hard-coded values.
104133 # cochlea = ["M_LR_000144_L", "M_LR_000145_L", "M_LR_000151_R"]
105134 # alias = ["c01", "c02", "c03"]
106135 # sgns = [7796, 6119, 9225]
107136
108- # TODO map the cochlea name to its alias
109- alias = [name .replace ("_" , "" ).replace ("0" , "" ) for name 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+
110143 sgns = [len (vals ) for vals in chreef_data .values ()]
111144
112145 if plot_by_side :
@@ -138,14 +171,15 @@ def fig_04c(chreef_data, save_path, plot=False, plot_by_side=False):
138171 plt .legend (loc = "upper center" , bbox_to_anchor = (0.5 , 1.11 ),
139172 ncol = 3 , fancybox = True , shadow = False , framealpha = 0.8 , fontsize = legendsize )
140173
141- # set range of literature values
142174 xmin = - 0.5
143175 xmax = len (alias ) - 0.5
144176 plt .xlim (xmin , xmax )
145- lower_y , upper_y = literature_reference_values ("SGN" )
146- plt .hlines ([lower_y , upper_y ], xmin , xmax )
147- plt .text (1.5 , lower_y - 400 , "literature" , color = "C0" , fontsize = main_tick_size , ha = "center" )
148- plt .fill_between ([xmin , xmax ], lower_y , upper_y , color = "C0" , alpha = 0.05 , interpolate = True )
177+
178+ # set range of literature values
179+ # lower_y, upper_y = literature_reference_values("SGN")
180+ # plt.hlines([lower_y, upper_y], xmin, xmax)
181+ # plt.text(1.5, lower_y - 400, "literature", color="C0", fontsize=main_tick_size, ha="center")
182+ # plt.fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
149183
150184 sgn_values = [11153 , 11398 , 10333 , 11820 ]
151185 sgn_value = np .mean (sgn_values )
@@ -168,11 +202,13 @@ def fig_04c(chreef_data, save_path, plot=False, plot_by_side=False):
168202 plt .close ()
169203
170204
171- def fig_04d (chreef_data , save_path , plot = False , plot_by_side = False , intensity = False ):
205+ def fig_04d (chreef_data , save_path , plot = False , plot_by_side = False , intensity = False , gerbil = False , use_alias = True ):
172206 """Transduction efficiency per cochlea.
173207 """
174- # TODO map the cochlea name to its alias
175- alias = [name .replace ("_" , "" ).replace ("0" , "" ) for name 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 ()]
176212
177213 values = []
178214 for vals in chreef_data .values ():
@@ -219,7 +255,10 @@ def fig_04d(chreef_data, save_path, plot=False, plot_by_side=False, intensity=Fa
219255 plt .legend (loc = "upper center" , bbox_to_anchor = (0.5 , 1.11 ),
220256 ncol = 3 , fancybox = True , shadow = False , framealpha = 0.8 , fontsize = legendsize )
221257 if not intensity :
222- plt .ylim (0.5 , 1.05 )
258+ if gerbil :
259+ plt .ylim (0.3 , 1.05 )
260+ else :
261+ plt .ylim (0.5 , 1.05 )
223262
224263 plt .tight_layout ()
225264 plt .savefig (save_path , bbox_inches = "tight" , pad_inches = 0.1 , dpi = png_dpi )
@@ -230,12 +269,14 @@ def fig_04d(chreef_data, save_path, plot=False, plot_by_side=False, intensity=Fa
230269 plt .close ()
231270
232271
233- def fig_04e (chreef_data , save_path , plot , intensity = False ):
272+ def fig_04e (chreef_data , save_path , plot , intensity = False , gerbil = False , use_alias = True ):
234273
235274 result = {"cochlea" : [], "octave_band" : [], "value" : []}
236275 for name , values in chreef_data .items ():
237- # TODO map name to alias
238- alias = name .replace ("_" , "" ).replace ("0" , "" )
276+ if use_alias :
277+ alias = COCHLEAE_ALIAS [name ]
278+ else :
279+ alias = name .replace ("_" , "" ).replace ("0" , "" )
239280
240281 freq = values ["frequency[kHz]" ].values
241282 if intensity :
@@ -264,7 +305,10 @@ def fig_04e(chreef_data, save_path, plot, intensity=False):
264305 band_label_offset_y = 0.09
265306 else :
266307 band_label_offset_y = 0.07
267- ax .set_ylim (0.45 , 1.05 )
308+ if gerbil :
309+ ax .set_ylim (0.05 , 1.05 )
310+ else :
311+ ax .set_ylim (0.45 , 1.05 )
268312
269313 # Offsets within each octave band
270314 offset_map = {"L" : - 0.15 , "R" : 0.15 }
@@ -336,28 +380,48 @@ def fig_04e(chreef_data, save_path, plot, intensity=False):
336380def main ():
337381 parser = argparse .ArgumentParser (description = "Generate plots for Fig 4 of the cochlea paper." )
338382 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" )
339384 parser .add_argument ("--plot" , action = "store_true" )
340385 args = parser .parse_args ()
341386
387+ use_alias = not args .no_alias
342388 os .makedirs (args .figure_dir , exist_ok = True )
343389
344390 # Get the chreef data as a dictionary of cochlea name to measurements.
345391 chreef_data = get_chreef_data ()
346392 # M_LR_00143_L is a complete outlier
347393 chreef_data .pop ("M_LR_000143_L" )
394+ # remove other cochlea to have only pairs remaining
395+ chreef_data .pop ("M_LR_000143_R" )
348396
349397 # Create the panels:
350398
351399 # C: The SGN count compared to reference values from literature and healthy
352400 # Maybe remove literature reference from plot?
353- 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 )
354403
355404 # D: The transduction efficiency. We also plot GFP intensities.
356- fig_04d (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04d_transduction" ), plot = args .plot , plot_by_side = True ) # noqa
357- 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
358-
359- fig_04e (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04e_transduction" ), plot = args .plot )
360- fig_04e (chreef_data , save_path = os .path .join (args .figure_dir , "fig_04e_intensity" ), plot = args .plot , intensity = True )
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 )
409+
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 )
414+
415+ chreef_data_gerbil = get_chreef_data (animal = "gerbil" )
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 )
361425
362426
363427if __name__ == "__main__" :
0 commit comments