Skip to content

Commit bc72b93

Browse files
committed
Try and fix clem calls
1 parent a837000 commit bc72b93

File tree

1 file changed

+37
-27
lines changed

1 file changed

+37
-27
lines changed

src/murfey/server/api/clem.py

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,25 @@ def get_db_entry(
196196
"""
197197

198198

199+
class LifInfo(BaseModel):
200+
lif_file: Path
201+
master_metadata: Optional[Path] = None
202+
child_metadata: list[Path] = []
203+
child_series: list[str] = []
204+
child_stacks: list[Path] = []
205+
206+
207+
class TiffInfo(BaseModel):
208+
tiff_file: Path
209+
associated_metadata: Optional[Path] = None
210+
associated_series: Optional[str] = None
211+
associated_stack: Optional[Path] = None
212+
213+
199214
@router.post("/sessions/{session_id}/clem/lif_files")
200215
def register_lif_file(
201-
lif_file: Path,
216+
lif_file: LifInfo,
202217
session_id: int,
203-
master_metadata: Optional[Path] = None,
204-
child_metadata: list[Path] = [],
205-
child_series: list[str] = [],
206-
child_stacks: list[Path] = [],
207218
db: Session = murfey_db,
208219
):
209220
# Return or register the LIF file entry
@@ -212,7 +223,7 @@ def register_lif_file(
212223
db=db,
213224
table=CLEMLIFFile,
214225
session_id=session_id,
215-
file_path=lif_file,
226+
file_path=lif_file.lif_file,
216227
)
217228
except Exception:
218229
logger.error(
@@ -223,9 +234,11 @@ def register_lif_file(
223234
return False
224235

225236
# Add metadata information if provided
226-
if master_metadata is not None:
237+
if lif_file.master_metadata is not None:
227238
try:
228-
master_metadata = validate_and_sanitise(master_metadata, session_id, db)
239+
master_metadata = validate_and_sanitise(
240+
lif_file.master_metadata, session_id, db
241+
)
229242
clem_lif_file.master_metadata = str(master_metadata)
230243
except Exception:
231244
logger.warning(
@@ -235,7 +248,7 @@ def register_lif_file(
235248
)
236249

237250
# Register child metadata if provided
238-
for metadata in child_metadata:
251+
for metadata in lif_file.child_metadata:
239252
try:
240253
metadata_db_entry: CLEMImageMetadata = get_db_entry(
241254
db=db,
@@ -255,7 +268,7 @@ def register_lif_file(
255268
continue
256269

257270
# Register child image series if provided
258-
for series in child_series:
271+
for series in lif_file.child_series:
259272
try:
260273
series_db_entry: CLEMImageSeries = get_db_entry(
261274
db=db,
@@ -275,7 +288,7 @@ def register_lif_file(
275288
continue
276289

277290
# Register child image stacks if provided
278-
for stack in child_stacks:
291+
for stack in lif_file.child_stacks:
279292
try:
280293
stack_db_entry: CLEMImageStack = get_db_entry(
281294
db=db,
@@ -303,11 +316,8 @@ def register_lif_file(
303316

304317
@router.post("/sessions/{session_id}/clem/tiff_files")
305318
def register_tiff_file(
306-
tiff_file: Path,
319+
tiff_file: TiffInfo,
307320
session_id: int,
308-
associated_metadata: Optional[Path] = None,
309-
associated_series: Optional[str] = None,
310-
associated_stack: Optional[Path] = None,
311321
db: Session = murfey_db,
312322
):
313323
# Get or register the database entry
@@ -316,7 +326,7 @@ def register_tiff_file(
316326
db=db,
317327
table=CLEMTIFFFile,
318328
session_id=session_id,
319-
file_path=tiff_file,
329+
file_path=tiff_file.tiff_file,
320330
)
321331
except Exception:
322332
logger.error(
@@ -327,58 +337,58 @@ def register_tiff_file(
327337
return False
328338

329339
# Add metadata if provided
330-
if associated_metadata is not None:
340+
if tiff_file.associated_metadata is not None:
331341
try:
332342
metadata_db_entry: CLEMImageMetadata = get_db_entry(
333343
db=db,
334344
table=CLEMImageMetadata,
335345
session_id=session_id,
336-
file_path=associated_metadata,
346+
file_path=tiff_file.associated_metadata,
337347
)
338348
# Link database entries
339349
clem_tiff_file.associated_metadata = metadata_db_entry
340350
except Exception:
341351
logger.warning(
342352
"Unable to register "
343-
f"metadata file {sanitise(str(associated_metadata))!r} in association with "
353+
f"metadata file {sanitise(str(tiff_file.associated_metadata))!r} in association with "
344354
f"TIFF file {sanitise(str(tiff_file))!r}: \n"
345355
f"{traceback.format_exc()}"
346356
)
347357

348358
# Add series information if provided
349-
if associated_series is not None:
359+
if tiff_file.associated_series is not None:
350360
try:
351361
series_db_entry: CLEMImageSeries = get_db_entry(
352362
db=db,
353363
table=CLEMImageSeries,
354364
session_id=session_id,
355-
series_name=associated_series,
365+
series_name=tiff_file.associated_series,
356366
)
357367
# Link database entries
358368
clem_tiff_file.child_series = series_db_entry
359369
except Exception:
360370
logger.warning(
361371
"Unable to register "
362-
f"CLEM series {sanitise(associated_series)!r} in association with "
372+
f"CLEM series {sanitise(tiff_file.associated_series)!r} in association with "
363373
f"TIFF file {sanitise(str(tiff_file))!r}: \n"
364374
f"{traceback.format_exc()}"
365375
)
366376

367377
# Add image stack information if provided
368-
if associated_stack is not None:
378+
if tiff_file.associated_stack is not None:
369379
try:
370380
stack_db_entry: CLEMImageStack = get_db_entry(
371381
db=db,
372382
table=CLEMImageStack,
373383
session_id=session_id,
374-
file_path=associated_stack,
384+
file_path=tiff_file.associated_stack,
375385
)
376386
# Link database entries
377387
clem_tiff_file.child_stack = stack_db_entry
378388
except Exception:
379389
logger.warning(
380390
"Unable to register "
381-
f"image stack {sanitise(str(associated_stack))!r} in association with "
391+
f"image stack {sanitise(str(tiff_file.associated_stack))!r} in association with "
382392
f"{traceback.format_exc()}"
383393
)
384394

@@ -737,7 +747,7 @@ def register_image_stack(
737747
) # API posts to this URL
738748
def process_raw_lifs(
739749
session_id: int,
740-
lif_file: Path,
750+
lif_file: LifInfo,
741751
db: Session = murfey_db,
742752
):
743753
try:
@@ -759,7 +769,7 @@ def process_raw_lifs(
759769
# Pass arguments along to the correct workflow
760770
workflow.load()(
761771
# Match the arguments found in murfey.workflows.clem.process_raw_lifs
762-
file=lif_file,
772+
file=lif_file.lif_file,
763773
root_folder="images",
764774
session_id=session_id,
765775
instrument_name=instrument_name,

0 commit comments

Comments
 (0)