OPTITYPE

https://img.shields.io/badge/wrapper_version-v9.9.0-10785b https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/optitype?label=version%20update%20pull%20requests&color=1cb481

Precision 4-digit HLA-I-typing from NGS data based on integer linear programming. Use razers3 beforehand to generate input fastq files only mapping to HLA-regions.

URL: https://github.com/FRED-2/OptiType

Example

This wrapper can be used in the following way:

rule optitype:
    input:
        # list of input reads
        reads=["reads/{sample}_1.fished.fastq", "reads/{sample}_2.fished.fastq"],
        #config="config_file",
    output:
        pdf="optitype/{sample}_coverage_plot.pdf",
        tsv="optitype/{sample}_result.tsv",
    log:
        "logs/optitype/{sample}.log",
    params:
        sequencing_type="dna",
        extra="",
    wrapper:
        "v9.9.0/bio/optitype"

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

  • optitype=1.5.0

Input/Output

Input:

  • reads: input FASTQ files

  • config: config.ini file

Output:

  • tsv: HLA typing results

  • pdf: coverage plot

Params

  • sequencing_type: type of sequencing data (can be ‘dna’ or ‘rna’; default is ‘dna’).

  • extra: additional program arguments

Authors

  • Jan Forster

Code

__author__ = "Jan Forster, David Lähnemann"
__copyright__ = "Copyright 2020, Jan Forster"
__email__ = "j.forster@dkfz.de"
__license__ = "MIT"


from tempfile import TemporaryDirectory
from snakemake.shell import shell

extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)

# Input
in_reads = snakemake.input.reads
if not isinstance(in_reads, list):
    in_reads = [in_reads]
in_reads = " --input ".join(in_reads)

# get sequencing type
seq_type = snakemake.params.get("sequencing_type", "dna")
seq_type = f"--{seq_type}"

# check if non-default config.ini is used
config = snakemake.input.get("config", "")
if config:
    config = f"--config {config}"

with TemporaryDirectory() as tempdir:
    shell(
        "(optitype run"
        "  --input {in_reads}"
        "  --outdir {tempdir}"
        "  --prefix tmp_prefix"
        "  {seq_type}"
        "  {config}"
        "  {extra}; "
        " mv {tempdir}/tmp_prefix_coverage_plot.pdf {snakemake.output.pdf:q} ;"
        " mv {tempdir}/tmp_prefix_result.tsv {snakemake.output.tsv:q} )"
        " {log}"
    )