Skip to content

Commit

Permalink
Bam sort memory, fix #404 (#407)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten-vd-Sande authored Jun 16, 2020
1 parent db24671 commit 4580785
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
8 changes: 4 additions & 4 deletions seq2science/rules/alignment.smk
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ rule samtools_presort:
expand("{benchmark_dir}/samtools_presort/{{assembly}}-{{sample}}.benchmark.txt", **config)[0]
params:
threads=lambda wildcards, input, output, threads: max([1, threads - 1]),
sort_order="-n" if not sieve_bam(config) and config.get("bam_sort_order") == "queryname" else "",
out_dir=f"{config['result_dir']}/{config['aligner']}"
out_dir=f"{config['result_dir']}/{config['aligner']}",
memory=lambda wildcards, input, output, threads: f"-m {int(1000 * round(config['bam_sort_mem']/threads, 3))}M"
threads: 2
resources:
mem_mb=2500
mem_gb=config['bam_sort_mem']
conda:
"../envs/samtools.yaml"
shell:
Expand All @@ -308,6 +308,6 @@ rule samtools_presort:
trap "rm -f {params.out_dir}/{wildcards.assembly}-{wildcards.sample}.tmp*bam" INT;
rm -f {params.out_dir}/{wildcards.assembly}-{wildcards.sample}.tmp*bam 2> {log}
samtools sort {params.sort_order} -@ {params.threads} {input} -o {output} \
samtools sort -@ {params.threads} {params.memory} {input} -o {output} \
-T {params.out_dir}/{wildcards.assembly}-{wildcards.sample}.tmp 2> {log}
"""
12 changes: 8 additions & 4 deletions seq2science/rules/bam_cleaning.smk
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,13 @@ rule sambamba_sort:
benchmark:
expand("{benchmark_dir}/sambamba_sort/{{assembly}}-{{sample}}-{{sorting}}{{sieve}}.benchmark.txt", **config)[0]
params:
lambda wildcards: "-n" if 'queryname' in wildcards.sorting else '',
sort_order=lambda wildcards: "-n" if 'queryname' in wildcards.sorting else '',
memory=f"-m {config['bam_sort_mem']}G"
threads: 2
conda:
"../envs/sambamba.yaml"
resources:
mem_gb=config['bam_sort_mem']
shell:
"""
sambamba view --nthreads {threads} -f bam {input} -o /dev/stdout 2> {log} |
Expand All @@ -146,10 +149,11 @@ rule samtools_sort:
params:
sort_order=lambda wildcards: "-n" if wildcards.sorting == 'queryname' else '',
threads=lambda wildcards, input, output, threads: max([1, threads - 1]),
out_dir=f"{config['result_dir']}/{config['aligner']}"
out_dir=f"{config['result_dir']}/{config['aligner']}",
memory=lambda wildcards, input, output, threads: f"-m {int(1000 * round(config['bam_sort_mem']/threads, 3))}M"
threads: 2
resources:
mem_mb=2500
mem_gb=config['bam_sort_mem']
conda:
"../envs/samtools.yaml"
shell:
Expand All @@ -158,7 +162,7 @@ rule samtools_sort:
trap "rm -f {params.out_dir}/{wildcards.assembly}-{wildcards.sample}.tmp*bam" INT;
rm -f {params.out_dir}/{wildcards.assembly}-{wildcards.sample}.tmp*bam 2> {log}
samtools sort {params.sort_order} -@ {params.threads} {input} -o {output} \
samtools sort {params.sort_order} -@ {params.threads} {params.memory} {input} -o {output} \
-T {params.out_dir}/{wildcards.assembly}-{wildcards.sample}.tmp 2> {log}
"""

Expand Down
5 changes: 5 additions & 0 deletions seq2science/schemas/config/alignment_general.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,8 @@ properties:
description: whether or not to generate a multiqc report
default: True
type: boolean

bam_sort_mem:
description: The max memory used in gigabytes by samtools/sambamba when sorting bams
default: 2
type: integer

0 comments on commit 4580785

Please sign in to comment.