Browse Source

api changes

- normilization api for measurement changed to
   `split_channels`
 - named tuple for exposure maps exposed in package as
   `ExposureInfo`
xmlparsing
Holger Frey 4 years ago
parent
commit
58d49bf967
  1. 10
      CHANGES.md
  2. 9
      README.md
  3. 5
      sensospot_data/__init__.py
  4. 3
      sensospot_data/normalisation.py
  5. 4
      sensospot_data/parameters.py
  6. 6
      sensospot_data/parser.py
  7. 9
      tests/test_normailsation.py
  8. 11
      tests/test_parameters.py
  9. 4
      tests/test_sensovation_data_parser.py

10
CHANGES.md

@ -1,3 +1,13 @@ @@ -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
--------------------------

9
README.md

@ -9,7 +9,14 @@ Parsing the numerical output from Sensovation Sensospot image analysis. @@ -9,7 +9,14 @@ Parsing the numerical output from Sensovation Sensospot image analysis.
import sensospot_data
sensovation_data.process_folder(<path to results directory>)
# read the raw data of a folder
raw_data = sensospot_data.process_folder(<path to results directory>)
# 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)
```

5
sensospot_data/__init__.py

@ -3,7 +3,7 @@ @@ -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 @@ -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

3
sensospot_data/normalisation.py

@ -137,6 +137,7 @@ def normalize_exposure_time(split_data_frames): @@ -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): @@ -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,

4
sensospot_data/parameters.py

@ -15,7 +15,7 @@ from .columns import ( @@ -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): @@ -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

6
sensospot_data/parser.py

@ -85,7 +85,7 @@ def _cleanup_data_columns(data_frame): @@ -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): @@ -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): @@ -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())

9
tests/test_normailsation.py

@ -217,10 +217,7 @@ def test_infer_normalization_map(normalization_data_frame): @@ -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): @@ -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): @@ -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"}

11
tests/test_parameters.py

@ -69,15 +69,12 @@ def test_get_measurement_params_file_not_found(example_dir): @@ -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)

4
tests/test_sensovation_data_parser.py

@ -3,8 +3,10 @@ @@ -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

Loading…
Cancel
Save