2020 |
13 Sep 13 |
nicklas |
1 |
package net.sf.basedb.reggie.dao; |
2020 |
13 Sep 13 |
nicklas |
2 |
|
2020 |
13 Sep 13 |
nicklas |
3 |
import java.util.ArrayList; |
2020 |
13 Sep 13 |
nicklas |
4 |
import java.util.Collection; |
2020 |
13 Sep 13 |
nicklas |
5 |
import java.util.List; |
2020 |
13 Sep 13 |
nicklas |
6 |
|
2020 |
13 Sep 13 |
nicklas |
7 |
import org.json.simple.JSONObject; |
2020 |
13 Sep 13 |
nicklas |
8 |
|
2222 |
11 Feb 14 |
nicklas |
9 |
import net.sf.basedb.core.AnnotationType; |
2020 |
13 Sep 13 |
nicklas |
10 |
import net.sf.basedb.core.DbControl; |
2344 |
09 Apr 14 |
nicklas |
11 |
import net.sf.basedb.core.HibernateUtil; |
4890 |
06 Jul 18 |
nicklas |
12 |
import net.sf.basedb.core.Include; |
2222 |
11 Feb 14 |
nicklas |
13 |
import net.sf.basedb.core.InvalidDataException; |
2020 |
13 Sep 13 |
nicklas |
14 |
import net.sf.basedb.core.ItemQuery; |
2020 |
13 Sep 13 |
nicklas |
15 |
import net.sf.basedb.core.PhysicalBioAssay; |
2222 |
11 Feb 14 |
nicklas |
16 |
import net.sf.basedb.core.query.Annotations; |
2020 |
13 Sep 13 |
nicklas |
17 |
import net.sf.basedb.core.query.Expressions; |
2020 |
13 Sep 13 |
nicklas |
18 |
import net.sf.basedb.core.query.Hql; |
2020 |
13 Sep 13 |
nicklas |
19 |
import net.sf.basedb.core.query.Orders; |
2020 |
13 Sep 13 |
nicklas |
20 |
import net.sf.basedb.core.query.Restrictions; |
2020 |
13 Sep 13 |
nicklas |
21 |
import net.sf.basedb.reggie.Reggie; |
2344 |
09 Apr 14 |
nicklas |
22 |
import net.sf.basedb.reggie.query.LowerExpression; |
2020 |
13 Sep 13 |
nicklas |
23 |
|
2020 |
13 Sep 13 |
nicklas |
24 |
/** |
2222 |
11 Feb 14 |
nicklas |
Class for loading information that is related to Flow cells. |
2020 |
13 Sep 13 |
nicklas |
26 |
|
2020 |
13 Sep 13 |
nicklas |
@author nicklas |
2020 |
13 Sep 13 |
nicklas |
@since 2.12 |
2020 |
13 Sep 13 |
nicklas |
29 |
*/ |
2020 |
13 Sep 13 |
nicklas |
30 |
public class FlowCell |
2020 |
13 Sep 13 |
nicklas |
31 |
extends ReggieItem<PhysicalBioAssay> |
2020 |
13 Sep 13 |
nicklas |
32 |
{ |
2020 |
13 Sep 13 |
nicklas |
33 |
|
2020 |
13 Sep 13 |
nicklas |
34 |
/** |
2412 |
09 May 14 |
nicklas |
Annotation value for the {@link Annotationtype#FLOWCELL_TYPE} when |
2412 |
09 May 14 |
nicklas |
the flow cell is a HiSeq flow cell type. |
2412 |
09 May 14 |
nicklas |
@since 2.15.1 |
2412 |
09 May 14 |
nicklas |
38 |
*/ |
2412 |
09 May 14 |
nicklas |
39 |
public static final String FLOW_CELL_TYPE_HISEQ = "HiSeq"; |
2412 |
09 May 14 |
nicklas |
40 |
|
2412 |
09 May 14 |
nicklas |
41 |
/** |
2412 |
09 May 14 |
nicklas |
Annotation value for the {@link Annotationtype#FLOWCELL_TYPE} when |
2412 |
09 May 14 |
nicklas |
the flow cell is a NextSeq flow cell type. |
2412 |
09 May 14 |
nicklas |
44 |
*/ |
2412 |
09 May 14 |
nicklas |
45 |
public static final String FLOW_CELL_TYPE_NEXTSEQ = "NextSeq"; |
5855 |
09 Mar 20 |
nicklas |
46 |
|
5855 |
09 Mar 20 |
nicklas |
47 |
/** |
5855 |
09 Mar 20 |
nicklas |
Annotation value for the {@link Annotationtype#FLOWCELL_TYPE} when |
5855 |
09 Mar 20 |
nicklas |
the flow cell is a NovaSeq flow cell type. |
5855 |
09 Mar 20 |
nicklas |
@since 4.26 |
5855 |
09 Mar 20 |
nicklas |
51 |
*/ |
5855 |
09 Mar 20 |
nicklas |
52 |
public static final String FLOW_CELL_TYPE_NOVASEQ = "NovaSeq"; |
5855 |
09 Mar 20 |
nicklas |
53 |
|
2412 |
09 May 14 |
nicklas |
54 |
|
2412 |
09 May 14 |
nicklas |
55 |
/** |
2222 |
11 Feb 14 |
nicklas |
Find a flow cell by barcode number. If exactly one match is found all is |
2222 |
11 Feb 14 |
nicklas |
good and this is the flow cell we are looking for. More than one match |
2222 |
11 Feb 14 |
nicklas |
is an error condition. No match indicates a flow cell that has not yet |
2222 |
11 Feb 14 |
nicklas |
been registered (null is returned). |
2222 |
11 Feb 14 |
nicklas |
60 |
*/ |
2222 |
11 Feb 14 |
nicklas |
61 |
public static FlowCell findByBarcode(DbControl dc, String barcode) |
2222 |
11 Feb 14 |
nicklas |
62 |
{ |
2222 |
11 Feb 14 |
nicklas |
63 |
FlowCell fc = null; |
2222 |
11 Feb 14 |
nicklas |
64 |
|
2222 |
11 Feb 14 |
nicklas |
65 |
AnnotationType barcodeType = Annotationtype.FLOWCELL_ID.load(dc); |
2222 |
11 Feb 14 |
nicklas |
66 |
ItemQuery<PhysicalBioAssay> query = PhysicalBioAssay.getQuery(); |
2222 |
11 Feb 14 |
nicklas |
67 |
Subtype.FLOW_CELL.addFilter(dc, query); |
2344 |
09 Apr 14 |
nicklas |
68 |
query.join(Annotations.innerJoin(barcodeType, "bc")); |
2344 |
09 Apr 14 |
nicklas |
69 |
if (HibernateUtil.getDbEngine().caseInsensitiveComparison()) |
2344 |
09 Apr 14 |
nicklas |
70 |
{ |
2344 |
09 Apr 14 |
nicklas |
71 |
query.restrict(Restrictions.eq(Hql.alias("bc"), Expressions.string(barcode))); |
2344 |
09 Apr 14 |
nicklas |
72 |
} |
2344 |
09 Apr 14 |
nicklas |
73 |
else |
2344 |
09 Apr 14 |
nicklas |
74 |
{ |
2344 |
09 Apr 14 |
nicklas |
75 |
query.restrict(Restrictions.eq(new LowerExpression(Hql.alias("bc")), Expressions.string(barcode.toLowerCase()))); |
2344 |
09 Apr 14 |
nicklas |
76 |
} |
2344 |
09 Apr 14 |
nicklas |
77 |
|
2222 |
11 Feb 14 |
nicklas |
78 |
List<PhysicalBioAssay> flowCells = query.list(dc); |
2222 |
11 Feb 14 |
nicklas |
79 |
|
2222 |
11 Feb 14 |
nicklas |
80 |
if (flowCells.size() > 1) |
2222 |
11 Feb 14 |
nicklas |
81 |
{ |
2222 |
11 Feb 14 |
nicklas |
82 |
throw new InvalidDataException( |
2222 |
11 Feb 14 |
nicklas |
83 |
"More than one flow cell with barcode (" + barcode + ") was found. " + |
2222 |
11 Feb 14 |
nicklas |
84 |
"This wizard can't be used until that is corrected."); |
2222 |
11 Feb 14 |
nicklas |
85 |
} |
2222 |
11 Feb 14 |
nicklas |
86 |
if (flowCells.size() == 1) |
2222 |
11 Feb 14 |
nicklas |
87 |
{ |
2222 |
11 Feb 14 |
nicklas |
88 |
fc = new FlowCell(flowCells.get(0)); |
2222 |
11 Feb 14 |
nicklas |
89 |
} |
2222 |
11 Feb 14 |
nicklas |
90 |
return fc; |
2222 |
11 Feb 14 |
nicklas |
91 |
} |
2222 |
11 Feb 14 |
nicklas |
92 |
|
2222 |
11 Feb 14 |
nicklas |
93 |
|
2222 |
11 Feb 14 |
nicklas |
94 |
/** |
6193 |
30 Mar 21 |
nicklas |
Get a FlowCell when the id is known. |
2020 |
13 Sep 13 |
nicklas |
96 |
*/ |
2020 |
13 Sep 13 |
nicklas |
97 |
public static FlowCell getById(DbControl dc, int id) |
2020 |
13 Sep 13 |
nicklas |
98 |
{ |
2020 |
13 Sep 13 |
nicklas |
99 |
return new FlowCell(PhysicalBioAssay.getById(dc, id)); |
2020 |
13 Sep 13 |
nicklas |
100 |
} |
2020 |
13 Sep 13 |
nicklas |
101 |
|
6193 |
30 Mar 21 |
nicklas |
102 |
public static FlowCell get(PhysicalBioAssay fc) |
6193 |
30 Mar 21 |
nicklas |
103 |
{ |
6193 |
30 Mar 21 |
nicklas |
104 |
return new FlowCell(fc); |
6193 |
30 Mar 21 |
nicklas |
105 |
} |
2020 |
13 Sep 13 |
nicklas |
106 |
|
2020 |
13 Sep 13 |
nicklas |
107 |
public static List<FlowCell> toList(Collection<PhysicalBioAssay> bioassays) |
2020 |
13 Sep 13 |
nicklas |
108 |
{ |
2020 |
13 Sep 13 |
nicklas |
109 |
List<FlowCell> lib = new ArrayList<FlowCell>(bioassays.size()); |
2020 |
13 Sep 13 |
nicklas |
110 |
for (PhysicalBioAssay ba : bioassays) |
2020 |
13 Sep 13 |
nicklas |
111 |
{ |
2020 |
13 Sep 13 |
nicklas |
112 |
lib.add(new FlowCell(ba)); |
2020 |
13 Sep 13 |
nicklas |
113 |
} |
2020 |
13 Sep 13 |
nicklas |
114 |
return lib; |
2020 |
13 Sep 13 |
nicklas |
115 |
} |
2020 |
13 Sep 13 |
nicklas |
116 |
|
2020 |
13 Sep 13 |
nicklas |
117 |
/** |
2225 |
13 Feb 14 |
nicklas |
Load the flow cell on the sequening run. |
2197 |
14 Jan 14 |
nicklas |
119 |
*/ |
2225 |
13 Feb 14 |
nicklas |
120 |
public static FlowCell getBySequencingRun(DbControl dc, SequencingRun sequencingRun) |
2197 |
14 Jan 14 |
nicklas |
121 |
{ |
2197 |
14 Jan 14 |
nicklas |
122 |
ItemQuery<PhysicalBioAssay> fcQuery = PhysicalBioAssay.getQuery(); |
2197 |
14 Jan 14 |
nicklas |
123 |
Subtype.FLOW_CELL.addFilter(dc, fcQuery); |
2197 |
14 Jan 14 |
nicklas |
124 |
fcQuery.include(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2197 |
14 Jan 14 |
nicklas |
125 |
|
2197 |
14 Jan 14 |
nicklas |
// Join sequencing runs |
2197 |
14 Jan 14 |
nicklas |
127 |
fcQuery.join(Hql.innerJoin("derivedBioAssays", "dba")); |
2197 |
14 Jan 14 |
nicklas |
128 |
fcQuery.restrict(Restrictions.eq(Hql.alias("dba"), Hql.entity(sequencingRun.getItem()))); |
2197 |
14 Jan 14 |
nicklas |
129 |
|
2197 |
14 Jan 14 |
nicklas |
130 |
fcQuery.order(Orders.asc(Hql.property("name"))); |
2197 |
14 Jan 14 |
nicklas |
131 |
|
2197 |
14 Jan 14 |
nicklas |
132 |
List<PhysicalBioAssay> tmp = fcQuery.list(dc); |
2197 |
14 Jan 14 |
nicklas |
133 |
|
2225 |
13 Feb 14 |
nicklas |
134 |
PhysicalBioAssay fc = null; |
2225 |
13 Feb 14 |
nicklas |
135 |
if (tmp.size() > 1) |
2225 |
13 Feb 14 |
nicklas |
136 |
{ |
2225 |
13 Feb 14 |
nicklas |
137 |
throw new InvalidDataException( |
2225 |
13 Feb 14 |
nicklas |
138 |
"More than one flow cell was found on " + sequencingRun.getName() + |
2225 |
13 Feb 14 |
nicklas |
139 |
"This wizard can't be used until that is corrected."); |
2225 |
13 Feb 14 |
nicklas |
140 |
} |
2225 |
13 Feb 14 |
nicklas |
141 |
else if (tmp.size() == 1) |
2225 |
13 Feb 14 |
nicklas |
142 |
{ |
2225 |
13 Feb 14 |
nicklas |
143 |
fc = tmp.get(0); |
2225 |
13 Feb 14 |
nicklas |
144 |
} |
2225 |
13 Feb 14 |
nicklas |
145 |
|
2225 |
13 Feb 14 |
nicklas |
146 |
return fc == null ? null : new FlowCell(fc); |
2197 |
14 Jan 14 |
nicklas |
147 |
} |
2364 |
15 Apr 14 |
nicklas |
148 |
|
2364 |
15 Apr 14 |
nicklas |
149 |
/** |
2364 |
15 Apr 14 |
nicklas |
Load the flow cell for a demuxed sequences item. |
2364 |
15 Apr 14 |
nicklas |
151 |
*/ |
2364 |
15 Apr 14 |
nicklas |
152 |
public static FlowCell getByDemuxedSequences(DbControl dc, DemuxedSequences demux) |
2364 |
15 Apr 14 |
nicklas |
153 |
{ |
2364 |
15 Apr 14 |
nicklas |
154 |
ItemQuery<PhysicalBioAssay> fcQuery = PhysicalBioAssay.getQuery(); |
2364 |
15 Apr 14 |
nicklas |
155 |
Subtype.FLOW_CELL.addFilter(dc, fcQuery); |
2364 |
15 Apr 14 |
nicklas |
156 |
fcQuery.include(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2364 |
15 Apr 14 |
nicklas |
157 |
|
2364 |
15 Apr 14 |
nicklas |
// Join sequencing runs |
2364 |
15 Apr 14 |
nicklas |
159 |
fcQuery.join(Hql.innerJoin("derivedBioAssays", "dba")); |
2364 |
15 Apr 14 |
nicklas |
160 |
fcQuery.restrict(Restrictions.eq(Hql.alias("dba"), Hql.entity(demux.getItem()))); |
2364 |
15 Apr 14 |
nicklas |
161 |
|
2364 |
15 Apr 14 |
nicklas |
162 |
fcQuery.order(Orders.asc(Hql.property("name"))); |
2364 |
15 Apr 14 |
nicklas |
163 |
|
2364 |
15 Apr 14 |
nicklas |
164 |
List<PhysicalBioAssay> tmp = fcQuery.list(dc); |
2364 |
15 Apr 14 |
nicklas |
165 |
|
2364 |
15 Apr 14 |
nicklas |
166 |
PhysicalBioAssay fc = null; |
2364 |
15 Apr 14 |
nicklas |
167 |
if (tmp.size() > 1) |
2364 |
15 Apr 14 |
nicklas |
168 |
{ |
2364 |
15 Apr 14 |
nicklas |
169 |
throw new InvalidDataException( |
2364 |
15 Apr 14 |
nicklas |
170 |
"More than one flow cell was found for " + demux.getName() + |
2364 |
15 Apr 14 |
nicklas |
171 |
"This wizard can't be used until that is corrected."); |
2364 |
15 Apr 14 |
nicklas |
172 |
} |
2364 |
15 Apr 14 |
nicklas |
173 |
else if (tmp.size() == 1) |
2364 |
15 Apr 14 |
nicklas |
174 |
{ |
2364 |
15 Apr 14 |
nicklas |
175 |
fc = tmp.get(0); |
2364 |
15 Apr 14 |
nicklas |
176 |
} |
2364 |
15 Apr 14 |
nicklas |
177 |
|
2364 |
15 Apr 14 |
nicklas |
178 |
return fc == null ? null : new FlowCell(fc); |
2364 |
15 Apr 14 |
nicklas |
179 |
} |
2197 |
14 Jan 14 |
nicklas |
180 |
|
2197 |
14 Jan 14 |
nicklas |
181 |
/** |
4890 |
06 Jul 18 |
nicklas |
Generate a sequence of names for the new flow cells. This method will search all flow |
4890 |
06 Jul 18 |
nicklas |
cells and find the one with the highest numeric suffix which |
4890 |
06 Jul 18 |
nicklas |
is incremented to create the following names. |
4890 |
06 Jul 18 |
nicklas |
@since 4.19 |
2020 |
13 Sep 13 |
nicklas |
186 |
*/ |
4890 |
06 Jul 18 |
nicklas |
187 |
public static List<String> getNextNames(DbControl dc, int numNames) |
2020 |
13 Sep 13 |
nicklas |
188 |
{ |
4895 |
09 Jul 18 |
nicklas |
189 |
String prefix = Subtype.FLOW_CELL.getItemPrefix(); |
2020 |
13 Sep 13 |
nicklas |
190 |
int numDigitsInName = 4; |
2020 |
13 Sep 13 |
nicklas |
191 |
ItemQuery<PhysicalBioAssay> query = PhysicalBioAssay.getQuery(); |
2020 |
13 Sep 13 |
nicklas |
192 |
Subtype.FLOW_CELL.addFilter(dc, query); |
4890 |
06 Jul 18 |
nicklas |
193 |
query.include(Include.ALL); |
4890 |
06 Jul 18 |
nicklas |
194 |
return ReggieItem.getNextItemNames(dc, numNames, query, prefix, numDigitsInName, false); |
2020 |
13 Sep 13 |
nicklas |
195 |
} |
2020 |
13 Sep 13 |
nicklas |
196 |
|
2020 |
13 Sep 13 |
nicklas |
197 |
|
2020 |
13 Sep 13 |
nicklas |
198 |
private FlowCell(PhysicalBioAssay bioAssay) |
2020 |
13 Sep 13 |
nicklas |
199 |
{ |
2020 |
13 Sep 13 |
nicklas |
200 |
super(bioAssay); |
2020 |
13 Sep 13 |
nicklas |
201 |
|
2020 |
13 Sep 13 |
nicklas |
202 |
} |
2020 |
13 Sep 13 |
nicklas |
203 |
|
2020 |
13 Sep 13 |
nicklas |
204 |
/** |
2020 |
13 Sep 13 |
nicklas |
Get the real physical bioassay that represents this Flow cell in BASE. |
2020 |
13 Sep 13 |
nicklas |
206 |
*/ |
2020 |
13 Sep 13 |
nicklas |
207 |
public PhysicalBioAssay getPhysicalBioAssay() |
2020 |
13 Sep 13 |
nicklas |
208 |
{ |
2020 |
13 Sep 13 |
nicklas |
209 |
return getItem(); |
2020 |
13 Sep 13 |
nicklas |
210 |
} |
2020 |
13 Sep 13 |
nicklas |
211 |
|
2020 |
13 Sep 13 |
nicklas |
212 |
@Override |
2020 |
13 Sep 13 |
nicklas |
213 |
protected void initJSON(JSONObject json) |
2020 |
13 Sep 13 |
nicklas |
214 |
{ |
2020 |
13 Sep 13 |
nicklas |
215 |
super.initJSON(json); |
2020 |
13 Sep 13 |
nicklas |
216 |
} |
2020 |
13 Sep 13 |
nicklas |
217 |
|
2020 |
13 Sep 13 |
nicklas |
218 |
|
2020 |
13 Sep 13 |
nicklas |
219 |
} |