From ed5b729c8dba9e938bf6dea4ccde75dca1eaa4ab Mon Sep 17 00:00:00 2001
From: Mia Croiset <mia.croiset@ens-lyon.fr>
Date: Thu, 26 Oct 2023 17:21:36 +0200
Subject: [PATCH] bypass validation error for bin_size and co

---
 lib/WorkflowHic.groovy | 17 +++++++++++++++++
 nextflow.config        |  2 +-
 workflows/hic.nf       | 22 ++++++++++++++++++----
 3 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/lib/WorkflowHic.groovy b/lib/WorkflowHic.groovy
index f14c26c..7e833dc 100755
--- a/lib/WorkflowHic.groovy
+++ b/lib/WorkflowHic.groovy
@@ -18,6 +18,11 @@ class WorkflowHic {
             Nextflow.error "Unknown digestion protocol. Currently, the available digestion options are ${params.digest.keySet().join(", ")}. Please set manually the '--restriction_site' and '--ligation_site' parameters."
         }
 
+        checkParamIntList(params.bin_size, log)
+        checkParamIntList(params.res_dist_decay, log)
+        checkParamIntList(params.res_tads, log)
+        checkParamIntList(params.res_compartments, log)
+
         // Check Digestion or DNase Hi-C mode
         //if (!params.dnase && !params.ligation_site) {
         //  Nextflow.error "Ligation motif not found. Please either use the `--digestion` parameters or specify the `--restriction_site` and `--ligation_site`. For DNase Hi-C, please use '--dnase' option"
@@ -82,4 +87,16 @@ class WorkflowHic {
             Nextflow.error(error_string)
         }
     }
+
+    // Check the params 'list of Integer' or Integer (ex bin_size)
+    public static void checkParamIntList(def param2check, log) {
+        if (param2check instanceof Integer || (param2check instanceof String && param2check ==~ /(\d+)(,\d+)*/)){
+            //good format, do nothing
+        }
+        else {
+            println "\n"
+            log.error "ERROR: ${param2check} must be integer or list of integer"
+            Nextflow.error('Exiting!')
+        }
+    }
 }
diff --git a/nextflow.config b/nextflow.config
index abcab99..6fbc00c 100644
--- a/nextflow.config
+++ b/nextflow.config
@@ -114,7 +114,7 @@ params {
     version                    = false
     validate_params            = true
     show_hidden_params         = false
-    schema_ignore_params       = 'genomes,digest'
+    schema_ignore_params       = 'genomes,digest,bin_size,res_dist_decay,res_tads,res_compartments'
 
     // Config options
     custom_config_version      = 'master'
diff --git a/workflows/hic.nf b/workflows/hic.nf
index 11c3d81..c53fd60 100644
--- a/workflows/hic.nf
+++ b/workflows/hic.nf
@@ -41,14 +41,22 @@ if (params.digestion){
 //****************************************
 // Combine all maps resolution for downstream analysis
 
-ch_map_res = Channel.from( params.bin_size ).splitCsv().flatten().toInteger()
+if (params.bin_size instanceof Integer) {
+    ch_map_res = Channel.from( params.bin_size ).toInteger()
+}
+else {
+    ch_map_res = Channel.from( params.bin_size ).splitCsv().flatten().toInteger()
+}
 
 if (params.res_zoomify){
   ch_zoom_res = Channel.from( params.res_zoomify ).splitCsv().flatten().toInteger()
   ch_map_res = ch_map_res.concat(ch_zoom_res)
 }
 
-if (params.res_tads && !params.skip_tads){
+if (params.res_tads && !params.skip_tads && params.res_tads instanceof Integer){
+  ch_tads_res = Channel.from( "${params.res_tads}" ).toInteger()
+  ch_map_res = ch_map_res.concat(ch_tads_res)
+}else if (params.res_tads && !params.skip_tads){
   ch_tads_res = Channel.from( "${params.res_tads}" ).splitCsv().flatten().toInteger()
   ch_map_res = ch_map_res.concat(ch_tads_res)
 }else{
@@ -58,7 +66,10 @@ if (params.res_tads && !params.skip_tads){
   }
 }
 
-if (params.res_dist_decay && !params.skip_dist_decay){
+if (params.res_dist_decay && !params.skip_dist_decay && params.res_dist_decay instanceof Integer){
+  ch_ddecay_res = Channel.from( "${params.res_dist_decay}" ).toInteger()
+  ch_map_res = ch_map_res.concat(ch_ddecay_res)
+}else if (params.res_dist_decay && !params.skip_dist_decay){
   ch_ddecay_res = Channel.from( "${params.res_dist_decay}" ).splitCsv().flatten().toInteger()
   ch_map_res = ch_map_res.concat(ch_ddecay_res)
 }else{
@@ -68,7 +79,10 @@ if (params.res_dist_decay && !params.skip_dist_decay){
   }
 }
 
-if (params.res_compartments && !params.skip_compartments){
+if (params.res_compartments && !params.skip_compartments && params.res_compartments instanceof Integer){
+  ch_comp_res = Channel.from( "${params.res_compartments}" ).toInteger()
+  ch_map_res = ch_map_res.concat(ch_comp_res)
+}else if (params.res_compartments && !params.skip_compartments){
   ch_comp_res = Channel.from( "${params.res_compartments}" ).splitCsv().flatten().toInteger()
   ch_map_res = ch_map_res.concat(ch_comp_res)
 }else{
-- 
GitLab