4925 |
08 May 09 |
nicklas |
1 |
/** |
4925 |
08 May 09 |
nicklas |
$Id$ |
4925 |
08 May 09 |
nicklas |
3 |
|
4925 |
08 May 09 |
nicklas |
Copyright (C) 2009 Nicklas Nordborg |
4925 |
08 May 09 |
nicklas |
5 |
|
4925 |
08 May 09 |
nicklas |
This file is part of BASE - BioArray Software Environment. |
4925 |
08 May 09 |
nicklas |
Available at http://base.thep.lu.se/ |
4925 |
08 May 09 |
nicklas |
8 |
|
4925 |
08 May 09 |
nicklas |
BASE is free software; you can redistribute it and/or |
4925 |
08 May 09 |
nicklas |
modify it under the terms of the GNU General Public License |
4925 |
08 May 09 |
nicklas |
as published by the Free Software Foundation; either version 3 |
4925 |
08 May 09 |
nicklas |
of the License, or (at your option) any later version. |
4925 |
08 May 09 |
nicklas |
13 |
|
4925 |
08 May 09 |
nicklas |
BASE is distributed in the hope that it will be useful, |
4925 |
08 May 09 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4925 |
08 May 09 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
4925 |
08 May 09 |
nicklas |
GNU General Public License for more details. |
4925 |
08 May 09 |
nicklas |
18 |
|
4925 |
08 May 09 |
nicklas |
You should have received a copy of the GNU General Public License |
4925 |
08 May 09 |
nicklas |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
4925 |
08 May 09 |
nicklas |
21 |
*/ |
4925 |
08 May 09 |
nicklas |
22 |
package net.sf.basedb.util.export.spotdata; |
4925 |
08 May 09 |
nicklas |
23 |
|
4925 |
08 May 09 |
nicklas |
24 |
import net.sf.basedb.core.AnnotationType; |
4925 |
08 May 09 |
nicklas |
25 |
import net.sf.basedb.core.ExtendedProperty; |
4928 |
13 May 09 |
nicklas |
26 |
import net.sf.basedb.core.ExtraValueType; |
4925 |
08 May 09 |
nicklas |
27 |
import net.sf.basedb.core.Formula; |
5199 |
15 Dec 09 |
nicklas |
28 |
import net.sf.basedb.core.Metadata; |
4925 |
08 May 09 |
nicklas |
29 |
import net.sf.basedb.core.RawDataProperty; |
5319 |
20 Apr 10 |
nicklas |
30 |
import net.sf.basedb.core.Type; |
4925 |
08 May 09 |
nicklas |
31 |
import net.sf.basedb.core.VirtualColumn; |
4925 |
08 May 09 |
nicklas |
32 |
import net.sf.basedb.core.query.Dynamic; |
4925 |
08 May 09 |
nicklas |
33 |
import net.sf.basedb.core.query.Expression; |
4925 |
08 May 09 |
nicklas |
34 |
import net.sf.basedb.util.formatter.Formatter; |
4925 |
08 May 09 |
nicklas |
35 |
|
4925 |
08 May 09 |
nicklas |
36 |
/** |
4925 |
08 May 09 |
nicklas |
Utility class with factory methods that helps with the creation |
4925 |
08 May 09 |
nicklas |
of exportable fields. |
4925 |
08 May 09 |
nicklas |
39 |
|
4925 |
08 May 09 |
nicklas |
@author Nicklas |
4925 |
08 May 09 |
nicklas |
@version 2.12 |
4925 |
08 May 09 |
nicklas |
@base.modified $Date$ |
4925 |
08 May 09 |
nicklas |
43 |
*/ |
4925 |
08 May 09 |
nicklas |
44 |
public class ExportableFieldFactory |
4925 |
08 May 09 |
nicklas |
45 |
{ |
4925 |
08 May 09 |
nicklas |
46 |
/** |
4925 |
08 May 09 |
nicklas |
Create an annotation assay field. |
4925 |
08 May 09 |
nicklas |
@param at The annotation type |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter or null |
4925 |
08 May 09 |
nicklas |
@see AnnotationAssayField |
4925 |
08 May 09 |
nicklas |
51 |
*/ |
4925 |
08 May 09 |
nicklas |
52 |
public static AnnotationAssayField annotation(AnnotationType at, Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
53 |
{ |
5319 |
20 Apr 10 |
nicklas |
54 |
return annotation(at, null, formatter); |
5319 |
20 Apr 10 |
nicklas |
55 |
} |
5319 |
20 Apr 10 |
nicklas |
56 |
|
5319 |
20 Apr 10 |
nicklas |
57 |
/** |
5319 |
20 Apr 10 |
nicklas |
Create an annotation assay field, overriding the title |
5319 |
20 Apr 10 |
nicklas |
of the annotation type. |
5319 |
20 Apr 10 |
nicklas |
@param at The annotation type |
5319 |
20 Apr 10 |
nicklas |
@param title A custom title for the assay field, or null to use the |
5319 |
20 Apr 10 |
nicklas |
name of the annotation type |
5319 |
20 Apr 10 |
nicklas |
@param formatter A formatter or null |
5319 |
20 Apr 10 |
nicklas |
@see AnnotationAssayField |
5319 |
20 Apr 10 |
nicklas |
@since 2.15 |
5319 |
20 Apr 10 |
nicklas |
66 |
*/ |
5319 |
20 Apr 10 |
nicklas |
67 |
public static AnnotationAssayField annotation(AnnotationType at, String title, Formatter<?> formatter) |
5319 |
20 Apr 10 |
nicklas |
68 |
{ |
4925 |
08 May 09 |
nicklas |
69 |
AnnotationAssayField field = new AnnotationAssayField(); |
4925 |
08 May 09 |
nicklas |
70 |
field.setAnnotationType(at); |
4925 |
08 May 09 |
nicklas |
71 |
field.setFormatter(formatter); |
5319 |
20 Apr 10 |
nicklas |
72 |
field.setTitle(title); |
4925 |
08 May 09 |
nicklas |
73 |
return field; |
4925 |
08 May 09 |
nicklas |
74 |
} |
5319 |
20 Apr 10 |
nicklas |
75 |
|
4925 |
08 May 09 |
nicklas |
76 |
|
4925 |
08 May 09 |
nicklas |
77 |
/** |
5199 |
15 Dec 09 |
nicklas |
Create a property assay field. This field is used to export, for |
5199 |
15 Dec 09 |
nicklas |
example, name and description, from the bioassay. |
5590 |
16 Mar 11 |
nicklas |
@param property The property to export, see {@link Metadata#getPropertyPath(String, boolean)} |
5199 |
15 Dec 09 |
nicklas |
for more information about the syntax of this parameter. |
5199 |
15 Dec 09 |
nicklas |
@param title The column title |
5199 |
15 Dec 09 |
nicklas |
@param formatter A formatter or null |
5199 |
15 Dec 09 |
nicklas |
@return An {@link AssayPropertyField} object |
5199 |
15 Dec 09 |
nicklas |
@since 2.15 |
5199 |
15 Dec 09 |
nicklas |
86 |
*/ |
5199 |
15 Dec 09 |
nicklas |
87 |
public static AssayPropertyField assayProperty(String property, String title, |
5319 |
20 Apr 10 |
nicklas |
88 |
Type type, Formatter<?> formatter) |
5199 |
15 Dec 09 |
nicklas |
89 |
{ |
5199 |
15 Dec 09 |
nicklas |
90 |
AssayPropertyField field = new AssayPropertyField(); |
5199 |
15 Dec 09 |
nicklas |
91 |
field.setProperty(property); |
5199 |
15 Dec 09 |
nicklas |
92 |
field.setTitle(title); |
5199 |
15 Dec 09 |
nicklas |
93 |
field.setFormatter(formatter); |
5319 |
20 Apr 10 |
nicklas |
94 |
field.setType(type); |
5199 |
15 Dec 09 |
nicklas |
95 |
return field; |
5199 |
15 Dec 09 |
nicklas |
96 |
} |
5199 |
15 Dec 09 |
nicklas |
97 |
|
5199 |
15 Dec 09 |
nicklas |
98 |
/** |
4925 |
08 May 09 |
nicklas |
Create a simple dynamic field. |
4925 |
08 May 09 |
nicklas |
100 |
|
4925 |
08 May 09 |
nicklas |
@param e The expression to export |
4925 |
08 May 09 |
nicklas |
@param title The column title |
4925 |
08 May 09 |
nicklas |
@param averageMethod Average method to use or null to use the |
4925 |
08 May 09 |
nicklas |
average method specified by the bioassay set |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter or null |
4925 |
08 May 09 |
nicklas |
@see SimpleDynamicField |
5319 |
20 Apr 10 |
nicklas |
@since 2.15 |
4925 |
08 May 09 |
nicklas |
108 |
*/ |
4925 |
08 May 09 |
nicklas |
109 |
public static SimpleDynamicField simple(Expression e, String title, |
5319 |
20 Apr 10 |
nicklas |
110 |
Type type, Formula.AverageMethod averageMethod, Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
111 |
{ |
4925 |
08 May 09 |
nicklas |
112 |
SimpleDynamicField field = new SimpleDynamicField(); |
4925 |
08 May 09 |
nicklas |
113 |
field.setExpression(e); |
4925 |
08 May 09 |
nicklas |
114 |
field.setTitle(title); |
5319 |
20 Apr 10 |
nicklas |
115 |
field.setType(type); |
4925 |
08 May 09 |
nicklas |
116 |
field.setAverageMethod(averageMethod); |
4925 |
08 May 09 |
nicklas |
117 |
field.setFormatter(formatter); |
4925 |
08 May 09 |
nicklas |
118 |
return field; |
4925 |
08 May 09 |
nicklas |
119 |
} |
4925 |
08 May 09 |
nicklas |
120 |
|
4925 |
08 May 09 |
nicklas |
121 |
/** |
4925 |
08 May 09 |
nicklas |
Create a JEP dynamic field. |
4925 |
08 May 09 |
nicklas |
123 |
|
4925 |
08 May 09 |
nicklas |
@param jep The JEP expression |
4925 |
08 May 09 |
nicklas |
@param title The column title |
5319 |
20 Apr 10 |
nicklas |
@param type The data type of the expression |
4925 |
08 May 09 |
nicklas |
@param averageMethod Average method to use or null to use the |
4925 |
08 May 09 |
nicklas |
average method specified by the bioassay set |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter or null |
4925 |
08 May 09 |
nicklas |
130 |
*/ |
5319 |
20 Apr 10 |
nicklas |
131 |
public static JepDynamicField jep(String jep, String title, Type type, |
5319 |
20 Apr 10 |
nicklas |
132 |
Formula.AverageMethod averageMethod, Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
133 |
{ |
4925 |
08 May 09 |
nicklas |
134 |
JepDynamicField field = new JepDynamicField(); |
4925 |
08 May 09 |
nicklas |
135 |
field.setTitle(title); |
4925 |
08 May 09 |
nicklas |
136 |
field.setJep(jep); |
4925 |
08 May 09 |
nicklas |
137 |
field.setAverageMethod(averageMethod); |
4925 |
08 May 09 |
nicklas |
138 |
field.setFormatter(formatter); |
5319 |
20 Apr 10 |
nicklas |
139 |
field.setType(type); |
4925 |
08 May 09 |
nicklas |
140 |
return field; |
4925 |
08 May 09 |
nicklas |
141 |
} |
4925 |
08 May 09 |
nicklas |
142 |
|
4925 |
08 May 09 |
nicklas |
143 |
/** |
4925 |
08 May 09 |
nicklas |
Create a simple dynamic field that exports the channel intensity |
4925 |
08 May 09 |
nicklas |
of the given channel. This method uses {@link Dynamic#column(VirtualColumn)} |
4925 |
08 May 09 |
nicklas |
and {@link VirtualColumn#channelRaw(int)} to generate the expression. It |
4925 |
08 May 09 |
nicklas |
uses the average method specified by the bioassay set. |
4925 |
08 May 09 |
nicklas |
148 |
|
4925 |
08 May 09 |
nicklas |
@param channel The channel number |
4925 |
08 May 09 |
nicklas |
@param title The column title. If null, the title is generated as 'intensity' + channel |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter for numeric data or null |
4925 |
08 May 09 |
nicklas |
152 |
*/ |
4925 |
08 May 09 |
nicklas |
153 |
public static SimpleDynamicField channel(int channel, String title, |
4925 |
08 May 09 |
nicklas |
154 |
Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
155 |
{ |
5319 |
20 Apr 10 |
nicklas |
156 |
if (title == null) title = "Ch " + channel; |
4925 |
08 May 09 |
nicklas |
157 |
Expression e = Dynamic.column(VirtualColumn.channelRaw(channel)); |
5319 |
20 Apr 10 |
nicklas |
158 |
return simple(e, title, Type.FLOAT, null, formatter); |
4925 |
08 May 09 |
nicklas |
159 |
} |
4925 |
08 May 09 |
nicklas |
160 |
|
4925 |
08 May 09 |
nicklas |
161 |
/** |
4925 |
08 May 09 |
nicklas |
Create a simple dynamic field that exports a raw data value. |
4925 |
08 May 09 |
nicklas |
This method uses {@link Dynamic#rawData(String)} to generate the |
4925 |
08 May 09 |
nicklas |
expression and uses the average method specified by the raw data |
4925 |
08 May 09 |
nicklas |
property. |
4925 |
08 May 09 |
nicklas |
@param property The raw data property |
4925 |
08 May 09 |
nicklas |
@param title The column title, or null to use the title of |
4925 |
08 May 09 |
nicklas |
the property |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter or null |
4925 |
08 May 09 |
nicklas |
170 |
*/ |
4925 |
08 May 09 |
nicklas |
171 |
public static SimpleDynamicField rawData(RawDataProperty property, String title, |
4925 |
08 May 09 |
nicklas |
172 |
Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
173 |
{ |
4925 |
08 May 09 |
nicklas |
174 |
String name = property.getName(); |
4925 |
08 May 09 |
nicklas |
175 |
if (title == null) title = property.getTitle(); |
5319 |
20 Apr 10 |
nicklas |
176 |
return simple(Dynamic.rawData(name), title, property.getType(), |
5319 |
20 Apr 10 |
nicklas |
177 |
property.getAverageMethod(), formatter); |
4925 |
08 May 09 |
nicklas |
178 |
} |
4925 |
08 May 09 |
nicklas |
179 |
|
4925 |
08 May 09 |
nicklas |
180 |
/** |
4925 |
08 May 09 |
nicklas |
Create a simple dynamic field that exports a raw data value. |
4925 |
08 May 09 |
nicklas |
This method uses {@link Dynamic#rawData(String)} to generate the |
4925 |
08 May 09 |
nicklas |
expression. |
4925 |
08 May 09 |
nicklas |
@param property The raw data property |
4925 |
08 May 09 |
nicklas |
@param title The column title, or null to use the property |
4925 |
08 May 09 |
nicklas |
as title |
4925 |
08 May 09 |
nicklas |
@param averageMethod Average method to use or null to use |
5385 |
13 Aug 10 |
nicklas |
{@link net.sf.basedb.core.Formula.AverageMethod#NONE} |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter or null |
5319 |
20 Apr 10 |
nicklas |
@since 2.15 |
4925 |
08 May 09 |
nicklas |
191 |
*/ |
5319 |
20 Apr 10 |
nicklas |
192 |
public static SimpleDynamicField rawData(String property, String title, Type type, |
4925 |
08 May 09 |
nicklas |
193 |
Formula.AverageMethod averageMethod, Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
194 |
{ |
4925 |
08 May 09 |
nicklas |
195 |
if (title == null) title = property; |
4925 |
08 May 09 |
nicklas |
196 |
if (averageMethod == null) averageMethod = Formula.AverageMethod.NONE; |
5319 |
20 Apr 10 |
nicklas |
197 |
return simple(Dynamic.rawData(property), title, type, averageMethod, formatter); |
4925 |
08 May 09 |
nicklas |
198 |
} |
4925 |
08 May 09 |
nicklas |
199 |
|
5319 |
20 Apr 10 |
nicklas |
200 |
|
4925 |
08 May 09 |
nicklas |
201 |
/** |
4925 |
08 May 09 |
nicklas |
Create a simple dynamic field that exports reporter annotation values. |
4925 |
08 May 09 |
nicklas |
This method uses {@link Dynamic#reporter(String)} to generate the |
4925 |
08 May 09 |
nicklas |
expression and uses the average method specified by the reporter |
4925 |
08 May 09 |
nicklas |
property. |
4925 |
08 May 09 |
nicklas |
@param property The reporter property |
4925 |
08 May 09 |
nicklas |
@param title The column title, or null to use the title of |
4925 |
08 May 09 |
nicklas |
the property |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter or null |
4925 |
08 May 09 |
nicklas |
210 |
*/ |
4925 |
08 May 09 |
nicklas |
211 |
public static SimpleDynamicField reporter(ExtendedProperty property, String title, |
4925 |
08 May 09 |
nicklas |
212 |
Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
213 |
{ |
4925 |
08 May 09 |
nicklas |
214 |
String name = property.getName(); |
4925 |
08 May 09 |
nicklas |
215 |
if (title == null) title = property.getTitle(); |
5319 |
20 Apr 10 |
nicklas |
216 |
return simple(Dynamic.reporter(name), title, property.getType(), |
5319 |
20 Apr 10 |
nicklas |
217 |
property.getAverageMethod(), formatter); |
4925 |
08 May 09 |
nicklas |
218 |
} |
5319 |
20 Apr 10 |
nicklas |
219 |
|
5319 |
20 Apr 10 |
nicklas |
220 |
/** |
4925 |
08 May 09 |
nicklas |
Create a simple dynamic field that exports reporter annotation values. |
4925 |
08 May 09 |
nicklas |
This method uses {@link Dynamic#reporter(String)} to generate the |
4925 |
08 May 09 |
nicklas |
expression. |
4925 |
08 May 09 |
nicklas |
@param property The reporter property |
4925 |
08 May 09 |
nicklas |
@param title The column title, or null to use the property |
4925 |
08 May 09 |
nicklas |
as title |
4925 |
08 May 09 |
nicklas |
@param averageMethod Average method to use or null to use |
5385 |
13 Aug 10 |
nicklas |
{@link net.sf.basedb.core.Formula.AverageMethod#NONE} |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter or null |
5319 |
20 Apr 10 |
nicklas |
@since 2.15 |
4925 |
08 May 09 |
nicklas |
231 |
*/ |
5319 |
20 Apr 10 |
nicklas |
232 |
public static DynamicField reporter(String property, String title, Type type, |
4925 |
08 May 09 |
nicklas |
233 |
Formula.AverageMethod averageMethod, Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
234 |
{ |
4925 |
08 May 09 |
nicklas |
235 |
if (title == null) title = property; |
4925 |
08 May 09 |
nicklas |
236 |
if (averageMethod == null) averageMethod = Formula.AverageMethod.NONE; |
5319 |
20 Apr 10 |
nicklas |
237 |
return simple(Dynamic.reporter(property), title, type, averageMethod, formatter); |
4925 |
08 May 09 |
nicklas |
238 |
} |
4925 |
08 May 09 |
nicklas |
239 |
|
5319 |
20 Apr 10 |
nicklas |
240 |
|
4925 |
08 May 09 |
nicklas |
241 |
/** |
4925 |
08 May 09 |
nicklas |
Create a JEP dynamic field that exports the result of |
4925 |
08 May 09 |
nicklas |
the JEP expression in a formula. This method doesn't |
4925 |
08 May 09 |
nicklas |
check the type of the formula or the number of expressions |
4925 |
08 May 09 |
nicklas |
stored in the formula. It just takes the first expression |
4925 |
08 May 09 |
nicklas |
it finds. |
4925 |
08 May 09 |
nicklas |
247 |
|
4925 |
08 May 09 |
nicklas |
@param f The formula |
4925 |
08 May 09 |
nicklas |
@param title The column title, or null to use the |
4925 |
08 May 09 |
nicklas |
name of the formula as the title |
4925 |
08 May 09 |
nicklas |
@param formatter A formatter or null |
4925 |
08 May 09 |
nicklas |
252 |
*/ |
4925 |
08 May 09 |
nicklas |
253 |
public static JepDynamicField formula(Formula f, String title, Formatter<?> formatter) |
4925 |
08 May 09 |
nicklas |
254 |
{ |
4925 |
08 May 09 |
nicklas |
255 |
String expression = f.getFormula(0); |
4925 |
08 May 09 |
nicklas |
256 |
if (title == null) title = f.getName(); |
5319 |
20 Apr 10 |
nicklas |
257 |
return jep(expression, title, f.getValueType(), f.getAverageMethod(), formatter); |
4925 |
08 May 09 |
nicklas |
258 |
} |
4925 |
08 May 09 |
nicklas |
259 |
|
4928 |
13 May 09 |
nicklas |
260 |
/** |
4928 |
13 May 09 |
nicklas |
Create a JEP dynamic field that exports an extra value. |
4928 |
13 May 09 |
nicklas |
@param extra The extra value type |
4928 |
13 May 09 |
nicklas |
@param title The column title, or null to use the |
4928 |
13 May 09 |
nicklas |
name of the formula as the title |
4928 |
13 May 09 |
nicklas |
@param formatter A formatter or null |
4928 |
13 May 09 |
nicklas |
266 |
*/ |
4928 |
13 May 09 |
nicklas |
267 |
public static JepDynamicField extraValue(ExtraValueType extra, String title, Formatter<?> formatter) |
4928 |
13 May 09 |
nicklas |
268 |
{ |
4928 |
13 May 09 |
nicklas |
269 |
String expression = "xtra('" + extra.getExternalId() + "')"; |
4928 |
13 May 09 |
nicklas |
270 |
if (title == null) title = extra.getName(); |
5319 |
20 Apr 10 |
nicklas |
271 |
return jep(expression, title, extra.getValueType(), extra.getAverageMethod(), formatter); |
4928 |
13 May 09 |
nicklas |
272 |
} |
4928 |
13 May 09 |
nicklas |
273 |
|
4925 |
08 May 09 |
nicklas |
274 |
} |