From 16f1c49611b28291fb45afe765accc8f13ec69b3 Mon Sep 17 00:00:00 2001
From: Floreal Cabanettes <floreal.cabanettes@inra.fr>
Date: Fri, 3 Aug 2018 13:36:18 +0200
Subject: [PATCH] Fix: pindel detect all variants type grouped

---
 snakecnv/svsnakemake_utils.py | 13 ++++++++-----
 snakecnv/tools/pindel.snk     | 16 ++++++++++------
 2 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/snakecnv/svsnakemake_utils.py b/snakecnv/svsnakemake_utils.py
index f4b96de..cc46fb1 100644
--- a/snakecnv/svsnakemake_utils.py
+++ b/snakecnv/svsnakemake_utils.py
@@ -69,12 +69,15 @@ class SnakemakeUtils:
         return inputs
 
     def get_pindel_chr_batches(self, wildcards):
-        inputs = []
+        inputs = {"D": [],
+                  "INV": [],
+                  "TD": []}
         for batch in self.chr_batches[wildcards.chrom]:
-            inputs.append("{batch}/pindel/{chrom}_{svtype}/{chrbatch}/pindel_{chrom}_{svtype}.gz".format(
-                batch=wildcards.batch, chrom=wildcards.chrom, chrbatch="-".join(map(str, batch)),
-                svtype=wildcards.svtype
-            ))
+            for svtype in inputs:
+                inputs[svtype].append("{batch}/pindel/{chrom}/{chrbatch}/pindel_{chrom}_{svtype}.gz".format(
+                    batch=wildcards.batch, chrom=wildcards.chrom, chrbatch="-".join(map(str, batch)),
+                    svtype=svtype
+                ))
         return inputs
 
 
diff --git a/snakecnv/tools/pindel.snk b/snakecnv/tools/pindel.snk
index 4e1e6d7..74c5197 100644
--- a/snakecnv/tools/pindel.snk
+++ b/snakecnv/tools/pindel.snk
@@ -30,9 +30,9 @@ rule pindel:
         genome = REFERENCE,
         fai = REFERENCE + ".fai"
     output:
-        "{batch}/pindel/{chrom}_{svtype}/{chrbatch}/pindel_{chrom}_D.gz",
-        "{batch}/pindel/{chrom}_{svtype}/{chrbatch}/pindel_{chrom}_INV.gz",
-        "{batch}/pindel/{chrom}_{svtype}/{chrbatch}/pindel_{chrom}_TD.gz",
+        "{batch}/pindel/{chrom}/{chrbatch}/pindel_{chrom}_D.gz",
+        "{batch}/pindel/{chrom}/{chrbatch}/pindel_{chrom}_INV.gz",
+        "{batch}/pindel/{chrom}/{chrbatch}/pindel_{chrom}_TD.gz",
     threads:
         get_threads("pindel", 4)
     log:
@@ -50,7 +50,7 @@ rule pindel:
         """
         for svtype in D TD INV RP SI LI BP CloseEndMapped INT_final;
         do
-        gzip -f {wildcards.batch}/pindel/{wildcards.chrom}_{wildcards.svtype}/{wildcards.chrbatch}/pindel_{wildcards.chrom}_${{svtype}}
+        gzip -f {wildcards.batch}/pindel/{wildcards.chrom}/{wildcards.chrbatch}/pindel_{wildcards.chrom}_${{svtype}}
         done
         """
 
@@ -58,12 +58,16 @@ rule mergepindelbatches:
     input:
         unpack(snakemake_utils.get_pindel_chr_batches)
     output:
-        "{batch}/pindel/pindel_{chrom}_{svtype}.gz"
+        D="{batch}/pindel/pindel_{chrom}_D.gz",
+        INV="{batch}/pindel/pindel_{chrom}_INV.gz",
+        TD="{batch}/pindel/pindel_{chrom}_TD.gz"
     log:
         stdout = "{batch}/logs/pindel/{chrom}_{svtype}.o",
         stderr = "{batch}/logs/pindel/{chrom}_{svtype}.e",
     threads:
         1
     shell:
-        "mergepindelbatches.py {output} {input} 1>{log.stdout} 2>{log.stderr}; "
+        "mergepindelbatches.py {output.D} {input.D} 1>{log.stdout} 2>{log.stderr}; "
+        "mergepindelbatches.py {output.INV} {input.INV} 1>>{log.stdout} 2>>{log.stderr}; "
+        "mergepindelbatches.py {output.TD} {input.TD} 1>>{log.stdout} 2>>{log.stderr}; "
         "rm -rf {wildcards.batch}/pindel/{wildcards.chrom}_{wildcards.svtype}"
\ No newline at end of file
-- 
GitLab