11rule snps_to_ancestor :
22 threads : 2
33 retries : 3
4- shadow : "minimal"
5- conda : "../envs/var_calling.yaml"
4+ shadow :
5+ "minimal"
6+ conda :
7+ "../envs/var_calling.yaml"
68 params :
7- mpileup_depth = config ["VC" ]["MAX_DEPTH" ],
8- mpileup_quality = 0 ,
9- ivar_quality = config ["VC" ]["MIN_QUALITY" ],
10- ivar_freq = config ["VC" ]["MIN_FREQ" ],
11- ivar_depth = config ["VC" ]["MIN_DEPTH" ],
9+ mpileup_depth = config ["VC" ]["MAX_DEPTH" ],
10+ mpileup_quality = 0 ,
11+ ivar_quality = config ["VC" ]["MIN_QUALITY" ],
12+ ivar_freq = config ["VC" ]["MIN_FREQ" ],
13+ ivar_depth = config ["VC" ]["MIN_DEPTH" ],
1214 input :
13- reference_fasta = OUTDIR / f"{ OUTPUT_NAME } .ancestor.fasta" ,
14- bam = get_input_bam ,
15- gff = OUTDIR / "reference.gff3"
15+ reference_fasta = OUTDIR / f"{ OUTPUT_NAME } .ancestor.fasta" ,
16+ bam = get_input_bam ,
17+ gff = OUTDIR / "reference.gff3" ,
1618 output :
17- tsv = temp (OUTDIR / "vaf" / "{sample}.tsv" ),
18- reference_fasta_renamed = temp (OUTDIR / "vaf" / "{sample}.reference.fasta" ),
19+ tsv = temp (OUTDIR / "vaf" / "vc" / "{sample}.tsv" ),
20+ reference_fasta_renamed = temp (OUTDIR / "vaf" / "{sample}.reference.fasta" ),
1921 log :
20- LOGDIR / "snps_to_ancestor" / "{sample}.log.txt"
22+ LOGDIR / "snps_to_ancestor" / "{sample}.log.txt" ,
2123 shell :
2224 """
2325 set -e
@@ -55,65 +57,70 @@ rule snps_to_ancestor:
5557
5658rule mask_tsv :
5759 threads : 1
58- conda : "../envs/biopython.yaml"
60+ conda :
61+ "../envs/biopython.yaml"
5962 params :
60- mask_class = ["mask" ]
61- input :
62- tsv = OUTDIR / "vaf" / "{sample}.tsv" ,
63- vcf = lambda wildcards : select_problematic_vcf ()
63+ mask_class = ["mask" ],
64+ input :
65+ tsv = OUTDIR / "vaf" / "vc" / "{sample}.tsv" ,
66+ vcf = lambda wildcards : select_problematic_vcf (),
6467 output :
65- masked_tsv = temp (OUTDIR / "vaf" / " {sample}.masked. tsv" )
68+ masked_tsv = temp (OUTDIR / "vaf" / "masked" / " {sample}.tsv" ),
6669 log :
67- LOGDIR / "mask_tsv" / "{sample}.log.txt"
70+ LOGDIR / "mask_tsv" / "{sample}.log.txt" ,
6871 script :
6972 "../scripts/mask_tsv.py"
7073
7174
7275rule filter_tsv :
7376 threads : 1
74- conda : "../envs/renv.yaml"
77+ conda :
78+ "../envs/renv.yaml"
7579 params :
76- min_depth = 20 ,
77- min_alt_rv = 2 ,
78- min_alt_dp = 2 ,
79- input :
80- tsv = OUTDIR / "vaf" / " {sample}.masked. tsv"
80+ min_depth = 20 ,
81+ min_alt_rv = 2 ,
82+ min_alt_dp = 2 ,
83+ input :
84+ tsv = OUTDIR / "vaf" / "masked" / " {sample}.tsv",
8185 output :
82- filtered_tsv = temp (OUTDIR / "vaf" / " {sample}.masked.prefiltered. tsv" )
86+ filtered_tsv = temp (OUTDIR / "vaf" / "filtered" / " {sample}.tsv" ),
8387 log :
84- LOGDIR / "filter_tsv" / "{sample}.log.txt"
88+ LOGDIR / "filter_tsv" / "{sample}.log.txt" ,
8589 script :
8690 "../scripts/filter_tsv.R"
8791
8892
8993rule tsv_to_vcf :
9094 threads : 1
91- conda : "../envs/biopython.yaml"
95+ conda :
96+ "../envs/biopython.yaml"
9297 params :
93- ref_name = config ["ALIGNMENT_REFERENCE" ],
94- input :
95- tsv = OUTDIR / "vaf" / " {sample}.masked.prefiltered .tsv" ,
98+ ref_name = config ["ALIGNMENT_REFERENCE" ],
99+ input :
100+ tsv = OUTDIR / "vaf" / "filtered" / " {sample}.tsv" ,
96101 output :
97- vcf = temp (OUTDIR / "vaf" / " {sample}.vcf" )
102+ vcf = temp (OUTDIR / "vaf" / "vcf" / " {sample}.vcf" ),
98103 log :
99- LOGDIR / "tsv_to_vcf" / "{sample}.log.txt"
104+ LOGDIR / "tsv_to_vcf" / "{sample}.log.txt" ,
100105 script :
101106 "../scripts/tsv_to_vcf.py"
102107
103108
104109rule variants_effect :
105110 threads : 1
106- shadow : "minimal"
107- conda : "../envs/snpeff.yaml"
111+ shadow :
112+ "minimal"
113+ conda :
114+ "../envs/snpeff.yaml"
108115 params :
109- ref_name = config ["ALIGNMENT_REFERENCE" ],
110- snpeff_data_dir = (BASE_PATH / "config" / "snpeff" ).resolve ()
116+ ref_name = config ["ALIGNMENT_REFERENCE" ],
117+ snpeff_data_dir = (BASE_PATH / "config" / "snpeff" ).resolve (),
111118 input :
112- vcf = OUTDIR / "vaf" / " {sample}.vcf"
119+ vcf = OUTDIR / "vaf" / "vcf" / " {sample}.vcf",
113120 output :
114- ann_vcf = OUTDIR / "vaf" / " {sample}.annotated. vcf"
121+ ann_vcf = OUTDIR / "vaf" / "annotated" / " {sample}.vcf",
115122 log :
116- LOGDIR / "variants_effect" / "{sample}.log.txt"
123+ LOGDIR / "variants_effect" / "{sample}.log.txt" ,
117124 retries : 2
118125 shell :
119126 """
@@ -133,74 +140,82 @@ rule variants_effect:
133140
134141rule extract_vcf_fields :
135142 threads : 1
136- conda : "../envs/snpeff.yaml"
143+ conda :
144+ "../envs/snpeff.yaml"
137145 params :
138- extract_columns = [f"'{ col } '" for col in config ["ANNOTATION" ]["SNPEFF_COLS" ].values ()],
139- sep = "," ,
146+ extract_columns = [
147+ f"'{ col } '" for col in config ["ANNOTATION" ]["SNPEFF_COLS" ].values ()
148+ ],
149+ sep = "," ,
140150 input :
141- vcf = OUTDIR / "vaf" / " {sample}.annotated. vcf"
151+ vcf = OUTDIR / "vaf" / "annotated" / " {sample}.vcf",
142152 output :
143- tsv = OUTDIR / "vaf" / " {sample}.vcf_fields. tsv"
153+ tsv = OUTDIR / "vaf" / "fields" / " {sample}.tsv",
144154 log :
145- LOGDIR / "tsv_to_vcf" / "{sample}.log.txt"
155+ LOGDIR / "tsv_to_vcf" / "{sample}.log.txt" ,
146156 shell :
147157 "SnpSift extractFields -e 'NA' -s {params.sep:q} {input.vcf:q} {params.extract_columns} >{output.tsv:q} 2>{log:q}"
148158
149159
150160rule format_vcf_fields_longer :
151- conda : "../envs/renv.yaml"
161+ conda :
162+ "../envs/renv.yaml"
152163 params :
153- sample = "{sample}" ,
154- colnames_mapping = config ["ANNOTATION" ]["SNPEFF_COLS" ],
155- filter_include = config ["ANNOTATION" ]["FILTER_INCLUDE" ],
156- filter_exclude = config ["ANNOTATION" ]["FILTER_EXCLUDE" ],
157- variant_name_pattern = lambda wildcards : config ["ANNOTATION" ]["VARIANT_NAME_PATTERN" ], # lambda to deactivate automatic wildcard expansion in pattern
158- sep = "," ,
164+ sample = "{sample}" ,
165+ colnames_mapping = config ["ANNOTATION" ]["SNPEFF_COLS" ],
166+ filter_include = config ["ANNOTATION" ]["FILTER_INCLUDE" ],
167+ filter_exclude = config ["ANNOTATION" ]["FILTER_EXCLUDE" ],
168+ variant_name_pattern = lambda wildcards : config ["ANNOTATION" ][
169+ "VARIANT_NAME_PATTERN"
170+ ], # lambda to deactivate automatic wildcard expansion in pattern
171+ sep = "," ,
159172 input :
160- tsv = OUTDIR / "vaf" / " {sample}.vcf_fields .tsv" ,
173+ tsv = OUTDIR / "vaf" / "fields" / " {sample}.tsv" ,
161174 output :
162- tsv = OUTDIR / "vaf" / " {sample}.vcf_fields.longer .tsv" ,
175+ tsv = OUTDIR / "vaf" / "fields_longer" / " {sample}.tsv" ,
163176 log :
164- LOGDIR / "format_vcf_fields_longer" / "{sample}.log.txt"
177+ LOGDIR / "format_vcf_fields_longer" / "{sample}.log.txt" ,
165178 script :
166179 "../scripts/format_vcf_fields_longer.R"
167180
168181
169182rule concat_vcf_fields :
170183 params :
171- sep = "\t " ,
184+ sep = "\t " ,
172185 input :
173- expand (OUTDIR / "vaf" / " {sample}.vcf_fields.longer .tsv" , sample = iter_samples ()),
186+ expand (OUTDIR / "vaf" / "fields_longer" / " {sample}.tsv" , sample = iter_samples ()),
174187 output :
175- OUTDIR / f"{ OUTPUT_NAME } .vcf_fields.longer.tsv" ,
188+ OUTDIR / f"{ OUTPUT_NAME } .vcf_fields.longer.tsv" ,
176189 run :
177190 import pandas as pd
178191 from functools import reduce
192+
179193 reduce (
180194 lambda a , b : pd .concat ((a , b ), axis = "rows" , ignore_index = True ),
181- (pd .read_csv (path , sep = params .sep ) for path in input )
195+ (pd .read_csv (path , sep = params .sep ) for path in input ),
182196 ).to_csv (output [0 ], sep = params .sep , index = False )
183197
184198
185199rule merge_annotation :
186200 threads : 1
187- conda : "../envs/renv.yaml"
201+ conda :
202+ "../envs/renv.yaml"
188203 params :
189- sample = "{sample}" ,
190- ref_name = config ["ALIGNMENT_REFERENCE" ],
204+ sample = "{sample}" ,
205+ ref_name = config ["ALIGNMENT_REFERENCE" ],
191206 input :
192- tsv = OUTDIR / "vaf" / " {sample}.masked.prefiltered .tsv" ,
193- annot = OUTDIR / "vaf" / " {sample}.vcf_fields.longer .tsv" ,
207+ tsv = OUTDIR / "vaf" / "filtered" / " {sample}.tsv" ,
208+ annot = OUTDIR / "vaf" / "fields_longer" / " {sample}.tsv" ,
194209 output :
195- tsv = OUTDIR / "vaf" / " {sample}.variants. tsv"
210+ tsv = OUTDIR / "vaf" / "variants" / " {sample}.tsv",
196211 log :
197- LOGDIR / "merge_annotation" / "{sample}.log.txt"
212+ LOGDIR / "merge_annotation" / "{sample}.log.txt" ,
198213 script :
199214 "../scripts/merge_annotation.R"
200215
201216
202217use rule concat_vcf_fields as concat_variants with :
203218 input :
204- expand (OUTDIR / "vaf" / " {sample}.variants .tsv" , sample = iter_samples ()),
219+ expand (OUTDIR / "vaf" / "variants" / " {sample}.tsv" , sample = iter_samples ()),
205220 output :
206- OUTDIR / f"{ OUTPUT_NAME } .variants.tsv" ,
221+ OUTDIR / f"{ OUTPUT_NAME } .variants.tsv" ,
0 commit comments