From 93e009ff8c32919c5e09108384e70241ab671e99 Mon Sep 17 00:00:00 2001
From: Tobias Marschall <tobias.marschall@0ohm.net>
Date: Tue, 17 Jul 2018 19:22:28 +0200
Subject: [PATCH] Fix haplotag likelihood computation from snakefile

---
 Snakefile                       |  8 ++++----
 utils/haplotagProbs.snakemake.R | 14 +++++++++-----
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/Snakefile b/Snakefile
index 80e371b..9ca01ca 100644
--- a/Snakefile
+++ b/Snakefile
@@ -705,7 +705,7 @@ rule create_haplotag_table:
     output:
         tsv='haplotag/table/{sample}/by-cell/haplotag-counts.{cell}.{windows}.{bpdens}.tsv'
     log:
-        "log/create_haplotag_table/{sample}.{cell}.log"
+        "log/create_haplotag_table/{sample}.{cell}.{windows}.{bpdens}.log"
     script:
         "utils/haplotagTable.snakemake.R"
 
@@ -720,11 +720,11 @@ rule merge_haplotag_tables:
 
 rule create_haplotag_likelihoods:
     input:
-        haplotag_table='haplotag/table/{sample}/haplotag-counts.{windows}.{bpdens}.tsv'
-        sv_probs_table = 'sv_probabilities/{sample}/{windows}.{bpdens}/probabilities.Rdata'
+        haplotag_table='haplotag/table/{sample}/full/haplotag-counts.{windows}.{bpdens}.tsv',
+        sv_probs_table = 'sv_probabilities/{sample}/{windows}.{bpdens}/probabilities.Rdata',
     output: 'haplotag/table/{sample}/haplotag-likelihoods.{windows}.{bpdens}.data'
     log:
-        "log/create_haplotag_likelihoods/{sample}.log"
+        "log/create_haplotag_likelihoods/{sample}.{windows}.{bpdens}.log"
     script:
         "utils/haplotagProbs.snakemake.R"
 
diff --git a/utils/haplotagProbs.snakemake.R b/utils/haplotagProbs.snakemake.R
index 14e14df..2518e6f 100644
--- a/utils/haplotagProbs.snakemake.R
+++ b/utils/haplotagProbs.snakemake.R
@@ -1,8 +1,12 @@
-sink(snakemake@log[[1]])
+log <- file(snakemake@log[[1]], open='wt')
+sink(file=log, type='message')
+sink(file=log, type='output')
 
-haplotagCounts <- snakemake@input[[haplotag_table]]
-probs <- snakemake@input[[sv_probs_table]]
+source('utils/haplotagProbs.R')
 
-probs <- addHaploCountProbs(probs, haploCounts, alpha)
+haplotagCounts <- fread(snakemake@input[["haplotag_table"]])
+probs <- readRDS(snakemake@input[["sv_probs_table"]])
 
-save(probs, file=snakemake@output[[1]])
\ No newline at end of file
+probs <- addHaploCountProbs(probs, haplotagCounts, alpha=0.05)
+
+saveRDS(probs, file=snakemake@output[[1]])
-- 
GitLab