Skip to content

Commit

Permalink
check-linear-fit (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Duane Walker <[email protected]>
  • Loading branch information
misterbrandonwalker and Brandon Duane Walker authored May 29, 2024
1 parent 07a9b3a commit d436818
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 0 deletions.
29 changes: 29 additions & 0 deletions utils/fitting/check-linear-fit-tool/.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/mm/utils/check_linear_fit/__init__.py]
4 changes: 4 additions & 0 deletions utils/fitting/check-linear-fit-tool/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.venv
out
tests
__pycache__
1 change: 1 addition & 0 deletions utils/fitting/check-linear-fit-tool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
poetry.lock
5 changes: 5 additions & 0 deletions utils/fitting/check-linear-fit-tool/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# CHANGELOG

## 0.1.0

Initial release.
22 changes: 22 additions & 0 deletions utils/fitting/check-linear-fit-tool/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# docker build -f Dockerfile -t mrbrandonwalker/check_linear_fit .
FROM condaforge/mambaforge

ENV EXEC_DIR="/opt/executables"
ENV POLUS_LOG="INFO"
RUN mkdir -p ${EXEC_DIR}

# Work directory defined in the base container
# WORKDIR ${EXEC_DIR}

COPY pyproject.toml ${EXEC_DIR}
COPY VERSION ${EXEC_DIR}
COPY README.md ${EXEC_DIR}
COPY CHANGELOG.md ${EXEC_DIR}

# Install needed packages here

COPY src ${EXEC_DIR}/src

RUN pip3 install ${EXEC_DIR} --no-cache-dir

CMD ["--help"]
17 changes: 17 additions & 0 deletions utils/fitting/check-linear-fit-tool/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# check_linear_fit (0.1.0)

check_linear_fit

## Options

This plugin takes 6 input arguments and 1 output argument:

| Name | Description | I/O | Type | Default |
|---------------|-------------------------|--------|--------|---------|
| script | | Input | string | string |
| xs | | Input | {'type': 'array', 'items': 'float'} | {'type': 'array', 'items': 'float'} |
| ys | | Input | {'type': 'array', 'items': 'float'} | {'type': 'array', 'items': 'float'} |
| tol_quad | | Input | float | float |
| slope_min | | Input | float | float |
| slope_max | | Input | float | float |
| success | | Output | boolean | boolean |
1 change: 1 addition & 0 deletions utils/fitting/check-linear-fit-tool/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.0
59 changes: 59 additions & 0 deletions utils/fitting/check-linear-fit-tool/check_linear_fit.cwl
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env cwl-runner
cwlVersion: v1.0

class: CommandLineTool

label: check_linear_fit

doc: |-
check_linear_fit

baseCommand: ["python", "-m", "polus.mm.utils.check_linear_fit"]

requirements:
DockerRequirement:
dockerPull: mrbrandonwalker/check_linear_fit
InlineJavascriptRequirement: {}

inputs:

xs:
type:
type: array
items: float
inputBinding:
prefix: --xs

ys:
type:
type: array
items: float
inputBinding:
prefix: --ys

tol_quad:
type: float
inputBinding:
prefix: --tol_quad

slope_min:
type: float
inputBinding:
prefix: --slope_min

slope_max:
type: float
inputBinding:
prefix: --slope_max

outputs:
success:
type: boolean
outputBinding:
outputEval: $(true) # If check_linear_fit.py didn't call sys.exit(1), then it called sys.exit(0)

$namespaces:
edam: https://edamontology.org/

$schemas:
- https://raw.githubusercontent.com/edamontology/edamontology/master/EDAM_dev.owl
69 changes: 69 additions & 0 deletions utils/fitting/check-linear-fit-tool/ict.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
specVersion: "0.1.0"
name: check_linear_fit
version: 0.1.0
container: check-linear-fit-tool
entrypoint:
title: check_linear_fit
description: check_linear_fit
author: Data Scientist
contact: [email protected]
repository:
documentation:
citation:

inputs:
- name: script
required: true
description:
type: string
defaultValue: /check_linear_fit.py
- name: xs
required: true
description:
type: {'type': 'array', 'items': 'float'}
- name: ys
required: true
description:
type: {'type': 'array', 'items': 'float'}
- name: tol_quad
required: true
description:
type: float
- name: slope_min
required: true
description:
type: float
- name: slope_max
required: true
description:
type: float
outputs:
- name: success
required: true
description:
type: boolean
ui:
- key: inputs.script
title: "script: "
description: ""
type: string
- key: inputs.xs
title: "xs: "
description: ""
type: {'type': 'array', 'items': 'float'}
- key: inputs.ys
title: "ys: "
description: ""
type: {'type': 'array', 'items': 'float'}
- key: inputs.tol_quad
title: "tol_quad: "
description: ""
type: float
- key: inputs.slope_min
title: "slope_min: "
description: ""
type: float
- key: inputs.slope_max
title: "slope_max: "
description: ""
type: float
33 changes: 33 additions & 0 deletions utils/fitting/check-linear-fit-tool/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
[tool.poetry]
name = "polus-mm-utils-check-linear-fit"
version = "0.1.0"
description = "check_linear_fit"
authors = ["Data Scientist <[email protected]>"]
readme = "README.md"
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"
numpy = "1.26.4"
scipy = "1.13.0"

[tool.poetry.group.dev.dependencies]
bump2version = "^1.0.1"
pytest = "^7.4"
pytest-sugar = "^0.9.6"
pre-commit = "^3.2.1"
black = "^23.3.0"
mypy = "^1.1.1"
ruff = "^0.0.270"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.pytest.ini_options]
pythonpath = [
"."
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""check_linear_fit."""

__version__ = "0.1.0"

from polus.mm.utils.check_linear_fit.check_linear_fit import ( # noqa # pylint: disable=unused-import
check_linear_fit,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Package entrypoint for the check_linear_fit package."""

# Base packages
import logging
import sys
from os import environ

import typer
from polus.mm.utils.check_linear_fit.check_linear_fit import check_linear_fit

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.check_linear_fit.")
logger.setLevel(POLUS_LOG)

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


@app.command()
def main(
xs: list[float] = typer.Option(
...,
"--xs",
help="",
),
ys: list[float] = typer.Option(
...,
"--ys",
help="",
),
tol_quad: float = typer.Option(
...,
"--tol_quad",
help="",
),
slope_min: float = typer.Option(
...,
"--slope_min",
help="",
),
slope_max: float = typer.Option(
...,
"--slope_max",
help="",
),
) -> None:
"""check_linear_fit."""
logger.info(f"xs: {xs}")
logger.info(f"ys: {ys}")
logger.info(f"tol_quad: {tol_quad}")
logger.info(f"slope_min: {slope_min}")
logger.info(f"slope_max: {slope_max}")

is_linear_and_within_bounds = check_linear_fit(
xs=xs,
ys=ys,
tol_quad=tol_quad,
slope_min=slope_min,
slope_max=slope_max,
)
if is_linear_and_within_bounds:
sys.exit(0)
else:
sys.exit(1)


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

0 comments on commit d436818

Please sign in to comment.