0
|
1 <tool id="query_tabular" name="Query Tabular" version="0.1.0">
|
|
2 <description>using sqlite sql</description>
|
|
3
|
|
4 <requirements>
|
|
5 </requirements>
|
|
6 <stdio>
|
|
7 <exit_code range="1:" />
|
|
8 </stdio>
|
2
|
9 <configfiles>
|
|
10 <configfile name="query_file">
|
|
11 $sqlquery
|
|
12 </configfile>
|
|
13 </configfiles>
|
0
|
14 <command interpreter="python"><![CDATA[
|
|
15 query_tabular.py
|
|
16 #if $save_db
|
|
17 -s $sqlitedb
|
|
18 #else
|
|
19 -s $workdb
|
|
20 #end if
|
|
21 #for $i,$tbl in enumerate($tables):
|
|
22 #if $tbl.table_name
|
|
23 #set $tname = $tbl.table_name
|
|
24 #else
|
|
25 #set $tname = 't' + str($i + 1)
|
|
26 #end if
|
|
27 #if $tbl.col_names:
|
|
28 #set $col_names = ':' + str($tbl.col_names)
|
|
29 #else
|
|
30 #set $col_names = ''
|
|
31 #end if
|
|
32 -t ${tbl.table}=${tname}${$col_names}
|
|
33 #end for
|
2
|
34 #if $sqlquery:
|
|
35 -Q "$query_file"
|
1
|
36 $no_header
|
0
|
37 -o $output
|
|
38 #end if
|
|
39 ]]></command>
|
|
40 <inputs>
|
|
41 <param name="workdb" type="hidden" value="workdb.sqlite" label=""/>
|
|
42 <repeat name="tables" title="Add tables" min="1">
|
|
43 <param name="table" type="data" format="tabular" label="Dataset"/>
|
|
44 <param name="table_name" type="text" value="" optional="true" label="Table name">
|
|
45 <help>By default, tables will be named: t1,t2,...,tn</help>
|
|
46 <validator type="regex" message="Table name should start with a letter and may contain additional letters, digits, and underscores">^[A-Za-z]\w*$</validator>
|
|
47 </param>
|
|
48 <!--
|
|
49 <param name="sel_cols" label="Include columns" type="data_column" multiple="true" data_ref="table" />
|
|
50 -->
|
|
51 <param name="col_names" type="text" value="" optional="true" label="Column names">
|
|
52 <help>By default, table columns will be named: c1,c2,c3,...,cn</help>
|
|
53 <validator type="regex" message="A List of separated by commas: Column names should start with a letter and may contain additional letters, digits, and underscores">^([A-Za-z]\w*)?(,([A-Za-z]\w*)?)*$</validator>
|
|
54 </param>
|
|
55 </repeat>
|
2
|
56 <param name="sqlquery" type="text" area="true" size="10x80" value="" optional="true" label="SQL Query">
|
0
|
57 <help>By default, tables will be named: t1,t2,...,tn</help>
|
|
58 <sanitizer sanitize="False"/>
|
|
59 <validator type="regex" message="">^(?i)\s*select\s+.*\s+from\s+.*$</validator>
|
|
60 </param>
|
1
|
61 <param name="no_header" type="boolean" truevalue="-n" falsevalue="" checked="False" label="Omit column headers"/>
|
|
62
|
0
|
63 <param name="save_db" type="boolean" truevalue="yes" falsevalue="no" checked="false" label="Save the sqlite database"/>
|
|
64 </inputs>
|
|
65 <outputs>
|
|
66 <data format="sqlite" name="sqlitedb" label="sqlite">
|
2
|
67 <filter>save_db or not (sqlquery and len(sqlquery) > 0)</filter>
|
0
|
68 </data>
|
|
69 <data format="tabular" name="output" label="query results">
|
2
|
70 <filter>sqlquery and len(sqlquery) > 0</filter>
|
0
|
71 </data>
|
|
72 </outputs>
|
|
73 <tests>
|
|
74
|
|
75 <test>
|
|
76 <repeat name="tables">
|
|
77 <param name="table" ftype="tabular" value="customers.tsv"/>
|
|
78 <param name="table_name" value="customers"/>
|
|
79 <param name="col_names" value="CustomerID,FirstName,LastName,Email,DOB,Phone"/>
|
|
80 </repeat>
|
|
81 <repeat name="tables">
|
|
82 <param name="table" ftype="tabular" value="sales.tsv"/>
|
|
83 <param name="table_name" value="sales"/>
|
|
84 <param name="col_names" value="CustomerID,Date,SaleAmount"/>
|
|
85 </repeat>
|
2
|
86 <param name="sqlquery" value="SELECT FirstName,LastName,sum(SaleAmount) as "TotalSales" FROM customers join sales on customers.CustomerID = sales.CustomerID GROUP BY customers.CustomerID ORDER BY TotalSales DESC"/>
|
0
|
87 <output name="output" file="sales_results.tsv"/>
|
|
88 </test>
|
|
89
|
|
90 <test>
|
|
91 <repeat name="tables">
|
|
92 <param name="table" ftype="tabular" value="customers.tsv"/>
|
|
93 <param name="col_names" value=",FirstName,LastName,,DOB,"/>
|
|
94 </repeat>
|
|
95 <repeat name="tables">
|
|
96 <param name="table" ftype="tabular" value="sales.tsv"/>
|
|
97 </repeat>
|
2
|
98 <param name="sqlquery" value="SELECT FirstName,LastName,sum(t2.c3) as "TotalSales" FROM t1 join t2 on t1.c1 = t2.c1 GROUP BY t1.c1 ORDER BY TotalSales DESC;"/>
|
0
|
99 <output name="output" file="sales_results.tsv"/>
|
|
100 </test>
|
|
101
|
|
102 <test>
|
|
103 <repeat name="tables">
|
|
104 <param name="table" ftype="tabular" value="IEDB.tsv"/>
|
|
105 <param name="table_name" value="iedb"/>
|
|
106 <param name="col_names" value="ID,allele,seq_num,start,end,length,peptide,method,percentile_rank,ann_ic50,ann_rank,smm_ic50,smm_rank,comblib_sidney2008_score,comblib_sidney2008_rank,netmhcpan_ic50,netmhcpan_rank"/>
|
|
107 </repeat>
|
|
108 <repeat name="tables">
|
|
109 <param name="table" ftype="tabular" value="netMHC_summary.tsv"/>
|
|
110 <param name="table_name" value="mhc_summary"/>
|
|
111 <param name="col_names" value="pos,peptide,logscore,affinity,Bind_Level,Protein,Allele"/>
|
|
112 </repeat>
|
2
|
113 <param name="sqlquery" value="select iedb.ID,iedb.peptide,iedb.start,iedb.end,iedb.percentile_rank,mhc_summary.logscore,mhc_summary.affinity,mhc_summary.Bind_Level from iedb left outer join mhc_summary on iedb.peptide = mhc_summary.peptide order by affinity,Bind_Level"/>
|
0
|
114 <output name="output" file="query_results.tsv"/>
|
|
115 </test>
|
|
116
|
|
117 </tests>
|
|
118 <help><![CDATA[
|
|
119 =============
|
|
120 Query Tabular
|
|
121 =============
|
|
122
|
|
123 **Inputs**
|
|
124
|
|
125 Loads tabular datasets into a SQLite_ data base.
|
|
126
|
|
127 **Outputs**
|
|
128
|
|
129 The results of a SQL query are output to the history as a tabular file.
|
|
130
|
|
131 The SQLite_ data base can also be saved and output as a dataset in the history.
|
|
132
|
|
133
|
|
134 For help in using SQLite_ see: http://www.sqlite.org/docs.html
|
|
135
|
|
136 **NOTE:** input for SQLite dates input field must be in the format: *YYYY-MM-DD* for example: 2015-09-30
|
|
137
|
|
138 See: http://www.sqlite.org/lang_datefunc.html
|
|
139
|
|
140 **Example**
|
|
141
|
|
142 Given 2 tabular datasets: *customers* and *sales*
|
|
143
|
|
144 Dataset *customers*
|
|
145
|
|
146 Table name: "customers"
|
|
147
|
|
148 Column names: "CustomerID,FirstName,LastName,Email,DOB,Phone"
|
|
149
|
|
150 =========== ========== ========== ===================== ========== ============
|
|
151 #CustomerID FirstName LastName Email DOB Phone
|
|
152 =========== ========== ========== ===================== ========== ============
|
|
153 1 John Smith John.Smith@yahoo.com 1968-02-04 626 222-2222
|
|
154 2 Steven Goldfish goldfish@fishhere.net 1974-04-04 323 455-4545
|
|
155 3 Paula Brown pb@herowndomain.org 1978-05-24 416 323-3232
|
|
156 4 James Smith jim@supergig.co.uk 1980-10-20 416 323-8888
|
|
157 =========== ========== ========== ===================== ========== ============
|
|
158
|
|
159 Dataset *sales*
|
|
160
|
|
161 Table name: "sales"
|
|
162
|
|
163 Column names: "CustomerID,Date,SaleAmount"
|
|
164
|
|
165 ============= ============ ============
|
|
166 #CustomerID Date SaleAmount
|
|
167 ============= ============ ============
|
|
168 2 2004-05-06 100.22
|
|
169 1 2004-05-07 99.95
|
|
170 3 2004-05-07 122.95
|
|
171 3 2004-05-13 100.00
|
|
172 4 2004-05-22 555.55
|
|
173 ============= ============ ============
|
|
174
|
|
175 The query
|
|
176
|
|
177 ::
|
|
178
|
|
179 SELECT FirstName,LastName,sum(SaleAmount) as "TotalSales"
|
|
180 FROM customers join sales on customers.CustomerID = sales.CustomerID
|
|
181 GROUP BY customers.CustomerID ORDER BY TotalSales DESC;
|
|
182
|
|
183 Produces this tabular output:
|
|
184
|
|
185 ========== ======== ==========
|
|
186 #FirstName LastName TotalSales
|
|
187 ========== ======== ==========
|
|
188 James Smith 555.55
|
|
189 Paula Brown 222.95
|
|
190 Steven Goldfish 100.22
|
|
191 John Smith 99.95
|
|
192 ========== ======== ==========
|
|
193
|
|
194
|
|
195 If the optional Table name and Column names inputs are not used, the query would be:
|
|
196
|
|
197 ::
|
|
198
|
|
199 SELECT t1.c2 as "FirstName", t1.c3 as "LastName", sum(t2.c3) as "TotalSales"
|
|
200 FROM t1 join t2 on t1.c1 = t2.c1
|
|
201 GROUP BY t1.c1 ORDER BY TotalSales DESC;
|
|
202
|
|
203 You can selectively name columns, e.g. on the customers input you could just name columns 2,3, and 5:
|
|
204
|
|
205 Column names: ,FirstName,LastName,,BirthDate
|
|
206
|
|
207 Results in the following data base table
|
|
208
|
|
209 =========== ========== ========== ===================== ========== ============
|
|
210 #c1 FirstName LastName c4 BithDate c6
|
|
211 =========== ========== ========== ===================== ========== ============
|
|
212 1 John Smith John.Smith@yahoo.com 1968-02-04 626 222-2222
|
|
213 2 Steven Goldfish goldfish@fishhere.net 1974-04-04 323 455-4545
|
|
214 3 Paula Brown pb@herowndomain.org 1978-05-24 416 323-3232
|
|
215 4 James Smith jim@supergig.co.uk 1980-10-20 416 323-8888
|
|
216 =========== ========== ========== ===================== ========== ============
|
|
217
|
|
218 .. _SQLite: http://www.sqlite.org/index.html
|
|
219
|
|
220 ]]></help>
|
|
221 </tool>
|