-
Notifications
You must be signed in to change notification settings - Fork 40
updated czi-extract-plugin #491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hamshkhawar
wants to merge
3
commits into
PolusAI:master
Choose a base branch
from
hamshkhawar:update_czi
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| .venv | ||
| out | ||
| tests | ||
| __pycache__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Jupyter Notebook | ||
| .ipynb_checkpoints | ||
| poetry.lock | ||
| ../../poetry.lock | ||
| # Environments | ||
| .env | ||
| .myenv | ||
| .venv | ||
| env/ | ||
| venv/ | ||
| # test data directory | ||
| data | ||
| # yaml file | ||
| .pre-commit-config.yaml | ||
| # hidden files | ||
| .DS_Store | ||
| .ds_store | ||
| # flake8 | ||
| .flake8 | ||
| ../../.flake8 | ||
| __pycache__ | ||
| .mypy_cache | ||
| requirements.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| ## [1.1.2-dev] - 2024-01-10 | ||
| ### Added | ||
| - Pytests to test this plugin | ||
| - This plugin is now installable with pip. | ||
|
|
||
| ### Changed | ||
| - Updated dependencies (bfio, filepattern, preadator) to latest | ||
| - Argparse package is replaced with Typer package for command line arguments | ||
| - Replaced docker base image with latest container image with pre-installed bfio | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| FROM polusai/bfio:2.3.3 | ||
|
|
||
| # environment variables defined in polusai/bfio | ||
| ENV EXEC_DIR="/opt/executables" | ||
| ENV POLUS_IMG_EXT=".ome.tif" | ||
| ENV POLUS_TAB_EXT=".csv" | ||
|
|
||
| # 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 src ${EXEC_DIR}/src | ||
|
|
||
| RUN pip3 install ${EXEC_DIR} --no-cache-dir | ||
|
|
||
| ENTRYPOINT ["python3", "-m", "polus.plugins.formats.czi_extract"] | ||
| CMD ["--help"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 1.1.2-dev |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| #!/bin/bash | ||
|
|
||
| version=$(<VERSION) | ||
| docker build . -t polusai/czi-extract-plugin:${version} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| [bumpversion] | ||
| current_version = 1.1.2-dev | ||
| commit = True | ||
| 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:plugin.json] | ||
|
|
||
| [bumpversion:file:VERSION] | ||
|
|
||
| [bumpversion:file:src/polus/plugins/formats/czi_extract/__init__.py] |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| { | ||
| "name": "Czi Extraction", | ||
| "version": "1.1.2-dev", | ||
| "title": "Extract TIFFs From CZI", | ||
| "description": "Extracts individual fields of view from a CZI file. Saves as OME TIFF.", | ||
| "author": "Nick Schaub (nick.schaub@nih.gov), Hamdah Shafqat Abbasi (hamdahshafqat.abbasi@nih.gov)", | ||
| "institution": "National Center for Advancing Translational Sciences, National Institutes of Health", | ||
| "repository": "https://github.com/PolusAI/polus-plugins", | ||
| "website": "https://ncats.nih.gov/preclinical/core/informatics", | ||
| "containerId": "polusai/czi-extract-plugin:1.1.2-dev", | ||
| "baseCommand": [ | ||
| "python3", | ||
| "-m", | ||
| "polus.plugins.formats.czi_extract" | ||
| ], | ||
| "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" | ||
| }, | ||
| "preview": { | ||
| "type": "boolean", | ||
| "title": "Preview", | ||
| "description": "Generate an output preview.", | ||
| "required": "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": ".*.czi" | ||
| }, | ||
| "preview": { | ||
| "type": "boolean", | ||
| "title": "Preview example output of this plugin", | ||
| "description": "Generate an output preview.", | ||
| "required": "False" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| [tool.poetry] | ||
| name = "polus-plugins-formats-czi-extract" | ||
| version = "1.1.2-dev" | ||
| description = "Extracts individual fields of view from a CZI file. Saves as OME TIFF." | ||
| authors = [ | ||
| "Nick Schaub <nick.schaub@nih.gov>", | ||
| "Hamdah Shafqat abbasi <hamdahshafqat.abbasi@nih.gov>" | ||
| ] | ||
| readme = "README.md" | ||
| packages = [{include = "polus", from = "src"}] | ||
|
|
||
| [tool.poetry.dependencies] | ||
| python = ">=3.9,<3.12" | ||
| filepattern = "^2.0.4" | ||
| typer = "^0.7.0" | ||
| tqdm = "^4.64.1" | ||
| bfio = {version = "2.3.3", extras = ["all"]} | ||
| preadator="0.4.0.dev2" | ||
| czifile="^2019.7.2" | ||
|
|
||
| [tool.poetry.group.dev.dependencies] | ||
| bump2version = "^1.0.1" | ||
| pre-commit = "^3.0.4" | ||
| black = "^23.1.0" | ||
| flake8 = "^6.0.0" | ||
| mypy = "^1.0.0" | ||
| pytest = "^7.2.1" | ||
| ipykernel = "^6.21.2" | ||
| requests = "^2.28.2" | ||
| scikit-image = "^0.22.0" | ||
|
|
||
| [build-system] | ||
| requires = ["poetry-core"] | ||
| build-backend = "poetry.core.masonry.api" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
formats/czi-extract-plugin/src/polus/plugins/formats/czi_extract/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| """Czi Extract Plugin.""" | ||
| __version__ = "1.1.2-dev" |
91 changes: 91 additions & 0 deletions
91
formats/czi-extract-plugin/src/polus/plugins/formats/czi_extract/__main__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| """Czi Extract Plugin.""" | ||
| import json | ||
| import logging | ||
| import os | ||
| from multiprocessing import cpu_count | ||
| from pathlib import Path | ||
| from typing import Any | ||
| from typing import Optional | ||
|
|
||
| import filepattern as fp | ||
| import polus.plugins.formats.czi_extract.czi as cz | ||
| import typer | ||
|
|
||
| # Import environment variables | ||
| POLUS_EXT = os.environ.get("POLUS_EXT", ".ome.tif") | ||
|
|
||
| app = typer.Typer() | ||
|
|
||
| # Initialize the logger | ||
| logging.basicConfig( | ||
| format="%(asctime)s - %(name)-8s - %(levelname)-8s - %(message)s", | ||
| datefmt="%d-%b-%y %H:%M:%S", | ||
| ) | ||
| logger = logging.getLogger("polus.plugins.formats.czi_extract") | ||
|
|
||
|
|
||
| @app.command() | ||
| def main( | ||
| inp_dir: Path = typer.Option( | ||
| ..., | ||
| "--inpDir", | ||
| "-i", | ||
| help="Path to folder with CZI files", | ||
| ), | ||
| file_pattern: str = typer.Option( | ||
| ".*.czi", | ||
| "--filePattern", | ||
| "-f", | ||
| help="Pattern use to parse filenames", | ||
| ), | ||
| out_dir: Path = typer.Option( | ||
| ..., | ||
| "--outDir", | ||
| "-o", | ||
| help="Output directory", | ||
| ), | ||
| preview: Optional[bool] = typer.Option( | ||
| False, | ||
| "--preview", | ||
| help="Output a JSON preview of files", | ||
| ), | ||
| ) -> None: | ||
| """Extracts individual fields of view from a CZI file and saves as OME TIFF.""" | ||
| logger.info(f"--inpDir = {inp_dir}") | ||
| logger.info(f"--filePattern = {file_pattern}") | ||
| logger.info(f"--outDir = {out_dir}") | ||
|
|
||
| inp_dir = inp_dir.resolve() | ||
| out_dir = out_dir.resolve() | ||
|
|
||
| assert inp_dir.exists(), f"{inp_dir} does not exist!! Please check input path again" | ||
| assert ( | ||
| out_dir.exists() | ||
| ), f"{out_dir} does not exist!! Please check output path again" | ||
|
|
||
| files = fp.FilePattern(inp_dir, file_pattern) | ||
|
|
||
| file_ext = all(Path(f[1][0].name).suffix for f in files()) | ||
| assert ( | ||
| file_ext is True | ||
| ), f"{inp_dir} does not contain all czi files!! Please check input directory again" | ||
|
|
||
| if preview: | ||
| with Path.open(Path(out_dir, "preview.json"), "w") as jfile: | ||
| out_json: dict[str, Any] = { | ||
| "filepattern": file_pattern, | ||
| "outDir": [], | ||
| } | ||
| for file in files(): | ||
| out_name = file[1][0].name.replace( | ||
| "".join(file[1][0].suffixes), | ||
| ".ome.tif", | ||
| ) | ||
| out_json["outDir"].append(out_name) | ||
| json.dump(out_json, jfile, indent=2) | ||
| else: | ||
| for file in files(): | ||
| cz.extract_fovs(file[1][0], out_dir) | ||
|
|
||
| if __name__ == "__main__": | ||
| app() | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When running with the
previewoption, we shouldreturnhere and not run the rest of the code.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done