From 7b21ecbe5c2ffe7c492549e4209c72f59f05fc2d Mon Sep 17 00:00:00 2001
From: Blaise Li <blaise.li__git@nsup.org>
Date: Thu, 4 Oct 2018 11:10:50 +0200
Subject: [PATCH] Added --delete option to rsync on success.

This is to limit clutter from old analyses.
---
 CLIP/iCLIP.snakefile                      | 2 +-
 Degradome-seq/Degradome-seq.snakefile     | 4 ++--
 PRO-seq/PRO-seq.snakefile                 | 2 +-
 RNA_Seq_Cecere/RNA-seq.snakefile          | 2 +-
 Ribo-seq/Ribo-seq.snakefile               | 2 +-
 libworkflows/libworkflows/libworkflows.py | 6 +++++-
 small_RNA-seq/small_RNA-seq.snakefile     | 2 +-
 7 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/CLIP/iCLIP.snakefile b/CLIP/iCLIP.snakefile
index c7955cf..cb477b3 100644
--- a/CLIP/iCLIP.snakefile
+++ b/CLIP/iCLIP.snakefile
@@ -720,7 +720,7 @@ rule make_normalized_bigwig:
 
 onsuccess:
     print("iCLIP data analysis finished.")
-    cleanup_and_backup(output_dir, config)
+    cleanup_and_backup(output_dir, config, delete=True)
 
 onerror:
     shell(f"rm -rf {output_dir}_err")
diff --git a/Degradome-seq/Degradome-seq.snakefile b/Degradome-seq/Degradome-seq.snakefile
index b4fbc43..61dda0f 100644
--- a/Degradome-seq/Degradome-seq.snakefile
+++ b/Degradome-seq/Degradome-seq.snakefile
@@ -59,7 +59,7 @@ CONTRAST2PAIR = dict(zip(DD_CONTRASTS, DD_COND_PAIRS))
 
 # TODO: have a distinct subset of biotypes for join_all_counts, that are guaranteed overlap-free.
 BIOTYPES = config["biotypes"]
-ORIENTATIONS = ["all"]
+ORIENTATIONS = ["all", "fwd", "rev"]
 
 aligner = config["aligner"]
 alignment_settings = {
@@ -516,7 +516,7 @@ rule compute_efficiency_difference:
 
 onsuccess:
     print("Degradome-seq analysis finished.")
-    cleanup_and_backup(output_dir, config)
+    cleanup_and_backup(output_dir, config, delete=True)
 
 onerror:
     shell(f"rm -rf {output_dir}_err")
diff --git a/PRO-seq/PRO-seq.snakefile b/PRO-seq/PRO-seq.snakefile
index 116aa1b..62f8ea6 100644
--- a/PRO-seq/PRO-seq.snakefile
+++ b/PRO-seq/PRO-seq.snakefile
@@ -1687,7 +1687,7 @@ rm -rf ${{tmpdir}}
 
 onsuccess:
     print("PRO-seq analysis finished.")
-    cleanup_and_backup(output_dir, config)
+    cleanup_and_backup(output_dir, config, delete=True)
 
 onerror:
     shell(f"rm -rf {output_dir}_err")
diff --git a/RNA_Seq_Cecere/RNA-seq.snakefile b/RNA_Seq_Cecere/RNA-seq.snakefile
index 9001c89..66c4def 100644
--- a/RNA_Seq_Cecere/RNA-seq.snakefile
+++ b/RNA_Seq_Cecere/RNA-seq.snakefile
@@ -2020,7 +2020,7 @@ rule make_contrast_lfc_boxplots:
 
 onsuccess:
     print("RNA-seq analysis finished.")
-    cleanup_and_backup(output_dir, config)
+    cleanup_and_backup(output_dir, config, delete=True)
 
 onerror:
     shell(f"rm -rf {output_dir}_err")
diff --git a/Ribo-seq/Ribo-seq.snakefile b/Ribo-seq/Ribo-seq.snakefile
index cf060f6..e42ee98 100644
--- a/Ribo-seq/Ribo-seq.snakefile
+++ b/Ribo-seq/Ribo-seq.snakefile
@@ -3467,7 +3467,7 @@ def try_to_cluster_genes(counts_data):
 
 onsuccess:
     print("small RNA-seq analysis finished.")
-    cleanup_and_backup(output_dir, config)
+    cleanup_and_backup(output_dir, config, delete=True)
 
 
 onerror:
diff --git a/libworkflows/libworkflows/libworkflows.py b/libworkflows/libworkflows/libworkflows.py
index 5afa22f..2fbb7d1 100644
--- a/libworkflows/libworkflows/libworkflows.py
+++ b/libworkflows/libworkflows/libworkflows.py
@@ -128,7 +128,7 @@ def wc_applied(source_function):
     return wc_applied_source_func
 
 
-def cleanup_and_backup(output_dir, config):
+def cleanup_and_backup(output_dir, config, delete=False):
     """Performs cleanup and backup according to the information present in the
     *config* dictionary."""
     print("removing metadata")
@@ -142,6 +142,10 @@ def cleanup_and_backup(output_dir, config):
         # If no dest_dir, we assume the directory structure
         # is the same on the destination host
         dest_dir = config["backup"].get("dest_dir", os.getcwd())
+        if delete:
+            rsync_options = "-vaP --delete"
+        else:
+            rsync_options = "-vaP"
         try:
             print(f"backuping results to {user}@{host}:{dest_dir}")
             shell(f"rsync -vaP {output_dir} {user}@{host}:{dest_dir}")
diff --git a/small_RNA-seq/small_RNA-seq.snakefile b/small_RNA-seq/small_RNA-seq.snakefile
index fda01ed..912a0d9 100644
--- a/small_RNA-seq/small_RNA-seq.snakefile
+++ b/small_RNA-seq/small_RNA-seq.snakefile
@@ -4346,7 +4346,7 @@ def try_to_cluster_genes(counts_data):
 
 onsuccess:
     print("small RNA-seq analysis finished.")
-    cleanup_and_backup(output_dir, config)
+    cleanup_and_backup(output_dir, config, delete=True)
 
 
 onerror:
-- 
GitLab