Skip to content

Commit 5540d08

Browse files
More plot update
1 parent bb4364e commit 5540d08

File tree

4 files changed

+49
-37
lines changed

4 files changed

+49
-37
lines changed

scripts/export_frequency_mapping.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def export_frequency_mapping(cochlea, scale, output_folder, source_name, colorma
3636
seg_path = os.path.join(cochlea, source["imageData"]["ome.zarr"]["relativePath"])
3737
s3_store, _ = get_s3_path(seg_path, bucket_name=BUCKET_NAME, service_endpoint=SERVICE_ENDPOINT)
3838
input_key = f"s{scale}"
39-
with zarr.open(s3_store, mode="r") as f:
40-
seg = f[input_key][:]
39+
f = zarr.open(s3_store, mode="r")
40+
seg = f[input_key][:]
4141

4242
mapping = {int(seg_id): freq for seg_id, freq in zip(table.label_id, frequencies)}
4343
lut = np.zeros(max_id + 1, dtype="float32")

scripts/figures/plot_fig3.py

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@
1111

1212
from util import sliding_runlength_sum, frequency_mapping, SYNAPSE_DIR_ROOT
1313

14-
INPUT_ROOT = "/home/pape/Work/my_projects/flamingo-tools/scripts/M_LR_000227_R/scale3/frequency_mapping"
14+
INPUT_ROOT = "/home/pape/Work/my_projects/flamingo-tools/scripts/M_LR_000227_R/scale3"
15+
16+
TYPE_TO_CHANNEL = {
17+
"Type-Ia": "CR",
18+
"Type-Ib": "Calb1",
19+
"Type-Ic": "Lypd1",
20+
"Type-II": "Prph",
21+
}
1522

1623
png_dpi = 300
1724

@@ -42,35 +49,27 @@ def _plot_colormap(vol, title, plot, save_path):
4249
plt.tight_layout()
4350
if plot:
4451
plt.show()
52+
4553
plt.savefig(save_path)
4654
plt.close()
4755

4856

4957
def fig_03a(save_path, plot, plot_napari):
50-
path = os.path.join(INPUT_ROOT, "frequencies_IHC_v4c.tif")
51-
vol = imageio.imread(path)
52-
_plot_colormap(vol, title="Tonotopic Mapping: IHCs", plot=plot, save_path=save_path)
58+
path_ihc = os.path.join(INPUT_ROOT, "frequencies_IHC_v4c.tif")
59+
path_sgn = os.path.join(INPUT_ROOT, "frequencies_SGN_v2.tif")
60+
sgn = imageio.imread(path_sgn)
61+
ihc = imageio.imread(path_ihc)
62+
_plot_colormap(sgn, title="Tonotopic Mapping", plot=plot, save_path=save_path)
5363

5464
# Show the image in napari for rendering.
5565
if plot_napari:
5666
import napari
5767
v = napari.Viewer()
58-
v.add_image(vol, colormap="viridis")
68+
v.add_image(ihc, colormap="viridis")
69+
v.add_image(sgn, colormap="viridis")
5970
napari.run()
6071

6172

62-
def fig_03b(save_path, plot, plot_napari):
63-
path = os.path.join(INPUT_ROOT, "frequencies_SGN_v2.tif")
64-
vol = imageio.imread(path)
65-
_plot_colormap(vol, title="Tonotopic Mapping: SGNs", plot=plot, save_path=save_path)
66-
67-
# Show the image in napari for rendering.
68-
if plot_napari:
69-
import napari
70-
v = napari.Viewer()
71-
v.add_image(vol, colormap="viridis")
72-
73-
7473
def fig_03c_rl(save_path, plot=False):
7574
tables = glob("./ihc_counts/ihc_count_M_LR*.tsv")
7675
fig, ax = plt.subplots(figsize=(8, 4))
@@ -102,9 +101,9 @@ def fig_03c_rl(save_path, plot=False):
102101

103102

104103
def fig_03c_octave(save_path, plot=False):
105-
# TODO update this table
106104
ihc_version = "ihc_counts_v4c"
107105
tables = glob(os.path.join(SYNAPSE_DIR_ROOT, ihc_version, "ihc_count_M_LR*.tsv"))
106+
assert len(tables) == 4
108107

109108
result = {"cochlea": [], "octave_band": [], "value": []}
110109
for tab_path in tables:
@@ -114,7 +113,6 @@ def fig_03c_octave(save_path, plot=False):
114113
freq = tab["frequency"].values
115114
syn_count = tab["synapse_count"].values
116115

117-
# Compute the running sum of 10 micron.
118116
octave_binned = frequency_mapping(freq, syn_count, animal="mouse")
119117

120118
result["cochlea"].extend([alias] * len(octave_binned))
@@ -164,7 +162,11 @@ def fig_03d(save_path, plot, print_stats=True):
164162
vals = table[col].values
165163
subtype = col[3:]
166164
n_subtype = vals.sum()
167-
print(subtype, ":", n_subtype, "/", n_sgns, f"({np.round(float(n_subtype) / n_sgns * 100, 2)} %)")
165+
channel = TYPE_TO_CHANNEL[subtype]
166+
print(
167+
f"{subtype} ({channel}):", n_subtype, "/", n_sgns,
168+
f"({np.round(float(n_subtype) / n_sgns * 100, 2)} %)"
169+
)
168170

169171
coexpr = np.logical_and(subtype_table.iloc[:, 0].values, subtype_table.iloc[:, 1].values)
170172
print("Co-expression:", coexpr.sum())
@@ -178,16 +180,13 @@ def main():
178180

179181
os.makedirs(args.figure_dir, exist_ok=True)
180182

181-
# Panel A: Tonotopic mapping of IHCs (rendering in napari)
182-
# fig_03a(save_path=os.path.join(args.figure_dir, "fig_03a.png"), plot=args.plot, plot_napari=False)
183-
184-
# Panel B: Tonotopic mapping of SGNs (rendering in napari)
185-
# fig_03b(save_path=os.path.join(args.figure_dir, "fig_03b.png"), plot=args.plot, plot_napari=False)
183+
# Panel A: Tonotopic mapping of SGNs and IHCs (rendering in napari + heatmap)
184+
# fig_03a(save_path=os.path.join(args.figure_dir, "fig_03a_cmap.png"), plot=args.plot, plot_napari=True)
186185

187186
# Panel C: Spatial distribution of synapses across the cochlea.
188187
# We have two options: running sum over the runlength or per octave band
189188
# fig_03c_rl(save_path=os.path.join(args.figure_dir, "fig_03c_runlength.png"), plot=args.plot)
190-
# fig_03c_octave(save_path=os.path.join(args.figure_dir, "fig_03c_octave.png"), plot=args.plot)
189+
fig_03c_octave(save_path=os.path.join(args.figure_dir, "fig_03c_octave.png"), plot=args.plot)
191190

192191
# Panel D: Spatial distribution of SGN sub-types.
193192
fig_03d(save_path=os.path.join(args.figure_dir, "fig_03d.png"), plot=args.plot)

scripts/figures/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import numpy as np
33

44
# Directory with synapse measurement tables
5-
SYNAPSE_DIR_ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/predictions/synapses"
6-
# SYNAPSE_DIR_ROOT = "./synapses"
5+
# SYNAPSE_DIR_ROOT = "/mnt/vast-nhr/projects/nim00007/data/moser/cochlea-lightsheet/predictions/synapses"
6+
SYNAPSE_DIR_ROOT = "./synapses"
77

88

99
# Define the animal specific octave bands.

scripts/measurements/sgn_subtypes.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"M_LR_000099_L": ["PV", "Calb1", "Lypd1"],
1111
"M_LR_000214_L": ["PV", "CR", "Calb1"],
1212
"M_AMD_N62_L": ["PV", "CR", "Calb1"],
13-
"M_AMD_Runx1_L": ["PV", "Lypd1", "Calb1"],
13+
# Mutant / some stuff is weird.
14+
# "M_AMD_Runx1_L": ["PV", "Lypd1", "Calb1"],
1415
# This one still has to be stitched:
1516
# "M_LR_000184_R": {"PV", "Prph"},
1617
# We don't have PV here, so we exclude these two for now.
@@ -32,6 +33,15 @@
3233
"Prph": "Type-II",
3334
}
3435

