Skip to content

Commit b3fd38e

Browse files
committed
Begin generalization to multi-folder image parsing (not complete in fractal_cmd.py)
1 parent b1525dc commit b3fd38e

File tree

3 files changed

+45
-37
lines changed

3 files changed

+45
-37
lines changed

fractal/fractal_cmd.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -391,31 +391,34 @@ def workflow_add_task(project_name, workflow_name, tasks):
391391
@click.argument("workflow_name", required=True, nargs=1)
392392
@click.argument("input_dataset", required=True, nargs=1)
393393
@click.argument("output_dataset", required=True, nargs=1)
394-
@click.argument("resource_in", required=True, nargs=1)
394+
@click.argument("resources_in", required=True, nargs=-1)
395395
@click.argument("resource_out", required=True, nargs=1)
396396
@click.argument("json_worker_params", required=True, nargs=1)
397397
def workflow_apply(
398398
project_name,
399399
workflow_name,
400400
input_dataset,
401401
output_dataset,
402-
resource_in,
402+
resources_in,
403403
resource_out,
404404
json_worker_params,
405405
):
406406

407-
resource_in = add_slash_to_path(resource_in)
407+
resources_in = [
408+
add_slash_to_path(resource_in) for resource_in in resources_in
409+
]
408410
resource_out = add_slash_to_path(resource_out)
409411

410412
prj, _ = project_file_load(project_name)
411413

412-
# Verify that resource_in has been added to the resources of input_dataset
414+
# Verify that resources_in has been added to the resources of input_dataset
413415
dataset_resources = prj["datasets"][input_dataset]["resources"]
414-
if resource_in not in dataset_resources:
415-
raise Exception(
416-
f"Error in workflow_apply, {resource_in} not in"
417-
f" {dataset_resources}"
418-
)
416+
for resource_in in resources_in:
417+
if resource_in not in dataset_resources:
418+
raise Exception(
419+
f"Error in workflow_apply, {resource_in} not in"
420+
f" {dataset_resources}"
421+
)
419422

