From 178666c9ef3f4ef07bfdf8751a67b5355b806b00 Mon Sep 17 00:00:00 2001
From: "kai.schleicher@unibas.ch" <kai.schleicher@unibas.ch>
Date: Tue, 3 Nov 2020 09:26:45 +0100
Subject: [PATCH] each script writes its result into its own specific folder

---
 1_identify_fibers.py         |  9 +++++----
 2a_central_nuclei_counter.py | 12 +++++++-----
 2b_fibertyping.py            | 19 +++++++++++++------
 3_manual_rerun.py            |  7 +++++--
 4 files changed, 30 insertions(+), 17 deletions(-)

diff --git a/1_identify_fibers.py b/1_identify_fibers.py
index 40bfad0..ad19079 100644
--- a/1_identify_fibers.py
+++ b/1_identify_fibers.py
@@ -502,12 +502,11 @@ raw_image_calibration = raw.getCalibration()
 raw_image_title = fix_BF_czi_imagetitle(raw)
 
 # take care of paths and directories
-output_dir = fix_ij_dirs(output_dir)
+output_dir = fix_ij_dirs(output_dir) + str(raw_image_title) + "/1_identify_fibers/"
 
-if not os.path.exists( str(output_dir + raw_image_title) ):
-    os.makedirs( str(output_dir + raw_image_title) )
+if not os.path.exists( output_dir ):
+    os.makedirs( output_dir )
 
-output_dir = str( output_dir + raw_image_title ) + "/"
 classifiers_dir = fix_ij_dirs(classifiers_dir)
 primary_model = classifiers_dir + "primary.model"
 secondary_model = classifiers_dir + "secondary_central_nuclei.model"
@@ -525,6 +524,8 @@ IJ.log( "solidity = " + str(minSol) + "-" + str(maxSol) )
 IJ.log( "feret_ar = " + str(minFAR) + "-" + str(maxFAR) )
 IJ.log( "min_feret = " + str(minMinFer) + "-" + str(maxMinFer) )
 IJ.log( "ROI expansion [microns] = " + str(enlarge) )
+IJ.log( "Membrane channel = " + str(membrane_channel) )
+IJ.log( "MHC positive fiber channel = " + str(fiber_channel) )
 IJ.log( "sub-tiling = " + str(tiling_factor) )
 IJ.log( " -- settings used -- ")
 
diff --git a/2a_central_nuclei_counter.py b/2a_central_nuclei_counter.py
index 19f8f85..122aaf4 100644
--- a/2a_central_nuclei_counter.py
+++ b/2a_central_nuclei_counter.py
@@ -19,6 +19,7 @@ import os
 #@ String (visibility=MESSAGE, value="<html><b> Welcome to Myosoft - centralized nuclei counter! </b></html>") msg1
 #@ File (label="Select fiber-ROIs zip-file", style="file") roi_zip
 #@ File (label="Select image file", description="select your image") path_to_image
+#@ File (label="Select directory for output", style="directory") output_dir
 #@ Boolean (label="close image after processing", description="tick this box when using batch mode", value=False) close_raw
 #@ String (visibility=MESSAGE, value="<html><b> shrink ROIs to find nuclei </b></html>") msg3
 #@ Float (label="ROI Shrinking factor", value=0.7) shrink
@@ -62,7 +63,7 @@ def fix_ij_dirs(path):
     """
 
     fixed_path = str(path).replace("\\", "/")
-    fixed_path = fixed_path + "/"
+    # fixed_path = fixed_path + "/"
 
     return fixed_path
 
@@ -372,10 +373,11 @@ raw_image_calibration = raw.getCalibration()
 raw_image_title = fix_BF_czi_imagetitle(raw)
 
 # take care of paths and directories
-output_dir = os.path.dirname(str(roi_zip))
-input_roi_zip = os.path.basename(str(roi_zip))
-output_dir = fix_ij_dirs(output_dir)
-input_rois_path = output_dir + input_roi_zip
+input_rois_path = fix_ij_dirs( roi_zip )
+output_dir = fix_ij_dirs(output_dir) + "/2a_central_nuclei_counter/"
+
+if not os.path.exists( output_dir ):
+    os.makedirs( output_dir )
 
 # open ROIS and show on image
 open_rois_from_zip( rm, input_rois_path )
diff --git a/2b_fibertyping.py b/2b_fibertyping.py
index 99d150d..91f82db 100644
--- a/2b_fibertyping.py
+++ b/2b_fibertyping.py
@@ -19,6 +19,7 @@ import os
 #@ String (visibility=MESSAGE, value="<html><b> Welcome to Myosoft! </b></html>") msg1
 #@ File (label="Select fiber-ROIs zip-file", style="file") roi_zip
 #@ File (label="Select image file", description="select your image") path_to_image
+#@ File (label="Select directory for output", style="directory") output_dir
 #@ Boolean (label="close image after processing", description="tick this box when using batch mode", value=False) close_raw
 #@ String (visibility=MESSAGE, value="<html><b> channel positions in the hyperstack </b></html>") msg5
 #@ Integer (label="Fiber staining 1 channel number (0=n.a.)", style="slider", min=0, max=5, value=1) fiber_channel_1
@@ -64,7 +65,7 @@ def fix_ij_dirs(path):
     """
 
     fixed_path = str(path).replace("\\", "/")
