I'm writing a samplesheet schema for a nested data...
# nf-schema
j
I'm writing a samplesheet schema for a nested data structure. Each top-level array entry has five possible fields:
id
,
pacbio_hifi
,
oxford_nanopore
,
illumina_hic
and
illumina_10x
. How can I specify that
id
and at least /one/ of the other sections must be specified for an entry to be valid?
Copy code
{
    "$schema": "<https://json-schema.org/draft/2020-12/schema>",
    "$id": "<https://raw.githubusercontent.com/test/test/master/assets/schema_input.json>",
    "title": "Test schema for samplesheets",
    "description": "Schema for the file provided with params.data_input",
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "id": {
                "type": "string",
            },
            "pacbio_hifi": {
                "type": "object",
                "properties": {
                },
                "required": ["reads"]
            },
            "oxford_nanopore": {
                "type": "object",
                "properties": {
                },
                "required": ["reads"]
            },
            "illumina_hic": {
                "type": "object",
                "properties": {
                },
                "required": ["reads"]
            },
            "illumina_10x": {
                "type": "object",
                "properties": {
                },
                "required": ["reads"]
            }
        }
    }
}
n
You can add
"required": ["id"]
in the
items
scope for that
j
But that would mean that a section with /only/
id
would be valid - but I want to enforce specification of at least one other field
n
Then you can also add something like this:
Copy code
"anyOf": [
    {"required": ["pacbio_hifi"]},
    ...
]
Where
...
is a repeat of the required section above with another field 😛
This will check that at least one of those fields are given
j
Do I need to specify every possible combination of fields? Or do I just have to specify each possible required field once
n
Each field once should do the trick 😛
🙌 1
j
Thanks!
n
You're welcome, let me know if something is not working as expected
j
I will! I am succumbing to expectations and re-writing this samplesheet to operate as a list, rather than as an object. So I'm very excited to be able to use samplesheetToList() on it!
🎉 1
n
Glad to hear that 😉
j
Copy code
"anyOf": [
            {
                "dependentRequired": {
                    "maternal_illumina_dataset": ["paternal_illumina_dataset"]
                }
            },
            {
                "dependentRequired": {
                    "paternal_illumina_dataset": ["maternal_illumina_dataset"]
                }
            }
        ]
Is that the right way to specify a reciprocal optional dependency?
n
Copy code
"dependentRequired": {
                    "paternal_illumina_dataset": ["maternal_illumina_dataset"],
                    "maternal_illumina_dataset": ["paternal_illumina_dataset"]
                }
Is enough here, but it does exactly the same as your code
j
Ah, that's cleaner!
🎉 1
p
Also, better to not use nested parameters if you can
(Can't remember if it was you that was part of a fairly recent thread on this?)
They're fairly high risk for not being supported in nextflow soon
n
This is a case of nested samplesheets 😛
up arrows 1
j
Exactly, this is to specify a JSON/YAML input to the pipeline describing all the available data for each sample
p
Ah ok 👍🏻