Mercurial > repos > lldelisle > omero_get_children_ids
annotate omero_get_children_ids.py @ 0:b0876c73076b draft
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
author | lldelisle |
---|---|
date | Fri, 22 Dec 2023 12:55:40 +0000 |
parents | |
children | 82f2efb46200 |
rev | line source |
---|---|
0
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
1 import argparse |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
2 import json |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
3 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
4 from omero.gateway import BlitzGateway |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
5 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
6 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
7 def get_omero_credentials(config_file): |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
8 if config_file is None: # IDR connection |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
9 omero_username = "public" |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
10 omero_password = "public" |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
11 else: # other omero instance |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
12 with open(config_file) as f: |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
13 cfg = json.load(f) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
14 omero_username = cfg["username"] |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
15 omero_password = cfg["password"] |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
16 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
17 if omero_username == "" or omero_password == "": |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
18 omero_username = "public" |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
19 omero_password = "public" |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
20 return (omero_username, omero_password) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
21 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
22 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
23 def recursive_get_children_id(parent_object, final_object_type): |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
24 output = [] |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
25 if parent_object.OMERO_CLASS == 'WellSample': |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
26 return [parent_object.getImage().id] |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
27 for children in parent_object.listChildren(): |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
28 if children.OMERO_CLASS == final_object_type.title(): |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
29 output.append(children.id) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
30 else: |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
31 # We need to go one step further |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
32 output += recursive_get_children_id(children, final_object_type) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
33 return output |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
34 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
35 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
36 def get_children_ids(parent_object_type, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
37 omero_id, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
38 final_object_type, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
39 omero_username, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
40 omero_password, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
41 omero_host="idr.openmicroscopy.org", |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
42 omero_secured=False): |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
43 # Connect to omero: |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
44 with BlitzGateway( |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
45 omero_username, omero_password, host=omero_host, secure=omero_secured |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
46 ) as conn: |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
47 # Retrieve omero object |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
48 parent_object = conn.getObject(parent_object_type.title(), omero_id) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
49 return recursive_get_children_id(parent_object, final_object_type) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
50 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
51 |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
52 if __name__ == "__main__": |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
53 p = argparse.ArgumentParser() |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
54 p.add_argument("-oh", "--omero-host", type=str, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
55 default="idr.openmicroscopy.org") |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
56 p.add_argument("--omero-secured", action="store_true", default=True) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
57 p.add_argument("-cf", "--config-file", dest="config_file", |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
58 default=None) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
59 p.add_argument("--parent-object-type", dest="parent_object_type", |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
60 type=str, default=None, required=True) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
61 p.add_argument("--omero-id", dest="omero_id", |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
62 type=int, default=None, required=True) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
63 p.add_argument("--final-object-type", dest="final_object_type", |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
64 type=str, default=None, required=True) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
65 p.add_argument("--output", type=str, default=None, required=True) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
66 args = p.parse_args() |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
67 children_ids = get_children_ids( |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
68 args.parent_object_type, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
69 args.omero_id, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
70 args.final_object_type, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
71 *get_omero_credentials(args.config_file), |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
72 omero_host=args.omero_host, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
73 omero_secured=args.omero_secured, |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
74 ) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
75 with open(args.output, 'w') as fo: |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
76 fo.write('\n'.join([str(id) for id in children_ids])) |
b0876c73076b
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 8ac44b0341c70ce330fc0f24712b6f9b59b14731
lldelisle
parents:
diff
changeset
|
77 fo.write('\n') |