Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
Data,
Mapper,
)
from allotropy.constants import CHARDET_ENCODING
from allotropy.named_file_contents import NamedFileContents
from allotropy.parsers.lines_reader import CsvReader, read_to_lines
from allotropy.parsers.moldev_softmax_pro.softmax_pro_data_creator import (
Expand Down Expand Up @@ -48,6 +49,12 @@ def sniff(cls, named_file_contents: NamedFileContents) -> bool:
return False

def create_data(self, named_file_contents: NamedFileContents) -> Data:
if named_file_contents.encoding is None:
named_file_contents = NamedFileContents(
named_file_contents.contents,
named_file_contents.original_file_path,
CHARDET_ENCODING,
)
lines = read_to_lines(named_file_contents)
reader = CsvReader(lines)
data = StructureData.create(reader)
Expand Down
53 changes: 27 additions & 26 deletions src/allotropy/parsers/moldev_softmax_pro/softmax_pro_structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from abc import ABC
from collections.abc import Iterator
from dataclasses import dataclass, field
from datetime import datetime
from enum import Enum
import math
import re
Expand Down Expand Up @@ -65,14 +64,25 @@ def num_wells_to_n_columns(well_count: int) -> int:


def time_to_seconds(time: str) -> float:
"""Transforms HH:MM:SS formatted time into seconds"""
try:
pt = datetime.strptime(time, "%H:%M:%S").astimezone()
except ValueError as e:
msg = "Bad time formatting, expected HH:MM:SS, got {time}"
raise AllotropeConversionError(msg) from e

return pt.hour * 3600 + pt.minute * 60 + pt.second
"""Transforms time string into seconds. Supports H:MM:SS, HH:MM:SS, and M:SS formats."""
parts = time.split(":")
if len(parts) == 3:
try:
h, m, s = int(parts[0]), int(parts[1]), int(parts[2])
return h * 3600 + m * 60 + s
except ValueError as e:
msg = f"Bad time formatting, expected HH:MM:SS, got {time}"
raise AllotropeConversionError(msg) from e
elif len(parts) == 2:
Comment thread
nathan-stender marked this conversation as resolved.
try:
m, s = int(parts[0]), int(parts[1])
return m * 60 + s
except ValueError as e:
msg = f"Bad time formatting, expected MM:SS, got {time}"
raise AllotropeConversionError(msg) from e
else:
msg = f"Bad time formatting, expected HH:MM:SS or MM:SS, got {time}"
raise AllotropeConversionError(msg)


class ReadType(Enum):
Expand Down Expand Up @@ -256,10 +266,8 @@ def create(reader: CsvReader) -> GroupData:
# We are doing 1 for now, but we should check
data = data.dropna(axis=1, how="all")

assert_not_none(
data.get("Sample"),
msg=f"Unable to find sample identifier column in group data {name}",
)
if data.empty or data.get("Sample") is None:
return GroupData(name=name, sample_data=[])

calc_data_cols = GroupData.get_calculated_data_columns(data)

Expand Down Expand Up @@ -296,18 +304,10 @@ class GroupColumns:

@staticmethod
def create(reader: CsvReader) -> GroupColumns:
data = assert_not_none(
reader.pop_csv_block_as_df(sep="\t", header=0),
msg="Unable to find group block columns.",
)

if "Formula Name" not in data:
msg = "Unable to find 'Formula Name' in group block columns."
raise AllotropeConversionError(msg)
data = reader.pop_csv_block_as_df(sep="\t", header=0)

if "Formula" not in data:
msg = "Unable to find 'Formula' in group block columns."
raise AllotropeConversionError(msg)
if data is None or "Formula Name" not in data or "Formula" not in data:
return GroupColumns(data={})

return GroupColumns(
data=dict(zip(data["Formula Name"], data["Formula"], strict=True)),
Expand Down Expand Up @@ -430,8 +430,7 @@ def create(
for position, raw_value in data.items():
value = try_non_nan_float_or_none(raw_value)
if value is None and elapsed_time is not None:
msg = f"Missing kinetic measurement for well position {position} at {elapsed_time}s."
raise AllotropeConversionError(msg)
continue
data_elements[str(position)] = DataElement(
uuid=random_uuid_str(),
plate=header.name,
Expand Down Expand Up @@ -459,6 +458,8 @@ def update_kinetic_data_elements(
for col, raw_value in zip(df_data.columns, row_data, strict=True)
}
for position, value in data.items():
if position not in self.data_elements:
continue
if value is None:
msg = f"Missing kinetic measurement for well position {position} at {elapsed_time}s."
raise AllotropeConversionError(msg)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ foo bar baz

Plate: Plate1 1.3 PlateFormat Kinetic Fluorescence FALSE Raw FALSE 4 120 90 1 525 1 3 6 485 Automatic 515 6 Medium 1 2
Temperature(¡C) 1 2 3
00:00:00 35 NaN 0 0
00:00:00 35 1.5 0 0
0 0 0

00:01:30 35 39.50988 20.26845 10.26596
00:01:30 35 NaN 20.26845 10.26596
41.66635 21.40594 10.85013

1 2 3
Expand Down
Loading
Loading