src/core/net/sf/basedb/util/export/spotdata/ExportableFieldFactory.java

Code
Comments
Other
Rev Date Author Line
4925 08 May 09 nicklas 1 /**
4925 08 May 09 nicklas 2   $Id$
4925 08 May 09 nicklas 3
4925 08 May 09 nicklas 4   Copyright (C) 2009 Nicklas Nordborg
4925 08 May 09 nicklas 5
4925 08 May 09 nicklas 6   This file is part of BASE - BioArray Software Environment.
4925 08 May 09 nicklas 7   Available at http://base.thep.lu.se/
4925 08 May 09 nicklas 8
4925 08 May 09 nicklas 9   BASE is free software; you can redistribute it and/or
4925 08 May 09 nicklas 10   modify it under the terms of the GNU General Public License
4925 08 May 09 nicklas 11   as published by the Free Software Foundation; either version 3
4925 08 May 09 nicklas 12   of the License, or (at your option) any later version.
4925 08 May 09 nicklas 13
4925 08 May 09 nicklas 14   BASE is distributed in the hope that it will be useful,
4925 08 May 09 nicklas 15   but WITHOUT ANY WARRANTY; without even the implied warranty of
4925 08 May 09 nicklas 16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
4925 08 May 09 nicklas 17   GNU General Public License for more details.
4925 08 May 09 nicklas 18
4925 08 May 09 nicklas 19   You should have received a copy of the GNU General Public License
4925 08 May 09 nicklas 20   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 37   Utility class with factory methods that helps with the creation
4925 08 May 09 nicklas 38   of exportable fields.
4925 08 May 09 nicklas 39   
4925 08 May 09 nicklas 40   @author Nicklas
4925 08 May 09 nicklas 41   @version 2.12
4925 08 May 09 nicklas 42   @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 47     Create an annotation assay field.
4925 08 May 09 nicklas 48     @param at The annotation type
4925 08 May 09 nicklas 49     @param formatter A formatter or null
4925 08 May 09 nicklas 50     @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 58     Create an annotation assay field, overriding the title
5319 20 Apr 10 nicklas 59     of the annotation type.
5319 20 Apr 10 nicklas 60     @param at The annotation type
5319 20 Apr 10 nicklas 61     @param title A custom title for the assay field, or null to use the 
5319 20 Apr 10 nicklas 62       name of the annotation type
5319 20 Apr 10 nicklas 63     @param formatter A formatter or null
5319 20 Apr 10 nicklas 64     @see AnnotationAssayField
5319 20 Apr 10 nicklas 65     @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 78     Create a property assay field. This field is used to export, for
5199 15 Dec 09 nicklas 79     example, name and description, from the bioassay.
5590 16 Mar 11 nicklas 80     @param property The property to export, see {@link Metadata#getPropertyPath(String, boolean)}
5199 15 Dec 09 nicklas 81       for more information about the syntax of this parameter.
5199 15 Dec 09 nicklas 82     @param title The column title
5199 15 Dec 09 nicklas 83     @param formatter A formatter or null
5199 15 Dec 09 nicklas 84     @return An {@link AssayPropertyField} object
5199 15 Dec 09 nicklas 85     @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 99     Create a simple dynamic field.
4925 08 May 09 nicklas 100     
4925 08 May 09 nicklas 101     @param e The expression to export
4925 08 May 09 nicklas 102     @param title The column title
4925 08 May 09 nicklas 103     @param averageMethod Average method to use or null to use the
4925 08 May 09 nicklas 104       average method specified by the bioassay set
4925 08 May 09 nicklas 105     @param formatter A formatter or null
4925 08 May 09 nicklas 106     @see SimpleDynamicField
5319 20 Apr 10 nicklas 107     @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 122     Create a JEP dynamic field.
4925 08 May 09 nicklas 123     
4925 08 May 09 nicklas 124     @param jep The JEP expression
4925 08 May 09 nicklas 125     @param title The column title
5319 20 Apr 10 nicklas 126     @param type The data type of the expression
4925 08 May 09 nicklas 127     @param averageMethod Average method to use or null to use the
4925 08 May 09 nicklas 128       average method specified by the bioassay set
4925 08 May 09 nicklas 129     @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 144     Create a simple dynamic field that exports the channel intensity
4925 08 May 09 nicklas 145     of the given channel. This method uses {@link Dynamic#column(VirtualColumn)}
4925 08 May 09 nicklas 146     and {@link VirtualColumn#channelRaw(int)} to generate the expression. It
4925 08 May 09 nicklas 147     uses the average method specified by the bioassay set.
4925 08 May 09 nicklas 148     
4925 08 May 09 nicklas 149     @param channel The channel number
4925 08 May 09 nicklas 150     @param title The column title. If null, the title is generated as 'intensity' + channel
4925 08 May 09 nicklas 151     @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 162     Create a simple dynamic field that exports a raw data value.
4925 08 May 09 nicklas 163     This method uses {@link Dynamic#rawData(String)} to generate the
4925 08 May 09 nicklas 164     expression and uses the average method specified by the raw data
4925 08 May 09 nicklas 165     property.
4925 08 May 09 nicklas 166     @param property The raw data property
4925 08 May 09 nicklas 167     @param title The column title, or null to use the title of 
4925 08 May 09 nicklas 168       the property
4925 08 May 09 nicklas 169     @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 181     Create a simple dynamic field that exports a raw data value.
4925 08 May 09 nicklas 182     This method uses {@link Dynamic#rawData(String)} to generate the
4925 08 May 09 nicklas 183     expression.
4925 08 May 09 nicklas 184     @param property The raw data property
4925 08 May 09 nicklas 185     @param title The column title, or null to use the property
4925 08 May 09 nicklas 186       as title
4925 08 May 09 nicklas 187     @param averageMethod Average method to use or null to use 
5385 13 Aug 10 nicklas 188       {@link net.sf.basedb.core.Formula.AverageMethod#NONE}
4925 08 May 09 nicklas 189     @param formatter A formatter or null
5319 20 Apr 10 nicklas 190     @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 202     Create a simple dynamic field that exports reporter annotation values.
4925 08 May 09 nicklas 203     This method uses {@link Dynamic#reporter(String)} to generate the
4925 08 May 09 nicklas 204     expression and uses the average method specified by the reporter
4925 08 May 09 nicklas 205     property.
4925 08 May 09 nicklas 206     @param property The reporter property
4925 08 May 09 nicklas 207     @param title The column title, or null to use the title of 
4925 08 May 09 nicklas 208       the property
4925 08 May 09 nicklas 209     @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 221     Create a simple dynamic field that exports reporter annotation values.
4925 08 May 09 nicklas 222     This method uses {@link Dynamic#reporter(String)} to generate the
4925 08 May 09 nicklas 223     expression.
4925 08 May 09 nicklas 224     @param property The reporter property
4925 08 May 09 nicklas 225     @param title The column title, or null to use the property
4925 08 May 09 nicklas 226       as title
4925 08 May 09 nicklas 227     @param averageMethod Average method to use or null to use 
5385 13 Aug 10 nicklas 228       {@link net.sf.basedb.core.Formula.AverageMethod#NONE}
4925 08 May 09 nicklas 229     @param formatter A formatter or null
5319 20 Apr 10 nicklas 230     @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 242     Create a JEP dynamic field that exports the result of 
4925 08 May 09 nicklas 243     the JEP expression in a formula. This method doesn't
4925 08 May 09 nicklas 244     check the type of the formula or the number of expressions
4925 08 May 09 nicklas 245     stored in the formula. It just takes the first expression
4925 08 May 09 nicklas 246     it finds.
4925 08 May 09 nicklas 247     
4925 08 May 09 nicklas 248     @param f The formula
4925 08 May 09 nicklas 249     @param title The column title, or null to use the
4925 08 May 09 nicklas 250       name of the formula as the title
4925 08 May 09 nicklas 251     @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 261     Create a JEP dynamic field that exports an extra value.
4928 13 May 09 nicklas 262     @param extra The extra value type
4928 13 May 09 nicklas 263     @param title The column title, or null to use the
4928 13 May 09 nicklas 264       name of the formula as the title
4928 13 May 09 nicklas 265     @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 }