Mercurial > repos > lldelisle > upload_roi_and_measures_to_omero
annotate upload_omero_roi_results.py @ 0:d507ce86f0d0 draft default tip
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
author | lldelisle |
---|---|
date | Fri, 16 Dec 2022 21:02:41 +0000 |
parents | |
children |
rev | line source |
---|---|
0
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
1 import argparse |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
2 import json |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
3 import os |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
4 import re |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
5 import tempfile |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
6 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
7 import numpy as np |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
8 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
9 import omero |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
10 from omero.gateway import BlitzGateway |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
11 from omero.rtypes import rdouble, rstring |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
12 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
13 import pandas as pd |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
14 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
15 file_base_name_exportedTIFF = re.compile(r"^.*__(\d+)__0__0__\d+__\d+$") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
16 file_base_name_original = re.compile(r"^.*__(\d+)$") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
17 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
18 non_roi_value = -1 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
19 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
20 non_numeric_columns = ["Label", "Date", "Version", "IlastikProject", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
21 "Preprocess"] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
22 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
23 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
24 def get_image_id(image_file_name): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
25 # Check the file name |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
26 # corresponds to the expected: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
27 match = \ |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
28 file_base_name_exportedTIFF.findall(image_file_name.replace(".tiff", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
29 "")) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
30 if len(match) == 0: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
31 match = \ |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
32 file_base_name_original.findall(image_file_name.replace(".tiff", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
33 "")) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
34 if len(match) == 0: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
35 raise Exception(f"{image_file_name} does not match" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
36 "the expected format") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
37 # Get the image_id |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
38 image_id = int(match[0]) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
39 return image_id |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
40 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
41 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
42 def get_omero_credentials(config_file): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
43 if config_file is None: # IDR connection |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
44 omero_username = "public" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
45 omero_password = "public" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
46 else: # other omero instance |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
47 with open(config_file) as f: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
48 cfg = json.load(f) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
49 omero_username = cfg["username"] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
50 omero_password = cfg["password"] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
51 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
52 if omero_username == "" or omero_password == "": |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
53 omero_username = "public" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
54 omero_password = "public" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
55 return (omero_username, omero_password) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
56 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
57 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
58 def clean(image_id, omero_username, omero_password, omero_host, omero_secured, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
59 verbose): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
60 with BlitzGateway( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
61 omero_username, omero_password, host=omero_host, secure=omero_secured |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
62 ) as conn: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
63 roi_service = conn.getRoiService() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
64 img = conn.getObject("Image", image_id) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
65 rois = roi_service.findByImage(image_id, None, conn.SERVICE_OPTS).rois |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
66 # Delete existing rois |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
67 if len(rois) > 0: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
68 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
69 print(f"Removing {len(rois)} existing ROIs.") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
70 conn.deleteObjects("Roi", [roi.getId().val |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
71 for roi |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
72 in rois], |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
73 wait=True) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
74 # Delete existing table named Results_from_Fiji |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
75 for ann in img.listAnnotations(): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
76 if ann.OMERO_TYPE == omero.model.FileAnnotationI: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
77 if ann.getFileName() == "Results_from_Fiji": |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
78 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
79 print("Removing the table Results_from_Fiji.") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
80 conn.deleteObjects("OriginalFile", [ann.getFile().id], |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
81 wait=True) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
82 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
83 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
84 def upload( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
85 image_id, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
86 df, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
87 roi_files, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
88 omero_username, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
89 omero_password, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
90 omero_host, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
91 omero_secured, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
92 verbose, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
93 ): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
94 with BlitzGateway( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
95 omero_username, omero_password, host=omero_host, secure=omero_secured |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
96 ) as conn: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
97 updateService = conn.getUpdateService() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
98 img = conn.getObject("Image", image_id) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
99 # Create ROIs: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
100 roi_ids = [] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
101 # roi_big_circle_ids = [] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
102 # roi_spine_ids = [] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
103 for i, ro_file in enumerate(roi_files): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
104 # Create a polygon |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
105 my_poly = omero.model.PolygonI() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
106 # Add the coordinates |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
107 with open(ro_file, "r") as f: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
108 coos = f.readlines() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
109 coos_formatted = ", ".join([line.strip().replace("\t", ",") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
110 for line in coos]) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
111 my_poly.setPoints(rstring(coos_formatted)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
112 # Add a name |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
113 my_poly.setTextValue(rstring("ROI" + str(i))) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
114 # Create a omero ROI |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
115 my_new_roi = omero.model.RoiI() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
116 my_new_roi.addShape(my_poly) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
117 # Attach it to the image |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
118 my_new_roi.setImage(img._obj) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
119 my_new_roi = updateService.saveAndReturnObject(my_new_roi) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
120 roi_ids.append(my_new_roi.getId().val) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
121 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
122 print(f"Created ROI{i} {my_new_roi.getId().val}.") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
123 # Check if there is an elongation ROI associated: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
124 if os.path.exists(ro_file.replace("roi_coordinates", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
125 "elongation_rois")): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
126 # Get the coordinates |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
127 with open( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
128 ro_file.replace("roi_coordinates", "elongation_rois"), |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
129 "r" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
130 ) as f: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
131 all_coos = f.readlines() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
132 # Get the circles coos |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
133 circles_coos = [line for line in all_coos |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
134 if len(line.split("\t")) == 3] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
135 for j, circle_coo in enumerate(circles_coos): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
136 # Create an ellipse |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
137 my_ellipse = omero.model.EllipseI() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
138 # Get the characteristics from text file |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
139 xleft, ytop, width = [ |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
140 float(v) for v in circle_coo.strip().split("\t") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
141 ] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
142 # Add it to the ellipse |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
143 my_ellipse.setRadiusX(rdouble(width / 2.0)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
144 my_ellipse.setRadiusY(rdouble(width / 2.0)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
145 my_ellipse.setX(rdouble(xleft + width / 2)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
146 my_ellipse.setY(rdouble(ytop + width / 2)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
147 # Add a name |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
148 my_ellipse.setTextValue( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
149 rstring("inscribedCircle" + str(i) + "_" + str(j)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
150 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
151 # Create a omero ROI |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
152 my_new_roi = omero.model.RoiI() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
153 my_new_roi.addShape(my_ellipse) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
154 # Attach it to the image |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
155 my_new_roi.setImage(img._obj) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
156 my_new_roi = updateService.saveAndReturnObject(my_new_roi) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
157 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
158 print( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
159 f"Created ROI inscribedCircle {i}_{j}:" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
160 f"{my_new_roi.getId().val}." |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
161 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
162 # I store the id of the first circle: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
163 # if j == 0: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
164 # roi_big_circle_ids.append(my_new_roi.getId().val) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
165 if len(all_coos) > len(circles_coos): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
166 # Create a polyline for the spine |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
167 my_poly = omero.model.PolylineI() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
168 coos_formatted = ", ".join( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
169 [ |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
170 line.strip().replace("\t", ",") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
171 for line in all_coos[len(circles_coos):] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
172 ] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
173 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
174 my_poly.setPoints(rstring(coos_formatted)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
175 # Add a name |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
176 my_poly.setTextValue(rstring("spine" + str(i))) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
177 # Create a omero ROI |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
178 my_new_roi = omero.model.RoiI() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
179 my_new_roi.addShape(my_poly) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
180 # Attach it to the image |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
181 my_new_roi.setImage(img._obj) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
182 my_new_roi = updateService.saveAndReturnObject(my_new_roi) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
183 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
184 print(f"Created ROI spine{i}:" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
185 f" {my_new_roi.getId().val}.") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
186 # roi_spine_ids.append(my_new_roi.getId().val) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
187 else: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
188 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
189 print("No spine found") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
190 # roi_spine_ids.append(non_roi_value) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
191 # else: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
192 # roi_big_circle_ids.append(non_roi_value) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
193 # roi_spine_ids.append(non_roi_value) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
194 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
195 # Create the table: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
196 table_name = "Results_from_Fiji" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
197 columns = [] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
198 for col_name in df.columns[1:]: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
199 if col_name in non_numeric_columns: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
200 columns.append(omero.grid.StringColumn(col_name, "", 256, [])) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
201 else: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
202 columns.append(omero.grid.DoubleColumn(col_name, "", [])) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
203 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
204 # From Claire's groovy: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
205 # table_columns[size] = new TableDataColumn("Roi", size, ROIData) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
206 columns.append(omero.grid.RoiColumn("Roi", "", [])) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
207 # For the moment (20220729), |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
208 # the table support only one ROI column with link... |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
209 # if 'Elongation_index' in df.columns[1:]: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
210 # columns.append(omero.grid.RoiColumn('Roi_maxCircle', '', [])) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
211 # columns.append(omero.grid.RoiColumn('Roi_Spine', '', [])) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
212 # columns.append(omero.grid.RoiColumn('Roi_main', '', [])) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
213 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
214 resources = conn.c.sf.sharedResources() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
215 repository_id = \ |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
216 resources.repositories().descriptions[0].getId().getValue() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
217 table = resources.newTable(repository_id, table_name) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
218 table.initialize(columns) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
219 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
220 data = [] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
221 for col_name in df.columns[1:]: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
222 if col_name in non_numeric_columns: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
223 data.append( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
224 omero.grid.StringColumn( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
225 col_name, "", 256, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
226 df[col_name].astype("string").to_list() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
227 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
228 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
229 else: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
230 data.append( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
231 omero.grid.DoubleColumn(col_name, "", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
232 df[col_name].to_list()) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
233 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
234 data.append(omero.grid.RoiColumn("Roi", "", roi_ids)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
235 # if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
236 # print("Columns are " + " ".join(df.columns[1:])) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
237 # if 'Elongation_index' in df.columns[1:]: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
238 # if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
239 # print("Adding 2 rois columns") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
240 # print(roi_ids) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
241 # print(roi_big_circle_ids) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
242 # data.append(omero.grid.RoiColumn('Roi_maxCircle', '', |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
243 # roi_big_circle_ids)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
244 # data.append(omero.grid.RoiColumn('Roi_Spine', '', |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
245 # roi_spine_ids)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
246 # data.append(omero.grid.RoiColumn('Roi_main', '', roi_ids)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
247 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
248 table.addData(data) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
249 orig_file = table.getOriginalFile() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
250 table.close() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
251 # when we are done, close. |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
252 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
253 # Load the table as an original file |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
254 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
255 orig_file_id = orig_file.id.val |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
256 # ...so you can attach this data to an object e.g. Image |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
257 file_ann = omero.model.FileAnnotationI() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
258 # use unloaded OriginalFileI |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
259 file_ann.setFile(omero.model.OriginalFileI(orig_file_id, False)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
260 file_ann = updateService.saveAndReturnObject(file_ann) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
261 link = omero.model.ImageAnnotationLinkI() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
262 link.setParent(omero.model.ImageI(image_id, False)) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
263 link.setChild(omero.model.FileAnnotationI( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
264 file_ann.getId().getValue(), False |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
265 )) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
266 updateService.saveAndReturnObject(link) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
267 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
268 print("Successfully created a Table with results.") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
269 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
270 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
271 def scan_and_upload( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
272 roi_directory, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
273 summary_results, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
274 omero_username, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
275 omero_password, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
276 omero_host="idr.openmicroscopy.org", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
277 omero_secured=False, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
278 verbose=False, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
279 ): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
280 # First get the summary results |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
281 full_df = pd.read_csv(summary_results) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
282 # Loop over the image names |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
283 for image_file_name in np.unique(full_df["Label"]): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
284 # Get the image_id |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
285 image_id = get_image_id(image_file_name) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
286 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
287 print(f"Image:{image_id} is in the table." |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
288 " Cleaning old results.") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
289 clean( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
290 image_id, omero_username, omero_password, omero_host, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
291 omero_secured, verbose |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
292 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
293 # Subset the result to the current image |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
294 df = full_df[full_df["Label"] == image_file_name] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
295 if np.isnan(df["Area"].to_list()[0]): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
296 # No ROI has been detected |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
297 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
298 print("No ROI was found.") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
299 continue |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
300 n_rois = df.shape[0] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
301 if verbose: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
302 print(f"I found {n_rois} measurements.") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
303 # Check the corresponding rois exists |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
304 roi_files = [ |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
305 os.path.join( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
306 roi_directory, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
307 image_file_name.replace(".tiff", "_tiff") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
308 + "__" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
309 + str(i) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
310 + "_roi_coordinates.txt", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
311 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
312 for i in range(n_rois) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
313 ] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
314 for ro_file in roi_files: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
315 if not os.path.exists(ro_file): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
316 raise Exception(f"Could not find {ro_file}") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
317 upload( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
318 image_id, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
319 df, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
320 roi_files, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
321 omero_username, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
322 omero_password, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
323 omero_host, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
324 omero_secured, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
325 verbose, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
326 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
327 # Update the full_df with image id: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
328 full_df["id"] = [ |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
329 get_image_id(image_file_name) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
330 for image_file_name in full_df["Label"] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
331 ] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
332 # Attach it to the dataset: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
333 with BlitzGateway( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
334 omero_username, omero_password, host=omero_host, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
335 secure=omero_secured |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
336 ) as conn: |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
337 full_df["dataset_id"] = [ |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
338 a.id |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
339 for id in full_df["id"] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
340 for a in conn.getObject("Image", id).getAncestry() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
341 if a.OMERO_CLASS == "Dataset" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
342 ] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
343 dir = tempfile.mkdtemp() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
344 for dataset_id in np.unique(full_df["dataset_id"]): |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
345 df = full_df[full_df["dataset_id"] == dataset_id] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
346 first_date = df["Date"].to_list()[0] |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
347 file_to_upload = os.path.join( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
348 dir, "Results_from_Fiji_" + first_date + ".csv" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
349 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
350 df.to_csv(file_to_upload, index=False) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
351 dataset = conn.getObject("Dataset", dataset_id) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
352 # create the original file and file annotation |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
353 # (uploads the file etc.) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
354 # namespace = "my.custom.demo.namespace" |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
355 file_ann = conn.createFileAnnfromLocalFile( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
356 file_to_upload |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
357 ) # , mimetype="text/plain", ns=namespace, desc=None) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
358 print( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
359 "Attaching FileAnnotation to Dataset: ", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
360 "File ID:", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
361 file_ann.getId(), |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
362 ",", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
363 file_ann.getFile().getName(), |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
364 "Size:", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
365 file_ann.getFile().getSize(), |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
366 ) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
367 dataset.linkAnnotation(file_ann) # link it to dataset. |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
368 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
369 |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
370 if __name__ == "__main__": |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
371 p = argparse.ArgumentParser() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
372 p.add_argument("-oh", "--omero-host", type=str, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
373 default="idr.openmicroscopy.org") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
374 p.add_argument("--omero-secured", action="store_true", default=True) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
375 p.add_argument("-cf", "--config-file", dest="config_file", |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
376 default=None) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
377 p.add_argument("--rois", type=str, default=None) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
378 p.add_argument("--summaryResults", type=str, default=None) |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
379 p.add_argument("--verbose", action="store_true") |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
380 args = p.parse_args() |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
381 scan_and_upload( |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
382 args.rois, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
383 args.summaryResults, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
384 *get_omero_credentials(args.config_file), |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
385 omero_host=args.omero_host, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
386 omero_secured=args.omero_secured, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
387 verbose=args.verbose, |
d507ce86f0d0
planemo upload for repository https://github.com/lldelisle/tools-lldelisle/tree/master/tools/upload_roi_and_measures_to_omero commit 68de74426a3f93a240d64cb416f608ba7caca6eb
lldelisle
parents:
diff
changeset
|
388 ) |