Mercurial > repos > lldelisle > omero_get_children_ids
comparison omero_get_children_ids.py @ 1:82f2efb46200 draft default tip
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/omero_get_children_ids commit 3a5c830ad68e29c5e9f91edffa0a548c77aac141
author | lldelisle |
---|---|
date | Mon, 17 Jun 2024 08:05:48 +0000 |
parents | b0876c73076b |
children |
comparison
equal
deleted
inserted
replaced
0:b0876c73076b | 1:82f2efb46200 |
---|---|
18 omero_username = "public" | 18 omero_username = "public" |
19 omero_password = "public" | 19 omero_password = "public" |
20 return (omero_username, omero_password) | 20 return (omero_username, omero_password) |
21 | 21 |
22 | 22 |
23 def recursive_get_children_id(parent_object, final_object_type): | 23 def recursive_get_children_id(parent_object, final_object_type, get_name): |
24 output = [] | 24 output = [] |
25 if parent_object.OMERO_CLASS == 'WellSample': | 25 if parent_object.OMERO_CLASS == 'WellSample': |
26 return [parent_object.getImage().id] | 26 if get_name: |
27 parent_image = parent_object.getImage() | |
28 return [f"{parent_image.id}\t{parent_image.getName()}"] | |
29 else: | |
30 return [parent_object.getImage().id] | |
27 for children in parent_object.listChildren(): | 31 for children in parent_object.listChildren(): |
28 if children.OMERO_CLASS == final_object_type.title(): | 32 if children.OMERO_CLASS == final_object_type.title(): |
29 output.append(children.id) | 33 if get_name: |
34 output.append(f"{children.id}\t{children.getName()}") | |
35 else: | |
36 output.append(children.id) | |
30 else: | 37 else: |
31 # We need to go one step further | 38 # We need to go one step further |
32 output += recursive_get_children_id(children, final_object_type) | 39 output += recursive_get_children_id( |
40 children, final_object_type, get_name | |
41 ) | |
33 return output | 42 return output |
34 | 43 |
35 | 44 |
36 def get_children_ids(parent_object_type, | 45 def get_children_ids(parent_object_type, |
37 omero_id, | 46 omero_id, |
38 final_object_type, | 47 final_object_type, |
48 get_name, | |
39 omero_username, | 49 omero_username, |
40 omero_password, | 50 omero_password, |
41 omero_host="idr.openmicroscopy.org", | 51 omero_host="idr.openmicroscopy.org", |
42 omero_secured=False): | 52 omero_secured=False): |
43 # Connect to omero: | 53 # Connect to omero: |
44 with BlitzGateway( | 54 with BlitzGateway( |
45 omero_username, omero_password, host=omero_host, secure=omero_secured | 55 omero_username, omero_password, host=omero_host, secure=omero_secured |
46 ) as conn: | 56 ) as conn: |
47 # Retrieve omero object | 57 # Retrieve omero object |
48 parent_object = conn.getObject(parent_object_type.title(), omero_id) | 58 parent_object = conn.getObject(parent_object_type.title(), omero_id) |
49 return recursive_get_children_id(parent_object, final_object_type) | 59 return recursive_get_children_id( |
60 parent_object, final_object_type, get_name | |
61 ) | |
50 | 62 |
51 | 63 |
52 if __name__ == "__main__": | 64 if __name__ == "__main__": |
53 p = argparse.ArgumentParser() | 65 p = argparse.ArgumentParser() |
54 p.add_argument("-oh", "--omero-host", type=str, | 66 p.add_argument("-oh", "--omero-host", type=str, |
60 type=str, default=None, required=True) | 72 type=str, default=None, required=True) |
61 p.add_argument("--omero-id", dest="omero_id", | 73 p.add_argument("--omero-id", dest="omero_id", |
62 type=int, default=None, required=True) | 74 type=int, default=None, required=True) |
63 p.add_argument("--final-object-type", dest="final_object_type", | 75 p.add_argument("--final-object-type", dest="final_object_type", |
64 type=str, default=None, required=True) | 76 type=str, default=None, required=True) |
77 p.add_argument("--get-name", dest="get_name", | |
78 action="store_true", default=False) | |
65 p.add_argument("--output", type=str, default=None, required=True) | 79 p.add_argument("--output", type=str, default=None, required=True) |
66 args = p.parse_args() | 80 args = p.parse_args() |
67 children_ids = get_children_ids( | 81 children_ids = get_children_ids( |
68 args.parent_object_type, | 82 args.parent_object_type, |
69 args.omero_id, | 83 args.omero_id, |
70 args.final_object_type, | 84 args.final_object_type, |
85 args.get_name, | |
71 *get_omero_credentials(args.config_file), | 86 *get_omero_credentials(args.config_file), |
72 omero_host=args.omero_host, | 87 omero_host=args.omero_host, |
73 omero_secured=args.omero_secured, | 88 omero_secured=args.omero_secured, |
74 ) | 89 ) |
75 with open(args.output, 'w') as fo: | 90 with open(args.output, 'w') as fo: |