annotate keras_deep_learning.py @ 42:1c95e2935e52 draft

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ea12f973df4b97a2691d9e4ce6bf6fae59d57717"
author bgruening
date Fri, 30 Apr 2021 23:26:31 +0000
parents 156835c25f62
children 0e4066f5751d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
1 import argparse
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
2 import json
40
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
3 import pickle
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
4 import warnings
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
5 from ast import literal_eval
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
6
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
7 import keras
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
8 import pandas as pd
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
9 import six
40
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
10 from galaxy_ml.utils import get_search_params, SafeEval, try_get_attr
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
11 from keras.models import Model, Sequential
33
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
12
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
13 safe_eval = SafeEval()
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
14
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
15
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
16 def _handle_shape(literal):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
17 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
18 Eval integer or list/tuple of integers from string
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
19
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
20 Parameters:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
21 -----------
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
22 literal : str.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
23 """
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
24 literal = literal.strip()
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
25 if not literal:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
26 return None
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
27 try:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
28 return literal_eval(literal)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
29 except NameError as e:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
30 print(e)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
31 return literal
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
33
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
34 def _handle_regularizer(literal):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
35 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
36 Construct regularizer from string literal
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
37
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
38 Parameters
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
39 ----------
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
40 literal : str. E.g. '(0.1, 0)'
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
41 """
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
42 literal = literal.strip()
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
43 if not literal:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
44 return None
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
45
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
46 l1, l2 = literal_eval(literal)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
47
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
48 if not l1 and not l2:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
49 return None
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
50
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
51 if l1 is None:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
52 l1 = 0.0
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
53 if l2 is None:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
54 l2 = 0.0
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
55
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
56 return keras.regularizers.l1_l2(l1=l1, l2=l2)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
57
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
58
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
59 def _handle_constraint(config):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
60 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
61 Construct constraint from galaxy tool parameters.
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
62 Suppose correct dictionary format
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
63
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
64 Parameters
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
65 ----------
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
66 config : dict. E.g.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
67 "bias_constraint":
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
68 {"constraint_options":
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
69 {"max_value":1.0,
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
70 "min_value":0.0,
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
71 "axis":"[0, 1, 2]"
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
72 },
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
73 "constraint_type":
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
74 "MinMaxNorm"
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
75 }
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
76 """
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
77 constraint_type = config["constraint_type"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
78 if constraint_type in ("None", ""):
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
79 return None
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
80
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
81 klass = getattr(keras.constraints, constraint_type)
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
82 options = config.get("constraint_options", {})
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
83 if "axis" in options:
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
84 options["axis"] = literal_eval(options["axis"])
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
85
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
86 return klass(**options)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
87
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
88
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
89 def _handle_lambda(literal):
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
90 return None
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
91
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
92
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
93 def _handle_layer_parameters(params):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
94 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
95 Access to handle all kinds of parameters
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
96 """
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
97 for key, value in six.iteritems(params):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
98 if value in ("None", ""):
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
99 params[key] = None
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
100 continue
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
101
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
102 if type(value) in [int, float, bool] or (
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
103 type(value) is str and value.isalpha()
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
104 ):
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
105 continue
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
106
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
107 if (
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
108 key
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
109 in [
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
110 "input_shape",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
111 "noise_shape",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
112 "shape",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
113 "batch_shape",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
114 "target_shape",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
115 "dims",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
116 "kernel_size",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
117 "strides",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
118 "dilation_rate",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
119 "output_padding",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
120 "cropping",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
121 "size",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
122 "padding",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
123 "pool_size",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
124 "axis",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
125 "shared_axes",
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
126 ]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
127 and isinstance(value, str)
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
128 ):
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
129 params[key] = _handle_shape(value)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
130
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
131 elif key.endswith("_regularizer") and isinstance(value, dict):
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
132 params[key] = _handle_regularizer(value)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
133
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
134 elif key.endswith("_constraint") and isinstance(value, dict):
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
135 params[key] = _handle_constraint(value)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
136
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
137 elif key == "function": # No support for lambda/function eval
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
138 params.pop(key)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
139
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
140 return params
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
141
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
142
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
143 def get_sequential_model(config):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
144 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
145 Construct keras Sequential model from Galaxy tool parameters
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
146
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
147 Parameters:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
148 -----------
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
149 config : dictionary, galaxy tool parameters loaded by JSON
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
150 """
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
151 model = Sequential()
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
152 input_shape = _handle_shape(config["input_shape"])
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
153 layers = config["layers"]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
154 for layer in layers:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
155 options = layer["layer_selection"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
156 layer_type = options.pop("layer_type")
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
157 klass = getattr(keras.layers, layer_type)
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
158 kwargs = options.pop("kwargs", "")
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
159
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
160 # parameters needs special care
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
161 options = _handle_layer_parameters(options)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
162
33
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
163 if kwargs:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
164 kwargs = safe_eval("dict(" + kwargs + ")")
33
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
165 options.update(kwargs)
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
166
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
167 # add input_shape to the first layer only
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
168 if not getattr(model, "_layers") and input_shape is not None:
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
169 options["input_shape"] = input_shape
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
170
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
171 model.add(klass(**options))
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
172
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
173 return model
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
174
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
175
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
176 def get_functional_model(config):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
177 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
178 Construct keras functional model from Galaxy tool parameters
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
179
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
180 Parameters
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
181 -----------
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
182 config : dictionary, galaxy tool parameters loaded by JSON
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
183 """
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
184 layers = config["layers"]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
185 all_layers = []
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
186 for layer in layers:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
187 options = layer["layer_selection"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
188 layer_type = options.pop("layer_type")
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
189 klass = getattr(keras.layers, layer_type)
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
190 inbound_nodes = options.pop("inbound_nodes", None)
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
191 kwargs = options.pop("kwargs", "")
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
192
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
193 # parameters needs special care
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
194 options = _handle_layer_parameters(options)
33
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
195
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
196 if kwargs:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
197 kwargs = safe_eval("dict(" + kwargs + ")")
33
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
198 options.update(kwargs)
fbd849199283 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ba6a47bdf76bbf4cb276206ac1a8cbf61332fd16"
bgruening
parents: 32
diff changeset
199
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
200 # merge layers
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
201 if "merging_layers" in options:
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
202 idxs = literal_eval(options.pop("merging_layers"))
40
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
203 merging_layers = [all_layers[i - 1] for i in idxs]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
204 new_layer = klass(**options)(merging_layers)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
205 # non-input layers
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
206 elif inbound_nodes is not None:
40
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
207 new_layer = klass(**options)(all_layers[inbound_nodes - 1])
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
208 # input layers
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
209 else:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
210 new_layer = klass(**options)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
211
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
212 all_layers.append(new_layer)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
213
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
214 input_indexes = _handle_shape(config["input_layers"])
40
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
215 input_layers = [all_layers[i - 1] for i in input_indexes]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
216
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
217 output_indexes = _handle_shape(config["output_layers"])
40
006e27f0a7ef "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 208a8d348e7c7a182cfbe1b6f17868146428a7e2"
bgruening
parents: 37
diff changeset
218 output_layers = [all_layers[i - 1] for i in output_indexes]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
219
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
220 return Model(inputs=input_layers, outputs=output_layers)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
221
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
222
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
223 def get_batch_generator(config):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
224 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
225 Construct keras online data generator from Galaxy tool parameters
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
226
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
227 Parameters
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
228 -----------
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
229 config : dictionary, galaxy tool parameters loaded by JSON
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
230 """
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
231 generator_type = config.pop("generator_type")
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
232 if generator_type == "none":
37
80bb86a40de6 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 33
diff changeset
233 return None
80bb86a40de6 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 33
diff changeset
234
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
235 klass = try_get_attr("galaxy_ml.preprocessors", generator_type)
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
236
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
237 if generator_type == "GenomicIntervalBatchGenerator":
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
238 config["ref_genome_path"] = "to_be_determined"
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
239 config["intervals_path"] = "to_be_determined"
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
240 config["target_path"] = "to_be_determined"
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
241 config["features"] = "to_be_determined"
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
242 else:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
243 config["fasta_path"] = "to_be_determined"
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
244
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
245 return klass(**config)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
246
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
247
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
248 def config_keras_model(inputs, outfile):
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
249 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
250 config keras model layers and output JSON
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
251
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
252 Parameters
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
253 ----------
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
254 inputs : dict
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
255 loaded galaxy tool parameters from `keras_model_config`
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
256 tool.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
257 outfile : str
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
258 Path to galaxy dataset containing keras model JSON.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
259 """
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
260 model_type = inputs["model_selection"]["model_type"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
261 layers_config = inputs["model_selection"]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
262
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
263 if model_type == "sequential":
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
264 model = get_sequential_model(layers_config)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
265 else:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
266 model = get_functional_model(layers_config)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
267
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
268 json_string = model.to_json()
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
269
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
270 with open(outfile, "w") as f:
37
80bb86a40de6 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5b2ac730ec6d3b762faa9034eddd19ad1b347476"
bgruening
parents: 33
diff changeset
271 json.dump(json.loads(json_string), f, indent=2)
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
272
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
273
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
274 def build_keras_model(
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
275 inputs,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
276 outfile,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
277 model_json,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
278 infile_weights=None,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
279 batch_mode=False,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
280 outfile_params=None,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
281 ):
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
282 """
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
283 for `keras_model_builder` tool
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
284
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
285 Parameters
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
286 ----------
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
287 inputs : dict
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
288 loaded galaxy tool parameters from `keras_model_builder` tool.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
289 outfile : str
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
290 Path to galaxy dataset containing the keras_galaxy model output.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
291 model_json : str
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
292 Path to dataset containing keras model JSON.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
293 infile_weights : str or None
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
294 If string, path to dataset containing model weights.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
295 batch_mode : bool, default=False
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
296 Whether to build online batch classifier.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
297 outfile_params : str, default=None
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
298 File path to search parameters output.
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
299 """
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
300 with open(model_json, "r") as f:
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
301 json_model = json.load(f)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
302
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
303 config = json_model["config"]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
304
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
305 options = {}
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
306
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
307 if json_model["class_name"] == "Sequential":
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
308 options["model_type"] = "sequential"
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
309 klass = Sequential
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
310 elif json_model["class_name"] == "Model":
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
311 options["model_type"] = "functional"
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
312 klass = Model
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
313 else:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
314 raise ValueError("Unknow Keras model class: %s" % json_model["class_name"])
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
315
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
316 # load prefitted model
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
317 if inputs["mode_selection"]["mode_type"] == "prefitted":
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
318 estimator = klass.from_config(config)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
319 estimator.load_weights(infile_weights)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
320 # build train model
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
321 else:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
322 cls_name = inputs["mode_selection"]["learning_type"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
323 klass = try_get_attr("galaxy_ml.keras_galaxy_models", cls_name)
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
324
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
325 options["loss"] = inputs["mode_selection"]["compile_params"]["loss"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
326 options["optimizer"] = (
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
327 inputs["mode_selection"]["compile_params"]["optimizer_selection"][
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
328 "optimizer_type"
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
329 ]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
330 ).lower()
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
331
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
332 options.update(
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
333 (
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
334 inputs["mode_selection"]["compile_params"]["optimizer_selection"][
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
335 "optimizer_options"
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
336 ]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
337 )
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
338 )
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
339
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
340 train_metrics = inputs["mode_selection"]["compile_params"]["metrics"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
341 if train_metrics[-1] == "none":
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
342 train_metrics = train_metrics[:-1]
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
343 options["metrics"] = train_metrics
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
344
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
345 options.update(inputs["mode_selection"]["fit_params"])
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
346 options["seed"] = inputs["mode_selection"]["random_seed"]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
347
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
348 if batch_mode:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
349 generator = get_batch_generator(
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
350 inputs["mode_selection"]["generator_selection"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
351 )
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
352 options["data_batch_generator"] = generator
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
353 options["prediction_steps"] = inputs["mode_selection"]["prediction_steps"]
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
354 options["class_positive_factor"] = inputs["mode_selection"][
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
355 "class_positive_factor"
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
356 ]
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
357 estimator = klass(config, **options)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
358 if outfile_params:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
359 hyper_params = get_search_params(estimator)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
360 # TODO: remove this after making `verbose` tunable
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
361 for h_param in hyper_params:
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
362 if h_param[1].endswith("verbose"):
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
363 h_param[0] = "@"
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
364 df = pd.DataFrame(hyper_params, columns=["", "Parameter", "Value"])
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
365 df.to_csv(outfile_params, sep="\t", index=False)
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
366
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
367 print(repr(estimator))
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
368 # save model by pickle
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
369 with open(outfile, "wb") as f:
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
370 pickle.dump(estimator, f, pickle.HIGHEST_PROTOCOL)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
371
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
372
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
373 if __name__ == "__main__":
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
374 warnings.simplefilter("ignore")
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
375
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
376 aparser = argparse.ArgumentParser()
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
377 aparser.add_argument("-i", "--inputs", dest="inputs", required=True)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
378 aparser.add_argument("-m", "--model_json", dest="model_json")
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
379 aparser.add_argument("-t", "--tool_id", dest="tool_id")
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
380 aparser.add_argument("-w", "--infile_weights", dest="infile_weights")
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
381 aparser.add_argument("-o", "--outfile", dest="outfile")
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
382 aparser.add_argument("-p", "--outfile_params", dest="outfile_params")
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
383 args = aparser.parse_args()
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
384
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
385 input_json_path = args.inputs
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
386 with open(input_json_path, "r") as param_handler:
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
387 inputs = json.load(param_handler)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
388
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
389 tool_id = args.tool_id
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
390 outfile = args.outfile
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
391 outfile_params = args.outfile_params
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
392 model_json = args.model_json
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
393 infile_weights = args.infile_weights
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
394
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
395 # for keras_model_config tool
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
396 if tool_id == "keras_model_config":
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
397 config_keras_model(inputs, outfile)
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
398
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
399 # for keras_model_builder tool
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
400 else:
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
401 batch_mode = False
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
402 if tool_id == "keras_batch_models":
32
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
403 batch_mode = True
a36e1455971d planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 60f0fbc0eafd7c11bc60fb6c77f2937782efd8a9-dirty
bgruening
parents:
diff changeset
404
41
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
405 build_keras_model(
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
406 inputs=inputs,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
407 model_json=model_json,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
408 infile_weights=infile_weights,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
409 batch_mode=batch_mode,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
410 outfile=outfile,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
411 outfile_params=outfile_params,
156835c25f62 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit ca87db9c038a6fcf96aa39da50f384865fd932ff"
bgruening
parents: 40
diff changeset
412 )