Skip to content

Commit 31f1ca9

Browse files
committed
Subtype thresholding without PV stain
1 parent d91eccf commit 31f1ca9

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

scripts/intensity_annotation/sgn_subtype_annotation.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,27 @@ def sgn_subtype_annotation(prefix, subtype, seg_version="SGN_v2", default_stat="
141141
file_names = [entry.name for entry in os.scandir(direc)]
142142

143143
stain1_file = [name for name in file_names if basename in name and subtype in name][0]
144-
stain2_file = [name for name in file_names if basename in name and "PV.tif" in name][0]
144+
pv_files = [name for name in file_names if basename in name and "PV.tif" in name]
145+
if len(pv_files) == 0:
146+
ratio = False
147+
stain2_name = ""
148+
stain2 = None
149+
seg_version = "SGN_merged"
150+
else:
151+
ratio = True
152+
stain2_name = "PV"
153+
stain2_file = [name for name in file_names if basename in name and "PV.tif" in name][0]
154+
stain2 = imageio.imread(os.path.join(direc, stain2_file))
155+
145156
seg_file = [name for name in file_names if basename in name and "SGN" in name][0]
146157

147158
if "PV" in seg_file:
148159
seg_version = f"PV_{seg_version}"
149160

150161
stain1_name = subtype
151-
stain2_name = "PV"
152162
seg_name = "SGN"
153163

154164
stain1 = imageio.imread(os.path.join(direc, stain1_file))
155-
stain2 = imageio.imread(os.path.join(direc, stain2_file))
156165
seg = imageio.imread(os.path.join(direc, seg_file))
157166

158167
# bb = np.s_[128:-128, 128:-128, 128:-128]
@@ -166,22 +175,33 @@ def sgn_subtype_annotation(prefix, subtype, seg_version="SGN_v2", default_stat="
166175
# Compute the intensity statistics.
167176
mask = None
168177

169-
cochlea = os.path.basename(stain2_file).split("_crop_")[0]
170-
171-
table_measurement_path = f"{cochlea}/tables/{seg_version}/subtype_ratio.tsv"
172-
print(table_measurement_path)
173-
table_path_s3, fs = get_s3_path(table_measurement_path)
174-
with fs.open(table_path_s3, "r") as f:
175-
table_measurement = pd.read_csv(f, sep="\t")
178+
cochlea = os.path.basename(stain1_file).split("_crop_")[0]
179+
180+
if ratio:
181+
table_measurement_path = f"{cochlea}/tables/{seg_version}/subtype_ratio.tsv"
182+
print(table_measurement_path)
183+
table_path_s3, fs = get_s3_path(table_measurement_path)
184+
with fs.open(table_path_s3, "r") as f:
185+
table_measurement = pd.read_csv(f, sep="\t")
186+
187+
subtype_ratio = f"{subtype}_ratio_PV"
188+
statistics = get_object_measures_from_table(seg, table=table_measurement, keyword=subtype_ratio)
189+
else:
190+
seg_string = "-".join(seg_version.split("_"))
191+
table_measurement_path = f"{cochlea}/tables/{seg_version}/{stain1_name}_{seg_string}_object-measures.tsv"
192+
print(table_measurement_path)
193+
table_path_s3, fs = get_s3_path(table_measurement_path)
194+
with fs.open(table_path_s3, "r") as f:
195+
table_measurement = pd.read_csv(f, sep="\t")
196+
statistics = get_object_measures_from_table(seg, table=table_measurement)
176197

177-
subtype_ratio = f"{subtype}_ratio_PV"
178-
statistics = get_object_measures_from_table(seg, table=table_measurement, keyword=subtype_ratio)
179198
# Open the napari viewer.
180199
v = napari.Viewer()
181200

182201
# Add the base layers.
183202
v.add_image(stain1, name=stain1_name)
184-
v.add_image(stain2, visible=False, name=stain2_name)
203+
if stain2 is not None:
204+
v.add_image(stain2, visible=False, name=stain2_name)
185205
v.add_labels(seg, visible=False, name=f"{seg_name}s")
186206
v.add_labels(seg_extended, name=f"{seg_name}s-extended")
187207
if mask is not None:

0 commit comments

Comments
 (0)