src/core/net/sf/basedb/util/export/spotdata/AnnotationAssayField.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 java.util.Collection;
4925 08 May 09 nicklas 25
4925 08 May 09 nicklas 26 import net.sf.basedb.core.AnnotationType;
4925 08 May 09 nicklas 27 import net.sf.basedb.core.BioAssay;
4925 08 May 09 nicklas 28 import net.sf.basedb.core.DbControl;
5319 20 Apr 10 nicklas 29 import net.sf.basedb.core.Type;
5130 13 Oct 09 nicklas 30 import net.sf.basedb.core.snapshot.SnapshotManager;
4925 08 May 09 nicklas 31 import net.sf.basedb.util.BioAssaySetUtil;
5319 20 Apr 10 nicklas 32 import net.sf.basedb.util.EqualsHelper;
4925 08 May 09 nicklas 33 import net.sf.basedb.util.formatter.Formatter;
4925 08 May 09 nicklas 34
4925 08 May 09 nicklas 35 /**
4925 08 May 09 nicklas 36   Assay field implementation that exports the annotations of a
4925 08 May 09 nicklas 37   bioassay. Before it can be used an {@link AnnotationType}
5319 20 Apr 10 nicklas 38   must be configured. One instance of this class is considered to
5319 20 Apr 10 nicklas 39   be equal to another if they are configured with the same annotation
5319 20 Apr 10 nicklas 40   type 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 AnnotationAssayField
4925 08 May 09 nicklas 47   implements AssayField
4925 08 May 09 nicklas 48 {
4925 08 May 09 nicklas 49   private AnnotationType at;
5319 20 Apr 10 nicklas 50   private String title;
4925 08 May 09 nicklas 51   private Formatter<?> formatter;
5130 13 Oct 09 nicklas 52   private SnapshotManager snapshotManager;
4925 08 May 09 nicklas 53   
4925 08 May 09 nicklas 54   /**
4925 08 May 09 nicklas 55     Create a new annotation field. Call {@link #setAnnotationType(AnnotationType)}
4925 08 May 09 nicklas 56     before use.
4925 08 May 09 nicklas 57   */
4925 08 May 09 nicklas 58   public AnnotationAssayField()
4925 08 May 09 nicklas 59   {}
4925 08 May 09 nicklas 60   
4925 08 May 09 nicklas 61   /*
4925 08 May 09 nicklas 62     From the AssayField interface
4925 08 May 09 nicklas 63     -------------------------------
4925 08 May 09 nicklas 64   */
4925 08 May 09 nicklas 65   /**
4925 08 May 09 nicklas 66     Returns the name of the configured annotation type, or the empty
4925 08 May 09 nicklas 67     string if not configured.
4925 08 May 09 nicklas 68    */
4925 08 May 09 nicklas 69   @Override
4925 08 May 09 nicklas 70   public String getTitle()
4925 08 May 09 nicklas 71   {
5319 20 Apr 10 nicklas 72     if (title != null) 
5319 20 Apr 10 nicklas 73     {
5319 20 Apr 10 nicklas 74       return title;
5319 20 Apr 10 nicklas 75     }
5319 20 Apr 10 nicklas 76     else if (at != null)
5319 20 Apr 10 nicklas 77     {
5319 20 Apr 10 nicklas 78       return at.getName();
5319 20 Apr 10 nicklas 79     }
5319 20 Apr 10 nicklas 80     return "";
4925 08 May 09 nicklas 81   }
4925 08 May 09 nicklas 82   /**
4925 08 May 09 nicklas 83     Return all annotation values that are related to the specified
4925 08 May 09 nicklas 84     bioassay, or null if not configured.
4925 08 May 09 nicklas 85   */
4925 08 May 09 nicklas 86   @Override
4925 08 May 09 nicklas 87   public Collection<?> getAssayValue(DbControl dc, BioAssay ba)
4925 08 May 09 nicklas 88   {
5130 13 Oct 09 nicklas 89     return at == null ? null : BioAssaySetUtil.getAnnotationValues(dc, snapshotManager, ba, at);
4925 08 May 09 nicklas 90   }
5319 20 Apr 10 nicklas 91   /**
5319 20 Apr 10 nicklas 92     Return the value type of the annotation type, or null if not
5319 20 Apr 10 nicklas 93     configured.
5319 20 Apr 10 nicklas 94     @since 2.15
5319 20 Apr 10 nicklas 95   */
4925 08 May 09 nicklas 96   @Override
5319 20 Apr 10 nicklas 97   public Type getType()
5319 20 Apr 10 nicklas 98   {
5319 20 Apr 10 nicklas 99     return at == null ? null : at.getValueType();
5319 20 Apr 10 nicklas 100   }
5319 20 Apr 10 nicklas 101   @Override
4925 08 May 09 nicklas 102   public Formatter<?> getFormatter()
4925 08 May 09 nicklas 103   {
4925 08 May 09 nicklas 104     return formatter;
4925 08 May 09 nicklas 105   }
5373 03 Aug 10 nicklas 106   /**
5373 03 Aug 10 nicklas 107     @return Always TRUE
5373 03 Aug 10 nicklas 108   */
5373 03 Aug 10 nicklas 109   @Override
5373 03 Aug 10 nicklas 110   public boolean isAnnotation()
5373 03 Aug 10 nicklas 111   {
5373 03 Aug 10 nicklas 112     return true;
5373 03 Aug 10 nicklas 113   }
4925 08 May 09 nicklas 114   // -----------------------------------
4925 08 May 09 nicklas 115   
4925 08 May 09 nicklas 116   /**
5319 20 Apr 10 nicklas 117     An assay field is equal to another assay field if it uses the same
5319 20 Apr 10 nicklas 118     annotation type and has the same title.
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 boolean equals(Object obj)
5319 20 Apr 10 nicklas 123   {
5319 20 Apr 10 nicklas 124     if (this == obj) return true;
5319 20 Apr 10 nicklas 125     if (!(obj instanceof AnnotationAssayField)) return false;
5319 20 Apr 10 nicklas 126     AnnotationAssayField other = (AnnotationAssayField)obj;
5319 20 Apr 10 nicklas 127     return EqualsHelper.equals(this.getAnnotationType(), other.getAnnotationType()) 
5319 20 Apr 10 nicklas 128       && EqualsHelper.equals(this.getTitle(), other.getTitle());
5319 20 Apr 10 nicklas 129   }
5319 20 Apr 10 nicklas 130
5319 20 Apr 10 nicklas 131   /**
5319 20 Apr 10 nicklas 132     @since 2.15
5319 20 Apr 10 nicklas 133   */
5319 20 Apr 10 nicklas 134   @Override
5319 20 Apr 10 nicklas 135   public int hashCode()
5319 20 Apr 10 nicklas 136   {
5319 20 Apr 10 nicklas 137     return 13 * EqualsHelper.hashCode(getAnnotationType()) + 
5319 20 Apr 10 nicklas 138       EqualsHelper.hashCode(getTitle());
5319 20 Apr 10 nicklas 139   }
5319 20 Apr 10 nicklas 140   /**
5319 20 Apr 10 nicklas 141      @since 2.15
5319 20 Apr 10 nicklas 142   */
5319 20 Apr 10 nicklas 143   @Override
5319 20 Apr 10 nicklas 144   public String toString()
5319 20 Apr 10 nicklas 145   {
5319 20 Apr 10 nicklas 146     return "AnnotationAssayField(title=" + getTitle() + "; annotation type=" + getAnnotationType() + ")";
5319 20 Apr 10 nicklas 147   }
5319 20 Apr 10 nicklas 148   
5319 20 Apr 10 nicklas 149   /**
4925 08 May 09 nicklas 150     Set the annotation type of the annotations that should be
4925 08 May 09 nicklas 151     exported in this field.
4925 08 May 09 nicklas 152   */
4925 08 May 09 nicklas 153   public void setAnnotationType(AnnotationType at)
4925 08 May 09 nicklas 154   {
4925 08 May 09 nicklas 155     this.at = at;
4925 08 May 09 nicklas 156   }
5319 20 Apr 10 nicklas 157
4925 08 May 09 nicklas 158   /**
4925 08 May 09 nicklas 159     Get the configured annotation type.
4925 08 May 09 nicklas 160   */
4925 08 May 09 nicklas 161   public AnnotationType getAnnotationType()
4925 08 May 09 nicklas 162   {
4925 08 May 09 nicklas 163     return at;
4925 08 May 09 nicklas 164   }
4925 08 May 09 nicklas 165   
4925 08 May 09 nicklas 166   /**
4925 08 May 09 nicklas 167     Set a formatter to use for formatting the exported values.
4925 08 May 09 nicklas 168   */
4925 08 May 09 nicklas 169   public void setFormatter(Formatter<?> formatter)
4925 08 May 09 nicklas 170   {
4925 08 May 09 nicklas 171     this.formatter = formatter;
4925 08 May 09 nicklas 172   }
5130 13 Oct 09 nicklas 173   
5130 13 Oct 09 nicklas 174   /**
5130 13 Oct 09 nicklas 175     Set the snapshot manager that should be used to load annotation values.
5130 13 Oct 09 nicklas 176     @since 2.14
5130 13 Oct 09 nicklas 177   */
5130 13 Oct 09 nicklas 178   public void setSnapshotManager(SnapshotManager snapshotManager)
5130 13 Oct 09 nicklas 179   {
5130 13 Oct 09 nicklas 180     this.snapshotManager = snapshotManager;
5130 13 Oct 09 nicklas 181   }
5319 20 Apr 10 nicklas 182   
5319 20 Apr 10 nicklas 183   /**
5319 20 Apr 10 nicklas 184     Set a custom title for the assay field.
5319 20 Apr 10 nicklas 185     @param title The custom title or null to use the name
5319 20 Apr 10 nicklas 186     of the annotation type
5319 20 Apr 10 nicklas 187   */
5319 20 Apr 10 nicklas 188   public void setTitle(String title)
5319 20 Apr 10 nicklas 189   {
5319 20 Apr 10 nicklas 190     this.title = title;
5319 20 Apr 10 nicklas 191   }
4925 08 May 09 nicklas 192
4925 08 May 09 nicklas 193 }