From 06e80ae5752aed8e0b0710cbf7fa505e8debc2d0 Mon Sep 17 00:00:00 2001
From: burri0000 <dominik.burri@unibas.ch>
Date: Mon, 19 Oct 2020 15:24:52 +0200
Subject: [PATCH] use onsuccess to properly remove index dirs

---
 Snakefile                               | 10 ++++++----
 workflow/rules/paired_end.snakefile.smk |  8 +++++++-
 workflow/rules/single_end.snakefile.smk |  9 ++++++++-
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/Snakefile b/Snakefile
index 1648e97..d7dd8fb 100644
--- a/Snakefile
+++ b/Snakefile
@@ -38,6 +38,12 @@ if cluster_config:
 include: os.path.join("workflow", "rules", "paired_end.snakefile.smk")
 include: os.path.join("workflow", "rules", "single_end.snakefile.smk")
 
+onsuccess:
+    print("Workflow finished, no error.")
+    os.system("rm -rv " + config['kallisto_indexes'])
+    os.system("rm -rv " + config['salmon_indexes'])
+    os.system("rm -rv " + config['alfa_indexes'])
+
 rule finish:
     """
         Rule for collecting outputs
@@ -195,8 +201,6 @@ rule create_index_star:
             "STAR_index",
             "chrName.txt")
 
-    shadow: "full"
-
     params:
         output_dir = os.path.join(
             config['star_indexes'],
@@ -386,8 +390,6 @@ rule create_index_kallisto:
             "{organism}",
             "kallisto.idx")
 
-    shadow: "full"
-
     params:
         output_dir = os.path.join(
             config['kallisto_indexes'],
diff --git a/workflow/rules/paired_end.snakefile.smk b/workflow/rules/paired_end.snakefile.smk
index f06d4dc..a756856 100644
--- a/workflow/rules/paired_end.snakefile.smk
+++ b/workflow/rules/paired_end.snakefile.smk
@@ -401,7 +401,13 @@ rule pe_genome_quantification_kallisto:
             "samples",
             "{sample}",
             "quant_kallisto",
-            "{sample}.pe.kallisto.pseudo.sam")
+            "{sample}.pe.kallisto.pseudo.sam"),
+        abundances = os.path.join(
+            config["output_dir"],
+            "samples",
+            "{sample}",
+            "quant_kallisto",
+            "abundance.h5")
 
     shadow: "full"
 
diff --git a/workflow/rules/single_end.snakefile.smk b/workflow/rules/single_end.snakefile.smk
index 565bc01..a1c62e4 100644
--- a/workflow/rules/single_end.snakefile.smk
+++ b/workflow/rules/single_end.snakefile.smk
@@ -343,7 +343,14 @@ rule genome_quantification_kallisto:
             "samples",
             "{sample}",
             "quant_kallisto",
-            "{sample}.se.kallisto.pseudo.sam")
+            "{sample}.se.kallisto.pseudo.sam"),
+        abundances = os.path.join(
+            config["output_dir"],
+            "samples",
+            "{sample}",
+            "quant_kallisto",
+            "abundance.h5")
+
 
     shadow: "full"
 
-- 
GitLab