Skip to content

Commit 6c7be52

Browse files
committed
Fix rule thread assignment at parse time
1 parent 3e43481 commit 6c7be52

29 files changed

+99
-51
lines changed

workflow/Snakefile

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,11 @@ def make_resource_fn(rule_name, kind):
126126
return _fn
127127

128128

129-
def get_cpus(rule_name):
130-
return int(resources_config.get(rule_name, {}).get("cpus", resources_config["default"]["cpus"]))
131-
132-
133129
# Set the resources for all rules automatically,
134130
# without having to specify this for all of them individually.
131+
# We also re-set the threads here, just in case.
135132
# Cannot name the iteration variable `rule` here, as that conflicts...
136133
for wf_rule in workflow.rules:
137134
wf_rule.resources["mem_mb"] = make_resource_fn(wf_rule.name, "mem")
138135
wf_rule.resources["runtime"] = make_resource_fn(wf_rule.name, "time")
139-
wf_rule.threads = get_cpus(wf_rule.name)
136+
wf_rule.threads = get_rule_threads(wf_rule.name)

workflow/rules/annotation.smk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ rule snpeff:
9090
params:
9191
# For finding the chromosome names used by snpeff, add `-v` here
9292
extra=config["params"]["snpeff"]["extra"],
93+
threads: get_rule_threads("snpeff")
9394
conda:
9495
"../envs/snpeff.yaml"
9596
wrapper:
@@ -224,6 +225,7 @@ rule vep:
224225
# Plugin args can be added as well, e.g. via an entry "MyPlugin,1,FOO", see docs.
225226
plugins=config["params"]["vep"]["plugins"],
226227
extra=config["params"]["vep"]["extra"],
228+
threads: get_rule_threads("vep")
227229
log:
228230
"logs/annotation/vep-annotate.log",
229231
conda:

workflow/rules/calling-bcftools-combined.smk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ rule call_variants:
4141
mpileup=get_mpileup_params,
4242
# Optional parameters for bcftools call (except -v, -o, -m).
4343
call=config["params"]["bcftools"]["call"],
44-
threads: 1 # Dummy, but will be overwritten by our automatic resources
44+
threads: get_rule_threads("call_variants")
4545
log:
4646
"logs/calling/bcftools-call/{contig}.log",
4747
benchmark:

workflow/rules/calling-bcftools-individual.smk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ rule call_variants:
4040
mpileup=get_mpileup_params,
4141
# Optional parameters for bcftools call (except -v, -o, -m).
4242
call=config["params"]["bcftools"]["call"],
43-
threads: 1 # Dummy, but will be overwritten by our automatic resources
43+
threads: get_rule_threads("call_variants")
4444
log:
4545
"logs/calling/bcftools-call/{sample}-{contig}.log",
4646
benchmark:

workflow/rules/calling-freebayes.smk

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,16 @@ rule call_variants:
5050
output:
5151
# touch("calling/called/{contig}.vcf.done"),
5252
pipe("calling/called/{contig}.vcf"),
53-
log:
54-
"logs/calling/freebayes/{contig}.log",
55-
benchmark:
56-
"benchmarks/calling/freebayes/{contig}.log"
5753
params:
5854
# Optional extra parameters.
5955
extra=config["params"]["freebayes"]["extra"] + know_variants_extra(),
6056
# Reference genome chunk size for parallelization (default: 100000)
6157
chunksize=config["params"]["freebayes"]["chunksize"],
58+
threads: get_rule_threads("call_variants")
59+
log:
60+
"logs/calling/freebayes/{contig}.log",
61+
benchmark:
62+
"benchmarks/calling/freebayes/{contig}.log"
6263
group:
6364
"call_variants"
6465
# wrapper:
@@ -83,7 +84,7 @@ rule compress_vcf:
8384
),
8485
# protected("calling/called/{contig}.vcf.gz")
8586
touch("calling/called/{contig}.vcf.gz.done"),
86-
threads: 1 # Dummy, but will be overwritten by our automatic resources
87+
threads: 1 # Dummy, but will be overwritten by our automatic resources
8788
log:
8889
"logs/calling/compress-vcf/{contig}.log",
8990
group:

