Skip to content

Commit

Permalink
Add validation of ome_tif_fields.json
Browse files Browse the repository at this point in the history
  • Loading branch information
jswelling committed Oct 11, 2024
1 parent 28f1116 commit e2ad513
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/ingest_validation_tests/ome_tiff_field_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import tifffile
import xmlschema
from jsonschema import validate
from ingest_validation_tools.plugin_validator import Validator


Expand Down Expand Up @@ -107,7 +108,15 @@ class OmeTiffFieldValidator(Validator):
def collect_errors(self, **kwargs) -> List[Optional[str]]:
cfg_path = Path(__file__).parent / "ome_tiff_fields.json"
cfg_list = json.loads(cfg_path.read_text())
# TODO: need a jsonschema test of cfg_list here
cfg_schema_path = Path(__file__).parent / "ome_tiff_fields_schema.json"
schema = json.loads(cfg_schema_path.read_text())
try:
pprint(cfg_list)
pprint(schema)
validate(cfg_list, schema)
except Exception as excp:
raise RuntimeError(f"Configuration error: {cfg_path}"
f" does not satisfy schema {cfg_schema_path}")
all_tests = {}
for test_set in cfg_list:
if re.fullmatch(test_set["re"], self.assay_type):
Expand Down
47 changes: 47 additions & 0 deletions src/ingest_validation_tests/ome_tiff_fields_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"$schema": "http://json-schema.org/schema#",
"$id": "http://schemata.hubmapconsortium.org/ome_tiff_fields_schema_schema.json",
"title": "ome-tiff fields schema",
"description": "schema for the definitions file of required ome-tiff fields",
"allOf":[{"$ref": "#/definitions/file_info"}],
"definitions": {
"file_info_record": {
"type": "object",
"properties": {
"re": {
"type": "string",
"description": "regular expression for assay types"
},
"fields": {
"type": "object",
"additionalProperties": {
"oneOf": [
{
"type": "object",
"properties": {
"dtype": {"enum": ["integer", "float"]}
},
"required": ["dtype"]
},
{
"type": "object",
"properties": {
"dtype": {"enum": ["categorical"]},
"allowed_values": {
"type": "array",
"items": {"type": "string"}
}
},
"required": ["dtype", "allowed_values"]
}
]
}
}
}
},
"file_info": {
"type": "array",
"items": {"$ref": "#/definitions/file_info_record"}
}
}
}

0 comments on commit e2ad513

Please sign in to comment.