comparison generalized_linear.xml @ 15:f0e215cbade3 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit f54ff2ba2f8e7542d68966ce5a6b17d7f624ac48
author bgruening
date Fri, 13 Jul 2018 03:56:33 -0400
parents 10a8543142fc
children a259111a305a
comparison
equal deleted inserted replaced
14:10a8543142fc 15:f0e215cbade3
24 24
25 @COLUMNS_FUNCTION@ 25 @COLUMNS_FUNCTION@
26 @GET_X_y_FUNCTION@ 26 @GET_X_y_FUNCTION@
27 27
28 input_json_path = sys.argv[1] 28 input_json_path = sys.argv[1]
29 params = json.load(open(input_json_path, "r")) 29 with open(input_json_path, "r") as param_handler:
30 params = json.load(param_handler)
30 31
31 #if $selected_tasks.selected_task == "train": 32 #if $selected_tasks.selected_task == "train":
32 33
33 X, y = get_X_y(params, "$selected_tasks.selected_algorithms.input_options.infile1" ,"$selected_tasks.selected_algorithms.input_options.infile2") 34 X, y = get_X_y(params, "$selected_tasks.selected_algorithms.input_options.infile1" ,"$selected_tasks.selected_algorithms.input_options.infile2")
34 35
36 options = params["selected_tasks"]["selected_algorithms"]["options"] 37 options = params["selected_tasks"]["selected_algorithms"]["options"]
37 38
38 my_class = getattr(sklearn.linear_model, algorithm) 39 my_class = getattr(sklearn.linear_model, algorithm)
39 estimator = my_class(**options) 40 estimator = my_class(**options)
40 estimator.fit(X,y) 41 estimator.fit(X,y)
41 pickle.dump(estimator,open("$outfile_fit", 'w+'), pickle.HIGHEST_PROTOCOL) 42 with open("$outfile_fit", 'wb') as out_handler:
43 pickle.dump(estimator, out_handler, pickle.HIGHEST_PROTOCOL)
42 44
43 #else: 45 #else:
44 classifier_object = pickle.load(open("$selected_tasks.infile_model", 'r')) 46 with open("$selected_tasks.infile_model", 'rb') as model_handler:
47 classifier_object = pickle.load(model_handler)
45 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=None, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False ) 48 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=None, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False )
46 prediction = classifier_object.predict(data) 49 prediction = classifier_object.predict(data)
47 prediction_df = pandas.DataFrame(prediction, columns=["predicted"]) 50 prediction_df = pandas.DataFrame(prediction, columns=["predicted"])
48 res = pandas.concat([data, prediction_df], axis=1) 51 res = pandas.concat([data, prediction_df], axis=1)
49 res.to_csv(path_or_buf = "$outfile_predict", sep="\t", index=False, header=None) 52 res.to_csv(path_or_buf = "$outfile_predict", sep="\t", index=False, header=None)