comparison main_macros.xml @ 18:21fdd6cdb88f draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit b1e5fa3170484d2cc3396f2abe99bb8cfcfa9c65
author bgruening
date Tue, 07 Aug 2018 05:48:10 -0400
parents 0b57ef8831fb
children 98b632c407ae
comparison
equal deleted inserted replaced
17:f0340a2279d7 18:21fdd6cdb88f
98 ) 98 )
99 y=y.ravel() 99 y=y.ravel()
100 return X, y 100 return X, y
101 </token> 101 </token>
102 102
103 <token name="@SAFE_EVAL_FUNCTION@">
104 def safe_eval(literal):
105
106 FROM_SCIPY_STATS = [ 'bernoulli', 'binom', 'boltzmann', 'dlaplace', 'geom', 'hypergeom',
107 'logser', 'nbinom', 'planck', 'poisson', 'randint', 'skellam', 'zipf' ]
108
109 FROM_NUMPY_RANDOM = [ 'beta', 'binomial', 'bytes', 'chisquare', 'choice', 'dirichlet', 'division',
110 'exponential', 'f', 'gamma', 'geometric', 'gumbel', 'hypergeometric',
111 'laplace', 'logistic', 'lognormal', 'logseries', 'mtrand', 'multinomial',
112 'multivariate_normal', 'negative_binomial', 'noncentral_chisquare', 'noncentral_f',
113 'normal', 'pareto', 'permutation', 'poisson', 'power', 'rand', 'randint',
114 'randn', 'random', 'random_integers', 'random_sample', 'ranf', 'rayleigh',
115 'sample', 'seed', 'set_state', 'shuffle', 'standard_cauchy', 'standard_exponential',
116 'standard_gamma', 'standard_normal', 'standard_t', 'triangular', 'uniform',
117 'vonmises', 'wald', 'weibull', 'zipf' ]
118
119 # File opening and other unneeded functions could be dropped
120 UNWANTED = ['open', 'type', 'dir', 'id', 'str', 'repr']
121
122 # Allowed symbol table. Add more if needed.
123 new_syms = {
124 'np_arange': getattr(np, 'arange'),
125 'ensemble_ExtraTreesClassifier': getattr(ensemble, 'ExtraTreesClassifier')
126 }
127
128 syms = make_symbol_table(use_numpy=False, **new_syms)
129
130 for method in FROM_SCIPY_STATS:
131 syms['scipy_stats_' + method] = getattr(scipy.stats, method)
132
133 for func in FROM_NUMPY_RANDOM:
134 syms['np_random_' + func] = getattr(np.random, func)
135
136 for key in UNWANTED:
137 syms.pop(key, None)
138
139 aeval = Interpreter(symtable=syms, use_numpy=False, minimal=False,
140 no_if=True, no_for=True, no_while=True, no_try=True,
141 no_functiondef=True, no_ifexp=True, no_listcomp=False,
142 no_augassign=False, no_assert=True, no_delete=True,
143 no_raise=True, no_print=True)
144
145 return aeval(literal)
146 </token>
147
103 <token name="@GET_SEARCH_PARAMS_FUNCTION@"> 148 <token name="@GET_SEARCH_PARAMS_FUNCTION@">
104 def get_search_params(params_builder): 149 def get_search_params(params_builder):
105 search_params = {} 150 search_params = {}
106
107 def safe_eval(literal):
108
109 FROM_SCIPY_STATS = [ 'bernoulli', 'binom', 'boltzmann', 'dlaplace', 'geom', 'hypergeom',
110 'logser', 'nbinom', 'planck', 'poisson', 'randint', 'skellam', 'zipf' ]
111
112 FROM_NUMPY_RANDOM = [ 'beta', 'binomial', 'bytes', 'chisquare', 'choice', 'dirichlet', 'division',
113 'exponential', 'f', 'gamma', 'geometric', 'gumbel', 'hypergeometric',
114 'laplace', 'logistic', 'lognormal', 'logseries', 'mtrand', 'multinomial',
115 'multivariate_normal', 'negative_binomial', 'noncentral_chisquare', 'noncentral_f',
116 'normal', 'pareto', 'permutation', 'poisson', 'power', 'rand', 'randint',
117 'randn', 'random', 'random_integers', 'random_sample', 'ranf', 'rayleigh',
118 'sample', 'seed', 'set_state', 'shuffle', 'standard_cauchy', 'standard_exponential',
119 'standard_gamma', 'standard_normal', 'standard_t', 'triangular', 'uniform',
120 'vonmises', 'wald', 'weibull', 'zipf' ]
121
122 # File opening and other unneeded functions could be dropped
123 UNWANTED = ['open', 'type', 'dir', 'id', 'str', 'repr']
124
125 # Allowed symbol table. Add more if needed.
126 new_syms = {
127 'np_arange': getattr(np, 'arange'),
128 'ensemble_ExtraTreesClassifier': getattr(ensemble, 'ExtraTreesClassifier')
129 }
130
131 syms = make_symbol_table(use_numpy=False, **new_syms)
132
133 for method in FROM_SCIPY_STATS:
134 syms['scipy_stats_' + method] = getattr(scipy.stats, method)
135
136 for func in FROM_NUMPY_RANDOM:
137 syms['np_random_' + func] = getattr(np.random, func)
138
139 for key in UNWANTED:
140 syms.pop(key, None)
141
142 aeval = Interpreter(symtable=syms, use_numpy=False, minimal=False,
143 no_if=True, no_for=True, no_while=True, no_try=True,
144 no_functiondef=True, no_ifexp=True, no_listcomp=False,
145 no_augassign=False, no_assert=True, no_delete=True,
146 no_raise=True, no_print=True)
147
148 return aeval(literal)
149 151
150 for p in params_builder['param_set']: 152 for p in params_builder['param_set']:
151 search_p = p['search_param_selector']['search_p'] 153 search_p = p['search_param_selector']['search_p']
152 if search_p.strip() == '': 154 if search_p.strip() == '':
153 continue 155 continue
185 except ValueError: 187 except ValueError:
186 sys.exit("Unsupported parameter input: `%s`" %estimator_params) 188 sys.exit("Unsupported parameter input: `%s`" %estimator_params)
187 estimator.set_params(**params) 189 estimator.set_params(**params)
188 190
189 return estimator 191 return estimator
192 </token>
193
194 <token name="@GET_CV_FUNCTION@">
195 def get_cv(literal):
196 if literal == "":
197 return None
198 if re.match(r'^\d+$', literal):
199 return int(literal)
200 m = re.match(r'^(?P&lt;method&gt;\w+)\((?P&lt;args&gt;.*)\)$', literal)
201 if m:
202 my_class = getattr( model_selection, m.group('method') )
203 args = safe_eval( 'dict('+ m.group('args') + ')' )
204 return my_class( **args )
205 sys.exit("Unsupported CV input: %s" %literal)
190 </token> 206 </token>
191 207
192 <xml name="python_requirements"> 208 <xml name="python_requirements">
193 <requirements> 209 <requirements>
194 <requirement type="package" version="2.7">python</requirement> 210 <requirement type="package" version="2.7">python</requirement>
1141 </when> 1157 </when>
1142 </conditional> 1158 </conditional>
1143 </xml> 1159 </xml>
1144 1160
1145 <xml name="model_validation_common_options"> 1161 <xml name="model_validation_common_options">
1146 <param argument="cv" type="integer" value="" optional="true" label="cv" help="The number of folds in a (Stratified)KFold" /> 1162 <param argument="cv" type="text" value="" size="50" optional="true" label="cv" help="Optional. Integer or evalable splitter object, e.g., StratifiedKFold(n_splits=3, shuffle=True, random_state=10). Leave blank for default." />
1147 <expand macro="n_jobs"/> 1163 <expand macro="n_jobs"/>
1148 <expand macro="verbose"/> 1164 <expand macro="verbose"/>
1149 <yield/> 1165 <yield/>
1150 </xml> 1166 </xml>
1151 1167