From 3caf9979ac25904b38c49d96b3901b54a0e6fb2a Mon Sep 17 00:00:00 2001
From: renewiegandt <rene.wiegandt@mpi-bn.mpg.de>
Date: Tue, 16 Apr 2019 10:21:47 +0200
Subject: [PATCH] Added error message for missing required parameters

---
 pipeline.nf | 45 ++++++++++++++++++++++++---------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/pipeline.nf b/pipeline.nf
index c50ba2d..1c1230b 100644
--- a/pipeline.nf
+++ b/pipeline.nf
@@ -89,32 +89,19 @@ val_missing = false
 send_help = false
 missing_params = []
 
+//@TODO remove iteration over all parameter
 params.each { key, value ->
 	if (req_params.contains(key)){
 		if (key == "gtf_annotation" && value == "" && params.gtf_merged == ""){
 			val_missing = true
+			missing_params.add("$key or gtf_merged")
 		} else {
 			if (value == ""){
 				val_missing = true
-				missing_params + key
+				missing_params.add(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){
@@ -122,8 +109,8 @@ if (val_missing){
 	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]
+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]
 
 	Required arguments:
 		--bigwig		 Path to BigWig-file
@@ -185,8 +172,8 @@ if (send_help || "${params.help}" != "0") {
 					config
 		Evaluation:
 		--max_uropa_runs INT	 Maximum number UROPA runs running parallelized (Default: 10)
-	All arguments can be set in the configuration files
-	"""
+All arguments can be set in the configuration files
+"""
 	System.exit(2)
 } else {
 	Channel.fromPath(params.bigwig).map {it -> [it.simpleName, it]}.set {bigwig_input}
@@ -202,7 +189,23 @@ if (send_help || "${params.help}" != "0") {
 	}
 }
 
-
+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(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 (!("${params.identity}" ==~ /^0\.[8-9][[0-9]*]?|^1(\.0)?/ )){
   println("ERROR: --identity needs to be float in range 0.8 to 1.0")