Skip to content
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ZEDprofiler [![Documentation](https://img.shields.io/badge/documentation-available-brightgreen)](https://zedprofiler.readthedocs.io/en/latest/) ![License](https://img.shields.io/badge/license-BSD%203--Clause-blue)[![Coverage](https://img.shields.io/badge/coverage-92%25-brightgreen)](#quality-gates)
# ZEDprofiler [![Documentation](https://img.shields.io/badge/documentation-available-brightgreen)](https://zedprofiler.readthedocs.io/en/latest/) ![License](https://img.shields.io/badge/license-BSD%203--Clause-blue)[![Coverage](https://img.shields.io/badge/coverage-91%25-brightgreen)](#quality-gates)

[![ZEDprofiler](https://github.com/WayScience/ZEDprofiler/raw/main/logo/with-text-for-dark-bg.png)](https://github.com/WayScience/ZEDprofiler)

Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ dependencies = [
"pyarrow>=23.0.1",
"pydantic>=2.10",
"scikit-image>=0.26",
"scipy>=1.14",
"tomli>=2.4.1",
]
urls.Homepage = "https://zedprofiler.readthedocs.io"
Expand Down Expand Up @@ -111,6 +112,10 @@ ignore-words-list = "inout"
paths = [ "src/zedprofiler", "tests" ]
min_confidence = 90

[tool.mypy]
ignore_missing_imports = true
python_version = "3.11"

[tool.pytest]
ini_options.pythonpath = [ "." ]

Expand Down
49 changes: 19 additions & 30 deletions src/zedprofiler/IO/feature_writing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,22 @@
import pandera.pandas as pa
from beartype import beartype

FEATURE_NAME_COMPONENT_COLUMNS = (
"compartment",
"channel",
"feature_type",
"measurement",
)


def _coerce_dataframe_column_names_to_strings(
dataframe: pandas.DataFrame,
) -> pandas.DataFrame:
"""
Ensure DataFrame column labels are string-typed before writing.
"""Ensure DataFrame column labels are string-typed before writing.

Parameters
----------
dataframe : pandas.DataFrame
The DataFrame whose column names should be coerced to strings.

Returns
-------
pandas.DataFrame
A copy of the input DataFrame with all column names coerced to strings.

"""
parsed_dataframe = dataframe.copy()
parsed_dataframe.columns = [str(column) for column in parsed_dataframe.columns]
Expand All @@ -42,8 +36,7 @@ def _coerce_dataframe_column_names_to_strings(

@beartype
def remove_underscores_from_string(string: object) -> str:
"""
Remove unwanted delimiters from a string and replace them with hyphens.
"""Remove unwanted delimiters from a string and replace them with hyphens.

Parameters
----------
Expand All @@ -54,6 +47,7 @@ def remove_underscores_from_string(string: object) -> str:
-------
str
The string with unwanted delimiters removed and replaced with hyphens.

"""
if not isinstance(string, str):
try:
Expand All @@ -64,42 +58,34 @@ def remove_underscores_from_string(string: object) -> str:
f"Received input: {string!r} of type {type(string)}"
)
raise ValueError(msg) from e
string = string.translate(
str.maketrans(
{
"_": "-",
".": "-",
" ": "-",
"/": "-",
}
)
)
string = string.translate(str.maketrans("_. /", "----"))

return string


def _coerce_feature_name_components(
dataframe: pandas.DataFrame,
) -> pandas.DataFrame:
"""
Normalize feature-name components using shared delimiter cleanup.
"""Normalize feature-name components using shared delimiter cleanup.

Parameters
----------
dataframe : pandas.DataFrame
The DataFrame containing feature name components to be normalized.
Expected to have columns corresponding to FEATURE NAME COMPONENT COLUMNS.

Returns
-------
pandas.DataFrame
A copy of the input DataFrame with feature name components normalized by
removing unwanted delimiters and replacing them with hyphens.

"""
parsed_dataframe = dataframe.copy()
for column in FEATURE_NAME_COMPONENT_COLUMNS:
if column in parsed_dataframe.columns:
parsed_dataframe[column] = parsed_dataframe[column].map(
remove_underscores_from_string
remove_underscores_from_string,
)
return parsed_dataframe

Expand Down Expand Up @@ -135,10 +121,12 @@ def _coerce_feature_name_components(

@beartype
def format_morphology_feature_name(
compartment: object, channel: object, feature_type: object, measurement: object
compartment: object,
channel: object,
feature_type: object,
measurement: object,
) -> str:
"""
Format a morphology feature name in a consistent way across all morphology features.
"""Format a morphology feature name consistently across all morphology features.
This format follows specification for the following:
https://github.com/WayScience/NF1_3D_organoid_profiling_pipeline/blob/main/docs/RFC-2119-Feature-Naming-Convention.md

Expand All @@ -157,17 +145,17 @@ def format_morphology_feature_name(
-------
str
The formatted feature name.
"""

"""
component_frame = pandas.DataFrame(
[
{
"compartment": compartment,
"channel": channel,
"feature_type": feature_type,
"measurement": measurement,
}
]
},
],
)
coerced_components = FEATURE_NAME_COMPONENT_SCHEMA.validate(component_frame)
parsed_row = coerced_components.iloc[0]
Expand Down Expand Up @@ -212,6 +200,7 @@ def save_features_as_parquet(
Returns
-------
pathlib.Path

"""
validated_df = FEATURE_OUTPUT_SCHEMA.validate(df)
output_prefix = format_morphology_feature_name(
Expand Down
Loading
Loading