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

Support camel case downstream access #13

Merged
merged 4 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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).

## [v0.2.0] - 2024-10-03

### 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
8 changes: 6 additions & 2 deletions spotfishing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
"""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 +15,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"
17 changes: 7 additions & 10 deletions spotfishing/detection_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,20 @@ 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[tuple[str, str], ...] = tuple(
(f"{ROI_CENTROID_KEY}-{i}", c) for i, c in enumerate(RoiCenterKeys.to_list())
) + (
(ROI_AREA_KEY, ROI_AREA_KEY),
(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
] + ROI_MEASUREMENT_KEYS
old for old, _ in SPOT_DETECTION_COLUMN_RENAMING
]

# 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)
for c in SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED
]
DETECTION_RESULT_TABLE_COLUMNS = [new for _, new in SPOT_DETECTION_COLUMN_RENAMING]


@doc(
Expand Down
14 changes: 7 additions & 7 deletions spotfishing/detectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
from ._exceptions import DimensionalityError
from ._types import *
from .detection_result import (
ROI_CENTROID_COLUMN_RENAMING,
ROI_MEASUREMENT_KEYS,
SKIMAGE_REGIONPROPS_TABLE_COLUMNS_EXPANDED,
SPOT_DETECTION_COLUMN_RENAMING,
DetectionResult,
)
from .dog_transform import DifferenceOfGaussiansTransformation
Expand Down Expand Up @@ -125,13 +124,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_AREA_KEY, ROI_MEAN_INTENSITY_KEY),
)
)
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,zc,yc,xc,intensity_mean
,zc,yc,xc,intensityMean
0,2.4580271876546713,125.05243771893812,189.95460283233513,140.35164243403338
1,3.215275611393135,165.8262102606279,338.60801357496007,142.0859637340497
2,2.9371662355253076,174.2444293945887,343.5015376758335,135.34335086401202
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,zc,yc,xc,intensity_mean
,zc,yc,xc,intensityMean
0,1.464823275885825,381.0047398327831,256.9925375190833,150.19950331125827
1,5.64082522600635,21.70851874992031,177.53797926734416,158.95216862586136
2,5.645954517203461,334.42413956132106,246.54587324100783,158.50154364299746
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,zc,yc,xc,intensity_mean
,zc,yc,xc,intensityMean
0,2.900904569286373,478.08907046083226,672.0878758101751,143.69342359767893
1,3.4613367258090584,206.96659488938826,769.1328018686423,119.6487835308796
2,3.3685636416728855,557.7280560872998,563.5415814974639,150.34634146341463
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,zc,yc,xc,intensity_mean
,zc,yc,xc,intensityMean
0,5.338708099413269,21.623742874490315,177.42528322192456,160.0732381391064
1,5.4162750969712805,334.3139437667062,246.38533874630704,159.93892639022823
2,6.183825840659056,343.4778794839467,238.8895252240894,161.87028235951914
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,zc,yc,xc,intensity_mean
,zc,yc,xc,intensityMean
0,3.3902772597289568,125.08864851423598,190.01392515230637,187.04651162790697
1,4.863298083935557,126.35459623417093,210.9740933501293,266.3664459161148
2,2.74294559405134,134.9870391491757,311.8039430611308,201.5253731343284
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,zc,yc,xc,intensity_mean
,zc,yc,xc,intensityMean
0,3.658232714432168,22.889665679462357,178.80805758059003,221.90205371248024
1,0.5710688944838636,250.68390936140997,486.9258411535821,189.95652173913044
2,4.348300667423207,340.4061183666404,242.91498528591487,226.78735005452563
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,zc,yc,xc,intensity_mean
,zc,yc,xc,intensityMean
0,0.2320966350301984,477.7818809318378,672.2436583261432,275.95238095238096
1,2.3448733193085154,557.9810207628282,563.80988749657,283.97402597402595
2,5.223356373573381,126.48178213577668,210.59382200075012,358.90384615384613
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
,zc,yc,xc,intensity_mean
,zc,yc,xc,intensityMean
0,3.315825788780396,22.067221443954253,177.91419072908607,298.91875
1,3.748072232760957,336.2526422113276,245.102830676751,302.9179104477612
2,4.329418330331549,341.85340300854875,240.40516475989955,323.12295081967216
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import spotfishing_looptrace
from spotfishing import (
ROI_MEAN_INTENSITY_KEY,
ROI_MEAN_INTENSITY_KEY_CAMEL_CASE,
RoiCenterKeys,
detect_spots_dog,
detect_spots_int,
Expand Down Expand Up @@ -82,7 +82,7 @@ def test_output_is_correct_with_original_settings(
arr_name = f"img__{data_name}__smaller.npy"
input_image = load_image_file(arr_name)
obs = detect(input_image, spot_threshold=threshold, expand_px=expand_px)
obs_table = obs.table[RoiCenterKeys.to_list() + [ROI_MEAN_INTENSITY_KEY]]
obs_table = obs.table[RoiCenterKeys.to_list() + [ROI_MEAN_INTENSITY_KEY_CAMEL_CASE]]

print("EXPECTED (below):")
print(exp_table)
Expand Down
Loading