From fe74d0678e59c6829f2dc8ff1501eebd1d1ad0aa Mon Sep 17 00:00:00 2001
From: Christopher Schmied <schmied@mpi-cbg.de>
Date: Wed, 8 Jul 2015 11:53:13 +0200
Subject: [PATCH] Added the deletion of the temp files to the workflow

This approach assumes that the processing itself runs without error.
When Fiji fails in on process then the whole workflow needs to restart.
Because the dummy files are now gone.
---
 spim_registration/timelapse/Snakefile        | 10 +++++-----
 spim_registration/timelapse/single_test.yaml |  3 +++
 2 files changed, 8 insertions(+), 5 deletions(-)
 mode change 100644 => 100755 spim_registration/timelapse/single_test.yaml

diff --git a/spim_registration/timelapse/Snakefile b/spim_registration/timelapse/Snakefile
index 20eccb8..8394f62 100755
--- a/spim_registration/timelapse/Snakefile
+++ b/spim_registration/timelapse/Snakefile
@@ -38,7 +38,7 @@ rule resave_prepared:
 # defining xml for czi dataset
 rule define_xml_czi:
     input: glob_and_escape("*.czi"), config["common"]["first_czi"]
-    output: config["common"]["first_xml_filename"] + ".xml"
+    output: temp (config["common"]["first_xml_filename"] + ".xml")
     log: "logs/a1_define_xml_czi.log"
     run: 
         cmd_string = produce_string("""{fiji-prefix} {fiji-app} \
@@ -66,7 +66,7 @@ rule define_xml_czi:
 # defining xml for tif dataset
 rule define_xml_tif:
     input: glob.glob(re.sub("{{.}}","*",config["common"]['image_file_pattern'])) #replaces all occurrences of {{a}} (a can be any character) by * to use the string for globbing
-    output: config["common"]["first_xml_filename"] + ".xml"
+    output: temp(config["common"]["first_xml_filename"] + ".xml")
     log: "logs/a2_define_xml_tif.log"
     run:
         cmd_string = produce_string(
@@ -134,7 +134,7 @@ rule hdf5_xml:
 
 # resave  .czi/.tif dataset as hdf5	
 rule resave_hdf5:
-    input: rules.hdf5_xml.output # "{xml_base}-{file_id,\d+}-00.h5_xml"
+    input: rules.hdf5_xml.output, config["common"]["first_xml_filename"] + ".xml" # "{xml_base}-{file_id,\d+}-00.h5_xml"
     output: "{xml_base}-{file_id,\d+}-00.h5", temp("{xml_base}-{file_id,\d+}-00.h5_hdf5")
     log: "logs/b2_resave_hdf5-{file_id}.log"
     run:
@@ -447,7 +447,7 @@ rule define_output:
 rule hdf5_xml_output:
     input: config["common"]["output_xml"].strip('\"') + ".xml"
     output: expand("{dataset}.{suffix}",dataset=[ config["common"]["output_hdf5_xml"].strip('\"')], suffix=["xml","h5"]),
-    	    temp([ item+"_output" for item in datasets ])
+    	    temp([ item+"_output" for item in datasets ]), 
     log: "logs/f2_output_hdf5_xml.log"
     run:
         part_string = produce_string(
@@ -477,7 +477,7 @@ rule hdf5_xml_output:
         shell(part_string)
 
 rule resave_hdf5_output:
-    input: rules.hdf5_xml_output.output
+    input: rules.hdf5_xml_output.output, rules.define_output.output
     output: temp("{xml_base}-{file_id,\d+}-00.h5_output_hdf5")
     log: "logs/f3_resave_output-{file_id}.log"
     run:
diff --git a/spim_registration/timelapse/single_test.yaml b/spim_registration/timelapse/single_test.yaml
old mode 100644
new mode 100755
index 3171fb1..b5017f3
--- a/spim_registration/timelapse/single_test.yaml
+++ b/spim_registration/timelapse/single_test.yaml
@@ -179,6 +179,9 @@ common: {
   # File type
   output_data_type: "16Bit" # "32Bit" or "16Bit"
   }
+  # ============================================================================
+  # Advanced settings
+  # ============================================================================
   
 define_xml_czi: {
   rotation_around: "X-Axis",       # axis of acquistion
-- 
GitLab