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 @@ -166,13 +166,22 @@ def _create_melt_curve_data_cube(

def _create_measurement(well: Well, well_item: WellItem, data: Data) -> Measurement:
header = data.header
multicomponent = well.multicomponent_data
reporter_dye = well_item.reporter_dye_setting
passive_dye = header.passive_reference_dye_setting
# Only request dye columns that actually exist in multicomponent data
if multicomponent is not None:
if reporter_dye is not None and reporter_dye not in multicomponent.columns:
reporter_dye = None
if passive_dye is not None and passive_dye not in multicomponent.columns:
passive_dye = None
(
reporter_dye_data_cube,
passive_reference_dye_data_cube,
) = _create_multicomponent_data_cubes(
well.multicomponent_data,
well_item.reporter_dye_setting,
header.passive_reference_dye_setting,
multicomponent,
reporter_dye,
passive_dye,
)
return Measurement(
identifier=well_item.uuid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def sniff(cls, named_file_contents: NamedFileContents) -> bool:
)
sheet_names = set(wb.sheetnames)
wb.close()
return "Results" in sheet_names
return "Results" in sheet_names or "Primary_result" in sheet_names
except Exception:
return False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
assert_not_none,
)

RESULTS_SHEET = "Results"
PRIMARY_RESULT_SHEET = "Primary_result"


class DesignQuantstudioReader:
SUPPORTED_EXTENSIONS = "xlsx,xls"
Expand All @@ -36,12 +39,14 @@ def create(named_file_contents: NamedFileContents) -> DesignQuantstudioReader:

def __init__(self, contents: dict[str, pd.DataFrame]) -> None:
self.contents = contents
if PRIMARY_RESULT_SHEET in contents and RESULTS_SHEET not in contents:
contents[RESULTS_SHEET] = contents.pop(PRIMARY_RESULT_SHEET)
self.header = self._get_header(contents)
self.data = self._get_data(contents)

def _get_header(self, contents: dict[str, pd.DataFrame]) -> SeriesData:
sheet = assert_not_none(
contents.get("Results"),
contents.get(RESULTS_SHEET),
msg="Unable to find 'Results' sheet.",
)
df, _ = split_header_and_data(sheet, lambda row: row[0] is None)
Expand All @@ -52,8 +57,29 @@ def _get_data(self, contents: dict[str, pd.DataFrame]) -> dict[str, pd.DataFrame
for name, sheet in contents.items():
_, data = split_header_and_data(sheet, lambda row: row[0] is None)
data_structure[name] = parse_header_row(data.replace(np.nan, None))
self._normalize_well_columns(data_structure)
return data_structure

def _normalize_well_columns(self, data_structure: dict[str, pd.DataFrame]) -> None:
results = data_structure.get(RESULTS_SHEET)
if results is None or "Well" not in results.columns:
return
first_well = results["Well"].iloc[0] if not results.empty else None
if first_well is None or isinstance(first_well, int | float):
return
# Alphanumeric wells — build a stable numeric mapping and add Well Position
all_wells: list[str] = []
for df in data_structure.values():
if "Well" in df.columns:
all_wells.extend(df["Well"].dropna().unique().tolist())
unique_wells = sorted({str(w) for w in all_wells})
well_to_id = {well: idx + 1 for idx, well in enumerate(unique_wells)}
for df in data_structure.values():
if "Well" in df.columns:
if "Well Position" not in df.columns:
df.insert(1, "Well Position", df["Well"].astype(str))
df["Well"] = df["Well"].map(well_to_id)

def has_sheet(self, sheet_name: str) -> bool:
return sheet_name in self.data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ def create(header: SeriesData) -> Header:
software_name, software_version = (
(software_info.group(1), software_info.group(2))
if software_info
else (None, None)
else (
header.get(str, "Software name"),
header.get(str, "Software version"),
)
)

stage_number_raw = header.get(str, "PCR Stage/Step Number", "")
Expand Down
Loading
Loading