From c7ea296f185f78e0945e3751f194d965759f90f1 Mon Sep 17 00:00:00 2001 From: Eduardo Hirata-Miyasaki Date: Wed, 20 Nov 2024 23:38:49 -0800 Subject: [PATCH 1/3] adding phate --- src/napari_iohub/_view_tracks.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/napari_iohub/_view_tracks.py b/src/napari_iohub/_view_tracks.py index bd1edec..c0021bb 100644 --- a/src/napari_iohub/_view_tracks.py +++ b/src/napari_iohub/_view_tracks.py @@ -23,13 +23,19 @@ def _zarr_modes(label: str) -> dict[str, str]: def _load_features(features_path: pathlib.Path, fov_name: str) -> pandas.DataFrame: - """Load UMAP coordinates from Zarr store.""" + """Load UMAP and PHATE coordinates from Zarr store if PHATE exists.""" + ds = open_zarr(features_path).set_index( + sample=["fov_name", "track_id", "t", "UMAP1", "UMAP2"] + ) + if "PHATE1" in ds.sample and "PHATE2" in ds.sample: + ds = ds.set_index(sample=["PHATE1", "PHATE2"], append=True) + coords = ["UMAP1", "UMAP2", "PHATE1", "PHATE2"] + else: + coords = ["UMAP1", "UMAP2"] return ( - open_zarr(features_path) - .set_index(sample=["fov_name", "track_id", "t", "UMAP1", "UMAP2"]) - .sel(fov_name=fov_name)["sample"] + ds.sel(fov_name=fov_name)["sample"] .to_dataframe() - .reset_index(drop=True)[["track_id", "t", "UMAP1", "UMAP2"]] + .reset_index(drop=True)[["track_id", "t"] + coords] .rename(columns={"track_id": "label", "t": "frame"}) ) From 1630c5f82725ca5efe726fdbe7ea1ac0e6aad60f Mon Sep 17 00:00:00 2001 From: Ziwen Liu Date: Thu, 21 Nov 2024 10:00:43 -0800 Subject: [PATCH 2/3] build dynamic list of dimensionality reductions only load UMAP or PHATE coordinates it available --- src/napari_iohub/_view_tracks.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/napari_iohub/_view_tracks.py b/src/napari_iohub/_view_tracks.py index c0021bb..87de8c1 100644 --- a/src/napari_iohub/_view_tracks.py +++ b/src/napari_iohub/_view_tracks.py @@ -24,18 +24,17 @@ def _zarr_modes(label: str) -> dict[str, str]: def _load_features(features_path: pathlib.Path, fov_name: str) -> pandas.DataFrame: """Load UMAP and PHATE coordinates from Zarr store if PHATE exists.""" - ds = open_zarr(features_path).set_index( - sample=["fov_name", "track_id", "t", "UMAP1", "UMAP2"] - ) - if "PHATE1" in ds.sample and "PHATE2" in ds.sample: - ds = ds.set_index(sample=["PHATE1", "PHATE2"], append=True) - coords = ["UMAP1", "UMAP2", "PHATE1", "PHATE2"] - else: - coords = ["UMAP1", "UMAP2"] + ds = open_zarr(features_path) + coords = ["fov_name", "track_id", "t"] + reductions = ["UMAP1", "UMAP2", "PHATE1", "PHATE2"] + for dim in reductions: + if dim in ds: + coords.append(dim) + ds = ds.set_index(sample=coords) return ( ds.sel(fov_name=fov_name)["sample"] .to_dataframe() - .reset_index(drop=True)[["track_id", "t"] + coords] + .reset_index(drop=True)[coords[1:]] .rename(columns={"track_id": "label", "t": "frame"}) ) From bc8604f821ad7616521f37773bfa3cbdce7dc244 Mon Sep 17 00:00:00 2001 From: Ziwen Liu Date: Thu, 21 Nov 2024 10:03:50 -0800 Subject: [PATCH 3/3] tweak docstring --- src/napari_iohub/_view_tracks.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/napari_iohub/_view_tracks.py b/src/napari_iohub/_view_tracks.py index 87de8c1..76d5656 100644 --- a/src/napari_iohub/_view_tracks.py +++ b/src/napari_iohub/_view_tracks.py @@ -23,7 +23,7 @@ def _zarr_modes(label: str) -> dict[str, str]: def _load_features(features_path: pathlib.Path, fov_name: str) -> pandas.DataFrame: - """Load UMAP and PHATE coordinates from Zarr store if PHATE exists.""" + """Load UMAP and PHATE coordinates from Zarr store if they exist.""" ds = open_zarr(features_path) coords = ["fov_name", "track_id", "t"] reductions = ["UMAP1", "UMAP2", "PHATE1", "PHATE2"]