workflow/rules/calling-haplotypecaller.smk

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,17 @@ rule call_variants:
6363
else temp("calling/called/{sample}-{contig}.g.vcf.gz.tbi")
6464
),
6565
done=touch("calling/called/{sample}-{contig}.g.vcf.gz.done"),
66-
log:
67-
"logs/calling/gatk-haplotypecaller/{sample}-{contig}.log",
68-
benchmark:
69-
"benchmarks/calling/gatk-haplotypecaller/{sample}-{contig}.log"
7066
params:
7167
# The intervals param here is where the contig variable is propagated to haplotypecaller.
7268
# Contigs are used as long as no restrict-regions are given in the config file.
7369
intervals=get_gatk_intervals,
7470
extra=config["params"]["gatk"].get("HaplotypeCaller-extra", ""),
7571
java_opts=config["params"]["gatk"].get("HaplotypeCaller-java-opts", ""),
72+
threads: get_rule_threads("call_variants")
73+
log:
74+
"logs/calling/gatk-haplotypecaller/{sample}-{contig}.log",
75+
benchmark:
76+
"benchmarks/calling/gatk-haplotypecaller/{sample}-{contig}.log"
7677
group:
7778
"call_variants"
7879
conda:
@@ -142,10 +143,6 @@ rule genomics_db_import:
142143
output:
143144
db=directory("calling/genomics_db/{contig}"),
144145
done=touch("calling/genomics_db/{contig}.done"),
145-
log:
146-
"logs/calling/gatk-genomicsdbimport/{contig}.log",
147-
benchmark:
148-
"benchmarks/calling/gatk-genomicsdbimport/{contig}.log"
149146
params:
150147
# Here, we actually use the intervals to provide them to the wrapper.
151148
intervals=get_gatk_intervals,
@@ -157,6 +154,11 @@ rule genomics_db_import:
157154
+ " "
158155
+ config["params"]["gatk"].get("GenomicsDBImport-extra", ""),
159156
java_opts=config["params"]["gatk"].get("GenomicsDBImport-java-opts", ""),
157+
threads: get_rule_threads("genomics_db_import")
158+
log:
159+
"logs/calling/gatk-genomicsdbimport/{contig}.log",
160+
benchmark:
161+
"benchmarks/calling/gatk-genomicsdbimport/{contig}.log"
160162
resources:
161163
tmpdir=config["params"]["gatk"].get("GenomicsDBImport-temp-dir", ""),
162164
conda:
@@ -204,6 +206,7 @@ rule combine_calls:
204206
else ""
205207
),
206208
java_opts=config["params"]["gatk"]["CombineGVCFs-java-opts"],
209+
threads: get_rule_threads("combine_calls")
207210
log:
208211
"logs/calling/gatk-combine-gvcfs/{contig}.log",
209212
benchmark:
@@ -274,6 +277,7 @@ rule genotype_variants:
274277
+ " "
275278
+ config["params"]["gatk"]["GenotypeGVCFs-extra"],
276279
java_opts=config["params"]["gatk"]["GenotypeGVCFs-java-opts"],
280+
threads: get_rule_threads("genotype_variants")
277281
log:
278282
"logs/calling/gatk-genotype-gvcfs/{contig}.log",
279283
benchmark:
@@ -325,6 +329,7 @@ rule merge_variants:
325329
if platform.system() == "Darwin"
326330
else ""
327331
),
332+
threads: get_rule_threads("merge_variants")
328333
log:
329334
"logs/calling/picard-merge-genotyped.log",
330335
benchmark:

workflow/rules/duplicates-dedup.smk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ rule sort_reads_dedup:
7171
extra=config["params"]["samtools"]["sort"],
7272
tmp_dir=config["params"]["samtools"]["temp-dir"],
7373
# Samtools takes additional threads through its option -@
74-
threads: 1 # This value - 1 will be sent to -@. Weird flex, but okay.
74+
threads: get_rule_threads("sort_reads_dedup")
7575
log:
7676
"logs/mapping/dedup-samtools-sort/{sample}.log",
7777
benchmark:

workflow/rules/duplicates-picard.smk

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ rule mark_duplicates:
2323
),
2424
metrics="qc/dedup/{sample}.metrics.txt",
2525
done=touch("mapping/dedup/{sample}.bam.done"),
26-
log:
27-
"logs/mapping/picard-markduplicates/{sample}.log",
28-
benchmark:
29-
"benchmarks/mapping/picard-markduplicates/{sample}.log"
3026
params:
3127
# Take the params from the config.
3228
# On MacOS (we experienced it with 10.16, 11, and 12 so far), there is an issue between Java
@@ -40,6 +36,11 @@ rule mark_duplicates:
4036
else ""
4137
),
4238
java_opts=config["params"]["picard"]["MarkDuplicates-java-opts"],
39+
threads: get_rule_threads("mark_duplicates")
40+
log:
41+
"logs/mapping/picard-markduplicates/{sample}.log",
42+
benchmark:
43+
"benchmarks/mapping/picard-markduplicates/{sample}.log"
4344
group:
4445
"mapping_extra"
4546
conda:

workflow/rules/filtering-gatk-variantfiltration.smk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ rule gatk_hard_filter_calls:
2929
filters=get_filter,
3030
extra=config["params"]["gatk-variantfiltration"]["extra"],
3131
java_opts=config["params"]["gatk-variantfiltration"]["java-opts"],
32+
threads: get_rule_threads("gatk_hard_filter_calls")
3233
log:
3334
"logs/calling/gatk-variantfiltration/{vartype}.log",
3435
benchmark:

workflow/rules/filtering-gatk-vqsr.smk

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ rule gatk_variant_recalibrator:
101101
# Extras
102102
extra=get_variant_recalibrator_extra,
103103
java_opts=config["params"]["gatk-vqsr"]["variantrecalibrator-java-opts"],
104+
threads: get_rule_threads("gatk_variant_recalibrator")
104105
log:
105106
"logs/calling/gatk-variantrecalibrator/{vartype}.log",
106107
benchmark:
@@ -132,15 +133,16 @@ rule gatk_apply_vqsr:
132133
else temp("calling/filtered/all.{vartype}.recalibrated.vcf.gz")
133134
),
134135
done=touch("calling/filtered/all.{vartype}.recalibrated.vcf.gz.done"),
135-
log:
136-
"logs/calling/gatk-applyvqsr/{vartype}.log",
137-
benchmark:
138-
"benchmarks/calling/gatk-applyvqsr/{vartype}.log"
139136
params:
140137
# set mode, must be either SNP, INDEL or BOTH
141138
mode="{vartype}",
142139
extra=get_apply_vqsr_extra,
143140
java_opts=config["params"]["gatk-vqsr"]["applyvqsr-java-opts"],
141+
threads: get_rule_threads("gatk_apply_vqsr")
142+
log:
143+
"logs/calling/gatk-applyvqsr/{vartype}.log",
144+
benchmark:
145+
"benchmarks/calling/gatk-applyvqsr/{vartype}.log"
144146
conda:
145147
# We overwrite the original yaml, as this wrapper here (version 0.85.0) and the one above
146148
# for the variantrecalibrator (also 0.85.0) use different GATK versions originally...

0 commit comments

Comments
 (0)