From c5af5c0e73d5e2fdf8a0b603e4c4197a328a5395 Mon Sep 17 00:00:00 2001
From: Christopher Schmied <schmied@mpi-cbg.de>
Date: Wed, 27 May 2015 20:02:40 +0200
Subject: [PATCH] Added and tested resaving of output files

---
 spim_registration/timelapse/Snakefile         |  47 ++++----
 spim_registration/timelapse/define_output.bsh | 107 ++++++++++++++++++
 spim_registration/timelapse/export.bsh        |   3 -
 spim_registration/timelapse/tomancak_czi.json |   5 +-
 4 files changed, 133 insertions(+), 29 deletions(-)
 create mode 100755 spim_registration/timelapse/define_output.bsh

diff --git a/spim_registration/timelapse/Snakefile b/spim_registration/timelapse/Snakefile
index 66ddfed..36d8cfb 100755
--- a/spim_registration/timelapse/Snakefile
+++ b/spim_registration/timelapse/Snakefile
@@ -112,7 +112,6 @@ rule hdf5_xml:
                 -Dtimepoints_per_partition={timepoints_per_partition} \
                 -Dsetups_per_partition={setups_per_partition} \
                 -Drun_only_job_number=0 \
-                -Djob_type=xml \
                 -- --no-splash {path_bsh}""", 
            config["common"],
            config["define_xml_czi"],
@@ -148,7 +147,6 @@ rule resave_hdf5:
         -Dtimepoints_per_partition={timepoints_per_partition} \
         -Dsetups_per_partition={setups_per_partition} \
         -Drun_only_job_number={job_number} \
-        -Djob_type=hdf5 \
         -- --no-splash {path_bsh}""", # the & submits everyting at once
            config["common"],
            config["define_xml_czi"],
@@ -379,39 +377,38 @@ rule deconvolution:
 
 rule define_output:
     input: glob.glob('TP*')
-    output: config["hdf5_output"]["output_xml"] + ".xml"
+    output: config["hdf5_output"]["output_xml"].strip('\"') + ".xml"
     log: "define_xml_tif.log"
     run:
         cmd_string = produce_string(
         	"""{fiji-prefix} {fiji-app} \
         -Dimage_file_directory={jdir} \
         -Dtimepoints={output_timepoints} \
-        -Dacquisition_angles={acquisition_angles} \
         -Dchannels={output_channels} \
         -Dimage_file_pattern={output_image_file_pattern} \
         -Dpixel_distance_x={output_pixel_distance_x} \
         -Dpixel_distance_y={output_pixel_distance_y} \
         -Dpixel_distance_z={output_pixel_distance_z} \
         -Dpixel_unit={output_pixel_unit} \
-       	-Dxml_filename={first_xml_filename} \
-        -Dtype_of_dataset={type_of_dataset} \
-        -Dmultiple_timepoints={multiple_timepoints} \
-        -Dmultiple_channels={multiple_channels} \
-        -Dmultiple_illumination_directions={multiple_illumination_directions} \
-        -Dmultiple_angles={multiple_angles} \
-        -Dimglib_container={imglib_container} \
+       	-Dxml_filename={output_xml} \
+        -Dtype_of_dataset={output_type_of_dataset} \
+        -Dmultiple_timepoints={output_multiple_timepoints} \
+        -Dmultiple_channels={output_multiple_channels} \
+        -Dmultiple_illumination_directions={output_illumination_directions} \
+        -Dmultiple_angles={output_multiple_angles} \
+        -Dimglib_container={output_imglib_container} \
 	-- --no-splash {path_bsh}""",
 	config["common"],
-	config["define_xml_tif"],
+	config["hdf5_output"],
 	jdir=JOBDIR,
-	path_bsh=config["common"]["bsh_directory"] + config["define_xml_tif"]["bsh_file"])
+	path_bsh=config["common"]["bsh_directory"] + config["hdf5_output"]["bsh_file_define"])
 	
 	cmd_string +=" > {log} 2>&1"
 	shell(cmd_string)
 
 # create mother .xml/.h5
 rule hdf5_xml_output:
-    input: config["hdf5_output"]["output_xml"] + ".xml"
+    input: config["hdf5_output"]["output_xml"].strip('\"') + ".xml"
     output: expand("{dataset}.{suffix}",dataset=[ config["hdf5_output"]["output_hdf5_xml"].strip('\"')], suffix=["xml","h5"]),
             [ item+"_output" for item in datasets ]
     log: "hdf5_xml.log"
