Skip to content

Commit a218881

Browse files
More measurement updates
1 parent 1803292 commit a218881

File tree

4 files changed

+96
-18
lines changed

4 files changed

+96
-18
lines changed

scripts/export_lower_resolution.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
from skimage.segmentation import relabel_sequential
1111

1212

13-
def filter_component(fs, segmentation, cochlea, seg_name):
13+
def filter_component(fs, segmentation, cochlea, seg_name, components):
1414
# First, we download the MoBIE table for this segmentation.
1515
internal_path = os.path.join(BUCKET_NAME, cochlea, "tables", seg_name, "default.tsv")
1616
with fs.open(internal_path, "r") as f:
1717
table = pd.read_csv(f, sep="\t")
1818

1919
# Then we get the ids for the components and us them to filter the segmentation.
20-
component_mask = np.isin(table.component_labels.values, [1])
20+
component_mask = np.isin(table.component_labels.values, components)
2121
keep_label_ids = table.label_id.values[component_mask].astype("int64")
2222
filter_mask = ~np.isin(segmentation, keep_label_ids)
2323
segmentation[filter_mask] = 0
2424

25-
segmentation, _, _ = relabel_sequential(segmentation)
25+
# segmentation, _, _ = relabel_sequential(segmentation)
2626
return segmentation
2727

2828

@@ -42,8 +42,8 @@ def export_lower_resolution(args):
4242
with zarr.open(s3_store, mode="r") as f:
4343
data = f[input_key][:]
4444
print(data.shape)
45-
if args.filter_by_component:
46-
data = filter_component(fs, data, args.cochlea, channel)
45+
if args.filter_by_components is not None:
46+
data = filter_component(fs, data, args.cochlea, channel, args.filter_by_components)
4747
tifffile.imwrite(out_path, data, bigtiff=True, compression="zlib")
4848

4949

@@ -53,7 +53,7 @@ def main():
5353
parser.add_argument("--scale", "-s", type=int, required=True)
5454
parser.add_argument("--output_folder", "-o", required=True)
5555
parser.add_argument("--channels", nargs="+", default=["PV", "VGlut3", "CTBP2"])
56-
parser.add_argument("--filter_by_component", action="store_true")
56+
parser.add_argument("--filter_by_components", nargs="+", type=int, default=None)
5757
args = parser.parse_args()
5858

5959
export_lower_resolution(args)

scripts/measurements/evaluate_otof_therapy.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,31 @@ def check_project(save=False):
4949
print()
5050

5151

52+
def plot_distribution():
53+
import seaborn as sns
54+
import matplotlib.pyplot as plt
55+
56+
table1 = "./results/otof-measurements/M_AMD_OTOF1_L.csv"
57+
table2 = "./results/otof-measurements/M_AMD_OTOF2_L.csv"
58+
59+
table1 = pd.read_csv(table1)
60+
table2 = pd.read_csv(table2)
61+
62+
fig, axes = plt.subplots(1, 2, figsize=(10, 4))
63+
sns.histplot(data=table1, x="mean", bins=32, ax=axes[0])
64+
axes[0].set_title("Dual AAV")
65+
sns.histplot(data=table2, x="mean", bins=32, ax=axes[1])
66+
axes[1].set_title("Overloaded AAV")
67+
68+
fig.suptitle("OTOF Gene Therapy - Mean AlphaTag Intensity of IHCs")
69+
plt.tight_layout()
70+
71+
plt.show()
72+
73+
5274
def main():
53-
check_project(save=True)
75+
# check_project(save=True)
76+
plot_distribution()
5477

5578

5679
if __name__ == "__main__":

scripts/measurements/evaluate_sgn_therapy.py

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ def check_project(save=False):
3232
continue
3333

3434
# Get the ihc table folder.
35-
ihc = sources[sgn_name]["segmentation"]
36-
table_folder = os.path.join(BUCKET_NAME, cochlea, ihc["tableData"]["tsv"]["relativePath"])
35+
sgn = sources[sgn_name]["segmentation"]
36+
table_folder = os.path.join(BUCKET_NAME, cochlea, sgn["tableData"]["tsv"]["relativePath"])
3737

