Skip to content

Commit 5967230

Browse files
committed
Custom tonotopic mapping parameters
1 parent c5ed84e commit 5967230

File tree

2 files changed

+47
-10
lines changed

2 files changed

+47
-10
lines changed

flamingo_tools/segmentation/cochlea_mapping.py

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def measure_run_length_ihcs(centroids, max_edge_distance=50):
205205
return total_distance, path, path_dict
206206

207207

208-
def map_frequency(table: pd.DataFrame):
208+
def map_frequency(table: pd.DataFrame, cell_type: str, animal: str = "mouse"):
209209
"""Map the frequency range of SGNs in the cochlea
210210
using Greenwood function f(x) = A * (10 **(ax) - K).
211211
Values for humans: a=2.1, k=0.88, A = 165.4 [kHz].
@@ -217,12 +217,42 @@ def map_frequency(table: pd.DataFrame):
217217
Returns:
218218
Dataframe containing frequency in an additional column 'frequency[kHz]'.
219219
"""
220-
var_k = 0.88
221-
fmin = 1
222-
fmax = 80
223-
var_A = fmin / (1 - var_k)
224-
var_exp = ((fmax + var_A * var_k) / var_A)
225-
table.loc[table['offset'] >= 0, 'frequency[kHz]'] = var_A * (var_exp ** table["length_fraction"] - var_k)
220+
if animal == "mouse":
221+
if cell_type == "ihc":
222+
# freq_min = 5.16 kHz
223+
# freq_max = 81.38 kHz
224+
var_A = 4.232
225+
var_a = 1.279
226+
var_k = -0.22
227+
if cell_type == "sgn":
228+
# freq_min = 0.0095 kHz
229+
# freq_max = 47.47 kHz
230+
var_A = 0.38
231+
var_a = 2.1
232+
var_k = 0.975
233+
234+
elif animal == "gerbil":
235+
if cell_type == "ihc":
236+
# freq_min = 0.0105 kHz
237+
# freq_max = 43.82 kHz
238+
var_A = 0.35
239+
var_a = 2.1
240+
var_k = 0.7
241+
if cell_type == "sgn":
242+
# freq_min = 0.0105 kHz
243+
# freq_max = 43.82 kHz
244+
var_A = 0.35
245+
var_a = 2.1
246+
var_k = 0.7
247+
248+
# alternative Gerbil Greenwood function according to Mueller1995
249+
# var_A = 0.398
250+
# var_a = 2.2
251+
# var_k = 0.631
252+
else:
253+
raise ValueError("Animal not supported. Use either 'mouse' or 'gerbil'.")
254+
255+
table.loc[table['offset'] >= 0, 'frequency[kHz]'] = var_A * (10 ** (var_a * table["length_fraction"]) - var_k)
226256
table.loc[table['offset'] < 0, 'frequency[kHz]'] = 0
227257

228258
return table
@@ -273,7 +303,8 @@ def equidistant_centers(
273303
def tonotopic_mapping(
274304
table: pd.DataFrame,
275305
component_label: List[int] = [1],
276-
cell_type: str = "ihc"
306+
cell_type: str = "ihc",
307+
animal: str = "mouse",
277308
) -> pd.DataFrame:
278309
"""Tonotopic mapping of IHCs by supplying a table with component labels.
279310
The mapping assigns a tonotopic label to each IHC according to the position along the length of the cochlea.
@@ -329,6 +360,6 @@ def tonotopic_mapping(
329360
table.loc[:, "length_fraction"] = length_fraction
330361
table.loc[:, "length[µm]"] = table["length_fraction"] * total_distance
331362

332-
table = map_frequency(table)
363+
table = map_frequency(table, cell_type=cell_type, animal=animal)
333364

334365
return table

reproducibility/tonotopic_mapping/repro_tonotopic_mapping.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ def repro_tonotopic_mapping(
3333
for dic in param_dicts:
3434
cochlea = dic["cochlea"]
3535
seg_channel = dic["segmentation_channel"]
36+
if cochlea[0] in ["M", "m"]:
37+
animal = "mouse"
38+
elif cochlea[0] in ["G", "g"]:
39+
animal = "gerbil"
40+
else:
41+
raise ValueError("Cochlea does not have expected name format 'M_[...]' or 'G_[...]'.")
3642

3743
cochlea_str = "-".join(cochlea.split("_"))
3844
seg_str = "-".join(seg_channel.split("_"))
@@ -54,7 +60,7 @@ def repro_tonotopic_mapping(
5460
table = table.drop(column, axis=1)
5561

5662
if not os.path.isfile(output_table_path) or force_overwrite:
57-
table = tonotopic_mapping(table, component_label=component_list, cell_type=cell_type)
63+
table = tonotopic_mapping(table, component_label=component_list, animal=animal, cell_type=cell_type)
5864

5965
table.to_csv(output_table_path, sep="\t", index=False)
6066

0 commit comments

Comments
 (0)