extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/CDna.java

Code
Comments
Other
Rev Date Author Line
1806 22 Jan 13 nicklas 1 package net.sf.basedb.reggie.dao;
1806 22 Jan 13 nicklas 2
1806 22 Jan 13 nicklas 3 import java.util.ArrayList;
1806 22 Jan 13 nicklas 4 import java.util.Collection;
1806 22 Jan 13 nicklas 5 import java.util.List;
1806 22 Jan 13 nicklas 6
1806 22 Jan 13 nicklas 7 import org.json.simple.JSONObject;
1806 22 Jan 13 nicklas 8
1806 22 Jan 13 nicklas 9 import net.sf.basedb.core.DbControl;
1806 22 Jan 13 nicklas 10 import net.sf.basedb.core.Extract;
4885 04 Jul 18 nicklas 11 import net.sf.basedb.core.Include;
2050 07 Oct 13 olle 12 import net.sf.basedb.core.ItemQuery;
2050 07 Oct 13 olle 13 import net.sf.basedb.core.Type;
2050 07 Oct 13 olle 14 import net.sf.basedb.core.query.Expressions;
2050 07 Oct 13 olle 15 import net.sf.basedb.core.query.Hql;
2917 11 Nov 14 nicklas 16 import net.sf.basedb.core.query.Orders;
2050 07 Oct 13 olle 17 import net.sf.basedb.core.query.Restrictions;
2050 07 Oct 13 olle 18 import net.sf.basedb.reggie.JsonUtil;
2917 11 Nov 14 nicklas 19 import net.sf.basedb.reggie.Reggie;
1806 22 Jan 13 nicklas 20
1806 22 Jan 13 nicklas 21 /**
1806 22 Jan 13 nicklas 22   Class for loading information that is related to mRNA extracts.
1806 22 Jan 13 nicklas 23   
1806 22 Jan 13 nicklas 24   @author nicklas
1867 19 Feb 13 nicklas 25   @since 2.12
1806 22 Jan 13 nicklas 26 */
1806 22 Jan 13 nicklas 27 public class CDna 
1806 22 Jan 13 nicklas 28   extends ReggieItem<Extract>
1806 22 Jan 13 nicklas 29 {
2050 07 Oct 13 olle 30   /**
2050 07 Oct 13 olle 31     Find all cDNA items by case name. This method will check for {@link Subtype#CDNA}
2050 07 Oct 13 olle 32     extracts with a name matching the case name (eg. xxx.r.m.c).
2050 07 Oct 13 olle 33     @since 2.13
2050 07 Oct 13 olle 34   */
2050 07 Oct 13 olle 35   public static List<CDna> findByCaseName(DbControl dc, String name)
2050 07 Oct 13 olle 36   {
2050 07 Oct 13 olle 37     // Get rid of suffixes in the name (eg. 'C' which is used for pre-neoadjuvant forms)
2050 07 Oct 13 olle 38     if (name.length() > 7) name = name.substring(0, 7);    
1806 22 Jan 13 nicklas 39
2050 07 Oct 13 olle 40     // Look for a cdna with the given name 
2050 07 Oct 13 olle 41     ItemQuery<Extract> cdnaQuery = Extract.getQuery();
2917 11 Nov 14 nicklas 42     cdnaQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
2050 07 Oct 13 olle 43     Subtype.CDNA.addFilter(dc, cdnaQuery);
2050 07 Oct 13 olle 44     cdnaQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.parameter("name", name+".%", Type.STRING)));
2917 11 Nov 14 nicklas 45     cdnaQuery.order(Orders.asc(Hql.property("name")));
2917 11 Nov 14 nicklas 46
2050 07 Oct 13 olle 47     List<Extract> tmp = cdnaQuery.list(dc);
2050 07 Oct 13 olle 48     List<CDna> cdna = new ArrayList<CDna>(tmp.size());
2050 07 Oct 13 olle 49     for (Extract e : tmp)
2050 07 Oct 13 olle 50     {
2050 07 Oct 13 olle 51       cdna.add(new CDna(e));
2050 07 Oct 13 olle 52     }
2050 07 Oct 13 olle 53     return cdna;
2050 07 Oct 13 olle 54   }
2050 07 Oct 13 olle 55
2050 07 Oct 13 olle 56   
1806 22 Jan 13 nicklas 57   /**
1806 22 Jan 13 nicklas 58     Get a cDNA extract when the id is known.
1806 22 Jan 13 nicklas 59   */
1806 22 Jan 13 nicklas 60   public static CDna getById(DbControl dc, int id)
1806 22 Jan 13 nicklas 61   {
1806 22 Jan 13 nicklas 62     return new CDna(Extract.getById(dc, id));
1806 22 Jan 13 nicklas 63   }
1806 22 Jan 13 nicklas 64   
2906 07 Nov 14 nicklas 65   /**
2906 07 Nov 14 nicklas 66     @since 2.18
2906 07 Nov 14 nicklas 67   */
2906 07 Nov 14 nicklas 68   public static CDna get(Extract extract)
2906 07 Nov 14 nicklas 69   {
2906 07 Nov 14 nicklas 70     return new CDna(extract);
2906 07 Nov 14 nicklas 71   }
2906 07 Nov 14 nicklas 72
1806 22 Jan 13 nicklas 73   public static List<CDna> toList(Collection<Extract> extracts)
1806 22 Jan 13 nicklas 74   {
1806 22 Jan 13 nicklas 75     List<CDna> cdna = new ArrayList<CDna>(extracts.size());
1806 22 Jan 13 nicklas 76     for (Extract e : extracts)
1806 22 Jan 13 nicklas 77     {
1806 22 Jan 13 nicklas 78       cdna.add(new CDna(e));
1806 22 Jan 13 nicklas 79     }
1806 22 Jan 13 nicklas 80     return cdna;
1806 22 Jan 13 nicklas 81   }
1806 22 Jan 13 nicklas 82   
1806 22 Jan 13 nicklas 83   private JSONObject jsonWell;
1806 22 Jan 13 nicklas 84   
1806 22 Jan 13 nicklas 85   private CDna(Extract extract)
1806 22 Jan 13 nicklas 86   {
1806 22 Jan 13 nicklas 87     super(extract);
1806 22 Jan 13 nicklas 88
1806 22 Jan 13 nicklas 89   }  
1806 22 Jan 13 nicklas 90   
1806 22 Jan 13 nicklas 91   /**
1806 22 Jan 13 nicklas 92     Get the real extract that represents this mRNA in BASE.
1806 22 Jan 13 nicklas 93   */
1806 22 Jan 13 nicklas 94   public Extract getExtract()
1806 22 Jan 13 nicklas 95   {
1806 22 Jan 13 nicklas 96     return getItem();
1806 22 Jan 13 nicklas 97   }
1806 22 Jan 13 nicklas 98
2906 07 Nov 14 nicklas 99   public MRna getMRna()
2906 07 Nov 14 nicklas 100   {
2906 07 Nov 14 nicklas 101     Extract crna = getItem();    
2906 07 Nov 14 nicklas 102     Extract mrna = (Extract)crna.getParent();
2906 07 Nov 14 nicklas 103     return MRna.get(mrna);
2906 07 Nov 14 nicklas 104   }
2906 07 Nov 14 nicklas 105
4885 04 Jul 18 nicklas 106   /**
4885 04 Jul 18 nicklas 107     Find the next name to give a "Library" child item. This assumes that
4885 04 Jul 18 nicklas 108     all child items are using the naming convention. foo.lib, foo.lib2, and
4885 04 Jul 18 nicklas 109     so on. NOTE! The first child item have no number!
4885 04 Jul 18 nicklas 110     @return The next unused name
4885 04 Jul 18 nicklas 111     @since 4.19
4885 04 Jul 18 nicklas 112   */
4885 04 Jul 18 nicklas 113   public String getNextLibraryName(DbControl dc)
4885 04 Jul 18 nicklas 114   {
4885 04 Jul 18 nicklas 115     Extract cdna = getItem();
6193 30 Mar 21 nicklas 116     ItemQuery<Extract> query = null;
6193 30 Mar 21 nicklas 117     if (cdna.isInDatabase())
6193 30 Mar 21 nicklas 118     {
6193 30 Mar 21 nicklas 119       query = cdna.getChildExtracts();
6193 30 Mar 21 nicklas 120       Subtype.LIBRARY.addFilter(dc, query);
6193 30 Mar 21 nicklas 121       query.setIncludes(Include.ALL);
6193 30 Mar 21 nicklas 122     }
4885 04 Jul 18 nicklas 123     return getNextChildItemName(dc, query, Subtype.LIBRARY.getItemSuffix(), true);
4885 04 Jul 18 nicklas 124   }
4885 04 Jul 18 nicklas 125
2906 07 Nov 14 nicklas 126   
1806 22 Jan 13 nicklas 127   @Override
1806 22 Jan 13 nicklas 128   protected void initJSON(JSONObject json) 
1806 22 Jan 13 nicklas 129   {
1806 22 Jan 13 nicklas 130     super.initJSON(json);
1806 22 Jan 13 nicklas 131     if (jsonWell != null) json.put("bioWell", jsonWell);
1806 22 Jan 13 nicklas 132     
1806 22 Jan 13 nicklas 133   }
1806 22 Jan 13 nicklas 134
1806 22 Jan 13 nicklas 135   /**
1806 22 Jan 13 nicklas 136     Load information about the plate and location the current cDNA
1806 22 Jan 13 nicklas 137     is located on.
1806 22 Jan 13 nicklas 138   */
1806 22 Jan 13 nicklas 139   public JSONObject loadBioPlateLocation()
1806 22 Jan 13 nicklas 140   {
2050 07 Oct 13 olle 141     if (jsonWell == null)
1806 22 Jan 13 nicklas 142     {
2134 11 Nov 13 nicklas 143       jsonWell = JsonUtil.getBioWellAsJSON(getItem().getBioWell(), true);
1806 22 Jan 13 nicklas 144     }
1806 22 Jan 13 nicklas 145     return jsonWell;
1806 22 Jan 13 nicklas 146   }
1806 22 Jan 13 nicklas 147   
1806 22 Jan 13 nicklas 148 }