Skip to main content

Convert MIHCSME metadata from Excel to Pydantic model and upload to OMERO

Project description

MIHCSME-py

Convert MIHCSME (Minimum Information about a High Content Screening Microscopy Experiment) metadata from Excel spreadsheets to validated Pydantic models and upload to OMERO.

Python 3.9+ CI/CD Documentation PyPI version Python versions License

Features

  • Parse MIHCSME Excel templates into type-safe Pydantic models
  • Automatic validation with clear error messages
  • Bidirectional conversion between Excel, Pydantic, and OMERO key-pair value format
  • Modern CLI with rich terminal output
  • OMERO.script for server-side handling of MIHCSME templates

Installation

Development Installation

# Clone the repository
git clone https://github.com/Leiden-Cell-Observatory/MIHCSME_OMERO.git
cd MIHCSME_OMERO

# Create virtual environment with uv
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Install in editable mode with dev dependencies
uv pip install -e ".[dev]"

User Installation (After PyPI Release)

uv pip install mihcsme-py

Quick Start

Command Line

# Validate MIHCSME Excel file
mihcsme validate LEI-MIHCSME.xlsx

# Parse Excel to JSON
mihcsme parse LEI-MIHCSME.xlsx --output metadata.json

# Upload to OMERO Screen
mihcsme upload LEI-MIHCSME.xlsx \
    --screen-id 123 \
    --host omero.example.com \
    --user myuser

# Upload with replace (removes existing annotations)
mihcsme upload LEI-MIHCSME.xlsx \
    --plate-id 456 \
    --host omero.example.com \
    --user myuser \
    --replace

Python API

from pathlib import Path
from mihcsme_omero import connect, parse_excel_to_model, upload_metadata_to_omero

# Parse Excel file to Pydantic model
excel_path = Path("LEI-MIHCSME.xlsx")
metadata = parse_excel_to_model(excel_path)

# Inspect the model
print(f"Wells: {len(metadata.assay_conditions)}")
for condition in metadata.assay_conditions:
    print(f"{condition.plate} / {condition.well}: {condition.conditions}")

# Connect to OMERO
conn = connect(
    host="omero.example.com",
    user="myuser",
    password="mypassword",
    port=4064,
    secure=True,
)

# Upload to OMERO
result = upload_metadata_to_omero(
    conn=conn,
    metadata=metadata,
    target_type="Screen",
    target_id=123,
    namespace="MIHCSME",
    replace=False,
)

print(f"Status: {result['status']}")
print(f"Wells succeeded: {result['wells_succeeded']}")

conn.close()

Excel File Structure

The MIHCSME Excel file should contain these sheets:

  • InvestigationInformation - Investigation-level metadata (grouped key-value pairs)
  • StudyInformation - Study-level metadata (grouped key-value pairs)
  • AssayInformation - Assay-level metadata (grouped key-value pairs)
  • AssayConditions - Per-well metadata (tabular: Plate, Well, conditions...)
  • _Reference sheets - Reference data (sheets starting with _)

See LEI-MIHCSME.xlsx for an example.

Data Model

The package uses Pydantic models for type-safe metadata handling:

from mihcsme_omero.models import MIHCSMEMetadata, AssayCondition

# Create metadata programmatically
metadata = MIHCSMEMetadata(
    assay_conditions=[
        AssayCondition(
            plate="Plate1",
            well="A1",  # Automatically normalized to "A01"
            conditions={"Compound": "DMSO", "Concentration": "0.1%"},
        )
    ]
)

# Convert to OMERO dict format
omero_dict = metadata.to_omero_dict()

# Create from OMERO dict format
metadata = MIHCSMEMetadata.from_omero_dict(omero_dict)

Development

Running Tests

# Run all tests
pytest

# Run with coverage
pytest --cov=mihcsme_omero --cov-report=html

# Run type checking
mypy src/mihcsme_omero

# Format code
black src/ tests/

# Lint code
ruff check src/ tests/ --fix

Project Structure

mihcsme-omero/
├── src/mihcsme_omero/          # Source code (src layout)
│   ├── __init__.py              # Package exports
│   ├── models.py                # Pydantic models
│   ├── parser.py                # Excel → Pydantic
│   ├── omero_connection.py      # OMERO connection utilities
│   ├── uploader.py              # Pydantic → OMERO
│   └── cli.py                   # Typer CLI
├── tests/                       # Test suite
├── original_scripts/            # Legacy scripts (reference only)
├── pyproject.toml               # Package configuration
└── README.md                    # This file

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/my-feature)
  3. Make changes with tests
  4. Run quality checks (black, ruff, mypy, pytest)
  5. Commit with clear message
  6. Push and create pull request

License

See LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mihcsme_py-0.1.1.tar.gz (31.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mihcsme_py-0.1.1-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file mihcsme_py-0.1.1.tar.gz.

File metadata

  • Download URL: mihcsme_py-0.1.1.tar.gz
  • Upload date:
  • Size: 31.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mihcsme_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b49f899e0c781dc694a118f6335746edbb076200efbd964c5c4ad7c40bb52136
MD5 413d9f68456545489c1b32da63831221
BLAKE2b-256 74d0a503585843e5ec1c24906fd57a33764191a6fa144ab204ef6eb417b0d72c

See more details on using hashes here.

File details

Details for the file mihcsme_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mihcsme_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for mihcsme_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b34f571fa87e2a2e818537cdb86cfdf70a372079e72c93623f2816f37c0b2a39
MD5 d0624824944da5bff88bf87a7d25ef73
BLAKE2b-256 01c3e5950f7d8f2d4b600db20633fe25b587846a96425367317845790ab4c656

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page