Skip to content

Commit 9c71754

Browse files
committed
refactor: validate batch in loop
Signed-off-by: Josh Loecker <joshloecker@icloud.com>
1 parent 1219cc4 commit 9c71754

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

main/como/merge_xomics.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,16 @@ def _build_batches(
513513
continue
514514

515515
metadata: pd.DataFrame # Re-assign type to assist in type hinting
516-
for batch_num, study in enumerate(sorted(metadata["study"].unique()), start=1):
516+
for study in sorted(metadata["study"].unique()):
517+
batch_search = re.search(r"\d+", study)
518+
if not batch_search:
519+
_log_and_raise_error(
520+
message=f"Unable to find batch number in study name. Expected a digit in the study value: {study}",
521+
error=ValueError,
522+
level=LogLevel.ERROR,
523+
)
524+
525+
batch_num = int(batch_search.group(0)) # ty: ignore[possibly-missing-attribute]
517526
study_sample_names = metadata[metadata["study"] == study]["sample_name"].tolist()
518527
batch_names[source.value].append(_BatchEntry(batch_num=batch_num, sample_names=study_sample_names))
519528
logger.debug(f"Found {len(study_sample_names)} sample names for study '{study}', batch number {batch_num}")

0 commit comments

Comments
 (0)