1 | <%-- $Id: jep_filter.jsp 4506 2008-09-11 09:29:40Z nicklas $ |
---|
2 | ------------------------------------------------------------------ |
---|
3 | BioArray Software Environment (BASE) - http:// base.thep.lu.se/ |
---|
4 | |
---|
5 | This file is part of BASE - BioArray Software Environment. |
---|
6 | Available at http://base.thep.lu.se/ |
---|
7 | |
---|
8 | BASE is free software; you can redistribute it and/or |
---|
9 | modify it under the terms of the GNU General Public License |
---|
10 | as published by the Free Software Foundation; either version 3 |
---|
11 | of the License, or (at your option) any later version. |
---|
12 | |
---|
13 | BASE is distributed in the hope that it will be useful, |
---|
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | GNU General Public License for more details. |
---|
17 | |
---|
18 | You should have received a copy of the GNU General Public License |
---|
19 | along with this program; if not, write to the Free Software |
---|
20 | Foundation, Inc., 59 Temple Place - Suite 330, |
---|
21 | Boston, MA 02111-1307, USA. |
---|
22 | ------------------------------------------------------------------ |
---|
23 | |
---|
24 | @author Nicklas |
---|
25 | @version 2.0 |
---|
26 | --%> |
---|
27 | <%@ page session="false" |
---|
28 | import="net.sf.basedb.core.SessionControl" |
---|
29 | import="net.sf.basedb.core.DbControl" |
---|
30 | import="net.sf.basedb.core.Job" |
---|
31 | import="net.sf.basedb.core.BioAssaySet" |
---|
32 | import="net.sf.basedb.core.BioAssay" |
---|
33 | import="net.sf.basedb.core.RawDataType" |
---|
34 | import="net.sf.basedb.core.RawDataProperty" |
---|
35 | import="net.sf.basedb.core.Experiment" |
---|
36 | import="net.sf.basedb.core.Formula" |
---|
37 | import="net.sf.basedb.core.Type" |
---|
38 | import="net.sf.basedb.core.Item" |
---|
39 | import="net.sf.basedb.core.ItemContext" |
---|
40 | import="net.sf.basedb.core.ItemQuery" |
---|
41 | import="net.sf.basedb.core.ItemResultList" |
---|
42 | import="net.sf.basedb.core.Include" |
---|
43 | import="net.sf.basedb.core.query.Orders" |
---|
44 | import="net.sf.basedb.core.query.Hql" |
---|
45 | import="net.sf.basedb.core.query.Restrictions" |
---|
46 | import="net.sf.basedb.core.query.Expressions" |
---|
47 | import="net.sf.basedb.clients.web.Base" |
---|
48 | import="net.sf.basedb.clients.web.util.HTML" |
---|
49 | import="net.sf.basedb.util.Values" |
---|
50 | import="net.sf.basedb.clients.web.WebException" |
---|
51 | import="java.util.List" |
---|
52 | %> |
---|
53 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
54 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
55 | <%! |
---|
56 | private static void addFormulaOption(StringBuilder options, String formula, String title, String description) |
---|
57 | { |
---|
58 | options.append("<option value=\"").append(HTML.encodeTags(formula)).append("\""); |
---|
59 | options.append(" title=\"").append(HTML.encodeTags(description)).append("\""); |
---|
60 | options.append(">").append(HTML.encodeTags(title)).append("\n"); |
---|
61 | } |
---|
62 | %> |
---|
63 | <% |
---|
64 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
65 | final String ID = sc.getId(); |
---|
66 | ItemContext cc = sc.getCurrentContext(Item.BIOASSAYSET); |
---|
67 | DbControl dc = null; |
---|
68 | |
---|
69 | try |
---|
70 | { |
---|
71 | String errorMessage = (String)sc.getSessionSetting("plugin.configure.errors.message"); |
---|
72 | List<Throwable> errors = (List<Throwable>)sc.getSessionSetting("plugin.configure.errors.list"); |
---|
73 | |
---|
74 | dc = sc.newDbControl(); |
---|
75 | Job job = (Job)sc.getSessionSetting("plugin.configure.job"); |
---|
76 | dc.reattachItem(job); |
---|
77 | BioAssaySet source = null; |
---|
78 | source = (BioAssaySet)job.getParameterValue("source"); |
---|
79 | if (source == null && cc.getId() != 0) source = BioAssaySet.getById(dc, cc.getId()); |
---|
80 | if (source == null) throw new WebException("popup", "No current bioassay set", |
---|
81 | "Could not find any current bioassay set. Please select a bioassay set before trying again"); |
---|
82 | source = BioAssaySet.getById(dc, source.getId()); |
---|
83 | RawDataType rdt = source.getRawDataType(); |
---|
84 | long numBioAssays = source.getBioAssays().count(dc); |
---|
85 | int maxRawMappings = source.getMaxRawMappingsForSpot(); |
---|
86 | |
---|
87 | // Find selected bioassays |
---|
88 | List<BioAssay> bioAssays = null; |
---|
89 | bioAssays = (List<BioAssay>)job.getParameterValues("bioAssays"); |
---|
90 | if (bioAssays == null) |
---|
91 | { |
---|
92 | ItemContext bioAssayContext = sc.getCurrentContext(Item.BIOASSAY); |
---|
93 | ItemQuery<BioAssay> bioAssayQuery = null; |
---|
94 | if (bioAssayContext.getSelected().size() > 0) |
---|
95 | { |
---|
96 | bioAssayQuery = source.getBioAssays(); |
---|
97 | bioAssayQuery.restrict( |
---|
98 | Restrictions.in(Hql.property("id"), Expressions.parameter("selected")) |
---|
99 | ); |
---|
100 | bioAssayQuery.setParameter("selected", bioAssayContext.getSelected(), Type.INT); |
---|
101 | bioAssays = bioAssayQuery.list(dc); |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | // Current parameter values |
---|
106 | String childName = Values.getString((String)job.getParameterValue("childName"), |
---|
107 | source.getName().startsWith("Filtered") ? "" : "Filtered " + source.getName()); |
---|
108 | String childDescription = (String)job.getParameterValue("childDescription"); |
---|
109 | String expression = (String)job.getParameterValue("expression"); |
---|
110 | Integer includeLimit = (Integer)job.getParameterValue("includeLimit"); |
---|
111 | Integer excludeLimit = (Integer)job.getParameterValue("excludeLimit"); |
---|
112 | |
---|
113 | // Predefined formulas |
---|
114 | ItemQuery<Formula> formulaQuery = Formula.getQuery(Formula.Type.COLUMN_RESTRICTION, rdt); |
---|
115 | formulaQuery.order(Orders.asc(Hql.property("name"))); |
---|
116 | formulaQuery.include(Include.MINE, Include.SHARED, Include.IN_PROJECT, Include.OTHERS); |
---|
117 | ItemResultList<Formula> formulas = formulaQuery.list(dc); |
---|
118 | StringBuilder formulaOptions = new StringBuilder(); |
---|
119 | for (Formula f : formulas) |
---|
120 | { |
---|
121 | String formula = f.getFormula(0); |
---|
122 | if (maxRawMappings == 1 || !formula.contains("raw(")) |
---|
123 | { |
---|
124 | addFormulaOption(formulaOptions, formula, f.getName(), f.getDescription()); |
---|
125 | } |
---|
126 | } |
---|
127 | %> |
---|
128 | <base:page type="popup" title="Filter bioassay set"> |
---|
129 | <base:head scripts="linkitems.js" styles="parameters.css"> |
---|
130 | <script language="JavaScript"> |
---|
131 | function hideErrorList() |
---|
132 | { |
---|
133 | Main.hide('errorlist'); |
---|
134 | Main.show('showerrorlist'); |
---|
135 | } |
---|
136 | function showErrorList() |
---|
137 | { |
---|
138 | Main.show('errorlist'); |
---|
139 | Main.hide('showerrorlist'); |
---|
140 | } |
---|
141 | |
---|
142 | function presetOnChange(list, formula, label) |
---|
143 | { |
---|
144 | var index = list.selectedIndex; |
---|
145 | formula.value = list[index].value; |
---|
146 | if (list[index].value != '' && label) label.value = list[index].text; |
---|
147 | } |
---|
148 | function openExpressionBuilder() |
---|
149 | { |
---|
150 | Main.expressionBuilder('<%=ID%>', 'Expression', 'filter', 'parameter:expression', 'COLUMN_RESTRICTION', '<%=rdt.getId()%>', <%=rdt.getChannels()%>, true, <%=source.getId()%>); |
---|
151 | } |
---|
152 | function validate() |
---|
153 | { |
---|
154 | var frm = document.forms['filter']; |
---|
155 | var exclude = Main.trimString(frm['parameter:excludeLimit'].value); |
---|
156 | var include = Main.trimString(frm['parameter:includeLimit'].value); |
---|
157 | |
---|
158 | if (!frm.allBioAssays.checked && frm.bioAssays.length == 0) |
---|
159 | { |
---|
160 | alert('You have not selected any bioassays'); |
---|
161 | return false; |
---|
162 | } |
---|
163 | else if (Main.trimString(frm['parameter:childName'].value) == '') |
---|
164 | { |
---|
165 | alert('You must enter a name for the child bioassay set'); |
---|
166 | frm['parameter:name'].focus(); |
---|
167 | return false; |
---|
168 | } |
---|
169 | else if (Main.trimString(frm['parameter:expression'].value) == '') |
---|
170 | { |
---|
171 | alert('You must enter a filter expression'); |
---|
172 | frm['parameter:expression'].focus(); |
---|
173 | return false; |
---|
174 | } |
---|
175 | <% |
---|
176 | if (maxRawMappings != 1) |
---|
177 | { |
---|
178 | %> |
---|
179 | else if (frm['parameter:expression'].value.search(/raw\(/) != -1) |
---|
180 | { |
---|
181 | alert('Can\'t use function raw() for bioassayset with multiple mappings to raw data'); |
---|
182 | frm['parameter:expression'].focus(); |
---|
183 | return false; |
---|
184 | } |
---|
185 | <% |
---|
186 | } |
---|
187 | %> |
---|
188 | else if (exclude != '' || include != '') |
---|
189 | { |
---|
190 | exclude = parseInt(exclude); |
---|
191 | include = parseInt(include); |
---|
192 | |
---|
193 | if (include < 1 || include > <%=numBioAssays%>) |
---|
194 | { |
---|
195 | alert('The "include" value must be between 1 and <%=numBioAssays%>'); |
---|
196 | frm['parameter:includeLimit'].focus(); |
---|
197 | return false; |
---|
198 | } |
---|
199 | else if (exclude < 1 || exclude > <%=numBioAssays%>) |
---|
200 | { |
---|
201 | alert('The "exclude" value must be between 1 and <%=numBioAssays%>'); |
---|
202 | frm['parameter:excludeLimit'].focus(); |
---|
203 | return false; |
---|
204 | } |
---|
205 | else if (exclude > include) |
---|
206 | { |
---|
207 | alert('The "include" value can\'t be smaller than the "exclude" value.'); |
---|
208 | return false; |
---|
209 | } |
---|
210 | } |
---|
211 | return true; |
---|
212 | } |
---|
213 | function doNext() |
---|
214 | { |
---|
215 | if (validate()) |
---|
216 | { |
---|
217 | var frm = document.forms['filter']; |
---|
218 | if (!frm.allBioAssays.checked) |
---|
219 | { |
---|
220 | var ids = Link.getListIds(frm.bioAssays, 'R'); |
---|
221 | for (var i = 0; i < ids.length; i++) |
---|
222 | { |
---|
223 | Forms.createHidden(frm, 'parameter:bioAssays', ids[i]); |
---|
224 | } |
---|
225 | } |
---|
226 | frm.submit(); |
---|
227 | } |
---|
228 | } |
---|
229 | function doCancel() |
---|
230 | { |
---|
231 | location = 'index.jsp?ID=<%=ID%>&cmd=CancelWizard'; |
---|
232 | } |
---|
233 | |
---|
234 | function allBioAssaysOnClick() |
---|
235 | { |
---|
236 | var frm = document.forms['filter']; |
---|
237 | frm.bioAssays.disabled = frm.allBioAssays.checked; |
---|
238 | } |
---|
239 | |
---|
240 | function addBioAssaysOnClick() |
---|
241 | { |
---|
242 | var frm = document.forms['filter']; |
---|
243 | if (frm.allBioAssays.checked) |
---|
244 | { |
---|
245 | return; |
---|
246 | } |
---|
247 | var ids = Link.getListIds(frm.bioAssays, 'R'); |
---|
248 | var excludes = ids.join(','); |
---|
249 | var url = '../../views/experiments/bioassays/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple&callback=addBioAssayCallback&bioassayset_id=<%=source.getId()%>'; |
---|
250 | url += "&exclude="+excludes; |
---|
251 | Main.openPopup(url, 'AddBioAssays', 1000, 700); |
---|
252 | } |
---|
253 | function addBioAssayCallback(bioAssayId, name) |
---|
254 | { |
---|
255 | var item = Link.getItem('R', bioAssayId); |
---|
256 | if (!item) item = new Item('R', bioAssayId, name); |
---|
257 | Link.addItem(document.forms['filter'].bioAssays, item); |
---|
258 | } |
---|
259 | function removeBioAssaysOnClick() |
---|
260 | { |
---|
261 | var frm = document.forms['filter']; |
---|
262 | if (frm.allBioAssays.checked) |
---|
263 | { |
---|
264 | return; |
---|
265 | } |
---|
266 | Link.removeSelected(frm.bioAssays); |
---|
267 | } |
---|
268 | |
---|
269 | function init() |
---|
270 | { |
---|
271 | initBioAssays(); |
---|
272 | } |
---|
273 | |
---|
274 | function initBioAssays() |
---|
275 | { |
---|
276 | var frm = document.forms['filter']; |
---|
277 | <% |
---|
278 | if (bioAssays != null) |
---|
279 | { |
---|
280 | for (BioAssay ba : bioAssays) |
---|
281 | { |
---|
282 | %> |
---|
283 | Link.addNewItem(frm.bioAssays, new Item('R', <%=ba.getId()%>, '<%=HTML.javaScriptEncode(ba.getName())%>')); |
---|
284 | <% |
---|
285 | } |
---|
286 | } |
---|
287 | %> |
---|
288 | frm.allBioAssays.checked = frm.bioAssays.length == 0; |
---|
289 | allBioAssaysOnClick(); |
---|
290 | } |
---|
291 | </script> |
---|
292 | |
---|
293 | </base:head> |
---|
294 | <base:body onload="init()"> |
---|
295 | <form name="filter" action="index.jsp" method="post" onsubmit="return false;"> |
---|
296 | <input type="hidden" name="ID" value="<%=ID%>"> |
---|
297 | <input type="hidden" name="requestId" value="<%=request.getParameter("requestId")%>"> |
---|
298 | <input type="hidden" name="cmd" value="SetParameters"> |
---|
299 | <input type="hidden" name="parameter:source" value="<%=source.getId()%>"> |
---|
300 | |
---|
301 | <h3 class="docked">Filter bioassay set <base:help helpid="jepfilter.options"/></h3> |
---|
302 | <div class="boxed"> |
---|
303 | <% |
---|
304 | if (errorMessage != null || (errors != null && errors.size() > 0)) |
---|
305 | { |
---|
306 | %> |
---|
307 | <div id="errors" style="margin-bottom: 12px;" class="parameterhelp"> |
---|
308 | <div class="error" style="margin: 0px;"> |
---|
309 | <%=errorMessage %> |
---|
310 | </div> |
---|
311 | <% |
---|
312 | if (errors != null && errors.size() > 0) |
---|
313 | { |
---|
314 | %> |
---|
315 | <div id="showerrorlist" style="display: none;"> |
---|
316 | <base:icon image="bullet.gif" /><a href="javascript:showErrorList()">Show details</a> |
---|
317 | </div> |
---|
318 | <div id="errorlist"> |
---|
319 | <ol> |
---|
320 | <% |
---|
321 | for (Throwable t : errors) |
---|
322 | { |
---|
323 | %> |
---|
324 | <li><%=t.getMessage()%><br> |
---|
325 | <% |
---|
326 | } |
---|
327 | %> |
---|
328 | </ol> |
---|
329 | <base:icon image="bullet.gif" /><a href="javascript:hideErrorList()">Hide details</a> |
---|
330 | </div> |
---|
331 | <% |
---|
332 | } |
---|
333 | %> |
---|
334 | </div> |
---|
335 | <% |
---|
336 | } |
---|
337 | %> |
---|
338 | |
---|
339 | <table class="form"> |
---|
340 | <tr> |
---|
341 | <td class="prompt" colspan="2">Source</td> |
---|
342 | </tr> |
---|
343 | <tr valign="top"> |
---|
344 | <td> Bioassay set</td> |
---|
345 | <td><%=HTML.encodeTags(source.getName())%></td> |
---|
346 | </tr> |
---|
347 | <tr valign="top"> |
---|
348 | <td> Bioassays</td> |
---|
349 | <td> |
---|
350 | <input type="checkbox" name="allBioAssays" |
---|
351 | onclick="allBioAssaysOnClick()"><a |
---|
352 | href="javascript:document.forms['filter'].allBioAssays.click()">All bioassays</a><br> |
---|
353 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
354 | <tr valign="top"> |
---|
355 | <td> |
---|
356 | <select name="bioAssays" size="5" multiple style="width: 20em;"> |
---|
357 | </select> |
---|
358 | </td> |
---|
359 | <td> |
---|
360 | <table border="0"> |
---|
361 | <tr><td width="150"><base:button |
---|
362 | onclick="addBioAssaysOnClick()" |
---|
363 | title="Add bioassays…" |
---|
364 | tooltip="Add bioassays" |
---|
365 | /></td></tr> |
---|
366 | <tr><td width="150"><base:button |
---|
367 | onclick="removeBioAssaysOnClick()" |
---|
368 | title="Remove" |
---|
369 | tooltip="Remove the selected bioassays" |
---|
370 | /></td></tr> |
---|
371 | </table> |
---|
372 | </td> |
---|
373 | </tr> |
---|
374 | </table> |
---|
375 | </td> |
---|
376 | </tr> |
---|
377 | <tr> |
---|
378 | <td class="prompt" colspan="2">Child bioassay set</td> |
---|
379 | </tr> |
---|
380 | <tr> |
---|
381 | <td> Name</td> |
---|
382 | <td> |
---|
383 | <input type="text" class="text required" size="50" maxlength="255" |
---|
384 | name="parameter:childName" |
---|
385 | value="<%=HTML.encodeTags(childName)%>"></td> |
---|
386 | </tr> |
---|
387 | <tr valign="top"> |
---|
388 | <td> Description</td> |
---|
389 | <td nowrap> |
---|
390 | <textarea class="text" rows="3" cols="50" name="parameter:childDescription" wrap="virtual" |
---|
391 | ><%=HTML.encodeTags(childDescription) %></textarea> |
---|
392 | <a href="javascript:Main.zoom('Description', 'transformation', 'parameter:childDescription')" |
---|
393 | title="Edit in larger window"><base:icon image="zoom.gif" /></a> |
---|
394 | </td> |
---|
395 | </tr> |
---|
396 | |
---|
397 | <tr> |
---|
398 | <td class="prompt" colspan="2">Filter</td> |
---|
399 | </tr> |
---|
400 | <tr> |
---|
401 | <td> Presets</td> |
---|
402 | <td> |
---|
403 | <select name="presets" style="width: 32em;" |
---|
404 | onchange="presetOnChange(this, this.form['parameter:expression'])" |
---|
405 | > |
---|
406 | <option value="">- select from list or enter formula below - |
---|
407 | <%=formulaOptions.toString()%> |
---|
408 | </select> |
---|
409 | </td> |
---|
410 | </tr> |
---|
411 | <tr valign="top"> |
---|
412 | <td> Expression</td> |
---|
413 | <td> |
---|
414 | <table border="0" cellspacing="0" cellpadding="0"> |
---|
415 | <tr valign="top"> |
---|
416 | <td> |
---|
417 | <textarea class="text required" name="parameter:expression" |
---|
418 | rows="3" cols="50"><%=HTML.encodeTags(expression)%></textarea> |
---|
419 | </td> |
---|
420 | <td><base:button onclick="openExpressionBuilder()" |
---|
421 | title="Expression builder…" |
---|
422 | image="expression_builder.gif" |
---|
423 | tooltip="A simple utility for building expressions" /> |
---|
424 | </td> |
---|
425 | </tr> |
---|
426 | </table> |
---|
427 | </td> |
---|
428 | </tr> |
---|
429 | |
---|
430 | <tr valign="top"> |
---|
431 | <td> </td> |
---|
432 | <td>Keep non-matching spots from all bioassays if the filter matches that spot in at least<br> |
---|
433 | <input class="text" type="text" name="parameter:includeLimit" |
---|
434 | size="4" maxlength="10" value="<%=includeLimit == null ? "" : includeLimit.toString()%>" |
---|
435 | onkeypress="return Numbers.integerOnly(event)"> |
---|
436 | bioassay(s) [1 - <%=numBioAssays%>] |
---|
437 | </td> |
---|
438 | </tr> |
---|
439 | |
---|
440 | <tr valign="top"> |
---|
441 | <td> </td> |
---|
442 | <td>Exclude matching spots from all bioassays if the filter doesn't match that spot in at least<br> |
---|
443 | <input class="text" type="text" name="parameter:excludeLimit" |
---|
444 | size="4" maxlength="10" value="<%=excludeLimit == null ? "" : excludeLimit.toString()%>" |
---|
445 | onkeypress="return Numbers.integerOnly(event)"> |
---|
446 | bioassay(s) [1 - <%=numBioAssays%>] |
---|
447 | </td> |
---|
448 | </tr> |
---|
449 | |
---|
450 | </table> |
---|
451 | </div> |
---|
452 | </form> |
---|
453 | |
---|
454 | <table align="center"> |
---|
455 | <tr> |
---|
456 | <td width="50%"><base:button onclick="doNext();" title="Next" /></td> |
---|
457 | <td width="50%"><base:button onclick="doCancel();" title="Cancel" /></td> |
---|
458 | </tr> |
---|
459 | </table> |
---|
460 | </base:body> |
---|
461 | </base:page> |
---|
462 | <% |
---|
463 | } |
---|
464 | finally |
---|
465 | { |
---|
466 | if (dc != null) dc.close(); |
---|
467 | } |
---|
468 | %> |
---|
469 | |
---|