diff ensemble.xml @ 15:f02eeabab5d1 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit f54ff2ba2f8e7542d68966ce5a6b17d7f624ac48
author bgruening
date Fri, 13 Jul 2018 03:55:19 -0400
parents 84724d805bfa
children 4570575d060c
line wrap: on
line diff
--- a/ensemble.xml	Tue Jul 10 03:11:34 2018 -0400
+++ b/ensemble.xml	Fri Jul 13 03:55:19 2018 -0400
@@ -27,8 +27,9 @@
 
 # Get inputs, outputs.
 input_json_path = sys.argv[1]
-params = json.load(open(input_json_path, "r"))
-print params
+with open(input_json_path, "r") as param_handler:
+    params = json.load(param_handler)
+print(params)
 
 # Put all cheetah up here to avoid confusion.
 #if $selected_tasks.selected_task == "train":
@@ -63,14 +64,16 @@
         options["min_samples_split"] = int(options["min_samples_split"])
 
     X, y = get_X_y(params, infile1, infile2)
-                   
+
     my_class = getattr(sklearn.ensemble, algorithm)
     estimator = my_class(**options)
     estimator.fit(X,y)
-    pickle.dump(estimator,open(outfile_fit, 'w+'), pickle.HIGHEST_PROTOCOL)
+    with open(outfile_fit, 'wb') as out_handler:
+        pickle.dump(estimator, out_handler, pickle.HIGHEST_PROTOCOL)
 
 else:
-    classifier_object = pickle.load(open(infile_model, 'r'))
+    with open(infile_model, 'rb') as model_handler:
+        classifier_object = pickle.load(model_handler)
     header = 'infer' if params["selected_tasks"]["header"] else None
     data = pandas.read_csv(infile_data, sep='\t', header=header, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False)
     prediction = classifier_object.predict(data)