3449 |
28 Jul 15 |
olle |
1 |
package net.sf.basedb.meludi.dao; |
3449 |
28 Jul 15 |
olle |
2 |
|
3449 |
28 Jul 15 |
olle |
3 |
import java.util.ArrayList; |
3449 |
28 Jul 15 |
olle |
4 |
import java.util.Collection; |
3449 |
28 Jul 15 |
olle |
5 |
import java.util.List; |
3449 |
28 Jul 15 |
olle |
6 |
|
3449 |
28 Jul 15 |
olle |
7 |
import org.json.simple.JSONArray; |
3449 |
28 Jul 15 |
olle |
8 |
import org.json.simple.JSONObject; |
3449 |
28 Jul 15 |
olle |
9 |
|
3449 |
28 Jul 15 |
olle |
10 |
import net.sf.basedb.core.BioPlate; |
3449 |
28 Jul 15 |
olle |
11 |
import net.sf.basedb.core.BioWell; |
3449 |
28 Jul 15 |
olle |
12 |
import net.sf.basedb.core.DbControl; |
3449 |
28 Jul 15 |
olle |
13 |
import net.sf.basedb.core.Extract; |
3449 |
28 Jul 15 |
olle |
14 |
import net.sf.basedb.core.ItemQuery; |
3449 |
28 Jul 15 |
olle |
15 |
import net.sf.basedb.core.Type; |
3449 |
28 Jul 15 |
olle |
16 |
import net.sf.basedb.core.query.Annotations; |
3449 |
28 Jul 15 |
olle |
17 |
import net.sf.basedb.core.query.Expression; |
3449 |
28 Jul 15 |
olle |
18 |
import net.sf.basedb.core.query.Expressions; |
3449 |
28 Jul 15 |
olle |
19 |
import net.sf.basedb.core.query.Hql; |
3449 |
28 Jul 15 |
olle |
20 |
import net.sf.basedb.core.query.Orders; |
3449 |
28 Jul 15 |
olle |
21 |
import net.sf.basedb.core.query.Restrictions; |
3449 |
28 Jul 15 |
olle |
22 |
import net.sf.basedb.meludi.Meludi; |
3449 |
28 Jul 15 |
olle |
23 |
import net.sf.basedb.util.MD5; |
3449 |
28 Jul 15 |
olle |
24 |
|
3449 |
28 Jul 15 |
olle |
25 |
/** |
3449 |
28 Jul 15 |
olle |
Class for loading information that is related to Pooled library extracts. |
3449 |
28 Jul 15 |
olle |
27 |
|
3449 |
28 Jul 15 |
olle |
@author nicklas |
3449 |
28 Jul 15 |
olle |
@since 2.12 |
3449 |
28 Jul 15 |
olle |
30 |
*/ |
3449 |
28 Jul 15 |
olle |
31 |
public class PooledLibrary |
3449 |
28 Jul 15 |
olle |
32 |
extends MeludiItem<Extract> |
3449 |
28 Jul 15 |
olle |
33 |
{ |
3449 |
28 Jul 15 |
olle |
34 |
|
3449 |
28 Jul 15 |
olle |
35 |
/** |
3449 |
28 Jul 15 |
olle |
Value for the {@link Annotationtype#POOL_MIXING_STRATEGY} annotation |
3449 |
28 Jul 15 |
olle |
when the pool should be mixed using the FIXED strategy. This strategy |
3449 |
28 Jul 15 |
olle |
mixes all libraries to the same volume at the expense of a non-optimal |
3449 |
28 Jul 15 |
olle |
final pool molarity. |
3449 |
28 Jul 15 |
olle |
@since 2.13 |
3449 |
28 Jul 15 |
olle |
41 |
*/ |
3449 |
28 Jul 15 |
olle |
42 |
public static final String MIXING_STRATEGY_FIXED = "fixed"; |
3449 |
28 Jul 15 |
olle |
43 |
|
3449 |
28 Jul 15 |
olle |
44 |
|
3449 |
28 Jul 15 |
olle |
45 |
/** |
3449 |
28 Jul 15 |
olle |
Value for the {@link Annotationtype#POOL_MIXING_STRATEGY} annotation |
3449 |
28 Jul 15 |
olle |
when the pool should be mixed using the DYNAMIC strategy. This strategy |
3449 |
28 Jul 15 |
olle |
optimizes the final pool molarity but mixes all libraries to different |
3449 |
28 Jul 15 |
olle |
volumes. |
3449 |
28 Jul 15 |
olle |
@since 2.13 |
3449 |
28 Jul 15 |
olle |
51 |
*/ |
3449 |
28 Jul 15 |
olle |
52 |
public static final String MIXING_STRATEGY_DYNAMIC = "dynamic"; |
3449 |
28 Jul 15 |
olle |
53 |
|
3449 |
28 Jul 15 |
olle |
54 |
/** |
3449 |
28 Jul 15 |
olle |
Flag value for the {@link Annotationtype#FLAG} annotation when clustering |
3449 |
28 Jul 15 |
olle |
a pooled library failed. This flag is normally attached to 'PooledLibrary' |
3449 |
28 Jul 15 |
olle |
items, but may be found on RNA items if the pool runs out of biomaterial. |
3449 |
28 Jul 15 |
olle |
@since 2.13 |
3449 |
28 Jul 15 |
olle |
59 |
*/ |
3449 |
28 Jul 15 |
olle |
60 |
public static final String FLAG_CLUSTERING_FAILED = "ClusteringFailed"; |
3449 |
28 Jul 15 |
olle |
61 |
|
3449 |
28 Jul 15 |
olle |
62 |
/** |
3449 |
28 Jul 15 |
olle |
Flag value for the {@link Annotationtype#FLAG} annotation when sequencing |
3449 |
28 Jul 15 |
olle |
a pooled library failed. This flag is normally attached to 'PooledLibrary' |
3449 |
28 Jul 15 |
olle |
items, but may be found on RNA items if the pool runs out of biomaterial. |
3449 |
28 Jul 15 |
olle |
@since 2.15 |
3449 |
28 Jul 15 |
olle |
67 |
*/ |
3449 |
28 Jul 15 |
olle |
68 |
public static final String FLAG_SEQUENCING_FAILED = "SequencingFailed"; |
3449 |
28 Jul 15 |
olle |
69 |
|
3449 |
28 Jul 15 |
olle |
70 |
/** |
3449 |
28 Jul 15 |
olle |
Flag value for the {@link Annotationtype#FLAG} annotation when |
3449 |
28 Jul 15 |
olle |
a pool has been sequenced but the demux step failed. |
3449 |
28 Jul 15 |
olle |
@since 2.16 |
3449 |
28 Jul 15 |
olle |
74 |
*/ |
3449 |
28 Jul 15 |
olle |
75 |
public static final String FLAG_DEMUX_FAILED = Rna.FLAG_DEMUX_FAILED; |
3449 |
28 Jul 15 |
olle |
76 |
|
3449 |
28 Jul 15 |
olle |
77 |
|
3449 |
28 Jul 15 |
olle |
78 |
/** |
3449 |
28 Jul 15 |
olle |
Find all pooled library items by case name. This method will check for {@link Subtype#LIBRARY} |
3449 |
28 Jul 15 |
olle |
extracts with a name matching the case name (eg. xxx.r.m.c.lib), and then list all |
3449 |
28 Jul 15 |
olle |
child extracts of type {@link Subtype#POOLED_LIBRARY}. |
3449 |
28 Jul 15 |
olle |
@since 2.13 |
3449 |
28 Jul 15 |
olle |
83 |
*/ |
3449 |
28 Jul 15 |
olle |
84 |
public static List<PooledLibrary> findByCaseName(DbControl dc, String name) |
3449 |
28 Jul 15 |
olle |
85 |
{ |
3449 |
28 Jul 15 |
olle |
// Get rid of suffixes in the name (eg. 'C' which is used for pre-neoadjuvant forms) |
4149 |
03 Oct 16 |
olle |
87 |
name = Meludi.fetchRootItemName(name, dc.getSessionControl().getActiveProjectId()); |
3449 |
28 Jul 15 |
olle |
88 |
|
3449 |
28 Jul 15 |
olle |
// Look for a library with the given name |
3449 |
28 Jul 15 |
olle |
90 |
ItemQuery<Extract> libQuery = Extract.getQuery(); |
3449 |
28 Jul 15 |
olle |
91 |
Subtype.LIBRARY.addFilter(dc, libQuery); |
3449 |
28 Jul 15 |
olle |
92 |
libQuery.setIncludes(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
3449 |
28 Jul 15 |
olle |
93 |
libQuery.restrict(Restrictions.like(Hql.property("name"), Expressions.parameter("name", name+".%", Type.STRING))); |
3449 |
28 Jul 15 |
olle |
94 |
libQuery.order(Orders.asc(Hql.property("name"))); |
3449 |
28 Jul 15 |
olle |
95 |
|
3449 |
28 Jul 15 |
olle |
96 |
List<Extract> tmp = libQuery.list(dc); |
3449 |
28 Jul 15 |
olle |
97 |
List<PooledLibrary> lib = new ArrayList<PooledLibrary>(); |
3449 |
28 Jul 15 |
olle |
98 |
for (Extract e : tmp) |
3449 |
28 Jul 15 |
olle |
99 |
{ |
3449 |
28 Jul 15 |
olle |
100 |
ItemQuery<Extract> pooledLibQuery = e.getChildExtracts(); |
3449 |
28 Jul 15 |
olle |
101 |
Subtype.POOLED_LIBRARY.addFilter(dc, pooledLibQuery); |
3449 |
28 Jul 15 |
olle |
102 |
pooledLibQuery.setIncludes(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
3449 |
28 Jul 15 |
olle |
103 |
pooledLibQuery.order(Orders.asc(Hql.property("name"))); |
3449 |
28 Jul 15 |
olle |
104 |
|
3449 |
28 Jul 15 |
olle |
105 |
List<Extract> tmpPooled = pooledLibQuery.list(dc); |
3449 |
28 Jul 15 |
olle |
106 |
for (Extract pooledLib: tmpPooled) |
3449 |
28 Jul 15 |
olle |
107 |
{ |
3449 |
28 Jul 15 |
olle |
108 |
lib.add(new PooledLibrary(pooledLib)); |
3449 |
28 Jul 15 |
olle |
109 |
} |
3449 |
28 Jul 15 |
olle |
110 |
} |
3449 |
28 Jul 15 |
olle |
111 |
return lib; |
3449 |
28 Jul 15 |
olle |
112 |
} |
3449 |
28 Jul 15 |
olle |
113 |
|
3449 |
28 Jul 15 |
olle |
114 |
|
3449 |
28 Jul 15 |
olle |
115 |
/** |
3449 |
28 Jul 15 |
olle |
Get a Library extract when the id is known. |
3449 |
28 Jul 15 |
olle |
117 |
*/ |
3449 |
28 Jul 15 |
olle |
118 |
public static PooledLibrary getById(DbControl dc, int id) |
3449 |
28 Jul 15 |
olle |
119 |
{ |
3449 |
28 Jul 15 |
olle |
120 |
return new PooledLibrary(Extract.getById(dc, id)); |
3449 |
28 Jul 15 |
olle |
121 |
} |
3449 |
28 Jul 15 |
olle |
122 |
|
3449 |
28 Jul 15 |
olle |
123 |
/** |
3449 |
28 Jul 15 |
olle |
Load pools used on the flow cell. |
3449 |
28 Jul 15 |
olle |
125 |
*/ |
3449 |
28 Jul 15 |
olle |
126 |
/* |
3449 |
28 Jul 15 |
olle |
public static List<PooledLibrary> getByFlowCell(DbControl dc, FlowCell flowCell) |
3449 |
28 Jul 15 |
olle |
128 |
{ |
3449 |
28 Jul 15 |
olle |
ItemQuery<Extract> poolQuery = Extract.getQuery(); |
3449 |
28 Jul 15 |
olle |
Subtype.POOLED_LIBRARY.addFilter(dc, poolQuery); |
3449 |
28 Jul 15 |
olle |
poolQuery.include(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
3449 |
28 Jul 15 |
olle |
poolQuery.setDistinct(true); |
3449 |
28 Jul 15 |
olle |
133 |
|
3449 |
28 Jul 15 |
olle |
// Join intermediate aliquot |
3449 |
28 Jul 15 |
olle |
poolQuery.join(Hql.innerJoin("childCreationEvents", "cce1")); |
3449 |
28 Jul 15 |
olle |
poolQuery.join(Hql.innerJoin("cce1", "event", "evt1")); |
3449 |
28 Jul 15 |
olle |
poolQuery.join(Hql.innerJoin("evt1", "bioMaterial", "pa")); |
3449 |
28 Jul 15 |
olle |
138 |
|
3449 |
28 Jul 15 |
olle |
// Join flow cell |
3449 |
28 Jul 15 |
olle |
poolQuery.join(Hql.innerJoin("pa", "childCreationEvents", "cce2")); |
3449 |
28 Jul 15 |
olle |
poolQuery.join(Hql.innerJoin("cce2", "event", "evt2")); |
3449 |
28 Jul 15 |
olle |
poolQuery.join(Hql.innerJoin("evt2", "physicalBioAssay", "fc")); |
3449 |
28 Jul 15 |
olle |
poolQuery.restrict(Restrictions.eq(Hql.alias("fc"), Hql.entity(flowCell.getItem()))); |
3449 |
28 Jul 15 |
olle |
144 |
|
3449 |
28 Jul 15 |
olle |
poolQuery.order(Orders.asc(Hql.property("name"))); |
3449 |
28 Jul 15 |
olle |
146 |
|
3449 |
28 Jul 15 |
olle |
List<Extract> tmp = poolQuery.list(dc); |
3449 |
28 Jul 15 |
olle |
148 |
|
3449 |
28 Jul 15 |
olle |
return toList(tmp); |
3449 |
28 Jul 15 |
olle |
150 |
} |
3449 |
28 Jul 15 |
olle |
151 |
*/ |
3449 |
28 Jul 15 |
olle |
152 |
|
3449 |
28 Jul 15 |
olle |
153 |
|
3449 |
28 Jul 15 |
olle |
154 |
public static List<PooledLibrary> toList(Collection<Extract> extracts) |
3449 |
28 Jul 15 |
olle |
155 |
{ |
3449 |
28 Jul 15 |
olle |
156 |
List<PooledLibrary> lib = new ArrayList<PooledLibrary>(extracts.size()); |
3449 |
28 Jul 15 |
olle |
157 |
for (Extract e : extracts) |
3449 |
28 Jul 15 |
olle |
158 |
{ |
3449 |
28 Jul 15 |
olle |
159 |
lib.add(new PooledLibrary(e)); |
3449 |
28 Jul 15 |
olle |
160 |
} |
3449 |
28 Jul 15 |
olle |
161 |
return lib; |
3449 |
28 Jul 15 |
olle |
162 |
} |
3449 |
28 Jul 15 |
olle |
163 |
|
3449 |
28 Jul 15 |
olle |
164 |
/** |
3449 |
28 Jul 15 |
olle |
Generate a sequence of names for the new pools. This method will search all pooled |
3449 |
28 Jul 15 |
olle |
libraries and find the one with the highest numeric suffix. |
3449 |
28 Jul 15 |
olle |
The returned names start with the found library + offset and contains the numNames |
3449 |
28 Jul 15 |
olle |
new names. |
3449 |
28 Jul 15 |
olle |
169 |
*/ |
3449 |
28 Jul 15 |
olle |
170 |
public static List<String> generateNamesForBatch(DbControl dc, int offset, int numNames) |
3449 |
28 Jul 15 |
olle |
171 |
{ |
3449 |
28 Jul 15 |
olle |
172 |
String poolNamePrefix = "Pool"; |
3449 |
28 Jul 15 |
olle |
173 |
int numDigitsInName = 4; |
3449 |
28 Jul 15 |
olle |
174 |
ItemQuery<Extract> query = Extract.getQuery(); |
3449 |
28 Jul 15 |
olle |
175 |
Subtype.POOLED_LIBRARY.addFilter(dc, query); |
3449 |
28 Jul 15 |
olle |
176 |
query.include(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
3449 |
28 Jul 15 |
olle |
177 |
query.restrict(Restrictions.rlike(Hql.property("name"), Expressions.string("^"+poolNamePrefix + "[0-9]+$"))); |
3449 |
28 Jul 15 |
olle |
178 |
query.order(Orders.desc(Hql.property("name"))); |
3449 |
28 Jul 15 |
olle |
179 |
query.setMaxResults(1); |
3449 |
28 Jul 15 |
olle |
180 |
List<Extract> pools = query.list(dc); |
3449 |
28 Jul 15 |
olle |
181 |
|
3449 |
28 Jul 15 |
olle |
182 |
int startIndex = offset; |
3449 |
28 Jul 15 |
olle |
183 |
if (pools.size() > 0) |
3449 |
28 Jul 15 |
olle |
184 |
{ |
3449 |
28 Jul 15 |
olle |
185 |
String plateName = pools.get(0).getName().substring(poolNamePrefix.length()); |
3449 |
28 Jul 15 |
olle |
186 |
startIndex = Integer.parseInt(plateName) + offset; |
3449 |
28 Jul 15 |
olle |
187 |
} |
3449 |
28 Jul 15 |
olle |
188 |
|
3449 |
28 Jul 15 |
olle |
189 |
List<String> names = new ArrayList<String>(numNames); |
3449 |
28 Jul 15 |
olle |
190 |
for (int i = 0; i < numNames; ++i) |
3449 |
28 Jul 15 |
olle |
191 |
{ |
3449 |
28 Jul 15 |
olle |
192 |
names.add(poolNamePrefix + MD5.leftPad(Integer.toString(startIndex+i), '0', numDigitsInName)); |
3449 |
28 Jul 15 |
olle |
193 |
} |
3449 |
28 Jul 15 |
olle |
194 |
return names; |
3449 |
28 Jul 15 |
olle |
195 |
} |
3449 |
28 Jul 15 |
olle |
196 |
|
3449 |
28 Jul 15 |
olle |
197 |
/** |
3449 |
28 Jul 15 |
olle |
Find pooled libraries that have not yet been processed. The query will look for |
3449 |
28 Jul 15 |
olle |
extract with the {@link Subtype#POOLED_LIBRARY} subtype that has no 'created' date. |
3449 |
28 Jul 15 |
olle |
The list is sorted by name. |
3449 |
28 Jul 15 |
olle |
201 |
*/ |
3449 |
28 Jul 15 |
olle |
202 |
public static List<PooledLibrary> findUnprocessedPools(DbControl dc) |
3449 |
28 Jul 15 |
olle |
203 |
{ |
3449 |
28 Jul 15 |
olle |
204 |
List<PooledLibrary> pools = new ArrayList<PooledLibrary>(); |
3449 |
28 Jul 15 |
olle |
205 |
|
3449 |
28 Jul 15 |
olle |
// Create a query that load all Lysate extracts without created date |
3449 |
28 Jul 15 |
olle |
207 |
ItemQuery<Extract> query = Extract.getQuery(); |
3449 |
28 Jul 15 |
olle |
208 |
query.setIncludes(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
3449 |
28 Jul 15 |
olle |
// Filter on Lysate subtype |
3449 |
28 Jul 15 |
olle |
210 |
Subtype.POOLED_LIBRARY.addFilter(dc, query); |
3449 |
28 Jul 15 |
olle |
// Filter on created date |
3449 |
28 Jul 15 |
olle |
212 |
query.restrict(Restrictions.eq(Hql.property("ce", "eventDate"), null)); |
3449 |
28 Jul 15 |
olle |
213 |
|
3449 |
28 Jul 15 |
olle |
// Join the creation event and bioplate |
3449 |
28 Jul 15 |
olle |
215 |
query.join(Hql.innerJoin("creationEvent", "ce")); |
3449 |
28 Jul 15 |
olle |
216 |
|
3449 |
28 Jul 15 |
olle |
// Sort by name |
3449 |
28 Jul 15 |
olle |
218 |
query.order(Orders.asc(Hql.property("name"))); |
3449 |
28 Jul 15 |
olle |
219 |
|
3449 |
28 Jul 15 |
olle |
220 |
return toList(query.list(dc)); |
3449 |
28 Jul 15 |
olle |
221 |
} |
3449 |
28 Jul 15 |
olle |
222 |
|
3449 |
28 Jul 15 |
olle |
223 |
/** |
3449 |
28 Jul 15 |
olle |
Find pooled libraries that have not yet been used on a flow cell. The query will |
3449 |
28 Jul 15 |
olle |
look for extracts with the {@link Subtype#POOLED_LIBRARY} subtype that has remaining |
3449 |
28 Jul 15 |
olle |
quantity equal to original quantity. The list is sorted by name. |
3449 |
28 Jul 15 |
olle |
227 |
*/ |
3449 |
28 Jul 15 |
olle |
228 |
public static List<PooledLibrary> findUnusedPools(DbControl dc) |
3449 |
28 Jul 15 |
olle |
229 |
{ |
3449 |
28 Jul 15 |
olle |
230 |
List<PooledLibrary> pools = new ArrayList<PooledLibrary>(); |
3449 |
28 Jul 15 |
olle |
231 |
|
3449 |
28 Jul 15 |
olle |
// Create a query that load all Lysate extracts without created date |
3449 |
28 Jul 15 |
olle |
233 |
ItemQuery<Extract> query = Extract.getQuery(); |
3449 |
28 Jul 15 |
olle |
234 |
query.setIncludes(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
3449 |
28 Jul 15 |
olle |
// Filter on Pooled library subtype |
3449 |
28 Jul 15 |
olle |
236 |
Subtype.POOLED_LIBRARY.addFilter(dc, query); |
3449 |
28 Jul 15 |
olle |
237 |
|
3449 |
28 Jul 15 |
olle |
// Join the creation event |
3449 |
28 Jul 15 |
olle |
239 |
query.join(Hql.innerJoin(null, "creationEvent", "ce", true)); |
3449 |
28 Jul 15 |
olle |
// Filter on created date != null |
3449 |
28 Jul 15 |
olle |
241 |
query.restrict(Restrictions.neq(Hql.property("ce", "eventDate"), null)); |
3449 |
28 Jul 15 |
olle |
242 |
|
3449 |
28 Jul 15 |
olle |
243 |
/* |
3449 |
28 Jul 15 |
olle |
// Join AUTO_PROCESSING annotation |
3449 |
28 Jul 15 |
olle |
query.join(Annotations.leftJoin(null, Annotationtype.AUTO_PROCESSING.load(dc), "ap")); |
3449 |
28 Jul 15 |
olle |
246 |
*/ |
3449 |
28 Jul 15 |
olle |
247 |
|
3449 |
28 Jul 15 |
olle |
/* Create filter: AUTO_PROCESS==ReProcess OR (AUTO_PROCESS=null AND original=remaining quantity) */ |
3449 |
28 Jul 15 |
olle |
249 |
Expression autoProcessing = Hql.alias("ap"); |
3449 |
28 Jul 15 |
olle |
250 |
query.restrict( |
3449 |
28 Jul 15 |
olle |
251 |
Restrictions.nullSafeOr( |
3449 |
28 Jul 15 |
olle |
252 |
Restrictions.eq(autoProcessing, Expressions.string("ReProcess")), |
3449 |
28 Jul 15 |
olle |
253 |
Restrictions.and( |
3449 |
28 Jul 15 |
olle |
254 |
Restrictions.eq(autoProcessing, null), |
3449 |
28 Jul 15 |
olle |
255 |
Restrictions.eq(Hql.property("originalQuantity"), Hql.property("remainingQuantity")) |
3449 |
28 Jul 15 |
olle |
256 |
) |
3449 |
28 Jul 15 |
olle |
257 |
) |
3449 |
28 Jul 15 |
olle |
258 |
); |
3449 |
28 Jul 15 |
olle |
259 |
|
3449 |
28 Jul 15 |
olle |
// Sort by name |
3449 |
28 Jul 15 |
olle |
261 |
query.order(Orders.asc(Hql.property("name"))); |
3449 |
28 Jul 15 |
olle |
262 |
|
3449 |
28 Jul 15 |
olle |
263 |
return toList(query.list(dc)); |
3449 |
28 Jul 15 |
olle |
264 |
} |
3449 |
28 Jul 15 |
olle |
265 |
|
3449 |
28 Jul 15 |
olle |
266 |
private JSONObject jsonWell; |
3449 |
28 Jul 15 |
olle |
267 |
private JSONArray jsonLibPlates; |
3449 |
28 Jul 15 |
olle |
268 |
|
3449 |
28 Jul 15 |
olle |
269 |
private PooledLibrary(Extract extract) |
3449 |
28 Jul 15 |
olle |
270 |
{ |
3449 |
28 Jul 15 |
olle |
271 |
super(extract); |
3449 |
28 Jul 15 |
olle |
272 |
|
3449 |
28 Jul 15 |
olle |
273 |
} |
3449 |
28 Jul 15 |
olle |
274 |
|
3449 |
28 Jul 15 |
olle |
275 |
/** |
3449 |
28 Jul 15 |
olle |
Get the real extract that represents this Pooled library in BASE. |
3449 |
28 Jul 15 |
olle |
277 |
*/ |
3449 |
28 Jul 15 |
olle |
278 |
public Extract getExtract() |
3449 |
28 Jul 15 |
olle |
279 |
{ |
3449 |
28 Jul 15 |
olle |
280 |
return getItem(); |
3449 |
28 Jul 15 |
olle |
281 |
} |
3449 |
28 Jul 15 |
olle |
282 |
|
3449 |
28 Jul 15 |
olle |
283 |
@SuppressWarnings("unchecked") |
3449 |
28 Jul 15 |
olle |
284 |
@Override |
3449 |
28 Jul 15 |
olle |
285 |
protected void initJSON(JSONObject json) |
3449 |
28 Jul 15 |
olle |
286 |
{ |
3449 |
28 Jul 15 |
olle |
287 |
super.initJSON(json); |
3449 |
28 Jul 15 |
olle |
288 |
if (jsonWell != null) json.put("bioWell", jsonWell); |
3449 |
28 Jul 15 |
olle |
289 |
if (jsonLibPlates != null) json.put("libPlates", jsonLibPlates); |
3449 |
28 Jul 15 |
olle |
290 |
} |
3449 |
28 Jul 15 |
olle |
291 |
|
3449 |
28 Jul 15 |
olle |
292 |
/** |
3449 |
28 Jul 15 |
olle |
Load information about the plate and location the current Library |
3449 |
28 Jul 15 |
olle |
is located on. |
3449 |
28 Jul 15 |
olle |
295 |
*/ |
3449 |
28 Jul 15 |
olle |
296 |
@SuppressWarnings("unchecked") |
3449 |
28 Jul 15 |
olle |
297 |
public JSONObject loadBioPlateLocation() |
3449 |
28 Jul 15 |
olle |
298 |
{ |
3449 |
28 Jul 15 |
olle |
299 |
if (jsonWell != null) return jsonWell; |
3449 |
28 Jul 15 |
olle |
300 |
|
3449 |
28 Jul 15 |
olle |
301 |
Extract pool = getItem(); |
3449 |
28 Jul 15 |
olle |
302 |
BioWell well = pool.getBioWell(); |
3449 |
28 Jul 15 |
olle |
303 |
|
3449 |
28 Jul 15 |
olle |
304 |
if (well != null) |
3449 |
28 Jul 15 |
olle |
305 |
{ |
3449 |
28 Jul 15 |
olle |
306 |
jsonWell = new JSONObject(); |
3449 |
28 Jul 15 |
olle |
307 |
jsonWell.put("id", well.getId()); |
3449 |
28 Jul 15 |
olle |
308 |
jsonWell.put("row", well.getRow()); |
3449 |
28 Jul 15 |
olle |
309 |
jsonWell.put("column", well.getColumn()); |
3449 |
28 Jul 15 |
olle |
310 |
|
3449 |
28 Jul 15 |
olle |
311 |
BioPlate plate = well.getPlate(); |
3449 |
28 Jul 15 |
olle |
312 |
JSONObject jsonPlate = new JSONObject(); |
3449 |
28 Jul 15 |
olle |
313 |
jsonPlate.put("id", plate.getId()); |
3449 |
28 Jul 15 |
olle |
314 |
jsonPlate.put("name", plate.getName()); |
3449 |
28 Jul 15 |
olle |
315 |
|
3449 |
28 Jul 15 |
olle |
316 |
jsonWell.put("bioPlate", jsonPlate); |
3449 |
28 Jul 15 |
olle |
317 |
} |
3449 |
28 Jul 15 |
olle |
318 |
|
3449 |
28 Jul 15 |
olle |
319 |
return jsonWell; |
3449 |
28 Jul 15 |
olle |
320 |
} |
3449 |
28 Jul 15 |
olle |
321 |
|
3449 |
28 Jul 15 |
olle |
322 |
/** |
3449 |
28 Jul 15 |
olle |
Load the library bioplates that the parent libraries that |
3449 |
28 Jul 15 |
olle |
are part of this pool are coming from. The result is returned |
3449 |
28 Jul 15 |
olle |
as a JSON array and is also included in the "libPlates" property |
3449 |
28 Jul 15 |
olle |
when calling {@link #asJSONObject()} later. |
3449 |
28 Jul 15 |
olle |
327 |
*/ |
3449 |
28 Jul 15 |
olle |
328 |
@SuppressWarnings("unchecked") |
3449 |
28 Jul 15 |
olle |
329 |
public JSONArray loadLibPlates(DbControl dc) |
3449 |
28 Jul 15 |
olle |
330 |
{ |
3449 |
28 Jul 15 |
olle |
331 |
if (jsonLibPlates != null) return jsonLibPlates; |
3449 |
28 Jul 15 |
olle |
332 |
|
3449 |
28 Jul 15 |
olle |
333 |
Extract pool = getItem(); |
3449 |
28 Jul 15 |
olle |
334 |
|
3449 |
28 Jul 15 |
olle |
335 |
ItemQuery<BioPlate> libPlateQuery = BioPlate.getQuery(); |
3449 |
28 Jul 15 |
olle |
336 |
libPlateQuery.setDistinct(true); |
3449 |
28 Jul 15 |
olle |
337 |
libPlateQuery.include(Meludi.INCLUDE_IN_CURRENT_PROJECT); |
3449 |
28 Jul 15 |
olle |
338 |
|
3449 |
28 Jul 15 |
olle |
339 |
/* |
3449 |
28 Jul 15 |
olle |
// Library/NeoPrep bioplates |
3449 |
28 Jul 15 |
olle |
libPlateQuery.restrict( |
3449 |
28 Jul 15 |
olle |
Restrictions.or( |
3449 |
28 Jul 15 |
olle |
BioplateType.LIBRARY.restriction(dc, null), |
3449 |
28 Jul 15 |
olle |
BioplateType.NEOPREP.restriction(dc, null) |
3449 |
28 Jul 15 |
olle |
345 |
)); |
3449 |
28 Jul 15 |
olle |
346 |
*/ |
3449 |
28 Jul 15 |
olle |
347 |
|
3449 |
28 Jul 15 |
olle |
//BioplateType.LIBRARY.addFilter(dc, libPlateQuery, false); |
3449 |
28 Jul 15 |
olle |
349 |
libPlateQuery.join(Hql.innerJoin("bioWells", "bw")); |
3449 |
28 Jul 15 |
olle |
350 |
libPlateQuery.join(Hql.innerJoin("bw", "bioMaterial", "lib")); |
3449 |
28 Jul 15 |
olle |
351 |
|
3449 |
28 Jul 15 |
olle |
352 |
libPlateQuery.join(Hql.innerJoin("lib", "childCreationEvents", "cce")); |
3449 |
28 Jul 15 |
olle |
353 |
libPlateQuery.join(Hql.innerJoin("cce", "event", "evt")); |
3449 |
28 Jul 15 |
olle |
354 |
libPlateQuery.join(Hql.innerJoin("evt", "bioMaterial", "pool")); |
3449 |
28 Jul 15 |
olle |
355 |
|
3449 |
28 Jul 15 |
olle |
356 |
libPlateQuery.restrict(Restrictions.eq(Hql.alias("pool"), Hql.entity(pool))); |
3449 |
28 Jul 15 |
olle |
357 |
|
3449 |
28 Jul 15 |
olle |
358 |
libPlateQuery.order(Orders.asc(Hql.property("name"))); |
3449 |
28 Jul 15 |
olle |
359 |
List<BioPlate> result = libPlateQuery.list(dc); |
3449 |
28 Jul 15 |
olle |
360 |
|
3449 |
28 Jul 15 |
olle |
361 |
jsonLibPlates = new JSONArray(); |
3449 |
28 Jul 15 |
olle |
362 |
for (BioPlate libPlate : result) |
3449 |
28 Jul 15 |
olle |
363 |
{ |
3449 |
28 Jul 15 |
olle |
364 |
JSONObject jsonLibPlate = new JSONObject(); |
3449 |
28 Jul 15 |
olle |
365 |
jsonLibPlate.put("id", libPlate.getId()); |
3449 |
28 Jul 15 |
olle |
366 |
jsonLibPlate.put("name", libPlate.getName()); |
3449 |
28 Jul 15 |
olle |
367 |
jsonLibPlates.add(jsonLibPlate); |
3449 |
28 Jul 15 |
olle |
368 |
} |
3449 |
28 Jul 15 |
olle |
369 |
return jsonLibPlates; |
3449 |
28 Jul 15 |
olle |
370 |
} |
3449 |
28 Jul 15 |
olle |
371 |
|
3449 |
28 Jul 15 |
olle |
372 |
} |