forked from TheJacksonLaboratory/jax-omeroutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jaxLIMS_list_orphans.py
48 lines (44 loc) · 1.99 KB
/
jaxLIMS_list_orphans.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import argparse
from getpass import getpass
from omero.gateway import BlitzGateway
from ezomero import get_image_ids, get_group_id, get_image
from ezomero import get_original_filepaths
from pathlib import Path
def main(group, admin_user, server, port):
password = getpass(f'Enter password for {admin_user}: ')
conn = BlitzGateway(admin_user, password, host=server, port=port)
conn.connect()
group_id = get_group_id(conn, group)
conn.SERVICE_OPTS.setOmeroGroup(group_id)
image_ids = get_image_ids(conn, across_groups=False)
with open("omeroImages2Import.tsv", 'w') as f:
f.write('omero_id\timage_file\timage_name\n')
for im_id in image_ids:
im_o, _ = get_image(conn, im_id, no_pixels=True)
imp_filename = Path(get_original_filepaths(conn, im_id)[0]).name
image_name = im_o.getName()
out_string = f'{im_id}\t{imp_filename}\t{image_name}\n'
f.write(out_string)
conn.close()
if __name__ == "__main__":
description = ("Output a tsv of orphaned images for a particular group. "
"Columns: omero_id, image_file, image_name")
parser = argparse.ArgumentParser(description=description)
parser.add_argument('-g', '--group',
type=str,
help='Group in which to find orphans (REQUIRED)',
required=True)
parser.add_argument('--sudo',
type=str,
help='OMERO admin user for login (REQUIRED)',
required=True)
parser.add_argument('-s', '--server',
type=str,
help='OMERO server hostname (default = localhost)',
default='localhost')
parser.add_argument('-p', '--port',
type=int,
help='OMERO server port (default = 4064)',
default=4064)
args = parser.parse_args()
main(args.group, args.sudo, args.server, args.port)