Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/.bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[bumpversion]
current_version = 0.1.0
commit = False
tag = False
parse = (?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)(\-(?P<release>[a-z]+)(?P<dev>\d+))?
serialize =
{major}.{minor}.{patch}-{release}{dev}
{major}.{minor}.{patch}

[bumpversion:part:release]
optional_value = _
first_value = dev
values =
dev
_

[bumpversion:part:dev]

[bumpversion:file:pyproject.toml]
search = version = "{current_version}"
replace = version = "{new_version}"

[bumpversion:file:VERSION]

[bumpversion:file:README.md]

[bumpversion:file:plugin.json]

[bumpversion:file:src/polus/plugins/images/segmentation/ome_zarr_autosegmentation/__init__.py]
4 changes: 4 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv
out
tests
__pycache__
8 changes: 8 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
poetry.lock
uv.lock
test_datasets/**
**/models/**
autogenerated/**
cachedir/**
provenance/**
output_job.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
5 changes: 5 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG

## 0.1.0

Initial release.
35 changes: 35 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Build stage
FROM python:3.11-slim AS builder

RUN apt-get update && apt-get install -y \
gcc \
g++ \
python3-dev \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

WORKDIR /app

COPY pyproject.toml ./

RUN uv pip install --system -e .

COPY . .

# Final stage
FROM python:3.11-slim

WORKDIR /app

COPY --from=builder /app /app

COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages

WORKDIR /app/src

ENTRYPOINT ["python3", "-m", "polus.images.segmentation.ome_zarr_autosegmentation"]
CMD ["--help"]
23 changes: 23 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ome_zarr_autosegmentation (0.1.0)

description goes here

## Building

To build the Docker image for the conversion plugin, run `./build-docker.sh`.
Download the model you want to use for SAM from `https://github.com/facebookresearch/sam2?tab=readme-ov-file#download-checkpoints`

## Install WIPP Plugin

If WIPP is running, navigate to the plugins page and add a new plugin. Paste the
contents of `plugin.json` into the pop-up window and submit.

## Options

This plugin takes 1 input arguments and 1 output argument:

| Name | Description | I/O | Type | Default
|---------------|-------------------------|--------|--------|
| inpDir | Input dataset to be processed by this plugin | Input | collection
| preview | Generate an output preview | Input | boolean | False
| outDir | Output collection | Output | collection
1 change: 1 addition & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

version=$(<VERSION)
docker build . -t polusai/ome-zarr-autosegmentation-plugin:${version}
7 changes: 7 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/job.wic
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
steps:
ome-zarr-autosegmentation:
in:
inpDir: !ii input_directory
outDir: !ii output_directory
out:
- outDir: !& output_directory
63 changes: 63 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"name": "ome_zarr_autosegmentation",
"version": "0.1.0",
"title": "ome_zarr_autosegmentation",
"description": "description goes here",
"author": "Zhiyuan Liu (zhiyuan.liu@axleinfo.com)",
"institution": "National Center for Advancing Translational Sciences, National Institutes of Health",
"repository": "https://github.com/labshare/polus-plugins",
"website": "https://ncats.nih.gov/preclinical/core/informatics",
"citation": "",
"containerId": "polusai/ome-zarr-autosegmentation-plugin:0.1.0",
"baseCommand": ["python3", "-m", "polus.plugins.images.segmentation.ome_zarr_autosegmentation"],
"inputs": {
"inpDir": {
"type": "collection",
"title": "Input collection",
"description": "Input image collection to be processed by this plugin.",
"required": "True"
},
"filePattern": {
"type": "string",
"title": "Filename pattern",
"description": "Filename pattern used to separate data.",
"required": "False",
"default": ".*"
},
"preview": {
"type": "boolean",
"title": "Preview",
"description": "Generate an output preview.",
"required": "False",
"default": "False"
}
},
"outputs": {
"outDir": {
"type": "collection",
"description": "Output collection."
}
},
"ui": {
"inpDir": {
"type": "collection",
"title": "Input collection",
"description": "Input image collection to be processed by this plugin.",
"required": "True"
},
"filePattern": {
"type": "string",
"title": "Filename pattern",
"description": "Filename pattern used to separate data.",
"required": "False",
"default": "False"
},
"preview": {
"type": "boolean",
"title": "Filename pattern",
"description": "Generate an output preview.",
"required": "False",
"default": "False"
}
}
}
25 changes: 25 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[project]
name = "ome_zarr_autosegmentation_plugin"
version = "0.1.0"
description = "Add your description here"
readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"torch>=2.1.0",
"torchvision>=0.16.0",
"greenlet>=3.1.1",
"ome-zarr>=0.9.0",
"bfio>=2.3.6",
"sam2>=1.1.0",
"ngff-zarr[dask-image,tensorstore]>=0.12.2",
"argolid>=0.0.6",
"typer>=0.15.1",
]

[dependency-groups]
dev = [
"ruff>=0.8.0",
]

[tool.ruff.lint]
extend-select = ["I"]
17 changes: 17 additions & 0 deletions segmentation/ome-zarr-autosegmentation-plugin/run-plugin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

version=$(<VERSION)

# Update with your data
inpDir=/tmp/path/to/input
outDir=/tmp/path/to/output

container_input_dir="/inpDir"
container_output_dir="/outDir"

docker run -v $inpDir:/${container_input_dir} \
-v $outDir:/${container_output_dir} \
--user $(id -u):$(id -g) \
polusai/ome-zarr-autosegmentation-plugin:${version} \
--inpDir ${container_input_dir} \
--outDir ${container_output_dir}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""ome_zarr_autosegmentation."""

__version__ = "0.1.0"

from polus.images.segmentation import ( # noqa # pylint: disable=unused-import
ome_zarr_autosegmentation,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Package entrypoint for the ome_zarr_autosegmentation package."""

# Base packages
import json
import logging
from os import environ
from pathlib import Path

import typer
from polus.images.segmentation.ome_zarr_autosegmentation.autosegmentation import autosegmentation

logging.basicConfig(
format="%(asctime)s - %(name)-8s - %(levelname)-8s - %(message)s",
datefmt="%d-%b-%y %H:%M:%S",
)
POLUS_LOG = getattr(logging, environ.get("POLUS_LOG", "INFO"))
logger = logging.getLogger("polus.images.segmentation.ome_zarr_autosemgentation")
logger.setLevel(POLUS_LOG)

app = typer.Typer(help="ome_zarr_autosegmentation.")

def generate_preview(
in_dir: Path,
out_dir: Path,
) -> None:
"""Generate preview of the plugin outputs."""

preview = {}

with Path.open(out_dir / "preview.json", "w") as fw:
json.dump(preview, fw, indent=2)

@app.command()
def main(
inp_dir: Path = typer.Option(
...,
"--inpDir",
"-i",
help="Input directory to be processed.",
exists=True,
readable=True,
file_okay=False,
resolve_path=True,
),
out_dir: Path = typer.Option(
...,
"--outDir",
"-o",
help="Output directory.",
exists=False,
writable=True,
file_okay=False,
resolve_path=True,
),
preview: bool = typer.Option(
False,
"--preview",
"-v",
help="Preview of expected outputs (dry-run)",
show_default=False,
),
):
"""ome_zarr_autosegmentation."""
logger.info(f"inpDir: {inp_dir}")
logger.info(f"outDir: {out_dir}")

if preview:
generate_preview(inp_dir, out_dir)
logger.info(f"generating preview data in : {out_dir}.")
return

autosegmentation(inp_dir, out_dir)


if __name__ == "__main__":
app()
Loading
Loading