Skip to content

Commit

Permalink
Improved error handling if parameter is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
renewiegandt committed Apr 12, 2019
1 parent 2e14753 commit f210c5e
Showing 1 changed file with 55 additions and 37 deletions.
92 changes: 55 additions & 37 deletions pipeline.nf
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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:
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down

0 comments on commit f210c5e

Please sign in to comment.