From 9d905ba193c30bf57a526afd2292f2a05e617c8d Mon Sep 17 00:00:00 2001
From: mariabernard <maria.bernard@jouy.inra.fr>
Date: Thu, 14 Mar 2019 15:47:11 +0100
Subject: [PATCH] change bgzip\tabix management and temp files definition

---
 .../rules/combine_genotypeGVCF.rules          |  5 +++-
 Snakemake/IMAGE_calling/rules/freebayes.rules | 23 ++++++++++++++-----
 .../IMAGE_calling/rules/haplotypecaller.rules |  4 ++--
 Snakemake/IMAGE_calling/rules/mpileup.rules   | 23 ++++++++++++++-----
 4 files changed, 40 insertions(+), 15 deletions(-)

diff --git a/Snakemake/IMAGE_calling/rules/combine_genotypeGVCF.rules b/Snakemake/IMAGE_calling/rules/combine_genotypeGVCF.rules
index a01e10a..9f7cff3 100644
--- a/Snakemake/IMAGE_calling/rules/combine_genotypeGVCF.rules
+++ b/Snakemake/IMAGE_calling/rules/combine_genotypeGVCF.rules
@@ -49,4 +49,7 @@ rule GenotypeGVCFs:
         mem=config["GenotypeGVCFs"]["mem"]
    
     shell:
-        "java -Xmx{params.mem} -jar {config[bin][gatk]} -T GenotypeGVCFs -R {input.ref} --variant {input.gvcf} -o {output} 2> {log}"
+        """
+        java -Xmx{params.mem} -jar {config[bin][gatk]} -T GenotypeGVCFs -R {input.ref} --variant {input.gvcf} -o {output} 2> {log}
+        {config[bin][tabix]} -f -p vcf {output}
+        """
diff --git a/Snakemake/IMAGE_calling/rules/freebayes.rules b/Snakemake/IMAGE_calling/rules/freebayes.rules
index b6b934b..b18e55e 100644
--- a/Snakemake/IMAGE_calling/rules/freebayes.rules
+++ b/Snakemake/IMAGE_calling/rules/freebayes.rules
@@ -32,13 +32,23 @@ rule freebayes_gzip:
         "results/freebayes/{sample}.rg.sort.md.real.recal.vcf"
         
     output:
-        "results/freebayes/{sample}.rg.sort.md.real.recal.vcf.gz.tbi",
-        vcf="results/freebayes/{sample}.rg.sort.md.real.recal.vcf.gz"
+        temp("results/freebayes/{sample}.rg.sort.md.real.recal.vcf.gz")
         
     shell:
         """
-		{config[bin][bgzip]} -c {input} > {output.vcf}
-        {config[bin][tabix]} -f -p vcf {output.vcf}
+		{config[bin][bgzip]} -c {input} > {output}
+        """
+        
+rule freebayes_tabix:
+    input:
+        "results/freebayes/{sample}.rg.sort.md.real.recal.vcf.gz"
+        
+    output:
+        temp("results/freebayes/{sample}.rg.sort.md.real.recal.vcf.gz.tbi")
+        
+    shell:
+        """
+        {config[bin][tabix]} -f -p vcf {input}
         """
 
 rule vcf_merge_freebayes:
@@ -47,7 +57,8 @@ rule vcf_merge_freebayes:
         vcf=expand("results/freebayes/{sample}.rg.sort.md.real.recal.vcf.gz", sample=all_samples)
         
     output:
-         protected("results/freebayes/variants_freebayes_all.vcf.gz")
+         protected("results/freebayes/variants_freebayes_all.vcf.gz.tbi"),
+         vcf=protected("results/freebayes/variants_freebayes_all.vcf.gz")
          
     log:
         "results/freebayes/logs/merge_all_samples.stderr"
@@ -55,5 +66,5 @@ rule vcf_merge_freebayes:
     shell:
         """
         export PATH=`dirname {config[bin][tabix]}`:$PATH
-        {config[bin][vcf-merge]} {input.vcf} | {config[bin][bgzip]} -c > {output}; {config[bin][tabix]} -p vcf {output}
+        {config[bin][vcf-merge]} {input.vcf} | {config[bin][bgzip]} -c > {output.vcf}; {config[bin][tabix]} -p vcf {output.vcf}
         """
