annotate omero_roi_upload.py @ 0:9051b91545f6 draft

planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
author ufz
date Thu, 05 Sep 2024 11:55:44 +0000
parents
children 4f4dc352d660
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
1 import argparse
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
2 import re
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
3
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
4 import pandas as pd
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
5 from ezomero import connect, post_roi
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
6 from ezomero.rois import Ellipse, Label, Line, Point, Polygon, Polyline, Rectangle
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
7
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
8
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
9 def parse_color(color_str):
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
10 if not color_str:
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
11 return None
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
12 return tuple(map(int, re.findall(r'\d+', color_str)))
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
13
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
14
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
15 def parse_points(points_str):
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
16 if not points_str:
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
17 return None
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
18 # Remove leading and trailing brackets and split into individual points
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
19 points_str = points_str.strip("[]")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
20 points = points_str.split("),(")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
21 points = [point.strip("()") for point in points] # Remove any remaining parentheses
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
22 return [tuple(map(float, point.split(','))) for point in points]
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
23
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
24
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
25 def create_shape(row):
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
26 shape_type = row['shape']
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
27 shape = None
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
28
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
29 if shape_type == 'Ellipse':
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
30 shape = Ellipse(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
31 x=row['x'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
32 y=row['y'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
33 x_rad=row['x_rad'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
34 y_rad=row['y_rad'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
35 z=row.get('z'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
36 c=row.get('c'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
37 t=row.get('t'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
38 fill_color=parse_color(row.get('fill_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
39 stroke_color=parse_color(row.get('stroke_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
40 stroke_width=row.get('stroke_width')
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
41 )
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
42 elif shape_type == 'Label':
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
43 shape = Label(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
44 x=row['x'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
45 y=row['y'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
46 label=row['label'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
47 fontSize=row['fontSize'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
48 z=row.get('z'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
49 c=row.get('c'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
50 t=row.get('t'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
51 fill_color=parse_color(row.get('fill_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
52 stroke_color=parse_color(row.get('stroke_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
53 stroke_width=row.get('stroke_width')
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
54 )
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
55 elif shape_type == 'Line':
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
56 shape = Line(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
57 x1=row['x1'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
58 y1=row['y1'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
59 x2=row['x2'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
60 y2=row['y2'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
61 markerStart=row.get('markerStart', None),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
62 markerEnd=row.get('markerEnd', None),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
63 label=row.get('label', None),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
64 z=row.get('z'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
65 c=row.get('c'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
66 t=row.get('t'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
67 fill_color=parse_color(row.get('fill_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
68 stroke_color=parse_color(row.get('stroke_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
69 stroke_width=row.get('stroke_width')
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
70 )
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
71 elif shape_type == 'Point':
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
72 shape = Point(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
73 x=row['x'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
74 y=row['y'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
75 z=row.get('z'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
76 c=row.get('c'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
77 t=row.get('t'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
78 fill_color=parse_color(row.get('fill_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
79 stroke_color=parse_color(row.get('stroke_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
80 stroke_width=row.get('stroke_width')
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
81 )
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
82 elif shape_type == 'Polygon':
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
83 shape = Polygon(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
84 points=parse_points(row['points']),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
85 z=row.get('z'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
86 c=row.get('c'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
87 t=row.get('t'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
88 fill_color=parse_color(row.get('fill_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
89 stroke_color=parse_color(row.get('stroke_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
90 stroke_width=row.get('stroke_width')
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
91 )
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
92 elif shape_type == 'Polyline':
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
93 shape = Polyline(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
94 points=parse_points(row['points']),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
95 z=row.get('z'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
96 c=row.get('c'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
97 t=row.get('t'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
98 fill_color=parse_color(row.get('fill_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
99 stroke_color=parse_color(row.get('stroke_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
100 stroke_width=row.get('stroke_width')
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
101 )
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
102 elif shape_type == 'Rectangle':
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
103 shape = Rectangle(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
104 x=row['x'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
105 y=row['y'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
106 width=row['width'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
107 height=row['height'],
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
108 z=row.get('z'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
109 c=row.get('c'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
110 t=row.get('t'),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
111 fill_color=parse_color(row.get('fill_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
112 stroke_color=parse_color(row.get('stroke_color')),
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
113 stroke_width=row.get('stroke_width')
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
114 )
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
115 return shape
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
116
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
117
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
118 def main(input_file, conn, image_id, log_file):
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
119 # Open log file
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
120 with open(log_file, 'w') as log:
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
121 df = pd.read_csv(input_file, sep='\t')
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
122 for index, row in df.iterrows():
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
123 msg = f"Processing row {index + 1}/{len(df)}: {row.to_dict()}"
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
124 print(msg)
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
125 log.write(msg + "\n")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
126 shape = create_shape(row)
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
127 if shape:
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
128 roi_name = row['roi_name'] if 'roi_name' in row else None
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
129 roi_description = row['roi_description'] if 'roi_description' in row else None
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
130 roi_id = post_roi(conn, image_id, [shape], name=roi_name, description=roi_description)
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
131 msg = f"ROI ID: {roi_id} for row {index + 1}"
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
132 print(msg)
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
133 log.write(msg + "\n")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
134 else:
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
135 msg = f"Skipping row {index + 1}: Unable to create shape"
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
136 print(msg)
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
137 log.write(msg + "\n")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
138
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
139
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
140 if __name__ == "__main__":
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
141 parser = argparse.ArgumentParser(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
142 description="Create shapes from a tabular file and optionally post them as an ROI to OMERO.")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
143 parser.add_argument("--input_file", help="Path to the input tabular file.")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
144 parser.add_argument("--image_id", type=int, required=True, help="ID of the image to which the ROI will be linked")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
145 parser.add_argument("--host", type=str, required=True, help="OMERO server host")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
146 parser.add_argument("--user", type=str, required=True, help="OMERO username")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
147 parser.add_argument("--psw", type=str, required=True, help="OMERO password")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
148 parser.add_argument("--port", type=int, default=4064, help="OMERO server port")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
149 parser.add_argument("--log_file", type=str, default="process.txt", help="Log file path")
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
150
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
151 args = parser.parse_args()
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
152
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
153 conn = connect(
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
154 host=args.host,
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
155 user=args.user,
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
156 password=args.psw,
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
157 port=args.port,
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
158 group="",
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
159 secure=True
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
160 )
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
161
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
162 try:
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
163 main(args.input_file, conn, args.image_id, args.log_file)
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
164 finally:
9051b91545f6 planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff changeset
165 conn.close()