comparison simple_model_fit.py @ 37:913bf1c4c7bb draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
author bgruening
date Sat, 01 May 2021 01:18:07 +0000
parents 616a241c5b37
children fe181d613429
comparison
equal deleted inserted replaced
36:616a241c5b37 37:913bf1c4c7bb
4 4
5 import pandas as pd 5 import pandas as pd
6 from galaxy_ml.utils import load_model, read_columns 6 from galaxy_ml.utils import load_model, read_columns
7 from scipy.io import mmread 7 from scipy.io import mmread
8 from sklearn.pipeline import Pipeline 8 from sklearn.pipeline import Pipeline
9
10 9
11 N_JOBS = int(__import__("os").environ.get("GALAXY_SLOTS", 1)) 10 N_JOBS = int(__import__("os").environ.get("GALAXY_SLOTS", 1))
12 11
13 12
14 # TODO import from galaxy_ml.utils in future versions 13 # TODO import from galaxy_ml.utils in future versions
34 for name, p in estimator_params.items(): 33 for name, p in estimator_params.items():
35 # all potential unauthorized file write 34 # all potential unauthorized file write
36 if name == "memory" or name.endswith("__memory") or name.endswith("_path"): 35 if name == "memory" or name.endswith("__memory") or name.endswith("_path"):
37 new_p = {name: None} 36 new_p = {name: None}
38 estimator.set_params(**new_p) 37 estimator.set_params(**new_p)
39 elif n_jobs is not None and (name == 'n_jobs' or name.endswith('__n_jobs')): 38 elif n_jobs is not None and (name == "n_jobs" or name.endswith("__n_jobs")):
40 new_p = {name: n_jobs} 39 new_p = {name: n_jobs}
41 estimator.set_params(**new_p) 40 estimator.set_params(**new_p)
42 elif name.endswith("callbacks"): 41 elif name.endswith("callbacks"):
43 for cb in p: 42 for cb in p:
44 cb_type = cb["callback_selection"]["callback_type"] 43 cb_type = cb["callback_selection"]["callback_type"]
66 65
67 input_type = params["input_options"]["selected_input"] 66 input_type = params["input_options"]["selected_input"]
68 # tabular input 67 # tabular input
69 if input_type == "tabular": 68 if input_type == "tabular":
70 header = "infer" if params["input_options"]["header1"] else None 69 header = "infer" if params["input_options"]["header1"] else None
71 column_option = params["input_options"]["column_selector_options_1"]["selected_column_selector_option"] 70 column_option = params["input_options"]["column_selector_options_1"][
71 "selected_column_selector_option"
72 ]
72 if column_option in [ 73 if column_option in [
73 "by_index_number", 74 "by_index_number",
74 "all_but_by_index_number", 75 "all_but_by_index_number",
75 "by_header_name", 76 "by_header_name",
76 "all_but_by_header_name", 77 "all_but_by_header_name",
88 elif input_type == "sparse": 89 elif input_type == "sparse":
89 X = mmread(open(infile1, "r")) 90 X = mmread(open(infile1, "r"))
90 91
91 # Get target y 92 # Get target y
92 header = "infer" if params["input_options"]["header2"] else None 93 header = "infer" if params["input_options"]["header2"] else None
93 column_option = params["input_options"]["column_selector_options_2"]["selected_column_selector_option2"] 94 column_option = params["input_options"]["column_selector_options_2"][
95 "selected_column_selector_option2"
96 ]
94 if column_option in [ 97 if column_option in [
95 "by_index_number", 98 "by_index_number",
96 "all_but_by_index_number", 99 "all_but_by_index_number",
97 "by_header_name", 100 "by_header_name",
98 "all_but_by_header_name", 101 "all_but_by_header_name",
106 infile2 = loaded_df[df_key] 109 infile2 = loaded_df[df_key]
107 else: 110 else:
108 infile2 = pd.read_csv(infile2, sep="\t", header=header, parse_dates=True) 111 infile2 = pd.read_csv(infile2, sep="\t", header=header, parse_dates=True)
109 loaded_df[df_key] = infile2 112 loaded_df[df_key] = infile2
110 113
111 y = read_columns(infile2, 114 y = read_columns(
112 c=c, 115 infile2, c=c, c_option=column_option, sep="\t", header=header, parse_dates=True
113 c_option=column_option, 116 )
114 sep='\t',
115 header=header,
116 parse_dates=True)
117 if len(y.shape) == 2 and y.shape[1] == 1: 117 if len(y.shape) == 2 and y.shape[1] == 1:
118 y = y.ravel() 118 y = y.ravel()
119 119
120 return X, y 120 return X, y
121 121