comparison run-superdsm.py @ 1:700ae37e5c69 draft

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tools/superdsm/ commit 7db4b765fa5a1f526cc94cd1f65d963d1e047b27
author imgteam
date Thu, 06 Jul 2023 00:01:18 +0000
parents 1b0fc671187f
children 244f67290d28
comparison
equal deleted inserted replaced
0:1b0fc671187f 1:700ae37e5c69
17 import superdsm.automation 17 import superdsm.automation
18 import superdsm.io 18 import superdsm.io
19 import superdsm.render 19 import superdsm.render
20 20
21 21
22 hyperparameters = [
23 ('AF_scale', float),
24 ('c2f_region_analysis/min_atom_radius', float),
25 ('c2f_region_analysis_min_norm_energy_improvement', float),
26 ('c2f_region_analysis_max_atom_norm_energy', float),
27 ('c2f_region_analysis_max_cluster_marker_irregularity', float),
28 ('dsm_alpha', float),
29 ('dsm_AF_alpha', float),
30 ('global_energy_minimization_betai', float),
31 ('global_energy_minimization_AF_beta', float),
32 ('postprocess_mask_max_distance', int),
33 ('postprocess_mask_stdamp', float),
34 ('postprocess_max_norm_energy', float),
35 ('postprocess_min_contrast', float),
36 ('postprocess_min_object_radius', float),
37 ]
38
39
40 def get_param_name(key):
41 return key.replace('/', '_')
42
43
44 def create_config(args):
45 cfg = superdsm.config.Config()
46 for key, _ in hyperparameters:
47 value = getattr(args, get_param_name(key))
48 if value is not None:
49 cfg[key] = value
50 return cfg
51
52
22 if __name__ == "__main__": 53 if __name__ == "__main__":
23 parser = argparse.ArgumentParser(description='Segmentation of cell nuclei in 2-D fluorescence microscopy images') 54 parser = argparse.ArgumentParser(description='Segmentation of cell nuclei in 2-D fluorescence microscopy images')
24 parser.add_argument('image', help='Path to the input image') 55 parser.add_argument('image', help='Path to the input image')
25 parser.add_argument('cfg', help='Path to the file containing the configuration') 56 parser.add_argument('cfg', help='Path to the file containing the configuration')
26 parser.add_argument('masks', help='Path to the file containing the segmentation masks') 57 parser.add_argument('masks', help='Path to the file containing the segmentation masks')
27 parser.add_argument('overlay', help='Path to the file containing the overlay of the segmentation results') 58 parser.add_argument('overlay', help='Path to the file containing the overlay of the segmentation results')
28 parser.add_argument('seg_border', type=int) 59 parser.add_argument('seg_border', type=int)
29 parser.add_argument('slots', type=int) 60 parser.add_argument('slots', type=int)
61 for key, ptype in hyperparameters:
62 parser.add_argument('--' + get_param_name(key), type=ptype, default=None)
30 args = parser.parse_args() 63 args = parser.parse_args()
31 64
32 if args.slots >= 2: 65 if args.slots >= 2:
33 num_threads_per_process = 2 66 num_threads_per_process = 2
34 num_processes = args.slots // num_threads_per_process 67 num_processes = args.slots // num_threads_per_process
47 img_ext = imghdr.what(args.image) 80 img_ext = imghdr.what(args.image)
48 img_filepath = tmpdir / f'input.{img_ext}' 81 img_filepath = tmpdir / f'input.{img_ext}'
49 shutil.copy(str(args.image), img_filepath) 82 shutil.copy(str(args.image), img_filepath)
50 83
51 pipeline = superdsm.pipeline.create_default_pipeline() 84 pipeline = superdsm.pipeline.create_default_pipeline()
52 cfg = superdsm.config.Config() 85 cfg = create_config(args)
53 img = superdsm.io.imread(img_filepath) 86 img = superdsm.io.imread(img_filepath)
54 data, cfg, _ = superdsm.automation.process_image(pipeline, cfg, img) 87 data, cfg, _ = superdsm.automation.process_image(pipeline, cfg, img)
55 88
56 with open(args.cfg, 'w') as fp: 89 with open(args.cfg, 'w') as fp:
57 cfg.dump_json(fp) 90 cfg.dump_json(fp)