Skip to content

Commit 255e41c

Browse files
committed
Update Boxplots
1 parent c110dfe commit 255e41c

File tree

4 files changed

+163
-27
lines changed

4 files changed

+163
-27
lines changed

scripts/figures/plot_fig2.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
COLOR_F = "#9C276F"
2222
COLOR_T = "#279C52"
2323

24+
COLOR_MEASUREMENT = "#9C7427"
25+
COLOR_LITERATURE = "#27339C"
2426

2527
def scramble_instance_labels(arr):
2628
"""Scramble indexes of instance segmentation to avoid neighboring colors.
@@ -269,7 +271,6 @@ def supp_fig_02(save_path, plot=False, segm="SGN", mode="precision"):
269271

270272
# Labels and formatting
271273
x_pos = np.arange(1, len(labels)+1)
272-
print(x_pos)
273274
plt.xticks(x_pos, labels, fontsize=16)
274275
plt.yticks(fontsize=main_tick_size)
275276
plt.ylabel("Value", fontsize=main_label_size)
@@ -454,8 +455,17 @@ def fig_02d_01(save_path, plot=False, all_versions=False, plot_average_ribbon_sy
454455
ax = axes.flatten()
455456

456457
save_path_new = save_path.split(".")[0] + suffix + "." + save_path.split(".")[1]
457-
ax[0].boxplot(sgn_values)
458-
ax[1].boxplot(ihc_values)
458+
box_plot = ax[0].boxplot(sgn_values, patch_artist=True, zorder=1)
459+
for median in box_plot['medians']:
460+
median.set_color(COLOR_MEASUREMENT)
461+
for boxcolor in box_plot['boxes']:
462+
boxcolor.set_facecolor("white")
463+
464+
box_plot = ax[1].boxplot(ihc_values, patch_artist=True, zorder=1)
465+
for median in box_plot['medians']:
466+
median.set_color(COLOR_MEASUREMENT)
467+
for boxcolor in box_plot['boxes']:
468+
boxcolor.set_facecolor("white")
459469

460470
# Labels and formatting
461471
ax[0].set_xticklabels(["SGN"], fontsize=main_label_size)
@@ -475,9 +485,9 @@ def fig_02d_01(save_path, plot=False, all_versions=False, plot_average_ribbon_sy
475485
xmax = 1.5
476486
ax[0].set_xlim(xmin, xmax)
477487
lower_y, upper_y = literature_reference_values("SGN")
478-
ax[0].hlines([lower_y, upper_y], xmin, xmax)
488+
ax[0].hlines([lower_y, upper_y], xmin, xmax, color=COLOR_LITERATURE)
479489
ax[0].text(1., lower_y + (upper_y - lower_y) * 0.2, "literature",
480-
color="C0", fontsize=main_label_size, ha="center")
490+
color=COLOR_LITERATURE, fontsize=main_label_size, ha="center")
481491
ax[0].fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
482492

483493
ylim0 = 600
@@ -497,17 +507,22 @@ def fig_02d_01(save_path, plot=False, all_versions=False, plot_average_ribbon_sy
497507
xmax = 1.5
498508
lower_y, upper_y = literature_reference_values("IHC")
499509
ax[1].set_xlim(xmin, xmax)
500-
ax[1].hlines([lower_y, upper_y], xmin, xmax)
510+
ax[1].hlines([lower_y, upper_y], xmin, xmax, color=COLOR_LITERATURE)
501511
# ax[1].text(1.1, (lower_y + upper_y) // 2, "literature", color="C0", fontsize=main_tick_size, ha="left")
502-
ax[1].fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
512+
ax[1].fill_between([xmin, xmax], lower_y, upper_y, color=COLOR_LITERATURE, alpha=0.05, interpolate=True)
503513

504514
if plot_average_ribbon_synapses:
505515
ribbon_synapse_counts = _load_ribbon_synapse_counts()
506516
ylim0 = -1
507517
ylim1 = 41
508518
y_ticks = [0, 10, 20, 30, 40, 50]
509519

510-
ax[2].boxplot(ribbon_synapse_counts)
520+
box_plot = ax[2].boxplot(ribbon_synapse_counts, patch_artist=True, zorder=1)
521+
for median in box_plot['medians']:
522+
median.set_color(COLOR_MEASUREMENT)
523+
for boxcolor in box_plot['boxes']:
524+
boxcolor.set_facecolor("white")
525+
511526
ax[2].set_xticklabels(["Synapses per IHC"], fontsize=main_label_size)
512527
ax[2].set_yticks(y_ticks)
513528
ax[2].set_yticklabels(y_ticks, rotation=0, fontsize=main_tick_size)
@@ -518,9 +533,9 @@ def fig_02d_01(save_path, plot=False, all_versions=False, plot_average_ribbon_sy
518533
xmax = 1.5
519534
lower_y, upper_y = literature_reference_values("synapse")
520535
ax[2].set_xlim(xmin, xmax)
521-
ax[2].hlines([lower_y, upper_y], xmin, xmax)
536+
ax[2].hlines([lower_y, upper_y], xmin, xmax, color=COLOR_LITERATURE)
522537
# ax[2].text(1.1, (lower_y + upper_y) // 2, "literature", color="C0", fontsize=main_tick_size, ha="left")
523-
ax[2].fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
538+
ax[2].fill_between([xmin, xmax], lower_y, upper_y, color=COLOR_LITERATURE, alpha=0.05, interpolate=True)
524539

525540
prism_cleanup_axes(axes)
526541
plt.tight_layout()

scripts/figures/plot_fig4.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,8 @@ def fig_04e(chreef_data, save_path, plot, intensity=False, gerbil=False,
588588
eff = float(n_pos) / (n_pos + n_neg)
589589
values.append(eff)
590590
alias, values_left, values_right = group_lr(aliases, values)
591+
print(f"Average expression efficiency left {values_left}")
592+
print(f"Average expression efficiency right {values_right}")
591593

592594
result = pd.DataFrame(result)
593595
bin_labels = pd.unique(result["octave_band"])

scripts/figures/plot_fig5.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def fig_05c(save_path, plot=False):
7878
ylim1 = 24
7979
y_ticks = [i for i in range(0, 25, 5)]
8080

81-
axes[1].set_ylabel("Ribbon Syn. per IHC", fontsize=main_label_size)
81+
axes[1].set_ylabel("Synapses per IHC", fontsize=main_label_size)
8282
axes[1].set_yticks(y_ticks)
8383
axes[1].set_yticklabels(y_ticks, rotation=0, fontsize=main_tick_size)
8484
axes[1].set_ylim(ylim0, ylim1)

scripts/figures/plot_fig6.py

Lines changed: 135 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
COLOR_RIGHT = "#DB0063"
2929
MARKER_LEFT = "o"
3030
MARKER_RIGHT = "^"
31+
COLOR_MEASUREMENT = "#9C7427"
32+
COLOR_LITERATURE = "#27339C"
33+
COLOR_UNTREATED = "#DB7B00"
3134

3235

3336
def get_otof_data():
@@ -85,6 +88,7 @@ def _load_ribbon_synapse_counts():
8588
ihc_version = "ihc_counts_v6"
8689
synapse_dir = os.path.join(SYNAPSE_DIR_ROOT, ihc_version)
8790
tables = [entry.path for entry in os.scandir(synapse_dir) if "ihc_count_G_" in entry.name]
91+
print(f"Synapse count for tables {tables}.")
8892
syn_counts = []
8993
for tab in tables:
9094
x = pd.read_csv(tab, sep="\t")
@@ -155,11 +159,13 @@ def _get_trendline_params(trend_dict):
155159
return x_values, y_values_center, y_values_upper, y_values_lower
156160

157161

158-
def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline=False):
162+
def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline_mode=None):
159163
prism_style()
160164
label_size = 20
165+
tick_label_size = 14
161166

162167
result = {"cochlea": [], "octave_band": [], "value": []}
168+
expression_eff_dic = {}
163169
for name, values in otof_data.items():
164170
if use_alias:
165171
alias = COCHLEAE_DICT[name]["alias"]
@@ -168,11 +174,16 @@ def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline=F
168174

169175
freq = values["frequency[kHz]"].values
170176
marker_labels = values["expression_classification"].values
177+
marker_pos = len([1 for i in marker_labels if i == 1])
178+
marker_neg = len([1 for i in marker_labels if i == 2])
179+
expression_eff = marker_pos / (marker_pos + marker_neg)
180+
print(f"Cochlea {name}, efficiency {expression_eff}")
171181
octave_binned = frequency_mapping(freq, marker_labels, animal="mouse", transduction_efficiency=True)
172182

173183
result["cochlea"].extend([alias] * len(octave_binned))
174184
result["octave_band"].extend(octave_binned.axes[0].values.tolist())
175185
result["value"].extend(octave_binned.values.tolist())
186+
expression_eff_dic[alias] = expression_eff
176187

177188
result = pd.DataFrame(result)
178189
bin_labels = pd.unique(result["octave_band"])
@@ -195,15 +206,15 @@ def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline=F
195206

196207
# y_values.append(list(grp["value"]))
197208

198-
if trendline:
209+
if trendline_mode == "filled":
199210
sorted_idx = np.argsort(x_positions)
200211
x_sorted = np.array(x_positions)[sorted_idx]
201212
y_sorted = np.array(grp["value"])[sorted_idx]
202213
trend_dict[name] = {"x_sorted": x_sorted,
203214
"y_sorted": y_sorted,
204215
}
205216
# central line
206-
if trendline:
217+
if trendline_mode == "filled":
207218
#mean, std = _get_trendline_params(y_values)
208219
x_sorted, y_sorted, y_sorted_upper, y_sorted_lower = _get_trendline_params(trend_dict)
209220
trend_center, = ax.plot(
@@ -237,6 +248,26 @@ def fig_06e_octave(otof_data, save_path, plot=False, use_alias=True, trendline=F
237248
plt.fill_between(x_sorted, y_sorted_lower, y_sorted_upper,
238249
color="gray", alpha=0.05, interpolate=True)
239250

251+
elif trendline_mode == "mean":
252+
xlim_left, xlim_right = ax.get_xlim()
253+
y_offset = [0.01, -0.04]
254+
x_offset = 0.5
255+
plt.xlim(xlim_left, xlim_right)
256+
for num, key in enumerate(colors.keys()):
257+
color = colors[key]
258+
expression_eff = expression_eff_dic[key]
259+
260+
ax.text(xlim_left + x_offset, expression_eff + y_offset[num], "mean",
261+
color=color, fontsize=tick_label_size, ha="center")
262+
trend_r, = ax.plot(
263+
[xlim_left, xlim_right],
264+
[expression_eff, expression_eff],
265+
linestyle="dashed",
266+
color=color,
267+
alpha=0.7,
268+
zorder=0
269+
)
270+
240271
ax.set_xticks(range(len(bin_labels)))
241272
ax.set_xticklabels(bin_labels)
242273
ax.set_xlabel("Octave band [kHz]", fontsize=label_size)
@@ -267,15 +298,16 @@ def fig_06b(save_path, plot=False):
267298
rows = 1
268299
columns = 3
269300

270-
fig, ax = plt.subplots(rows, columns, figsize=(columns*3, rows*4))
301+
fig, ax = plt.subplots(rows, columns, figsize=(8.5, 4.5))
271302

272303
sgn_values = [18541]
273304
ihc_values = [1180]
274305

275-
ax[0].boxplot(sgn_values)
276-
ax[1].boxplot(ihc_values)
306+
ax[0].scatter([1], sgn_values, color=COLOR_MEASUREMENT, marker="x", s=100)
307+
ax[1].scatter([1], ihc_values, color=COLOR_MEASUREMENT, marker="x", s=100)
277308

278309
# Labels and formatting
310+
ax[0].set_xticks([1])
279311
ax[0].set_xticklabels(["SGN"], fontsize=main_label_size)
280312

281313
ylim0 = 14000
@@ -293,15 +325,16 @@ def fig_06b(save_path, plot=False):
293325
xmax = 1.5
294326
ax[0].set_xlim(xmin, xmax)
295327
lower_y, upper_y = literature_reference_values_gerbil("SGN")
296-
ax[0].hlines([lower_y, upper_y], xmin, xmax)
297-
ax[0].text(1, upper_y - 2000, "literature", color='C0', fontsize=main_tick_size, ha="center")
298-
ax[0].fill_between([xmin, xmax], lower_y, upper_y, color='C0', alpha=0.05, interpolate=True)
328+
ax[0].hlines([lower_y, upper_y], xmin, xmax, color=COLOR_LITERATURE)
329+
ax[0].text(1, upper_y - 2000, "literature", color=COLOR_LITERATURE, fontsize=main_tick_size, ha="center")
330+
ax[0].fill_between([xmin, xmax], lower_y, upper_y, color=COLOR_LITERATURE, alpha=0.05, interpolate=True)
299331

300332
ylim0 = 900
301333
ylim1 = 1400
302334
ytick_gap = 200
303335
y_ticks = [i for i in range((((ylim0 - 1) // ytick_gap) + 1) * ytick_gap, ylim1 + 1, ytick_gap)]
304336

337+
ax[1].set_xticks([1])
305338
ax[1].set_xticklabels(["IHC"], fontsize=main_label_size)
306339

307340
ax[1].set_yticks(y_ticks)
@@ -313,16 +346,21 @@ def fig_06b(save_path, plot=False):
313346
xmax = 1.5
314347
ax[1].set_xlim(xmin, xmax)
315348
lower_y, upper_y = literature_reference_values_gerbil("IHC")
316-
ax[1].hlines([lower_y, upper_y], xmin, xmax)
317-
ax[1].fill_between([xmin, xmax], lower_y, upper_y, color='C0', alpha=0.05, interpolate=True)
349+
ax[1].hlines([lower_y, upper_y], xmin, xmax, color=COLOR_LITERATURE)
350+
ax[1].fill_between([xmin, xmax], lower_y, upper_y, color=COLOR_LITERATURE, alpha=0.05, interpolate=True)
318351

319352
ribbon_synapse_counts = _load_ribbon_synapse_counts()
320353
ylim0 = -1
321354
ylim1 = 80
322355
ytick_gap = 20
323356
y_ticks = [i for i in range((((ylim0 - 1) // ytick_gap) + 1) * ytick_gap, ylim1 + 1, ytick_gap)]
324357

325-
ax[2].boxplot(ribbon_synapse_counts)
358+
box_plot = ax[2].boxplot(ribbon_synapse_counts, patch_artist=True)
359+
for median in box_plot['medians']:
360+
median.set_color(COLOR_MEASUREMENT)
361+
for boxcolor in box_plot['boxes']:
362+
boxcolor.set_facecolor("white")
363+
326364
ax[2].set_xticklabels(["Synapses per IHC"], fontsize=main_label_size)
327365
ax[2].set_yticks(y_ticks)
328366
ax[2].set_yticklabels(y_ticks, rotation=0, fontsize=main_tick_size)
@@ -333,8 +371,8 @@ def fig_06b(save_path, plot=False):
333371
xmax = 1.5
334372
lower_y, upper_y = literature_reference_values_gerbil("synapse")
335373
ax[2].set_xlim(xmin, xmax)
336-
ax[2].hlines([lower_y, upper_y], xmin, xmax)
337-
ax[2].fill_between([xmin, xmax], lower_y, upper_y, color="C0", alpha=0.05, interpolate=True)
374+
ax[2].hlines([lower_y, upper_y], xmin, xmax, color=COLOR_LITERATURE)
375+
ax[2].fill_between([xmin, xmax], lower_y, upper_y, color=COLOR_LITERATURE, alpha=0.05, interpolate=True)
338376

339377
plt.tight_layout()
340378
prism_cleanup_axes(ax)
@@ -349,6 +387,86 @@ def fig_06b(save_path, plot=False):
349387
plt.close()
350388

351389

390+
def fig_06c(save_path, plot=False):
391+
"""Box plot showing the SGN counts of ChReef treated cochleae compared to healthy ones.
392+
"""
393+
prism_style()
394+
values_left = [11351]
395+
values_right = [21995]
396+
397+
# Plot
398+
fig, ax = plt.subplots(figsize=(4, 5))
399+
400+
main_label_size = 20
401+
sub_label_size = 16
402+
main_tick_size = 16
403+
404+
offset = 0.08
405+
x_left = 1
406+
x_right = 2
407+
408+
x_pos_inj = [x_left - len(values_left) // 2 * offset + offset * i for i in range(len(values_left))]
409+
x_pos_non = [x_right - len(values_right) // 2 * offset + offset * i for i in range(len(values_right))]
410+
411+
# lines between cochleae of same animal
412+
for num, (left, right) in enumerate(zip(values_left, values_right)):
413+
ax.plot(
414+
[x_pos_inj[num], x_pos_non[num]],
415+
[left, right],
416+
linestyle="solid",
417+
color="grey",
418+
alpha=0.4,
419+
zorder=0
420+
)
421+
plt.scatter(x_pos_inj, values_left, label="Injected",
422+
color=COLOR_LEFT, marker=MARKER_LEFT, s=80, zorder=1)
423+
plt.scatter(x_pos_non, values_right, label="Non-Injected",
424+
color=COLOR_RIGHT, marker=MARKER_RIGHT, s=80, zorder=1)
425+
426+
# Labels and formatting
427+
plt.xticks([x_left, x_right], ["Injected", "Non-\nInjected"], fontsize=sub_label_size)
428+
for label in plt.gca().get_xticklabels():
429+
label.set_verticalalignment('center')
430+
ax.tick_params(axis='x', which='major', pad=16)
431+
432+
plt.ylim(10000, 24000)
433+
y_ticks = [i for i in range(10000, 24000, 4000)]
434+
435+
plt.yticks(y_ticks, fontsize=main_tick_size)
436+
plt.ylabel("SGN count per cochlea", fontsize=main_label_size)
437+
xmin = 0.5
438+
xmax = 2.5
439+
plt.xlim(xmin, xmax)
440+
441+
sgn_values = [18541] # G_EK_000233_L
442+
sgn_value = np.mean(sgn_values)
443+
sgn_std = np.std(sgn_values)
444+
445+
upper_y = sgn_value + 1.96 * sgn_std
446+
lower_y = sgn_value - 1.96 * sgn_std
447+
448+
c_untreated = COLOR_UNTREATED
449+
450+
plt.hlines([lower_y, upper_y], xmin, xmax, colors=[c_untreated for _ in range(2)], zorder=-1)
451+
plt.text((xmin + xmax) / 2, upper_y + 200, "untreated cochleae\n(95% confidence interval)",
452+
color=c_untreated, fontsize=11, ha="center")
453+
plt.fill_between([xmin, xmax], lower_y, upper_y, color=c_untreated, alpha=0.05, interpolate=True)
454+
455+
plt.tight_layout()
456+
457+
prism_cleanup_axes(ax)
458+
459+
if ".png" in save_path:
460+
plt.savefig(save_path, bbox_inches="tight", pad_inches=0.1, dpi=png_dpi)
461+
else:
462+
plt.savefig(save_path, bbox_inches='tight', pad_inches=0)
463+
464+
if plot:
465+
plt.show()
466+
else:
467+
plt.close()
468+
469+
352470
def fig_06d(save_path, plot=False):
353471
"""Plot the synapse distribution measured with different markers.
354472
@@ -373,10 +491,11 @@ def main():
373491
otof_data = get_otof_data()
374492
plot_legend_fig06e(args.figure_dir)
375493
fig_06e_octave(otof_data, save_path=os.path.join(args.figure_dir, f"fig_06e.{FILE_EXTENSION}"), plot=plot,
376-
trendline=False, gr)
494+
trendline_mode="mean")
377495

378496
fig_06b(save_path=os.path.join(args.figure_dir, f"fig_06b.{FILE_EXTENSION}"), plot=plot)
379-
fig_06d(save_path=os.path.join(args.figure_dir, f"fig_06d.{FILE_EXTENSION}"), plot=plot)
497+
fig_06c(save_path=os.path.join(args.figure_dir, f"fig_06c.{FILE_EXTENSION}"), plot=plot)
498+
# fig_06d(save_path=os.path.join(args.figure_dir, f"fig_06d.{FILE_EXTENSION}"), plot=plot)
380499

381500

382501
if __name__ == "__main__":

0 commit comments

Comments
 (0)