nf-core / nf-core/tools

Schema: Conditional input file validation

Open
#2,453 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

schema
Dominant language
Python
Stars
322
Forks
255
Avg merge
2d 3h
Merged PRs (30d)
5

Description

Description of feature

Sometimes the validation schema for an input file might depend on a parameter.
An example would be a pipeline requesting VCFs and chromosome region when using params.step = "panel_prep" and BAM file with a fasta reference when params.step="map".

The aim would be to have a conditional validation of the columns present in the input file depending of a selected parameters or a specific column in the input file.

What could be done include:

  • Not defining the schema of the input file in the nextflow.schema and conditionnally check the input with a given schema in the pipeline https://github.com/nextflow-io/nf-validation/pull/94
    • Pros: Easy to do, direct link with params.step
    • Cons: No easy readability for user, needs to look into pipeline which shema used when
if (params.step == "panel_prep") {
    ch_input = Channel.fromSamplesheet("input", schema : "assets/schema_input_panel_prep.json")
} else if (params.step == "map") {
    ch_input = Channel.fromSamplesheet("input", schema : "assets/schema_input_map.json")
}
  • Add if else statement in the input schema json and everything in the same file
    • Pros: All in one place
    • Cons: Can become really huge if multiple step. No link to params.step
{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "https://raw.githubusercontent.com/nf-core/phaseimpute/master/assets/schema_input.json",
    "title": "nf-core/phaseimpute pipeline - params.input",
    "description": "Schema for the file provided with params.input",
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "step": {
                "type": "string",
                "pattern": "^(panel_prep|map)$"
            }
        },
        "allOf": [
            {
                "if": {
                    "properties": {
                        "step": { "const": "panel_prep" }
                    }
                },
                "then": {
                    "vcf": {
                        "type": "string",
                        "pattern": "^\\S+\\.vcf$"
                    },
                    "region": {
                        "type": "string",
                        "pattern": "^(chr)\\d+:\\d+-\\d+$"
                    }
                }
            },
            {
                "if": {
                    "properties": {
                        "step": { "const": "map" }
                    }
                },
                "then": {
                     "bam": {
                        "type": "string",
                        "pattern": "^\\S+\\.bam$"
                    },
                    "fasta": {
                        "type": "string",
                        "pattern": "^\\S+\\.fa$"
                    }
                }
            }
        ],
        "required": ["step"]
    }
}
  • Add if else statement in the input schema json but with schema link to other schema json file
    • Pros: All easily available and readable, smaller size.
    • Cons: May not be easy to implement. No link to params.step.
{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "https://raw.githubusercontent.com/nf-core/phaseimpute/master/assets/schema_input.json",
    "title": "nf-core/phaseimpute pipeline - params.input",
    "description": "Schema for the file provided with params.input",
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "step": {
                "type": "string",
                "pattern": "^(panel_prep|map)$"
            }
        },
        "allOf": [
            {
                "if": {
                    "properties": {
                        "step": { "const": "panel_prep" }
                    }
                },
                "then": {
                    "schema": "assets/schema_input_panel_prep.json"
                }
            },
            {
                "if": {
                    "properties": {
                        "step": { "const": "map" }
                    }
                },
                "then": {
                    "schema": "assets/schema_input_map.json"
                }
            }
        ],
        "required": ["step"]
    }
}
  • Finally and maybe best solution: add if-else statement in nextflow.schema with link to params.step and separate json.schema
    • Pros: Readability, small
    • Cons: Complicated to implement ?
{
    "$schema": "http://json-schema.org/draft-07/schema",
    "$id": "https://raw.githubusercontent.com/nf-core/phaseimpute/master/nextflow_schema.json",
    "title": "nf-core/phaseimpute pipeline parameters",
    "description": "MyDescription",
    "type": "object",
    "definitions": {
        "input_output_options": {
            "title": "Input/output options",
            "type": "object",
            "fa_icon": "fas fa-terminal",
            "description": "Define where the pipeline should find input data and save output data.",
            "required": ["step", "input"],
            "properties": {
                "step": {
                    "type": "string",
                    "description": "Step to run.",
                    "fa_icon": "fas fa-step-forward",
                    "enum": ["simulate", "panelprep", "impute", "validate"]
                },
                "input": {
                        "type": "string",
                        "fa_icon": "fas fa-file-csv",
                        "pattern": "^\\S+\\.(csv|tsv|yaml)$",
                        "format": "file-path",
                        "mimetype": "text/csv"
                }
            },
           "allOf": [
            {
                "if": {"definitions": { "input_output_options" { "step": { "const": "panel_prep" } } }
                }, "then": {
                     "input": {"schema": "assets/schema_input_panel_prep.json"}
                }
            },
            {
               "if": {"definitions": { "input_output_options" { "step": { "const": "map" } } }
                }, "then": {
                     "input": {"schema": "assets/schema_input_panel_map.json"}
                }
            }
        ]
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the existing nextflow.schema examples and the referenced nf-validation pull request 94. Compare the proposed conditional forms and determine which approach the project should support. Done means conditional input-file validation can follow a selected parameter or input column, with the chosen schema behavior covered by the relevant tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
json, python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.