comparison pairwise_metrics.xml @ 0:dd1ed289bba1 draft

planemo upload for repository https://github.com/bgruening/galaxytools/tools/sklearn commit 0e582cf1f3134c777cce3aa57d71b80ed95e6ba9
author bgruening
date Fri, 16 Feb 2018 09:17:16 -0500
parents
children 0dfaead1d284
comparison
equal deleted inserted replaced
-1:000000000000 0:dd1ed289bba1
1 <tool id="sklearn_pairwise_metrics" name="Evaluate pairwise distances" version="@VERSION@">
2 <description>or compute affinity or kernel for sets of samples</description>
3 <macros>
4 <import>main_macros.xml</import>
5 </macros>
6 <expand macro="python_requirements"/>
7 <expand macro="macro_stdio"/>
8 <version_command>echo "@VERSION@"</version_command>
9 <command>
10 <![CDATA[
11 python "$pairwise_script" '$inputs'
12 ]]>
13 </command>
14 <configfiles>
15 <inputs name="inputs" />
16 <configfile name="pairwise_script">
17 <![CDATA[
18 import sys
19 import json
20 import pandas
21 import numpy as np
22 from sklearn.metrics import pairwise
23 from sklearn.metrics import pairwise_distances_argmin
24 from scipy.io import mmread
25 from scipy.io import mmwrite
26
27 input_json_path = sys.argv[1]
28 params = json.load(open(input_json_path, "r"))
29
30 options = params["input_type"]["metric_functions"]["options"]
31 metric_function = params["input_type"]["metric_functions"]["selected_metric_function"]
32
33 input_iter = []
34 #for $i, $s in enumerate( $input_type.input_files )
35 input_index=$i
36 input_path="${s.input.file_name}"
37 #if $input_type.selected_input_type == "sparse":
38 input_iter.append(mmread(open(input_path, 'r')))
39 #else:
40 input_iter.append(pandas.read_csv(input_path, sep='\t', header=0, index_col=None, parse_dates=True, encoding=None, tupleize_cols=False ).values)
41 #end if
42 #end for
43
44 if len(input_iter)>1:
45 X = input_iter[0]
46 Y = input_iter[1]
47 else: X = Y = input_iter[0]
48
49 if metric_function=="pairwise_distances_argmin":
50 metric_res = pairwise_distances_argmin(X,Y,**options)
51 else:
52 my_function = getattr(pairwise, metric_function)
53 metric_res = my_function(X,Y,**options)
54
55 pandas.DataFrame(metric_res).to_csv(path_or_buf = "$outfile", sep="\t", index=False, header=False)
56 ]]>
57 </configfile>
58 </configfiles>
59 <inputs>
60 <conditional name="input_type">
61 <param name="selected_input_type" type="select" label="Select the type of your input data:">
62 <option value="tabular" selected="true">Tabular data (.tabular, .txt)</option>
63 <option value="sparse">Sparse matrix (.mtx)</option>
64 </param>
65 <when value="tabular">
66 <expand macro="multiple_input" max_num="2" format="tabular"/>
67 <conditional name="metric_functions">
68 <expand macro="sparse_pairwise_metric_functions">
69 <expand macro="pairwise_metric_functions"/>
70 </expand>
71 <when value="additive_chi2_kernel">
72 </when>
73 <when value="chi2_kernel">
74 <section name="options" title="Advanced Options" expanded="False">
75 <expand macro="gamma" help_text="Floating point scaling parameter of the chi2 kernel. "/>
76 </section>
77 </when>
78 <when value="linear_kernel">
79 </when>
80 <when value="manhattan_distances">
81 <section name="options" title="Advanced Options" expanded="False">
82 <param argument="sum_over_features" type="boolean" optional="true" truevalue="booltrue" falsevalue="boolflase" checked="true" label="Sum over features" help="If True, return the pairwise distance matrix, else return the componentwise L1 pairwise-distances. "/>
83 </section>
84 </when>
85 <when value="polynomial_kernel">
86 <section name="options" title="Advanced Options" expanded="False">
87 <expand macro="gamma" default_value=""/>
88 <expand macro="degree"/>
89 <expand macro="coef0"/>
90 </section>
91 </when>
92 <when value="rbf_kernel">
93 <section name="options" title="Advanced Options" expanded="False">
94 <expand macro="gamma" default_value=""/>
95 </section>
96 </when>
97 <when value="laplacian_kernel">
98 <section name="options" title="Advanced Options" expanded="False">
99 <expand macro="gamma" default_value=""/>
100 </section>
101 </when>
102 <when value="pairwise_kernels">
103 <section name="options" title="Advanced Options" expanded="False">
104 <expand macro="pairwise_kernel_metrics"/>
105 </section>
106 </when>
107 <expand macro="sparse_pairwise_condition">
108 <expand macro="distance_nonsparse_metrics"/>
109 </expand>
110 <expand macro="argmin_distance_condition">
111 <expand macro="distance_nonsparse_metrics"/>
112 </expand>
113 </conditional>
114 </when>
115 <when value="sparse">
116 <expand macro="multiple_input" max_num="2"/>
117 <conditional name="metric_functions">
118 <expand macro="sparse_pairwise_metric_functions"/>
119 <expand macro="sparse_pairwise_condition"/>
120 <expand macro="argmin_distance_condition"/>
121 </conditional>
122 </when>
123 </conditional>
124 </inputs>
125 <outputs>
126 <data format="tabular" name="outfile"/>
127 </outputs>
128 <tests>
129 <test>
130 <param name="selected_input_type" value="tabular"/>
131 <param name="selected_metric_function" value="rbf_kernel"/>
132 <param name="input_files_0|input" value="test.tabular" ftype="tabular"/>
133 <param name="input_files_1|input" value="test2.tabular" ftype="tabular"/>
134 <param name="gamma" value="0.5"/>
135 <output name="outfile" file="pw_metric01.tabular" compare="sim_size" />
136 </test>
137 <test>
138 <param name="selected_input_type" value="tabular"/>
139 <param name="selected_metric_function" value="pairwise_distances"/>
140 <param name="metric" value="manhattan"/>
141 <param name="input_files_0|input" value="test.tabular" ftype="tabular"/>
142 <output name="outfile" file="pw_metric02.tabular"/>
143 </test>
144 <test>
145 <param name="selected_input_type" value="sparse"/>
146 <param name="selected_metric_function" value="pairwise_distances"/>
147 <param name="metric" value="cosine"/>
148 <param name="input_files_0|input" value="sparse.mtx" ftype="txt"/>
149 <output name="outfile" file="pw_metric03.tabular"/>
150 </test>
151 </tests>
152 <help>
153 <![CDATA[
154 **What it does**
155
156 This tool consists of utilities to evaluate pairwise distances or affinity of sets of samples.
157 The base utilities are contained in Scikit-learn python library in sklearn.metrics package.
158 This module contains both distance metrics and kernels. For a brief summary, please refer to:
159 http://scikit-learn.org/stable/modules/metrics.html#metrics
160 ]]>
161 </help>
162 <expand macro="sklearn_citation"/>
163 </tool>