2022-04-02 15:02:05 +00:00
|
|
|
//
|
|
|
|
// Process short raw reads with AdapterRemoval
|
|
|
|
//
|
2022-03-31 13:31:45 +00:00
|
|
|
|
|
|
|
include { ADAPTERREMOVAL as ADAPTERREMOVAL_SINGLE } from '../../modules/nf-core/modules/adapterremoval/main'
|
|
|
|
include { ADAPTERREMOVAL as ADAPTERREMOVAL_PAIRED } from '../../modules/nf-core/modules/adapterremoval/main'
|
|
|
|
include { CAT_FASTQ } from '../../modules/nf-core/modules/cat/fastq/main'
|
|
|
|
|
|
|
|
workflow SHORTREAD_ADAPTERREMOVAL {
|
|
|
|
|
|
|
|
take:
|
|
|
|
reads // [[meta], [reads]]
|
|
|
|
|
|
|
|
main:
|
|
|
|
ch_versions = Channel.empty()
|
|
|
|
ch_multiqc_files = Channel.empty()
|
|
|
|
|
|
|
|
ch_input_for_adapterremoval = reads
|
|
|
|
.branch{
|
2022-04-01 13:34:05 +00:00
|
|
|
single: it[0].single_end
|
|
|
|
paired: !it[0].single_end
|
2022-03-31 13:31:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ADAPTERREMOVAL_SINGLE ( ch_input_for_adapterremoval.single, [] )
|
|
|
|
ADAPTERREMOVAL_PAIRED ( ch_input_for_adapterremoval.paired, [] )
|
|
|
|
|
2022-04-02 15:05:46 +00:00
|
|
|
/*
|
|
|
|
* Due to the ~slightly~ very ugly output implementation of the current AdapterRemoval2 version, each file
|
|
|
|
* has to be exported in a separate channel and we must manually recombine when necessary.
|
|
|
|
*/
|
2022-04-01 19:36:22 +00:00
|
|
|
|
2022-03-31 13:31:45 +00:00
|
|
|
if ( params.shortread_clipmerge_mergepairs && !params.shortread_clipmerge_excludeunmerged ) {
|
2022-04-02 19:50:13 +00:00
|
|
|
|
2022-04-05 08:53:04 +00:00
|
|
|
ch_concat_fastq = Channel.empty()
|
|
|
|
.mix(
|
2022-04-02 19:50:13 +00:00
|
|
|
ADAPTERREMOVAL_PAIRED.out.collapsed,
|
|
|
|
ADAPTERREMOVAL_PAIRED.out.collapsed_truncated,
|
|
|
|
ADAPTERREMOVAL_PAIRED.out.singles_truncated,
|
2022-04-05 08:53:04 +00:00
|
|
|
ADAPTERREMOVAL_PAIRED.out.paired_truncated
|
2022-04-02 19:50:13 +00:00
|
|
|
)
|
2022-04-05 11:55:11 +00:00
|
|
|
.map { meta, reads ->
|
|
|
|
def meta_new = meta.clone()
|
|
|
|
meta_new.single_end = true
|
|
|
|
[meta_new, reads]
|
|
|
|
}
|
2022-04-05 08:53:04 +00:00
|
|
|
.groupTuple()
|
2022-04-05 09:29:39 +00:00
|
|
|
// Paired-end reads cause a nested tuple during grouping.
|
|
|
|
// We want to present a flat list of files to `CAT_FASTQ`.
|
|
|
|
.map { meta, fastq -> [meta, fastq.flatten()] }
|
2022-04-02 19:50:13 +00:00
|
|
|
|
2022-04-05 11:55:11 +00:00
|
|
|
|
2022-04-05 08:53:04 +00:00
|
|
|
CAT_FASTQ(ch_concat_fastq)
|
2022-04-02 19:50:13 +00:00
|
|
|
|
|
|
|
ch_adapterremoval_reads_prepped = CAT_FASTQ.out.reads
|
2022-04-05 08:53:04 +00:00
|
|
|
.mix(ADAPTERREMOVAL_SINGLE.out.singles_truncated)
|
2022-03-31 13:31:45 +00:00
|
|
|
|
|
|
|
} else if ( params.shortread_clipmerge_mergepairs && params.shortread_clipmerge_excludeunmerged ) {
|
|
|
|
|
2022-04-05 08:53:04 +00:00
|
|
|
ch_concat_fastq = Channel.empty()
|
|
|
|
.mix(
|
2022-04-02 19:50:13 +00:00
|
|
|
ADAPTERREMOVAL_PAIRED.out.collapsed,
|
|
|
|
ADAPTERREMOVAL_PAIRED.out.collapsed_truncated
|
|
|
|
)
|
|
|
|
.map { meta, reads ->
|
2022-04-05 11:55:11 +00:00
|
|
|
def meta_new = meta.clone()
|
|
|
|
meta_new.single_end = true
|
|
|
|
[meta_new, reads]
|
2022-04-02 19:50:13 +00:00
|
|
|
}
|
2022-04-05 08:53:04 +00:00
|
|
|
.groupTuple()
|
2022-04-08 11:46:12 +00:00
|
|
|
.map { meta, fastq -> [meta, fastq.flatten()] }
|
2022-04-05 11:55:11 +00:00
|
|
|
|
2022-03-31 13:31:45 +00:00
|
|
|
|
2022-04-05 08:53:04 +00:00
|
|
|
CAT_FASTQ(ch_concat_fastq)
|
2022-03-31 13:31:45 +00:00
|
|
|
|
2022-04-02 19:50:13 +00:00
|
|
|
ch_adapterremoval_reads_prepped = CAT_FASTQ.out.reads
|
2022-04-05 08:53:04 +00:00
|
|
|
.mix(ADAPTERREMOVAL_SINGLE.out.singles_truncated)
|
2022-03-31 13:31:45 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
2022-04-05 08:53:04 +00:00
|
|
|
ch_adapterremoval_reads_prepped = ADAPTERREMOVAL_PAIRED.out.paired_truncated
|
|
|
|
.mix(ADAPTERREMOVAL_SINGLE.out.singles_truncated)
|
2022-03-31 13:31:45 +00:00
|
|
|
|
2022-04-02 19:50:13 +00:00
|
|
|
}
|
2022-03-31 13:31:45 +00:00
|
|
|
|
|
|
|
ch_versions = ch_versions.mix( ADAPTERREMOVAL_SINGLE.out.versions.first() )
|
|
|
|
ch_versions = ch_versions.mix( ADAPTERREMOVAL_PAIRED.out.versions.first() )
|
2022-04-05 11:17:54 +00:00
|
|
|
|
2022-04-02 19:50:13 +00:00
|
|
|
ch_multiqc_files = ch_multiqc_files.mix(
|
2022-04-05 11:17:54 +00:00
|
|
|
ADAPTERREMOVAL_PAIRED.out.settings,
|
|
|
|
ADAPTERREMOVAL_SINGLE.out.settings
|
2022-04-02 19:50:13 +00:00
|
|
|
)
|
2022-03-31 13:31:45 +00:00
|
|
|
|
|
|
|
emit:
|
2022-04-02 19:50:13 +00:00
|
|
|
reads = ch_adapterremoval_reads_prepped // channel: [ val(meta), [ reads ] ]
|
|
|
|
versions = ch_versions // channel: [ versions.yml ]
|
2022-03-31 13:31:45 +00:00
|
|
|
mqc = ch_multiqc_files
|
|
|
|
}
|
2022-04-02 19:50:13 +00:00
|
|
|
|