-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from nf-core/samplesheet-validator
Samplesheet Validator
- Loading branch information
Showing
34 changed files
with
440 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from samshee.samplesheetv2 import read_samplesheetv2 | ||
from samshee.validation import illuminasamplesheetv2schema, illuminasamplesheetv2logic, validate | ||
import json | ||
import sys | ||
|
||
def validate_samplesheet(filename, custom_schema_file=None): | ||
# Load the custom schema if provided | ||
if custom_schema_file: | ||
with open(custom_schema_file, 'r') as f: | ||
custom_schema = json.load(f) | ||
custom_validator = lambda doc: validate(doc, custom_schema) | ||
else: | ||
custom_validator = None | ||
|
||
# Prepare the list of validators | ||
validators = [illuminasamplesheetv2schema, illuminasamplesheetv2logic] | ||
if custom_validator: | ||
validators.append(custom_validator) | ||
# Read and validate the sample sheet | ||
try: | ||
sheet = read_samplesheetv2(filename, validation=validators) | ||
print(f"Validation successful for {filename}") | ||
except Exception as e: | ||
print(f"Validation failed: {e}") | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) < 2 or len(sys.argv) > 3: | ||
print("Usage: validate_samplesheet.py <SampleSheet.csv> [custom_schema.json]") | ||
sys.exit(1) | ||
samplesheet_file = sys.argv[1] | ||
schema_file = sys.argv[2] if len(sys.argv) == 3 else None | ||
|
||
validate_samplesheet(samplesheet_file, schema_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Guide to Writing a `validation.json` Schema File | ||
|
||
## Introduction | ||
|
||
A JSON schema defines the structure and constraints of JSON data. This guide will help you create a `validation.json` schema file for use with Samshee to perform additional checks on Illumina® Sample Sheet v2 files. | ||
|
||
## JSON Schema Basics | ||
|
||
JSON Schema is a powerful tool for validating the structure of JSON data. It allows you to specify required fields, data types, and constraints. Here are some common components: | ||
|
||
- **`$schema`**: Declares the JSON Schema version being used. | ||
- **`type`**: Specifies the data type (e.g., `object`, `array`, `string`, `number`). | ||
- **`properties`**: Defines the properties of an object and their constraints. | ||
- **`required`**: Lists properties that must be present in the object. | ||
- **`items`**: Specifies the schema for items in an array. | ||
|
||
## Example Schema | ||
|
||
Here’s an example of a `validation.json` schema file for an Illumina® Sample Sheet: | ||
|
||
```json | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"Header": { | ||
"type": "object", | ||
"properties": { | ||
"InvestigatorName": { | ||
"type": "string" | ||
}, | ||
"ExperimentName": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["InvestigatorName", "ExperimentName"] | ||
}, | ||
"Reads": { | ||
"type": "object", | ||
"properties": { | ||
"Read1": { | ||
"type": "integer", | ||
"minimum": 1 | ||
}, | ||
"Read2": { | ||
"type": "integer", | ||
"minimum": 1 | ||
} | ||
}, | ||
"required": ["Read1", "Read2"] | ||
}, | ||
"BCLConvert": { | ||
"type": "object", | ||
"properties": { | ||
"Index": { | ||
"type": "string", | ||
"pattern": "^[ACGT]{8}$" // Example pattern for 8-base indices | ||
} | ||
} | ||
} | ||
}, | ||
"required": ["Header", "Reads"] | ||
} | ||
``` | ||
|
||
### Explanation of the Example | ||
|
||
- **`$schema`**: Specifies the JSON Schema version (draft-07). | ||
- **`type`**: Defines the main type as `object`. | ||
- **`properties`**: Lists the properties of the object: | ||
- **`Header`**: An object with required `InvestigatorName` and `ExperimentName` fields. | ||
- **`Reads`**: An object with required `Read1` and `Read2` fields that must be integers greater than or equal to 1. | ||
- **`BCLConvert`**: An object with an optional `Index` field that must be a string matching a pattern for 8-base indices. | ||
- **`required`**: Lists required properties at the top level. | ||
|
||
### Tips for Writing JSON Schemas | ||
|
||
1. **Start Simple**: Begin with basic constraints and gradually add complexity. | ||
2. **Use Online Validators**: Validate your schema using online tools to ensure it adheres to the JSON Schema specification. | ||
3. **Refer to Schema Documentation**: Consult the [JSON Schema documentation](https://json-schema.org/) for detailed guidance. | ||
|
||
### Conclusion | ||
|
||
By defining a JSON schema, you can enforce specific rules and ensure that your Illumina® Sample Sheet v2 files meet your required structure and constraints. Use this guide to create and validate your `validation.json` schema files effectively. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
channels: | ||
- conda-forge | ||
- bioconda | ||
dependencies: | ||
- python>=3.9 | ||
- pip | ||
- pip: # FIXME https://github.com/nf-core/modules/issues/5814 | ||
- samshee==0.1.12 |
Oops, something went wrong.