Skip to content

Commit 037fd46

Browse files
2 parents c907786 + b619d74 commit 037fd46

File tree

3 files changed

+65
-71
lines changed

3 files changed

+65
-71
lines changed

preprocessor/cellstar_preprocessor/preprocess.py

+33-64
Original file line numberDiff line numberDiff line change
@@ -560,19 +560,19 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
560560
tasks = []
561561
nii_segmentation_inputs: list[NIISegmentationInput] = []
562562
mask_segmentation_inputs: list[MaskInput] = []
563-
for input in inputs:
564-
if isinstance(input, ExtraDataInput):
563+
for i in inputs:
564+
if isinstance(i, ExtraDataInput):
565565
tasks.append(
566566
ProcessExtraDataTask(
567-
path=input.input_path,
567+
path=i.input_path,
568568
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
569569
)
570570
)
571-
elif isinstance(input, MAPInput):
571+
elif isinstance(i, MAPInput):
572572
self.store_internal_volume(
573573
internal_volume=InternalVolume(
574574
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
575-
volume_input_path=input.input_path,
575+
volume_input_path=i.input_path,
576576
params_for_storing=self.preprocessor_input.storing_params,
577577
volume_force_dtype=self.preprocessor_input.volume.force_volume_dtype,
578578
quantize_dtype_str=self.preprocessor_input.volume.quantize_dtype_str,
@@ -589,11 +589,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
589589
internal_volume=self.get_internal_volume()
590590
)
591591
)
592-
elif isinstance(input, SFFInput):
592+
elif isinstance(i, SFFInput):
593593
self.store_internal_segmentation(
594594
internal_segmentation=InternalSegmentation(
595595
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
596-
segmentation_input_path=input.input_path,
596+
segmentation_input_path=i.input_path,
597597
params_for_storing=self.preprocessor_input.storing_params,
598598
downsampling_parameters=self.preprocessor_input.downsampling,
599599
entry_data=self.preprocessor_input.entry_data,
@@ -615,33 +615,14 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
615615
)
616616
)
617617

