-
Notifications
You must be signed in to change notification settings - Fork 0
/
snakemake.signal+Q.py
265 lines (209 loc) · 8.1 KB
/
snakemake.signal+Q.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
configfile: "snakemake.signal+Q.config.yaml"
vcf=config["Vcf"] #240225 updated
refseq=config["Refseq"] #240225 updated
outdir=config["Outdir"] #240225 updated
BAM=config["Bam"] #240225 updated
flowcell=config["Flowcell"] #240429 updated
strategy=config["Strategy"] #240429 updated
ref_name=config["Ref"]
num=config["Num"]
tombodir=config["Tombo_dir"]
subsample=config["Subsample"]
print("Usage:")
print("snakemake -s snakemake.signal+Q.py --cores 8 --config Ref=refname Num=5 Vcf=path/to/VCF Refseq=path/to/refseq Outdir=path/to/outputdir Bam=path/to/sorted/bam Tombo_dir=path/to/tombo_processed/fast5 Subsample=2000 Flowcell=R9 Strategy=Amplicon")
print("Ref=refname".ljust(40)+"The value of #CHROM in vcf file, e.g., 'Ref=chr1'")
print("Num=5".ljust(40)+"The number of bases up- and down-stream that are centered around the variation loci, default=5")
print("Vcf=path/to/VCF".ljust(40)+"The file path to vcf file, e.g., 'Vcf=/data/res/lofreq.vcf'")
print("Refseq=path/to/refseq".ljust(40)+"The file path to reference sequence, e.g., 'Refseq=/database/COVID-19.fa'")
print("Outdir=path/to/outputdir".ljust(40)+"The file path storing the output results and intermediate files, e.g., 'Outdir=/data/res'")
print("Bam=path/to/sorted/bam".ljust(40)+"The file path to sorted bam files, e.g., 'Bam=/data/res/sorted.bam'")
print("Tombo_dir=path/to/tombo_processed/fast5".ljust(40)+"The file path to tombo-resquiggled single fats5 files, e.g., 'Tombo_dir=/data/fast5'")
print("Subsample=2000".ljust(40)+"The number to subsample from reads covering variation loci, should be larger than 200, default=2000")
print("Flowcell=R9".ljust(40)+"The version of flow cell, should be R9 or R10, default=R9")
print("Strategy=Amplicon".ljust(40)+"The sequencing strategy, should be Amplicon or Direct, default=Amplicon")
rule all:
input:
str(outdir) + "/" + "run.log"
rule vcf2delinfo:
input:
str(refseq),
str(vcf)
output:
str(outdir) + "/" + "variant.info.txt",
str(outdir) + "/" + "targetpos.txt",
str(outdir) + "/" + "startpos.txt",
str(outdir) + "/" + "endpos.txt",
str(outdir) + "/" + "dellen.txt",
str(outdir) + "/" + "reglen.txt",
str(outdir) + "/" + "location.txt",
str(outdir) + "/" + "metric.txt"
params:
opts1=str(flowcell),
opts2=str(strategy)
script:
"scripts/vcf2delinfo-v2.sh"
rule delinfo2Signal_Qinfo:
input:
str(BAM),
str(outdir) + "/" + "targetpos.txt",
str(outdir) + "/" + "startpos.txt",
str(outdir) + "/" + "endpos.txt",
str(outdir) + "/" + "dellen.txt",
str(outdir) + "/" + "reglen.txt",
str(outdir) + "/" + "metric.txt"
output:
str(outdir) + "/" + "target.upstream_downstream.bases.comparison.result.txt",
str(outdir) + "/" + "fq.Qscore.info.txt",
str(outdir) + "/" + "run.log"
params:
opts1=str(ref_name),
opts2=str(num),
opts3=str(outdir),
opts4=str(tombodir),
opts5=str(subsample)
script:
"scripts/delinfo2Signal+Qinfo.sh"
# rule bam2sam:
# input:
# "/public/data1/yefq/data/fast5/20220703_WGA_twist/processed/20230426_Guppy621_comparison/Sce20_guppy_sup_aligned.softclip_trimmed.endtrim10_minimap2_align.mapped.sorted.bam"
# output:
# "data/test/target.rev.simpified.sam.txt",
# "data/test/target.simpified.sam.txt"
# params:
# opts1="--output-fmt SAM -@ 8 -h -f 16",
# opts2="--output-fmt SAM -@ 8 -h -F 0x814",
# region=ref_name + ":" + str(target) + "-" + str(int(target)+1)
# shell:
# """
# samtools view {params.opts1} {input} {params.region} | awk -F "\\t" '{{if(NF>=10){{print $1,$2,$3,$4,$6}}}}' OFS="\\t" > {output[0]}
# samtools view {params.opts2} {input} {params.region} | awk -F "\\t" '{{if(NF>=10){{print $1,$2,$3,$4,$6}}}}' OFS="\\t" > {output[1]}
# """
# rule sam2readID:
# input:
# "data/test/target.rev.simpified.sam.txt",
# "data/test/target.simpified.sam.txt"
# output:
# "data/test/target.minus.del.readID.txt",
# "data/test/target.plus.del.readID.txt",
# "data/test/target.minus.match.readID.txt",
# "data/test/target.plus.match.readID.txt"
# params:
# opts1=str(dellen) + " " + str(target) + " D",
# opts2=str(rglen) + " " + str(target) + " M",
# script:
# "scripts/Plasmid_R9-guppy_sup_Sam2ReadID.sh"
# rule readID2Signal:
# input:
# "data/test/target.minus.del.readID.txt",
# "data/test/target.plus.del.readID.txt",
# "data/test/target.minus.match.readID.txt",
# "data/test/target.plus.match.readID.txt"
# output:
# "data/test/target.upstream_downstream.bases.singal_length.txt"
# params:
# opts1=str(start) + " " + str(end) + " " + str(target) + " " + str(num),
# tombo=tombodir,
# readIDdir="data/test"
# script:
# "scripts/Plasmid_R9-guppy_sup_ReadID2Signal.sh"
# rule Signal2Comparison:
# input:
# "data/test/target.upstream_downstream.bases.singal_length.txt"
# output:
# "data/test/target.upstream_downstream.bases.comparison.result.txt"
# params:
# subsampling=str(subsample)
# script:
# "scripts/Plasmid_R9-guppy_sup_Signal2Comparison.sh"
# rule Fq2info:
# input:
# "data/test/target.minus.del.fq",
# "data/test/target.plus.del.fq",
# "data/test/target.minus.match.fq",
# "data/test/target.plus.match.fq"
# output:
# "data/test/target.fq.Qscore.info.txt"
# params:
# # Dellen=str(dellen),
# # Target=str(target),
# # Rglen=str(rglen)
# opts1=str(target),
# opts2="data/test"
# #region="Zymo_Saccharomyces_cerevisiae_Seq5_ref:604-605"
# #region=ref_name + ":" + str(target) + "-" + str(int(target)+1)
# script:
# "scripts/Plasmid_R10-guppy_sup_Fq2Summary.sh"
# rule d:
# output:
# done = "results/d_done",
# md5 = "results/d_md5"
# shell:
# """
# echo "done" > {output.done}
# ssh remote -t \
# "echo .bashrc | awk '{{cmd=\\"md5sum \\"\$0;cmd | getline md5; print md5}}' > bashrc.md5"
# scp remote:/root/bashrc.md5 {output.md5}
# ssh remote -t 'rm -rf bashrc.md5'
# """
# rule all:
# input:
# "plots/quals.svg"
# rule bwa_map:
# input:
# "data/genome.fa",
# "data/samples/{sample}.fastq"
# output:
# "mapped_reads/{sample}.bam"
# shell:
# "bwa mem {input} | samtools view -Sb - > {output}"
# rule samtools_sort:
# input:
# "mapped_reads/{sample}.bam"
# output:
# "sorted_reads/{sample}.bam"
# shell:
# "samtools sort -T sorted_reads/{wildcards.sample} "
# "-O bam {input} > {output}"
# rule samtools_index:
# input:
# "sorted_reads/{sample}.bam"
# output:
# "sorted_reads/{sample}.bam.bai"
# shell:
# "samtools index {input}"
# rule bcftools_call:
# input:
# fa="data/genome.fa",
# bam=expand("sorted_reads/{sample}.bam", sample=SAMPLES),
# bai=expand("sorted_reads/{sample}.bam.bai", sample=SAMPLES)
# output:
# "calls/all.vcf"
# shell:
# "bcftools mpileup -f {input.fa} {input.bam} | "
# "bcftools call -mv - > {output}"
# rule plot_quals:
# input:
# "calls/all.vcf"
# output:
# "plots/quals.svg"
# script:
# "scripts/plot-quals.py"
# rule align:
# input:
# "{sample}.fq",
# reference="ref.fa",
# output:
# "{sample}.sam"
# params:
# opts="-a -x map-ont",
# threads: 4
# log:
# "align/{sample}.log"
# conda:
# "envs/align.yaml" #--use-conda
# script:
# "scripts/align.sh"
# # #!/usr/bin/env bash
# # echo "Aligning sample ${snakemake_wildcards[sample]} with minimap2" 2> "${snakemake_log[0]}"
# # minimap2 ${snakemake_params[opts]} -t ${snakemake[threads]} "${snakemake_input[reference]}" \
# # "${snakemake_input[0]}" > "${snakemake_output[0]}" 2>> "${snakemake_log[0]}"