1
0
Fork 0
mirror of https://github.com/MillironX/taxprofiler.git synced 2024-12-05 02:19:56 +00:00
taxprofiler/subworkflows/local/db_check.nf

79 lines
3.7 KiB
Text
Raw Normal View History

//
// Check input samplesheet and get read channels
//
include { UNTAR } from '../../modules/nf-core/untar/main'
workflow DB_CHECK {
take:
dbsheet // file: /path/to/dbsheet.csv
main:
ch_versions = Channel.empty()
2022-12-23 10:25:57 +00:00
ch_dbs_for_untar = Channel.empty()
ch_final_dbs = Channel.empty()
// Special check to check _between_ rows, for which we must group rows together
// Note: this will run in parallel to within-row validity, but we can assume this will run faster thus will fail first
2022-12-12 10:03:40 +00:00
Channel.fromPath(dbsheet)
.splitCsv ( header:true, sep:',' )
.map {[it.tool, it.db_name] }
.groupTuple()
.map {
tool, db_name ->
def unique_names = db_name.unique(false)
if ( unique_names.size() < db_name.size() ) error("[nf-core/taxprofiler] ERROR: Each database for a tool must have a unique name, duplicated detected. Tool: ${tool}, Database name: ${unique_names}")
2022-12-12 10:03:40 +00:00
}
// Normal checks for within-row validity, so can be moved to separate functions
parsed_samplesheet = Channel.fromPath(dbsheet)
.splitCsv ( header:true, sep:',' )
2023-03-07 11:30:02 +00:00
.map { row ->
validate_db_rows(row)
return [ row.subMap(['tool', 'db_name', 'db_params']), file(row.db_path) ]
}
2022-03-21 14:07:59 +00:00
2022-03-21 18:54:51 +00:00
ch_dbs_for_untar = parsed_samplesheet
.branch { db_meta, db ->
untar: db.name.endsWith(".tar.gz")
2022-03-21 14:07:59 +00:00
skip: true
}
// Filter the channel to untar only those databases for tools that are selected to be run by the user.
ch_input_untar = ch_dbs_for_untar.untar
.filter { db_meta, db -> params["run_${db_meta.tool}"] }
2022-12-23 10:25:57 +00:00
UNTAR (ch_input_untar)
ch_versions = ch_versions.mix(UNTAR.out.versions.first())
2022-03-21 14:58:19 +00:00
ch_final_dbs = ch_dbs_for_untar.skip.mix( UNTAR.out.untar )
2022-03-21 14:07:59 +00:00
emit:
2022-03-21 14:07:59 +00:00
dbs = ch_final_dbs // channel: [ val(meta), [ db ] ]
versions = ch_versions // channel: [ versions.yml ]
}
2023-03-07 11:30:02 +00:00
def validate_db_rows(LinkedHashMap row) {
2023-03-07 11:30:02 +00:00
// check minimum number of columns
if (row.size() < 4) error("[nf-core/taxprofiler] ERROR: Invalid database input sheet - malformed row (e.g. missing column). See documentation for more information. Error in: ${row}")
2023-03-07 11:30:02 +00:00
// all columns there
def expected_headers = ['tool', 'db_name', 'db_params', 'db_path']
if ( !row.keySet().containsAll(expected_headers) ) error("[nf-core/taxprofiler] ERROR: Invalid database input sheet - malformed column names. Please check input TSV. Column names should be: ${expected_headers.join(", ")}")
2023-03-07 11:30:02 +00:00
// valid tools specified
2023-03-11 19:06:59 +00:00
def expected_tools = [ "bracken", "centrifuge", "diamond", "kaiju", "kraken2", "krakenuniq", "malt", "metaphlan3", "motus" ]
if ( !expected_tools.contains(row.tool) ) error("[nf-core/taxprofiler] ERROR: Invalid tool name. Please see documentation for all supported profilers. Error in: ${row}")
2023-03-07 11:30:02 +00:00
// detect quotes in params
if ( row.db_params.contains('"') ) error("[nf-core/taxprofiler] ERROR: Invalid database db_params entry. No quotes allowed. Error in: ${row}")
if ( row.db_params.contains("'") ) error("[nf-core/taxprofiler] ERROR: Invalid database db_params entry. No quotes allowed. Error in: ${row}")
2023-03-07 11:30:02 +00:00
// check if any form of bracken params, that it must have `;`
if ( row.tool == 'bracken' && row.db_params && !row.db_params.contains(";") ) error("[nf-core/taxprofiler] ERROR: Invalid database db_params entry. Bracken requires a semi-colon if passing parameter. Error in: ${row}")
2023-03-07 11:30:02 +00:00
// ensure that the database directory exists
if (!file(row.db_path, type: 'dir').exists()) error("ERROR: Please check input samplesheet -> database path could not be found!\n${row.db_path}")
}