extensions/net.sf.basedb.varsearch/trunk/src/net/sf/basedb/varsearch/dao/Itemlist.java

Code
Comments
Other
Rev Date Author Line
6111 29 Jan 21 nicklas 1 package net.sf.basedb.varsearch.dao;
6111 29 Jan 21 nicklas 2
6111 29 Jan 21 nicklas 3 import java.lang.reflect.Field;
6111 29 Jan 21 nicklas 4 import java.util.List;
6111 29 Jan 21 nicklas 5
6111 29 Jan 21 nicklas 6 import net.sf.basedb.core.ItemList;
6111 29 Jan 21 nicklas 7 import net.sf.basedb.core.DbControl;
6111 29 Jan 21 nicklas 8 import net.sf.basedb.core.Include;
6111 29 Jan 21 nicklas 9 import net.sf.basedb.core.Item;
6111 29 Jan 21 nicklas 10 import net.sf.basedb.core.ItemQuery;
6111 29 Jan 21 nicklas 11 import net.sf.basedb.core.Type;
6111 29 Jan 21 nicklas 12 import net.sf.basedb.core.query.Expressions;
6111 29 Jan 21 nicklas 13 import net.sf.basedb.core.query.Hql;
6111 29 Jan 21 nicklas 14 import net.sf.basedb.core.query.Restrictions;
6111 29 Jan 21 nicklas 15
6111 29 Jan 21 nicklas 16 /**
6111 29 Jan 21 nicklas 17   Used to define special item lists.
6111 29 Jan 21 nicklas 18   
6111 29 Jan 21 nicklas 19   @author nicklas
6111 29 Jan 21 nicklas 20 */
6111 29 Jan 21 nicklas 21 public class Itemlist 
6111 29 Jan 21 nicklas 22 {
6111 29 Jan 21 nicklas 23
6111 29 Jan 21 nicklas 24   /**
6111 29 Jan 21 nicklas 25     The definition of the item list used for storing VariantCall RawBioassays
6140 19 Feb 21 nicklas 26     that should have their filtered VCF files indexed.
6111 29 Jan 21 nicklas 27   */
6140 19 Feb 21 nicklas 28   public static final Itemlist VARIANT_INDEX_FILTERED = 
6140 19 Feb 21 nicklas 29     new Itemlist("Variant index (filtered)", "net.sf.basedb.varsearch.filtered.need-index",
6140 19 Feb 21 nicklas 30       Item.RAWBIOASSAY, Rawdatatype.VARIANT_CALL, 
6140 19 Feb 21 nicklas 31       "This list contains RawBioassay items that should have their " +
6140 19 Feb 21 nicklas 32       "filtered VCF indexed by the Variant Indexing Service.");
6111 29 Jan 21 nicklas 33
6140 19 Feb 21 nicklas 34   /**
6140 19 Feb 21 nicklas 35     The definition of the item list used for storing VariantCall RawBioassays
6140 19 Feb 21 nicklas 36     that should have their raw/annotated VCF files indexed.
6140 19 Feb 21 nicklas 37   */
6140 19 Feb 21 nicklas 38   public static final Itemlist VARIANT_INDEX_ALL = 
6140 19 Feb 21 nicklas 39     new Itemlist("Variant index (all)", "net.sf.basedb.varsearch.all.need-index",
6140 19 Feb 21 nicklas 40       Item.RAWBIOASSAY, Rawdatatype.VARIANT_CALL, 
6140 19 Feb 21 nicklas 41       "This list contains RawBioassay items that should have their " +
6140 19 Feb 21 nicklas 42       "raw annotated VCF indexed by the Variant Indexing Service.");
6140 19 Feb 21 nicklas 43
6371 07 Sep 21 nicklas 44   /**
6371 07 Sep 21 nicklas 45     The definition of the item list used for storing VariantCall RawBioassays
6371 07 Sep 21 nicklas 46     that should have their targeted genotyping files indexed.
6371 07 Sep 21 nicklas 47     @since 1.1
6371 07 Sep 21 nicklas 48   */
6371 07 Sep 21 nicklas 49   public static final Itemlist VARIANT_INDEX_TARGETED = 
6371 07 Sep 21 nicklas 50     new Itemlist("Variant index (targeted genotyping)", "net.sf.basedb.varsearch.targeted.need-index",
6371 07 Sep 21 nicklas 51       Item.RAWBIOASSAY, Rawdatatype.VARIANT_CALL, 
6371 07 Sep 21 nicklas 52       "This list contains RawBioassay items that should have their " +
6371 07 Sep 21 nicklas 53       "targeted genotyping VCF indexed by the Variant Indexing Service.");
6371 07 Sep 21 nicklas 54
6539 17 Jan 22 nicklas 55   /**
6539 17 Jan 22 nicklas 56     The definition of the item list used for storing OncoArray500K rawbioassays
6539 17 Jan 22 nicklas 57      that should have their VCF genotyping files indexed.
6539 17 Jan 22 nicklas 58     @since 1.5
6539 17 Jan 22 nicklas 59   */
6539 17 Jan 22 nicklas 60   public static final Itemlist GENOTYPING_ONCOARRAY_500K = 
6539 17 Jan 22 nicklas 61     new Itemlist("Genotype index (OncoArray500K)", "net.sf.basedb.varsearch.oncoarray500K.need-index",
6543 18 Jan 22 nicklas 62       Item.RAWBIOASSAY, Rawdatatype.ONCOARRAY500K, 
6539 17 Jan 22 nicklas 63       "This list contains RawBioassay items that should have their " +
6539 17 Jan 22 nicklas 64       "OncoArray500K VCF indexed by the Variant Indexing Service.");
6111 29 Jan 21 nicklas 65   
6111 29 Jan 21 nicklas 66   /**
6111 29 Jan 21 nicklas 67     Get the bioplate type by name of the static constant defined in this class.
6111 29 Jan 21 nicklas 68     
6111 29 Jan 21 nicklas 69     @param cName The name of the static constant
6111 29 Jan 21 nicklas 70     @return A bioplate type object or null if not found
6111 29 Jan 21 nicklas 71    */
6111 29 Jan 21 nicklas 72   public static Itemlist getByCName(String cName)
6111 29 Jan 21 nicklas 73   {
6111 29 Jan 21 nicklas 74     if (cName == null) return null;
6111 29 Jan 21 nicklas 75     Itemlist bioplateType = null;
6111 29 Jan 21 nicklas 76     try
6111 29 Jan 21 nicklas 77     {
6111 29 Jan 21 nicklas 78       Field f = Itemlist.class.getDeclaredField(cName);
6111 29 Jan 21 nicklas 79       bioplateType = (Itemlist)f.get(null);
6111 29 Jan 21 nicklas 80     }
6111 29 Jan 21 nicklas 81     catch (NoSuchFieldException ex)
6111 29 Jan 21 nicklas 82     {}
6111 29 Jan 21 nicklas 83     catch (IllegalAccessException ex)
6111 29 Jan 21 nicklas 84     {}
6111 29 Jan 21 nicklas 85     catch (ClassCastException ex)
6111 29 Jan 21 nicklas 86     {}
6111 29 Jan 21 nicklas 87     return bioplateType;
6111 29 Jan 21 nicklas 88   }
6111 29 Jan 21 nicklas 89   
6111 29 Jan 21 nicklas 90   private final String name;
6111 29 Jan 21 nicklas 91   private final String externalId;
6111 29 Jan 21 nicklas 92   private final Item itemType;
6111 29 Jan 21 nicklas 93   private final Rawdatatype rawdatatype;
6111 29 Jan 21 nicklas 94   private final String description;
6111 29 Jan 21 nicklas 95   private int id;
6111 29 Jan 21 nicklas 96   
6111 29 Jan 21 nicklas 97   private Itemlist(String name, String externalId, Item itemType, Rawdatatype rawdatatype, String description)
6111 29 Jan 21 nicklas 98   {
6111 29 Jan 21 nicklas 99     this.name = name;
6111 29 Jan 21 nicklas 100     this.externalId = externalId;
6111 29 Jan 21 nicklas 101     this.itemType = itemType;
6111 29 Jan 21 nicklas 102     this.rawdatatype = rawdatatype;
6111 29 Jan 21 nicklas 103     this.description = description;
6111 29 Jan 21 nicklas 104   }
6111 29 Jan 21 nicklas 105     
6111 29 Jan 21 nicklas 106   /**
6111 29 Jan 21 nicklas 107     Get the name of the biomaterial list.
6111 29 Jan 21 nicklas 108   */
6111 29 Jan 21 nicklas 109   public String getName()
6111 29 Jan 21 nicklas 110   {
6111 29 Jan 21 nicklas 111     return name;
6111 29 Jan 21 nicklas 112   }
6111 29 Jan 21 nicklas 113   
6111 29 Jan 21 nicklas 114   /**
6111 29 Jan 21 nicklas 115     Get the list description.
6111 29 Jan 21 nicklas 116   */
6111 29 Jan 21 nicklas 117   public String getDescription()
6111 29 Jan 21 nicklas 118   {
6111 29 Jan 21 nicklas 119     return description;
6111 29 Jan 21 nicklas 120   }
6111 29 Jan 21 nicklas 121   
6111 29 Jan 21 nicklas 122   /**
6111 29 Jan 21 nicklas 123     Get the external id of the biomaterial list.
6111 29 Jan 21 nicklas 124   */
6111 29 Jan 21 nicklas 125   public String getExternalId()
6111 29 Jan 21 nicklas 126   {
6111 29 Jan 21 nicklas 127     return externalId;
6111 29 Jan 21 nicklas 128   }
6111 29 Jan 21 nicklas 129   
6111 29 Jan 21 nicklas 130   /**
6111 29 Jan 21 nicklas 131     Get the biomaterial item type that can be used in the list.
6111 29 Jan 21 nicklas 132   */
6111 29 Jan 21 nicklas 133   public Item getItemType()
6111 29 Jan 21 nicklas 134   {
6111 29 Jan 21 nicklas 135     return itemType;
6111 29 Jan 21 nicklas 136   }
6111 29 Jan 21 nicklas 137
6111 29 Jan 21 nicklas 138   /**
6111 29 Jan 21 nicklas 139     If the list contains raw bioassays, the raw data type can be specified.
6111 29 Jan 21 nicklas 140   */
6111 29 Jan 21 nicklas 141   public Rawdatatype getRawdatatype()
6111 29 Jan 21 nicklas 142   {
6111 29 Jan 21 nicklas 143     return rawdatatype;
6111 29 Jan 21 nicklas 144   }
6111 29 Jan 21 nicklas 145   
6111 29 Jan 21 nicklas 146   /**
6111 29 Jan 21 nicklas 147     Load the item list as a BASE item. Return null
6111 29 Jan 21 nicklas 148     if no BASE item is found instead of throwing an exception.
6111 29 Jan 21 nicklas 149     
6111 29 Jan 21 nicklas 150     @param dc The DbControl to use for database access
6111 29 Jan 21 nicklas 151     @return An ItemList object
6111 29 Jan 21 nicklas 152   */
6111 29 Jan 21 nicklas 153   public ItemList get(DbControl dc)
6111 29 Jan 21 nicklas 154   {
6111 29 Jan 21 nicklas 155     ItemList list = null;
6111 29 Jan 21 nicklas 156     if (id == 0)
6111 29 Jan 21 nicklas 157     {
6111 29 Jan 21 nicklas 158       List<ItemList> result = list(dc);
6111 29 Jan 21 nicklas 159       if (result.size() == 1)
6111 29 Jan 21 nicklas 160       {
6111 29 Jan 21 nicklas 161         list = result.get(0);
6111 29 Jan 21 nicklas 162         id = list.getId();
6111 29 Jan 21 nicklas 163       }
6111 29 Jan 21 nicklas 164     }
6111 29 Jan 21 nicklas 165     else
6111 29 Jan 21 nicklas 166     {
6111 29 Jan 21 nicklas 167       list = ItemList.getById(dc, id);
6111 29 Jan 21 nicklas 168     }
6111 29 Jan 21 nicklas 169     return list;
6111 29 Jan 21 nicklas 170     
6111 29 Jan 21 nicklas 171   }
6111 29 Jan 21 nicklas 172   
6111 29 Jan 21 nicklas 173   /**
6111 29 Jan 21 nicklas 174     List all item lists registered in BASE with an external id matching this list
6111 29 Jan 21 nicklas 175     definition. Normally, only a single biomaterial list type should be returned.
6111 29 Jan 21 nicklas 176   */
6111 29 Jan 21 nicklas 177   public List<ItemList> list(DbControl dc)
6111 29 Jan 21 nicklas 178   {
6111 29 Jan 21 nicklas 179     ItemQuery<ItemList> query = ItemList.getQuery();
6111 29 Jan 21 nicklas 180     query.restrict(
6111 29 Jan 21 nicklas 181       Restrictions.eq(
6111 29 Jan 21 nicklas 182         Hql.property("externalId"), 
6111 29 Jan 21 nicklas 183         Expressions.parameter("externalId", getExternalId(), Type.STRING)
6111 29 Jan 21 nicklas 184       ));
6111 29 Jan 21 nicklas 185     query.include(Include.ALL);
6111 29 Jan 21 nicklas 186     return query.list(dc);
6111 29 Jan 21 nicklas 187   }
6111 29 Jan 21 nicklas 188   
6111 29 Jan 21 nicklas 189   
6111 29 Jan 21 nicklas 190 }