Hi, I would like to clarify something regarding nf...
# nf-schema
n
Hi, I would like to clarify something regarding nf-schema defaults. I am allowing parameters via samplesheet, or params. The idea is that samplesheet should take priority, but if the param is not set per-sample there should be a fallback to the param. Here is what I am doing
Copy code
channel.fromList(samplesheetToList(params.input, "assets/schema_input.json"))
        /*
        This is a somewhat crucial step, where the samplesheet and params are used to determine per-sample parameters.
        This has been greatly simplified thanks to @nvnieuwk
        */
        .map { it ->
            def meta = it[0]
            // Populate everything that has no value with the value from params
            return meta.collectEntries { key, val -> key == "group" ? [ key, val ] : [ key, val ?: params.get(key) ] }
        }
1. However, I also set
defaults
in
schema_inputs
. As I understand, this probably breaks what I want to do, and I should rather remove the defaults from the schema, to ensure that this actually falls back to params? To do this: should I remove defaults? Will I still receive an entry if there is no default and it was not in the samplesheet? Should I set defaults to
null
? 2. Something about this that has been bothering me for a while is: I assume that if a user were to set a
param.something = true
and in the samplesheet would provide
something
as
false
, this would actually override the per-sample value false with the param value true, because
val ?: params.get(key)
would get it from params, since the condition is false. Is there some established pattern to handle this?
I guess maybe the best way to do this would be default everything in
schema_input
to a dummy value, e.g.
"default_dummy"
and perform checks based on that?
Copy code
return meta.collectEntries { key, val -> key == "group" ? [ key, val ] : [ key, val == "default_dummy" ? params.get(key) : val ]
Maybe I should have read the announcement on v3.. I think the ParamSubsitution would essentially solve my problem, if I can use
default: "${param.paramname}"
? Is that correct @Nicolas Vannieuwkerke?
n
This system only works for values specified in the samplesheet. It doesn't work for schema defaults (although it is something that I could implement if needed, feel free to open an issue if you want this.) I'd suggest removing the defaults from the schema if you specify the defaults in your pipeline code. This will automatically set all values to
[]
if they are missing, you could also set the default to
null
if you'd prefer that for your logic
n
Thanks a lot. I will remove the defaults. Just to clarify: even if there is no default, the respective k/v pair will come out of
samplesheetToList(params.input, "assets/schema_input.json")
with a value of
[]
, if it is listed in the schema, but not part of the actual samplesheet?
n
Yes! The structure of each samplesheet entry will be the same 🙂
🙌 1
Based on the JSON schema