From 4264731346731a74f81937aed72991fcf80fc7a4 Mon Sep 17 00:00:00 2001 From: ArneD Date: Tue, 10 Dec 2024 10:01:12 +0100 Subject: [PATCH] Sc 40 issue cluster intensity (#78) * SC_40 issue with coordinate system cluster intensity * SC_40 update notebook * SC_40 update flowsom clustering notebook * SC_40 example with multiple coordinate systems for flowsom clustering --- README.md | 8 +- ...lowSOM_for_pixel_and_cell_clustering.ipynb | 1438 ++++++++++++----- src/harpy/datasets/pixie_example.py | 12 +- .../table/cell_clustering/_preprocess.py | 2 +- .../pixel_clustering/_cluster_intensity.py | 21 +- 5 files changed, 1051 insertions(+), 430 deletions(-) diff --git a/README.md b/README.md index ac12af3..033bcbd 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Note: This package is still under very active development. ## Installation -Check out the docs for [installation instructions](docs/installation.md). +Check out the docs for [installation instructions](https://github.com/saeyslab/harpy/blob/main/docs/installation.md). ## Tutorials @@ -25,11 +25,11 @@ Tutorials are available [here](https://harpy.readthedocs.io/en/latest/). ## Usage -[Learn](docs/usage.md) how Harpy can be integrated into your workflow in different ways. +[Learn](https://github.com/saeyslab/harpy/blob/main/docs/usage.md) how Harpy can be integrated into your workflow in different ways. ## Contributing -See [here](docs/contributing.md) for info on how to contribute to Harpy. +See [here](https://github.com/saeyslab/harpy/blob/main/docs/contributing.md) for info on how to contribute to Harpy. ## References @@ -37,7 +37,7 @@ See [here](docs/contributing.md) for info on how to contribute to Harpy. ## License -Check license under license. Harpy is free for academic usage. +Check the [license](https://github.com/saeyslab/harpy/blob/main/LICENSE). Harpy is free for academic usage. For commercial usage, please contact Saeyslab. ## Issues diff --git a/docs/tutorials/general/FlowSOM_for_pixel_and_cell_clustering.ipynb b/docs/tutorials/general/FlowSOM_for_pixel_and_cell_clustering.ipynb index 114df67..1325a24 100644 --- a/docs/tutorials/general/FlowSOM_for_pixel_and_cell_clustering.ipynb +++ b/docs/tutorials/general/FlowSOM_for_pixel_and_cell_clustering.ipynb @@ -9,15 +9,15 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 1, "metadata": {}, "outputs": [ { - "name": "stdout", + "name": "stderr", "output_type": "stream", "text": [ - "The autoreload extension is already loaded. To reload it, use:\n", - " %reload_ext autoreload\n" + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/dask/dataframe/__init__.py:31: FutureWarning: The legacy Dask DataFrame implementation is deprecated and will be removed in a future version. Set the configuration option `dataframe.query-planning` to `True` or None to enable the new Dask Dataframe implementation and silence this warning.\n", + " warnings.warn(\n" ] } ], @@ -41,41 +41,43 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2024-06-14 10:18:53,290 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:53,348 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov0'\n", - "2024-06-14 10:18:53,351 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:53,357 - harpy.image._manager - INFO - Writing results to layer 'label_nuclear_fov0'\n", - "2024-06-14 10:18:53,359 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:53,365 - harpy.image._manager - INFO - Writing results to layer 'label_whole_fov0'\n", - "2024-06-14 10:18:53,394 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n" + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", + " from .autonotebook import tqdm as notebook_tqdm\n", + "2024-12-10 09:46:33,318 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:33,401 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov0'\n", + "2024-12-10 09:46:33,403 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:33,408 - harpy.image._manager - INFO - Writing results to layer 'label_nuclear_fov0'\n", + "2024-12-10 09:46:33,410 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:33,414 - harpy.image._manager - INFO - Writing results to layer 'label_whole_fov0'\n", + "2024-12-10 09:46:33,436 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "/Users/benjaminr/.cache/huggingface/datasets/downloads/extracted/ccde124668e88cec60561ae6aa0b5dd0317fef8e1096373c8ac24b309eefd749/post_clustering\n" + "/Users/arnedf/.cache/huggingface/datasets/downloads/extracted/ed276a09a07145a5c25cd3c0a3fd99368fc2f3387300f55927c0b600c043de39/post_clustering\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ - "2024-06-14 10:18:53,518 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov1'\n", - "2024-06-14 10:18:53,520 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:53,550 - harpy.image._manager - INFO - Writing results to layer 'label_nuclear_fov1'\n", - "2024-06-14 10:18:53,571 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:53,580 - harpy.image._manager - INFO - Writing results to layer 'label_whole_fov1'\n", - "/opt/homebrew/Caskroom/mambaforge/base/envs/harpy/lib/python3.10/site-packages/anndata/_core/anndata.py:183: ImplicitModificationWarning: Transforming to str index.\n", + "2024-12-10 09:46:33,539 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov1'\n", + "2024-12-10 09:46:33,541 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:33,546 - harpy.image._manager - INFO - Writing results to layer 'label_nuclear_fov1'\n", + "2024-12-10 09:46:33,548 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:33,553 - harpy.image._manager - INFO - Writing results to layer 'label_whole_fov1'\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/anndata/_core/aligned_df.py:67: ImplicitModificationWarning: Transforming to str index.\n", " warnings.warn(\"Transforming to str index.\", ImplicitModificationWarning)\n", - "/opt/homebrew/Caskroom/mambaforge/base/envs/harpy/lib/python3.10/site-packages/spatialdata/models/models.py:929: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/models/models.py:1046: ImplicitModificationWarning: Trying to modify attribute `._uns` of view, initializing view as actual.\n", " adata.uns[cls.ATTRS_KEY] = attr\n" ] }, @@ -84,21 +86,23 @@ "text/plain": [ "SpatialData object\n", "├── Images\n", - "│ ├── 'raw_image_fov0': SpatialImage[cyx] (22, 512, 512)\n", - "│ └── 'raw_image_fov1': SpatialImage[cyx] (22, 1024, 1024)\n", + "│ ├── 'raw_image_fov0': DataArray[cyx] (22, 512, 512)\n", + "│ └── 'raw_image_fov1': DataArray[cyx] (22, 1024, 1024)\n", "├── Labels\n", - "│ ├── 'label_nuclear_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_nuclear_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'label_whole_fov0': SpatialImage[yx] (512, 512)\n", - "│ └── 'label_whole_fov1': SpatialImage[yx] (1024, 1024)\n", + "│ ├── 'label_nuclear_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_nuclear_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'label_whole_fov0': DataArray[yx] (512, 512)\n", + "│ └── 'label_whole_fov1': DataArray[yx] (1024, 1024)\n", "└── Tables\n", " └── 'table': AnnData (1414, 22)\n", "with coordinate systems:\n", - " ▸ 'global', with elements:\n", - " raw_image_fov0 (Images), raw_image_fov1 (Images), label_nuclear_fov0 (Labels), label_nuclear_fov1 (Labels), label_whole_fov0 (Labels), label_whole_fov1 (Labels)" + " ▸ 'fov0', with elements:\n", + " raw_image_fov0 (Images), label_nuclear_fov0 (Labels), label_whole_fov0 (Labels)\n", + " ▸ 'fov1', with elements:\n", + " raw_image_fov1 (Images), label_nuclear_fov1 (Labels), label_whole_fov1 (Labels)" ] }, - "execution_count": 5, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -110,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -136,17 +140,17 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2024-06-14 10:18:54,056 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:54,549 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov0_processed'\n", - "2024-06-14 10:18:54,552 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:54,890 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov1_processed'\n" + "2024-12-10 09:46:33,984 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:34,839 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov0_processed'\n", + "2024-12-10 09:46:34,841 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:35,665 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov1_processed'\n" ] }, { @@ -154,23 +158,25 @@ "text/plain": [ "SpatialData object\n", "├── Images\n", - "│ ├── 'raw_image_fov0': SpatialImage[cyx] (22, 512, 512)\n", - "│ ├── 'raw_image_fov0_processed': SpatialImage[cyx] (16, 512, 512)\n", - "│ ├── 'raw_image_fov1': SpatialImage[cyx] (22, 1024, 1024)\n", - "│ └── 'raw_image_fov1_processed': SpatialImage[cyx] (16, 1024, 1024)\n", + "│ ├── 'raw_image_fov0': DataArray[cyx] (22, 512, 512)\n", + "│ ├── 'raw_image_fov0_processed': DataArray[cyx] (16, 512, 512)\n", + "│ ├── 'raw_image_fov1': DataArray[cyx] (22, 1024, 1024)\n", + "│ └── 'raw_image_fov1_processed': DataArray[cyx] (16, 1024, 1024)\n", "├── Labels\n", - "│ ├── 'label_nuclear_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_nuclear_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'label_whole_fov0': SpatialImage[yx] (512, 512)\n", - "│ └── 'label_whole_fov1': SpatialImage[yx] (1024, 1024)\n", + "│ ├── 'label_nuclear_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_nuclear_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'label_whole_fov0': DataArray[yx] (512, 512)\n", + "│ └── 'label_whole_fov1': DataArray[yx] (1024, 1024)\n", "└── Tables\n", " └── 'table': AnnData (1414, 22)\n", "with coordinate systems:\n", - " ▸ 'global', with elements:\n", - " raw_image_fov0 (Images), raw_image_fov0_processed (Images), raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov0 (Labels), label_nuclear_fov1 (Labels), label_whole_fov0 (Labels), label_whole_fov1 (Labels)" + " ▸ 'fov0', with elements:\n", + " raw_image_fov0 (Images), raw_image_fov0_processed (Images), label_nuclear_fov0 (Labels), label_whole_fov0 (Labels)\n", + " ▸ 'fov1', with elements:\n", + " raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov1 (Labels), label_whole_fov1 (Labels)" ] }, - "execution_count": 7, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -190,24 +196,24 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "\u001b[32m2024-06-14 10:18:55.164\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m84\u001b[0m - \u001b[34m\u001b[1mReading input.\u001b[0m\n", - "\u001b[32m2024-06-14 10:18:55.165\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m86\u001b[0m - \u001b[34m\u001b[1mFitting model: clustering and metaclustering.\u001b[0m\n", - "\u001b[32m2024-06-14 10:18:58.077\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m88\u001b[0m - \u001b[34m\u001b[1mUpdating derived values.\u001b[0m\n", - "2024-06-14 10:18:58,601 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:59,231 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov0_flowsom_clusters'\n", - "2024-06-14 10:18:59,232 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:18:59,625 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov0_flowsom_metaclusters'\n", - "2024-06-14 10:18:59,627 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:19:00,514 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov1_flowsom_clusters'\n", - "2024-06-14 10:19:00,515 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is (c, (z), y, x)\n", - "2024-06-14 10:19:01,370 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov1_flowsom_metaclusters'\n" + "\u001b[32m2024-12-10 09:46:35.835\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m84\u001b[0m - \u001b[34m\u001b[1mReading input.\u001b[0m\n", + "\u001b[32m2024-12-10 09:46:35.836\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m86\u001b[0m - \u001b[34m\u001b[1mFitting model: clustering and metaclustering.\u001b[0m\n", + "\u001b[32m2024-12-10 09:46:37.821\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m88\u001b[0m - \u001b[34m\u001b[1mUpdating derived values.\u001b[0m\n", + "2024-12-10 09:46:38,138 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:38,618 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov0_flowsom_clusters'\n", + "2024-12-10 09:46:38,618 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:38,904 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov0_flowsom_metaclusters'\n", + "2024-12-10 09:46:38,956 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:39,650 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov1_flowsom_clusters'\n", + "2024-12-10 09:46:39,650 - harpy.image._manager - WARNING - No dims parameter specified. Assuming order of dimension of provided array is ((c), (z), y, x)\n", + "2024-12-10 09:46:40,267 - harpy.image._manager - INFO - Writing results to layer 'raw_image_fov1_flowsom_metaclusters'\n" ] }, { @@ -215,27 +221,29 @@ "text/plain": [ "SpatialData object\n", "├── Images\n", - "│ ├── 'raw_image_fov0': SpatialImage[cyx] (22, 512, 512)\n", - "│ ├── 'raw_image_fov0_processed': SpatialImage[cyx] (16, 512, 512)\n", - "│ ├── 'raw_image_fov1': SpatialImage[cyx] (22, 1024, 1024)\n", - "│ └── 'raw_image_fov1_processed': SpatialImage[cyx] (16, 1024, 1024)\n", + "│ ├── 'raw_image_fov0': DataArray[cyx] (22, 512, 512)\n", + "│ ├── 'raw_image_fov0_processed': DataArray[cyx] (16, 512, 512)\n", + "│ ├── 'raw_image_fov1': DataArray[cyx] (22, 1024, 1024)\n", + "│ └── 'raw_image_fov1_processed': DataArray[cyx] (16, 1024, 1024)\n", "├── Labels\n", - "│ ├── 'label_nuclear_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_nuclear_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'label_whole_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_whole_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'raw_image_fov0_flowsom_clusters': SpatialImage[yx] (512, 512)\n", - "│ ├── 'raw_image_fov0_flowsom_metaclusters': SpatialImage[yx] (512, 512)\n", - "│ ├── 'raw_image_fov1_flowsom_clusters': SpatialImage[yx] (1024, 1024)\n", - "│ └── 'raw_image_fov1_flowsom_metaclusters': SpatialImage[yx] (1024, 1024)\n", + "│ ├── 'label_nuclear_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_nuclear_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'label_whole_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_whole_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'raw_image_fov0_flowsom_clusters': DataArray[yx] (512, 512)\n", + "│ ├── 'raw_image_fov0_flowsom_metaclusters': DataArray[yx] (512, 512)\n", + "│ ├── 'raw_image_fov1_flowsom_clusters': DataArray[yx] (1024, 1024)\n", + "│ └── 'raw_image_fov1_flowsom_metaclusters': DataArray[yx] (1024, 1024)\n", "└── Tables\n", " └── 'table': AnnData (1414, 22)\n", "with coordinate systems:\n", - " ▸ 'global', with elements:\n", - " raw_image_fov0 (Images), raw_image_fov0_processed (Images), raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov0 (Labels), label_nuclear_fov1 (Labels), label_whole_fov0 (Labels), label_whole_fov1 (Labels), raw_image_fov0_flowsom_clusters (Labels), raw_image_fov0_flowsom_metaclusters (Labels), raw_image_fov1_flowsom_clusters (Labels), raw_image_fov1_flowsom_metaclusters (Labels)" + " ▸ 'fov0', with elements:\n", + " raw_image_fov0 (Images), raw_image_fov0_processed (Images), label_nuclear_fov0 (Labels), label_whole_fov0 (Labels), raw_image_fov0_flowsom_clusters (Labels), raw_image_fov0_flowsom_metaclusters (Labels)\n", + " ▸ 'fov1', with elements:\n", + " raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov1 (Labels), label_whole_fov1 (Labels), raw_image_fov1_flowsom_clusters (Labels), raw_image_fov1_flowsom_metaclusters (Labels)" ] }, - "execution_count": 8, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -259,26 +267,26 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "/Users/benjaminr/Documents/GitHub/harpy/src/harpy/table/_allocation_intensity.py:210: ImplicitModificationWarning: Setting element `.obsm['spatial']` of view, initializing view as actual.\n", - " adata.obsm[\"spatial\"] = coordinates\n", - "/Users/benjaminr/Documents/GitHub/harpy/src/harpy/table/_allocation_intensity.py:210: ImplicitModificationWarning: Setting element `.obsm['spatial']` of view, initializing view as actual.\n", - " adata.obsm[\"spatial\"] = coordinates\n", - "/opt/homebrew/Caskroom/mambaforge/base/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:122: UserWarning: Key `counts_clusters` already exists. Overwriting it in-memory.\n", + "/Users/arnedf/VIB/harpy/src/harpy/table/_allocation_intensity.py:217: ImplicitModificationWarning: Setting element `.obsm['spatial']` of view, initializing view as actual.\n", + " adata.obsm[_SPATIAL] = coordinates\n", + "/Users/arnedf/VIB/harpy/src/harpy/table/_allocation_intensity.py:217: ImplicitModificationWarning: Setting element `.obsm['spatial']` of view, initializing view as actual.\n", + " adata.obsm[_SPATIAL] = coordinates\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:116: UserWarning: Key `counts_clusters` already exists. Overwriting it in-memory.\n", " self._check_key(key, self.keys(), self._shared_keys)\n", - "2024-06-14 10:19:02,922 - harpy.table._preprocess - INFO - Calculating cell size from provided labels_layer 'raw_image_fov0_flowsom_clusters'\n", - "2024-06-14 10:19:02,929 - harpy.table._preprocess - INFO - Calculating cell size from provided labels_layer 'raw_image_fov1_flowsom_clusters'\n", - "/Users/benjaminr/Documents/GitHub/harpy/src/harpy/table/_manager.py:33: UserWarning: Converting `region_key: fov_labels` to categorical dtype.\n", - " adata = spatialdata.models.TableModel.parse(\n", - "/opt/homebrew/Caskroom/mambaforge/base/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:122: UserWarning: Key `counts_clusters` already exists. Overwriting it in-memory.\n", + "2024-12-10 09:46:42,395 - harpy.table._preprocess - INFO - Calculating cell size from provided labels_layer 'raw_image_fov0_flowsom_clusters'\n", + "2024-12-10 09:46:42,412 - harpy.table._preprocess - INFO - Calculating cell size from provided labels_layer 'raw_image_fov1_flowsom_clusters'\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/models/models.py:1048: UserWarning: Converting `region_key: fov_labels` to categorical dtype.\n", + " return convert_region_column_to_categorical(adata)\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:116: UserWarning: Key `counts_clusters` already exists. Overwriting it in-memory.\n", " self._check_key(key, self.keys(), self._shared_keys)\n", - "/opt/homebrew/Caskroom/mambaforge/base/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:122: UserWarning: Key `counts_clusters` already exists. Overwriting it in-memory.\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:116: UserWarning: Key `counts_clusters` already exists. Overwriting it in-memory.\n", " self._check_key(key, self.keys(), self._shared_keys)\n" ] }, @@ -287,28 +295,30 @@ "text/plain": [ "SpatialData object\n", "├── Images\n", - "│ ├── 'raw_image_fov0': SpatialImage[cyx] (22, 512, 512)\n", - "│ ├── 'raw_image_fov0_processed': SpatialImage[cyx] (16, 512, 512)\n", - "│ ├── 'raw_image_fov1': SpatialImage[cyx] (22, 1024, 1024)\n", - "│ └── 'raw_image_fov1_processed': SpatialImage[cyx] (16, 1024, 1024)\n", + "│ ├── 'raw_image_fov0': DataArray[cyx] (22, 512, 512)\n", + "│ ├── 'raw_image_fov0_processed': DataArray[cyx] (16, 512, 512)\n", + "│ ├── 'raw_image_fov1': DataArray[cyx] (22, 1024, 1024)\n", + "│ └── 'raw_image_fov1_processed': DataArray[cyx] (16, 1024, 1024)\n", "├── Labels\n", - "│ ├── 'label_nuclear_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_nuclear_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'label_whole_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_whole_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'raw_image_fov0_flowsom_clusters': SpatialImage[yx] (512, 512)\n", - "│ ├── 'raw_image_fov0_flowsom_metaclusters': SpatialImage[yx] (512, 512)\n", - "│ ├── 'raw_image_fov1_flowsom_clusters': SpatialImage[yx] (1024, 1024)\n", - "│ └── 'raw_image_fov1_flowsom_metaclusters': SpatialImage[yx] (1024, 1024)\n", + "│ ├── 'label_nuclear_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_nuclear_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'label_whole_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_whole_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'raw_image_fov0_flowsom_clusters': DataArray[yx] (512, 512)\n", + "│ ├── 'raw_image_fov0_flowsom_metaclusters': DataArray[yx] (512, 512)\n", + "│ ├── 'raw_image_fov1_flowsom_clusters': DataArray[yx] (1024, 1024)\n", + "│ └── 'raw_image_fov1_flowsom_metaclusters': DataArray[yx] (1024, 1024)\n", "└── Tables\n", " ├── 'counts_clusters': AnnData (100, 16)\n", " └── 'table': AnnData (1414, 22)\n", "with coordinate systems:\n", - " ▸ 'global', with elements:\n", - " raw_image_fov0 (Images), raw_image_fov0_processed (Images), raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov0 (Labels), label_nuclear_fov1 (Labels), label_whole_fov0 (Labels), label_whole_fov1 (Labels), raw_image_fov0_flowsom_clusters (Labels), raw_image_fov0_flowsom_metaclusters (Labels), raw_image_fov1_flowsom_clusters (Labels), raw_image_fov1_flowsom_metaclusters (Labels)" + " ▸ 'fov0', with elements:\n", + " raw_image_fov0 (Images), raw_image_fov0_processed (Images), label_nuclear_fov0 (Labels), label_whole_fov0 (Labels), raw_image_fov0_flowsom_clusters (Labels), raw_image_fov0_flowsom_metaclusters (Labels)\n", + " ▸ 'fov1', with elements:\n", + " raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov1 (Labels), label_whole_fov1 (Labels), raw_image_fov1_flowsom_clusters (Labels), raw_image_fov1_flowsom_metaclusters (Labels)" ] }, - "execution_count": 9, + "execution_count": 6, "metadata": {}, "output_type": "execute_result" } @@ -319,35 +329,34 @@ " mapping=mapping,\n", " img_layer=[\"raw_image_fov0_processed\", \"raw_image_fov1_processed\"],\n", " labels_layer=[\"raw_image_fov0_flowsom_clusters\", \"raw_image_fov1_flowsom_clusters\"],\n", - " # labels_layer=\"raw_image_fov0_flowsom_clusters\",\n", + " to_coordinate_system=[ \"fov0\", \"fov1\" ],\n", " output_layer=\"counts_clusters\",\n", " overwrite=True,\n", ")\n", - "# Note: to visualize in napari-spatialdata, this counts_clusters table layer needs to be removed for now. See https://github.com/scverse/napari-spatialdata/issues/244\n", "sdata_ark_analysis" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2024-06-14 10:19:03,234 - harpy.table._preprocess - INFO - Calculating cell size from provided labels_layer 'label_whole_fov0'\n", - "2024-06-14 10:19:03,241 - harpy.table._preprocess - INFO - Calculating cell size from provided labels_layer 'label_whole_fov1'\n", - "/Users/benjaminr/Documents/GitHub/harpy/src/harpy/table/_manager.py:33: UserWarning: Converting `region_key: fov_labels` to categorical dtype.\n", - " adata = spatialdata.models.TableModel.parse(\n", - "/opt/homebrew/Caskroom/mambaforge/base/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:122: UserWarning: Key `table_cell_clustering_flowsom` already exists. Overwriting it in-memory.\n", + "2024-12-10 09:46:42,627 - harpy.table._preprocess - INFO - Calculating cell size from provided labels_layer 'label_whole_fov0'\n", + "2024-12-10 09:46:42,643 - harpy.table._preprocess - INFO - Calculating cell size from provided labels_layer 'label_whole_fov1'\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/models/models.py:1048: UserWarning: Converting `region_key: fov_labels` to categorical dtype.\n", + " return convert_region_column_to_categorical(adata)\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:116: UserWarning: Key `table_cell_clustering_flowsom` already exists. Overwriting it in-memory.\n", " self._check_key(key, self.keys(), self._shared_keys)\n", - "\u001b[32m2024-06-14 10:19:03.270\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m84\u001b[0m - \u001b[34m\u001b[1mReading input.\u001b[0m\n", - "\u001b[32m2024-06-14 10:19:03.271\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m86\u001b[0m - \u001b[34m\u001b[1mFitting model: clustering and metaclustering.\u001b[0m\n", - "\u001b[32m2024-06-14 10:19:03.302\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m88\u001b[0m - \u001b[34m\u001b[1mUpdating derived values.\u001b[0m\n", - "2024-06-14 10:19:03,514 - harpy.table.cell_clustering._clustering - INFO - Adding mean cluster intensity to '.uns['clustering']'\n", - "2024-06-14 10:19:03,535 - harpy.table.cell_clustering._clustering - INFO - Adding mean cluster intensity to '.uns['metaclustering']'\n", - "/opt/homebrew/Caskroom/mambaforge/base/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:122: UserWarning: Key `table_cell_clustering_flowsom` already exists. Overwriting it in-memory.\n", + "\u001b[32m2024-12-10 09:46:42.688\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m84\u001b[0m - \u001b[34m\u001b[1mReading input.\u001b[0m\n", + "\u001b[32m2024-12-10 09:46:42.689\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m86\u001b[0m - \u001b[34m\u001b[1mFitting model: clustering and metaclustering.\u001b[0m\n", + "\u001b[32m2024-12-10 09:46:42.711\u001b[0m | \u001b[34m\u001b[1mDEBUG \u001b[0m | \u001b[36mflowsom.main\u001b[0m:\u001b[36m__init__\u001b[0m:\u001b[36m88\u001b[0m - \u001b[34m\u001b[1mUpdating derived values.\u001b[0m\n", + "2024-12-10 09:46:42,840 - harpy.table.cell_clustering._clustering - INFO - Adding mean cluster intensity to '.uns['clustering']'\n", + "2024-12-10 09:46:42,853 - harpy.table.cell_clustering._clustering - INFO - Adding mean cluster intensity to '.uns['metaclustering']'\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:116: UserWarning: Key `table_cell_clustering_flowsom` already exists. Overwriting it in-memory.\n", " self._check_key(key, self.keys(), self._shared_keys)\n" ] }, @@ -356,29 +365,31 @@ "text/plain": [ "SpatialData object\n", "├── Images\n", - "│ ├── 'raw_image_fov0': SpatialImage[cyx] (22, 512, 512)\n", - "│ ├── 'raw_image_fov0_processed': SpatialImage[cyx] (16, 512, 512)\n", - "│ ├── 'raw_image_fov1': SpatialImage[cyx] (22, 1024, 1024)\n", - "│ └── 'raw_image_fov1_processed': SpatialImage[cyx] (16, 1024, 1024)\n", + "│ ├── 'raw_image_fov0': DataArray[cyx] (22, 512, 512)\n", + "│ ├── 'raw_image_fov0_processed': DataArray[cyx] (16, 512, 512)\n", + "│ ├── 'raw_image_fov1': DataArray[cyx] (22, 1024, 1024)\n", + "│ └── 'raw_image_fov1_processed': DataArray[cyx] (16, 1024, 1024)\n", "├── Labels\n", - "│ ├── 'label_nuclear_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_nuclear_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'label_whole_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_whole_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'raw_image_fov0_flowsom_clusters': SpatialImage[yx] (512, 512)\n", - "│ ├── 'raw_image_fov0_flowsom_metaclusters': SpatialImage[yx] (512, 512)\n", - "│ ├── 'raw_image_fov1_flowsom_clusters': SpatialImage[yx] (1024, 1024)\n", - "│ └── 'raw_image_fov1_flowsom_metaclusters': SpatialImage[yx] (1024, 1024)\n", + "│ ├── 'label_nuclear_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_nuclear_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'label_whole_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_whole_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'raw_image_fov0_flowsom_clusters': DataArray[yx] (512, 512)\n", + "│ ├── 'raw_image_fov0_flowsom_metaclusters': DataArray[yx] (512, 512)\n", + "│ ├── 'raw_image_fov1_flowsom_clusters': DataArray[yx] (1024, 1024)\n", + "│ └── 'raw_image_fov1_flowsom_metaclusters': DataArray[yx] (1024, 1024)\n", "└── Tables\n", " ├── 'counts_clusters': AnnData (100, 16)\n", " ├── 'table': AnnData (1414, 22)\n", " └── 'table_cell_clustering_flowsom': AnnData (1409, 20)\n", "with coordinate systems:\n", - " ▸ 'global', with elements:\n", - " raw_image_fov0 (Images), raw_image_fov0_processed (Images), raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov0 (Labels), label_nuclear_fov1 (Labels), label_whole_fov0 (Labels), label_whole_fov1 (Labels), raw_image_fov0_flowsom_clusters (Labels), raw_image_fov0_flowsom_metaclusters (Labels), raw_image_fov1_flowsom_clusters (Labels), raw_image_fov1_flowsom_metaclusters (Labels)" + " ▸ 'fov0', with elements:\n", + " raw_image_fov0 (Images), raw_image_fov0_processed (Images), label_nuclear_fov0 (Labels), label_whole_fov0 (Labels), raw_image_fov0_flowsom_clusters (Labels), raw_image_fov0_flowsom_metaclusters (Labels)\n", + " ▸ 'fov1', with elements:\n", + " raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov1 (Labels), label_whole_fov1 (Labels), raw_image_fov1_flowsom_clusters (Labels), raw_image_fov1_flowsom_metaclusters (Labels)" ] }, - "execution_count": 10, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -401,17 +412,17 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2024-06-14 10:19:03,666 - harpy.table.cell_clustering._weighted_channel_expression - INFO - Adding mean over obtained cell clusters '(clustering)' of the average marker expression for each cell weighted by pixel cluster count to '.uns[ 'clustering_channels' ]' of table layer 'table_cell_clustering_flowsom'\n", - "2024-06-14 10:19:03,670 - harpy.table.cell_clustering._weighted_channel_expression - INFO - Adding mean over obtained cell clusters '(metaclustering)' of the average marker expression for each cell weighted by pixel cluster count to '.uns[ 'metaclustering_channels' ]' of table layer 'table_cell_clustering_flowsom'\n", - "2024-06-14 10:19:03,670 - harpy.table.cell_clustering._weighted_channel_expression - INFO - Adding average marker expression for each cell weighted by pixel cluster count to '.obs' of table layer 'table_cell_clustering_flowsom'\n", - "/opt/homebrew/Caskroom/mambaforge/base/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:122: UserWarning: Key `table_cell_clustering_flowsom` already exists. Overwriting it in-memory.\n", + "2024-12-10 09:46:42,910 - harpy.table.cell_clustering._weighted_channel_expression - INFO - Adding mean over obtained cell clusters '(clustering)' of the average marker expression for each cell weighted by pixel cluster count to '.uns[ 'clustering_channels' ]' of table layer 'table_cell_clustering_flowsom'\n", + "2024-12-10 09:46:42,931 - harpy.table.cell_clustering._weighted_channel_expression - INFO - Adding mean over obtained cell clusters '(metaclustering)' of the average marker expression for each cell weighted by pixel cluster count to '.uns[ 'metaclustering_channels' ]' of table layer 'table_cell_clustering_flowsom'\n", + "2024-12-10 09:46:42,933 - harpy.table.cell_clustering._weighted_channel_expression - INFO - Adding average marker expression for each cell weighted by pixel cluster count to '.obs' of table layer 'table_cell_clustering_flowsom'\n", + "/Users/arnedf/miniconda3/envs/harpy/lib/python3.10/site-packages/spatialdata/_core/_elements.py:116: UserWarning: Key `table_cell_clustering_flowsom` already exists. Overwriting it in-memory.\n", " self._check_key(key, self.keys(), self._shared_keys)\n" ] }, @@ -420,29 +431,31 @@ "text/plain": [ "SpatialData object\n", "├── Images\n", - "│ ├── 'raw_image_fov0': SpatialImage[cyx] (22, 512, 512)\n", - "│ ├── 'raw_image_fov0_processed': SpatialImage[cyx] (16, 512, 512)\n", - "│ ├── 'raw_image_fov1': SpatialImage[cyx] (22, 1024, 1024)\n", - "│ └── 'raw_image_fov1_processed': SpatialImage[cyx] (16, 1024, 1024)\n", + "│ ├── 'raw_image_fov0': DataArray[cyx] (22, 512, 512)\n", + "│ ├── 'raw_image_fov0_processed': DataArray[cyx] (16, 512, 512)\n", + "│ ├── 'raw_image_fov1': DataArray[cyx] (22, 1024, 1024)\n", + "│ └── 'raw_image_fov1_processed': DataArray[cyx] (16, 1024, 1024)\n", "├── Labels\n", - "│ ├── 'label_nuclear_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_nuclear_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'label_whole_fov0': SpatialImage[yx] (512, 512)\n", - "│ ├── 'label_whole_fov1': SpatialImage[yx] (1024, 1024)\n", - "│ ├── 'raw_image_fov0_flowsom_clusters': SpatialImage[yx] (512, 512)\n", - "│ ├── 'raw_image_fov0_flowsom_metaclusters': SpatialImage[yx] (512, 512)\n", - "│ ├── 'raw_image_fov1_flowsom_clusters': SpatialImage[yx] (1024, 1024)\n", - "│ └── 'raw_image_fov1_flowsom_metaclusters': SpatialImage[yx] (1024, 1024)\n", + "│ ├── 'label_nuclear_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_nuclear_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'label_whole_fov0': DataArray[yx] (512, 512)\n", + "│ ├── 'label_whole_fov1': DataArray[yx] (1024, 1024)\n", + "│ ├── 'raw_image_fov0_flowsom_clusters': DataArray[yx] (512, 512)\n", + "│ ├── 'raw_image_fov0_flowsom_metaclusters': DataArray[yx] (512, 512)\n", + "│ ├── 'raw_image_fov1_flowsom_clusters': DataArray[yx] (1024, 1024)\n", + "│ └── 'raw_image_fov1_flowsom_metaclusters': DataArray[yx] (1024, 1024)\n", "└── Tables\n", " ├── 'counts_clusters': AnnData (100, 16)\n", " ├── 'table': AnnData (1414, 22)\n", " └── 'table_cell_clustering_flowsom': AnnData (1409, 20)\n", "with coordinate systems:\n", - " ▸ 'global', with elements:\n", - " raw_image_fov0 (Images), raw_image_fov0_processed (Images), raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov0 (Labels), label_nuclear_fov1 (Labels), label_whole_fov0 (Labels), label_whole_fov1 (Labels), raw_image_fov0_flowsom_clusters (Labels), raw_image_fov0_flowsom_metaclusters (Labels), raw_image_fov1_flowsom_clusters (Labels), raw_image_fov1_flowsom_metaclusters (Labels)" + " ▸ 'fov0', with elements:\n", + " raw_image_fov0 (Images), raw_image_fov0_processed (Images), label_nuclear_fov0 (Labels), label_whole_fov0 (Labels), raw_image_fov0_flowsom_clusters (Labels), raw_image_fov0_flowsom_metaclusters (Labels)\n", + " ▸ 'fov1', with elements:\n", + " raw_image_fov1 (Images), raw_image_fov1_processed (Images), label_nuclear_fov1 (Labels), label_whole_fov1 (Labels), raw_image_fov1_flowsom_clusters (Labels), raw_image_fov1_flowsom_metaclusters (Labels)" ] }, - "execution_count": 11, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -462,16 +475,16 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ - "2024-06-14 10:19:03,790 - harpy.table.cell_clustering._utils - WARNING - Increasing cell cluster IDs (SOM cluster and meta cluster IDs) with +1 for visualization. The underlying dataframe in the SpatialData object remains unchanges.\n", - "2024-06-14 10:19:03,793 - harpy.table.cell_clustering._utils - WARNING - Increasing cell cluster IDs (SOM cluster and meta cluster IDs) with +1 for visualization. The underlying dataframe in the SpatialData object remains unchanges.\n", - "2024-06-14 10:19:03,796 - harpy.table.cell_clustering._utils - WARNING - Increasing cell cluster IDs (SOM cluster and meta cluster IDs) with +1 for visualization. The underlying dataframe in the SpatialData object remains unchanges.\n" + "2024-12-10 09:46:42,978 - harpy.table.cell_clustering._utils - WARNING - Increasing cell cluster IDs (SOM cluster and meta cluster IDs) with +1 for visualization. The underlying dataframe in the SpatialData object remains unchanges.\n", + "2024-12-10 09:46:42,981 - harpy.table.cell_clustering._utils - WARNING - Increasing cell cluster IDs (SOM cluster and meta cluster IDs) with +1 for visualization. The underlying dataframe in the SpatialData object remains unchanges.\n", + "2024-12-10 09:46:42,986 - harpy.table.cell_clustering._utils - WARNING - Increasing cell cluster IDs (SOM cluster and meta cluster IDs) with +1 for visualization. The underlying dataframe in the SpatialData object remains unchanges.\n" ] }, { @@ -540,114 +553,114 @@ " \n", " \n", " \n", - " 1_counts_clusters_c87db112\n", - " 2.957331\n", - " 4.494543\n", - " 3.305711\n", - " 4.343360\n", - " 1.849581\n", - " 5.298170\n", - " 3.745769\n", - " 2.057324\n", - " 2.595093\n", - " 1.275055\n", - " 7.540906\n", - " 7.779709\n", - " 1.745743\n", - " 1.576688\n", - " 4.947849\n", - " 89.713973\n", - " 5\n", + " 1_counts_clusters_fe90513d\n", + " 37.843970\n", + " 2.887842\n", + " 97.043740\n", + " 5.178658\n", + " 1.315880\n", + " 0.589464\n", + " 30.252512\n", + " 1.639205\n", + " 2.432772\n", + " 2.077082\n", + " 7.781796\n", + " 4.139287\n", + " 1.638660\n", + " 2.509107\n", + " 2.552425\n", + " 7.210590\n", + " 2\n", + " 1\n", + " 9930\n", + " \n", + " \n", + " 2_counts_clusters_fe90513d\n", + " 38.690112\n", + " 9.945175\n", + " 49.737972\n", + " 5.014744\n", + " 8.713191\n", + " 1.219908\n", + " 56.096997\n", + " 2.077967\n", + " 4.129621\n", + " 2.686037\n", + " 5.455420\n", + " 5.524063\n", + " 2.271283\n", + " 3.385231\n", + " 0.894532\n", + " 8.693713\n", " 1\n", - " 9050\n", - " \n", - " \n", - " 2_counts_clusters_c87db112\n", - " 9.223635\n", - " 13.199765\n", - " 5.344522\n", - " 6.280923\n", - " 10.007229\n", - " 2.288556\n", - " 24.313907\n", - " 4.365400\n", - " 6.206642\n", - " 2.654662\n", - " 8.120834\n", - " 9.743484\n", - " 4.143529\n", - " 6.264831\n", - " 3.418407\n", - " 50.938679\n", - " 5\n", " 2\n", - " 9495\n", - " \n", - " \n", - " 3_counts_clusters_c87db112\n", - " 6.237812\n", - " 9.367096\n", - " 5.586749\n", - " 12.584922\n", - " 3.089530\n", - " 3.213206\n", - " 8.372398\n", - " 6.089461\n", - " 9.301675\n", - " 4.037615\n", - " 22.116019\n", - " 14.121541\n", - " 9.079312\n", - " 5.893481\n", - " 8.240330\n", - " 34.542586\n", - " 5\n", + " 12134\n", + " \n", + " \n", + " 3_counts_clusters_fe90513d\n", + " 73.091492\n", + " 17.922896\n", + " 18.220559\n", + " 4.631251\n", + " 4.585831\n", + " 1.025564\n", + " 52.106125\n", + " 2.153796\n", + " 4.097220\n", + " 2.331725\n", + " 7.267913\n", + " 6.139904\n", + " 2.960410\n", + " 2.698596\n", + " 1.826165\n", + " 9.665717\n", + " 1\n", " 3\n", - " 13887\n", - " \n", - " \n", - " 4_counts_clusters_c87db112\n", - " 18.534875\n", - " 4.432272\n", - " 49.607468\n", - " 7.216803\n", - " 1.551463\n", - " 0.690981\n", - " 17.769115\n", - " 2.776675\n", - " 3.575007\n", - " 2.577310\n", - " 29.798437\n", - " 17.675432\n", - " 2.835710\n", - " 3.067414\n", - " 6.869558\n", - " 9.590902\n", + " 5392\n", + " \n", + " \n", + " 4_counts_clusters_fe90513d\n", + " 76.282287\n", + " 61.344410\n", + " 2.660174\n", + " 3.988683\n", + " 3.950231\n", + " 0.583871\n", + " 39.929262\n", + " 1.899014\n", + " 2.709320\n", + " 1.705489\n", + " 7.024916\n", + " 4.346849\n", + " 2.103179\n", + " 2.492270\n", + " 1.044199\n", + " 5.976883\n", " 9\n", " 4\n", - " 10893\n", - " \n", - " \n", - " 5_counts_clusters_c87db112\n", - " 30.877554\n", - " 3.149300\n", - " 95.926183\n", - " 6.370782\n", - " 1.371339\n", - " 0.650704\n", - " 27.585160\n", - " 2.047785\n", - " 2.841191\n", - " 2.113751\n", - " 9.091455\n", - " 5.126966\n", - " 1.822619\n", - " 3.226701\n", - " 2.975826\n", - " 8.591069\n", + " 12617\n", + " \n", + " \n", + " 5_counts_clusters_fe90513d\n", + " 47.305260\n", + " 59.382376\n", + " 3.534356\n", + " 5.237534\n", + " 8.039006\n", + " 0.985423\n", + " 55.497515\n", + " 2.064406\n", + " 4.395945\n", + " 2.033076\n", + " 4.772678\n", + " 4.934692\n", + " 2.381851\n", + " 4.444559\n", + " 0.383196\n", + " 5.731354\n", " 9\n", " 5\n", - " 10411\n", + " 16815\n", " \n", " \n", " ...\n", @@ -672,114 +685,114 @@ " ...\n", " \n", " \n", - " 96_counts_clusters_c87db112\n", - " 2.338454\n", - " 9.962485\n", - " 2.193743\n", - " 62.699224\n", - " 0.810325\n", - " 0.677078\n", - " 9.805510\n", - " 3.943257\n", - " 9.179419\n", - " 1.048139\n", - " 40.200144\n", - " 11.909424\n", - " 1.028891\n", - " 8.213371\n", - " 3.419144\n", - " 4.546988\n", - " 2\n", + " 96_counts_clusters_fe90513d\n", + " 3.381922\n", + " 10.202954\n", + " 2.722567\n", + " 19.882297\n", + " 2.628480\n", + " 1.435061\n", + " 12.535290\n", + " 6.423287\n", + " 7.808438\n", + " 1.716372\n", + " 37.751931\n", + " 11.812116\n", + " 2.634270\n", + " 31.108982\n", + " 6.185559\n", + " 9.853439\n", + " 5\n", " 96\n", - " 13135\n", - " \n", - " \n", - " 97_counts_clusters_c87db112\n", - " 2.924828\n", - " 14.908827\n", - " 2.606520\n", - " 75.980420\n", - " 1.187327\n", - " 1.034916\n", - " 13.934763\n", - " 6.531429\n", - " 14.983489\n", - " 1.084566\n", - " 12.627397\n", - " 9.501719\n", - " 1.691567\n", - " 14.328754\n", - " 5.775819\n", - " 8.412790\n", - " 18\n", + " 11251\n", + " \n", + " \n", + " 97_counts_clusters_fe90513d\n", + " 2.470278\n", + " 8.337522\n", + " 2.250204\n", + " 45.239891\n", + " 0.850247\n", + " 0.568664\n", + " 8.317586\n", + " 3.651513\n", + " 7.229076\n", + " 1.053102\n", + " 55.057834\n", + " 11.486410\n", + " 1.136371\n", + " 6.642796\n", + " 3.817631\n", + " 4.767680\n", + " 5\n", " 97\n", - " 18881\n", - " \n", - " \n", - " 98_counts_clusters_c87db112\n", - " 2.663261\n", - " 14.675678\n", - " 2.450740\n", - " 49.446807\n", - " 0.936380\n", - " 0.965804\n", - " 15.280870\n", - " 6.356314\n", - " 12.865684\n", - " 1.003338\n", - " 11.538158\n", - " 7.572785\n", - " 1.616540\n", - " 45.161700\n", - " 4.578395\n", - " 9.472542\n", - " 2\n", + " 13194\n", + " \n", + " \n", + " 98_counts_clusters_fe90513d\n", + " 3.030046\n", + " 12.170709\n", + " 2.506028\n", + " 59.447868\n", + " 1.032256\n", + " 0.860999\n", + " 11.455320\n", + " 4.825058\n", + " 9.948482\n", + " 1.224571\n", + " 33.234845\n", + " 12.156787\n", + " 1.475615\n", + " 9.946127\n", + " 4.933891\n", + " 6.348947\n", + " 5\n", " 98\n", - " 9606\n", - " \n", - " \n", - " 99_counts_clusters_c87db112\n", - " 2.786221\n", - " 16.886792\n", - " 2.544968\n", - " 57.760554\n", - " 1.510566\n", - " 0.621739\n", - " 9.873467\n", - " 9.815158\n", - " 48.120955\n", - " 1.054896\n", - " 9.604530\n", - " 7.028433\n", - " 1.367574\n", - " 9.942413\n", - " 3.265405\n", - " 11.612421\n", - " 8\n", + " 15672\n", + " \n", + " \n", + " 99_counts_clusters_fe90513d\n", + " 3.106052\n", + " 14.744514\n", + " 2.634652\n", + " 77.775664\n", + " 1.103696\n", + " 0.984863\n", + " 14.039679\n", + " 5.912146\n", + " 12.283513\n", + " 1.081740\n", + " 13.259535\n", + " 10.251130\n", + " 1.735470\n", + " 12.797073\n", + " 6.092375\n", + " 8.267192\n", + " 5\n", " 99\n", - " 10220\n", - " \n", - " \n", - " 100_counts_clusters_c87db112\n", - " 1.501354\n", - " 12.916443\n", - " 1.732045\n", - " 106.018177\n", - " 0.495795\n", - " 0.495713\n", - " 10.607854\n", - " 5.464689\n", - " 14.148630\n", - " 0.671717\n", - " 10.156424\n", - " 7.053110\n", - " 0.598646\n", - " 11.385688\n", - " 3.044625\n", - " 5.240363\n", + " 16393\n", + " \n", + " \n", + " 100_counts_clusters_fe90513d\n", + " 1.480684\n", + " 13.220733\n", + " 1.721745\n", + " 106.230223\n", + " 0.480134\n", + " 0.498194\n", + " 10.636129\n", + " 5.904330\n", + " 14.462784\n", + " 0.657815\n", + " 9.449697\n", + " 6.441781\n", + " 0.566056\n", + " 12.013471\n", + " 2.820398\n", + " 5.216806\n", " 18\n", " 100\n", - " 10450\n", + " 10009\n", " \n", " \n", "\n", @@ -789,78 +802,78 @@ "text/plain": [ "channels CD3 CD4 CD8 CD14 \\\n", "cells \n", - "1_counts_clusters_c87db112 2.957331 4.494543 3.305711 4.343360 \n", - "2_counts_clusters_c87db112 9.223635 13.199765 5.344522 6.280923 \n", - "3_counts_clusters_c87db112 6.237812 9.367096 5.586749 12.584922 \n", - "4_counts_clusters_c87db112 18.534875 4.432272 49.607468 7.216803 \n", - "5_counts_clusters_c87db112 30.877554 3.149300 95.926183 6.370782 \n", + "1_counts_clusters_fe90513d 37.843970 2.887842 97.043740 5.178658 \n", + "2_counts_clusters_fe90513d 38.690112 9.945175 49.737972 5.014744 \n", + "3_counts_clusters_fe90513d 73.091492 17.922896 18.220559 4.631251 \n", + "4_counts_clusters_fe90513d 76.282287 61.344410 2.660174 3.988683 \n", + "5_counts_clusters_fe90513d 47.305260 59.382376 3.534356 5.237534 \n", "... ... ... ... ... \n", - "96_counts_clusters_c87db112 2.338454 9.962485 2.193743 62.699224 \n", - "97_counts_clusters_c87db112 2.924828 14.908827 2.606520 75.980420 \n", - "98_counts_clusters_c87db112 2.663261 14.675678 2.450740 49.446807 \n", - "99_counts_clusters_c87db112 2.786221 16.886792 2.544968 57.760554 \n", - "100_counts_clusters_c87db112 1.501354 12.916443 1.732045 106.018177 \n", + "96_counts_clusters_fe90513d 3.381922 10.202954 2.722567 19.882297 \n", + "97_counts_clusters_fe90513d 2.470278 8.337522 2.250204 45.239891 \n", + "98_counts_clusters_fe90513d 3.030046 12.170709 2.506028 59.447868 \n", + "99_counts_clusters_fe90513d 3.106052 14.744514 2.634652 77.775664 \n", + "100_counts_clusters_fe90513d 1.480684 13.220733 1.721745 106.230223 \n", "\n", - "channels CD20 CD31 CD45 CD68 \\\n", - "cells \n", - "1_counts_clusters_c87db112 1.849581 5.298170 3.745769 2.057324 \n", - "2_counts_clusters_c87db112 10.007229 2.288556 24.313907 4.365400 \n", - "3_counts_clusters_c87db112 3.089530 3.213206 8.372398 6.089461 \n", - "4_counts_clusters_c87db112 1.551463 0.690981 17.769115 2.776675 \n", - "5_counts_clusters_c87db112 1.371339 0.650704 27.585160 2.047785 \n", - "... ... ... ... ... \n", - "96_counts_clusters_c87db112 0.810325 0.677078 9.805510 3.943257 \n", - "97_counts_clusters_c87db112 1.187327 1.034916 13.934763 6.531429 \n", - "98_counts_clusters_c87db112 0.936380 0.965804 15.280870 6.356314 \n", - "99_counts_clusters_c87db112 1.510566 0.621739 9.873467 9.815158 \n", - "100_counts_clusters_c87db112 0.495795 0.495713 10.607854 5.464689 \n", + "channels CD20 CD31 CD45 CD68 \\\n", + "cells \n", + "1_counts_clusters_fe90513d 1.315880 0.589464 30.252512 1.639205 \n", + "2_counts_clusters_fe90513d 8.713191 1.219908 56.096997 2.077967 \n", + "3_counts_clusters_fe90513d 4.585831 1.025564 52.106125 2.153796 \n", + "4_counts_clusters_fe90513d 3.950231 0.583871 39.929262 1.899014 \n", + "5_counts_clusters_fe90513d 8.039006 0.985423 55.497515 2.064406 \n", + "... ... ... ... ... \n", + "96_counts_clusters_fe90513d 2.628480 1.435061 12.535290 6.423287 \n", + "97_counts_clusters_fe90513d 0.850247 0.568664 8.317586 3.651513 \n", + "98_counts_clusters_fe90513d 1.032256 0.860999 11.455320 4.825058 \n", + "99_counts_clusters_fe90513d 1.103696 0.984863 14.039679 5.912146 \n", + "100_counts_clusters_fe90513d 0.480134 0.498194 10.636129 5.904330 \n", "\n", "channels CD163 CK17 Collagen1 Fibronectin \\\n", "cells \n", - "1_counts_clusters_c87db112 2.595093 1.275055 7.540906 7.779709 \n", - "2_counts_clusters_c87db112 6.206642 2.654662 8.120834 9.743484 \n", - "3_counts_clusters_c87db112 9.301675 4.037615 22.116019 14.121541 \n", - "4_counts_clusters_c87db112 3.575007 2.577310 29.798437 17.675432 \n", - "5_counts_clusters_c87db112 2.841191 2.113751 9.091455 5.126966 \n", + "1_counts_clusters_fe90513d 2.432772 2.077082 7.781796 4.139287 \n", + "2_counts_clusters_fe90513d 4.129621 2.686037 5.455420 5.524063 \n", + "3_counts_clusters_fe90513d 4.097220 2.331725 7.267913 6.139904 \n", + "4_counts_clusters_fe90513d 2.709320 1.705489 7.024916 4.346849 \n", + "5_counts_clusters_fe90513d 4.395945 2.033076 4.772678 4.934692 \n", "... ... ... ... ... \n", - "96_counts_clusters_c87db112 9.179419 1.048139 40.200144 11.909424 \n", - "97_counts_clusters_c87db112 14.983489 1.084566 12.627397 9.501719 \n", - "98_counts_clusters_c87db112 12.865684 1.003338 11.538158 7.572785 \n", - "99_counts_clusters_c87db112 48.120955 1.054896 9.604530 7.028433 \n", - "100_counts_clusters_c87db112 14.148630 0.671717 10.156424 7.053110 \n", + "96_counts_clusters_fe90513d 7.808438 1.716372 37.751931 11.812116 \n", + "97_counts_clusters_fe90513d 7.229076 1.053102 55.057834 11.486410 \n", + "98_counts_clusters_fe90513d 9.948482 1.224571 33.234845 12.156787 \n", + "99_counts_clusters_fe90513d 12.283513 1.081740 13.259535 10.251130 \n", + "100_counts_clusters_fe90513d 14.462784 0.657815 9.449697 6.441781 \n", "\n", - "channels ECAD HLADR SMA Vim \\\n", - "cells \n", - "1_counts_clusters_c87db112 1.745743 1.576688 4.947849 89.713973 \n", - "2_counts_clusters_c87db112 4.143529 6.264831 3.418407 50.938679 \n", - "3_counts_clusters_c87db112 9.079312 5.893481 8.240330 34.542586 \n", - "4_counts_clusters_c87db112 2.835710 3.067414 6.869558 9.590902 \n", - "5_counts_clusters_c87db112 1.822619 3.226701 2.975826 8.591069 \n", - "... ... ... ... ... \n", - "96_counts_clusters_c87db112 1.028891 8.213371 3.419144 4.546988 \n", - "97_counts_clusters_c87db112 1.691567 14.328754 5.775819 8.412790 \n", - "98_counts_clusters_c87db112 1.616540 45.161700 4.578395 9.472542 \n", - "99_counts_clusters_c87db112 1.367574 9.942413 3.265405 11.612421 \n", - "100_counts_clusters_c87db112 0.598646 11.385688 3.044625 5.240363 \n", + "channels ECAD HLADR SMA Vim \\\n", + "cells \n", + "1_counts_clusters_fe90513d 1.638660 2.509107 2.552425 7.210590 \n", + "2_counts_clusters_fe90513d 2.271283 3.385231 0.894532 8.693713 \n", + "3_counts_clusters_fe90513d 2.960410 2.698596 1.826165 9.665717 \n", + "4_counts_clusters_fe90513d 2.103179 2.492270 1.044199 5.976883 \n", + "5_counts_clusters_fe90513d 2.381851 4.444559 0.383196 5.731354 \n", + "... ... ... ... ... \n", + "96_counts_clusters_fe90513d 2.634270 31.108982 6.185559 9.853439 \n", + "97_counts_clusters_fe90513d 1.136371 6.642796 3.817631 4.767680 \n", + "98_counts_clusters_fe90513d 1.475615 9.946127 4.933891 6.348947 \n", + "99_counts_clusters_fe90513d 1.735470 12.797073 6.092375 8.267192 \n", + "100_counts_clusters_fe90513d 0.566056 12.013471 2.820398 5.216806 \n", "\n", "channels pixel_meta_cluster pixel_som_cluster count \n", "cells \n", - "1_counts_clusters_c87db112 5 1 9050 \n", - "2_counts_clusters_c87db112 5 2 9495 \n", - "3_counts_clusters_c87db112 5 3 13887 \n", - "4_counts_clusters_c87db112 9 4 10893 \n", - "5_counts_clusters_c87db112 9 5 10411 \n", + "1_counts_clusters_fe90513d 2 1 9930 \n", + "2_counts_clusters_fe90513d 1 2 12134 \n", + "3_counts_clusters_fe90513d 1 3 5392 \n", + "4_counts_clusters_fe90513d 9 4 12617 \n", + "5_counts_clusters_fe90513d 9 5 16815 \n", "... ... ... ... \n", - "96_counts_clusters_c87db112 2 96 13135 \n", - "97_counts_clusters_c87db112 18 97 18881 \n", - "98_counts_clusters_c87db112 2 98 9606 \n", - "99_counts_clusters_c87db112 8 99 10220 \n", - "100_counts_clusters_c87db112 18 100 10450 \n", + "96_counts_clusters_fe90513d 5 96 11251 \n", + "97_counts_clusters_fe90513d 5 97 13194 \n", + "98_counts_clusters_fe90513d 5 98 15672 \n", + "99_counts_clusters_fe90513d 5 99 16393 \n", + "100_counts_clusters_fe90513d 18 100 10009 \n", "\n", "[100 rows x 19 columns]" ] }, - "execution_count": 12, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -874,6 +887,603 @@ ") = _export_to_ark_format_cells(sdata_ark_analysis, table_layer=\"table_cell_clustering_flowsom\", output=None)\n", "df" ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
channelscell_meta_clusterCD3CD4CD8CD14CD20CD31CD45CD68CD163CK17Collagen1FibronectinECADHLADRSMAVimcell_meta_cluster_rename
014.73297712.3349943.82658027.8072602.4614961.32918110.07625233.94405717.9683531.62993416.6186709.7233622.77062712.8757195.48196515.6193961
127.07574716.8512414.78248723.9333354.7683431.41909118.4241678.3910639.5335541.75629515.25607310.1501313.81761533.0355685.48996215.1353212
235.3108706.3266484.5520256.7826021.8897591.0577977.0216823.0857404.6366591.31156010.0391227.4251964.0318963.5932633.9358797.8293403
344.5881287.5046513.67025412.0558524.33834213.4431839.3970564.7277046.8568032.03714921.24071524.9632443.7882415.2085509.80144220.0212424
454.0785945.8587713.8884999.4723742.3720111.7031666.5180793.5631985.2308831.53007538.03022515.4346413.0980163.9489027.75970012.7903855
5618.03324520.7081148.37577710.89417922.9058142.07122636.0520114.2702518.4894502.85975611.2916149.7997474.53202910.4631473.16487812.2158096
6735.24613345.7553265.1436888.57520412.2453681.51720540.6911123.5523987.1673132.5196838.2625097.1138833.9896496.7961811.7066699.4814007
7822.0382326.72638448.54119912.7943022.1481811.41499122.1177694.8390546.9266172.43949517.79940911.2641552.9425485.3735075.77989113.5333108
8919.28792816.04428713.40028712.4061118.9261732.13510231.6265184.3614739.7135864.40711413.29799912.0338646.7299118.2530845.33690313.8988869
91010.38316315.0770014.6776689.39819039.1152241.86913437.1129923.7999537.8424502.65452212.0003788.9962423.81337611.4266392.55783611.44034810
10115.17781411.0393474.47730429.9584953.6753071.87249012.4297166.56310710.1149771.79055426.98842414.9543503.23978110.7332249.08885315.22043811
111222.37626813.12767430.34488312.2202538.0791261.49746931.4507174.1819879.0205242.92101113.82440911.1257253.8972397.4345584.23249312.20819712
121317.78174623.2595895.81740912.7437267.0031162.21412122.6213405.3962879.1708793.24215216.00820712.7432589.1962408.6094935.38562015.30165713
131429.75629917.79995822.6177338.8568199.5032871.86016747.4858673.3546307.4596243.2883769.2633668.7225124.2354076.8117992.42387111.26388114
141527.18599936.3291874.72158610.41264910.8280142.05083332.3717804.2736618.8718162.74522511.2045639.9045906.5026677.4057203.14529912.21304515
15167.0451437.4955636.1817226.4808602.1107531.6274329.4644812.5755025.87242048.4456617.1207636.28948332.7622084.10575432.1871677.51136016
161720.35497830.5201014.89232016.1739788.0759271.60313429.5833977.8280028.1016822.1346609.7811338.4949434.39656323.5514562.98812311.87451217
171810.49460717.1078815.34843617.78009421.2038111.46143827.2410456.12647518.5332192.45238212.95208410.3230794.16844311.1628883.74573313.40258618
18194.7224817.9387673.34224213.2843372.2355623.1048527.6243675.0105246.6270401.99983723.45261116.3326554.1696465.35052916.15260035.12702519
19208.96018218.1664244.33248226.9176215.3896721.52981516.7928068.85235729.4228262.79643215.95284610.7613414.1663569.9773595.01619014.36978520
\n", + "
" + ], + "text/plain": [ + "channels cell_meta_cluster CD3 CD4 CD8 CD14 \\\n", + "0 1 4.732977 12.334994 3.826580 27.807260 \n", + "1 2 7.075747 16.851241 4.782487 23.933335 \n", + "2 3 5.310870 6.326648 4.552025 6.782602 \n", + "3 4 4.588128 7.504651 3.670254 12.055852 \n", + "4 5 4.078594 5.858771 3.888499 9.472374 \n", + "5 6 18.033245 20.708114 8.375777 10.894179 \n", + "6 7 35.246133 45.755326 5.143688 8.575204 \n", + "7 8 22.038232 6.726384 48.541199 12.794302 \n", + "8 9 19.287928 16.044287 13.400287 12.406111 \n", + "9 10 10.383163 15.077001 4.677668 9.398190 \n", + "10 11 5.177814 11.039347 4.477304 29.958495 \n", + "11 12 22.376268 13.127674 30.344883 12.220253 \n", + "12 13 17.781746 23.259589 5.817409 12.743726 \n", + "13 14 29.756299 17.799958 22.617733 8.856819 \n", + "14 15 27.185999 36.329187 4.721586 10.412649 \n", + "15 16 7.045143 7.495563 6.181722 6.480860 \n", + "16 17 20.354978 30.520101 4.892320 16.173978 \n", + "17 18 10.494607 17.107881 5.348436 17.780094 \n", + "18 19 4.722481 7.938767 3.342242 13.284337 \n", + "19 20 8.960182 18.166424 4.332482 26.917621 \n", + "\n", + "channels CD20 CD31 CD45 CD68 CD163 CK17 \\\n", + "0 2.461496 1.329181 10.076252 33.944057 17.968353 1.629934 \n", + "1 4.768343 1.419091 18.424167 8.391063 9.533554 1.756295 \n", + "2 1.889759 1.057797 7.021682 3.085740 4.636659 1.311560 \n", + "3 4.338342 13.443183 9.397056 4.727704 6.856803 2.037149 \n", + "4 2.372011 1.703166 6.518079 3.563198 5.230883 1.530075 \n", + "5 22.905814 2.071226 36.052011 4.270251 8.489450 2.859756 \n", + "6 12.245368 1.517205 40.691112 3.552398 7.167313 2.519683 \n", + "7 2.148181 1.414991 22.117769 4.839054 6.926617 2.439495 \n", + "8 8.926173 2.135102 31.626518 4.361473 9.713586 4.407114 \n", + "9 39.115224 1.869134 37.112992 3.799953 7.842450 2.654522 \n", + "10 3.675307 1.872490 12.429716 6.563107 10.114977 1.790554 \n", + "11 8.079126 1.497469 31.450717 4.181987 9.020524 2.921011 \n", + "12 7.003116 2.214121 22.621340 5.396287 9.170879 3.242152 \n", + "13 9.503287 1.860167 47.485867 3.354630 7.459624 3.288376 \n", + "14 10.828014 2.050833 32.371780 4.273661 8.871816 2.745225 \n", + "15 2.110753 1.627432 9.464481 2.575502 5.872420 48.445661 \n", + "16 8.075927 1.603134 29.583397 7.828002 8.101682 2.134660 \n", + "17 21.203811 1.461438 27.241045 6.126475 18.533219 2.452382 \n", + "18 2.235562 3.104852 7.624367 5.010524 6.627040 1.999837 \n", + "19 5.389672 1.529815 16.792806 8.852357 29.422826 2.796432 \n", + "\n", + "channels Collagen1 Fibronectin ECAD HLADR SMA Vim \\\n", + "0 16.618670 9.723362 2.770627 12.875719 5.481965 15.619396 \n", + "1 15.256073 10.150131 3.817615 33.035568 5.489962 15.135321 \n", + "2 10.039122 7.425196 4.031896 3.593263 3.935879 7.829340 \n", + "3 21.240715 24.963244 3.788241 5.208550 9.801442 20.021242 \n", + "4 38.030225 15.434641 3.098016 3.948902 7.759700 12.790385 \n", + "5 11.291614 9.799747 4.532029 10.463147 3.164878 12.215809 \n", + "6 8.262509 7.113883 3.989649 6.796181 1.706669 9.481400 \n", + "7 17.799409 11.264155 2.942548 5.373507 5.779891 13.533310 \n", + "8 13.297999 12.033864 6.729911 8.253084 5.336903 13.898886 \n", + "9 12.000378 8.996242 3.813376 11.426639 2.557836 11.440348 \n", + "10 26.988424 14.954350 3.239781 10.733224 9.088853 15.220438 \n", + "11 13.824409 11.125725 3.897239 7.434558 4.232493 12.208197 \n", + "12 16.008207 12.743258 9.196240 8.609493 5.385620 15.301657 \n", + "13 9.263366 8.722512 4.235407 6.811799 2.423871 11.263881 \n", + "14 11.204563 9.904590 6.502667 7.405720 3.145299 12.213045 \n", + "15 7.120763 6.289483 32.762208 4.105754 32.187167 7.511360 \n", + "16 9.781133 8.494943 4.396563 23.551456 2.988123 11.874512 \n", + "17 12.952084 10.323079 4.168443 11.162888 3.745733 13.402586 \n", + "18 23.452611 16.332655 4.169646 5.350529 16.152600 35.127025 \n", + "19 15.952846 10.761341 4.166356 9.977359 5.016190 14.369785 \n", + "\n", + "channels cell_meta_cluster_rename \n", + "0 1 \n", + "1 2 \n", + "2 3 \n", + "3 4 \n", + "4 5 \n", + "5 6 \n", + "6 7 \n", + "7 8 \n", + "8 9 \n", + "9 10 \n", + "10 11 \n", + "11 12 \n", + "12 13 \n", + "13 14 \n", + "14 15 \n", + "15 16 \n", + "16 17 \n", + "17 18 \n", + "18 19 \n", + "19 20 " + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "df_cell_meta_cluster_channel_avg" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'region': ['label_whole_fov0', 'label_whole_fov1'],\n", + " 'region_key': 'fov_labels',\n", + " 'instance_key': 'cell_ID'}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# \"table_cell_clustering_flowsom\" is annotated by segmentation masks, so they can be visualised using napari-spatialdata\n", + "sdata_ark_analysis[ \"table_cell_clustering_flowsom\" ].uns[ \"spatialdata_attrs\" ]\n", + "\n", + "#from napari_spatialdata import Interactive\n", + "\n", + "#Interactive(sdata_ark_analysis)" + ] } ], "metadata": { @@ -892,7 +1502,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.13" + "version": "3.10.8" } }, "nbformat": 4, diff --git a/src/harpy/datasets/pixie_example.py b/src/harpy/datasets/pixie_example.py index 6e53a76..d90b3ae 100644 --- a/src/harpy/datasets/pixie_example.py +++ b/src/harpy/datasets/pixie_example.py @@ -96,9 +96,7 @@ def pixie_example(fovs: list | None = None, with_pixel_output=True, with_cells_o output_layer=f"raw_image_{fov}", c_coords=channels, overwrite=True, - # transformation={ - # fov: sd.transformations.Identity() - # } + transformations={fov: sd.transformations.Identity()}, ) sdata = harpy.im.add_labels_layer( @@ -106,9 +104,7 @@ def pixie_example(fovs: list | None = None, with_pixel_output=True, with_cells_o arr=imread.imread(os.path.join(path_segment_data, f"{fov}_nuclear.tiff")).squeeze(), output_layer=f"label_nuclear_{fov}", overwrite=True, - # transformation={ - # fov: sd.transformations.Identity() - # } + transformations={fov: sd.transformations.Identity()}, ) sdata = harpy.im.add_labels_layer( @@ -116,9 +112,7 @@ def pixie_example(fovs: list | None = None, with_pixel_output=True, with_cells_o arr=imread.imread(os.path.join(path_segment_data, f"{fov}_whole_cell.tiff")).squeeze(), output_layer=f"label_whole_{fov}", overwrite=True, - # transformation={ - # fov: sd.transformations.Identity() - # } + transformations={fov: sd.transformations.Identity()}, ) if with_cells_output: prefix = "label_whole_" diff --git a/src/harpy/table/cell_clustering/_preprocess.py b/src/harpy/table/cell_clustering/_preprocess.py index bcaeb35..c47880f 100644 --- a/src/harpy/table/cell_clustering/_preprocess.py +++ b/src/harpy/table/cell_clustering/_preprocess.py @@ -86,7 +86,7 @@ def cell_clustering_preprocess( ), f"Provided labels layers '{_labels_layer_cells}' and '{_labels_layer_clusters}' do not have the same shape." assert ( - get_transformation(se_labels) == get_transformation(se_clusters) + get_transformation(se_labels, get_all=True) == get_transformation(se_clusters, get_all=True) ), f"Transformation on provided labels layers '{_labels_layer_cells}' and '{_labels_layer_clusters}' are not equal. This is currently not supported." if i == 0: diff --git a/src/harpy/table/pixel_clustering/_cluster_intensity.py b/src/harpy/table/pixel_clustering/_cluster_intensity.py index e90ac17..2f30713 100644 --- a/src/harpy/table/pixel_clustering/_cluster_intensity.py +++ b/src/harpy/table/pixel_clustering/_cluster_intensity.py @@ -27,6 +27,7 @@ def cluster_intensity( img_layer: str | Iterable[str], labels_layer: str | Iterable[str], output_layer: str, + to_coordinate_system: str | Iterable[str] = "global", channels: int | str | Iterable[int] | Iterable[str] | None = None, chunks: str | int | tuple[int, ...] | None = 10000, overwrite=False, @@ -50,6 +51,10 @@ def cluster_intensity( The labels layer in `sdata` that contains the SOM cluster IDs. I.e. the `output_layer_clusters` labels layer obtained through `harpy.im.flowsom`. output_layer The output table layer in `sdata` where results are stored. + to_coordinate_system + The coordinate system that holds `img_layer` and `labels_layer`. + If `img_layer` and `labels_layer` are provided as a list, + elements in `to_coordinate_system` are the respective coordinate systems that holds the elements in `img_layer` and `labels_layer`. channels Specifies the channels to be included in the intensity calculation. chunks @@ -63,6 +68,8 @@ def cluster_intensity( Raises ------ + AssertionError + If number of provided `img_layer`, `labels_layer` and `to_coordinate_system` is not equal. AssertionError If some labels in `labels_layer` are not found in the provided mapping pandas Series. @@ -76,10 +83,19 @@ def cluster_intensity( if isinstance(labels_layer, Iterable) and not isinstance(labels_layer, str) else [labels_layer] ) + to_coordinate_system = ( + list(to_coordinate_system) + if isinstance(to_coordinate_system, Iterable) and not isinstance(to_coordinate_system, str) + else [to_coordinate_system] + ) - assert len(img_layer) == len(labels_layer) + assert ( + len(img_layer) == len(labels_layer) == len(to_coordinate_system) + ), "The number of provided 'img_layer', 'labels_layer' and 'to_coordinate_system' should be equal." - for i, (_img_layer, _labels_layer) in enumerate(zip(img_layer, labels_layer)): + for i, (_img_layer, _labels_layer, _to_coordinate_system) in enumerate( + zip(img_layer, labels_layer, to_coordinate_system) + ): se = _get_spatial_element(sdata, layer=_labels_layer) labels = da.unique(se.data).compute() @@ -100,6 +116,7 @@ def cluster_intensity( labels_layer=_labels_layer, output_layer=output_layer, channels=channels, + to_coordinate_system=_to_coordinate_system, chunks=chunks, append=append, overwrite=overwrite,