Commit 646885c5 authored by Bollen's avatar Bollen
Browse files

add more constraints to schema and add schema tests

parent 73f7434e
......@@ -6,98 +6,121 @@
"primer_min_gc": {
"description": "Minimum GC-percentage of primers",
"type": "number",
"default": 20
"default": 20,
"minimum" : 0,
"maximum": 100
},
"primer_internal_min_gc": {
"description": "Equivalent parameter of primer_min_gc for the internal oligo.",
"type": "number",
"default": 20
"default": 20,
"minimum" : 0,
"maximum": 100
},
"primer_opt_gc_percent": {
"description": "Optimum GC-percentage of primers",
"type": "number",
"default": 50
"default": 50,
"minimum": 0,
"maximum" : 100
},
"primer_max_gc": {
"description": "Maximum GC-percentage of primers.",
"type": "number",
"default": 80
"default": 80,
"minimum": 0,
"maximum": 100
},
"primer_internal_mac_gc": {
"primer_internal_max_gc": {
"description": "Equivalent parameter of primer_max_gc for the internal oligo.",
"type": "number",
"default": 80
"default": 80,
"minimum": 0,
"maximum": 100
},
"primer_wt_gc_percent_lt": {
"description": "Penalty weight for primers with GC-percentage lower than primer_opt_gc_percent",
"type": "number",
"default": 0
"default": 0,
"minimum": 0
},
"primer_internal_wt_gc_percent_lt": {
"description": "Equivalent parameter of primer_wt_gc_percent_lt for the interal oligo.",
"type": "number",
"default": 0
"default": 0,
"minimum": 0
},
"primer_wt_gc_percent_gt": {
"description": "Penality weight for primers with GC-percentage higher than primer_opt_gc_percent",
"type": "number",
"default": 0
"default": 0,
"minimum": 0
},
"primer_internal_wt_gc_percent_gt": {
"description": "Equivalent parameter of primer_wt_gc_percent_gt for the internal oligo.",
"type": "number",
"default": 0
"default": 0,
"minimum": 0
},
"primer_gc_clamp": {
"description": "Require the specified number of consecutive Gs and Cs at the 3' end of both the left and right primer.",
"type": "integer",
"default": 0
"default": 0,
"minimum": 0
},
"primer_max_end_gc": {
"description": "The maximum number of Gs or Cs allowed in the last five 3' bases of a left or right primer.",
"type": "integer",
"default": 5
"default": 5,
"minimum": 0
},
"primer_opt_size": {
"description": "Optimum size of primers in bases.",
"type": "integer",
"default": 25
"default": 25,
"minimum": 0
},
"primer_min_size": {
"description": "Minimum size of primers in bases.",
"type": "integer",
"default": 20
"default": 20,
"minimum": 0
},
"primer_max_size": {
"description": "Maximum size of primers in bases.",
"type": "integer",
"default": 30
"default": 30,
"minimum": 0
},
"primer_max_ns_accepted": {
"description": "Maximum number of unknown bases (N) accepted in a primer",
"type": "integer",
"default:": 0
"default:": 0,
"minimum": 0
},
"primer_product_size_range": {
"description": "Accepted size range of the product size.",
"type": "string",
"default": "200-450",
"pattern": "^\d+\-\d+$"
"pattern": "^\\d+\\-\\d+$"
},
"primer_product_opt_size": {
"description": "Optimum size of product. Will default to the midpoint in primer_product_size_range unless specified",
"type": "integer",
"default": 325
"default": 325,
"minimum": 0
},
"primer_pair_wt_product_size_gt": {
"description": "Penalty weight for products larger than primer_product_opt_size",
"type": "number",
"default": 0.1
"default": 0.1,
"minimum": 0
},
"primer_pair_wt_product_size_lt": {
"description": "Penalty weight for products smaller than primer_product_opt_size",
"type": "number",
"default": 0.1
"default": 0.1,
"minimum": 0
},
"primer_min_tm": {
"description": "Minimum melting temperature of primer degrees Celsius",
......@@ -112,7 +135,9 @@
"primer_num_return": {
"description": "Number of returned primers. Increase to increase search space",
"type": "integer",
"default": 200
"default": 200,
"minimum": 1
}
}
},
"additionalProperties": false
}
\ No newline at end of file
......@@ -3,4 +3,5 @@ biopython
lxml
pysam
pyfaidx
pyvcf
\ No newline at end of file
pyvcf
jsonschema>=2.6.0
\ No newline at end of file
{
"primer_min_gc": -30,
"primer_internal_min_gc": -30,
"primer_opt_gc_percent": -51,
"primer_max_gc": -81,
"primer_internal_max_gc": -81,
"primer_wt_gc_percent_lt": -0.12,
"primer_internal_wt_gc_percent_lt": -0.12,
"primer_wt_gc_percent_gt": -0.12,
"primer_internal_wt_gc_percent_gt": -0.12,
"primer_gc_clamp": -1,
"primer_max_end_gc": -0,
"primer_opt_size": -21,
"primer_min_size": -19,
"primer_max_size": -29,
"primer_max_ns_accepted": -1,
"primer_product_size_range": "300-500",
"primer_product_opt_size": -300,
"primer_pair_wt_product_size_gt": -0.12,
"primer_pair_wt_product_size_lt": -0.12,
"primer_min_tm": -55,
"primer_max_tm": -75,
"primer_num_return": -100
}
\ No newline at end of file
{
"primer_min_gc": 30,
"primer_internal_min_gc": 30,
"primer_opt_gc_percent": 51,
"primer_max_gc": 81,
"primer_internal_max_gc": 81,
"primer_wt_gc_percent_lt": 0.12,
"primer_internal_wt_gc_percent_lt": 0.12,
"primer_wt_gc_percent_gt": 0.12,
"primer_internal_wt_gc_percent_gt": 0.12,
"primer_gc_clamp": 1.0,
"primer_max_end_gc": 0,
"primer_opt_size": 21.54,
"primer_min_size": 19.12,
"primer_max_size": 29.8,
"primer_max_ns_accepted": 1,
"primer_product_size_range": "foobar",
"primer_product_opt_size": 300.50,
"primer_pair_wt_product_size_gt": 0.12,
"primer_pair_wt_product_size_lt": 0.12,
"primer_min_tm": 55,
"primer_max_tm": 75,
"primer_num_return": 100
}
\ No newline at end of file
{
"primer_min_gc": 30,
"primer_internal_min_gc": 30,
"primer_opt_gc_percent": 51,
"primer_max_gc": 81,
"primer_internal_max_gc": 81,
"primer_wt_gc_percent_lt": 0.12,
"primer_internal_wt_gc_percent_lt": 0.12,
"primer_wt_gc_percent_gt": 0.12,
"primer_internal_wt_gc_percent_gt": 0.12,
"primer_gc_clamp": 1,
"primer_max_end_gc": 0,
"primer_opt_size": 21,
"primer_min_size": 19,
"primer_max_size": 29,
"primer_max_ns_accepted": 1,
"primer_product_size_range": "300-500",
"primer_product_opt_size": 300,
"primer_pair_wt_product_size_gt": 0.12,
"primer_pair_wt_product_size_lt": 0.12,
"primer_min_tm": 55,
"primer_max_tm": 75,
"primer_num_return": 100
}
\ No newline at end of file
"""
test_schemas.py
~~~~~~~~~~~~~~~
:copyright: (c) 2018 Sander Bollen
:copyright: (c) 2018 Leiden University Medical Center
:license: MIT
"""
from pathlib import Path
import json
from jsonschema.validators import Draft4Validator
from pytest import fixture
import pytest
@fixture
def settings_schema():
return (Path(__file__).parent.parent / Path("prinia") / Path("static")
/ Path("primer3_settings_schema.json"))
data_dir = Path(__file__).parent / Path("data")
setting_jsons_data = [
(data_dir / Path("valid_settings.json"), True),
(data_dir / Path("settings_wrong_types.json"), False),
(data_dir / Path("settings_invalid_values.json"), False)
]
def test_settings_schema_is_loadable_json(settings_schema):
with settings_schema.open("r") as handle:
json.load(handle)
def test_settings_schema_is_valid_schema(settings_schema):
with settings_schema.open("r") as handle:
s = json.load(handle)
Draft4Validator.check_schema(s)
@pytest.mark.parametrize("settings_json, should_be_valid", setting_jsons_data)
def test_settings_json_valid(settings_schema, settings_json, should_be_valid):
with settings_schema.open("r") as shandle:
schema = json.load(shandle)
schema_instance = Draft4Validator(schema)
with settings_json.open("r") as jhandle:
j = json.load(jhandle)
assert schema_instance.is_valid(j) == should_be_valid
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment