changeset 3:97bc82ee2a61 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools commit 743c8acf1ea4e4b1e718743d3772b7e592646611
author bgruening
date Mon, 14 Jul 2025 18:28:46 +0000
parents 158e6ce48345
children f6990d85161c
files macros.xml preprocessing.py yolov8.py
diffstat 3 files changed, 13 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/macros.xml	Fri Jul 11 06:49:20 2025 +0000
+++ b/macros.xml	Mon Jul 14 18:28:46 2025 +0000
@@ -1,6 +1,6 @@
 <macros>
     <token name="@TOOL_VERSION@">8.3.0</token>
-    <token name="@VERSION_SUFFIX@">2</token>
+    <token name="@VERSION_SUFFIX@">3</token>
     <xml name="creator">
         <creator>
             <person name="Yi Sun" email="sunyi000@gmail.com" />
--- a/preprocessing.py	Fri Jul 11 06:49:20 2025 +0000
+++ b/preprocessing.py	Mon Jul 14 18:28:46 2025 +0000
@@ -1,6 +1,5 @@
 import argparse
 import os
-import shutil
 
 from sklearn.model_selection import train_test_split
 
@@ -22,12 +21,21 @@
     return [(image_dict[k], label_dict[k]) for k in keys]
 
 
+def copy_file(src, dst):
+    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
+        while True:
+            chunk = fsrc.read(8192)
+            if not chunk:
+                break
+            fdst.write(chunk)
+
+
 def copy_pairs(pairs, image_src, label_src, image_dst, label_dst):
     os.makedirs(image_dst, exist_ok=True)
     os.makedirs(label_dst, exist_ok=True)
     for img, lbl in pairs:
-        shutil.copy(os.path.join(image_src, img), os.path.join(image_dst, img))
-        shutil.copy(os.path.join(label_src, lbl), os.path.join(label_dst, lbl))
+        copy_file(os.path.join(image_src, img), os.path.join(image_dst, img))
+        copy_file(os.path.join(label_src, lbl), os.path.join(label_dst, lbl))
 
 
 def write_yolo_yaml(output_dir):
--- a/yolov8.py	Fri Jul 11 06:49:20 2025 +0000
+++ b/yolov8.py	Mon Jul 14 18:28:46 2025 +0000
@@ -1,7 +1,6 @@
 import argparse
 import os
 import pathlib
-import shutil
 import time
 from argparse import RawTextHelpFormatter
 from collections import defaultdict
@@ -175,15 +174,6 @@
 #
 # Functions
 #
-
-def safe_rmtree(path):
-    try:
-        shutil.rmtree(path)
-    except OSError:
-        time.sleep(1)
-        shutil.rmtree(path, ignore_errors=True)
-
-
 # Train a new model on the dataset mentioned in yaml file
 def trainModel(model_path, model_name, yaml_filepath, **kwargs):
     if "imgsz" in kwargs:
@@ -271,9 +261,6 @@
     else:
         init_lr = 1.0
 
-    train_save_path = os.path.expanduser('~/runs/' + args.mode + '/train/')
-    if os.path.isdir(train_save_path):
-        safe_rmtree(train_save_path)
     # Load a pretrained YOLO model (recommended for training)
     if args.model_format == 'pt':
         model = YOLO(os.path.join(model_path, model_name + "." + args.model_format))
@@ -291,10 +278,6 @@
 
 # Validate the trained model
 def validateModel(model):
-    # Remove prediction save path if already exists
-    val_save_path = os.path.expanduser('~/runs/' + args.mode + '/val/')
-    if os.path.isdir(val_save_path):
-        safe_rmtree(val_save_path)
     # Validate the model
     metrics = model.val()  # no args needed, dataset & settings remembered
     metrics.box.map    # map50-95
@@ -330,13 +313,7 @@
     else:
         maximum_detections = 300
 
-    if "run_dir" in kwargs:
-        run_save_dir = kwargs['run_dir']
-    else:
-        # Remove prediction save path if already exists
-        pred_save_path = os.path.expanduser('~/runs/' + args.mode + '/predict/')
-        if os.path.isdir(pred_save_path):
-            safe_rmtree(pred_save_path)
+    run_save_dir = kwargs['run_dir']  # For Galaxy, run_save_dir is always provided via xml wrapper
     if "foldername" in kwargs:
         save_folder_name = kwargs['foldername']
     # infer on a local image or directory containing images/videos