Skip to content

Commit

Permalink
refactor scatter_plot
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Duane Walker authored and misterbrandonwalker committed Jul 29, 2024
1 parent 23fb84d commit 0e9dc01
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 104 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# docker build -f Dockerfile -t mrbrandonwalker/scatter_plot .
# docker build -f Dockerfile -t polusai/scatter-plot-tool .
FROM condaforge/mambaforge

ENV EXEC_DIR="/opt/executables"
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions utils/plotting/scatter_plot_tool/build-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

version=$(<VERSION)
docker build . -t polusai/scatter-plot-tool:${version}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
specVersion: "0.1.0"
name: scatter_plot
version: 0.1.0
container: scatter-plot-plugin
container: scatter-plot-tool
entrypoint:
title: scatter_plot
description: Generate a scatter plot
author: Data Scientist
contact: [email protected]
author: Brandon Walker, Nazanin Donyapour
contact: [email protected], [email protected]
repository:
documentation:
citation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ packages = [{include = "polus", from = "src"}]
[tool.poetry.dependencies]
python = ">=3.9,<3.12"
typer = "^0.7.0"
cwl-utils = "0.33"
cwltool = "3.1.20240404144621"
sophios = "0.1.1"
matplotlib = "3.8.4"

[tool.poetry.group.dev.dependencies]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,39 @@ baseCommand: ["python", "-m", "polus.mm.utils.scatter_plot"]

hints:
DockerRequirement:
dockerPull: mrbrandonwalker/scatter_plot
dockerPull: polusai/scatter-plot-tool@sha256:00a025a1bc943207d8c938af07deb763f6ae1a3a67e94316ea64302427f1de8f

inputs:

xs:
type:
type: array
items: float
inputBinding:
position: 2
prefix: --xs
inputBinding:
position: 2
prefix: --xs
doc: |-
X-axis array of data

ys:
type:
type: array
items: float
inputBinding:
position: 3
prefix: --ys
inputBinding:
position: 3
prefix: --ys
doc: |-
Y-axis array of data

ys2:
type:
type: array
items: float
inputBinding:
position: 4
prefix: --ys2
inputBinding:
position: 4
prefix: --ys2
doc: |-
Alternative Y-axis array of data

output_png_path:
label: Path to the output png file
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""parse arguments and call scatter_plot."""
import argparse
import logging
from os import environ

from polus.mm.utils.scatter_plot.scatter_plot import scatter_plot

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.mm.utils.scatter_plot.")
logger.setLevel(POLUS_LOG)


def main(xs: list, ys: list, ys2: list, output_png_path: str) -> None:
"""scatter_plot."""
logger.info(f"xs: {xs}")
logger.info(f"ys: {ys}")
logger.info(f"ys2: {ys2}")
logger.info(f"output_png_path: {output_png_path}")

scatter_plot(xs=xs, ys=ys, ys2=ys2, output_png_path=output_png_path)


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="scatter_plot")
parser.add_argument(
"--xs",
type=float,
nargs="+",
required=True,
help="List of x values",
)
parser.add_argument(
"--ys",
type=float,
nargs="+",
required=True,
help="List of y values",
)
parser.add_argument(
"--ys2",
type=float,
nargs="+",
help="Optional second list of y values",
)
parser.add_argument(
"--output_png_path",
type=str,
required=True,
help="Path to the output \
png file",
)

args = parser.parse_args()

main(xs=args.xs, ys=args.ys, ys2=args.ys2, output_png_path=args.output_png_path)
File renamed without changes.
37 changes: 37 additions & 0 deletions utils/plotting/scatter_plot_tool/tests/test_scatter_plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Tests for scatter_plot."""
from pathlib import Path

from polus.mm.utils.scatter_plot.scatter_plot import scatter_plot
from sophios.api.pythonapi import Step
from sophios.api.pythonapi import Workflow


def test_scatter_plot() -> None:
"""Test scatter_plot."""
scatter_plot([1, 2, 3], [1, 2, 3], [], "test.png")
assert Path("test.png").exists()


def test_duplicate() -> None:
"""Test scatter plot CWL."""
cwl_file_str = "scatter_plot_0@[email protected]"
cwl_file = Path(__file__).resolve().parent.parent / Path(cwl_file_str)

scatter_plot = Step(clt_path=cwl_file)
scatter_plot.xs = [1, 2, 3]
scatter_plot.ys = [1, 2, 3]
scatter_plot.ys2 = [1, 2, 3]
scatter_plot.output_png_path = "test.png"

steps = [scatter_plot]
filename = "scatter_plot"
viz = Workflow(steps, filename)

viz.run()

outdir = Path("outdir")
files = list(outdir.rglob("test.png"))

assert (
files
), f"The file 'test.png' does not exist in any subdirectory of '{outdir}'."

This file was deleted.

34 changes: 0 additions & 34 deletions utils/scatter_plot_plugin/tests/test_scatter_plot.py

This file was deleted.

0 comments on commit 0e9dc01

Please sign in to comment.