Skip to content

Commit 6ec4f38

Browse files
committed
Moved LIF and TIFF registration Pydantic models to the files where they're used
1 parent 0067b6d commit 6ec4f38

File tree

2 files changed

+37
-37
lines changed

2 files changed

+37
-37
lines changed

src/murfey/util/models.py

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
from __future__ import annotations
22

3-
from ast import literal_eval
43
from datetime import datetime
54
from pathlib import Path
65
from typing import Any, Dict, List, Optional
76

8-
from pydantic import BaseModel, validator
7+
from pydantic import BaseModel
98

109
"""
1110
General Models
@@ -161,40 +160,6 @@ class TIFFSeriesInfo(BaseModel):
161160
series_metadata: Path
162161

163162

164-
class LIFPreprocessingResult(BaseModel):
165-
image_stack: Path
166-
metadata: Path
167-
series_name: str
168-
channel: str
169-
number_of_members: int
170-
parent_lif: Path
171-
172-
173-
class TIFFPreprocessingResult(BaseModel):
174-
image_stack: Path
175-
metadata: Path
176-
series_name: str
177-
channel: str
178-
number_of_members: int
179-
parent_tiffs: list[Path]
180-
181-
@validator(
182-
"parent_tiffs",
183-
pre=True,
184-
)
185-
def parse_stringified_list(cls, value):
186-
if isinstance(value, str):
187-
try:
188-
eval_result = literal_eval(value)
189-
if isinstance(eval_result, list):
190-
parent_tiffs = [Path(p) for p in eval_result]
191-
return parent_tiffs
192-
except (SyntaxError, ValueError):
193-
raise ValueError("Unable to parse input")
194-
# Return value as-is; if it fails, it fails
195-
return value
196-
197-
198163
"""
199164
FIB
200165
===

src/murfey/workflows/clem/register_preprocessing_results.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import logging
1212
import re
1313
import traceback
14+
from ast import literal_eval
1415
from pathlib import Path
1516
from typing import Optional, Type, Union
1617

18+
from pydantic import BaseModel, validator
1719
from sqlalchemy.exc import NoResultFound
1820
from sqlmodel import Session, select
1921

@@ -27,7 +29,6 @@
2729
CLEMTIFFFile,
2830
)
2931
from murfey.util.db import Session as MurfeySession
30-
from murfey.util.models import LIFPreprocessingResult, TIFFPreprocessingResult
3132
from murfey.workflows.clem.align_and_merge import submit_cluster_request
3233

3334
logger = logging.getLogger("murfey.workflows.clem.register_results")
@@ -194,6 +195,15 @@ def get_db_entry(
194195
return db_entry
195196

196197

198+
class LIFPreprocessingResult(BaseModel):
199+
image_stack: Path
200+
metadata: Path
201+
series_name: str
202+
channel: str
203+
number_of_members: int
204+
parent_lif: Path
205+
206+
197207
def register_lif_preprocessing_result(
198208
message: dict, db: Session, demo: bool = False
199209
) -> bool:
@@ -362,6 +372,31 @@ def register_lif_preprocessing_result(
362372
db.close()
363373

364374

375+
class TIFFPreprocessingResult(BaseModel):
376+
image_stack: Path
377+
metadata: Path
378+
series_name: str
379+
channel: str
380+
number_of_members: int
381+
parent_tiffs: list[Path]
382+
383+
@validator(
384+
"parent_tiffs",
385+
pre=True,
386+
)
387+
def parse_stringified_list(cls, value):
388+
if isinstance(value, str):
389+
try:
390+
eval_result = literal_eval(value)
391+
if isinstance(eval_result, list):
392+
parent_tiffs = [Path(p) for p in eval_result]
393+
return parent_tiffs
394+
except (SyntaxError, ValueError):
395+
raise ValueError("Unable to parse input")
396+
# Return value as-is; if it fails, it fails
397+
return value
398+
399+
365400
def register_tiff_preprocessing_result(
366401
message: dict, db: Session, demo: bool = False
367402
) -> bool:

0 commit comments

Comments
 (0)