rule delly_s: # single-sample analysis
input:
fasta=get_fasta(),
fai=get_faidx()[0],
bam=get_bam("{path}/{sample}"),
bai=get_bai("{path}/{sample}"),
excl_opt=get_bed()
params:
excl_opt='-x "%s"' % get_bed() if exclude_regions() else "",
output:
bcf = os.path.join(
"{path}",
"{sample}",
get_outdir("delly"),
"delly-{}{}".format("{sv_type}", config.file_exts.bcf),
)
conda:
"../envs/caller.yaml"
threads: 1
resources:
mem_mb=config.callers.delly.memory,
tmp_mb=config.callers.delly.tmpspace,
shell:
"""
set -xe
OUTDIR="$(dirname "{output.bcf}")"
PREFIX="$(basename "{output.bcf}" .bcf)"
OUTFILE="${{OUTDIR}}/${{PREFIX}}.unfiltered.bcf"
# run dummy or real job
if [ "{config.echo_run}" -eq "1" ]; then
echo "{input}" > "{output}"
else
# use OpenMP for threaded jobs
export OMP_NUM_THREADS={threads}
# SV calling
delly call \
-t "{wildcards.sv_type}" \
-g "{input.fasta}" \
-o "${{OUTFILE}}" \
-q 1 `# min.paired-end mapping quality` \
-s 9 `# insert size cutoff, DELs only` \
{params.excl_opt} \
"{input.bam}"
# SV quality filtering
bcftools filter \
-O b `# compressed BCF format` \
-o "{output.bcf}" \
-i "FILTER == 'PASS'" \
"${{OUTFILE}}"
# index BCF file
bcftools index "{output.bcf}"
fi
"""
rule delly_merge: # used by both modes
input:
bcf = [
os.path.join(
"{path}",
"{tumor}--{normal}",
get_outdir("delly"),
"delly-{}{}".format(sv, config.file_exts.bcf),
)
for sv in config.callers.delly.sv_types
]
if config.mode is config.mode.PAIRED_SAMPLE
else [
os.path.join(
"{path}",
"{sample}",
get_outdir("delly"),
"delly-{}{}".format(sv, config.file_exts.bcf),
)
for sv in config.callers.delly.sv_types
],
if config.mode is config.mode.PAIRED_SAMPLE
else [
os.path.join(
"{path}",
"{sample}",
get_outdir("delly"),
"delly-{}{}".format(sv, config.file_exts.bcf),
) + ".csi"
for sv in config.callers.delly.sv_types
]
output:
os.path.join(
"{path}",
"{tumor}--{normal}",
get_outdir("delly"),
"delly{}".format(config.file_exts.vcf),
)
if config.mode is config.mode.PAIRED_SAMPLE
else os.path.join(
"{path}",
"{sample}",
get_outdir("delly"),
"delly{}".format(config.file_exts.vcf),
),
conda:
"../envs/caller.yaml"
threads: 1
resources:
mem_mb=1024,
tmp_mb=0,
shell:
"""
set -x
# run dummy or real job
if [ "{config.echo_run}" -eq "1" ]; then
cat {input} > "{output}"
else
# concatenate rather than merge BCF files
bcftools concat \
-a `# allow overlaps` \
-O v `# uncompressed VCF format` \
-o "{output}" \
{input.bcf}
fi
"""