618-
elif isinstance(input, MaskInput):
619-
mask_segmentation_inputs.append(input)
620-
# self.store_internal_segmentation(
621-
# internal_segmentation=InternalSegmentation(
622-
# intermediate_zarr_structure_path=self.intermediate_zarr_structure,
623-
# segmentation_input_path=input.input_path,
624-
# params_for_storing=self.preprocessor_input.storing_params,
625-
# downsampling_parameters=self.preprocessor_input.downsampling,
626-
# entry_data=self.preprocessor_input.entry_data,
627-
# )
628-
# )
629-
# tasks.append(
630-
# MaskProcessSegmentationTask(
631-
# internal_segmentation=self.get_internal_segmentation()
632-
# )
633-
# )
634-
# tasks.append(
635-
# MaskMetadataCollectionTask(
636-
# internal_segmentation=self.get_internal_segmentation()
637-
# )
638-
# )
639-
640-
elif isinstance(input, OMEZARRInput):
618+
elif isinstance(i, MaskInput):
619+
mask_segmentation_inputs.append(i)
620+
621+
elif isinstance(i, OMEZARRInput):
641622
self.store_internal_volume(
642623
internal_volume=InternalVolume(
643624
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
644-
volume_input_path=input.input_path,
625+
volume_input_path=i.input_path,
645626
params_for_storing=self.preprocessor_input.storing_params,
646627
volume_force_dtype=self.preprocessor_input.volume.force_volume_dtype,
647628
quantize_dtype_str=self.preprocessor_input.volume.quantize_dtype_str,
@@ -657,7 +638,7 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
657638
self.store_internal_segmentation(
658639
internal_segmentation=InternalSegmentation(
659640
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
660-
segmentation_input_path=input.input_path,
641+
segmentation_input_path=i.input_path,
661642
params_for_storing=self.preprocessor_input.storing_params,
662643
downsampling_parameters=self.preprocessor_input.downsampling,
663644
entry_data=self.preprocessor_input.entry_data,
@@ -676,11 +657,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
676657
OMEZARRAnnotationsCollectionTask(self.get_internal_volume())
677658
)
678659

679-
elif isinstance(input, GeometricSegmentationInput):
660+
elif isinstance(i, GeometricSegmentationInput):
680661
self.store_internal_segmentation(
681662
internal_segmentation=InternalSegmentation(
682663
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
683-
segmentation_input_path=input.input_path,
664+
segmentation_input_path=i.input_path,
684665
params_for_storing=self.preprocessor_input.storing_params,
685666
downsampling_parameters=self.preprocessor_input.downsampling,
686667
entry_data=self.preprocessor_input.entry_data,
@@ -689,11 +670,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
689670
tasks.append(
690671
ProcessGeometricSegmentationTask(self.get_internal_segmentation())
691672
)
692-
elif isinstance(input, OMETIFFImageInput):
673+
elif isinstance(i, OMETIFFImageInput):
693674
self.store_internal_volume(
694675
internal_volume=InternalVolume(
695676
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
696-
volume_input_path=input.input_path,
677+
volume_input_path=i.input_path,
697678
params_for_storing=self.preprocessor_input.storing_params,
698679
volume_force_dtype=self.preprocessor_input.volume.force_volume_dtype,
699680
quantize_dtype_str=self.preprocessor_input.volume.quantize_dtype_str,
@@ -718,11 +699,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
718699
internal_volume=self.get_internal_volume()
719700
)
720701
)
721-
elif isinstance(input, OMETIFFSegmentationInput):
702+
elif isinstance(i, OMETIFFSegmentationInput):
722703
self.store_internal_segmentation(
723704
internal_segmentation=InternalSegmentation(
724705
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
725-
segmentation_input_path=input.input_path,
706+
segmentation_input_path=i.input_path,
726707
params_for_storing=self.preprocessor_input.storing_params,
727708
downsampling_parameters=self.preprocessor_input.downsampling,
728709
entry_data=self.preprocessor_input.entry_data,
@@ -741,11 +722,11 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
741722
internal_segmentation=self.get_internal_segmentation()
742723
)
743724
)
744-
elif isinstance(input, NIIVolumeInput):
725+
elif isinstance(i, NIIVolumeInput):
745726
self.store_internal_volume(
746727
internal_volume=InternalVolume(
747728
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
748-
volume_input_path=input.input_path,
729+
volume_input_path=i.input_path,
749730
params_for_storing=self.preprocessor_input.storing_params,
750731
volume_force_dtype=self.preprocessor_input.volume.force_volume_dtype,
751732
quantize_dtype_str=self.preprocessor_input.volume.quantize_dtype_str,
@@ -763,31 +744,12 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
763744
)
764745
)
765746

766-
elif isinstance(input, NIISegmentationInput):
767-
nii_segmentation_inputs.append(input)
768-
# self.store_internal_segmentation(
769-
# internal_segmentation=InternalSegmentation(
770-
# intermediate_zarr_structure_path=self.intermediate_zarr_structure,
771-
# segmentation_input_path=input.input_path,
772-
# params_for_storing=self.preprocessor_input.storing_params,
773-
# downsampling_parameters=self.preprocessor_input.downsampling,
774-
# entry_data=self.preprocessor_input.entry_data,
775-
# )
776-
# )
777-
# tasks.append(
778-
# NIIProcessSegmentationTask(
779-
# internal_segmentation=self.get_internal_segmentation()
780-
# )
781-
# )
782-
# tasks.append(
783-
# NIISegmentationMetadataCollectionTask(
784-
# internal_segmentation=self.get_internal_segmentation()
785-
# )
786-
# )
787-
elif isinstance(input, CustomAnnotationsInput):
747+
elif isinstance(i, NIISegmentationInput):
748+
nii_segmentation_inputs.append(i)
749+
elif isinstance(i, CustomAnnotationsInput):
788750
tasks.append(
789751
CustomAnnotationsCollectionTask(
790-
input_path=input.input_path,
752+
input_path=i.input_path,
791753
intermediate_zarr_structure_path=self.intermediate_zarr_structure,
792754
)
793755
)
@@ -854,7 +816,7 @@ def _process_inputs(self, inputs: list[InputT]) -> list[TaskBase]:
854816
)
855817
)
856818

857-
if any(isinstance(input, GeometricSegmentationInput) for input in inputs):
819+
if any(isinstance(i, GeometricSegmentationInput) for i in inputs):
858820
# tasks.append(SaveGeometricSegmentationSets(self.intermediate_zarr_structure))
859821
tasks.append(
860822
GeometricSegmentationAnnotationsCollectionTask(
@@ -876,10 +838,17 @@ def _execute_tasks(self, tasks: list[TaskBase]):
876838
for task in tasks:
877839
task.execute()
878840

841+
def __check_if_inputs_exists(self, raw_inputs_list: list[tuple[Path, InputKind]]):
842+
for input_item in raw_inputs_list:
843+
p = input_item[0]
844+
assert p.exists(), f'Input file {p} does not exist'
845+
879846
def _analyse_preprocessor_input(self) -> list[InputT]:
880847
raw_inputs_list = self.preprocessor_input.inputs.files
881848
analyzed_inputs: list[InputT] = []
882849

850+
self.__check_if_inputs_exists(raw_inputs_list)
851+
883852
for input_item in raw_inputs_list:
884853
if input_item[1] == InputKind.extra_data:
885854
analyzed_inputs.append(ExtraDataInput(input_path=input_item[0]))

preprocessor/cellstar_preprocessor/tools/deploy_api/deploy_api.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def parse_script_args():
2727
parser.add_argument("--db_path", type=str, default=DEFAULT_DB_PATH, help='path to db folder')
2828
parser.add_argument("--api_port", type=str, help='api port', default=DEFAULT_PORT,)
2929
parser.add_argument("--api_hostname", type=str, default=DEFAULT_HOST, help='default host')
30-
30+
parser.add_argument("--ssl-keyfile", type=str)
31+
parser.add_argument("--ssl-certfile", type=str)
3132
args=parser.parse_args()
3233
return args
3334

@@ -57,11 +58,20 @@ def run_api(args):
5758

5859
if args.api_port:
5960
deploy_env['PORT'] = args.api_port
60-
6161
lst = [
62-
"python", "serve.py"
62+
"python", "serve.py",
6363
]
6464

65+
if args.ssl_certfile and args.ssl_keyfile:
66+
lst.extend(
67+
[
68+
"--ssl_keyfile",
69+
str(Path(args.ssl_keyfile).resolve()),
70+
"--ssl_certfile",
71+
str(Path(args.ssl_certfile).resolve())
72+
]
73+
)
74+
6575
api_process = subprocess.Popen(lst, env=deploy_env, cwd='server/cellstar_server/')
6676
PROCESS_IDS_LIST.append(api_process.pid)
6777
print(f'API is running with args {vars(args)}')

server/cellstar_server/serve.py

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
1+
import argparse
2+
from pathlib import Path
13
import uvicorn
24
from cellstar_server.app.settings import settings
35

46
if __name__ == "__main__":
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("--ssl_keyfile", type=str)
9+
parser.add_argument("--ssl_certfile", type=str)
10+
args = parser.parse_args()
11+
512
print("Mol* Volume Server")
613
print(settings.dict())
7-
8-
uvicorn.run(
9-
app="main:app", host=settings.HOST, port=settings.PORT, reload=settings.DEV_MODE
10-
)
14+
if args.ssl_certfile and args.ssl_keyfile:
15+
uvicorn.run(
16+
app="main:app", host=settings.HOST, port=settings.PORT, reload=settings.DEV_MODE,
17+
ssl_keyfile=str(Path(args.ssl_keyfile).resolve()),
18+
ssl_certfile=str(Path(args.ssl_certfile).resolve())
19+
)
20+
if not args.ssl_certfile and not args.ssl_keyfile:
21+
uvicorn.run(
22+
app="main:app", host=settings.HOST, port=settings.PORT, reload=settings.DEV_MODE
23+
)
24+
else:
25+
print("ssl_certfile or ssl_keyfile was not provided")

0 commit comments

Comments
 (0)