Skip to content

Commit

Permalink
feat: automatically set temp dir tempfile (#446)
Browse files Browse the repository at this point in the history
* Implemented tempdir through tempfile

* Added missing import

* Change rule name

* Trigger retest
  • Loading branch information
fgvieira committed Feb 7, 2022
1 parent e99f2a1 commit 5b0d26a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
4 changes: 2 additions & 2 deletions bio/biobambam2/bamsormadup/meta.yaml
@@ -1,6 +1,6 @@
name: BioBamBam2 BamSorMaDup
description: |
Mark PCR and optical duplicates, followed with sorting, with BioBamBam2 tools
Mark PCR and optical duplicates, followed with sorting, with BioBamBam2 tools.
authors:
- Filipe G. Vieira
input:
Expand All @@ -11,5 +11,5 @@ output:
- BAM index file (optional)
- metrics file (optional)
notes: |
* The `extra` param allows for additional program arguments (not `inputformat` or `outputformat`).
* The `extra` param allows for additional program arguments (not `inputformat`, `outputformat` or `tmpfile`).
* For more information see, https://gitlab.com/german.tischler/biobambam2
10 changes: 5 additions & 5 deletions bio/biobambam2/bamsormadup/test/Snakefile
@@ -1,15 +1,15 @@
rule mark_duplicates:
rule mark_duplicates_bamsormadup:
input:
"mapped/{sample}.bam"
"mapped/{sample}.bam",
output:
bam="dedup/{sample}.bam",
index="dedup/{sample}.bai",
metrics="dedup/{sample}.metrics.txt",
log:
"logs/{sample}.log"
"logs/{sample}.log",
params:
extra="SO=coordinate"
extra="SO=coordinate",
resources:
mem_mb=1024
mem_mb=1024,
wrapper:
"master/bio/biobambam2/bamsormadup"
21 changes: 18 additions & 3 deletions bio/biobambam2/bamsormadup/wrapper.py
Expand Up @@ -4,6 +4,9 @@


import os
import random
import tempfile
from pathlib import Path
from snakemake.shell import shell


Expand All @@ -28,6 +31,18 @@
metrics = f"M={metrics}"


shell(
"bamsormadup threads={snakemake.threads} inputformat={in_format} outputformat={out_format} {index} {metrics} {extra} < {snakemake.input[0]} > {snakemake.output[0]} {log}"
)
with tempfile.TemporaryDirectory() as tmpdir:
# This folder must not exist; it is created by BamSorMaDup
tmpdir_bamsormadup = Path(tmpdir) / "bamsormadup_{:06d}".format(
random.randrange(10 ** 6)
)

shell(
"bamsormadup threads={snakemake.threads}"
" inputformat={in_format}"
" tmpfile={tmpdir_bamsormadup}"
" outputformat={out_format}"
" {index} {metrics} {extra}"
" < {snakemake.input[0]} > {snakemake.output[0]}"
" {log}"
)

0 comments on commit 5b0d26a

Please sign in to comment.