Skip to content

Commit bd4835f

Browse files
committed
Update initial plots
1 parent b0e8347 commit bd4835f

File tree

1 file changed

+30
-15
lines changed

1 file changed

+30
-15
lines changed

scripts/measurements/sgn_subtypes.py

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
import json
22
import os
3-
import sys
43
from glob import glob
54

65
import matplotlib.pyplot as plt
76
import numpy as np
87
import pandas as pd
98
from skimage.filters import threshold_otsu
109

11-
from flamingo_tools.s3_utils import BUCKET_NAME, create_s3_target, get_s3_path
10+
from flamingo_tools.s3_utils import BUCKET_NAME, create_s3_target
1211
from flamingo_tools.measurements import compute_object_measures
1312

1413

@@ -59,7 +58,7 @@ def frequency_mapping(frequencies, values, animal="mouse", transduction_efficien
5958
# "M_LR_000214_L": ["PV", "CR", "Calb1"],
6059
"M_LR_000184_R": ["PV", "Prph"],
6160
"M_LR_000184_L": ["PV", "Prph"],
62-
"M_LR_000260_L": ["PV", "Prph", "Tuj1"],
61+
# "M_LR_000260_L": ["PV", "Prph", "Tuj1"],
6362
}
6463

6564
COCHLEAE = {
@@ -72,7 +71,7 @@ def frequency_mapping(frequencies, values, animal="mouse", transduction_efficien
7271

7372

7473
REGULAR_COCHLEAE = [
75-
"M_LR_000099_L", "M_LR_000184_R", "M_LR_000184_L", "M_LR_000260_L"
74+
"M_LR_000099_L", "M_LR_000184_R", "M_LR_000184_L", # "M_LR_000260_L"
7675
]
7776

7877
# For custom thresholds.
@@ -85,7 +84,16 @@ def frequency_mapping(frequencies, values, animal="mouse", transduction_efficien
8584

8685
# For consistent colors.
8786
ALL_COLORS = ["red", "blue", "orange", "yellow", "cyan", "magenta", "green", "purple", "gray", "black"]
88-
COLORS = {}
87+
COLORS = {
88+
"Type Ib": "#27339C",
89+
"Type Ib/Ic": "#67279C",
90+
"Type Ic": "#9C276F",
91+
"inconclusive": "#9C8227",
92+
93+
"Type I": "#9C3B27",
94+
"Type II": "#279C96",
95+
"default": "#279C47"
96+
}
8997

9098
PLOT_OUT = "./subtype_plots"
9199

@@ -120,7 +128,7 @@ def stain_to_type(stain):
120128

121129
# Combinations of Prph and Tuj1:
122130
"Prph+/Tuj1+": "Type II",
123-
"Prph+/Tuj1-": "Type I",
131+
"Prph+/Tuj1-": "Type II",
124132
"Prph-/Tuj1+": "Type I",
125133
"Prph-/Tuj1-": "inconclusive",
126134

@@ -476,7 +484,11 @@ def combined_analysis(results, show_plots):
476484
bin_labels = pd.unique(frequency_mapped.index)
477485
x_positions = [i for i in range(len(bin_labels))]
478486
values = frequency_mapped.values
479-
ax.scatter(x_positions, values, label=cat, color=colors[cat])
487+
if cat in COLORS.keys():
488+
color = COLORS[cat]
489+
else:
490+
color = COLORS["default"]
491+
ax.scatter(x_positions, values, label=cat, color=color)
480492

481493
main_ticks = range(len(bin_labels))
482494
ax.set_xticks(main_ticks)
@@ -513,14 +525,21 @@ def combined_analysis(results, show_plots):
513525
summary[cochlea][stype] = type_ratio
514526

515527
types = list(set(types))
528+
types.sort()
516529
df = pd.DataFrame(summary).fillna(0) # missing values → 0
517530

518531
# Transpose → cochleae on x-axis, subtypes stacked
519-
ax = df.T.plot(kind="bar", stacked=True, figsize=(8, 5))
532+
if len(types) == 6:
533+
types = [types[2], types[3], types[4], types[5], types[0], types[1]]
534+
print(types)
535+
colors = [COLORS[t] for t in types]
536+
537+
ax = df.T.plot(kind="bar", stacked=True, figsize=(8, 5), color=colors)
520538

521539
ax.set_ylabel("Fraction")
522540
ax.set_xlabel("Cochlea")
523541
ax.set_title("Subtype Fractions per Cochlea")
542+
plt.legend(loc="lower right")
524543
plt.xticks(rotation=0)
525544
plt.tight_layout()
526545

@@ -580,7 +599,7 @@ def analyze_subtype_data_regular(show_plots=True):
580599
# filter subtype table
581600
for chan in channels[1:]:
582601
column = f"marker_{chan}"
583-
table = table.loc[table[column].isin([1,2])]
602+
table = table.loc[table[column].isin([1, 2])]
584603
print(f"Length of table after filtering channel {chan}: {len(table)}")
585604

586605
tab = pd.read_csv(ff, sep="\t")
@@ -627,19 +646,15 @@ def analyze_subtype_data_regular(show_plots=True):
627646
for label in unique_labels:
628647
if label in COLORS:
629648
continue
630-
if COLORS:
631-
last_color = list(COLORS.values())[-1]
632-
next_color = ALL_COLORS[ALL_COLORS.index(last_color) + 1]
633-
COLORS[label] = next_color
634649
else:
635650
COLORS[label] = ALL_COLORS[0]
636651

637652
# 3.) Plot tonotopic mapping.
638653
freq = table["frequency[kHz]"].values
639654
assert len(freq) == len(classification)
640-
#tonotopic_mapping = _plot_tonotopic_mapping(
655+
# tonotopic_mapping = _plot_tonotopic_mapping(
641656
# freq, classification, name=name, colors=COLORS, show_plots=show_plots
642-
#)
657+
# )
643658

644659
# 4.) Plot 2D space of ratios.
645660
if show_2d:

0 commit comments

Comments
 (0)