annotate create-config.py @ 0:f2fb987f5d09 draft default tip

planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
author imgteam
date Wed, 26 Jun 2024 08:02:56 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
1 import argparse
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
2 import json
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
3
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
4 import yaml
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
5
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
6
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
7 # This script genereates the config file required by PlantSeg.
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
8 # For an overview of the config fields, see:
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
9 # https://github.com/kreshuklab/plant-seg/blob/master/examples/config.yaml
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
10
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
11
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
12 def listify(d, k, sep=',', dtype=float):
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
13 if k not in d:
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
14 return
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
15 d[k] = [dtype(token.strip()) for token in str(d[k]).split(sep)]
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
16
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
17
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
18 if __name__ == '__main__':
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
19
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
20 parser = argparse.ArgumentParser()
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
21 parser.add_argument('--inputs', type=str, help='Path to the inputs file', required=True)
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
22 parser.add_argument('--config', type=str, help='Path to the config file', required=True)
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
23 parser.add_argument('--img_in', type=str, help='Path to the input image', required=True)
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
24 parser.add_argument('--workers', type=int, default=1)
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
25 args = parser.parse_args()
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
26
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
27 with open(args.inputs, 'r') as fp:
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
28 inputs = json.load(fp)
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
29
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
30 # Set configuration options from the tool wrapper
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
31 cfg = dict(path=args.img_in)
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
32 for section_name in (
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
33 'preprocessing',
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
34 'cnn_prediction',
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
35 'cnn_postprocessing',
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
36 'segmentation',
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
37 'segmentation_postprocessing',
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
38 ):
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
39 cfg[section_name] = inputs[section_name]
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
40
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
41 # Set additional required configuration options
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
42 cfg['preprocessing']['save_directory'] = 'PreProcessing'
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
43 cfg['preprocessing']['crop_volume'] = '[:,:,:]'
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
44 cfg['preprocessing']['filter'] = dict(state=False, type='gaussian', filter_param=1.0)
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
45
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
46 cfg['cnn_prediction']['device'] = 'cuda'
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
47 cfg['cnn_prediction']['num_workers'] = args.workers
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
48 cfg['cnn_prediction']['model_update'] = False
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
49
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
50 cfg['segmentation']['name'] = 'MultiCut'
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
51 cfg['segmentation']['save_directory'] = 'MultiCut'
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
52
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
53 # Parse lists of values encoded as strings as actual lists of values
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
54 listify(cfg['preprocessing'], 'factor')
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
55 listify(cfg['cnn_prediction'], 'patch')
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
56
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
57 with open(args.config, 'w') as fp:
f2fb987f5d09 planemo upload for repository https://github.com/BMCV/galaxy-image-analysis/tree/master/tools/plantseg/ commit 842fb4a9435114d06329e2cdfaeb8ed8d8479681
imgteam
parents:
diff changeset
58 fp.write(yaml.dump(cfg))