Mercurial > repos > ufz > omero_roi_import
annotate omero_roi_upload.py @ 3:dfe0aae1495c draft
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 19d84fd5a372f1428e3e5670144881a56e8af8b2
author | ufz |
---|---|
date | Tue, 22 Oct 2024 11:53:15 +0000 |
parents | 4f4dc352d660 |
children |
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 |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
2 import json |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
3 import re |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
4 |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
5 import numpy as np |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
6 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
|
7 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
|
8 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
|
9 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
10 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
11 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
|
12 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
|
13 return None |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
14 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
|
15 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
16 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
17 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
|
18 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
|
19 return None |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
20 # 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
26 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
27 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
|
28 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
|
29 shape = None |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
30 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
31 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
|
32 shape = Ellipse( |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
33 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
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 t=row.get('t'), |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
40 label=row.get('label'), |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
41 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
|
42 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
|
43 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
|
44 ) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
45 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
|
46 shape = Label( |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 ) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
58 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
|
59 shape = Line( |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 markerEnd=row.get('markerEnd', None), |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
66 label=row.get('label'), |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 ) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
74 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
|
75 shape = Point( |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
76 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
|
77 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
|
78 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
|
79 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
|
80 t=row.get('t'), |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
81 label=row.get('label'), |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
82 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
|
83 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
|
84 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
|
85 ) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
86 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
|
87 shape = Polygon( |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
88 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
|
89 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
|
90 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
|
91 t=row.get('t'), |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
92 label=row.get('label'), |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
93 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
|
94 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
|
95 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
|
96 ) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
97 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
|
98 shape = Polyline( |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
99 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
|
100 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
|
101 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
|
102 t=row.get('t'), |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
103 label=row.get('label'), |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
104 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
|
105 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
|
106 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
|
107 ) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
108 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
|
109 shape = Rectangle( |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 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
|
114 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
|
115 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
|
116 t=row.get('t'), |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
117 label=row.get('label'), |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
118 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
|
119 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
|
120 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
|
121 ) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
122 return shape |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
123 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
124 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
125 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
|
126 # 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
|
127 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
|
128 df = pd.read_csv(input_file, sep='\t') |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
129 # Replace nan to none |
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
130 df = df.replace({np.nan: None}) |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
131 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
|
132 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
|
133 print(msg) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
134 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
|
135 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
|
136 if shape: |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 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
|
141 print(msg) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
142 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
|
143 else: |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
144 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
|
145 print(msg) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
146 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
|
147 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
148 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 parser.add_argument("--host", type=str, required=True, help="OMERO server host") |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
155 parser.add_argument("--credential-file", dest="credential_file", type=str, required=True, help="Credential file (JSON file with username and password for OMERO)") |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
156 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
|
157 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
|
158 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
159 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
|
160 |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
161 with open(args.credential_file, 'r') as f: |
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
162 crds = json.load(f) |
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
163 |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
164 conn = connect( |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
165 host=args.host, |
2
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
166 user=crds['username'], |
4f4dc352d660
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
ufz
parents:
0
diff
changeset
|
167 password=crds['password'], |
0
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
168 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
|
169 group="", |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
170 secure=True |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
171 ) |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
172 |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
173 try: |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
174 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
|
175 finally: |
9051b91545f6
planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 5b1b30d409355cee98485815c1dd4ac48649bcc1
ufz
parents:
diff
changeset
|
176 conn.close() |