diff svm.xml @ 25:b878e4cdd63a draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
author bgruening
date Wed, 09 Aug 2023 12:24:57 +0000
parents d67dcd63f6cb
children
line wrap: on
line diff
--- a/svm.xml	Thu Aug 11 09:40:47 2022 +0000
+++ b/svm.xml	Wed Aug 09 12:24:57 2023 +0000
@@ -1,4 +1,4 @@
-<tool id="sklearn_svm_classifier" name="Support vector machines (SVMs)" version="@VERSION@" profile="20.05">
+<tool id="sklearn_svm_classifier" name="Support vector machines (SVMs)" version="@VERSION@" profile="@PROFILE@">
     <description>for classification</description>
     <macros>
         <import>main_macros.xml</import>
@@ -19,9 +19,9 @@
 import json
 import sklearn.svm
 import pandas
-import pickle
 
-from galaxy_ml.utils import load_model, get_X_y
+from galaxy_ml.model_persist import dump_model_to_h5, load_model_from_h5
+from galaxy_ml.utils import clean_params, get_X_y
 
 
 input_json_path = sys.argv[1]
@@ -33,8 +33,8 @@
 header = 'infer' if params["selected_tasks"]["header"] else None
 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=header, index_col=None, parse_dates=True, encoding=None)
 
-with open("$infile_model", 'rb') as model_handler:
-    classifier_object = load_model(model_handler)
+classifier_object = load_model_from_h5('$infile_model')
+classifier_object = clean_params(classifier_object)
 
 prediction = classifier_object.predict(data)
 prediction_df = pandas.DataFrame(prediction)
@@ -56,8 +56,7 @@
 classifier_object = my_class(**options)
 classifier_object.fit(X, y)
 
-with open("$outfile_fit", 'wb') as out_handler:
-    pickle.dump(classifier_object, out_handler)
+dump_model_to_h5(classifier_object, '$outfile_fit')
 
 #end if
 
@@ -65,7 +64,7 @@
         </configfile>
     </configfiles>
     <inputs>
-        <expand macro="sl_Conditional" model="zip">
+        <expand macro="sl_Conditional" model="h5mlm">
             <param name="selected_algorithm" type="select" label="Classifier type">
                 <option value="SVC">C-Support Vector Classification</option>
                 <option value="NuSVC">Nu-Support Vector Classification</option>
@@ -149,30 +148,29 @@
             <output name="outfile_fit" file="svc_model03" compare="sim_size" />
         </test>
         <test>
-            <param name="infile_model" value="svc_model01" ftype="zip" />
+            <param name="infile_model" value="svc_model01" ftype="h5mlm" />
             <param name="infile_data" value="test_set.tabular" ftype="tabular" />
             <param name="header" value="True" />
             <param name="selected_task" value="load" />
             <output name="outfile_predict" file="svc_prediction_result01.tabular" />
         </test>
         <test>
-            <param name="infile_model" value="svc_model02" ftype="zip" />
+            <param name="infile_model" value="svc_model02" ftype="h5mlm" />
             <param name="infile_data" value="test_set.tabular" ftype="tabular" />
             <param name="header" value="True" />
             <param name="selected_task" value="load" />
             <output name="outfile_predict" file="svc_prediction_result02.tabular" />
         </test>
         <test>
-            <param name="infile_model" value="svc_model03" ftype="zip" />
+            <param name="infile_model" value="svc_model03" ftype="h5mlm" />
             <param name="infile_data" value="test_set.tabular" ftype="tabular" />
-            <param name="header" value="True" />
             <param name="selected_task" value="load" />
             <output name="outfile_predict" file="svc_prediction_result03.tabular" />
         </test>
         <!-- The following test is expected to fail, it is testing the whitelist/blacklist filtering.
         It loads a pickle with malicious content that we do not accept. -->
         <test expect_failure="true">
-            <param name="infile_model" value="pickle_blacklist" ftype="zip" />
+            <param name="infile_model" value="unsafe_model.h5mlm" />
             <param name="infile_data" value="test_set.tabular" ftype="tabular" />
             <param name="header" value="True" />
             <param name="selected_task" value="load" />