-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsbx_kraken.smk
85 lines (70 loc) · 2.28 KB
/
sbx_kraken.smk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- mode: Snakemake -*-
#
# Rules for running Kraken
TARGET_CLASSIFY = [CLASSIFY_FP / "kraken" / "all_samples.tsv"]
def get_kraken_ext_path() -> Path:
ext_path = Path(sunbeam_dir) / "extensions" / "sbx_kraken"
if ext_path.exists():
return ext_path
raise Error(
"Filepath for kraken not found, are you sure it's installed under extensions/sbx_kraken?"
)
SBX_KRAKEN_VERSION = open(get_kraken_ext_path() / "VERSION").read().strip()
try:
BENCHMARK_FP
except NameError:
BENCHMARK_FP = output_subdir(Cfg, "benchmarks")
try:
LOG_FP
except NameError:
LOG_FP = output_subdir(Cfg, "logs")
localrules:
all_classify,
rule all_classify:
input:
TARGET_CLASSIFY,
rule kraken2_classify_report:
input:
expand(QC_FP / "decontam" / "{{sample}}_{rp}.fastq.gz", rp=Pairs),
output:
raw=CLASSIFY_FP / "kraken" / "raw" / "{sample}-raw.tsv",
report=CLASSIFY_FP / "kraken" / "{sample}-taxa.tsv",
benchmark:
BENCHMARK_FP / "kraken2_classify_report_{sample}.tsv"
log:
LOG_FP / "kraken2_classify_report_{sample}.log",
params:
db=Cfg["sbx_kraken"]["kraken_db_fp"],
paired_end="--paired" if Cfg["all"]["paired_end"] else "",
conda:
"envs/sbx_kraken_env.yml"
container:
f"docker://sunbeamlabs/sbx_kraken:{SBX_KRAKEN_VERSION}"
threads: 8
shell:
"""
if LC_ALL=C gzip -l {input[0]} | awk 'NR==2 {{exit($2!=0)}}'; then
echo "100.00\t0\t0\tR\t1\troot" > {output.report} && \
echo "C\tA\t1\t136|136\t1:102 |:| 1:102" > {output.raw}
else
kraken2 --gzip-compressed \
--db {params.db} \
--report {output.report} \
--output {output.raw} \
{params.paired_end} {input} \
2>&1 | tee {log}
fi
"""
rule summarize_kraken2_reports:
input:
reports=expand(
CLASSIFY_FP / "kraken" / "{sample}-taxa.tsv", sample=Samples.keys()
),
output:
summary=CLASSIFY_FP / "kraken" / "all_samples.tsv",
benchmark:
BENCHMARK_FP / "summarize_kraken2_reports.tsv"
log:
LOG_FP / "summarize_kraken2_reports.log",
script:
"scripts/summarize_kraken2_reports.py"