diff --git a/lib/WorkflowHic.groovy b/lib/WorkflowHic.groovy index 7e833dca3a57b706495ecc34d33497f9c6f499cd..74b621b4655c25afb12cb5960300186aaf2a79af 100755 --- a/lib/WorkflowHic.groovy +++ b/lib/WorkflowHic.groovy @@ -3,7 +3,9 @@ // import nextflow.Nextflow +import nextflow.Channel import groovy.text.SimpleTemplateEngine +import groovyx.gpars.dataflow.DataflowWriteChannel class WorkflowHic { @@ -90,13 +92,19 @@ class WorkflowHic { // 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" + if (param2check !instanceof Integer && !(param2check instanceof String && param2check ==~ /(\d+)(,\d+)*/)){ println "\n" log.error "ERROR: ${param2check} must be integer or list of integer" Nextflow.error('Exiting!') } } + + // In hic.nf: check if the param is int. If true, don't splitCsv and flatten to avoid error + public static DataflowWriteChannel checkIfInt(def param2check) { + if (param2check instanceof Integer) { + return Channel.from( param2check ).toInteger() + } + else { + return Channel.from( param2check ).splitCsv().flatten().toInteger() + } + } } diff --git a/workflows/hic.nf b/workflows/hic.nf index c53fd6012f571f3841b234097c478b949ebb33fc..68b4ef884b31c9a9ae8073daa84dc80108c364e6 100644 --- a/workflows/hic.nf +++ b/workflows/hic.nf @@ -41,23 +41,21 @@ if (params.digestion){ //**************************************** // Combine all maps resolution for downstream analysis -if (params.bin_size instanceof Integer) { +/* 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() -} +} */ +ch_map_res = WorkflowHic.checkIfInt(params.bin_size) 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 && 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() +if (params.res_tads && !params.skip_tads){ + ch_tads_res = WorkflowHic.checkIfInt(params.res_tads) ch_map_res = ch_map_res.concat(ch_tads_res) }else{ ch_tads_res=Channel.empty() @@ -66,11 +64,8 @@ if (params.res_tads && !params.skip_tads && params.res_tads instanceof Integer){ } } -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() +if (params.res_dist_decay && !params.skip_dist_decay){ + ch_ddecay_res = WorkflowHic.checkIfInt(params.res_dist_decay) ch_map_res = ch_map_res.concat(ch_ddecay_res) }else{ ch_ddecay_res = Channel.empty() @@ -79,11 +74,8 @@ if (params.res_dist_decay && !params.skip_dist_decay && params.res_dist_decay in } } -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() +if (params.res_compartments && !params.skip_compartments){ + ch_comp_res = WorkflowHic.checkIfInt(params.res_compartments) ch_map_res = ch_map_res.concat(ch_comp_res) }else{ ch_comp_res = Channel.empty()