diff --git a/src/nf_modules/bowtie2/main.nf b/src/nf_modules/bowtie2/main.nf index 4a670f17fbd75391e6bba6de7ed6e8f47dddaa0c..e31f560c1373aa7f18fb27474b168a00dc3c560a 100644 --- a/src/nf_modules/bowtie2/main.nf +++ b/src/nf_modules/bowtie2/main.nf @@ -100,3 +100,73 @@ process mapping_fastq { ${file_prefix}_bowtie2_mapping_report.txt """ } + + + +process mapping_fastq_chipster { + container = "${container_url}" + label "big_mem_multi_cpus" + tag "$file_id" + if (params.mapping_fastq_out != "") { + publishDir "results/${params.mapping_fastq_out}", mode: 'copy' + } + + input: + tuple val(index_id), path(index) + tuple val(file_id), path(reads), val(condition), val(type) + + output: + tuple val(file_id), path("*.bam"), val(condition), val(type), emit: bam + path "*_report.txt", emit: report + + script: + index_id = index[0] + for (index_file in index) { + if (index_file =~ /.*\.1\.bt2/ && !(index_file =~ /.*\.rev\.1\.bt2/)) { + index_id = ( index_file =~ /(.*)\.1\.bt2/)[0][1] + } + } + switch(file_id) { + case {it instanceof List}: + file_prefix = file_id[0] + break + case {it instanceof Map}: + file_prefix = file_id.values()[0] + break + default: + file_prefix = file_id + break + } + + if (reads.size() == 2) + """ + bowtie2 ${params.mapping_fastq} \ + -p ${task.cpus} \ + -x ${index_id} \ + -1 ${reads[0]} \ + -2 ${reads[1]} 2> \ + ${file_prefix}_bowtie2_mapping_report_tmp.txt | \ + samtools view -Sb - > ${file_prefix}.bam + + if grep -q "Error" ${file_prefix}_bowtie2_mapping_report_tmp.txt; then + exit 1 + fi + tail -n 19 ${file_prefix}_bowtie2_mapping_report_tmp.txt > \ + ${file_prefix}_bowtie2_mapping_report.txt + """ + else + """ + bowtie2 ${params.mapping_fastq} \ + -p ${task.cpus} \ + -x ${index_id} \ + -U ${reads} 2> \ + ${file_prefix}_bowtie2_mapping_report_tmp.txt | \ + samtools view -Sb - > ${file_prefix}.bam + + if grep -q "Error" ${file_prefix}_bowtie2_mapping_report_tmp.txt; then + exit 1 + fi + tail -n 19 ${file_prefix}_bowtie2_mapping_report_tmp.txt > \ + ${file_prefix}_bowtie2_mapping_report.txt + """ +}