src/core/net/sf/basedb/util/export/spotdata/JepDynamicField.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.BioAssaySet;
4925 08 May 09 nicklas 25 import net.sf.basedb.core.DbControl;
5319 20 Apr 10 nicklas 26 import net.sf.basedb.core.DynamicQuery;
4925 08 May 09 nicklas 27 import net.sf.basedb.core.Formula;
4925 08 May 09 nicklas 28 import net.sf.basedb.core.IntensityTransform;
5319 20 Apr 10 nicklas 29 import net.sf.basedb.core.Type;
4925 08 May 09 nicklas 30 import net.sf.basedb.core.query.Expression;
4925 08 May 09 nicklas 31 import net.sf.basedb.core.query.Expressions;
4925 08 May 09 nicklas 32 import net.sf.basedb.util.BioAssaySetUtil;
5319 20 Apr 10 nicklas 33 import net.sf.basedb.util.EqualsHelper;
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   A dynamic field implementation that uses a JEP expression to
5319 20 Apr 10 nicklas 38   generate the expression that is needed to select the data. One 
5319 20 Apr 10 nicklas 39   instance of this class is considered to be equal to another if 
5319 20 Apr 10 nicklas 40   they are configured with the same jep expression and title.
4925 08 May 09 nicklas 41
4925 08 May 09 nicklas 42   @author Nicklas
4925 08 May 09 nicklas 43   @version 2.12
4925 08 May 09 nicklas 44   @base.modified $Date$
4925 08 May 09 nicklas 45 */
4925 08 May 09 nicklas 46 public class JepDynamicField
4925 08 May 09 nicklas 47   implements DynamicField
4925 08 May 09 nicklas 48 {
4925 08 May 09 nicklas 49   private String jep;
4925 08 May 09 nicklas 50   private String title;
4925 08 May 09 nicklas 51   private Formula.AverageMethod averageMethod;
4925 08 May 09 nicklas 52   private Formatter<?> formatter;
5319 20 Apr 10 nicklas 53   private Type type;
4925 08 May 09 nicklas 54   
4925 08 May 09 nicklas 55   /**
4925 08 May 09 nicklas 56     Create a new object. Before it can be used it must be
4925 08 May 09 nicklas 57     configured.
4925 08 May 09 nicklas 58    */
4925 08 May 09 nicklas 59   public JepDynamicField()
4925 08 May 09 nicklas 60   {}
4925 08 May 09 nicklas 61   
4925 08 May 09 nicklas 62   /*
4925 08 May 09 nicklas 63     From the DynamicField interface
4925 08 May 09 nicklas 64     -------------------------------
4925 08 May 09 nicklas 65   */
4925 08 May 09 nicklas 66   /**
4925 08 May 09 nicklas 67     Converts the configured JEP expression using the
5319 20 Apr 10 nicklas 68     {@link BioAssaySetUtil#createJepExpression(DbControl, String, DynamicQuery)}
5385 13 Aug 10 nicklas 69     method. If 'forAverage' is TRUE the confgured {@link net.sf.basedb.core.Formula.AverageMethod} is 
4925 08 May 09 nicklas 70     allowed to transform  the expression. If no average method has been configured the 
4925 08 May 09 nicklas 71     average method specified by the {@link IntensityTransform} from
4925 08 May 09 nicklas 72     the 'source' bioassay set is used.
4925 08 May 09 nicklas 73   */
4925 08 May 09 nicklas 74   @Override
5319 20 Apr 10 nicklas 75   public Expression getExpression(DbControl dc, DynamicQuery query, BioAssaySet source, boolean forAverage)
4925 08 May 09 nicklas 76   {
5319 20 Apr 10 nicklas 77     Expression e = BioAssaySetUtil.createJepExpression(dc, jep, query);
4925 08 May 09 nicklas 78     if (forAverage)
4925 08 May 09 nicklas 79     {
4925 08 May 09 nicklas 80       Formula.AverageMethod avg = averageMethod == null ?
4925 08 May 09 nicklas 81           source.getIntensityTransform().getAverageMethod() : averageMethod;
4925 08 May 09 nicklas 82       e = avg.getAverageExpression(e);
4925 08 May 09 nicklas 83     }
4925 08 May 09 nicklas 84     return e;
4925 08 May 09 nicklas 85   }
4925 08 May 09 nicklas 86   @Override
4925 08 May 09 nicklas 87   public String getTitle()
4925 08 May 09 nicklas 88   {
4925 08 May 09 nicklas 89     return title;
4925 08 May 09 nicklas 90   }
4925 08 May 09 nicklas 91   @Override
5319 20 Apr 10 nicklas 92   public Type getType()
5319 20 Apr 10 nicklas 93   {
5319 20 Apr 10 nicklas 94     return type;
5319 20 Apr 10 nicklas 95   }
5319 20 Apr 10 nicklas 96   @Override
4925 08 May 09 nicklas 97   public Formatter<?> getFormatter()
4925 08 May 09 nicklas 98   {
4925 08 May 09 nicklas 99     return formatter;
4925 08 May 09 nicklas 100   }
4925 08 May 09 nicklas 101   // -----------------------------------
4925 08 May 09 nicklas 102   
4925 08 May 09 nicklas 103   /**
5319 20 Apr 10 nicklas 104     A jep dynamic field is equal to another field if it uses the same
5319 20 Apr 10 nicklas 105     jep expression and has the same title.
5319 20 Apr 10 nicklas 106     @since 2.15
5319 20 Apr 10 nicklas 107   */
5319 20 Apr 10 nicklas 108   @Override
5319 20 Apr 10 nicklas 109   public boolean equals(Object obj)
5319 20 Apr 10 nicklas 110   {
5319 20 Apr 10 nicklas 111     if (this == obj) return true;
5319 20 Apr 10 nicklas 112     if (!(obj instanceof JepDynamicField)) return false;
5319 20 Apr 10 nicklas 113     JepDynamicField other = (JepDynamicField)obj;
5319 20 Apr 10 nicklas 114     return EqualsHelper.equals(this.getJep(), other.getJep()) 
5319 20 Apr 10 nicklas 115       && EqualsHelper.equals(this.getTitle(), other.getTitle());
5319 20 Apr 10 nicklas 116   }
5319 20 Apr 10 nicklas 117   
5319 20 Apr 10 nicklas 118   /**
5319 20 Apr 10 nicklas 119     @since 2.15
5319 20 Apr 10 nicklas 120   */
5319 20 Apr 10 nicklas 121   @Override
5319 20 Apr 10 nicklas 122   public int hashCode()
5319 20 Apr 10 nicklas 123   {
5319 20 Apr 10 nicklas 124     return 13 * EqualsHelper.hashCode(getJep()) + 
5319 20 Apr 10 nicklas 125       EqualsHelper.hashCode(getTitle());
5319 20 Apr 10 nicklas 126   }
5319 20 Apr 10 nicklas 127   /**
5319 20 Apr 10 nicklas 128      @since 2.15
5319 20 Apr 10 nicklas 129   */
5319 20 Apr 10 nicklas 130   @Override
5319 20 Apr 10 nicklas 131   public String toString()
5319 20 Apr 10 nicklas 132   {
5319 20 Apr 10 nicklas 133     return "JepDynamicField(title=" + getTitle() + "; expression=" + getJep() + ")";
5319 20 Apr 10 nicklas 134   }
5319 20 Apr 10 nicklas 135   
5319 20 Apr 10 nicklas 136   /**
4925 08 May 09 nicklas 137     Get the configured JEP expression.
4925 08 May 09 nicklas 138   */
4925 08 May 09 nicklas 139   public String getJep()
4925 08 May 09 nicklas 140   {
4925 08 May 09 nicklas 141     return jep;
4925 08 May 09 nicklas 142   }
4925 08 May 09 nicklas 143
4925 08 May 09 nicklas 144   /**
4925 08 May 09 nicklas 145     Set the expression used to select data in the query. The
4925 08 May 09 nicklas 146     expression is parsed and converted to an {@link Expressions}
5319 20 Apr 10 nicklas 147     with the {@link BioAssaySetUtil#createJepExpression(DbControl, String, DynamicQuery)}
4925 08 May 09 nicklas 148     method.
4925 08 May 09 nicklas 149   */
4925 08 May 09 nicklas 150   public void setJep(String jep)
4925 08 May 09 nicklas 151   {
4925 08 May 09 nicklas 152     this.jep = jep;
4925 08 May 09 nicklas 153   }
4925 08 May 09 nicklas 154
4925 08 May 09 nicklas 155   /**
4925 08 May 09 nicklas 156     Set the column header title.
4925 08 May 09 nicklas 157   */
4925 08 May 09 nicklas 158   public void setTitle(String title)
4925 08 May 09 nicklas 159   {
4925 08 May 09 nicklas 160     this.title = title;
4925 08 May 09 nicklas 161   }
4925 08 May 09 nicklas 162   
4925 08 May 09 nicklas 163   /**
5319 20 Apr 10 nicklas 164     Set the data type of the exported field.
5319 20 Apr 10 nicklas 165     @since 2.15
5319 20 Apr 10 nicklas 166   */
5319 20 Apr 10 nicklas 167   public void setType(Type type)
5319 20 Apr 10 nicklas 168   {
5319 20 Apr 10 nicklas 169     this.type = type;
5319 20 Apr 10 nicklas 170   }
5319 20 Apr 10 nicklas 171   
5319 20 Apr 10 nicklas 172   /**
4925 08 May 09 nicklas 173     Get the average method to use if the exporter is exporting
4925 08 May 09 nicklas 174     averaged data. If no average method has been configured, the
4925 08 May 09 nicklas 175     everage method specified by the {@link IntensityTransform}
4925 08 May 09 nicklas 176     of the source bioassay set is used.
4925 08 May 09 nicklas 177   */
4925 08 May 09 nicklas 178   public Formula.AverageMethod getAverageMethod()
4925 08 May 09 nicklas 179   {
4925 08 May 09 nicklas 180     return averageMethod;
4925 08 May 09 nicklas 181   }
4925 08 May 09 nicklas 182   
4925 08 May 09 nicklas 183   /**
4925 08 May 09 nicklas 184     Set the average method to use when exporting averaged data.
4925 08 May 09 nicklas 185   */
4925 08 May 09 nicklas 186   public void setAverageMethod(Formula.AverageMethod averageMethod)
4925 08 May 09 nicklas 187   {
4925 08 May 09 nicklas 188     this.averageMethod = averageMethod;
4925 08 May 09 nicklas 189   }
4925 08 May 09 nicklas 190   
4925 08 May 09 nicklas 191   /**
4925 08 May 09 nicklas 192     Set a formatter to use for formatting the exported values.
4925 08 May 09 nicklas 193   */
4925 08 May 09 nicklas 194   public void setFormatter(Formatter<?> formatter)
4925 08 May 09 nicklas 195   {
4925 08 May 09 nicklas 196     this.formatter = formatter;
4925 08 May 09 nicklas 197   }
4925 08 May 09 nicklas 198
4925 08 May 09 nicklas 199
4925 08 May 09 nicklas 200 }