@@ -419,8 +416,8 @@ rule hdf5_xml_output:
         part_string = produce_string(
         	"""{fiji-prefix} {fiji-app} \
                 -Dimage_file_directory={jdir} \
-                -Dfirst_xml_filename={first_xml_filename} \
-                -Dhdf5_xml_filename={hdf5_xml_filename} \
+                -Dfirst_xml_filename={output_xml} \
+                -Dhdf5_xml_filename={output_hdf5_xml} \
                 -Dresave_angle={resave_angle} \
                 -Dresave_channel={resave_channel} \
                 -Dresave_illumination={resave_illumination} \
@@ -430,10 +427,11 @@ rule hdf5_xml_output:
                 -Dtimepoints_per_partition={timepoints_per_partition} \
                 -Dsetups_per_partition={setups_per_partition} \
                 -Drun_only_job_number=0 \
-                -Djob_type=xml \
+                -Doutput_data_type={output_data_type} \
+                -Dconvert_32bit={convert_32bit}\
                 -- --no-splash {path_bsh}""", 
            config["common"],
-           config["define_xml_czi"],
+           config["hdf5_output"],
            config["resave_hdf5"],
            jdir=JOBDIR,
            path_bsh=config["common"]["bsh_directory"] + config["resave_hdf5"]["bsh_file"])
@@ -444,13 +442,13 @@ rule hdf5_xml_output:
 rule resave_hdf5_output:
     input: rules.hdf5_xml_output.output
     output: "{xml_base}-{file_id,\d+}-00.h5_output_hdf5"
