changeset 13:40f3318b61c2 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/sklearn commit 5d71c93a3dd804b1469852240a86021ab9130364
author bgruening
date Mon, 09 Jul 2018 14:32:01 -0400
parents 3bd31820d63e
children 6bbf5cb20652
files main_macros.xml numeric_clustering.xml
diffstat 2 files changed, 76 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/main_macros.xml	Sun Jul 01 03:19:41 2018 -0400
+++ b/main_macros.xml	Mon Jul 09 14:32:01 2018 -0400
@@ -64,6 +64,45 @@
   return new_selector
   </token>
 
+  <token name="@GET_X_y_FUNCTION@">
+def get_X_y(params, file1, file2):
+  input_type = params["selected_tasks"]["selected_algorithms"]["input_options"]["selected_input"]
+  if input_type=="tabular":
+    header = 'infer' if params["selected_tasks"]["selected_algorithms"]["input_options"]["header1"] else None
+    column_option = params["selected_tasks"]["selected_algorithms"]["input_options"]["column_selector_options_1"]["selected_column_selector_option"]
+    if column_option in ["by_index_number", "all_but_by_index_number", "by_header_name", "all_but_by_header_name"]:
+      c = params["selected_tasks"]["selected_algorithms"]["input_options"]["column_selector_options_1"]["col1"]
+    else:
+      c = None
+    X = read_columns(
+      file1,
+      c = c,
+      c_option = column_option,
+      sep='\t',
+      header=header,
+      parse_dates=True
+    )
+  else:
+    X = mmread(open(file1, 'r'))
+
+  header = 'infer' if params["selected_tasks"]["selected_algorithms"]["input_options"]["header2"] else None
+  column_option = params["selected_tasks"]["selected_algorithms"]["input_options"]["column_selector_options_2"]["selected_column_selector_option2"]
+  if column_option in ["by_index_number", "all_but_by_index_number", "by_header_name", "all_but_by_header_name"]:
+    c = params["selected_tasks"]["selected_algorithms"]["input_options"]["column_selector_options_2"]["col2"]
+  else:
+    c = None
+  y = read_columns(
+    file2,
+    c = c,
+    c_option = column_option,
+    sep='\t',
+    header=header,
+    parse_dates=True
+  )
+  y=y.ravel()
+  return X, y
+  </token>
+
   <xml name="python_requirements">
       <requirements>
           <requirement type="package" version="2.7">python</requirement>
@@ -81,34 +120,6 @@
 
 
   <!--Generic interface-->
-  <xml name="train_loadConditional" token_train="tabular" token_data="tabular" token_model="txt">
-    <conditional name="selected_tasks">
-        <param name="selected_task" type="select" label="Select a Classification Task">
-            <option value="train" selected="true">Train a model</option>
-            <option value="load">Load a model and predict</option>
-        </param>
-        <when value="load">
-            <param name="infile_model" type="data" format="@MODEL@" label="Models" help="Select a model file."/>
-            <param name="infile_data" type="data" format="@DATA@" label="Data (tabular)" help="Select the dataset you want to classify."/>
-            <conditional name="prediction_options">
-                <param name="prediction_option" type="select" label="Select the type of prediction">
-                    <option value="predict">Predict class labels</option>
-                    <option value="advanced">Include advanced options</option>
-                </param>
-                <when value="predict">
-                </when>
-                <when value="advanced">
-                </when>
-            </conditional>
-        </when>
-        <when value="train">
-            <param name="infile_train" type="data" format="@TRAIN@" label="Training samples (tabular)"/>
-            <conditional name="selected_algorithms">
-                <yield />
-            </conditional>
-        </when>
-    </conditional>
-  </xml>
 
   <xml name="sl_Conditional" token_train="tabular" token_data="tabular" token_model="txt">
     <conditional name="selected_tasks">
--- a/numeric_clustering.xml	Sun Jul 01 03:19:41 2018 -0400
+++ b/numeric_clustering.xml	Mon Jul 09 14:32:01 2018 -0400
@@ -22,6 +22,8 @@
 from sklearn import metrics
 from scipy.io import mmread
 
+@COLUMNS_FUNCTION@
+
 input_json_path = sys.argv[1]
 params = json.load(open(input_json_path, "r"))
 
@@ -37,17 +39,22 @@
 data_matrix = mmread(open("$infile", 'r'))
 #else:
 data = pandas.read_csv("$infile", sep='\t', header=0, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False )
-
-start_column = $input_types.start_column
-end_column = $input_types.end_column
-
-if end_column and start_column:
-    if  end_column >= start_column:
-        data_matrix = data.values[:, start_column-1:end_column]
-    else:
-        data_matrix = data.values
+header = 'infer' if params["input_types"]["header"] else None
+column_option = params["input_types"]["column_selector_options"]["selected_column_selector_option"]
+if column_option in ["by_index_number", "all_but_by_index_number", "by_header_name", "all_but_by_header_name"]:
+    c = params["input_types"]["column_selector_options"]["col"]
 else:
