-
Notifications
You must be signed in to change notification settings - Fork 1
/
Snakefile
92 lines (79 loc) · 4.08 KB
/
Snakefile
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
86
87
88
import os
from glob import glob
configfile: "config.yaml"
rule all:
input:
expand("{out_dir}/Clair_ensemble_out",out_dir=config["out_dir"])
in_dir=config["in_dir"]
fastq_list=glob(f"{in_dir}/*.f*q")
fast5_list=glob(f"{in_dir}/*.f*5")
if fastq_list:
rule fastq_in:
input:
expand("{in_dir}",in_dir=config["in_dir"])
output:
fq=expand("{out_dir}/all.pass.fq",out_dir=config["out_dir"])
shell:
"""bioawk -c fastx '{{if (meanqual($qual)>{config[qual_threshold]}) print "@"$name" "$comment"\\n"$seq"\\n+\\n"$qual}}' {input}/*.f*q > {output.fq} """
if fast5_list:
rule fast5_in:
input:
expand("{in_dir}",in_dir=config["in_dir"])
output:
expand("{out_dir}/all.pass.fq",out_dir=config["out_dir"])
shell:
"bin/ont-guppy/bin/guppy_basecaller -r -i {input} -s {config[out_dir]}/Guppy_out -c dna_r9.4.1_450bps_hac.cfg --device cuda:{config[gpu_device]} -q 0 --hp_correct 1 --qscore_filtering --min_qscore 3 && "
"cat {config[out_dir]}/Guppy_out/pass/*.fastq > {config[out_dir]}/all.pass.fq"
rule analysis:
input:
expand("{out_dir}/all.pass.fq",out_dir=config["out_dir"])
output:
touch(".analysis.done")
shell:
"""echo "[INFO] *average read quality: " $(bioawk -c fastx '{{ print meanqual($qual) }}' {input} | awk '{{sum += $1}} END {{print sum/NR}}');"""
"""echo "[INFO] *total throughput: " $(cat {input} | paste - - - - | cut -f 2 | tr -d '\n' | wc -c);"""
"""echo "[INFO] *average read length: " $(cat {input} | awk '{{if(NR%4==2) {{count++; bases += length}} }} END{{print bases/count}}')"""
if config["minionqc"]==True:
rule minionqc:
input:
expand("{out_dir}/Guppy_out/sequencing_summary.txt",out_dir=config["out_dir"])
output:
expand("{out_dir}/MinIONQC_out",out_dir=config["out_dir"])
run:
directory(shell("MinIONQC.R -i {input} -o {output} -p {config[threads]}"))
rule porechop:
input:
checkpoint=".analysis.done",
fq=expand("{out_dir}/all.pass.fq",out_dir=config["out_dir"])
output:
expand("{out_dir}/Porechop_out/guppy_pass.porechop.fastq",out_dir=config["out_dir"])
run:
if config["discard_middle"]==True:
discard_middle_flag="--discard_middle"
else:
discard_middle_flag=""
shell("mkdir -p {config[out_dir]}/Porechop_out && " \
"porechop -i {input.fq} -o {output} -t {config[threads]} {discard_middle_flag}")
rule align_index:
input:
expand("{out_dir}/Porechop_out/guppy_pass.porechop.fastq",out_dir=config["out_dir"])
output:
bam=expand("{out_dir}/Minimap2_out/guppy_pass.porechop.minimap2_hg38.sorted.bam",out_dir=config["out_dir"]),
bai=expand("{out_dir}/Minimap2_out/guppy_pass.porechop.minimap2_hg38.sorted.bam.bai",out_dir=config["out_dir"])
shell:
"mkdir -p {config[out_dir]}/Minimap2_out && "
"minimap2 -ax map-ont reference/GRCh38_no_alt_analysis_set.no_chr.fasta {input} -t {config[threads]} | samtools sort -o {output.bam}; "
"samtools index {output.bam}"
rule clair_ensemble:
input:
bam=expand("{out_dir}/Minimap2_out/guppy_pass.porechop.minimap2_hg38.sorted.bam",out_dir=config["out_dir"]),
bai=expand("{out_dir}/Minimap2_out/guppy_pass.porechop.minimap2_hg38.sorted.bam.bai",out_dir=config["out_dir"]),
bed=expand("{bed}",bed=config["BED_FILE_PATH"]),
fa=expand("{ref}",ref=config["REFERENCE_FASTA_FILE_PATH"]),
fai=expand("{ref}.fai",ref=config["REFERENCE_FASTA_FILE_PATH"])
output:
directory(expand("{out_dir}/Clair_ensemble_out",out_dir=config["out_dir"]))
run:
config["CLAIR_MODELS"]= [''.join([os.getcwd(),'/',path]) for path in config["CLAIR_MODELS"]]
clair_models_delim=','.join(config["CLAIR_MODELS"])
shell("./bin/run_Clair_ensemble.sh -b {input.bam} -d {config[BED_FILE_PATH]} -r {config[REFERENCE_FASTA_FILE_PATH]} -c {config[CLAIR]} -m {clair_models_delim} -e {config[ENSEMBLE_CPP_EXECUTABLE]} -t {config[threads]} -o {output}")