Skip to content

Commit

Permalink
initial pass at new version to support camel case naming downstream
Browse files Browse the repository at this point in the history
  • Loading branch information
vreuter committed Sep 29, 2024
1 parent ae68768 commit 71ddcd6
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Changed
* Renaming `mean_intensity` to `meanIntensity` right away after detection, before writing to disk.

## [v0.1.0] - 2024-04-18

### Added
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "spotfishing"
version = "0.1.0"
version = "0.2.0"
description = "Detecting spots in FISH images"
authors = [
"Vince Reuter <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions spotfishing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Package-level members"""

from ._constants import ROI_AREA_KEY, ROI_MEAN_INTENSITY_KEY
from ._constants import ROI_AREA_KEY, ROI_MEAN_INTENSITY_KEY, ROI_MEAN_INTENSITY_KEY_CAMEL_CASE
from ._exceptions import *
from .detection_result import DetectionResult, RoiCenterKeys
from .detectors import detect_spots_dog, detect_spots_int
Expand All @@ -11,7 +11,7 @@

__all__ = [
"ROI_AREA_KEY",
"ROI_MEAN_INTENSITY_KEY",
"ROI_MEAN_INTENSITY_KEY_CAMEL_CASE", # Only export this (not the snake case one).
"DifferenceOfGaussiansTransformation",
"DimensionalityError",
"RoiCenterKeys",
Expand Down
11 changes: 5 additions & 6 deletions spotfishing/_constants.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"""Constant useful package-wide"""
"""Constants useful package-wide"""

__author__ = "Vince Reuter"
__credits__ = ["Vince Reuter"]

__all__ = [
"ROI_AREA_KEY",
"ROI_CENTROID_KEY",
"ROI_LABEL_KEY",
"ROI_MEAN_INTENSITY_KEY",
"ROI_MEAN_INTENSITY_KEY", # Export this for package-internal use.
"ROI_MEAN_INTENSITY_KEY_CAMEL_CASE",
]


Expand All @@ -17,8 +17,7 @@
# the key for an ROI's centroid, coming back from skimage.measure.regionprops_table
ROI_CENTROID_KEY = "centroid_weighted"

# the key for an ROI's label, coming back from skimage.measure.regionprops_table
ROI_LABEL_KEY = "label"

# the key for an ROI's average intensity, coming back from skimage.measure.regionprops_table
ROI_MEAN_INTENSITY_KEY = "intensity_mean"

ROI_MEAN_INTENSITY_KEY_CAMEL_CASE = "intensityMean"
8 changes: 4 additions & 4 deletions spotfishing/detection_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@ def to_list(cls) -> list[str]:

# how to rename columns arising from extraction from skimage.measure.regionprops_table, to better suit downstream analysis
# TODO: consider making this configurable, see: https://github.com/gerlichlab/spotfishing/issues/1
ROI_CENTROID_COLUMN_RENAMING = tuple(
SPOT_DETECTION_COLUMN_RENAMING: tuple[str, str] = tuple(
(f"{ROI_CENTROID_KEY}-{i}", c) for i, c in enumerate(RoiCenterKeys.to_list())
)
) + (ROI_MEAN_INTENSITY_KEY, ROI_MEAN_INTENSITY_KEY_CAMEL_CASE)

# fields to pull from skimage.measure.regionprops_table result, besides centroid coordinates and label
ROI_MEASUREMENT_KEYS = [ROI_AREA_KEY, ROI_MEAN_INTENSITY_KEY]

# the sequence of columns of fields extracted from skimage.measure.regionprops_table, after accounting for expansion in multiple dimensions (e.g., centroid_weighted)
SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED = [
old for old, _ in ROI_CENTROID_COLUMN_RENAMING
old for old, _ in SPOT_DETECTION_COLUMN_RENAMING
] + ROI_MEASUREMENT_KEYS

# the expected column names in a detection result table, after extraction and renaming
DETECTION_RESULT_TABLE_COLUMNS = [
dict(ROI_CENTROID_COLUMN_RENAMING).get(c, c)
dict(SPOT_DETECTION_COLUMN_RENAMING).get(c, c)
for c in SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED
]

Expand Down
13 changes: 7 additions & 6 deletions spotfishing/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ._exceptions import DimensionalityError
from ._types import *
from .detection_result import (
ROI_CENTROID_COLUMN_RENAMING,
SPOT_DETECTION_COLUMN_RENAMING,
ROI_MEASUREMENT_KEYS,
SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED,
DetectionResult,
Expand Down Expand Up @@ -125,13 +125,14 @@ def _build_props_table(
regionprops_table(
label_image=labels,
intensity_image=input_image,
properties=tuple(
[ROI_LABEL_KEY, ROI_CENTROID_KEY] + ROI_MEASUREMENT_KEYS
),
properties=(ROI_CENTROID_KEY, *ROI_MEASUREMENT_KEYS),
)
)
spot_props = spot_props.drop(["label"], axis=1, errors="ignore")
spot_props = spot_props.rename(columns=dict(ROI_CENTROID_COLUMN_RENAMING))
spot_props = spot_props.rename(
columns=dict(SPOT_DETECTION_COLUMN_RENAMING),
inplace=False,
errors="raise",
)
spot_props = spot_props.reset_index(drop=True)
return spot_props, labels

Expand Down

0 comments on commit 71ddcd6

Please sign in to comment.