-    data_matrix = data.values
+    c = None
+data_matrix = read_columns(
+    "$infile",
+    c = c,
+    c_option = column_option,
+    sep='\t',
+    header=header,
+    parse_dates=True,
+    encoding=None,
+    tupleize_cols=False
+)
 #end if
 
 prediction = cluster_object.fit_predict( data_matrix )
@@ -82,8 +89,10 @@
             </when>
             <when value="tabular">
                 <param name="infile" type="data" format="tabular" label="Data file with numeric values"/>
-                <param name="start_column" type="data_column" data_ref="infile" optional="True" label="Select a subset of data. Start column:" />
-                <param name="end_column" type="data_column" data_ref="infile" optional="True" label="End column:" />
+                <param name="header" type="boolean" optional="true" truevalue="booltrue" falsevalue="boolfalse" checked="True" label="Does the dataset contain header:" />
+                <conditional name="column_selector_options">
+                    <expand macro="samples_column_selector_options" col_name="col" multiple="true" infile="infile"/>
+                </conditional>
                 <!--expand macro="clustering_algorithms_options"-->
                 <conditional name="algorithm_options">
                     <param name="selected_algorithm" type="select" label="Clustering Algorithm">
@@ -168,8 +177,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_input_type" value="tabular"/>
             <param name="selected_algorithm" value="KMeans"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="n_clusters" value="4" />
             <param name="init" value="k-means++" />
             <param name="random_state" value="100"/>
@@ -179,8 +187,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="KMeans"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="n_clusters" value="4" />
             <param name="init" value="random" />
             <param name="random_state" value="100"/>
@@ -190,8 +197,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="DBSCAN"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="algorithm" value="kd_tree"/>
             <param name="leaf_size" value="10"/>
             <param name="eps" value="1.0"/>
@@ -201,8 +207,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="Birch"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="n_clusters" value="4"/>
             <param name="threshold" value="0.008"/>
             <output name="outfile" file="cluster_result04.txt"/>
@@ -211,8 +216,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="Birch"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="branching_factor" value="20"/>
             <output name="outfile" file="cluster_result05.txt"/>
         </test>
@@ -220,8 +224,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="AffinityPropagation"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="affinity" value="euclidean"/>
             <param name="copy" value="false"/>
             <output name="outfile" file="cluster_result06.txt"/>
@@ -230,8 +233,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="AffinityPropagation"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="damping" value="0.8"/>
             <output name="outfile" file="cluster_result07.txt"/>
         </test>
@@ -239,8 +241,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="MeanShift"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="min_bin_freq" value="3"/>
             <output name="outfile" file="cluster_result08.txt"/>
         </test>
@@ -248,8 +249,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="MeanShift"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="cluster_all" value="False"/>
             <output name="outfile" file="cluster_result09.txt"/>
         </test>
@@ -257,8 +257,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="AgglomerativeClustering"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="affinity" value="euclidean"/>
             <param name="linkage" value="average"/>
             <param name="n_clusters" value="4"/>
@@ -268,8 +267,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="AgglomerativeClustering"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="linkage" value="complete"/>
             <param name="n_clusters" value="4"/>
             <output name="outfile" file="cluster_result11.txt"/>
@@ -278,8 +276,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="SpectralClustering"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="eigen_solver" value="arpack"/>
             <param name="n_neighbors" value="12"/>
             <param name="n_clusters" value="4"/>
@@ -291,8 +288,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="SpectralClustering"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="assign_labels" value="discretize"/>
             <param name="random_state" value="100"/>
             <param name="degree" value="2"/>
@@ -302,8 +298,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="MiniBatchKMeans"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="tol" value="0.5"/>
             <param name="random_state" value="100"/>
             <output name="outfile" file="cluster_result14.txt"/>
@@ -313,8 +308,7 @@
             <param name="selected_algorithm" value="MiniBatchKMeans"/>
             <param name="selected_input_type" value="tabular"/>
             <param name="n_init" value="5"/>
-            <param name="start_column" value="2" />
-            <param name="end_column" value="4" />
+            <param name="col" value="2,3,4" />
             <param name="batch_size" value="10"/>
             <param name="n_clusters" value="4"/>
             <param name="random_state" value="100"/>
@@ -325,8 +319,7 @@
             <param name="infile" value="numeric_values.tabular" ftype="tabular"/>
             <param name="selected_algorithm" value="KMeans"/>
             <param name="selected_input_type" value="tabular"/>
-            <param name="start_column" value="1" />
-            <param name="end_column" value="1" />
+            <param name="col" value="1" />
             <param name="n_clusters" value="4" />
             <param name="random_state" value="100"/>
             <output name="outfile" file="cluster_result16.txt"/>