HISAT2

Map reads with hisat2.

Software dependencies

  • hisat2 ==2.1.0
  • samtools ==1.5

Example

This wrapper can be used in the following way:

rule hisat2:
    input:
      reads=["reads/{sample}.1.fastq.gz", "reads/{sample}.2.fastq.gz"],
    output:
      "mapped/{sample}.bam"
    log:                                # optional
      "logs/hisat2/{sample}.log"
    params:                             # idx is required, extra is optional
      idx="genome.fa",
      extra="--min-intronlen 1000"
    threads: 8                          # optional, defaults to 1
    wrapper:
      "0.20.1/bio/hisat2"

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.

Notes

  • The -S flag must not be used since output is already directly piped to samtools for compression.
  • The –threads/-p flag must not be used since threads is set separately via the snakemake threads directive.
  • The wrapper does not yet handle SRA input accessions.
  • No reference index files checking is done since the actual number of files may differ depending on the reference sequence size. This is also why the index is supplied in the params directive instead of the input directive.

Authors

  • Wibowo Arindrarto

Code

__author__ = "Wibowo Arindrarto"
__copyright__ = "Copyright 2016, Wibowo Arindrarto"
__email__ = "bow@bow.web.id"
__license__ = "BSD"


from snakemake.shell import shell

# Placeholder for optional parameters
extra = snakemake.params.get("extra", "")
# Run log
log = snakemake.log_fmt_shell()

# Input file wrangling
reads = snakemake.input.get("reads")
if isinstance(reads, str):
    input_flags = "-U {0}".format(reads)
elif len(reads) == 1:
    input_flags = "-U {0}".format(reads[0])
elif len(reads) == 2:
    input_flags = "-1 {0} -2 {1}".format(*reads)
else:
    raise RuntimeError(
        "Reads parameter must contain at least 1 and at most 2"
        " input files.")

# Executed shell command
shell(
    "(hisat2 {extra} --threads {snakemake.threads}"
    " -x {snakemake.params.idx} {input_flags}"
    " | samtools view -Sbh -o {snakemake.output[0]} -)"
    " {log}")