From f210c5e7f65f57a09a455d536a287a00edd53fbb Mon Sep 17 00:00:00 2001 From: renewiegandt Date: Fri, 12 Apr 2019 14:44:32 +0200 Subject: [PATCH] Improved error handling if parameter is missing --- pipeline.nf | 92 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 37 deletions(-) diff --git a/pipeline.nf b/pipeline.nf index 44104e7..c50ba2d 100644 --- a/pipeline.nf +++ b/pipeline.nf @@ -68,7 +68,60 @@ disable_mo_clu = 1 //evaluation params.max_uropa_runs = 10 -if (params.bigwig == "" || params.bed == "" || params.organism == "" || params.genome_fasta == "" || params.motif_db == "" || params.config == "" || (params.gtf_annotation == "" && params.gtf_merged == "" ) || "${params.help}" != "0" ) { +/* +Checking for parameter input! +*/ +int_params = ["window_length", "step", "min_size_fp", "max_size_fp", "kmer", + "aprox_motif_len", "motif_occurrence", "min_seq_length", "global", + "sequence_coverage", "memory", "throw_away_seq", "strand", + "min_seq", "motif_min_key", "motif_max_key", "iteration", + "edge_weight", "best_motif", "min_gap", "gap_penalty", "edge_weight", + "threads", "max_uropa_runs"] +file_params = ["bigwig", "bed", "genome_fasta", "motif_db", "config", "gtf_annotation",] +all_params = int_params + file_params + ["organism" , "identity", "tfbsscan_method", + "percentage", "tomtom_treshold", "motif_similarity_thresh", "out", + "tissues", "gtf_merged", "cluster_motif", "tfbs_path", "help", "seed"] +req_params = file_params + ["organism"] + +valid_organism = ["hg38", "hg19", "mm9", "mm10"] +valid_tfbsscan_methods = ["moods","fimo"] +val_missing = false +send_help = false +missing_params = [] + +params.each { key, value -> + if (req_params.contains(key)){ + if (key == "gtf_annotation" && value == "" && params.gtf_merged == ""){ + val_missing = true + } else { + if (value == ""){ + val_missing = true + missing_params + key + } + } + } + if (!(all_params.contains(key))){ + println("Warning: Parameter $key is unknown. Please check for typos or the parameter list!") + } + if(int_params.contains(key)) { + if (!("${value}" ==~ /\d+/ )){ + println("ERROR: $key needs to be an Integer") + System.exit(2) + } + } + if(file_params.contains(key) || (key == "gtf_merged" && value != "") ) { + if(!file(value).exists()) { + println("ERROR: $key not found. Please check the given path.") + System.exit(2) + } + } +} + +if (val_missing){ + send_help = true + println("Error: Following required parameters are missing: $missing_params") +} +if (send_help || "${params.help}" != "0") { log.info """ Usage: nextflow run pipeline.nf --bigwig [BigWig-file] --bed [BED-file] --genome_fasta [FASTA-file] --motif_db [MEME-file] --config [UROPA-config-file] @@ -79,7 +132,7 @@ if (params.bigwig == "" || params.bed == "" || params.organism == "" || params.g --motif_db Path to motif-database in MEME-format --config Path to UROPA configuration file --gtf_annotation Path to gtf annotation file - --organism Input organism [hg38 | hg19 | mm9 | mm10] + --organism Input organism [hg38 | hg19 | mm9 | mm10] --out Output Directory (Default: './out/') Optional arguments: @@ -133,7 +186,6 @@ if (params.bigwig == "" || params.bed == "" || params.organism == "" || params.g Evaluation: --max_uropa_runs INT Maximum number UROPA runs running parallelized (Default: 10) All arguments can be set in the configuration files - ``` """ System.exit(2) } else { @@ -152,40 +204,6 @@ if (params.bigwig == "" || params.bed == "" || params.organism == "" || params.g -/* -Checking for parameter input! -*/ -int_params = ["window_length", "step", "min_size_fp", "max_size_fp", "kmer", - "aprox_motif_len", "motif_occurrence", "min_seq_length", "global", - "sequence_coverage", "memory", "throw_away_seq", "strand", - "min_seq", "motif_min_key", "motif_max_key", "iteration", - "edge_weight", "best_motif", "min_gap", "gap_penalty", "edge_weight", - "threads", "max_uropa_runs"] -req_params = ["bigwig", "bed", "genome_fasta", "motif_db", "config"] -all_params = int_params + req_params + ["organism" , "identity", "tfbsscan_method", - "percentage", "tomtom_treshold", "motif_similarity_thresh", "out", - "tissues", "gtf_merged", "cluster_motif", "tfbs_path", "help", "gtf_annotation", "seed"] - -valid_organism = ["hg38", "hg19", "mm9", "mm10"] -valid_tfbsscan_methods = ["moods","fimo"] - -params.each { key, value -> - if (!(all_params.contains(key))){ - println("Warning: Parameter $key is unknown. Please check for typos or the parameter list!") - } - if(int_params.contains(key)) { - if (!("${value}" ==~ /\d+/ )){ - println("ERROR: $key needs to be an Integer") - System.exit(2) - } - } - if(req_params.contains(key) || (key == "gtf_merged" && value != "") ) { - if(!file(value).exists()) { - println("ERROR: $key not found. Please check the given path.") - System.exit(2) - } - } -} if (!("${params.identity}" ==~ /^0\.[8-9][[0-9]*]?|^1(\.0)?/ )){ println("ERROR: --identity needs to be float in range 0.8 to 1.0") System.exit(2)