From 58d49bf9675653090433b064fc535a7ccf4b39bd Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Tue, 24 Nov 2020 10:59:16 +0100 Subject: [PATCH] api changes - normilization api for measurement changed to `split_channels` - named tuple for exposure maps exposed in package as `ExposureInfo` --- CHANGES.md | 10 ++++++++++ README.md | 9 ++++++++- sensospot_data/__init__.py | 5 +++-- sensospot_data/normalisation.py | 3 ++- sensospot_data/parameters.py | 4 ++-- sensospot_data/parser.py | 6 +++--- tests/test_normailsation.py | 9 +++------ tests/test_parameters.py | 11 ++++------- tests/test_sensovation_data_parser.py | 4 +++- 9 files changed, 38 insertions(+), 23 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index c1ad670..3e7f367 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,13 @@ + +0.4.0 - api changes +-------------------- + + - normilization api for measurement changed to + `split_channels` + - named tuple for exposure maps exposed in package as + `ExposureInfo` + + 0.3.0 - normalization api -------------------------- diff --git a/README.md b/README.md index ca5571c..503ca54 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,14 @@ Parsing the numerical output from Sensovation Sensospot image analysis. import sensospot_data - sensovation_data.process_folder() + # read the raw data of a folder + raw_data = sensospot_data.process_folder() + + # split the measurement according to channels + channels = sensospot_data.split_channels(raw_data [, optional_exposure_map]) + + # normalize one channel to a specific exposure time + cy5_normalized = sensospot_data.normalize_channel(channels["cy5"], normalized_time=25) ``` diff --git a/sensospot_data/__init__.py b/sensospot_data/__init__.py index 0e30f40..aabfd3f 100644 --- a/sensospot_data/__init__.py +++ b/sensospot_data/__init__.py @@ -3,7 +3,7 @@ Parsing the numerical output from Sensovations Sensospot image analysis. """ -__version__ = "0.3.0" +__version__ = "0.4.0" VERSION_TABLE_NAME = f"v{__version__}".replace(".", "_") @@ -15,4 +15,5 @@ from .parser import ( # noqa: F401 process_folder, parse_multiple_files, ) -from .normalisation import normalize_channel, normalize_measurement # noqa: F401 +from .parameters import ExposureInfo # noqa: F401 +from .normalisation import normalize_channel, split_channels # noqa: F401 diff --git a/sensospot_data/normalisation.py b/sensospot_data/normalisation.py index fb40276..11ea73a 100644 --- a/sensospot_data/normalisation.py +++ b/sensospot_data/normalisation.py @@ -137,6 +137,7 @@ def normalize_exposure_time(split_data_frames): def normalize_channel(channel_frame, normalized_time): """ add time normalized values to a channel data frames """ + channel_frame = channel_frame.copy() channel_frame[COL_NAME_NORMALIZED_EXPOSURE_TIME] = normalized_time for original_col, normalized_col in COLUMN_NORMALIZATION.items(): @@ -147,7 +148,7 @@ def normalize_channel(channel_frame, normalized_time): return channel_frame -def normalize_measurement( +def split_channels( data_frame, exposure_map=None, overflow_column=COL_NAME_SPOT_MEAN, diff --git a/sensospot_data/parameters.py b/sensospot_data/parameters.py index 80ca6e2..2ce33de 100644 --- a/sensospot_data/parameters.py +++ b/sensospot_data/parameters.py @@ -15,7 +15,7 @@ from .columns import ( COL_NAME_PARAMETERS_CHANNEL, ) -MeasurementParams = namedtuple("MeasurementParams", ["channel", "time"]) +ExposureInfo = namedtuple("ExposureInfo", ["channel", "time"]) def _search_measurement_params_file(folder): @@ -44,7 +44,7 @@ def _parse_measurement_params(params_file): # channel_description == "[Cy3|Cy5] Green" channel = channel_description.rsplit(" ", 1)[-1] time = int(child.attrib["ExposureTimeMs"]) - result[exposure] = MeasurementParams(channel.lower(), time) + result[exposure] = ExposureInfo(channel.lower(), time) return result diff --git a/sensospot_data/parser.py b/sensospot_data/parser.py index c9d38e6..7895e3a 100755 --- a/sensospot_data/parser.py +++ b/sensospot_data/parser.py @@ -85,7 +85,7 @@ def _cleanup_data_columns(data_frame): def parse_file(data_file): """ parses one data file and adds metadata to result """ - measurement_info = _extract_measurement_info(data_file) + measurement_info = _extract_measurement_info(Path(data_file)) data_frame = _parse_csv(data_file) data_frame[COL_NAME_WELL_ROW] = measurement_info.row data_frame[COL_NAME_WELL_COLUMN] = measurement_info.column @@ -129,7 +129,7 @@ def _sanity_check(data_frame): def parse_folder(folder): """ parses all csv files in a folder to one large dataframe """ - file_list = _list_csv_files(folder) + file_list = _list_csv_files(Path(folder)) data_frame = parse_multiple_files(file_list) data_frame = add_optional_measurement_parameters(data_frame, folder) return _sanity_check(data_frame) @@ -137,7 +137,7 @@ def parse_folder(folder): def process_folder(folder, use_cache=True): """ parses all csv files in a folder, adds some checks and more data """ - hdf5_path = folder / CACHE_FILE_NAME + hdf5_path = Path(folder) / CACHE_FILE_NAME if use_cache: try: return pandas.read_hdf(hdf5_path, _get_cache_table_name()) diff --git a/tests/test_normailsation.py b/tests/test_normailsation.py index 4bb75b8..c62979c 100644 --- a/tests/test_normailsation.py +++ b/tests/test_normailsation.py @@ -217,10 +217,7 @@ def test_infer_normalization_map(normalization_data_frame): def test_normalize_channel(normalization_data_frame): from sensospot_data.columns import COLUMN_NORMALIZATION - from sensospot_data.normalisation import ( - reduce_overflow, - normalize_channel, - ) + from sensospot_data.normalisation import reduce_overflow, normalize_channel reduced = reduce_overflow(normalization_data_frame, "Saturation", 1) result = normalize_channel(reduced["Cy5"], 50) @@ -274,7 +271,7 @@ def test_normalize_exposure_time_infered_map(normalization_data_frame): def test_normalize_measurement(example_dir): from sensospot_data.parser import process_folder - from sensospot_data.normalisation import normalize_measurement + from sensospot_data.normalisation import split_channels sub_dir = example_dir / EXAMPLE_DIR_WITH_PARAMS data_frame = process_folder(sub_dir) @@ -285,7 +282,7 @@ def test_normalize_measurement(example_dir): 3: ExposureSetting("Cy5", 150), } - result = normalize_measurement(data_frame, exposure_map) + result = split_channels(data_frame, exposure_map) cy3_df, cy5_df = result["Cy3"], result["Cy5"] assert set(result.keys()) == {"Cy3", "Cy5"} diff --git a/tests/test_parameters.py b/tests/test_parameters.py index 86571c0..5d5a43a 100644 --- a/tests/test_parameters.py +++ b/tests/test_parameters.py @@ -69,15 +69,12 @@ def test_get_measurement_params_file_not_found(example_dir): def test_add_measurement_params(exposure_df): - from sensospot_data.parameters import ( - MeasurementParams, - _add_measurement_params, - ) + from sensospot_data.parameters import ExposureInfo, _add_measurement_params params = { - 1: MeasurementParams("red", 10), - 2: MeasurementParams("green", 20), - 3: MeasurementParams("blue", 50), + 1: ExposureInfo("red", 10), + 2: ExposureInfo("green", 20), + 3: ExposureInfo("blue", 50), } result = _add_measurement_params(exposure_df, params) diff --git a/tests/test_sensovation_data_parser.py b/tests/test_sensovation_data_parser.py index 8fe7e0d..e3aecd4 100644 --- a/tests/test_sensovation_data_parser.py +++ b/tests/test_sensovation_data_parser.py @@ -3,8 +3,10 @@ def test_import_api(): from sensospot_data import CACHE_FILE_NAME # noqa: F401 + from sensospot_data import ExposureInfo # noqa: F401 from sensospot_data import parse_file # noqa: F401 from sensospot_data import parse_folder # noqa: F401 from sensospot_data import process_folder # noqa: F401 + from sensospot_data import normalize_channel # noqa: F401 + from sensospot_data import split_channels # noqa: F401 from sensospot_data import parse_multiple_files # noqa: F401 - from sensospot_data import normalize_measurement # noqa: F401