diff omero_roi_upload.py @ 2:e41f70e69349 draft

planemo upload for repository https://github.com/Helmholtz-UFZ/galaxy-tools/tree/main/tools/omero commit 266752b0162fbdb32f132a6702cb661ae36f48f0
author ufz
date Thu, 12 Sep 2024 16:30:50 +0000
parents 588d6fa22fc4
children
line wrap: on
line diff
--- a/omero_roi_upload.py	Thu Sep 05 11:55:55 2024 +0000
+++ b/omero_roi_upload.py	Thu Sep 12 16:30:50 2024 +0000
@@ -1,6 +1,8 @@
 import argparse
+import json
 import re
 
+import numpy as np
 import pandas as pd
 from ezomero import connect, post_roi
 from ezomero.rois import Ellipse, Label, Line, Point, Polygon, Polyline, Rectangle
@@ -35,6 +37,7 @@
             z=row.get('z'),
             c=row.get('c'),
             t=row.get('t'),
+            label=row.get('label'),
             fill_color=parse_color(row.get('fill_color')),
             stroke_color=parse_color(row.get('stroke_color')),
             stroke_width=row.get('stroke_width')
@@ -60,7 +63,7 @@
             y2=row['y2'],
             markerStart=row.get('markerStart', None),
             markerEnd=row.get('markerEnd', None),
-            label=row.get('label', None),
+            label=row.get('label'),
             z=row.get('z'),
             c=row.get('c'),
             t=row.get('t'),
@@ -75,6 +78,7 @@
             z=row.get('z'),
             c=row.get('c'),
             t=row.get('t'),
+            label=row.get('label'),
             fill_color=parse_color(row.get('fill_color')),
             stroke_color=parse_color(row.get('stroke_color')),
             stroke_width=row.get('stroke_width')
@@ -85,6 +89,7 @@
             z=row.get('z'),
             c=row.get('c'),
             t=row.get('t'),
+            label=row.get('label'),
             fill_color=parse_color(row.get('fill_color')),
             stroke_color=parse_color(row.get('stroke_color')),
             stroke_width=row.get('stroke_width')
@@ -95,6 +100,7 @@
             z=row.get('z'),
             c=row.get('c'),
             t=row.get('t'),
+            label=row.get('label'),
             fill_color=parse_color(row.get('fill_color')),
             stroke_color=parse_color(row.get('stroke_color')),
             stroke_width=row.get('stroke_width')
@@ -108,6 +114,7 @@
             z=row.get('z'),
             c=row.get('c'),
             t=row.get('t'),
+            label=row.get('label'),
             fill_color=parse_color(row.get('fill_color')),
             stroke_color=parse_color(row.get('stroke_color')),
             stroke_width=row.get('stroke_width')
@@ -119,6 +126,8 @@
     # Open log file
     with open(log_file, 'w') as log:
         df = pd.read_csv(input_file, sep='\t')
+        # Replace nan to none
+        df = df.replace({np.nan: None})
         for index, row in df.iterrows():
             msg = f"Processing row {index + 1}/{len(df)}: {row.to_dict()}"
             print(msg)
@@ -143,17 +152,19 @@
     parser.add_argument("--input_file", help="Path to the input tabular file.")
     parser.add_argument("--image_id", type=int, required=True, help="ID of the image to which the ROI will be linked")
     parser.add_argument("--host", type=str, required=True, help="OMERO server host")
-    parser.add_argument("--user", type=str, required=True, help="OMERO username")
-    parser.add_argument("--psw", type=str, required=True, help="OMERO password")
+    parser.add_argument("--credential-file", dest="credential_file", type=str, required=True, help="Credential file (JSON file with username and password for OMERO)")
     parser.add_argument("--port", type=int, default=4064, help="OMERO server port")
     parser.add_argument("--log_file", type=str, default="process.txt", help="Log file path")
 
     args = parser.parse_args()
 
+    with open(args.credential_file, 'r') as f:
+        crds = json.load(f)
+
     conn = connect(
         host=args.host,
-        user=args.user,
-        password=args.psw,
+        user=crds['username'],
+        password=crds['password'],
         port=args.port,
         group="",
         secure=True