SNP-MUTATOR

Generate mutated sequence files from a reference genome.

URL:

Example

This wrapper can be used in the following way:

NUM_SIMULATIONS = 2

rule snpmutator:
    input:
        "{sample}.fa"
    output:
        vcf = "{sample}.mutated.vcf",
        sequences = expand(
            "{{sample}}_mutated_{simulation_number}.fasta",
            simulation_number=range(1, NUM_SIMULATIONS + 1)
        )
    params:
        num_simulations = NUM_SIMULATIONS,
        extra = " ".join([
            "--num-substitutions 2",
            "--num-insertions 2",
            "--num-deletions 0"
        ]),
    log:
        "logs/snp-mutator/test/{sample}.log"
    wrapper:
        "v1.1.0/bio/snp-mutator"

Note that input, output and log file paths can be chosen freely.

When running with

snakemake --use-conda

the software dependencies will be automatically deployed into an isolated environment before execution.

Software dependencies

  • snp-mutator==1.2.0

Authors

  • Michael Hall

Code

"""Snakemake wrapper for SNP Mutator."""

__author__ = "Michael Hall"
__copyright__ = "Copyright 2019, Michael Hall"
__email__ = "mbhall88@gmail.com"
__license__ = "MIT"


from snakemake.shell import shell
from pathlib import Path

# Placeholder for optional parameters
extra = snakemake.params.get("extra", "")
num_simulations = snakemake.params.get("num_simulations", 100)
fasta_outdir = Path(snakemake.output.sequences[0]).absolute().parent
# Formats the log redrection string
log = snakemake.log_fmt_shell(stdout=True, stderr=True)

# Executed shell command
shell(
    "snpmutator {extra} "
    "--num-simulations {num_simulations} "
    "--vcf {snakemake.output.vcf} "
    "-F {fasta_outdir} "
    "{snakemake.input} {log} "
)