Skip to content

Commit ff08ecc

Browse files
committed
Apex position for tonotopic mapping
1 parent 07d23b5 commit ff08ecc

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

flamingo_tools/segmentation/cochlea_mapping.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,14 +383,15 @@ def measure_run_length_ihcs(
383383
return total_distance, path, path_dict
384384

385385

386-
def map_frequency(table: pd.DataFrame, cell_type: str, animal: str = "mouse") -> pd.DataFrame:
386+
def map_frequency(table: pd.DataFrame, animal: str = "mouse") -> pd.DataFrame:
387387
"""Map the frequency range of SGNs in the cochlea
388388
using Greenwood function f(x) = A * (10 **(ax) - K).
389389
Values for humans: a=2.1, k=0.88, A = 165.4 [kHz].
390390
For mice: fit values between minimal (1kHz) and maximal (80kHz) values
391391
392392
Args:
393393
table: Dataframe containing the segmentation.
394+
animal: Select the Greenwood function parameters specific to a species. Either "mouse" or "gerbil".
394395
395396
Returns:
396397
Dataframe containing frequency in an additional column 'frequency[kHz]'.
@@ -569,6 +570,7 @@ def tonotopic_mapping(
569570
component_mapping: Optional[List[int]] = None,
570571
cell_type: str = "ihc",
571572
animal: str = "mouse",
573+
apex_higher: bool = True,
572574
) -> pd.DataFrame:
573575
"""Tonotopic mapping of IHCs by supplying a table with component labels.
574576
The mapping assigns a tonotopic label to each IHC according to the position along the length of the cochlea.
@@ -591,19 +593,25 @@ def tonotopic_mapping(
591593
component_mapping = component_label
592594

593595
if cell_type == "ihc":
594-
total_distance, _, path_dict = measure_run_length_ihcs(centroids, component_label=component_label)
596+
total_distance, _, path_dict = measure_run_length_ihcs(
597+
centroids, component_label=component_label, apex_higher=apex_higher,
598+
)
595599

596600
else:
597601
if len(component_mapping) == 1:
598-
total_distance, _, path_dict = measure_run_length_sgns(centroids)
602+
total_distance, _, path_dict = measure_run_length_sgns(
603+
centroids, apex_higher=apex_higher,
604+
)
599605

600606
else:
601607
centroids_components = []
602608
for label in component_mapping:
603609
subset = table[table["component_labels"] == label]
604610
subset_centroids = list(zip(subset["anchor_x"], subset["anchor_y"], subset["anchor_z"]))
605611
centroids_components.append(subset_centroids)
606-
total_distance, _, path_dict = measure_run_length_sgns_multi_component(centroids_components)
612+
total_distance, _, path_dict = measure_run_length_sgns_multi_component(
613+
centroids_components, apex_higher=apex_higher,
614+
)
607615

608616
node_dict = node_dict_from_path_dict(path_dict, label_ids, centroids)
609617

@@ -622,6 +630,6 @@ def tonotopic_mapping(
622630

623631
table.loc[:, "length[µm]"] = table["length_fraction"] * total_distance
624632

625-
table = map_frequency(table, cell_type=cell_type, animal=animal)
633+
table = map_frequency(table, animal=animal)
626634

627635
return table

reproducibility/tonotopic_mapping/2025-07-SGN_ChReef.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33
"cochlea": "M_LR_000143_L",
44
"segmentation_channel": "SGN_v2",
5+
"apex_position": "apex_lower",
56
"type": "sgn"
67
},
78
{
@@ -62,6 +63,7 @@
6263
{
6364
"cochlea": "M_LR_000189_R",
6465
"segmentation_channel": "SGN_v2",
66+
"apex_position": "apex_lower",
6567
"type": "sgn"
6668
}
6769
]

reproducibility/tonotopic_mapping/repro_tonotopic_mapping.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def repro_tonotopic_mapping(
1717
force_overwrite: Optional[bool] = None,
1818
):
1919
default_cell_type = "ihc"
20+
default_apex_position = "apex_higher"
2021
default_component_list = [1]
2122

2223
remove_columns = ["tonotopic_label",
@@ -56,14 +57,18 @@ def repro_tonotopic_mapping(
5657
cell_type = dic["type"] if "type" in dic else default_cell_type
5758
component_list = dic["component_list"] if "component_list" in dic else default_component_list
5859
component_mapping = dic["component_mapping"] if "component_mapping" in dic else component_list
60+
apex_position = dic["apex_position"] if "apex_position" in dic else default_apex_position
61+
62+
apex_higher = (apex_position == "apex_higher")
5963

6064
for column in remove_columns:
6165
if column in list(table.columns):
6266
table = table.drop(column, axis=1)
6367

6468
if not os.path.isfile(output_table_path) or force_overwrite:
6569
table = tonotopic_mapping(table, component_label=component_list, animal=animal,
66-
cell_type=cell_type, component_mapping=component_mapping)
70+
cell_type=cell_type, component_mapping=component_mapping,
71+
apex_higher=apex_higher)
6772

6873
table.to_csv(output_table_path, sep="\t", index=False)
6974

0 commit comments

Comments
 (0)