Commit 4f5695d8 authored by van den Berg's avatar van den Berg
Browse files

Add test for input multiple readgroups

Add test to make sure the markdup and baserecal groups receive the
correct inputs when a sample has multiple readgroups.
parent 1ce11c64
...@@ -111,7 +111,7 @@ rule align: ...@@ -111,7 +111,7 @@ rule align:
rule markdup: rule markdup:
"""Mark duplicates in BAM file""" """Mark duplicates in BAM file"""
input: input:
bam = markdup_input_files, bam = sample_bamfiles,
tmp = ancient("tmp") tmp = ancient("tmp")
output: output:
bam = "{sample}/bams/{sample}.bam", bam = "{sample}/bams/{sample}.bam",
...@@ -119,7 +119,7 @@ rule markdup: ...@@ -119,7 +119,7 @@ rule markdup:
metrics = "{sample}/bams/{sample}.metrics" metrics = "{sample}/bams/{sample}.metrics"
log: "log/{sample}/markdup.log" log: "log/{sample}/markdup.log"
params: params:
bams=markdup_input_string bams = lambda wc: expand('INPUT={bam}', bam=sample_bamfiles(wc))
container: containers["picard"] container: containers["picard"]
shell: "picard -Xmx4G -Djava.io.tmpdir={input.tmp} MarkDuplicates " shell: "picard -Xmx4G -Djava.io.tmpdir={input.tmp} MarkDuplicates "
"CREATE_INDEX=TRUE TMP_DIR={input.tmp} " "CREATE_INDEX=TRUE TMP_DIR={input.tmp} "
...@@ -136,21 +136,16 @@ def bqsr_bam_input(wildcards): ...@@ -136,21 +136,16 @@ def bqsr_bam_input(wildcards):
rule baserecal: rule baserecal:
"""Base recalibrated BAM files""" """Base recalibrated BAM files"""
input: input:
bam = lambda wildcards: bam = sample_bamfiles,
("{sample}/bams/{sample}-{read_group}.sorted.bam".format(
sample=wildcards.sample, read_group=rg)
for rg in get_readgroup(wildcards)),
ref = config["reference"], ref = config["reference"],
vcfs = config["known_sites"] vcfs = config["known_sites"]
output: "{sample}/bams/{sample}.baserecal.grp" output: "{sample}/bams/{sample}.baserecal.grp"
log: "log/{sample}/baserecal.log" log: "log/{sample}/baserecal.log"
params: params:
known_sites = " ".join( known_sites = expand("-knownSites {vcf}", vcf=config["known_sites"]),
expand("-knownSites {vcf}", vcf=config["known_sites"])
),
region = f"-L {config['restrict_BQSR']}" if "restrict_BQSR" in config else "", region = f"-L {config['restrict_BQSR']}" if "restrict_BQSR" in config else "",
gatk_jar = config["gatk_jar"], gatk_jar = config["gatk_jar"],
bams = bqsr_bam_input bams = lambda wc: expand("-I {bam}", bam=sample_bamfiles(wc))
container: containers["gatk"] container: containers["gatk"]
shell: "java -XX:ParallelGCThreads=1 -jar {params.gatk_jar} -T " shell: "java -XX:ParallelGCThreads=1 -jar {params.gatk_jar} -T "
"BaseRecalibrator {params.bams} -o {output} -nct 8 " "BaseRecalibrator {params.bams} -o {output} -nct 8 "
......
...@@ -81,10 +81,8 @@ def coverage_files(wildcards): ...@@ -81,10 +81,8 @@ def coverage_files(wildcards):
files.append(f'{sample}/vcf/{sample}_{threshold}.bed') files.append(f'{sample}/vcf/{sample}_{threshold}.bed')
return files return files
def markdup_input_files(wildcards): def sample_bamfiles(wildcards):
""" Determine the input files for markduplicaates """ Determine the bam files for a sample (one for each readgroup)
This is the step where we merge the different per-readgroup bam files
""" """
files = list() files = list()
sample = config['samples'][wildcards.sample] sample = config['samples'][wildcards.sample]
...@@ -92,7 +90,3 @@ def markdup_input_files(wildcards): ...@@ -92,7 +90,3 @@ def markdup_input_files(wildcards):
for readgroup in sample['read_groups']: for readgroup in sample['read_groups']:
files.append(f'{sample_name}/bams/{sample_name}-{readgroup}.sorted.bam') files.append(f'{sample_name}/bams/{sample_name}-{readgroup}.sorted.bam')
return files return files
def markdup_input_string(wildcards):
"""Generate the INPUT for each bam file """
return [f'INPUT={file} ' for file in markdup_input_files(wildcards)]
...@@ -177,6 +177,9 @@ ...@@ -177,6 +177,9 @@
- Job counts - Job counts
- localrule all - localrule all
- (100%) done - (100%) done
- BaseRecalibrator -I micro/bams/micro-lib_01.sorted.bam -I micro/bams/micro-lib_02.sorted.bam
contains_regex:
- MarkDuplicates.*INPUT=micro/bams/micro-lib_01.sorted.bam INPUT=micro/bams/micro-lib_02.sorted.bam
must_not_contain: must_not_contain:
- rror - rror
files: files:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment