Mercurial > repos > ufz > omero_metadata_import
annotate omero_dataset_to_plate.py @ 6:6d8603230e85 draft default tip
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 3d98eedf798f0d1dcb32c572580c871ad2b6c9aa
author | ufz |
---|---|
date | Thu, 19 Dec 2024 13:48:21 +0000 |
parents | 4291d37da555 |
children |
rev | line source |
---|---|
5
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
1 import argparse |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
2 import csv |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
3 import json |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
4 import re |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
5 import sys |
4291d37da555
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 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
7 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
8 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
9 import omero |
4291d37da555
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 |
4291d37da555
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 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
12 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
13 |
4291d37da555
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): |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
15 """ |
4291d37da555
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 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
17 """ |
4291d37da555
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) |
4291d37da555
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(): |
4291d37da555
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") |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
21 |
4291d37da555
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"): |
4291d37da555
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: |
4291d37da555
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}") |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
25 |
4291d37da555
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) |
4291d37da555
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: |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
28 conn.close() |
4291d37da555
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") |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
30 |
4291d37da555
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() |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
32 |
4291d37da555
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 |
4291d37da555
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() |
4291d37da555
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()) |
4291d37da555
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) |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
37 |
4291d37da555
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 |
4291d37da555
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 = {} |
4291d37da555
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: |
4291d37da555
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: |
4291d37da555
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') |
4291d37da555
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: |
4291d37da555
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'] |
4291d37da555
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'] |
4291d37da555
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) |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
47 if match: |
4291d37da555
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() |
4291d37da555
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') |
4291d37da555
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 |
4291d37da555
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) |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
52 else: |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
53 conn.close() |
4291d37da555
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}'") |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
55 |
4291d37da555
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 |
4291d37da555
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()) |
4291d37da555
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: |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
59 conn.close() |
4291d37da555
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") |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
61 |
4291d37da555
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 |
4291d37da555
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) |
4291d37da555
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: |
4291d37da555
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() |
4291d37da555
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: |
4291d37da555
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: |
4291d37da555
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] |
4291d37da555
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) |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
70 else: |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
71 conn.close() |
4291d37da555
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.") |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
73 |
4291d37da555
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 |
4291d37da555
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(): |
4291d37da555
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() |
4291d37da555
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) |
4291d37da555
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) |
4291d37da555
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) |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
80 |
4291d37da555
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: |
4291d37da555
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() |
4291d37da555
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) |
4291d37da555
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 |
4291d37da555
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) |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
86 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
87 try: |
4291d37da555
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) |
4291d37da555
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: |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
90 conn.close() |
4291d37da555
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))) |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
92 |
4291d37da555
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 |
4291d37da555
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: |
4291d37da555
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) |
4291d37da555
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}") |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
97 conn.close() |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
98 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
99 |
4291d37da555
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__": |
4291d37da555
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.") |
4291d37da555
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, |
4291d37da555
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)") |
4291d37da555
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') |
4291d37da555
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') |
4291d37da555
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") |
4291d37da555
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', |
4291d37da555
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') |
4291d37da555
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', |
4291d37da555
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)') |
4291d37da555
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', |
4291d37da555
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') |
4291d37da555
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() |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
114 |
4291d37da555
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: |
4291d37da555
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) |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
117 |
4291d37da555
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( |
4291d37da555
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'], |
4291d37da555
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'], |
4291d37da555
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, |
4291d37da555
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, |
4291d37da555
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, |
4291d37da555
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, |
4291d37da555
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, |
4291d37da555
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 |
4291d37da555
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 636cbb62d59819caca5bc9eab0a8ec31be5bdd46
ufz
parents:
diff
changeset
|
127 ) |