420423
# If the resource_out folder is not there, create it
421424
path_resource_out = Path(resource_out)
@@ -481,8 +484,7 @@ def collect_intermediate_results(inputs=[]):
481484
"create_zarr_structure_multifov",
482485
]:
483486
kwargs = dict(
484-
# FIXME : add support for a list!
485-
in_paths=[resource_in],
487+
in_paths=resources_in,
486488
out_path=resource_out,
487489
ext=ext,
488490
num_levels=num_levels,
@@ -496,14 +498,15 @@ def app_create_zarr_structure(**kwargs_):
496498
return dict_tasks[task_names[0]](**kwargs)
497499

498500
future = app_create_zarr_structure(**kwargs)
501+
499502
if task_names[0] == "create_zarr_structure":
500-
zarrurls, channels = future.result()
503+
zarrurls, chl_list = future.result()
501504
debug(zarrurls)
502-
debug(channels)
505+
debug(chl_list)
503506
elif task_names[0] == "create_zarr_structure_multifov":
504-
zarrurls, channels, sites_list = future.result()
507+
zarrurls, chl_list, sites_list = future.result()
505508
debug(zarrurls)
506-
debug(channels)
509+
debug(chl_list)
507510
debug(sites_list)
508511
task_names = task_names[1:] # FIXME
509512
else:
@@ -514,25 +517,32 @@ def app_create_zarr_structure(**kwargs_):
514517
# Tasks 1,2,...
515518
db = db_load()
516519
for task in task_names:
520+
if len(resources_in) > 1:
521+
raise Exception(
522+
"ERROR\n"
523+
"Support for len(resources_in)>1 is not there.\n"
524+
"Hint: we should modify the in_path argument of"
525+
"yokogawa_to_zarr."
526+
)
517527

518528
if task == "yokogawa_to_zarr":
519529
kwargs = dict(
520-
in_path=resource_in,
530+
in_path=resources_in[0], # FIXME
521531
ext=ext,
522532
delete_input=delete_input,
523533
rows=rows,
524534
cols=cols,
525-
channels=channels,
535+
chl_list=chl_list,
526536
num_levels=num_levels,
527537
coarsening_xy=coarsening_xy,
528538
coarsening_z=coarsening_z,
529539
)
530540
if task == "yokogawa_to_zarr_multifov":
531541
kwargs = dict(
532-
in_path=resource_in,
542+
in_path=resources_in[0], # FIXME
533543
ext=ext,
534544
delete_input=delete_input,
535-
channels=channels,
545+
chl_list=chl_list,
536546
sites_list=sites_list,
537547
num_levels=num_levels,
538548
coarsening_xy=coarsening_xy,
@@ -541,7 +551,6 @@ def app_create_zarr_structure(**kwargs_):
541551

542552
elif task == "maximum_intensity_projection":
543553
kwargs = dict(
544-
channels=channels,
545554
coarsening_xy=coarsening_xy,
546555
)
547556
elif task == "replicate_zarr_structure_mip":
@@ -550,7 +559,7 @@ def app_create_zarr_structure(**kwargs_):
550559
kwargs = dict(newzarrurl="new")
551560
elif task == "illumination_correction":
552561
kwargs = dict(
553-
channels=channels,
562+
chl_list=chl_list,
554563
coarsening_xy=coarsening_xy,
555564
overwrite=True,
556565
# background=background,

fractal/tasks/create_zarr_structure.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,19 @@ def create_zarr_structure(
138138
actual_channels.append(ch)
139139
print(f"actual_channels: {actual_channels}")
140140

141-
well = []
141+
zarrurls = {"plate": [], "well": []}
142+
# zarrurls_in_paths = {}
142143

143144
if not out_path.endswith("/"):
144145
out_path += "/"
145-
146-
zarrurls = {"plate": [], "well": []}
147-
148146
for plate in plates:
149147

150-
print(f"Creating {out_path}{plate}.zarr")
151-
152148
# Define plate zarr
153-
group_plate = zarr.group(out_path + f"{plate}.zarr")
154-
zarrurls["plate"].append(out_path + f"{plate}.zarr")
149+
zarrurl = f"{out_path}{plate}.zarr"
150+
print(f"Creating {zarrurl}")
151+
group_plate = zarr.group(zarrurl)
152+
zarrurls["plate"].append(zarrurl)
153+
# zarrurls_in_paths[zarrurl] = dict_plate_paths[plate]
155154

156155
# Identify all wells
157156
plate_prefix = dict_plate_prefixes[plate]

fractal/tasks/yokogawa_to_zarr.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def yokogawa_to_zarr(
2828
ext=None,
2929
rows=None,
3030
cols=None,
31-
channels=None,
31+
chl_list=None,
3232
num_levels=5,
3333
coarsening_xy=2,
3434
coarsening_z=1,
@@ -49,8 +49,8 @@ def yokogawa_to_zarr(
4949
:type rows: list
5050
:param cols: number of columns of the well
5151
:type cols: list
52-
:param chl_list: list of the channels #FIXME
53-
:type chl_list: list #FIXME
52+
:param chl_list: list of channel names (e.g. A01_C01)
53+
:type chl_list: list
5454
:param num_levels: number of levels in the zarr pyramid
5555
:type num_levels: int
5656
:param coarsening_xy: coarsening factor along X and Y
@@ -79,10 +79,10 @@ def yokogawa_to_zarr(
7979
lazy_imread = delayed(imread)
8080
fc_list = {level: [] for level in range(num_levels)}
8181

82-
print(channels)
82+
print(f"Channels: {chl_list}")
8383

84-
for channel in channels:
85-
A, C = channel.split("_")
84+
for chl in chl_list:
85+
A, C = chl.split("_")
8686

8787
l_rows = []
8888
all_rows = []
@@ -99,7 +99,7 @@ def yokogawa_to_zarr(
9999
f" in_path: {in_path}\n"
100100
f" ext: {ext}\n"
101101
f" well_ID: {well_ID}\n"
102-
f" channel: {channel},\n"
102+
f" channel: {chl},\n"
103103
f" glob_path: {glob_path}"
104104
)
105105
max_z = max(
@@ -222,7 +222,7 @@ def yokogawa_to_zarr(
222222
"-C",
223223
"--chl_list",
224224
nargs="+",
225-
help="list of channels ", # FIXME
225+
help="list of channel names (e.g. A01_C01)",
226226
)
227227

228228
parser.add_argument(

0 commit comments

Comments
 (0)