Mercurial > repos > bgruening > sklearn_discriminant_classifier
comparison discriminant.xml @ 41:d769d83ec796 draft
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 9981e25b00de29ed881b2229a173a8c812ded9bb
author | bgruening |
---|---|
date | Wed, 09 Aug 2023 13:14:12 +0000 |
parents | eeaf989f1024 |
children |
comparison
equal
deleted
inserted
replaced
40:4335cec181ba | 41:d769d83ec796 |
---|---|
1 <tool id="sklearn_discriminant_classifier" name="Discriminant Analysis" version="@VERSION@" profile="20.05"> | 1 <tool id="sklearn_discriminant_classifier" name="Discriminant Analysis" version="@VERSION@" profile="@PROFILE@"> |
2 <description></description> | 2 <description></description> |
3 <macros> | 3 <macros> |
4 <import>main_macros.xml</import> | 4 <import>main_macros.xml</import> |
5 <!--macro name="priors"--> | 5 <!--macro name="priors"--> |
6 </macros> | 6 </macros> |
20 import pandas | 20 import pandas |
21 import pickle | 21 import pickle |
22 import sklearn.discriminant_analysis | 22 import sklearn.discriminant_analysis |
23 import sys | 23 import sys |
24 | 24 |
25 from galaxy_ml.utils import load_model, get_X_y | 25 from galaxy_ml.model_persist import dump_model_to_h5, load_model_from_h5 |
26 from galaxy_ml.utils import clean_params, get_X_y | |
26 | 27 |
27 | 28 |
28 input_json_path = sys.argv[1] | 29 input_json_path = sys.argv[1] |
29 with open(input_json_path, "r") as param_handler: | 30 with open(input_json_path, "r") as param_handler: |
30 params = json.load(param_handler) | 31 params = json.load(param_handler) |
31 | 32 |
32 #if $selected_tasks.selected_task == "load": | 33 #if $selected_tasks.selected_task == "load": |
33 | 34 |
34 with open("$infile_model", 'rb') as model_handler: | 35 classifier_object = load_model_from_h5('$infile_model') |
35 classifier_object = load_model(model_handler) | 36 classifier_object = clean_params(classifier_object) |
36 | 37 |
37 header = 'infer' if params["selected_tasks"]["header"] else None | 38 header = 'infer' if params["selected_tasks"]["header"] else None |
38 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=header, index_col=None, parse_dates=True, encoding=None) | 39 data = pandas.read_csv("$selected_tasks.infile_data", sep='\t', header=header, index_col=None, parse_dates=True, encoding=None) |
39 prediction = classifier_object.predict(data) | 40 prediction = classifier_object.predict(data) |
40 prediction_df = pandas.DataFrame(prediction) | 41 prediction_df = pandas.DataFrame(prediction) |
49 selected_algorithm = params["selected_tasks"]["selected_algorithms"]["selected_algorithm"] | 50 selected_algorithm = params["selected_tasks"]["selected_algorithms"]["selected_algorithm"] |
50 | 51 |
51 my_class = getattr(sklearn.discriminant_analysis, selected_algorithm) | 52 my_class = getattr(sklearn.discriminant_analysis, selected_algorithm) |
52 classifier_object = my_class(**options) | 53 classifier_object = my_class(**options) |
53 classifier_object.fit(X, y) | 54 classifier_object.fit(X, y) |
54 with open("$outfile_fit", 'wb') as out_handler: | 55 dump_model_to_h5(classifier_object, '$outfile_fit') |
55 pickle.dump(classifier_object, out_handler, pickle.HIGHEST_PROTOCOL) | |
56 | 56 |
57 #end if | 57 #end if |
58 ]]> | 58 ]]> |
59 </configfile> | 59 </configfile> |
60 </configfiles> | 60 </configfiles> |
61 <inputs> | 61 <inputs> |
62 <expand macro="sl_Conditional" model="zip"> | 62 <expand macro="sl_Conditional" model="h5mlm"> |
63 <param name="selected_algorithm" type="select" label="Classifier type"> | 63 <param name="selected_algorithm" type="select" label="Classifier type"> |
64 <option value="LinearDiscriminantAnalysis" selected="true">Linear Discriminant Classifier</option> | 64 <option value="LinearDiscriminantAnalysis" selected="true">Linear Discriminant Classifier</option> |
65 <option value="QuadraticDiscriminantAnalysis">Quadratic Discriminant Classifier</option> | 65 <option value="QuadraticDiscriminantAnalysis">Quadratic Discriminant Classifier</option> |
66 </param> | 66 </param> |
67 <when value="LinearDiscriminantAnalysis"> | 67 <when value="LinearDiscriminantAnalysis"> |
93 <expand macro="output" /> | 93 <expand macro="output" /> |
94 <tests> | 94 <tests> |
95 <test> | 95 <test> |
96 <param name="infile1" value="train.tabular" ftype="tabular" /> | 96 <param name="infile1" value="train.tabular" ftype="tabular" /> |
97 <param name="infile2" value="train.tabular" ftype="tabular" /> | 97 <param name="infile2" value="train.tabular" ftype="tabular" /> |
98 <param name="header1" value="True" /> | |
99 <param name="header2" value="True" /> | |
100 <param name="col1" value="1,2,3,4" /> | 98 <param name="col1" value="1,2,3,4" /> |
101 <param name="col2" value="5" /> | 99 <param name="col2" value="5" /> |
102 <param name="selected_task" value="train" /> | 100 <param name="selected_task" value="train" /> |
103 <param name="selected_algorithm" value="LinearDiscriminantAnalysis" /> | 101 <param name="selected_algorithm" value="LinearDiscriminantAnalysis" /> |
104 <param name="solver" value="svd" /> | 102 <param name="solver" value="svd" /> |
106 <output name="outfile_fit" file="lda_model01" compare="sim_size" delta="1" /> | 104 <output name="outfile_fit" file="lda_model01" compare="sim_size" delta="1" /> |
107 </test> | 105 </test> |
108 <test> | 106 <test> |
109 <param name="infile1" value="train.tabular" ftype="tabular" /> | 107 <param name="infile1" value="train.tabular" ftype="tabular" /> |
110 <param name="infile2" value="train.tabular" ftype="tabular" /> | 108 <param name="infile2" value="train.tabular" ftype="tabular" /> |
111 <param name="header1" value="True" /> | |
112 <param name="header2" value="True" /> | |
113 <param name="col1" value="1,2,3,4" /> | 109 <param name="col1" value="1,2,3,4" /> |
114 <param name="col2" value="5" /> | 110 <param name="col2" value="5" /> |
115 <param name="selected_task" value="train" /> | 111 <param name="selected_task" value="train" /> |
116 <param name="selected_algorithm" value="LinearDiscriminantAnalysis" /> | 112 <param name="selected_algorithm" value="LinearDiscriminantAnalysis" /> |
117 <param name="solver" value="lsqr" /> | 113 <param name="solver" value="lsqr" /> |
118 <output name="outfile_fit" file="lda_model02" compare="sim_size" delta="1" /> | 114 <output name="outfile_fit" file="lda_model02" compare="sim_size" delta="1" /> |
119 </test> | 115 </test> |
120 <test> | 116 <test> |
121 <param name="infile1" value="train.tabular" ftype="tabular" /> | 117 <param name="infile1" value="train.tabular" ftype="tabular" /> |
122 <param name="infile2" value="train.tabular" ftype="tabular" /> | 118 <param name="infile2" value="train.tabular" ftype="tabular" /> |
123 <param name="header1" value="True" /> | |
124 <param name="header2" value="True" /> | |
125 <param name="col1" value="1,2,3,4" /> | 119 <param name="col1" value="1,2,3,4" /> |
126 <param name="col2" value="5" /> | 120 <param name="col2" value="5" /> |
127 <param name="selected_task" value="train" /> | 121 <param name="selected_task" value="train" /> |
128 <param name="selected_algorithm" value="QuadraticDiscriminantAnalysis" /> | 122 <param name="selected_algorithm" value="QuadraticDiscriminantAnalysis" /> |
129 <output name="outfile_fit" file="qda_model01" compare="sim_size" delta="1" /> | 123 <output name="outfile_fit" file="qda_model01" compare="sim_size" delta="1" /> |
130 </test> | 124 </test> |
131 <test> | 125 <test> |
132 <param name="infile_model" value="lda_model01" ftype="zip" /> | 126 <param name="infile_model" value="lda_model01" ftype="h5mlm" /> |
133 <param name="infile_data" value="test.tabular" ftype="tabular" /> | 127 <param name="infile_data" value="test.tabular" ftype="tabular" /> |
134 <param name="header" value="True" /> | |
135 <param name="selected_task" value="load" /> | 128 <param name="selected_task" value="load" /> |
136 <output name="outfile_predict" file="lda_prediction_result01.tabular" /> | 129 <output name="outfile_predict" file="lda_prediction_result01.tabular" /> |
137 </test> | 130 </test> |
138 <test> | 131 <test> |
139 <param name="infile_model" value="lda_model02" ftype="zip" /> | 132 <param name="infile_model" value="lda_model02" ftype="h5mlm" /> |
140 <param name="infile_data" value="test.tabular" ftype="tabular" /> | 133 <param name="infile_data" value="test.tabular" ftype="tabular" /> |
141 <param name="header" value="True" /> | |
142 <param name="selected_task" value="load" /> | 134 <param name="selected_task" value="load" /> |
143 <output name="outfile_predict" file="lda_prediction_result02.tabular" /> | 135 <output name="outfile_predict" file="lda_prediction_result02.tabular" /> |
144 </test> | 136 </test> |
145 <test> | 137 <test> |
146 <param name="infile_model" value="qda_model01" ftype="zip" /> | 138 <param name="infile_model" value="qda_model01" ftype="h5mlm" /> |
147 <param name="infile_data" value="test.tabular" ftype="tabular" /> | 139 <param name="infile_data" value="test.tabular" ftype="tabular" /> |
148 <param name="header" value="True" /> | |
149 <param name="selected_task" value="load" /> | 140 <param name="selected_task" value="load" /> |
150 <output name="outfile_predict" file="qda_prediction_result01.tabular" /> | 141 <output name="outfile_predict" file="qda_prediction_result01.tabular" /> |
151 </test> | 142 </test> |
152 </tests> | 143 </tests> |
153 <help><![CDATA[ | 144 <help><![CDATA[ |