Skip to content
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

Refactor core-library modules #631

Merged
merged 49 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
51f2409
Remove `lib` prefix from `lib_channels.py`
tcompa Dec 11, 2023
e7685b9
Remove `lib` prefix from `lib_tables
tcompa Dec 11, 2023
55a1fe8
Rename `lib_regions_of_interes` into `roi`
tcompa Dec 11, 2023
14bfad0
Remove `lib` prefix from `lib_input_models.py
tcompa Dec 11, 2023
17aa85d
Remove `lib` prefix from `lib_masked_loading.py
tcompa Dec 11, 2023
2ae5279
Remove `lib` prefix from `lib_metadata_parsing.py
tcompa Dec 11, 2023
308ac45
Remove `lib` prefix from `lib_parse_filename_metadata.py`
tcompa Dec 11, 2023
dc32e5f
Remove `lib` prefix from `lib_zattrs_utils.py`
tcompa Dec 11, 2023
6732878
Remove `lib` prefix from `lib_write.py`
tcompa Dec 11, 2023
1c28822
Remove `lib` prefix from `lib_read_fractal_metadata.py`
tcompa Dec 11, 2023
04c7288
Remove `lib` prefix from `lib_pyramid_creation.py`
tcompa Dec 11, 2023
969e3d4
Remove `lib` prefix from `lib_ngff.py`
tcompa Dec 11, 2023
9bb3137
Remove `lib` prefix from `lib_upscale_array.py`
tcompa Dec 11, 2023
4d50fb6
Populate `ome_zarr` and `yokogawa` subpackages
tcompa Dec 11, 2023
cf4518b
Fix input_models paths in dev tools
tcompa Dec 11, 2023
b473dea
Fix error message
tcompa Dec 11, 2023
8c491ad
Remove `lib` prefix from `lib_glob.py`
tcompa Dec 11, 2023
cef747e
Add missing `yokogawa/glob.py` file
tcompa Dec 11, 2023
b89ef39
Merge yokogawa modules related to filenames
tcompa Dec 11, 2023
b79e566
Rename `yokogawa/metadata_parsing.py` into `yokogawa/metadata.py`
tcompa Dec 11, 2023
22a066a
Rename `pyramid_creation.py` into `pyramids.py`
tcompa Dec 11, 2023
51cd7ce
Fix docstring
tcompa Dec 11, 2023
b1af79a
Fill `__init__.py` files
tcompa Dec 11, 2023
9ae3700
Rename yokogawa subpackage to cellvoyager
tcompa Dec 12, 2023
242a129
Extract `ngff` from `ome_zarr` subpackage
tcompa Dec 12, 2023
e01c57f
Simplify import statement
tcompa Dec 12, 2023
4725649
Rename `find_omengff_acquisition` with leading underscore
tcompa Dec 12, 2023
5736e23
Merge `ome_zarr/read_fractal_metadata.py` into `ome_zarr/zattrs_utils…
tcompa Dec 12, 2023
08549dc
Extract `prepare_label_group` function from `write.py`
tcompa Dec 12, 2023
12626a9
Clarify imports
tcompa Dec 12, 2023
4be2146
Clarify imports and remove `import *`
tcompa Dec 12, 2023
2d9e182
Improve exports in `ngff` subpackage
tcompa Dec 12, 2023
5f4a4c6
Add `_` prefix to `open_zarr_group_with_overwrite` function name
tcompa Dec 12, 2023
b89ebb9
Move `write.py` to main namespace, and extract `_write_elem_with_over…
tcompa Dec 12, 2023
9e9218e
Move `labels.py` out of `ome_zarr` subpackage`
tcompa Dec 12, 2023
d806290
Rename `write.py` into `zarr.py`
tcompa Dec 12, 2023
6acd4a0
Remove deprecated use of `Dict`
tcompa Dec 12, 2023
2867525
Move napari-workflows input models to task module
tcompa Dec 13, 2023
116757a
Rename `Channel into `ChannelInputModel`
tcompa Dec 13, 2023
1de1dd0
Rename `zarr.py` into `zarr_utils.py`
tcompa Dec 13, 2023
2f11e55
Rename `zattrs_utils.py` into `utils.py`
tcompa Dec 13, 2023
cf1119e
Move `ChannelInputModel` to `channels.py`
tcompa Dec 13, 2023
f088333
Remove init of `ome_zarr` subpackage
tcompa Dec 13, 2023
cdf6ee9
Move most relative imports to absolute imports
tcompa Dec 13, 2023
e26cc10
Remove `ome_zarr` subpackage, and move its content to main package
tcompa Dec 13, 2023
d364ad3
Update dev tools with new paths to models
tcompa Dec 13, 2023
e6080b5
Update manifest
tcompa Dec 13, 2023
dc2779c
Extract napari-workflows-task input models into separate module
tcompa Dec 13, 2023
be25157
Fix test
tcompa Dec 13, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.pytest_cache/
tree.sh
.coverage*
__pycache__
*.cpython-*.pyc
Expand Down
4 changes: 2 additions & 2 deletions examples/01_cardio_tiny_dataset/run_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.yokogawa_to_ome_zarr import yokogawa_to_ome_zarr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.yokogawa_to_ome_zarr import yokogawa_to_ome_zarr

