HISAT2 ALIGN
Map reads with hisat2.
URL: http://daehwankimlab.github.io/hisat2
Example
This wrapper can be used in the following way:
rule hisat2_align:
input:
reads=["reads/{sample}_R1.fastq", "reads/{sample}_R2.fastq"],
idx=multiext(
"index/ref",
".1.ht2",
".2.ht2",
".3.ht2",
".4.ht2",
".5.ht2",
".6.ht2",
".7.ht2",
".8.ht2",
),
output:
"mapped/{sample}.bam",
log:
"logs/hisat2_align_{sample}.log",
params:
extra="",
threads: 2
wrapper:
"v5.7.0/bio/hisat2/align"
rule hisat2_alignL:
input:
reads=["reads/{sample}_R1.fastq", "reads/{sample}_R2.fastq"],
idx=multiext(
"index/ref",
".1.ht2l",
".2.ht2l",
".3.ht2l",
".4.ht2l",
".5.ht2l",
".6.ht2l",
".7.ht2l",
".8.ht2l",
),
output:
"mappedL/{sample}.bam",
log:
"logs/hisat2_alignL_{sample}.log",
params:
extra="",
threads: 2
wrapper:
"v5.7.0/bio/hisat2/align"
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.
Software dependencies
hisat2=2.2.1
samtools=1.21
Input/Output
Input:
reads
: either 1 or 2 FASTQ files with readsidx
: index files
Output:
bam file with mapped reads
Params
extra
: additional parameters
Code
__author__ = "Wibowo Arindrarto"
__copyright__ = "Copyright 2016, Wibowo Arindrarto"
__email__ = "bow@bow.web.id"
__license__ = "BSD"
import os
from snakemake.shell import shell
# Placeholder for optional parameters
extra = snakemake.params.get("extra", "")
# Run log
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
# Input file wrangling
reads = snakemake.input.get("reads")
if isinstance(reads, str):
input_flags = f"-U {reads}"
elif len(reads) == 1:
input_flags = f"-U {reads[0]}"
elif len(reads) == 2:
input_flags = f"-1 {reads[0]} -2 {reads[1]}"
else:
raise RuntimeError(
"Reads parameter must contain at least 1 and at most 2 input files."
)
# Index path
idx_prefix = os.path.commonprefix(snakemake.input.idx).rstrip(".")
# Executed shell command
shell(
"(hisat2"
" --threads {snakemake.threads}"
" -x {idx_prefix}"
" {extra}"
" {input_flags}"
" | samtools view -Sbh -o {snakemake.output[0]} -"
") {log}"
)