36+
# TODO
37+
THRESHOLDS = {
38+
"M_LR_000214_L": {
39+
},
40+
"M_AMD_N62_L": {
41+
"Calb1": 380,
42+
},
43+
}
44+
3545

3646
def check_processing_status():
3747
s3 = create_s3_target()
@@ -83,10 +93,6 @@ def analyze_subtypes_intensity_based():
8393
# Remove the PV channel, which we don't need for analysis.
8494
channels = channels[1:]
8595

86-
# FIXME
87-
if cochlea != "M_LR_000099_L":
88-
continue
89-
9096
content = s3.open(f"{BUCKET_NAME}/{cochlea}/dataset.json", mode="r", encoding="utf-8")
9197
info = json.loads(content.read())
9298
sources = info["sources"]
@@ -110,7 +116,11 @@ def analyze_subtypes_intensity_based():
110116
for channel in channels:
111117
# Load the intensity table.
112118
intensity_path = os.path.join(table_folder, f"{channel}_PV-SGN-v2_object-measures.tsv")
113-
table_content = s3.open(intensity_path, mode="rb")
119+
try:
120+
table_content = s3.open(intensity_path, mode="rb")
121+
except FileNotFoundError:
122+
print(intensity_path, "is missing")
123+
continue
114124
intensities = pd.read_csv(table_content, sep="\t")
115125
intensities = intensities[intensities.label_id.isin(valid_sgns)]
116126
assert len(table) == len(intensities)
@@ -120,7 +130,10 @@ def analyze_subtypes_intensity_based():
120130
medians = intensities["median"].values
121131

122132
# TODO: we need to determine the threshold in a better way / validate it in MoBIE.
123-
intensity_threshold = float(threshold_otsu(medians))
133+
intensity_threshold = THRESHOLDS.get(cochlea, {}).get(channel, None)
134+
if intensity_threshold is None:
135+
print("Could not find a threshold for", cochlea, channel, "falling back to OTSU")
136+
intensity_threshold = float(threshold_otsu(medians))
124137
threshold_dict[cochlea][channel] = intensity_threshold
125138

126139
subtype = CHANNEL_TO_TYPE[channel]

0 commit comments

Comments
 (0)