|
4 | 4 | import imageio.v3 as imageio |
5 | 5 | import napari |
6 | 6 | import numpy as np |
| 7 | +import pandas as pd |
7 | 8 |
|
8 | 9 | import matplotlib.pyplot as plt |
9 | 10 | import seaborn as sns |
|
14 | 15 | from elf.parallel.distance_transform import distance_transform |
15 | 16 | from elf.parallel.seeded_watershed import seeded_watershed |
16 | 17 |
|
17 | | -from flamingo_tools.measurements import compute_object_measures_impl |
| 18 | +from flamingo_tools.measurements import compute_object_measures_impl, get_object_measures_from_table |
| 19 | +from flamingo_tools.s3_utils import get_s3_path |
18 | 20 |
|
19 | 21 |
|
20 | 22 | class HistogramWidget(QWidget): |
@@ -132,7 +134,7 @@ def _create_mask(seg_extended, stain): |
132 | 134 | return mask |
133 | 135 |
|
134 | 136 |
|
135 | | -def gfp_annotation(prefix, default_stat="median", background_norm=None, is_otof=False): |
| 137 | +def gfp_annotation(prefix, default_stat="median", background_norm=None, is_otof=False, seg_version=None): |
136 | 138 | assert background_norm in (None, "division", "subtraction") |
137 | 139 |
|
138 | 140 | direc = os.path.dirname(os.path.abspath(prefix)) |
@@ -179,9 +181,22 @@ def gfp_annotation(prefix, default_stat="median", background_norm=None, is_otof= |
179 | 181 | mask = _create_mask(seg_extended, stain1) |
180 | 182 | assert mask.shape == seg_extended.shape |
181 | 183 | feature_set = "default_background_norm" if background_norm == "division" else "default_background_subtract" |
182 | | - statistics = compute_object_measures_impl( |
183 | | - stain1, seg_extended, feature_set=feature_set, background_mask=mask, median_only=True |
184 | | - ) |
| 184 | + |
| 185 | + if seg_version is not None: |
| 186 | + seg_string = "-".join(seg_version.split("_")) |
| 187 | + cochlea = os.path.basename(prefix).split("_crop_")[0] |
| 188 | + |
| 189 | + table_measurement_path = f"{cochlea}/tables/{seg_version}/{stain1_name}_{seg_string}_object-measures.tsv" |
| 190 | + table_path_s3, fs = get_s3_path(table_measurement_path) |
| 191 | + with fs.open(table_path_s3, "r") as f: |
| 192 | + table_measurement = pd.read_csv(f, sep="\t") |
| 193 | + |
| 194 | + statistics = get_object_measures_from_table(seg, table=table_measurement) |
| 195 | + |
| 196 | + else: |
| 197 | + statistics = compute_object_measures_impl( |
| 198 | + stain1, seg_extended, feature_set=feature_set, background_mask=mask, median_only=True |
| 199 | + ) |
185 | 200 |
|
186 | 201 | # Open the napari viewer. |
187 | 202 | v = napari.Viewer() |
@@ -281,9 +296,11 @@ def main(): |
281 | 296 | parser.add_argument("--otof", action="store_true", |
282 | 297 | help="Whether to run the annotation tool for otof samples with VGlut3, " |
283 | 298 | "Alphatag and IHC segmentation.") # noqa |
| 299 | + parser.add_argument("--seg_version", type=str, default=None, |
| 300 | + help="Supply segmentation version, e.g. SGN_v2, to use intensities from object measure table.") |
284 | 301 | args = parser.parse_args() |
285 | 302 |
|
286 | | - gfp_annotation(args.prefix, background_norm=args.background_norm, is_otof=args.otof) |
| 303 | + gfp_annotation(args.prefix, background_norm=args.background_norm, is_otof=args.otof, seg_version=args.seg_version) |
287 | 304 |
|
288 | 305 |
|
289 | 306 | if __name__ == "__main__": |
|
0 commit comments