Anybody got an easy way to error out a pipeline if...
# help
e
Anybody got an easy way to error out a pipeline if the samplesheet has fewer than N values? It's giving a run for my money... I've tried variations of this already, no dice. Gotten data type errors and errors that I believe are due to the asynchronous nature of the channels (also tried
.collect()
Copy code
// Error if sample count is insufficient after filtering
if( ch_samplesheet.size() < params.min_samples ) {
    error "ERROR: At least ${params.min_samples} samples are required." }
a
Very common mistake. You cannot compare channels to static values like that. Also channels do not have a
size
but rather a
count
. Probably best to try something like:
Copy code
ch_samplesheet.count().map{ ct -> ct < params.min_samples ? error("Too few samples. ${ct} < ${params.min_samples}") : "" }
But be aware that if you don’t block the use of
ch_samplesheet
downstream then processes can start before this full evaluates (they will then be killed/finish if this errors out). I can’t think of the best way to block in this instance right now, but I think there will be one.
party this 1
👍 1
n
If you are using nf-schema you can also add a check to the samplesheet schema: https://json-schema.org/understanding-json-schema/reference/array#length note that this does not show a nice error though so Arthur solution might be preffered
❤️ 1
e
Ended up going with the nf-schema option since it was the cleanest, also the error message is clear enough. Albeit, I can't parameterize the minimum samples in my case but I don't need to in this case so it works
🙌 1
n
Awesome to hear that!