Expand Down
4 changes: 2 additions & 2 deletions examples/02_cardio_tiny_dataset_sparse/run_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.yokogawa_to_ome_zarr import yokogawa_to_ome_zarr

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.illumination_correction import (
illumination_correction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.napari_workflows_wrapper import (
napari_workflows_wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.napari_workflows_wrapper import (
napari_workflows_wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.napari_workflows_wrapper import (
napari_workflows_wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.cellpose_segmentation import (
cellpose_segmentation,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.napari_workflows_wrapper import (
napari_workflows_wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.napari_workflows_wrapper import (
napari_workflows_wrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.cellpose_segmentation import (
cellpose_segmentation,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.cellpose_segmentation import (
cellpose_segmentation,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.cellpose_segmentation import (
cellpose_segmentation,
)
Expand Down
4 changes: 2 additions & 2 deletions examples/08_subset_of_data/run_example_single_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.copy_ome_zarr import copy_ome_zarr
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.maximum_intensity_projection import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.copy_ome_zarr import copy_ome_zarr
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.maximum_intensity_projection import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.copy_ome_zarr import copy_ome_zarr
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.maximum_intensity_projection import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.copy_ome_zarr import copy_ome_zarr
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.maximum_intensity_projection import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.copy_ome_zarr import copy_ome_zarr
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.maximum_intensity_projection import (
Expand Down
4 changes: 2 additions & 2 deletions examples/09_secondary_labeling/01_images_to_mip.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from devtools import debug

from fractal_tasks_core.lib_channels import OmeroChannel
from fractal_tasks_core.lib_channels import Window
from fractal_tasks_core.channels import OmeroChannel
from fractal_tasks_core.channels import Window
from fractal_tasks_core.tasks.copy_ome_zarr import copy_ome_zarr
from fractal_tasks_core.tasks.create_ome_zarr import create_ome_zarr
from fractal_tasks_core.tasks.maximum_intensity_projection import (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from devtools import debug

from fractal_tasks_core.lib_input_models import Channel
from fractal_tasks_core.channels import ChannelInputModel
from fractal_tasks_core.tasks.cellpose_segmentation import (
cellpose_segmentation,
)
Expand All @@ -31,7 +31,7 @@
output_path=zarr_path_mip,
metadata=metadata,
component=component,
channel=Channel(wavelength_id="A01_C01"),
channel=ChannelInputModel(wavelength_id="A01_C01"),
level=2,
relabeling=True,
diameter_level0=400.0,
Expand All @@ -53,7 +53,7 @@
output_path=zarr_path_mip,
metadata=metadata,
component=component,
channel=Channel(wavelength_id="A01_C01"),
channel=ChannelInputModel(wavelength_id="A01_C01"),
level=2,
relabeling=True,
diameter_level0=20.0,
Expand Down
2 changes: 1 addition & 1 deletion examples/09_secondary_labeling/check_ROI_table.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from fractal_tasks_core.lib_regions_of_interest import _inspect_ROI_table
from fractal_tasks_core.roi import _inspect_ROI_table


table = sys.argv[1]
Expand Down
2 changes: 1 addition & 1 deletion examples/tools/lib_inspect_ROI_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import anndata as ad

from fractal_tasks_core.lib_regions_of_interest import (
from fractal_tasks_core.roi import (
convert_ROI_table_to_indices,
)

Expand Down
4 changes: 3 additions & 1 deletion examples/tools/show_FOV_ROIs/show_FOV_ROIs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
"""
import matplotlib.pyplot as plt

from fractal_tasks_core.lib_metadata_parsing import parse_yokogawa_metadata
from fractal_tasks_core.cellvoyager.metadata import (
parse_yokogawa_metadata,
)
from fractal_tasks_core.lib_ROI_overlaps import run_overlap_check


Expand Down
16 changes: 8 additions & 8 deletions fractal_tasks_core/__FRACTAL_MANIFEST__.json
Original file line number Diff line number Diff line change
Expand Up @@ -393,12 +393,12 @@
"description": "Pyramid level of the image to be segmented. Choose `0` to process at full resolution."
},
"channel": {
"$ref": "#/definitions/Channel",
"$ref": "#/definitions/ChannelInputModel",
"title": "Channel",
"description": "Primary channel for segmentation; requires either `wavelength_id` (e.g. `A01_C01`) or `label` (e.g. `DAPI`)."
},
"channel2": {
"$ref": "#/definitions/Channel",
"$ref": "#/definitions/ChannelInputModel",
"title": "Channel2",
"description": "Second channel for segmentation (in the same format as `channel`). If specified, cellpose runs in dual channel mode. For dual channel segmentation of cells, the first channel should contain the membrane marker, the second channel should contain the nuclear marker."
},
Expand Down Expand Up @@ -505,8 +505,8 @@
],
"additionalProperties": false,
"definitions": {
"Channel": {
"title": "Channel",
"ChannelInputModel": {
"title": "ChannelInputModel",
"description": "A channel which is specified by either `wavelength_id` or `label`.",
"type": "object",
"properties": {
Expand Down Expand Up @@ -709,8 +709,8 @@
],
"additionalProperties": false,
"definitions": {
"Channel": {
"title": "Channel",
"ChannelInputModel": {
"title": "ChannelInputModel",
"description": "A channel which is specified by either `wavelength_id` or `label`.",
"type": "object",
"properties": {
Expand Down Expand Up @@ -746,9 +746,9 @@
"description": "Label name (for label inputs only)."
},
"channel": {
"$ref": "#/definitions/Channel",
"$ref": "#/definitions/ChannelInputModel",
"title": "Channel",
"description": "Channel object (for image inputs only)."
"description": "`ChannelInputModel` object (for image inputs only)."
}
},
"required": [
Expand Down
1 change: 1 addition & 0 deletions fractal_tasks_core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging


logging.basicConfig(
level=logging.INFO, format="%(asctime)s; %(levelname)s; %(message)s"
)
Expand Down
3 changes: 3 additions & 0 deletions fractal_tasks_core/cellvoyager/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
Subpackage with utilities for tasks converting CellVoyager images to OME-Zarr.
"""
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,54 @@
# Institute for Biomedical Research and Pelkmans Lab from the University of
# Zurich.
"""
Extract metadata from image filename.
Auxiliary functions related to filenames of Yokogawa-microscope images.
"""
import logging
import re
from glob import glob
from pathlib import Path
from typing import Sequence


def glob_with_multiple_patterns(
*,
folder: str,
patterns: Sequence[str] = None,
) -> set[str]:
"""
List all the items (files and folders) in a given folder that
simultaneously match a series of glob patterns.

Args:
folder: Base folder where items will be searched.
patterns: If specified, the list of patterns (defined as in
https://docs.python.org/3/library/fnmatch.html) that item
names will match with.
"""

# Sanitize base-folder path
if folder.endswith("/"):
actual_folder = folder[:-1]
else:
actual_folder = folder[:]

# If not pattern is specified, look for *all* items in the base folder
if not patterns:
patterns = ["*"]

# Combine multiple glob searches (via set intersection)
logging.info(f"[glob_with_multiple_patterns] {patterns=}")
items = None
for pattern in patterns:
new_matches = glob(f"{actual_folder}/{pattern}")
if items is None:
items = set(new_matches)
else:
items = items.intersection(new_matches)
items = items or set()
logging.info(f"[glob_with_multiple_patterns] Found {len(items)} items")

return items


def _get_plate_name(plate_prefix: str) -> str:
Expand Down
Loading
Loading