|
|
@ -16,6 +16,7 @@ from .columns import ( |
|
|
|
COL_NAME_EXPOSURE_ID, |
|
|
|
COL_NAME_EXPOSURE_ID, |
|
|
|
COL_NAME_WELL_COLUMN, |
|
|
|
COL_NAME_WELL_COLUMN, |
|
|
|
COL_NAME_SPOT_DIAMETER, |
|
|
|
COL_NAME_SPOT_DIAMETER, |
|
|
|
|
|
|
|
RAW_DATA_COLUMN_SET |
|
|
|
) |
|
|
|
) |
|
|
|
from .parameters import add_optional_measurement_parameters |
|
|
|
from .parameters import add_optional_measurement_parameters |
|
|
|
|
|
|
|
|
|
|
@ -27,7 +28,7 @@ REGEX_WELL = re.compile( |
|
|
|
re.VERBOSE | re.IGNORECASE, |
|
|
|
re.VERBOSE | re.IGNORECASE, |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
COLUMNS_TO_DROP = ["Rect.", "Contour"] |
|
|
|
COLUMNS_TO_DROP = ["Rect.", "Contour", "Id", "Name", "Foo"] |
|
|
|
COLUMNS_RENAME_MAP = { |
|
|
|
COLUMNS_RENAME_MAP = { |
|
|
|
" ID ": COL_NAME_POS_ID, |
|
|
|
" ID ": COL_NAME_POS_ID, |
|
|
|
"Found": COL_NAME_SPOT_FOUND, |
|
|
|
"Found": COL_NAME_SPOT_FOUND, |
|
|
@ -79,13 +80,17 @@ def _extract_measurement_info(data_file): |
|
|
|
|
|
|
|
|
|
|
|
def _cleanup_data_columns(data_frame): |
|
|
|
def _cleanup_data_columns(data_frame): |
|
|
|
""" renames some data columns for consistency and drops unused columns """ |
|
|
|
""" renames some data columns for consistency and drops unused columns """ |
|
|
|
renamed = data_frame.rename(columns=COLUMNS_RENAME_MAP) |
|
|
|
renamed = data_frame.rename(columns=COLUMNS_RENAME_MAP) |
|
|
|
return renamed.drop(columns=COLUMNS_TO_DROP) |
|
|
|
surplus_columns = set(renamed.columns) - RAW_DATA_COLUMN_SET |
|
|
|
|
|
|
|
return renamed.drop(columns=surplus_columns) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def parse_file(data_file): |
|
|
|
def parse_file(data_file): |
|
|
|
""" parses one data file and adds metadata to result """ |
|
|
|
""" parses one data file and adds metadata to result """ |
|
|
|
measurement_info = _extract_measurement_info(Path(data_file)) |
|
|
|
try: |
|
|
|
|
|
|
|
measurement_info = _extract_measurement_info(Path(data_file)) |
|
|
|
|
|
|
|
except ValueError as e: |
|
|
|
|
|
|
|
return None |
|
|
|
data_frame = _parse_csv(data_file) |
|
|
|
data_frame = _parse_csv(data_file) |
|
|
|
data_frame[COL_NAME_WELL_ROW] = measurement_info.row |
|
|
|
data_frame[COL_NAME_WELL_ROW] = measurement_info.row |
|
|
|
data_frame[COL_NAME_WELL_COLUMN] = measurement_info.column |
|
|
|
data_frame[COL_NAME_WELL_COLUMN] = measurement_info.column |
|
|
@ -98,8 +103,9 @@ def parse_multiple_files(file_list): |
|
|
|
if not file_list: |
|
|
|
if not file_list: |
|
|
|
raise ValueError("Empty file list provided") |
|
|
|
raise ValueError("Empty file list provided") |
|
|
|
collection = (parse_file(path) for path in file_list) |
|
|
|
collection = (parse_file(path) for path in file_list) |
|
|
|
data_frame = next(collection) |
|
|
|
filtered = (frame for frame in collection if frame is not None) |
|
|
|
for next_frame in collection: |
|
|
|
data_frame = next(filtered) |
|
|
|
|
|
|
|
for next_frame in filtered: |
|
|
|
data_frame = data_frame.append(next_frame, ignore_index=True) |
|
|
|
data_frame = data_frame.append(next_frame, ignore_index=True) |
|
|
|
data_frame[COL_NAME_WELL_ROW] = data_frame[COL_NAME_WELL_ROW].astype( |
|
|
|
data_frame[COL_NAME_WELL_ROW] = data_frame[COL_NAME_WELL_ROW].astype( |
|
|
|
"category" |
|
|
|
"category" |
|
|
|