-    fixed_path = fixed_path + "/"
+    # fixed_path = fixed_path + "/"
 
     return fixed_path
 
@@ -373,11 +374,17 @@ raw_image_calibration = raw.getCalibration()
 raw_image_title = fix_BF_czi_imagetitle(raw)
 
 # take care of paths and directories
-output_dir = os.path.dirname(str(roi_zip))
-output_dir = fix_ij_dirs(output_dir)
+# output_dir = os.path.dirname(str(roi_zip))
+# output_dir = fix_ij_dirs(output_dir)
+
+input_rois_path = fix_ij_dirs( roi_zip )
+output_dir = fix_ij_dirs(output_dir) + "/2b_fibertyping/"
+
+if not os.path.exists( output_dir ):
+    os.makedirs( output_dir )
 
 # open ROIS and show on image
-open_rois_from_zip( rm, str(roi_zip) )
+open_rois_from_zip( rm, str(input_rois_path) )
 change_all_roi_color(rm, "blue")
 show_all_rois_on_image( rm, raw )
 
@@ -386,7 +393,7 @@ IJ.log( "Now working on " + str(raw_image_title) )
 if raw_image_calibration.scaled() == False:
     IJ.log("Your image is not spatially calibrated! Size measurements are only possible in [px].")
 IJ.log( " -- settings used -- ")
-IJ.log( "Selected fiber-ROIs zip-file = " + str(roi_zip) )
+IJ.log( "Selected fiber-ROIs zip-file = " + str(input_rois_path) )
 IJ.log( "Fiber staining 1 channel number = " + str(fiber_channel_1) )
 IJ.log( "Fiber staining 2 channel number = " + str(fiber_channel_2) )
 IJ.log( "Fiber staining 3 channel number = " + str(fiber_channel_3) )
@@ -397,7 +404,7 @@ IJ.run("Set Measurements...", "area perimeter shape feret's redirect=None decima
 IJ.run("Clear Results", "")
 measure_in_all_rois( raw, fiber_channel_1, rm )
 
-# loop trhough the fiber channels, check if positive, add info to results table
+# loop through the fiber channels, check if positive, add info to results table
 all_fiber_channels = [fiber_channel_1, fiber_channel_2, fiber_channel_3]
 all_min_fiber_intensities = [min_fiber_intensity_1, min_fiber_intensity_2, min_fiber_intensity_3]
 roi_colors = ["green", "orange", "red"]
diff --git a/3_manual_rerun.py b/3_manual_rerun.py
index 98c3c33..a8908d7 100644
--- a/3_manual_rerun.py
+++ b/3_manual_rerun.py
@@ -24,7 +24,7 @@ def fix_ij_dirs(path):
     """
 
     fixed_path = str(path).replace("\\", "/")
-    fixed_path = fixed_path + "/"
+    # fixed_path = fixed_path + "/"
 
     return fixed_path
 
@@ -164,7 +164,10 @@ def show_all_rois_on_image(rm, imp):
     rm.runCommand(imp,"Show All")
 
 
-output_dir = fix_ij_dirs(output_dir)
+output_dir = fix_ij_dirs(output_dir) + "/3_manual_rerun/"
+if not os.path.exists( output_dir ):
+    os.makedirs( output_dir )
+
 rt.reset()
 raw_image_title = fix_BF_czi_imagetitle(raw)
 renumber_rois(rm)
-- 
GitLab