Browse Source

remove custom normalization map

normilization of exposure time is always to the largest time available
xmlparsing
Holger Frey 4 years ago
parent
commit
0ac616648c
  1. 12
      CHANGES.md
  2. 2
      sensospot_data/__init__.py
  3. 23
      sensospot_data/normalisation.py
  4. 11
      tests/test_normailsation.py

12
CHANGES.md

@ -1,3 +1,15 @@
0.2.0 - remove custom normalization map
----------------------------------------
- normilization of exposure time is always to the largest time available
0.1.0 - first working version
------------------------------
- woohoo
0.0.1 - first version 0.0.1 - first version
---------------------- ----------------------

2
sensospot_data/__init__.py

@ -3,7 +3,7 @@
Parsing the numerical output from Sensovations Sensospot image analysis. Parsing the numerical output from Sensovations Sensospot image analysis.
""" """
__version__ = "0.1.0" __version__ = "0.2.0"
VERSION_TABLE_NAME = f"v{__version__}".replace(".", "_") VERSION_TABLE_NAME = f"v{__version__}".replace(".", "_")

23
sensospot_data/normalisation.py

@ -123,21 +123,14 @@ def _infer_normalization_map(split_data_frames):
} }
def normalize_exposure_time(split_data_frames, normalization_map=None): def normalize_exposure_time(split_data_frames):
""" add time normalized values to the split data frames """ add time normalized values to the split data frames
normalization_map: The max exposure time per channel is used for normalization.
keys: channel identifier (e.g. "Cy5")
values: target exposure time for normalization
If normalization_map is None, the max exposure time per channel is used
""" """
complete_map = _infer_normalization_map(split_data_frames) normalization_map = _infer_normalization_map(split_data_frames)
if normalization_map is not None:
complete_map.update(normalization_map)
return { return {
key: _normalize_exposure(frame, complete_map[key]) key: _normalize_exposure(frame, normalization_map[key])
for key, frame in split_data_frames.items() for key, frame in split_data_frames.items()
} }
@ -157,7 +150,6 @@ def _normalize_exposure(channel_frame, normalized_time):
def normalize_measurement( def normalize_measurement(
data_frame, data_frame,
exposure_map=None, exposure_map=None,
normalization_map=None,
overflow_column=COL_NAME_SPOT_MEAN, overflow_column=COL_NAME_SPOT_MEAN,
overflow_limit=0.5, overflow_limit=0.5,
): ):
@ -169,14 +161,11 @@ def normalize_measurement(
if the exposure map is None, the values from the optionally parsed if the exposure map is None, the values from the optionally parsed
measurement parameters are used. measurement parameters are used.
normalization_map: The max exposure time per channel is used for normalization.
keys: channel identifier (e.g. "Cy5")
values: target exposure time for normalization
If normalization_map is None, the max exposure time per channel is used
""" """
exposure_data_frame = apply_exposure_map(data_frame, exposure_map) exposure_data_frame = apply_exposure_map(data_frame, exposure_map)
split_data_frames = reduce_overflow( split_data_frames = reduce_overflow(
exposure_data_frame, overflow_column, overflow_limit exposure_data_frame, overflow_column, overflow_limit
) )
return normalize_exposure_time(split_data_frames, normalization_map) return normalize_exposure_time(split_data_frames)

11
tests/test_normailsation.py

@ -228,7 +228,7 @@ def test_normalize_exposure(normalization_data_frame):
sorted_results = result.sort_values( sorted_results = result.sort_values(
by=["Well.Row", "Well.Column", "Pos.Id"] by=["Well.Row", "Well.Column", "Pos.Id"]
) )
expected_values = [2, 8, 30, 2, 20, 20, 20, 20, 200, 200, 200, 200] expected_values = [1, 4, 15, 1, 10, 10, 10, 10, 100, 100, 100, 100]
for normalized_col in COLUMN_NORMALIZATION.values(): for normalized_col in COLUMN_NORMALIZATION.values():
list(sorted_results[normalized_col]) == expected_values list(sorted_results[normalized_col]) == expected_values
@ -241,14 +241,14 @@ def test_normalize_exposure_time(normalization_data_frame):
) )
reduced = reduce_overflow(normalization_data_frame, "Saturation", 1) reduced = reduce_overflow(normalization_data_frame, "Saturation", 1)
result = normalize_exposure_time(reduced, {"Cy5": 100, "Cy3": 0}) result = normalize_exposure_time(reduced)
assert "Cy5" in result assert "Cy5" in result
sorted_results = result["Cy5"].sort_values( sorted_results = result["Cy5"].sort_values(
by=["Well.Row", "Well.Column", "Pos.Id"] by=["Well.Row", "Well.Column", "Pos.Id"]
) )
expected_values = [2, 8, 30, 2, 20, 20, 20, 20, 200, 200, 200, 200] expected_values = [1, 4, 15, 1, 10, 10, 10, 10, 100, 100, 100, 100]
assert list(sorted_results["Normalized.Spot.Mean"]) == expected_values assert list(sorted_results["Normalized.Spot.Mean"]) == expected_values
@ -284,11 +284,10 @@ def test_normalize_measurement(example_dir):
2: ExposureSetting("Cy5", 15), 2: ExposureSetting("Cy5", 15),
3: ExposureSetting("Cy5", 150), 3: ExposureSetting("Cy5", 150),
} }
normalization_map = {"Cy5": 25}
result = normalize_measurement(data_frame, exposure_map, normalization_map) result = normalize_measurement(data_frame, exposure_map)
cy3_df, cy5_df = result["Cy3"], result["Cy5"] cy3_df, cy5_df = result["Cy3"], result["Cy5"]
assert set(result.keys()) == {"Cy3", "Cy5"} assert set(result.keys()) == {"Cy3", "Cy5"}
assert cy3_df["Normalized.Exposure.Time"].unique() == 100 assert cy3_df["Normalized.Exposure.Time"].unique() == 100
assert cy5_df["Normalized.Exposure.Time"].unique() == 25 assert cy5_df["Normalized.Exposure.Time"].unique() == 150

Loading…
Cancel
Save