nf-core_modules/modules/hisat2/align/main.nf

94 lines
3.5 KiB
Text
Raw Normal View History

2020-09-10 11:45:11 -04:00
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
2020-10-14 13:29:50 -04:00
params.options = [:]
options = initOptions(params.options)
2020-10-14 13:29:50 -04:00
2020-09-10 11:45:11 -04:00
def VERSION = '2.2.0'
process HISAT2_ALIGN {
tag "$meta.id"
label 'process_high'
publishDir "${params.outdir}",
mode: params.publish_dir_mode,
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) }
2020-09-10 11:45:11 -04:00
2021-02-16 18:58:23 -05:00
conda (params.enable_conda ? "bioconda::hisat2=2.2.0 bioconda::samtools=1.10" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/mulled-v2-a97e90b3b802d1da3d6958e0867610c718cb5eb1:2880dd9d8ad0a7b221d4eacda9a818e92983128d-0"
} else {
container "quay.io/biocontainers/mulled-v2-a97e90b3b802d1da3d6958e0867610c718cb5eb1:2880dd9d8ad0a7b221d4eacda9a818e92983128d-0"
}
2020-12-17 18:50:24 -05:00
2020-09-10 11:45:11 -04:00
input:
tuple val(meta), path(reads)
path index
path splicesites
2020-12-17 18:50:24 -05:00
2020-09-10 11:45:11 -04:00
output:
tuple val(meta), path("*.bam"), emit: bam
tuple val(meta), path("*.log"), emit: summary
path "*.version.txt" , emit: version
tuple val(meta), path("*fastq.gz"), optional:true, emit: fastq
script:
def software = getSoftwareName(task.process)
2020-10-14 13:29:50 -04:00
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
2020-09-10 11:45:11 -04:00
def strandedness = ''
if (meta.strandedness == 'forward') {
strandedness = meta.single_end ? '--rna-strandness F' : '--rna-strandness FR'
} else if (meta.strandedness == 'reverse') {
strandedness = meta.single_end ? '--rna-strandness R' : '--rna-strandness RF'
}
2020-09-18 05:39:41 -04:00
def seq_center = params.seq_center ? "--rg-id ${prefix} --rg SM:$prefix --rg CN:${params.seq_center.replaceAll('\\s','_')}" : "--rg-id ${prefix} --rg SM:$prefix"
2020-09-10 11:45:11 -04:00
if (meta.single_end) {
def unaligned = params.save_unaligned ? "--un-gz ${prefix}.unmapped.fastq.gz" : ''
"""
INDEX=`find -L ./ -name "*.1.ht2" | sed 's/.1.ht2//'`
hisat2 \\
-x \$INDEX \\
-U $reads \\
$strandedness \\
--known-splicesite-infile $splicesites \\
--summary-file ${prefix}.hisat2.summary.log \\
--threads $task.cpus \\
$seq_center \\
$unaligned \\
2020-10-14 13:29:50 -04:00
$options.args \\
2020-09-10 11:45:11 -04:00
| samtools view -bS -F 4 -F 256 - > ${prefix}.bam
echo $VERSION > ${software}.version.txt
"""
} else {
def unaligned = params.save_unaligned ? "--un-conc-gz ${prefix}.unmapped.fastq.gz" : ''
"""
INDEX=`find -L ./ -name "*.1.ht2" | sed 's/.1.ht2//'`
hisat2 \\
-x \$INDEX \\
-1 ${reads[0]} \\
-2 ${reads[1]} \\
$strandedness \\
--known-splicesite-infile $splicesites \\
--summary-file ${prefix}.hisat2.summary.log \\
--threads $task.cpus \\
$seq_center \\
$unaligned \\
--no-mixed \\
--no-discordant \\
2020-10-14 13:29:50 -04:00
$options.args \\
2020-09-10 11:45:11 -04:00
| samtools view -bS -F 4 -F 8 -F 256 - > ${prefix}.bam
if [ -f ${prefix}.unmapped.fastq.1.gz ]; then
mv ${prefix}.unmapped.fastq.1.gz ${prefix}.unmapped_1.fastq.gz
fi
if [ -f ${prefix}.unmapped.fastq.2.gz ]; then
mv ${prefix}.unmapped.fastq.2.gz ${prefix}.unmapped_2.fastq.gz
fi
echo $VERSION > ${software}.version.txt
"""
}
}