-    log: "resave_hdf5-{file_id}.log"
+    log: "resave_output-{file_id}.log"
     run:
         part_string = produce_string(
         	"""{fiji-prefix} {fiji-app} \
                 -Dimage_file_directory={jdir} \
-                -Dfirst_xml_filename={first_xml_filename} \
-                -Dhdf5_xml_filename={input_xml_base} \
+                -Dfirst_xml_filename={output_xml} \
+                -Dhdf5_xml_filename={output_hdf5_xml} \
         -Dresave_angle={resave_angle} \
         -Dresave_channel={resave_channel} \
         -Dresave_illumination={resave_illumination} \
@@ -460,10 +458,11 @@ rule resave_hdf5_output:
         -Dtimepoints_per_partition={timepoints_per_partition} \
         -Dsetups_per_partition={setups_per_partition} \
         -Drun_only_job_number={job_number} \
-        -Djob_type=hdf5 \
-        -- --no-splash {path_bsh}""", # the & submits everyting at once
+        -Doutput_data_type={output_data_type} \
+        -Dconvert_32bit={convert_32bit}\
+        -- --no-splash {path_bsh}""", 
            config["common"],
-           config["define_xml_czi"],
+           config["hdf5_output"],
            config["resave_hdf5"],
            jdir=JOBDIR,
            path_bsh=config["common"]["bsh_directory"] + config["resave_hdf5"]["bsh_file"],
diff --git a/spim_registration/timelapse/define_output.bsh b/spim_registration/timelapse/define_output.bsh
new file mode 100755
index 0000000..aae8803
--- /dev/null
+++ b/spim_registration/timelapse/define_output.bsh
@@ -0,0 +1,107 @@
+import ij.IJ; 		// calls imagej
+import ij.Prefs; 	// calls imagej settings
+import ij.ImagePlus;
+import java.lang.Runtime;
+import java.io.File;
+import java.io.FilenameFilter;
+
+runtime = Runtime.getRuntime();
+System.out.println(runtime.availableProcessors() + " cores available for multi-threading");
+
+Prefs.setThreads(1); 	// defines the number of threads allowed 
+print("Threads: "+Prefs.getThreads()); // prints thread setting in output
+
+System.out.println("Start loading parameters");
+// Directory
+System.out.println("=========================================================");
+System.out.println("Directory:");
+image_file_directory = System.getProperty( "image_file_directory" );
+xml_filename = System.getProperty( "xml_filename" );
+
+System.out.println( "image_file_directory = " + image_file_directory );
+System.out.println( "xml_filename = " + xml_filename );
+
+// Dataset settings
+System.out.println("=========================================================");
+System.out.println("Dataset:");
+timepoints = System.getProperty( "timepoints" );
+
+image_file_pattern = System.getProperty( "image_file_pattern" );
+type_of_dataset = System.getProperty( "type_of_dataset" );
+multiple_timepoints = System.getProperty( "multiple_timepoints" );
+multiple_illumination_directions = System.getProperty( "multiple_illumination_directions" );
+multiple_angles = System.getProperty( "multiple_angles" );
+imglib_container = System.getProperty( "imglib_container" );
+
+System.out.println( "timepoints = " + timepoints );
+System.out.println( "image_file_pattern = " + image_file_pattern );
+System.out.println( "type_of_dataset = " + type_of_dataset );
+System.out.println( "multiple_timepoints = " + multiple_timepoints );
+
+System.out.println( "multiple_illumination_directions = " + multiple_illumination_directions );
+System.out.println( "multiple_angles = " + multiple_angles );
+System.out.println( "imglib_container = " + imglib_container );
+
+// Calibaration
+System.out.println("=========================================================");
+System.out.println("Calibration:");
+float pixel_distance_x = Float.parseFloat( System.getProperty( "pixel_distance_x" ) );
+float pixel_distance_y = Float.parseFloat( System.getProperty( "pixel_distance_y" ) );
+float pixel_distance_z = Float.parseFloat( System.getProperty( "pixel_distance_z" ) );
+pixel_unit = System.getProperty( "pixel_unit" );
+
+System.out.println( "pixel_distance_x = " + pixel_distance_x );
+System.out.println( "pixel_distance_y = " + pixel_distance_y );
+System.out.println( "pixel_distance_z = " + pixel_distance_z );
+System.out.println( "pixel_unit = " + pixel_unit );
+
+// Channel Switch
+System.out.println("=========================================================");
+System.out.println("Channel Switch:");
+multiple_channels = System.getProperty( "multiple_channels" );
+System.out.println( "multiple_channels = " + multiple_channels );
+
+channels = System.getProperty( "channels" ); 
+
+IJ.run("Define Multi-View Dataset , type_of_dataset=[" + type_of_dataset + "] " +
+	"xml_filename=[" + xml_filename + ".xml] " +
+	"multiple_timepoints=[" + multiple_timepoints + "] " +
+	"multiple_channels=[" + multiple_channels + "] " +
+	"_____multiple_illumination_directions=[" + multiple_illumination_directions + "] " + 
+	"multiple_angles=[" + multiple_angles + "] " +
+	"image_file_directory=" + image_file_directory + " " +
+	"image_file_pattern=" + image_file_pattern + " " + 
+	"timepoints_=" + timepoints + " " +
+	channels +
+	"calibration_type=[Same voxel-size for all views] calibration_definition=[User define voxel-size(s)]" + " " + 
+	"imglib2_data_container=[" + imglib_container + "] " + 
+	"pixel_distance_x=" + pixel_distance_x + " " + 
+	"pixel_distance_y=" + pixel_distance_y + " " + 
+	"pixel_distance_z=" + pixel_distance_z + " " +
+	"pixel_unit=" + pixel_unit + "");	
+	
+// Executes Fiji plugin
+System.out.println("=========================================================");
+System.out.println("Start plugin:");
+IJ.run("Define Multi-View Dataset", 
+	"type_of_dataset=[" + type_of_dataset + "] " +
+	"xml_filename=[" + xml_filename + ".xml] " +
+	"multiple_timepoints=[" + multiple_timepoints + "] " +
+	"multiple_channels=[" + multiple_channels + "] " +
+	"_____multiple_illumination_directions=[" + multiple_illumination_directions + "] " + 
+	"multiple_angles=[" + multiple_angles + "] " +
+	"image_file_directory=" + image_file_directory + " " +
+	"image_file_pattern=" + image_file_pattern + " " + 
+	"timepoints_=" + timepoints + " " +
+	channels +
+	"calibration_type=[Same voxel-size for all views] calibration_definition=[User define voxel-size(s)]" + " " + 
+	"imglib2_data_container=[" + imglib_container + "] " + 
+	"pixel_distance_x=" + pixel_distance_x + " " + 
+	"pixel_distance_y=" + pixel_distance_y + " " + 
+	"pixel_distance_z=" + pixel_distance_z + " " +
+	"pixel_unit=" + pixel_unit + "");
+ 
+/* shutdown */
+runtime.exit(0);
+
+
diff --git a/spim_registration/timelapse/export.bsh b/spim_registration/timelapse/export.bsh
index 8666721..d7d064b 100755
--- a/spim_registration/timelapse/export.bsh
+++ b/spim_registration/timelapse/export.bsh
@@ -52,9 +52,6 @@ System.out.println( "hdf5_chunk_sizes=" + hdf5_chunk_sizes );
 System.out.println( "timepoints_per_partition=" + timepoints_per_partition );
 System.out.println( "setups_per_partition=" + setups_per_partition );
 
-
-// job switch
-
 int run_only_job_number =  Integer.parseInt( System.getProperty( "run_only_job_number" ) );
 System.out.println( "run_only_job_number=" + run_only_job_number );
 
diff --git a/spim_registration/timelapse/tomancak_czi.json b/spim_registration/timelapse/tomancak_czi.json
index a21c0bc..317466f 100755
--- a/spim_registration/timelapse/tomancak_czi.json
+++ b/spim_registration/timelapse/tomancak_czi.json
@@ -175,7 +175,7 @@
     
     "hdf5_output" :
     {
-    	    "output_image_file_pattern" : "TP{t}_Ch{c}_Ill0_Ang0,72,144,216,288.tif",
+    	    "output_image_file_pattern" : "TP{{t}}_Ch{{c}}_Ill0_Ang0,72,144,216,288.tif",
     	    "output_data_type" : "32Bit",
     	    "output_xml" : "\"fused_Dual_Channel\"",
     	    "output_hdf5_xml" : "\"hdf5_fused_Stock68\"",
@@ -191,7 +191,8 @@
     	    "output_multiple_angles" : "\"NO (one angle)\"",					
     	    "output_type_of_dataset" : "\"Image Stacks (ImageJ Opener)\"", 		
     	    "output_imglib_container" : "\"ArrayImg (faster)\"",
-    	    "bsh_file" : "/export_output.bsh", 	
+    	    "bsh_file_define" : "/define_output.bsh",
+    	    "bsh_file_hdf5" : "/export_output.bsh", 	
     	    "convert_32bit" : "\"[Use min/max of first image (might saturate intenities over time)]\""
     	    
     }
-- 
GitLab