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