1934 |
17 Apr 13 |
nicklas |
1 |
package net.sf.basedb.reggie.dao; |
1934 |
17 Apr 13 |
nicklas |
2 |
|
1934 |
17 Apr 13 |
nicklas |
3 |
import java.util.ArrayList; |
1934 |
17 Apr 13 |
nicklas |
4 |
import java.util.Collection; |
1934 |
17 Apr 13 |
nicklas |
5 |
import java.util.List; |
1934 |
17 Apr 13 |
nicklas |
6 |
|
2090 |
21 Oct 13 |
nicklas |
7 |
import org.json.simple.JSONArray; |
1934 |
17 Apr 13 |
nicklas |
8 |
import org.json.simple.JSONObject; |
1934 |
17 Apr 13 |
nicklas |
9 |
|
1934 |
17 Apr 13 |
nicklas |
10 |
import net.sf.basedb.core.BioPlate; |
5452 |
28 May 19 |
nicklas |
11 |
import net.sf.basedb.core.BioPlateType; |
1934 |
17 Apr 13 |
nicklas |
12 |
import net.sf.basedb.core.BioWell; |
1934 |
17 Apr 13 |
nicklas |
13 |
import net.sf.basedb.core.DbControl; |
1934 |
17 Apr 13 |
nicklas |
14 |
import net.sf.basedb.core.Extract; |
4883 |
04 Jul 18 |
nicklas |
15 |
import net.sf.basedb.core.Include; |
1934 |
17 Apr 13 |
nicklas |
16 |
import net.sf.basedb.core.ItemQuery; |
2052 |
09 Oct 13 |
olle |
17 |
import net.sf.basedb.core.Type; |
2077 |
17 Oct 13 |
nicklas |
18 |
import net.sf.basedb.core.query.Annotations; |
2077 |
17 Oct 13 |
nicklas |
19 |
import net.sf.basedb.core.query.Expression; |
1934 |
17 Apr 13 |
nicklas |
20 |
import net.sf.basedb.core.query.Expressions; |
1934 |
17 Apr 13 |
nicklas |
21 |
import net.sf.basedb.core.query.Hql; |
1934 |
17 Apr 13 |
nicklas |
22 |
import net.sf.basedb.core.query.Orders; |
1934 |
17 Apr 13 |
nicklas |
23 |
import net.sf.basedb.core.query.Restrictions; |
1934 |
17 Apr 13 |
nicklas |
24 |
import net.sf.basedb.reggie.Reggie; |
1934 |
17 Apr 13 |
nicklas |
25 |
|
1934 |
17 Apr 13 |
nicklas |
26 |
/** |
1934 |
17 Apr 13 |
nicklas |
Class for loading information that is related to Pooled library extracts. |
1934 |
17 Apr 13 |
nicklas |
28 |
|
1934 |
17 Apr 13 |
nicklas |
@author nicklas |
1934 |
17 Apr 13 |
nicklas |
@since 2.12 |
1934 |
17 Apr 13 |
nicklas |
31 |
*/ |
1934 |
17 Apr 13 |
nicklas |
32 |
public class PooledLibrary |
1934 |
17 Apr 13 |
nicklas |
33 |
extends ReggieItem<Extract> |
2041 |
04 Oct 13 |
nicklas |
34 |
{ |
2041 |
04 Oct 13 |
nicklas |
35 |
|
2041 |
04 Oct 13 |
nicklas |
36 |
/** |
2041 |
04 Oct 13 |
nicklas |
Value for the {@link Annotationtype#POOL_MIXING_STRATEGY} annotation |
2041 |
04 Oct 13 |
nicklas |
when the pool should be mixed using the FIXED strategy. This strategy |
2041 |
04 Oct 13 |
nicklas |
mixes all libraries to the same volume at the expense of a non-optimal |
2041 |
04 Oct 13 |
nicklas |
final pool molarity. |
2041 |
04 Oct 13 |
nicklas |
@since 2.13 |
2041 |
04 Oct 13 |
nicklas |
42 |
*/ |
2041 |
04 Oct 13 |
nicklas |
43 |
public static final String MIXING_STRATEGY_FIXED = "fixed"; |
1934 |
17 Apr 13 |
nicklas |
44 |
|
2052 |
09 Oct 13 |
olle |
45 |
|
1934 |
17 Apr 13 |
nicklas |
46 |
/** |
2041 |
04 Oct 13 |
nicklas |
Value for the {@link Annotationtype#POOL_MIXING_STRATEGY} annotation |
2041 |
04 Oct 13 |
nicklas |
when the pool should be mixed using the DYNAMIC strategy. This strategy |
2041 |
04 Oct 13 |
nicklas |
optimizes the final pool molarity but mixes all libraries to different |
2041 |
04 Oct 13 |
nicklas |
volumes. |
2041 |
04 Oct 13 |
nicklas |
@since 2.13 |
2041 |
04 Oct 13 |
nicklas |
52 |
*/ |
2041 |
04 Oct 13 |
nicklas |
53 |
public static final String MIXING_STRATEGY_DYNAMIC = "dynamic"; |
2041 |
04 Oct 13 |
nicklas |
54 |
|
2077 |
17 Oct 13 |
nicklas |
55 |
/** |
2077 |
17 Oct 13 |
nicklas |
Flag value for the {@link Annotationtype#FLAG} annotation when clustering |
2077 |
17 Oct 13 |
nicklas |
a pooled library failed. This flag is normally attached to 'PooledLibrary' |
2077 |
17 Oct 13 |
nicklas |
items, but may be found on RNA items if the pool runs out of biomaterial. |
2077 |
17 Oct 13 |
nicklas |
@since 2.13 |
2077 |
17 Oct 13 |
nicklas |
60 |
*/ |
2077 |
17 Oct 13 |
nicklas |
61 |
public static final String FLAG_CLUSTERING_FAILED = "ClusteringFailed"; |
2077 |
17 Oct 13 |
nicklas |
62 |
|
2224 |
12 Feb 14 |
nicklas |
63 |
/** |
2224 |
12 Feb 14 |
nicklas |
Flag value for the {@link Annotationtype#FLAG} annotation when sequencing |
2224 |
12 Feb 14 |
nicklas |
a pooled library failed. This flag is normally attached to 'PooledLibrary' |
2224 |
12 Feb 14 |
nicklas |
items, but may be found on RNA items if the pool runs out of biomaterial. |
2224 |
12 Feb 14 |
nicklas |
@since 2.15 |
2224 |
12 Feb 14 |
nicklas |
68 |
*/ |
2224 |
12 Feb 14 |
nicklas |
69 |
public static final String FLAG_SEQUENCING_FAILED = "SequencingFailed"; |
2052 |
09 Oct 13 |
olle |
70 |
|
2041 |
04 Oct 13 |
nicklas |
71 |
/** |
2367 |
17 Apr 14 |
nicklas |
Flag value for the {@link Annotationtype#FLAG} annotation when |
2367 |
17 Apr 14 |
nicklas |
a pool has been sequenced but the demux step failed. |
2367 |
17 Apr 14 |
nicklas |
@since 2.16 |
2367 |
17 Apr 14 |
nicklas |
75 |
*/ |
2367 |
17 Apr 14 |
nicklas |
76 |
public static final String FLAG_DEMUX_FAILED = Rna.FLAG_DEMUX_FAILED; |
2367 |
17 Apr 14 |
nicklas |
77 |
|
2367 |
17 Apr 14 |
nicklas |
78 |
|
2367 |
17 Apr 14 |
nicklas |
79 |
/** |
5012 |
05 Oct 18 |
nicklas |
Find all pooled library items by case name. This method will check for {@link Subtype#POOLED_LIBRARY} |
5012 |
05 Oct 18 |
nicklas |
where at least one of the source items is a {@link Subtype#LIBRARY} with a name matching the case |
5012 |
05 Oct 18 |
nicklas |
name (eg. xxx.r.m.c.lib) |
2052 |
09 Oct 13 |
olle |
@since 2.13 |
2052 |
09 Oct 13 |
olle |
84 |
*/ |
2052 |
09 Oct 13 |
olle |
85 |
public static List<PooledLibrary> findByCaseName(DbControl dc, String name) |
2052 |
09 Oct 13 |
olle |
86 |
{ |
2052 |
09 Oct 13 |
olle |
// Get rid of suffixes in the name (eg. 'C' which is used for pre-neoadjuvant forms) |
2052 |
09 Oct 13 |
olle |
88 |
if (name.length() > 7) name = name.substring(0, 7); |
2052 |
09 Oct 13 |
olle |
89 |
|
5012 |
05 Oct 18 |
nicklas |
90 |
ItemQuery<Extract> poolQuery = Extract.getQuery(); |
5012 |
05 Oct 18 |
nicklas |
91 |
Subtype.POOLED_LIBRARY.addFilter(dc, poolQuery); |
5012 |
05 Oct 18 |
nicklas |
92 |
poolQuery.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
5012 |
05 Oct 18 |
nicklas |
93 |
poolQuery.join(Hql.innerJoin("creationEvent", "ce")); |
5012 |
05 Oct 18 |
nicklas |
94 |
poolQuery.join(Hql.innerJoin("ce", "sources", "src")); |
5012 |
05 Oct 18 |
nicklas |
95 |
poolQuery.join(Hql.innerJoin("src", "bioMaterial", "lib")); |
5012 |
05 Oct 18 |
nicklas |
96 |
poolQuery.restrict(Restrictions.like(Hql.property("lib", "name"), Expressions.parameter("name", name+".%", Type.STRING))); |
5012 |
05 Oct 18 |
nicklas |
97 |
poolQuery.order(Orders.asc(Hql.property("name"))); |
5012 |
05 Oct 18 |
nicklas |
98 |
poolQuery.setDistinct(true); |
5012 |
05 Oct 18 |
nicklas |
99 |
List<Extract> tmp = poolQuery.list(dc); |
5012 |
05 Oct 18 |
nicklas |
100 |
return toList(tmp); |
2052 |
09 Oct 13 |
olle |
101 |
} |
2052 |
09 Oct 13 |
olle |
102 |
|
2052 |
09 Oct 13 |
olle |
103 |
|
2052 |
09 Oct 13 |
olle |
104 |
/** |
1934 |
17 Apr 13 |
nicklas |
Get a Library extract when the id is known. |
1934 |
17 Apr 13 |
nicklas |
106 |
*/ |
1934 |
17 Apr 13 |
nicklas |
107 |
public static PooledLibrary getById(DbControl dc, int id) |
1934 |
17 Apr 13 |
nicklas |
108 |
{ |
1934 |
17 Apr 13 |
nicklas |
109 |
return new PooledLibrary(Extract.getById(dc, id)); |
1934 |
17 Apr 13 |
nicklas |
110 |
} |
1934 |
17 Apr 13 |
nicklas |
111 |
|
2094 |
21 Oct 13 |
nicklas |
112 |
/** |
6193 |
30 Mar 21 |
nicklas |
@since 4.32 |
6193 |
30 Mar 21 |
nicklas |
114 |
*/ |
6193 |
30 Mar 21 |
nicklas |
115 |
public static PooledLibrary get(Extract extract) |
6193 |
30 Mar 21 |
nicklas |
116 |
{ |
6193 |
30 Mar 21 |
nicklas |
117 |
return new PooledLibrary(extract); |
6193 |
30 Mar 21 |
nicklas |
118 |
} |
6193 |
30 Mar 21 |
nicklas |
119 |
|
6193 |
30 Mar 21 |
nicklas |
120 |
|
6193 |
30 Mar 21 |
nicklas |
121 |
/** |
2094 |
21 Oct 13 |
nicklas |
Load pools used on the flow cell. |
2094 |
21 Oct 13 |
nicklas |
123 |
*/ |
2094 |
21 Oct 13 |
nicklas |
124 |
public static List<PooledLibrary> getByFlowCell(DbControl dc, FlowCell flowCell) |
2094 |
21 Oct 13 |
nicklas |
125 |
{ |
2094 |
21 Oct 13 |
nicklas |
126 |
ItemQuery<Extract> poolQuery = Extract.getQuery(); |
2094 |
21 Oct 13 |
nicklas |
127 |
Subtype.POOLED_LIBRARY.addFilter(dc, poolQuery); |
2094 |
21 Oct 13 |
nicklas |
128 |
poolQuery.include(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2094 |
21 Oct 13 |
nicklas |
129 |
poolQuery.setDistinct(true); |
2094 |
21 Oct 13 |
nicklas |
130 |
|
2094 |
21 Oct 13 |
nicklas |
// Join intermediate aliquot |
2094 |
21 Oct 13 |
nicklas |
132 |
poolQuery.join(Hql.innerJoin("childCreationEvents", "cce1")); |
2094 |
21 Oct 13 |
nicklas |
133 |
poolQuery.join(Hql.innerJoin("cce1", "event", "evt1")); |
2094 |
21 Oct 13 |
nicklas |
134 |
poolQuery.join(Hql.innerJoin("evt1", "bioMaterial", "pa")); |
2094 |
21 Oct 13 |
nicklas |
135 |
|
2094 |
21 Oct 13 |
nicklas |
// Join flow cell |
2094 |
21 Oct 13 |
nicklas |
137 |
poolQuery.join(Hql.innerJoin("pa", "childCreationEvents", "cce2")); |
2094 |
21 Oct 13 |
nicklas |
138 |
poolQuery.join(Hql.innerJoin("cce2", "event", "evt2")); |
2094 |
21 Oct 13 |
nicklas |
139 |
poolQuery.join(Hql.innerJoin("evt2", "physicalBioAssay", "fc")); |
2094 |
21 Oct 13 |
nicklas |
140 |
poolQuery.restrict(Restrictions.eq(Hql.alias("fc"), Hql.entity(flowCell.getItem()))); |
2094 |
21 Oct 13 |
nicklas |
141 |
|
2094 |
21 Oct 13 |
nicklas |
142 |
poolQuery.order(Orders.asc(Hql.property("name"))); |
2094 |
21 Oct 13 |
nicklas |
143 |
|
2094 |
21 Oct 13 |
nicklas |
144 |
List<Extract> tmp = poolQuery.list(dc); |
2094 |
21 Oct 13 |
nicklas |
145 |
|
2094 |
21 Oct 13 |
nicklas |
146 |
return toList(tmp); |
2094 |
21 Oct 13 |
nicklas |
147 |
} |
2094 |
21 Oct 13 |
nicklas |
148 |
|
1934 |
17 Apr 13 |
nicklas |
149 |
|
1934 |
17 Apr 13 |
nicklas |
150 |
public static List<PooledLibrary> toList(Collection<Extract> extracts) |
1934 |
17 Apr 13 |
nicklas |
151 |
{ |
1934 |
17 Apr 13 |
nicklas |
152 |
List<PooledLibrary> lib = new ArrayList<PooledLibrary>(extracts.size()); |
1934 |
17 Apr 13 |
nicklas |
153 |
for (Extract e : extracts) |
1934 |
17 Apr 13 |
nicklas |
154 |
{ |
1934 |
17 Apr 13 |
nicklas |
155 |
lib.add(new PooledLibrary(e)); |
1934 |
17 Apr 13 |
nicklas |
156 |
} |
1934 |
17 Apr 13 |
nicklas |
157 |
return lib; |
1934 |
17 Apr 13 |
nicklas |
158 |
} |
1934 |
17 Apr 13 |
nicklas |
159 |
|
1934 |
17 Apr 13 |
nicklas |
160 |
/** |
1934 |
17 Apr 13 |
nicklas |
Generate a sequence of names for the new pools. This method will search all pooled |
4883 |
04 Jul 18 |
nicklas |
libraries and find the one with the highest numeric suffix which |
4883 |
04 Jul 18 |
nicklas |
is incremented to create the following names. |
1934 |
17 Apr 13 |
nicklas |
164 |
*/ |
4883 |
04 Jul 18 |
nicklas |
165 |
public static List<String> getNextNames(DbControl dc, int numNames) |
1934 |
17 Apr 13 |
nicklas |
166 |
{ |
4895 |
09 Jul 18 |
nicklas |
167 |
String prefix = Subtype.POOLED_LIBRARY.getItemPrefix(); |
1934 |
17 Apr 13 |
nicklas |
168 |
int numDigitsInName = 4; |
1934 |
17 Apr 13 |
nicklas |
169 |
ItemQuery<Extract> query = Extract.getQuery(); |
1934 |
17 Apr 13 |
nicklas |
170 |
Subtype.POOLED_LIBRARY.addFilter(dc, query); |
4883 |
04 Jul 18 |
nicklas |
171 |
query.include(Include.ALL); |
4883 |
04 Jul 18 |
nicklas |
172 |
return ReggieItem.getNextItemNames(dc, numNames, query, prefix, numDigitsInName, false); |
1934 |
17 Apr 13 |
nicklas |
173 |
} |
1934 |
17 Apr 13 |
nicklas |
174 |
|
1959 |
03 May 13 |
nicklas |
175 |
/** |
1959 |
03 May 13 |
nicklas |
Find pooled libraries that have not yet been processed. The query will look for |
5434 |
17 May 19 |
nicklas |
extract with the {@link Subtype#POOLED_LIBRARY} subtype for the given pipeline |
5434 |
17 May 19 |
nicklas |
that has no 'created' date. The list is sorted by name. |
1959 |
03 May 13 |
nicklas |
179 |
*/ |
5434 |
17 May 19 |
nicklas |
180 |
public static List<PooledLibrary> findUnprocessedPools(DbControl dc, Pipeline pipeline) |
1959 |
03 May 13 |
nicklas |
181 |
{ |
1959 |
03 May 13 |
nicklas |
182 |
List<PooledLibrary> pools = new ArrayList<PooledLibrary>(); |
1959 |
03 May 13 |
nicklas |
183 |
|
5434 |
17 May 19 |
nicklas |
// Create a query that load all PooledLibrary extracts without created date |
1959 |
03 May 13 |
nicklas |
185 |
ItemQuery<Extract> query = Extract.getQuery(); |
1959 |
03 May 13 |
nicklas |
186 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
5434 |
17 May 19 |
nicklas |
// Filter on PooledLibrary subtype |
1959 |
03 May 13 |
nicklas |
188 |
Subtype.POOLED_LIBRARY.addFilter(dc, query); |
5434 |
17 May 19 |
nicklas |
// Filter on pipeline |
5434 |
17 May 19 |
nicklas |
190 |
if (pipeline != null) pipeline.addFilter(dc, query); |
1959 |
03 May 13 |
nicklas |
// Filter on created date |
1959 |
03 May 13 |
nicklas |
192 |
query.restrict(Restrictions.eq(Hql.property("ce", "eventDate"), null)); |
1959 |
03 May 13 |
nicklas |
193 |
|
1959 |
03 May 13 |
nicklas |
// Join the creation event and bioplate |
1959 |
03 May 13 |
nicklas |
195 |
query.join(Hql.innerJoin("creationEvent", "ce")); |
1959 |
03 May 13 |
nicklas |
196 |
|
1959 |
03 May 13 |
nicklas |
// Sort by name |
1959 |
03 May 13 |
nicklas |
198 |
query.order(Orders.asc(Hql.property("name"))); |
1959 |
03 May 13 |
nicklas |
199 |
|
1959 |
03 May 13 |
nicklas |
200 |
return toList(query.list(dc)); |
1959 |
03 May 13 |
nicklas |
201 |
} |
1959 |
03 May 13 |
nicklas |
202 |
|
2020 |
13 Sep 13 |
nicklas |
203 |
/** |
2020 |
13 Sep 13 |
nicklas |
Find pooled libraries that have not yet been used on a flow cell. The query will |
5434 |
17 May 19 |
nicklas |
look for extracts with the {@link Subtype#POOLED_LIBRARY} subtype for the given |
5434 |
17 May 19 |
nicklas |
pipeline that has remaining quantity equal to original quantity. The list is sorted by name. |
2020 |
13 Sep 13 |
nicklas |
207 |
*/ |
5434 |
17 May 19 |
nicklas |
208 |
public static List<PooledLibrary> findUnusedPools(DbControl dc, Pipeline pipeline) |
2020 |
13 Sep 13 |
nicklas |
209 |
{ |
2020 |
13 Sep 13 |
nicklas |
210 |
List<PooledLibrary> pools = new ArrayList<PooledLibrary>(); |
2020 |
13 Sep 13 |
nicklas |
211 |
|
2020 |
13 Sep 13 |
nicklas |
// Create a query that load all Lysate extracts without created date |
2020 |
13 Sep 13 |
nicklas |
213 |
ItemQuery<Extract> query = Extract.getQuery(); |
2020 |
13 Sep 13 |
nicklas |
214 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2077 |
17 Oct 13 |
nicklas |
// Filter on Pooled library subtype |
2020 |
13 Sep 13 |
nicklas |
216 |
Subtype.POOLED_LIBRARY.addFilter(dc, query); |
5434 |
17 May 19 |
nicklas |
// Filter on pipeline |
5434 |
17 May 19 |
nicklas |
218 |
if (pipeline != null) pipeline.addFilter(dc, query); |
2077 |
17 Oct 13 |
nicklas |
219 |
|
2020 |
13 Sep 13 |
nicklas |
// Join the creation event |
2020 |
13 Sep 13 |
nicklas |
221 |
query.join(Hql.innerJoin(null, "creationEvent", "ce", true)); |
2077 |
17 Oct 13 |
nicklas |
// Filter on created date != null |
2077 |
17 Oct 13 |
nicklas |
223 |
query.restrict(Restrictions.neq(Hql.property("ce", "eventDate"), null)); |
2077 |
17 Oct 13 |
nicklas |
224 |
|
2077 |
17 Oct 13 |
nicklas |
// Join AUTO_PROCESSING annotation |
2077 |
17 Oct 13 |
nicklas |
226 |
query.join(Annotations.leftJoin(null, Annotationtype.AUTO_PROCESSING.load(dc), "ap")); |
2077 |
17 Oct 13 |
nicklas |
227 |
|
5452 |
28 May 19 |
nicklas |
/* Create filter: AUTO_PROCESS==ReProcess OR (AUTO_PROCESS=null AND size(childCreationEvents)==0) */ |
2077 |
17 Oct 13 |
nicklas |
229 |
Expression autoProcessing = Hql.alias("ap"); |
2077 |
17 Oct 13 |
nicklas |
230 |
query.restrict( |
2077 |
17 Oct 13 |
nicklas |
231 |
Restrictions.nullSafeOr( |
2077 |
17 Oct 13 |
nicklas |
232 |
Restrictions.eq(autoProcessing, Expressions.string("ReProcess")), |
2077 |
17 Oct 13 |
nicklas |
233 |
Restrictions.and( |
2077 |
17 Oct 13 |
nicklas |
234 |
Restrictions.eq(autoProcessing, null), |
5452 |
28 May 19 |
nicklas |
235 |
Restrictions.eq(Hql.size(null, "childCreationEvents"), Expressions.integer(0)) |
2077 |
17 Oct 13 |
nicklas |
236 |
) |
2077 |
17 Oct 13 |
nicklas |
237 |
) |
2077 |
17 Oct 13 |
nicklas |
238 |
); |
2077 |
17 Oct 13 |
nicklas |
239 |
|
2020 |
13 Sep 13 |
nicklas |
// Sort by name |
2020 |
13 Sep 13 |
nicklas |
241 |
query.order(Orders.asc(Hql.property("name"))); |
2020 |
13 Sep 13 |
nicklas |
242 |
return toList(query.list(dc)); |
2020 |
13 Sep 13 |
nicklas |
243 |
} |
2020 |
13 Sep 13 |
nicklas |
244 |
|
1934 |
17 Apr 13 |
nicklas |
245 |
private JSONObject jsonWell; |
2090 |
21 Oct 13 |
nicklas |
246 |
private JSONArray jsonLibPlates; |
1934 |
17 Apr 13 |
nicklas |
247 |
|
1934 |
17 Apr 13 |
nicklas |
248 |
private PooledLibrary(Extract extract) |
1934 |
17 Apr 13 |
nicklas |
249 |
{ |
1934 |
17 Apr 13 |
nicklas |
250 |
super(extract); |
1934 |
17 Apr 13 |
nicklas |
251 |
|
1934 |
17 Apr 13 |
nicklas |
252 |
} |
1934 |
17 Apr 13 |
nicklas |
253 |
|
1934 |
17 Apr 13 |
nicklas |
254 |
/** |
1934 |
17 Apr 13 |
nicklas |
Get the real extract that represents this Pooled library in BASE. |
1934 |
17 Apr 13 |
nicklas |
256 |
*/ |
1934 |
17 Apr 13 |
nicklas |
257 |
public Extract getExtract() |
1934 |
17 Apr 13 |
nicklas |
258 |
{ |
1934 |
17 Apr 13 |
nicklas |
259 |
return getItem(); |
1934 |
17 Apr 13 |
nicklas |
260 |
} |
1934 |
17 Apr 13 |
nicklas |
261 |
|
4890 |
06 Jul 18 |
nicklas |
262 |
/** |
4890 |
06 Jul 18 |
nicklas |
Find the next name to give a "PooledLibraryAliquot" child item. This assumes that |
4890 |
06 Jul 18 |
nicklas |
all child items are using the naming convention. foo.a1, foo.a2, and |
4890 |
06 Jul 18 |
nicklas |
so on. NOTE! The first child item also have a number in this case! |
4890 |
06 Jul 18 |
nicklas |
@return The next unused name |
4890 |
06 Jul 18 |
nicklas |
@since 4.19 |
4890 |
06 Jul 18 |
nicklas |
268 |
*/ |
4890 |
06 Jul 18 |
nicklas |
269 |
public String getNextAliquotName(DbControl dc) |
4890 |
06 Jul 18 |
nicklas |
270 |
{ |
4890 |
06 Jul 18 |
nicklas |
271 |
Extract pool = getItem(); |
6193 |
30 Mar 21 |
nicklas |
272 |
ItemQuery<Extract> query = null; |
6193 |
30 Mar 21 |
nicklas |
273 |
if (pool.isInDatabase()) |
6193 |
30 Mar 21 |
nicklas |
274 |
{ |
6193 |
30 Mar 21 |
nicklas |
275 |
query = pool.getChildExtracts(); |
6193 |
30 Mar 21 |
nicklas |
276 |
Subtype.POOLED_LIBRARY_ALIQUOT.addFilter(dc, query); |
6193 |
30 Mar 21 |
nicklas |
277 |
query.setIncludes(Include.ALL); |
6193 |
30 Mar 21 |
nicklas |
278 |
} |
4890 |
06 Jul 18 |
nicklas |
279 |
String name = getNextChildItemName(dc, query, Subtype.POOLED_LIBRARY_ALIQUOT.getItemSuffix(), true); |
4890 |
06 Jul 18 |
nicklas |
280 |
if (name.endsWith(Subtype.POOLED_LIBRARY_ALIQUOT.getItemSuffix())) name += "1"; |
4890 |
06 Jul 18 |
nicklas |
281 |
return name; |
4890 |
06 Jul 18 |
nicklas |
282 |
} |
4890 |
06 Jul 18 |
nicklas |
283 |
|
4890 |
06 Jul 18 |
nicklas |
284 |
|
1934 |
17 Apr 13 |
nicklas |
285 |
@Override |
1934 |
17 Apr 13 |
nicklas |
286 |
protected void initJSON(JSONObject json) |
1934 |
17 Apr 13 |
nicklas |
287 |
{ |
1934 |
17 Apr 13 |
nicklas |
288 |
super.initJSON(json); |
1934 |
17 Apr 13 |
nicklas |
289 |
if (jsonWell != null) json.put("bioWell", jsonWell); |
2090 |
21 Oct 13 |
nicklas |
290 |
if (jsonLibPlates != null) json.put("libPlates", jsonLibPlates); |
1934 |
17 Apr 13 |
nicklas |
291 |
} |
1934 |
17 Apr 13 |
nicklas |
292 |
|
1934 |
17 Apr 13 |
nicklas |
293 |
/** |
1934 |
17 Apr 13 |
nicklas |
Load information about the plate and location the current Library |
1934 |
17 Apr 13 |
nicklas |
is located on. |
1934 |
17 Apr 13 |
nicklas |
296 |
*/ |
1934 |
17 Apr 13 |
nicklas |
297 |
public JSONObject loadBioPlateLocation() |
1934 |
17 Apr 13 |
nicklas |
298 |
{ |
1934 |
17 Apr 13 |
nicklas |
299 |
if (jsonWell != null) return jsonWell; |
1934 |
17 Apr 13 |
nicklas |
300 |
|
1959 |
03 May 13 |
nicklas |
301 |
Extract pool = getItem(); |
1959 |
03 May 13 |
nicklas |
302 |
BioWell well = pool.getBioWell(); |
1934 |
17 Apr 13 |
nicklas |
303 |
|
1934 |
17 Apr 13 |
nicklas |
304 |
if (well != null) |
1934 |
17 Apr 13 |
nicklas |
305 |
{ |
1934 |
17 Apr 13 |
nicklas |
306 |
jsonWell = new JSONObject(); |
1934 |
17 Apr 13 |
nicklas |
307 |
jsonWell.put("id", well.getId()); |
1934 |
17 Apr 13 |
nicklas |
308 |
jsonWell.put("row", well.getRow()); |
1934 |
17 Apr 13 |
nicklas |
309 |
jsonWell.put("column", well.getColumn()); |
1934 |
17 Apr 13 |
nicklas |
310 |
|
1934 |
17 Apr 13 |
nicklas |
311 |
BioPlate plate = well.getPlate(); |
1934 |
17 Apr 13 |
nicklas |
312 |
JSONObject jsonPlate = new JSONObject(); |
1934 |
17 Apr 13 |
nicklas |
313 |
jsonPlate.put("id", plate.getId()); |
1934 |
17 Apr 13 |
nicklas |
314 |
jsonPlate.put("name", plate.getName()); |
1934 |
17 Apr 13 |
nicklas |
315 |
|
1934 |
17 Apr 13 |
nicklas |
316 |
jsonWell.put("bioPlate", jsonPlate); |
1934 |
17 Apr 13 |
nicklas |
317 |
} |
1934 |
17 Apr 13 |
nicklas |
318 |
|
1934 |
17 Apr 13 |
nicklas |
319 |
return jsonWell; |
1934 |
17 Apr 13 |
nicklas |
320 |
} |
1934 |
17 Apr 13 |
nicklas |
321 |
|
2090 |
21 Oct 13 |
nicklas |
322 |
/** |
2090 |
21 Oct 13 |
nicklas |
Load the library bioplates that the parent libraries that |
2090 |
21 Oct 13 |
nicklas |
are part of this pool are coming from. The result is returned |
2090 |
21 Oct 13 |
nicklas |
as a JSON array and is also included in the "libPlates" property |
2090 |
21 Oct 13 |
nicklas |
when calling {@link #asJSONObject()} later. |
2090 |
21 Oct 13 |
nicklas |
327 |
*/ |
2090 |
21 Oct 13 |
nicklas |
328 |
public JSONArray loadLibPlates(DbControl dc) |
2090 |
21 Oct 13 |
nicklas |
329 |
{ |
2090 |
21 Oct 13 |
nicklas |
330 |
if (jsonLibPlates != null) return jsonLibPlates; |
2090 |
21 Oct 13 |
nicklas |
331 |
|
2090 |
21 Oct 13 |
nicklas |
332 |
Extract pool = getItem(); |
2090 |
21 Oct 13 |
nicklas |
333 |
|
2090 |
21 Oct 13 |
nicklas |
334 |
ItemQuery<BioPlate> libPlateQuery = BioPlate.getQuery(); |
2090 |
21 Oct 13 |
nicklas |
335 |
libPlateQuery.setDistinct(true); |
2090 |
21 Oct 13 |
nicklas |
336 |
libPlateQuery.include(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
5883 |
26 Mar 20 |
nicklas |
337 |
|
2090 |
21 Oct 13 |
nicklas |
338 |
libPlateQuery.join(Hql.innerJoin("bioWells", "bw")); |
2090 |
21 Oct 13 |
nicklas |
339 |
libPlateQuery.join(Hql.innerJoin("bw", "bioMaterial", "lib")); |
2090 |
21 Oct 13 |
nicklas |
340 |
|
2090 |
21 Oct 13 |
nicklas |
341 |
libPlateQuery.join(Hql.innerJoin("lib", "childCreationEvents", "cce")); |
2090 |
21 Oct 13 |
nicklas |
342 |
libPlateQuery.join(Hql.innerJoin("cce", "event", "evt")); |
2090 |
21 Oct 13 |
nicklas |
343 |
libPlateQuery.join(Hql.innerJoin("evt", "bioMaterial", "pool")); |
2090 |
21 Oct 13 |
nicklas |
344 |
|
2090 |
21 Oct 13 |
nicklas |
345 |
libPlateQuery.restrict(Restrictions.eq(Hql.alias("pool"), Hql.entity(pool))); |
2090 |
21 Oct 13 |
nicklas |
346 |
|
2090 |
21 Oct 13 |
nicklas |
347 |
libPlateQuery.order(Orders.asc(Hql.property("name"))); |
2090 |
21 Oct 13 |
nicklas |
348 |
List<BioPlate> result = libPlateQuery.list(dc); |
2090 |
21 Oct 13 |
nicklas |
349 |
|
2090 |
21 Oct 13 |
nicklas |
350 |
jsonLibPlates = new JSONArray(); |
2090 |
21 Oct 13 |
nicklas |
351 |
for (BioPlate libPlate : result) |
2090 |
21 Oct 13 |
nicklas |
352 |
{ |
5452 |
28 May 19 |
nicklas |
353 |
BioPlateType plateType = libPlate.getBioPlateType(); |
2090 |
21 Oct 13 |
nicklas |
354 |
JSONObject jsonLibPlate = new JSONObject(); |
2090 |
21 Oct 13 |
nicklas |
355 |
jsonLibPlate.put("id", libPlate.getId()); |
2090 |
21 Oct 13 |
nicklas |
356 |
jsonLibPlate.put("name", libPlate.getName()); |
5452 |
28 May 19 |
nicklas |
357 |
jsonLibPlate.put("plateType", plateType.getName()); |
2090 |
21 Oct 13 |
nicklas |
358 |
jsonLibPlates.add(jsonLibPlate); |
2090 |
21 Oct 13 |
nicklas |
359 |
} |
2090 |
21 Oct 13 |
nicklas |
360 |
return jsonLibPlates; |
2090 |
21 Oct 13 |
nicklas |
361 |
} |
2090 |
21 Oct 13 |
nicklas |
362 |
|
1934 |
17 Apr 13 |
nicklas |
363 |
} |