Eido: Project Metadata Validator

0.2.5 · active · verified Thu Apr 16

Eido (pronounced 'eye-doe') is a Python library and CLI tool designed for validating project metadata, primarily within the Portable Encapsulated Project (PEP) framework. It leverages JSON Schema to ensure the correctness and consistency of project configuration files and sample annotations. The current version is 0.2.5, and releases are relatively infrequent, often tied to updates in the broader PEPKit ecosystem.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use eido to validate a peppy Project object against a JSON schema. It involves creating temporary config and schema files, loading them with `peppy`, and then invoking `eido.validate_project` for both a valid and an intentionally invalid project.

import os
import peppy
import eido
import yaml
from jsonschema import ValidationError

# Create a dummy project config file
config_content = """
project_name: MyTestProject
output_dir: output/
samples:
  - sample_name: sample1
    file_path: data/sample1.txt
    organism: human
  - sample_name: sample2
    file_path: data/sample2.txt
    organism: mouse
"""

# Create a dummy schema file
schema_content = """
type: object
properties:
  project_name: { type: string }
  output_dir: { type: string }
  samples:
    type: array
    items:
      type: object
      properties:
        sample_name: { type: string }
        file_path: { type: string }
        organism: { type: string, enum: [human, mouse, rat] }
      required: [sample_name, file_path, organism]
required: [project_name, samples]
"""

config_file = "_eido_test_config.yaml"
schema_file = "_eido_test_schema.yaml"

try:
    # Write dummy files
    with open(config_file, 'w') as f:
        f.write(config_content)
    with open(schema_file, 'w') as f:
        f.write(schema_content)

    # Load the project using peppy
    project = peppy.Project(config_file)

    # Validate the project using eido
    print(f"Attempting to validate project '{project.name}'...")
    eido.validate_project(project, schema_file)
    print("Project validated successfully!")

    # Example of validation failure (optional, for demonstration)
    print("\n--- Demonstrating a validation failure ---")
    bad_config_content = """
project_name: AnotherProject
samples:
  - sample_name: invalid_sample
    organism: alien # 'alien' is not in enum
"""
    bad_config_file = "_eido_bad_config.yaml"
    with open(bad_config_file, 'w') as f:
        f.write(bad_config_content)
    bad_project = peppy.Project(bad_config_file)
    try:
        print("Attempting to validate a project with invalid organism...")
        eido.validate_project(bad_project, schema_file)
        print("Unexpected: Validation passed for bad project!")
    except ValidationError as e:
        print(f"Caught expected validation error: {e.message}")

finally:
    # Clean up dummy files
    if os.path.exists(config_file):
        os.remove(config_file)
    if os.path.exists(schema_file):
        os.remove(schema_file)
    if os.path.exists(bad_config_file):
        os.remove(bad_config_file)

view raw JSON →