Skip to content

Commit 6d7d844

Browse files
committed
Fix alignstats rule to handle both BAM and CRAM inputs
- Add _alignstats_input() function: returns BAM+BAI for BAM_ALIGNERS, CRAM+CRAI otherwise - Add _alignstats_format() function: returns bam/cram for alignstats -j flag - Enables produce_alignstats to work with Roche BAM-only data
1 parent f8d1cd1 commit 6d7d844

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

workflow/rules/alignstats.smk

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,23 @@ import os
1313
def fetch_alnr(wildcards):
1414
return wildcards.alnr
1515

16+
17+
def _alignstats_input(wildcards):
18+
"""Return alignment file + index, choosing BAM for BAM_ALIGNERS else CRAM."""
19+
base = MDIR + f"{wildcards.sample}/align/{wildcards.alnr}/{wildcards.ddup}/{wildcards.sample}.{wildcards.alnr}.{wildcards.ddup}"
20+
if wildcards.alnr in BAM_ALIGNERS:
21+
return {"aln": base + ".bam", "idx": base + ".bam.bai"}
22+
return {"aln": base + ".cram", "idx": base + ".cram.crai"}
23+
24+
25+
def _alignstats_format(wildcards):
26+
"""Return 'bam' or 'cram' for the alignstats -j flag."""
27+
return "bam" if wildcards.alnr in BAM_ALIGNERS else "cram"
28+
29+
1630
rule alignstats:
1731
input:
18-
cram=MDIR + "{sample}/align/{alnr}/{ddup}/{sample}.{alnr}.{ddup}.cram",
19-
crai=MDIR + "{sample}/align/{alnr}/{ddup}/{sample}.{alnr}.{ddup}.cram.crai",
32+
unpack(_alignstats_input),
2033
output:
2134
json=MDIR
2235
+ "{sample}/align/{alnr}/{ddup}/alignqc/alignstats/{sample}.{alnr}.{ddup}.alignstats.json",
@@ -34,6 +47,7 @@ rule alignstats:
3447
huref=config["supporting_files"]["files"]["huref"]["fasta"]["name"],
3548
n=config["alignstats"]["num_reads_in_mem"],
3649
cluster_sample=ret_sample,
50+
aln_format=_alignstats_format,
3751
ld_preload=" "
3852
if "ld_preload" not in config["malloc_alt"]
3953
else config["malloc_alt"]["ld_preload"],
@@ -42,7 +56,7 @@ rule alignstats:
4256
conda:
4357
config["alignstats"]["env_yaml"]
4458
shell:
45-
"alignstats -C -U -i {input.cram} -T {params.huref} -o {output.json} -j cram -v -P {threads} -p {threads} > {log};"
59+
"alignstats -C -U -i {input.aln} -T {params.huref} -o {output.json} -j {params.aln_format} -v -P {threads} -p {threads} > {log};"
4660

4761

4862
localrules:

0 commit comments

Comments
 (0)