From 58644cd352eaa4fb79b64287b921ddf9ecce9adf Mon Sep 17 00:00:00 2001
From: schlda00 <kai.schleicher@unibas.ch>
Date: Wed, 23 Apr 2025 14:02:46 +0200
Subject: [PATCH] Calculate instead of measure the number of DAPI negative
 spots

---
 2d_spots_in_fibers.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/2d_spots_in_fibers.py b/2d_spots_in_fibers.py
index 036a298..18161e8 100644
--- a/2d_spots_in_fibers.py
+++ b/2d_spots_in_fibers.py
@@ -31,7 +31,7 @@ from inra.ijpb.binary import BinaryImages
 # BIOP imports
 from ch.epfl.biop.ij2command import Labels2Rois
 # python imports
-import os
+import os, operator
 
 
 def get_parentdir_filename_ext_from_path(path):
@@ -520,17 +520,16 @@ for index, channel in enumerate(processing_channels):
     save_labelimage_as_ijroiset(spots_label_imp, rm, filename, "spots_ch" + str(channel), parent_dir)
     spots_binary_imp = convert_labelimage_to_binary(spots_label_imp)
     dapi_positive_spots_binary = ImageCalculator.run(spots_binary_imp, dapi_binary, "Multiply create")
-    dapi_negative_spots_binary = ImageCalculator.run(spots_binary_imp, dapi_positive_spots_binary, "Subtract create")
     
     load_rois_from_zip(fiber_segmentation_roiset, rm)
     _, n_spots_per_fiber = measure_intensity_sum(spots_binary_imp, rm)
     _, n_dapi_positive_spots_per_fiber = measure_intensity_sum(dapi_positive_spots_binary, rm)
-    _, n_dapi_negative_spots_per_fiber = measure_intensity_sum(dapi_negative_spots_binary, rm)
+    n_dapi_negative_spots_per_fiber = map(operator.sub, n_spots_per_fiber, n_dapi_positive_spots_per_fiber)
 
     add_results_to_resultstable(results_table, "n spots channel " + str(channel), n_spots_per_fiber)
     add_results_to_resultstable(results_table, "n spots dapi positive channel " + str(channel), n_dapi_positive_spots_per_fiber)
     add_results_to_resultstable(results_table, "n spots dapi negative channel " + str(channel), n_dapi_negative_spots_per_fiber)
-    close_images([spots_channel, spots_label_imp, spots_binary_imp, spots_binary_imp, dapi_binary, dapi_positive_spots_binary, dapi_negative_spots_binary])
+    close_images([spots_channel, spots_label_imp, spots_binary_imp, spots_binary_imp, dapi_binary, dapi_positive_spots_binary])
 
 results_table.show("Spots")
 save_results_table(results_table, filename, "Spots", parent_dir)
-- 
GitLab