annotate omero_dataset_to_plate.py @ 2:5513b999c56e draft

planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
author ufz
date Mon, 16 Dec 2024 20:56:41 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
1 import argparse
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
2 import csv
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
3 import json
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
4 import re
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
5 import sys
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
6 from collections import defaultdict
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
7
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
8
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
9 import omero
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
10 from omero.gateway import BlitzGateway
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
11 from omero.rtypes import rint, rstring
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
12
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
13
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
14 def convert_dataset_to_plate(host, user, pws, port, dataset_id, log_file, mapping_file, delete_dataset):
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
15 """
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
16 Connect to OMERO server, convert a dataset to a plate using the specified well mapping file
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
17 """
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
18 conn = BlitzGateway(user, pws, host=host, port=port, secure=True)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
19 if not conn.connect():
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
20 sys.exit("ERROR: Failed to connect to OMERO server")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
21
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
22 def log_message(message, status="INFO"):
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
23 with open(log_file, 'w') as f:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
24 f.write(f"{message}")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
25
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
26 dataset = conn.getObject("Dataset", dataset_id)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
27 if dataset is None:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
28 conn.close()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
29 sys.exit("ERROR: Dataset not found")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
30
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
31 update_service = conn.getUpdateService()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
32
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
33 # Create a Plate
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
34 plate = omero.model.PlateI()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
35 plate.name = rstring(dataset.getName())
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
36 plate = update_service.saveAndReturnObject(plate)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
37
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
38 # Parse the mapping file
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
39 image_to_well_mapping = {}
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
40 if mapping_file:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
41 with open(mapping_file, 'r') as f:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
42 reader = csv.DictReader(f, delimiter='\t')
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
43 for row in reader:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
44 filename = row['Filename']
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
45 well = row['Well']
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
46 match = re.match(r"([A-Z])(\d+)", well)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
47 if match:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
48 row_char, col = match.groups()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
49 row = ord(row_char.upper()) - ord('A')
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
50 col = int(col) - 1
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
51 image_to_well_mapping[filename] = (row, col)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
52 else:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
53 conn.close()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
54 sys.exit(f"Invalid well format '{well}' for file '{filename}'")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
55
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
56 # List the dataset children
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
57 images = list(dataset.listChildren())
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
58 if not images:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
59 conn.close()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
60 sys.exit("ERROR: No images found in dataset")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
61
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
62 # Compare images in the mapping file and in the dataset
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
63 grouped_images = defaultdict(list)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
64 for image in images:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
65 image_name = image.getName()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
66 if image_to_well_mapping:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
67 if image_name in image_to_well_mapping:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
68 row, col = image_to_well_mapping[image_name]
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
69 grouped_images[(row, col)].append(image)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
70 else:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
71 conn.close()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
72 sys.exit(f"Image '{image_name}' not found in mapping file.")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
73
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
74 # Assign images to the well based on the mapping file
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
75 for (row, col), imgs_in_group in grouped_images.items():
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
76 well = omero.model.WellI()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
77 well.plate = omero.model.PlateI(plate.id.val, False)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
78 well.column = rint(col)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
79 well.row = rint(row)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
80
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
81 for image in imgs_in_group:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
82 ws = omero.model.WellSampleI()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
83 ws.image = omero.model.ImageI(image.id, False)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
84 ws.well = well
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
85 well.addWellSample(ws)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
86
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
87 try:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
88 update_service.saveObject(well)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
89 except ValueError as e:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
90 conn.close()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
91 sys.exit("ERROR: Failed to update plate for dataset '{}' due to: {}".format(dataset.getName(), str(e)))
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
92
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
93 # Close the connection and, in case, delete the dataset
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
94 if delete_dataset is True:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
95 conn.deleteObjects("Dataset", [dataset_id], wait=True)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
96 log_message(f"Images from Dataset {dataset_id} successfully added to Plate {plate.id.val}")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
97 conn.close()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
98
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
99
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
100 if __name__ == "__main__":
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
101 parser = argparse.ArgumentParser(description="Convert an OMERO dataset to a plate.")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
102 parser.add_argument("--credential-file", dest="credential_file", type=str, required=True,
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
103 help="Credential file (JSON file with username and password for OMERO)")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
104 parser.add_argument('--host', required=True, help='OMERO host')
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
105 parser.add_argument('--port', required=True, type=int, help='OMERO port')
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
106 parser.add_argument('--dataset_id', type=int, required=True, help="Dataset ID to convert plate")
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
107 parser.add_argument('--log_file', default='metadata_import_log.txt',
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
108 help='Path to the log file')
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
109 parser.add_argument('--mapping_file',
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
110 help='Tabular file mapping filenames to well positions (2 columns: filename, Well)')
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
111 parser.add_argument('--delete_dataset', action='store_true',
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
112 help='Flag to delete the original dataset')
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
113 args = parser.parse_args()
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
114
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
115 with open(args.credential_file, 'r') as f:
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
116 crds = json.load(f)
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
117
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
118 convert_dataset_to_plate(
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
119 user=crds['username'],
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
120 pws=crds['password'],
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
121 host=args.host,
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
122 port=args.port,
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
123 dataset_id=args.dataset_id,
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
124 log_file=args.log_file,
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
125 mapping_file=args.mapping_file,
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
126 delete_dataset=args.delete_dataset
5513b999c56e planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff changeset
127 )