Skip to content

Commit

Permalink
Update seqspec check so we can run it directly in python script (#58)
Browse files Browse the repository at this point in the history
* update seqspec check

* add spec parameter back to check function
  • Loading branch information
mingjiecn authored Jan 15, 2025
1 parent e3a6dea commit 8e9554f
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions seqspec/seqspec_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,14 @@ def setup_check_args(parser):
def validate_check_args(parser, args):
spec_fn = args.yaml
o = args.o
schema_fn = path.join(path.dirname(__file__), "schema/seqspec.schema.json")

return run_check(schema_fn, spec_fn, o)
return run_check(spec_fn, o)


def run_check(schema_fn, spec_fn, o):
def run_check(spec_fn, o):
spec = load_spec(spec_fn)

with open(schema_fn, "r") as stream:
schema = yaml.load(stream, Loader=yaml.Loader)
v = Draft4Validator(schema)

errors = check(v, spec, spec_fn)
errors = check(spec)

if errors:
if o:
Expand All @@ -56,14 +51,19 @@ def run_check(schema_fn, spec_fn, o):
return errors


def check(schema: Draft4Validator, spec: Assay, spec_fn: str):
def check(spec: Assay, spec_fn: str = None):
schema_fn = path.join(path.dirname(__file__), "schema/seqspec.schema.json")

with open(schema_fn, "r") as stream:
schema = yaml.load(stream, Loader=yaml.Loader)
validator = Draft4Validator(schema)
errors = []
idx = 0

# with open("del.json", "w") as f:
# json.dump(spec.to_dict(), f, indent=4)

for idx, error in enumerate(schema.iter_errors(spec.to_dict()), 1):
for idx, error in enumerate(validator.iter_errors(spec.to_dict()), 1):
errors.append(
f"[error {idx}] {error.message} in spec[{']['.join(repr(index) for index in error.path)}]"
)
Expand Down

0 comments on commit 8e9554f

Please sign in to comment.