Skip to content

Commit 2579f63

Browse files
tsacktonTim Sackton
andauthored
Auto-tune GenMap indexing for large genomes (#313)
Co-authored-by: Tim Sackton <timsackton@gmail.com>
1 parent 07df95b commit 2579f63

3 files changed

Lines changed: 31 additions & 6 deletions

File tree

docs/setup.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ Parabricks HaplotypeCaller also follows `variant_calling.expected_coverage` to s
151151
|`callable_sites.mappability.merge_distance`| Merge passing mappability regions within this many base pairs. | `int`|
152152
|`callable_sites.coverage.merge_distance`| Merge passing coverage regions within this many base pairs. | `int`|
153153

154+
GenMap indexing is selected automatically from the decompressed reference FASTA size. snpArcher uses the default `divsufsort` indexer for references up to 2 GiB, switches to `-S 20` above 2 GiB to reduce RAM usage, and switches to `-A skew` above 5 GiB to favor lower-memory indexing on very large genomes.
155+
154156
#### Coverage Filtering Options
155157
If `callable_sites.coverage.enabled` is set to `True`, then these options control coverage-based filtering:
156158

workflow-profiles/default/config.yaml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ default-resources:
1212

1313
# Control number of threads each rule will use.
1414
set-threads:
15-
# Mappability
16-
genmap: 1
17-
1815
# Fastq Processing
1916
get_fastq_pe: 6
2017
fastp: 6

workflow/rules/callable_sites.smk

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
from pathlib import Path
22

33

4+
GENMAP_SAMPLING_THRESHOLD_BYTES = 2 * 1024 * 1024 * 1024
5+
GENMAP_SKEW_THRESHOLD_BYTES = 5 * 1024 * 1024 * 1024
6+
GENMAP_SAMPLING_VALUE = 20
7+
8+
49
def get_callable_source_beds(_wildcards):
510
beds = []
611
if CALLABLE_COVERAGE_ENABLED:
@@ -150,6 +155,9 @@ rule genmap_index:
150155
idx=directory("results/callable_sites/genmap_index"),
151156
params:
152157
ref_decompressed=lambda wc, input: input.ref.replace(".gz", ""),
158+
sampling_threshold_bytes=GENMAP_SAMPLING_THRESHOLD_BYTES,
159+
skew_threshold_bytes=GENMAP_SKEW_THRESHOLD_BYTES,
160+
sampling_value=GENMAP_SAMPLING_VALUE,
153161
conda:
154162
"../envs/genmap.yaml"
155163
benchmark:
@@ -158,9 +166,27 @@ rule genmap_index:
158166
"logs/genmap_index.txt"
159167
shell:
160168
"""
161-
gunzip -c {input.ref} > {params.ref_decompressed}
162-
genmap index -F {params.ref_decompressed} -I {output.idx} &> {log}
163-
rm {params.ref_decompressed}
169+
set -euo pipefail
170+
171+
REF_FASTA="{params.ref_decompressed}"
172+
trap 'rm -f "$REF_FASTA"' EXIT
173+
174+
gunzip -c "{input.ref}" > "$REF_FASTA"
175+
SIZE_BYTES=$(wc -c < "$REF_FASTA" | tr -d '[:space:]')
176+
177+
: > "{log}"
178+
echo "Decompressed FASTA size (bytes): $SIZE_BYTES" >> "{log}"
179+
180+
if (( SIZE_BYTES > {params.skew_threshold_bytes} )); then
181+
echo "GenMap index mode: skew (-A skew)" >> "{log}"
182+
genmap index -F "$REF_FASTA" -I "{output.idx}" -A skew >> "{log}" 2>&1
183+
elif (( SIZE_BYTES > {params.sampling_threshold_bytes} )); then
184+
echo "GenMap index mode: sampled (-S {params.sampling_value})" >> "{log}"
185+
genmap index -F "$REF_FASTA" -I "{output.idx}" -S {params.sampling_value} >> "{log}" 2>&1
186+
else
187+
echo "GenMap index mode: default (divsufsort)" >> "{log}"
188+
genmap index -F "$REF_FASTA" -I "{output.idx}" >> "{log}" 2>&1
189+
fi
164190
"""
165191

166192

0 commit comments

Comments
 (0)