1
0
Fork 0
mirror of https://github.com/MillironX/taxprofiler.git synced 2024-11-28 15:49:54 +00:00
taxprofiler/subworkflows/local/input_check.nf

93 lines
3.1 KiB
Text
Raw Normal View History

//
// Check input samplesheet and get read channels
//
include { SAMPLESHEET_CHECK } from '../../modules/local/samplesheet_check'
workflow INPUT_CHECK {
take:
samplesheet // file: /path/to/samplesheet.csv
main:
parsed_samplesheet = SAMPLESHEET_CHECK ( samplesheet )
.csv
.splitCsv ( header:true, sep:',' )
.dump(tag: "input_split_csv_out")
.branch {
fasta: it['fasta'] != ''
2022-03-18 09:45:06 +00:00
nanopore: it['instrument_platform'] == 'OXFORD_NANOPORE'
fastq: true
}
parsed_samplesheet.fastq
2022-03-18 09:47:41 +00:00
.map { create_fastq_channel(it) }
.dump(tag: "fastq_channel_init")
.set { fastq }
2022-03-18 09:47:41 +00:00
parsed_samplesheet.nanopore
.map { create_fastq_channel(it) }
.dump(tag: "fastq_nanopore_channel_init")
.set { nanopore }
parsed_samplesheet.fasta
2022-03-21 19:28:09 +00:00
.map { create_fasta_channel(it) }
.dump(tag: "fasta_channel_init")
.set { fasta }
emit:
fastq // channel: [ val(meta), [ reads ] ]
2022-03-18 09:47:41 +00:00
nanopore // channel: [ val(meta), [ reads ] ]
fasta // channel: [ val(meta), fasta ]
versions = SAMPLESHEET_CHECK.out.versions // channel: [ versions.yml ]
}
// Function to get list of [ meta, [ fastq_1, fastq_2 ] ]
2022-03-21 19:28:09 +00:00
def create_fastq_channel(LinkedHashMap row) {
// create meta map
def meta = [:]
meta.id = row.sample
meta.run_accession = row.run_accession
meta.instrument_platform = row.instrument_platform
meta.single_end = row.single_end.toBoolean()
// add path(s) of the fastq file(s) to the meta map
def fastq_meta = []
if (!file(row.fastq_1).exists()) {
exit 1, "ERROR: Please check input samplesheet -> Read 1 FastQ file does not exist!\n${row.fastq_1}"
}
if (meta.single_end) {
fastq_meta = [ meta, [ file(row.fastq_1) ] ]
} else {
2022-03-18 09:47:41 +00:00
if (meta.instrument_platform == 'OXFORD_NANOPORE') {
if (row.fastq_2 != '') {
exit 1, "ERROR: Please check input samplesheet -> For Oxford Nanopore reads Read 2 FastQ should be empty!\n${row.fastq_2}"
}
fastq_meta = [ meta, [ file(row.fastq_1) ] ]
} else {
if (!file(row.fastq_2).exists()) {
exit 1, "ERROR: Please check input samplesheet -> Read 2 FastQ file does not exist!\n${row.fastq_2}"
}
2022-03-24 11:51:45 +00:00
fastq_meta = [ meta, [ file(row.fastq_1), file(row.fastq_2) ] ]
}
2022-03-24 11:51:45 +00:00
}
return fastq_meta
}
// Function to get list of [ meta, fasta ]
2022-03-21 19:28:09 +00:00
def create_fasta_channel(LinkedHashMap row) {
def meta = [:]
meta.id = row.sample
meta.run_accession = row.run_accession
meta.instrument_platform = row.instrument_platform
meta.single_end = true
def array = []
if (!file(row.fasta).exists()) {
exit 1, "ERROR: Please check input samplesheet -> FastA file does not exist!\n${row.fasta}"
}
array = [ meta, [ file(row.fasta) ] ]
return array
}