Mercurial > repos > imgteam > superdsm
annotate run-superdsm.py @ 3:7fd8dba15bd3 draft
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
author | imgteam |
---|---|
date | Thu, 16 Nov 2023 12:29:41 +0000 |
parents | 244f67290d28 |
children | dc5f72f6b1e9 |
rev | line source |
---|---|
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
1 """ |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
2 Copyright 2023 Leonid Kostrykin, Biomedical Computer Vision Group, Heidelberg University. |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
3 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
4 Distributed under the MIT license. |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
5 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
6 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
7 """ |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
8 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
9 import argparse |
3
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
10 import csv |
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
11 import imghdr |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
12 import os |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
13 import pathlib |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
14 import shutil |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
15 import tempfile |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
16 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
17 |
1
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
18 hyperparameters = [ |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
19 ('AF_scale', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
20 ('c2f_region_analysis/min_atom_radius', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
21 ('c2f_region_analysis_min_norm_energy_improvement', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
22 ('c2f_region_analysis_max_atom_norm_energy', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
23 ('c2f_region_analysis_max_cluster_marker_irregularity', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
24 ('dsm_alpha', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
25 ('dsm_AF_alpha', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
26 ('global_energy_minimization_betai', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
27 ('global_energy_minimization_AF_beta', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
28 ('postprocess_mask_max_distance', int), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
29 ('postprocess_mask_stdamp', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
30 ('postprocess_max_norm_energy', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
31 ('postprocess_min_contrast', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
32 ('postprocess_min_object_radius', float), |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
33 ] |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
34 |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
35 |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
36 def get_param_name(key): |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
37 return key.replace('/', '_') |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
38 |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
39 |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
40 def create_config(args): |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
41 cfg = superdsm.config.Config() |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
42 for key, _ in hyperparameters: |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
43 value = getattr(args, get_param_name(key)) |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
44 if value is not None: |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
45 cfg[key] = value |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
46 return cfg |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
47 |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
48 |
3
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
49 def flatten_dict(d, sep='/'): |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
50 result = {} |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
51 for key, val in d.items(): |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
52 if isinstance(val, dict): |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
53 for sub_key, sub_val in flatten_dict(val, sep=sep).items(): |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
54 result[f'{key}{sep}{sub_key}'] = sub_val |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
55 else: |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
56 result[key] = val |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
57 return result |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
58 |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
59 |
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
60 if __name__ == "__main__": |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
61 parser = argparse.ArgumentParser(description='Segmentation of cell nuclei in 2-D fluorescence microscopy images') |
3
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
62 parser.add_argument('image', type=str, help='Path to the input image') |
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
63 parser.add_argument('slots', type=int) |
3
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
64 parser.add_argument('--do-masks', type=str, default=None, help='Path to the file containing the segmentation masks') |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
65 parser.add_argument('--do-cfg', type=str, default=None, help='Path to the file containing the configuration') |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
66 parser.add_argument('--do-overlay', type=str, default=None, help='Path to the file containing the overlay of the segmentation results') |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
67 parser.add_argument('--do-overlay-border', type=int) |
1
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
68 for key, ptype in hyperparameters: |
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
69 parser.add_argument('--' + get_param_name(key), type=ptype, default=None) |
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
70 args = parser.parse_args() |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
71 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
72 if args.slots >= 2: |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
73 num_threads_per_process = 2 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
74 num_processes = args.slots // num_threads_per_process |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
75 else: |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
76 num_threads_per_process = 1 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
77 num_processes = 1 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
78 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
79 os.environ['MKL_NUM_THREADS'] = str(num_threads_per_process) |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
80 os.environ['OPENBLAS_NUM_THREADS'] = str(num_threads_per_process) |
2
244f67290d28
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents:
1
diff
changeset
|
81 |
244f67290d28
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents:
1
diff
changeset
|
82 import ray |
244f67290d28
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents:
1
diff
changeset
|
83 import superdsm.automation |
244f67290d28
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents:
1
diff
changeset
|
84 import superdsm.io |
244f67290d28
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit 2286a6c9da88596349ed9d967c51541409c0a7bf
imgteam
parents:
1
diff
changeset
|
85 import superdsm.render |
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
86 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
87 ray.init(num_cpus=num_processes, log_to_driver=True) |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
88 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
89 with tempfile.TemporaryDirectory() as tmpdirname: |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
90 tmpdir = pathlib.Path(tmpdirname) |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
91 img_ext = imghdr.what(args.image) |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
92 img_filepath = tmpdir / f'input.{img_ext}' |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
93 shutil.copy(str(args.image), img_filepath) |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
94 |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
95 pipeline = superdsm.pipeline.create_default_pipeline() |
1
700ae37e5c69
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
imgteam
parents:
0
diff
changeset
|
96 cfg = create_config(args) |
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
97 img = superdsm.io.imread(img_filepath) |
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
98 |
3
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
99 if args.do_cfg: |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
100 print(f'Writing config to: {args.do_cfg}') |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
101 cfg, _ = superdsm.automation.create_config(pipeline, cfg, img) |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
102 with open(args.do_cfg, 'w') as fp: |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
103 tsv_out = csv.writer(fp, delimiter='\t') |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
104 tsv_out.writerow(['Hyperparameter', 'Value']) |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
105 for key, value in flatten_dict(cfg.entries).items(): |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
106 tsv_out.writerow([key, value]) |
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
107 |
3
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
108 if args.do_overlay or args.do_masks: |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
109 print('Performing segmentation') |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
110 data, cfg, _ = pipeline.process_image(img, cfg) |
0
1b0fc671187f
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 4d66ff6e8a2a842e44e8d0d7102dfb3ac78dca7e
imgteam
parents:
diff
changeset
|
111 |
3
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
112 if args.do_overlay: |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
113 print(f'Writing overlay to: {args.do_overlay}') |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
114 overlay = superdsm.render.render_result_over_image(data, border_width=args.do_overlay_border, normalize_img=False) |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
115 superdsm.io.imwrite(args.do_overlay, overlay) |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
116 |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
117 if args.do_masks: |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
118 print(f'Writing masks to: {args.do_masks}') |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
119 masks = superdsm.render.rasterize_labels(data) |
7fd8dba15bd3
planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/superdsm/ commit fea6c8161c4b3e6394fe035b12b69b73e6fa7d75
imgteam
parents:
2
diff
changeset
|
120 superdsm.io.imwrite(args.do_masks, masks) |