6314 |
02 Sep 13 |
nicklas |
1 |
<%-- $Id $ |
6314 |
02 Sep 13 |
nicklas |
2 |
------------------------------------------------------------------ |
6314 |
02 Sep 13 |
nicklas |
Copyright (C) 2013 Nicklas Nordborg |
6314 |
02 Sep 13 |
nicklas |
4 |
|
6314 |
02 Sep 13 |
nicklas |
5 |
This file is part of BASE - BioArray Software Environment. |
6314 |
02 Sep 13 |
nicklas |
6 |
Available at http://base.thep.lu.se/ |
6314 |
02 Sep 13 |
nicklas |
7 |
|
6314 |
02 Sep 13 |
nicklas |
8 |
BASE is free software; you can redistribute it and/or modify it |
6314 |
02 Sep 13 |
nicklas |
9 |
under the terms of the GNU General Public License as published by |
6314 |
02 Sep 13 |
nicklas |
10 |
the Free Software Foundation; either version 3 of the License, or |
6314 |
02 Sep 13 |
nicklas |
11 |
(at your option) any later version. |
6314 |
02 Sep 13 |
nicklas |
12 |
|
6314 |
02 Sep 13 |
nicklas |
13 |
BASE is distributed in the hope that it will be useful, but |
6314 |
02 Sep 13 |
nicklas |
14 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
6314 |
02 Sep 13 |
nicklas |
15 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
6314 |
02 Sep 13 |
nicklas |
16 |
General Public License for more details. |
6314 |
02 Sep 13 |
nicklas |
17 |
|
6314 |
02 Sep 13 |
nicklas |
18 |
You should have received a copy of the GNU General Public License |
6314 |
02 Sep 13 |
nicklas |
19 |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
6314 |
02 Sep 13 |
nicklas |
20 |
------------------------------------------------------------------ |
6314 |
02 Sep 13 |
nicklas |
21 |
|
6314 |
02 Sep 13 |
nicklas |
22 |
@author Nicklas |
6314 |
02 Sep 13 |
nicklas |
23 |
--%> |
6314 |
02 Sep 13 |
nicklas |
24 |
<%@page %> |
6314 |
02 Sep 13 |
nicklas |
25 |
<%@ page pageEncoding="UTF-8" session="false" contentType="application/json" |
6314 |
02 Sep 13 |
nicklas |
26 |
import="net.sf.basedb.core.DbControl" |
6314 |
02 Sep 13 |
nicklas |
27 |
import="net.sf.basedb.core.SessionControl" |
6314 |
02 Sep 13 |
nicklas |
28 |
import="net.sf.basedb.core.Item" |
6314 |
02 Sep 13 |
nicklas |
29 |
import="net.sf.basedb.core.BioAssaySet" |
6314 |
02 Sep 13 |
nicklas |
30 |
import="net.sf.basedb.core.VirtualDb" |
6314 |
02 Sep 13 |
nicklas |
31 |
import="net.sf.basedb.core.ReporterCloneTemplate" |
6314 |
02 Sep 13 |
nicklas |
32 |
import="net.sf.basedb.core.RawDataType" |
6314 |
02 Sep 13 |
nicklas |
33 |
import="net.sf.basedb.core.RawDataTypes" |
6314 |
02 Sep 13 |
nicklas |
34 |
import="net.sf.basedb.core.RawDataProperty" |
6314 |
02 Sep 13 |
nicklas |
35 |
import="net.sf.basedb.core.ExtendedProperty" |
6314 |
02 Sep 13 |
nicklas |
36 |
import="net.sf.basedb.core.ExtendedProperties" |
6314 |
02 Sep 13 |
nicklas |
37 |
import="net.sf.basedb.core.Formula" |
6314 |
02 Sep 13 |
nicklas |
38 |
import="net.sf.basedb.core.IntensityTransform" |
6314 |
02 Sep 13 |
nicklas |
39 |
import="net.sf.basedb.core.ClonableProperty" |
6314 |
02 Sep 13 |
nicklas |
40 |
import="net.sf.basedb.core.ReporterList" |
6314 |
02 Sep 13 |
nicklas |
41 |
import="net.sf.basedb.core.ItemQuery" |
6314 |
02 Sep 13 |
nicklas |
42 |
import="net.sf.basedb.core.Include" |
6314 |
02 Sep 13 |
nicklas |
43 |
import="net.sf.basedb.core.query.Orders" |
6314 |
02 Sep 13 |
nicklas |
44 |
import="net.sf.basedb.core.query.Hql" |
6314 |
02 Sep 13 |
nicklas |
45 |
import="net.sf.basedb.util.Enumeration" |
6314 |
02 Sep 13 |
nicklas |
46 |
import="net.sf.basedb.util.jep.Jep" |
6314 |
02 Sep 13 |
nicklas |
47 |
import="net.sf.basedb.util.jep.SimpleJepFunction" |
6314 |
02 Sep 13 |
nicklas |
48 |
import="net.sf.basedb.util.jep.JepFunction" |
6314 |
02 Sep 13 |
nicklas |
49 |
import="net.sf.basedb.clients.web.Base" |
6314 |
02 Sep 13 |
nicklas |
50 |
import="net.sf.basedb.util.Values" |
6314 |
02 Sep 13 |
nicklas |
51 |
import="net.sf.basedb.clients.web.util.HTML" |
6314 |
02 Sep 13 |
nicklas |
52 |
import="net.sf.basedb.clients.web.DynamicUtil" |
6314 |
02 Sep 13 |
nicklas |
53 |
import="net.sf.basedb.clients.web.taglib.table.TableColumn" |
6314 |
02 Sep 13 |
nicklas |
54 |
import="net.sf.basedb.util.error.ThrowableUtil" |
6314 |
02 Sep 13 |
nicklas |
55 |
import="java.util.Stack" |
6314 |
02 Sep 13 |
nicklas |
56 |
import="java.util.List" |
6314 |
02 Sep 13 |
nicklas |
57 |
import="java.util.LinkedList" |
6314 |
02 Sep 13 |
nicklas |
58 |
import="java.util.HashSet" |
6314 |
02 Sep 13 |
nicklas |
59 |
import="java.util.Set" |
6314 |
02 Sep 13 |
nicklas |
60 |
import="java.util.Arrays" |
6314 |
02 Sep 13 |
nicklas |
61 |
import="org.json.simple.JSONObject" |
6314 |
02 Sep 13 |
nicklas |
62 |
import="org.nfunk.jep.JEP" |
6314 |
02 Sep 13 |
nicklas |
63 |
import="org.nfunk.jep.ParseException" |
6314 |
02 Sep 13 |
nicklas |
64 |
%> |
6314 |
02 Sep 13 |
nicklas |
65 |
<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
6314 |
02 Sep 13 |
nicklas |
66 |
<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %> |
6314 |
02 Sep 13 |
nicklas |
67 |
<%! |
6314 |
02 Sep 13 |
nicklas |
68 |
|
6314 |
02 Sep 13 |
nicklas |
69 |
private static Set<String> staticRawProperties = |
6314 |
02 Sep 13 |
nicklas |
70 |
new HashSet<String>(Arrays.asList("position", "block", "metaGridX", "metaGridY", |
6314 |
02 Sep 13 |
nicklas |
71 |
"row", "column", "x", "y")); |
6314 |
02 Sep 13 |
nicklas |
72 |
|
6314 |
02 Sep 13 |
nicklas |
73 |
private static void checkRawProperty(String functionName, Object property, RawDataType rawDataType) |
6314 |
02 Sep 13 |
nicklas |
74 |
throws ParseException |
6314 |
02 Sep 13 |
nicklas |
75 |
{ |
6314 |
02 Sep 13 |
nicklas |
76 |
if (property == null) |
6314 |
02 Sep 13 |
nicklas |
77 |
{ |
6314 |
02 Sep 13 |
nicklas |
78 |
throw new ParseException("Function " + functionName + " requires a single parameter"); |
6314 |
02 Sep 13 |
nicklas |
79 |
} |
6314 |
02 Sep 13 |
nicklas |
80 |
if (rawDataType == null) |
6314 |
02 Sep 13 |
nicklas |
81 |
{ |
6314 |
02 Sep 13 |
nicklas |
82 |
throw new ParseException("Cannot use function " + functionName + ". No raw data type selected."); |
6314 |
02 Sep 13 |
nicklas |
83 |
} |
6314 |
02 Sep 13 |
nicklas |
84 |
RawDataProperty rp = rawDataType.getProperty(property.toString()); |
6314 |
02 Sep 13 |
nicklas |
85 |
if (rp == null && !staticRawProperties.contains(property)) |
6314 |
02 Sep 13 |
nicklas |
86 |
{ |
6314 |
02 Sep 13 |
nicklas |
87 |
throw new ParseException("Property '"+property+"' not found for raw data type '" + rawDataType.getName() + "'."); |
6314 |
02 Sep 13 |
nicklas |
88 |
} |
6314 |
02 Sep 13 |
nicklas |
89 |
} |
6314 |
02 Sep 13 |
nicklas |
90 |
|
6314 |
02 Sep 13 |
nicklas |
91 |
private static void checkChannel(String functionName, Object channel, int numChannels) |
6314 |
02 Sep 13 |
nicklas |
92 |
throws ParseException |
6314 |
02 Sep 13 |
nicklas |
93 |
{ |
6314 |
02 Sep 13 |
nicklas |
94 |
if (channel == null) |
6314 |
02 Sep 13 |
nicklas |
95 |
{ |
6314 |
02 Sep 13 |
nicklas |
96 |
throw new ParseException("Function " + functionName + " requires a single parameter"); |
6314 |
02 Sep 13 |
nicklas |
97 |
} |
6314 |
02 Sep 13 |
nicklas |
98 |
int channelNum = channel instanceof Number ? ((Number)channel).intValue() : 0; |
6314 |
02 Sep 13 |
nicklas |
99 |
if (channelNum <= 0 || channelNum > numChannels) |
6314 |
02 Sep 13 |
nicklas |
100 |
{ |
6314 |
02 Sep 13 |
nicklas |
101 |
throw new ParseException("Invalid channel: " + channel + "; must be between 1 and "+ numChannels); |
6314 |
02 Sep 13 |
nicklas |
102 |
} |
6314 |
02 Sep 13 |
nicklas |
103 |
} |
6314 |
02 Sep 13 |
nicklas |
104 |
%> |
6314 |
02 Sep 13 |
nicklas |
105 |
<% |
6314 |
02 Sep 13 |
nicklas |
106 |
final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
6314 |
02 Sep 13 |
nicklas |
107 |
final Formula.Type formulaType = Formula.Type.valueOf(request.getParameter("formulatype")); |
6314 |
02 Sep 13 |
nicklas |
108 |
final RawDataType rawDataType = RawDataTypes.getRawDataType(request.getParameter("rawdatatype")); |
6314 |
02 Sep 13 |
nicklas |
109 |
int bioAssaySetId = Values.getInt(request.getParameter("bioassayset_id"), -1); |
6314 |
02 Sep 13 |
nicklas |
110 |
boolean restrictions = Values.getBoolean(request.getParameter("restrictions")); |
6314 |
02 Sep 13 |
nicklas |
111 |
final int channels = Values.getInt(request.getParameter("channels")); |
6314 |
02 Sep 13 |
nicklas |
112 |
final String expression = request.getParameter("expression"); |
6314 |
02 Sep 13 |
nicklas |
113 |
|
6314 |
02 Sep 13 |
nicklas |
114 |
JSONObject json = new JSONObject(); |
6314 |
02 Sep 13 |
nicklas |
115 |
json.put("status", "ok"); |
6314 |
02 Sep 13 |
nicklas |
116 |
DbControl dc = null; |
6314 |
02 Sep 13 |
nicklas |
117 |
|
6314 |
02 Sep 13 |
nicklas |
118 |
|
6314 |
02 Sep 13 |
nicklas |
119 |
JepFunction raw = new SimpleJepFunction("raw", 1) |
6314 |
02 Sep 13 |
nicklas |
120 |
{ |
7605 |
26 Feb 19 |
nicklas |
121 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
6314 |
02 Sep 13 |
nicklas |
122 |
@Override |
6314 |
02 Sep 13 |
nicklas |
123 |
public void run(Stack stack) |
6314 |
02 Sep 13 |
nicklas |
124 |
throws ParseException |
6314 |
02 Sep 13 |
nicklas |
125 |
{ |
6314 |
02 Sep 13 |
nicklas |
126 |
Object property = stack.pop(); |
6314 |
02 Sep 13 |
nicklas |
127 |
checkRawProperty(getFunctionName(), property, rawDataType); |
6314 |
02 Sep 13 |
nicklas |
128 |
stack.push(Math.random()*100); |
6314 |
02 Sep 13 |
nicklas |
129 |
} |
6314 |
02 Sep 13 |
nicklas |
130 |
}; |
6314 |
02 Sep 13 |
nicklas |
131 |
|
6314 |
02 Sep 13 |
nicklas |
132 |
JepFunction mean = new SimpleJepFunction("mean", 1) |
6314 |
02 Sep 13 |
nicklas |
133 |
{ |
7605 |
26 Feb 19 |
nicklas |
134 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
6314 |
02 Sep 13 |
nicklas |
135 |
@Override |
6314 |
02 Sep 13 |
nicklas |
136 |
public void run(Stack stack) |
6314 |
02 Sep 13 |
nicklas |
137 |
throws ParseException |
6314 |
02 Sep 13 |
nicklas |
138 |
{ |
6314 |
02 Sep 13 |
nicklas |
139 |
Object property = stack.pop(); |
6314 |
02 Sep 13 |
nicklas |
140 |
checkRawProperty(getFunctionName(), property, rawDataType); |
6314 |
02 Sep 13 |
nicklas |
141 |
stack.push(Math.random()*100); |
6314 |
02 Sep 13 |
nicklas |
142 |
} |
6314 |
02 Sep 13 |
nicklas |
143 |
}; |
6314 |
02 Sep 13 |
nicklas |
144 |
|
6314 |
02 Sep 13 |
nicklas |
145 |
JepFunction ch = new SimpleJepFunction("ch", 1) |
6314 |
02 Sep 13 |
nicklas |
146 |
{ |
7605 |
26 Feb 19 |
nicklas |
147 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
6314 |
02 Sep 13 |
nicklas |
148 |
@Override |
6314 |
02 Sep 13 |
nicklas |
149 |
public void run(Stack stack) |
6314 |
02 Sep 13 |
nicklas |
150 |
throws ParseException |
6314 |
02 Sep 13 |
nicklas |
151 |
{ |
6314 |
02 Sep 13 |
nicklas |
152 |
Object channel = stack.pop(); |
6314 |
02 Sep 13 |
nicklas |
153 |
checkChannel(getFunctionName(), channel, channels); |
6314 |
02 Sep 13 |
nicklas |
154 |
stack.push(Math.random()*100); |
6314 |
02 Sep 13 |
nicklas |
155 |
} |
6314 |
02 Sep 13 |
nicklas |
156 |
}; |
6314 |
02 Sep 13 |
nicklas |
157 |
|
6314 |
02 Sep 13 |
nicklas |
158 |
JepFunction rawCh = new SimpleJepFunction("rawCh", 1) |
6314 |
02 Sep 13 |
nicklas |
159 |
{ |
7605 |
26 Feb 19 |
nicklas |
160 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
6314 |
02 Sep 13 |
nicklas |
161 |
@Override |
6314 |
02 Sep 13 |
nicklas |
162 |
public void run(Stack stack) |
6314 |
02 Sep 13 |
nicklas |
163 |
throws ParseException |
6314 |
02 Sep 13 |
nicklas |
164 |
{ |
6314 |
02 Sep 13 |
nicklas |
165 |
Object channel = stack.pop(); |
6314 |
02 Sep 13 |
nicklas |
166 |
checkChannel(getFunctionName(), channel, channels); |
6314 |
02 Sep 13 |
nicklas |
167 |
stack.push(Math.random()*100); |
6314 |
02 Sep 13 |
nicklas |
168 |
} |
6314 |
02 Sep 13 |
nicklas |
169 |
}; |
6314 |
02 Sep 13 |
nicklas |
170 |
|
6314 |
02 Sep 13 |
nicklas |
171 |
if (formulaType == Formula.Type.INTENSITY_EXPRESSION) |
6314 |
02 Sep 13 |
nicklas |
172 |
{ |
6314 |
02 Sep 13 |
nicklas |
173 |
ch = null; |
6314 |
02 Sep 13 |
nicklas |
174 |
rawCh = null; |
6314 |
02 Sep 13 |
nicklas |
175 |
} |
6314 |
02 Sep 13 |
nicklas |
176 |
|
6314 |
02 Sep 13 |
nicklas |
177 |
JepFunction pos = new SimpleJepFunction("pos", 0) |
6314 |
02 Sep 13 |
nicklas |
178 |
{ |
7605 |
26 Feb 19 |
nicklas |
179 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
6314 |
02 Sep 13 |
nicklas |
180 |
@Override |
6314 |
02 Sep 13 |
nicklas |
181 |
public void run(Stack stack) |
6314 |
02 Sep 13 |
nicklas |
182 |
throws ParseException |
6314 |
02 Sep 13 |
nicklas |
183 |
{ |
6314 |
02 Sep 13 |
nicklas |
184 |
stack.push((int)(Math.random()*1000)); |
6314 |
02 Sep 13 |
nicklas |
185 |
} |
6314 |
02 Sep 13 |
nicklas |
186 |
}; |
6314 |
02 Sep 13 |
nicklas |
187 |
|
6314 |
02 Sep 13 |
nicklas |
188 |
JepFunction rep = new SimpleJepFunction("rep", 1) |
6314 |
02 Sep 13 |
nicklas |
189 |
{ |
7605 |
26 Feb 19 |
nicklas |
190 |
@SuppressWarnings({ "unchecked", "rawtypes" }) |
6314 |
02 Sep 13 |
nicklas |
191 |
@Override |
6314 |
02 Sep 13 |
nicklas |
192 |
public void run(Stack stack) |
6314 |
02 Sep 13 |
nicklas |
193 |
throws ParseException |
6314 |
02 Sep 13 |
nicklas |
194 |
{ |
6314 |
02 Sep 13 |
nicklas |
195 |
Object property = stack.pop(); |
6314 |
02 Sep 13 |
nicklas |
196 |
if (property == null) |
6314 |
02 Sep 13 |
nicklas |
197 |
{ |
6314 |
02 Sep 13 |
nicklas |
198 |
throw new ParseException("Function rep() requires a single parameter"); |
6314 |
02 Sep 13 |
nicklas |
199 |
} |
6314 |
02 Sep 13 |
nicklas |
200 |
ClonableProperty cp = null; |
6314 |
02 Sep 13 |
nicklas |
201 |
try |
6314 |
02 Sep 13 |
nicklas |
202 |
{ |
6314 |
02 Sep 13 |
nicklas |
203 |
cp = ClonableProperty.create(property.toString()); |
6314 |
02 Sep 13 |
nicklas |
204 |
} |
6314 |
02 Sep 13 |
nicklas |
205 |
catch (RuntimeException ex) |
6314 |
02 Sep 13 |
nicklas |
206 |
{} |
6314 |
02 Sep 13 |
nicklas |
207 |
if (cp == null) |
6314 |
02 Sep 13 |
nicklas |
208 |
{ |
6314 |
02 Sep 13 |
nicklas |
209 |
throw new ParseException("Property '"+property+"' not found for reporter."); |
6314 |
02 Sep 13 |
nicklas |
210 |
} |
6314 |
02 Sep 13 |
nicklas |
211 |
|
6314 |
02 Sep 13 |
nicklas |
212 |
stack.push(Math.random()*100); |
6314 |
02 Sep 13 |
nicklas |
213 |
} |
6314 |
02 Sep 13 |
nicklas |
214 |
}; |
6314 |
02 Sep 13 |
nicklas |
215 |
|
6314 |
02 Sep 13 |
nicklas |
216 |
JepFunction score = new SimpleJepFunction("score", 1); |
6314 |
02 Sep 13 |
nicklas |
217 |
JepFunction xtra = new SimpleJepFunction("xtra", 1); |
6314 |
02 Sep 13 |
nicklas |
218 |
|
6314 |
02 Sep 13 |
nicklas |
219 |
try |
6314 |
02 Sep 13 |
nicklas |
220 |
{ |
6314 |
02 Sep 13 |
nicklas |
221 |
JEP jep = Jep.newJep(expression, raw, mean, ch, rawCh, pos, rep, score, xtra); |
6314 |
02 Sep 13 |
nicklas |
222 |
if (jep.getSymbolTable().containsKey("null")) |
6314 |
02 Sep 13 |
nicklas |
223 |
{ |
6314 |
02 Sep 13 |
nicklas |
224 |
jep.setVarValue("null", 0); |
6314 |
02 Sep 13 |
nicklas |
225 |
} |
6314 |
02 Sep 13 |
nicklas |
226 |
json.put("value", jep.getValueAsObject()); |
6314 |
02 Sep 13 |
nicklas |
227 |
/* |
6314 |
02 Sep 13 |
nicklas |
228 |
if (jep.hasError()) |
6314 |
02 Sep 13 |
nicklas |
229 |
{ |
6314 |
02 Sep 13 |
nicklas |
230 |
throw new ParseException(jep.getErrorInfo()); |
6314 |
02 Sep 13 |
nicklas |
231 |
} |
6314 |
02 Sep 13 |
nicklas |
232 |
*/ |
6314 |
02 Sep 13 |
nicklas |
233 |
} |
6314 |
02 Sep 13 |
nicklas |
234 |
catch (Throwable t) |
6314 |
02 Sep 13 |
nicklas |
235 |
{ |
6314 |
02 Sep 13 |
nicklas |
236 |
t.printStackTrace(); |
6314 |
02 Sep 13 |
nicklas |
237 |
json.clear(); |
6314 |
02 Sep 13 |
nicklas |
238 |
json.put("status", "error"); |
6314 |
02 Sep 13 |
nicklas |
239 |
json.put("message", t.getMessage()); |
6314 |
02 Sep 13 |
nicklas |
240 |
json.put("stacktrace", ThrowableUtil.stackTraceToString(t)); |
6314 |
02 Sep 13 |
nicklas |
241 |
} |
6314 |
02 Sep 13 |
nicklas |
242 |
finally |
6314 |
02 Sep 13 |
nicklas |
243 |
{ |
6314 |
02 Sep 13 |
nicklas |
244 |
json.writeJSONString(out); |
6314 |
02 Sep 13 |
nicklas |
245 |
out.flush(); |
6314 |
02 Sep 13 |
nicklas |
246 |
if (dc != null) dc.close(); |
6314 |
02 Sep 13 |
nicklas |
247 |
} |
6314 |
02 Sep 13 |
nicklas |
248 |
|
6314 |
02 Sep 13 |
nicklas |
249 |
%> |