diff --git a/Snakemake/IMAGE_calling/rules/haplotypecaller.rules b/Snakemake/IMAGE_calling/rules/haplotypecaller.rules
index 40fa56b..ec12ddb 100755
--- a/Snakemake/IMAGE_calling/rules/haplotypecaller.rules
+++ b/Snakemake/IMAGE_calling/rules/haplotypecaller.rules
@@ -16,7 +16,7 @@ rule HaplotypeCaller:
         ref=config["reference_genome"]
         
     output:
-        gvcf="results/gatk_haplotypecaller/{sample}.rg.sort.md.real.recal.g.vcf.gz",
+        gvcf=protected("results/gatk_haplotypecaller/{sample}.rg.sort.md.real.recal.g.vcf.gz"),
         index="results/gatk_haplotypecaller/{sample}.rg.sort.md.real.recal.g.vcf.gz.tbi"
     
     log: 
@@ -26,7 +26,7 @@ rule HaplotypeCaller:
     params:
         mem=config["HaplotypeCaller"]["mem"],
         stand_call_conf="30" if config["stand_call_conf"]=="" else config["stand_call_conf"],
-        mmq="30" if config["min_mapping_quality"]=="" else config["min_mapping_quality"]
+        mmq="30" if config["min_mapping_quality"]=="" else config["min_mapping_quality"],
         mbq="10" if config["min_base_quality"]=="" else config["min_base_quality"]
         
     shell:
diff --git a/Snakemake/IMAGE_calling/rules/mpileup.rules b/Snakemake/IMAGE_calling/rules/mpileup.rules
index 2f17903..8b4e18e 100644
--- a/Snakemake/IMAGE_calling/rules/mpileup.rules
+++ b/Snakemake/IMAGE_calling/rules/mpileup.rules
@@ -32,13 +32,23 @@ rule mpileup_gzip:
         "results/mpileup/{sample}.rg.sort.md.real.recal.vcf"
         
     output:
-        vcf=protected("results/mpileup/{sample}.rg.sort.md.real.recal.vcf.gz"),
-        tbi=protected("results/mpileup/{sample}.rg.sort.md.real.recal.vcf.gz.tbi")
+        temp("results/mpileup/{sample}.rg.sort.md.real.recal.vcf.gz")
         
     shell:
         """
-        {config[bin][bgzip]} -c {input} > {output.vcf}
-        {config[bin][tabix]} -f -p vcf {output.vcf}
+        {config[bin][bgzip]} -c {input} > {output}
+        """
+
+rule mpileup_tabix:
+    input:
+        "results/mpileup/{sample}.rg.sort.md.real.recal.vcf.gz"
+        
+    output:
+        temp("results/mpileup/{sample}.rg.sort.md.real.recal.vcf.gz.tbi")
+        
+    shell:
+        """
+        {config[bin][tabix]} -f -p vcf {input}
         """
 
 rule vcf_merge_mpileup:
@@ -47,7 +57,8 @@ rule vcf_merge_mpileup:
         vcf=expand("results/mpileup/{sample}.rg.sort.md.real.recal.vcf.gz", sample=all_samples)
         
     output:
-        protected("results/mpileup/variants_mpileup_all.vcf.gz")
+        protected("results/mpileup/variants_mpileup_all.vcf.gz.tbi"),
+        vcf = protected("results/mpileup/variants_mpileup_all.vcf.gz")
         
     log:
         "results/mpileup/logs/merge_all_samples.stderr"
@@ -55,6 +66,6 @@ rule vcf_merge_mpileup:
     shell:
         """
         export PATH=`dirname {config[bin][tabix]}`:$PATH
-        {config[bin][vcf-merge]} {input.vcf} | {config[bin][bgzip]} -c > {output} ; {config[bin][tabix]} -p vcf {output}
+        {config[bin][vcf-merge]} {input.vcf} | {config[bin][bgzip]} -c > {output.vcf} ; {config[bin][tabix]} -p vcf {output.vcf}
         """
 
-- 
GitLab