From 049e6af380dbc664987472c321f3752ac611ca74 Mon Sep 17 00:00:00 2001 From: Lenz Date: Fri, 22 Nov 2024 17:20:08 +0100 Subject: [PATCH] Fixed a small bug in the cell analyzer --- src/nimbus_inference/cell_analyzer.py | 4 +-- templates/3_analyze_individual_cells.ipynb | 29 +++++++++++----------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/nimbus_inference/cell_analyzer.py b/src/nimbus_inference/cell_analyzer.py index 104aa2f..04ba651 100644 --- a/src/nimbus_inference/cell_analyzer.py +++ b/src/nimbus_inference/cell_analyzer.py @@ -140,7 +140,7 @@ def create_composite_image(self, path_dict, add_boundaries=True): if self.segmentation_naming_convention and add_boundaries: fov_path = os.path.split(list(path_dict.values())[0])[0] seg_path = self.segmentation_naming_convention(fov_path) - seg_img = io.imread(seg_path) + seg_img = np.squeeze(io.imread(seg_path)) seg_boundaries = find_boundaries(seg_img, mode='inner') individual_cell_boundary = seg_boundaries.copy() cell_mask = seg_img == self.cell_df[ @@ -166,7 +166,7 @@ def create_instance_image(self, path_dict, cell_id): # add overlay of instances fov_path = os.path.split(list(path_dict.values())[0])[0] seg_path = self.segmentation_naming_convention(fov_path) - seg_img = io.imread(seg_path) + seg_img = np.squeeze(io.imread(seg_path)) seg_boundaries = find_boundaries(seg_img, mode='inner') seg_img[seg_boundaries] = 0 seg_img_clipped = np.clip(seg_img, 0, 1) * 0.2 diff --git a/templates/3_analyze_individual_cells.ipynb b/templates/3_analyze_individual_cells.ipynb index 3b3d3e1..caa2832 100644 --- a/templates/3_analyze_individual_cells.ipynb +++ b/templates/3_analyze_individual_cells.ipynb @@ -54,21 +54,20 @@ "metadata": {}, "outputs": [], "source": [ - "off_diagonal_df = pd.DataFrame(\n", - " {\n", - " \"Cell ID\": [1, 2, 3, 4],\n", - " \"pixie_ct\": [\"Eosinophil\", \"Neutrophil\", \"Lymphocyte\", \"Monocyte\"],\n", - " \"nimbus_ct\": [\"Neutrophil\", \"Lymphocyte\", \"Monocyte\", \"Eosinophil\"],\n", - " \"fov\": [\"TMA32_R4C6\", \"TMA32_R4C6\", \"TMA32_R5C4\", \"TMA32_R5C4\"],\n", - " \"label\": [451, 123, 234, 345],\n", - " } \n", - ")\n", - "base_dir = os.path.normpath(\"C:/Users/lorenz/Desktop/angelo_lab/data/SPAIN_TNBC_fov_subset\")\n", - "tiff_dir = os.path.join(base_dir, \"image_data\")\n", - "deepcell_output_dir = os.path.join(base_dir, \"segmentation\", \"deepcell_output\")\n", + "off_diagonal_df = pd.read_csv(\"E:/angelo_lab/data/DCIS/cell_tables/potchara_data.csv\")\n", + "base_dir = os.path.normpath(\"E:/angelo_lab/data/DCIS\")\n", + "tiff_dir = os.path.join(base_dir, \"20230317_DCIS\", \"image_data\")\n", + "deepcell_output_dir = os.path.join(base_dir, \"deepcell_output\")\n", "segmentation_naming_convention = prep_naming_convention(deepcell_output_dir)\n", "\n", - "off_diagonal_df" + "fov_paths = [os.path.join(tiff_dir, f) for f in os.listdir(tiff_dir) if os.path.isdir(os.path.join(tiff_dir, f))]\n", + "# test segmentation_naming_convention\n", + "if os.path.exists(segmentation_naming_convention(fov_paths[0])):\n", + " print(\"Segmentation data exists for fov 0 and naming convention is correct\")\n", + "else:\n", + " print(\"Segmentation data does not exist for fov 0 or naming convention is incorrect\")\n", + "\n", + "off_diagonal_df[\"Cell ID\"] = off_diagonal_df.index.values" ] }, { @@ -89,7 +88,7 @@ " output_dir=base_dir,\n", " segmentation_naming_convention=segmentation_naming_convention,\n", " img_width='600px',\n", - " context=200)\n", + " context=120)\n", "viewer.display()" ] } @@ -110,7 +109,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.0" + "version": "3.10.14" } }, "nbformat": 4,