3838
# For debugging.
3939
x = s3.ls(table_folder)
@@ -47,6 +47,7 @@ def check_project(save=False):
4747
os.path.join(table_folder, "GFP-resized_SGN-resized-v2_object-measures.tsv"), mode="rb"
4848
)
4949
measurement_table = pd.read_csv(measurement_table, sep="\t")
50+
breakpoint()
5051

5152
if save:
5253
os.makedirs(OUTPUT_FOLDER, exist_ok=True)
@@ -58,8 +59,40 @@ def check_project(save=False):
5859
print()
5960

6061

62+
def plot_distribution():
63+
import seaborn as sns
64+
import matplotlib.pyplot as plt
65+
66+
table1 = "./results/sgn-measurements/M_LR_000145_L.csv"
67+
table2 = "./results/sgn-measurements/M_LR_000151_R.csv"
68+
table3 = "./results/sgn-measurements/M_LR_000155_L.csv"
69+
70+
table1 = pd.read_csv(table1)
71+
table2 = pd.read_csv(table2)
72+
table3 = pd.read_csv(table3)
73+
74+
print(len(table1))
75+
print(len(table3))
76+
77+
fig, axes = plt.subplots(1, 2, figsize=(12, 4))
78+
79+
sns.histplot(data=table1, x="mean", bins=32, ax=axes[0])
80+
axes[0].set_title("M145_L")
81+
# Something is wrong here, the values are normalized.
82+
# sns.histplot(data=table2, x="mean", bins=32, ax=axes[1])
83+
# axes[1].set_title("M151_R")
84+
sns.histplot(data=table3, x="mean", bins=32, ax=axes[1])
85+
axes[1].set_title("M155_L")
86+
87+
fig.suptitle("SGN Gene Therapy - Mean GFP Intensity of SGNs")
88+
plt.tight_layout()
89+
90+
plt.show()
91+
92+
6193
def main():
62-
check_project(save=True)
94+
# check_project(save=True)
95+
plot_distribution()
6396

6497

6598
if __name__ == "__main__":

scripts/measurements/measure_sgns.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@ def open_tsv(fs, path):
2121

2222

2323
def main():
24+
import argparse
25+
parser = argparse.ArgumentParser()
26+
parser.add_argument("--cochleae", "-c", nargs="+")
27+
args = parser.parse_args()
28+
2429
fs = create_s3_target()
2530
project_info = open_json(fs, "project.json")
26-
for dataset in project_info["datasets"]:
27-
if dataset == "fens":
31+
32+
if args.cochleae is None:
33+
cochleae = project_info["datasets"]
34+
else:
35+
cochleae = args.cochleae
36+
37+
for dataset in cochleae:
38+
if dataset not in project_info["datasets"]:
39+
print("Could not find cochleae", dataset)
2840
continue
2941
print(dataset)
3042
dataset_info = open_json(fs, os.path.join(dataset, "dataset.json"))
@@ -36,12 +48,22 @@ def main():
3648
source_info = source_info["segmentation"]
3749
table_path = source_info["tableData"]["tsv"]["relativePath"]
3850
table = open_tsv(fs, os.path.join(dataset, table_path, "default.tsv"))
39-
component_labels = table.component_labels.values
40-
remaining_sgns = component_labels[component_labels != 0]
41-
print(source)
42-
print("Number of SGNs (all components) :", len(remaining_sgns))
43-
_, n_per_component = np.unique(remaining_sgns, return_counts=True)
44-
print("Number of SGNs (largest component):", max(n_per_component))
51+
52+
if hasattr(table, "component_labels"):
53+
component_labels = table.component_labels.values
54+
remaining_sgns = component_labels[component_labels != 0]
55+
print(source)
56+
print(
57+
"Number of SGNs (all components) :", len(remaining_sgns), "/", len(table),
58+
"(total number of segmented objects)"
59+
)
60+
component_ids, n_per_component = np.unique(
61+
remaining_sgns, return_counts=True
62+
)
63+
print("Number of SGNs (largest component):", max(n_per_component))
64+
else:
65+
print(source)
66+
print("Number of SGNs (no postprocessing):", len(table))
4567

4668

4769
if __name__ == "__main__":

0 commit comments

Comments
 (0)