kkonganti@1
|
1 process CAT_FASTQ {
|
kkonganti@1
|
2 tag "$meta.id"
|
kkonganti@1
|
3 label 'process_micro'
|
kkonganti@1
|
4
|
kkonganti@1
|
5 conda (params.enable_conda ? "conda-forge::sed=4.7 conda-forge::gzip" : null)
|
kkonganti@1
|
6 container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
|
kkonganti@1
|
7 'https://containers.biocontainers.pro/s3/SingImgsRepo/biocontainers/v1.2.0_cv1/biocontainers_v1.2.0_cv1.img' :
|
kkonganti@1
|
8 'biocontainers/biocontainers:v1.2.0_cv1' }"
|
kkonganti@1
|
9
|
kkonganti@1
|
10 input:
|
kkonganti@1
|
11 tuple val(meta), path(reads, stageAs: "input*/*")
|
kkonganti@1
|
12
|
kkonganti@1
|
13 output:
|
kkonganti@1
|
14 tuple val(meta), path("*.merged.fastq.gz"), emit: catted_reads
|
kkonganti@1
|
15 path "versions.yml" , emit: versions
|
kkonganti@1
|
16
|
kkonganti@1
|
17 when:
|
kkonganti@1
|
18 task.ext.when == null || task.ext.when
|
kkonganti@1
|
19
|
kkonganti@1
|
20 script:
|
kkonganti@1
|
21 def args = task.ext.args ?: ''
|
kkonganti@1
|
22 def prefix = task.ext.prefix ?: "${meta.id}"
|
kkonganti@1
|
23 def readList = reads.collect{ it.toString() }
|
kkonganti@1
|
24 def is_in_gz = readList[0].endsWith('.gz')
|
kkonganti@1
|
25 def gz_or_ungz = (is_in_gz ? '' : ' | gzip')
|
kkonganti@1
|
26 def pigz_or_ungz = (is_in_gz ? '' : " | pigz -p ${task.cpus}")
|
kkonganti@1
|
27 if (meta.single_end) {
|
kkonganti@1
|
28 if (readList.size > 1) {
|
kkonganti@1
|
29 """
|
kkonganti@1
|
30 zcmd="gzip"
|
kkonganti@1
|
31 zver=""
|
kkonganti@1
|
32
|
kkonganti@1
|
33 if type pigz > /dev/null 2>&1; then
|
kkonganti@1
|
34 cat ${readList.join(' ')} ${pigz_or_ungz} > ${prefix}.merged.fastq.gz
|
kkonganti@1
|
35 zcmd="pigz"
|
kkonganti@1
|
36 zver=\$( echo \$( \$zcmd --version 2>&1 ) | sed -e '1!d' | sed "s/\$zcmd //" )
|
kkonganti@1
|
37 else
|
kkonganti@1
|
38 cat ${readList.join(' ')} ${gz_or_ungz} > ${prefix}.merged.fastq.gz
|
kkonganti@1
|
39 zcmd="gzip"
|
kkonganti@1
|
40
|
kkonganti@1
|
41 if [ "${workflow.containerEngine}" != "null" ]; then
|
kkonganti@1
|
42 zver=\$( echo \$( \$zcmd --help 2>&1 ) | sed -e '1!d; s/ (.*\$//' )
|
kkonganti@1
|
43 else
|
kkonganti@1
|
44 zver=\$( echo \$( \$zcmd --version 2>&1 ) | sed "s/^.*(\$zcmd) //; s/\$zcmd //; s/ Copyright.*\$//" )
|
kkonganti@1
|
45 fi
|
kkonganti@1
|
46 fi
|
kkonganti@1
|
47
|
kkonganti@1
|
48 cat <<-END_VERSIONS > versions.yml
|
kkonganti@1
|
49 "${task.process}":
|
kkonganti@1
|
50 cat: \$( echo \$(cat --version 2>&1) | sed 's/^.*coreutils) //; s/ .*\$//' )
|
kkonganti@1
|
51 \$zcmd: \$zver
|
kkonganti@1
|
52 END_VERSIONS
|
kkonganti@1
|
53 """
|
kkonganti@1
|
54 }
|
kkonganti@1
|
55 } else {
|
kkonganti@1
|
56 if (readList.size > 2) {
|
kkonganti@1
|
57 def read1 = []
|
kkonganti@1
|
58 def read2 = []
|
kkonganti@1
|
59 readList.eachWithIndex{ v, ix -> ( ix & 1 ? read2 : read1 ) << v }
|
kkonganti@1
|
60 """
|
kkonganti@1
|
61 zcmd="gzip"
|
kkonganti@1
|
62 zver=""
|
kkonganti@1
|
63
|
kkonganti@1
|
64 if type pigz > /dev/null 2>&1; then
|
kkonganti@1
|
65 cat ${read1.join(' ')} ${pigz_or_ungz} > ${prefix}_1.merged.fastq.gz
|
kkonganti@1
|
66 cat ${read2.join(' ')} ${pigz_or_ungz} > ${prefix}_2.merged.fastq.gz
|
kkonganti@1
|
67 zcmd="pigz"
|
kkonganti@1
|
68 zver=\$( echo \$( \$zcmd --version 2>&1 ) | sed -e '1!d' | sed "s/\$zcmd //" )
|
kkonganti@1
|
69 else
|
kkonganti@1
|
70 cat ${read1.join(' ')} ${gz_or_ungz} > ${prefix}_1.merged.fastq.gz
|
kkonganti@1
|
71 cat ${read2.join(' ')} ${gz_or_ungz} > ${prefix}_2.merged.fastq.gz
|
kkonganti@1
|
72 zcmd="gzip"
|
kkonganti@1
|
73
|
kkonganti@1
|
74 if [ "${workflow.containerEngine}" != "null" ]; then
|
kkonganti@1
|
75 zver=\$( echo \$( \$zcmd --help 2>&1 ) | sed -e '1!d; s/ (.*\$//' )
|
kkonganti@1
|
76 else
|
kkonganti@1
|
77 zver=\$( echo \$( \$zcmd --version 2>&1 ) | sed "s/^.*(\$zcmd) //; s/\$zcmd //; s/ Copyright.*\$//" )
|
kkonganti@1
|
78 fi
|
kkonganti@1
|
79 fi
|
kkonganti@1
|
80
|
kkonganti@1
|
81 cat <<-END_VERSIONS > versions.yml
|
kkonganti@1
|
82 "${task.process}":
|
kkonganti@1
|
83 cat: \$( echo \$(cat --version 2>&1) | sed 's/^.*coreutils) //; s/ .*\$//' )
|
kkonganti@1
|
84 \$zcmd: \$zver
|
kkonganti@1
|
85 END_VERSIONS
|
kkonganti@1
|
86 """
|
kkonganti@1
|
87 }
|
kkonganti@1
|
88 }
|
kkonganti@1
|
89 } |