2364 |
15 Apr 14 |
nicklas |
1 |
package net.sf.basedb.reggie.dao; |
2364 |
15 Apr 14 |
nicklas |
2 |
|
2364 |
15 Apr 14 |
nicklas |
3 |
import java.util.ArrayList; |
2364 |
15 Apr 14 |
nicklas |
4 |
import java.util.Collection; |
2364 |
15 Apr 14 |
nicklas |
5 |
import java.util.List; |
2364 |
15 Apr 14 |
nicklas |
6 |
|
2364 |
15 Apr 14 |
nicklas |
7 |
import org.json.simple.JSONObject; |
2364 |
15 Apr 14 |
nicklas |
8 |
|
2364 |
15 Apr 14 |
nicklas |
9 |
import net.sf.basedb.core.DbControl; |
2364 |
15 Apr 14 |
nicklas |
10 |
import net.sf.basedb.core.DerivedBioAssay; |
2819 |
16 Oct 14 |
nicklas |
11 |
import net.sf.basedb.core.Extract; |
2373 |
23 Apr 14 |
nicklas |
12 |
import net.sf.basedb.core.InvalidDataException; |
2364 |
15 Apr 14 |
nicklas |
13 |
import net.sf.basedb.core.ItemQuery; |
2819 |
16 Oct 14 |
nicklas |
14 |
import net.sf.basedb.core.Job; |
2819 |
16 Oct 14 |
nicklas |
15 |
import net.sf.basedb.core.Type; |
2373 |
23 Apr 14 |
nicklas |
16 |
import net.sf.basedb.core.query.Expressions; |
2364 |
15 Apr 14 |
nicklas |
17 |
import net.sf.basedb.core.query.Hql; |
2364 |
15 Apr 14 |
nicklas |
18 |
import net.sf.basedb.core.query.Orders; |
2373 |
23 Apr 14 |
nicklas |
19 |
import net.sf.basedb.core.query.Restrictions; |
2364 |
15 Apr 14 |
nicklas |
20 |
import net.sf.basedb.reggie.Reggie; |
2364 |
15 Apr 14 |
nicklas |
21 |
|
2364 |
15 Apr 14 |
nicklas |
22 |
/** |
2364 |
15 Apr 14 |
nicklas |
Class for loading information that is related to demuxed sequences. |
2364 |
15 Apr 14 |
nicklas |
24 |
|
2364 |
15 Apr 14 |
nicklas |
@author nicklas |
2364 |
15 Apr 14 |
nicklas |
@since 2.16 |
2364 |
15 Apr 14 |
nicklas |
27 |
*/ |
2364 |
15 Apr 14 |
nicklas |
28 |
public class DemuxedSequences |
2364 |
15 Apr 14 |
nicklas |
29 |
extends ReggieItem<DerivedBioAssay> |
2364 |
15 Apr 14 |
nicklas |
30 |
{ |
2364 |
15 Apr 14 |
nicklas |
31 |
|
2364 |
15 Apr 14 |
nicklas |
32 |
/** |
2367 |
17 Apr 14 |
nicklas |
Value for the {@link Annotationtype#ANALYSIS_RESULT} annotation |
2367 |
17 Apr 14 |
nicklas |
when the demux was successful. |
2367 |
17 Apr 14 |
nicklas |
35 |
*/ |
2367 |
17 Apr 14 |
nicklas |
36 |
public static final String DEMUX_SUCCESSFUL = "Successful"; |
3723 |
25 Jan 16 |
nicklas |
37 |
|
3723 |
25 Jan 16 |
nicklas |
38 |
/** |
3723 |
25 Jan 16 |
nicklas |
Value for the {@link Annotationtype#ANALYSIS_RESULT} annotation |
3723 |
25 Jan 16 |
nicklas |
when the demux was partially successful (=no warnings, but |
3723 |
25 Jan 16 |
nicklas |
some libs have too few reads). |
3723 |
25 Jan 16 |
nicklas |
@since 4.1 |
3723 |
25 Jan 16 |
nicklas |
43 |
*/ |
3723 |
25 Jan 16 |
nicklas |
44 |
public static final String DEMUX_PARTIAL = "Partial"; |
2367 |
17 Apr 14 |
nicklas |
45 |
|
2367 |
17 Apr 14 |
nicklas |
46 |
/** |
2367 |
17 Apr 14 |
nicklas |
Value for the {@link Annotationtype#ANALYSIS_RESULT} annotation when |
2367 |
17 Apr 14 |
nicklas |
the demux failed. |
2367 |
17 Apr 14 |
nicklas |
49 |
*/ |
2367 |
17 Apr 14 |
nicklas |
50 |
public static final String DEMUX_FAILED = "Failed"; |
2367 |
17 Apr 14 |
nicklas |
51 |
|
2367 |
17 Apr 14 |
nicklas |
52 |
|
2367 |
17 Apr 14 |
nicklas |
53 |
/** |
2364 |
15 Apr 14 |
nicklas |
Get demuxed sequences item when the id is known. |
2364 |
15 Apr 14 |
nicklas |
55 |
*/ |
2364 |
15 Apr 14 |
nicklas |
56 |
public static DemuxedSequences getById(DbControl dc, int id) |
2364 |
15 Apr 14 |
nicklas |
57 |
{ |
2364 |
15 Apr 14 |
nicklas |
58 |
return new DemuxedSequences(DerivedBioAssay.getById(dc, id)); |
2364 |
15 Apr 14 |
nicklas |
59 |
} |
2364 |
15 Apr 14 |
nicklas |
60 |
|
6193 |
30 Mar 21 |
nicklas |
61 |
public static DemuxedSequences get(DerivedBioAssay dba) |
6193 |
30 Mar 21 |
nicklas |
62 |
{ |
6193 |
30 Mar 21 |
nicklas |
63 |
return new DemuxedSequences(dba); |
6193 |
30 Mar 21 |
nicklas |
64 |
} |
6193 |
30 Mar 21 |
nicklas |
65 |
|
2373 |
23 Apr 14 |
nicklas |
66 |
public static DemuxedSequences getByName(DbControl dc, String name) |
2373 |
23 Apr 14 |
nicklas |
67 |
{ |
2373 |
23 Apr 14 |
nicklas |
68 |
ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery(); |
2373 |
23 Apr 14 |
nicklas |
69 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2373 |
23 Apr 14 |
nicklas |
70 |
Subtype.DEMUXED_SEQUENCES.addFilter(dc, query); |
2373 |
23 Apr 14 |
nicklas |
71 |
query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(name))); |
2373 |
23 Apr 14 |
nicklas |
72 |
|
2373 |
23 Apr 14 |
nicklas |
73 |
List<DerivedBioAssay> list = query.list(dc); |
2373 |
23 Apr 14 |
nicklas |
74 |
if (list.size() > 1) |
2373 |
23 Apr 14 |
nicklas |
75 |
{ |
2373 |
23 Apr 14 |
nicklas |
76 |
throw new InvalidDataException( |
2373 |
23 Apr 14 |
nicklas |
77 |
"More than one item with the name " + name + " was found. " + |
2373 |
23 Apr 14 |
nicklas |
78 |
"This wizard can't be used until that is corrected."); |
2373 |
23 Apr 14 |
nicklas |
79 |
} |
2373 |
23 Apr 14 |
nicklas |
80 |
DemuxedSequences demux = null; |
2373 |
23 Apr 14 |
nicklas |
81 |
if (list.size() == 1) |
2373 |
23 Apr 14 |
nicklas |
82 |
{ |
2373 |
23 Apr 14 |
nicklas |
83 |
demux = new DemuxedSequences(list.get(0)); |
2373 |
23 Apr 14 |
nicklas |
84 |
} |
2373 |
23 Apr 14 |
nicklas |
85 |
return demux; |
2373 |
23 Apr 14 |
nicklas |
86 |
} |
2373 |
23 Apr 14 |
nicklas |
87 |
|
2819 |
16 Oct 14 |
nicklas |
88 |
/** |
2819 |
16 Oct 14 |
nicklas |
@since 2.16.2 |
2819 |
16 Oct 14 |
nicklas |
90 |
*/ |
2819 |
16 Oct 14 |
nicklas |
91 |
public static List<DemuxedSequences> findByJob(DbControl dc, Job job) |
2819 |
16 Oct 14 |
nicklas |
92 |
{ |
2819 |
16 Oct 14 |
nicklas |
93 |
ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery(); |
2819 |
16 Oct 14 |
nicklas |
94 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2819 |
16 Oct 14 |
nicklas |
95 |
Subtype.DEMUXED_SEQUENCES.addFilter(dc, query); |
2819 |
16 Oct 14 |
nicklas |
96 |
query.restrict(Restrictions.eq(Hql.property("job", "id"), Hql.entity(job))); |
2819 |
16 Oct 14 |
nicklas |
97 |
query.order(Orders.asc(Hql.property("name"))); |
2819 |
16 Oct 14 |
nicklas |
98 |
return toList(query.list(dc)); |
2819 |
16 Oct 14 |
nicklas |
99 |
} |
2819 |
16 Oct 14 |
nicklas |
100 |
|
2819 |
16 Oct 14 |
nicklas |
101 |
|
2364 |
15 Apr 14 |
nicklas |
102 |
public static List<DemuxedSequences> findByFlowCell(DbControl dc, FlowCell fc) |
2364 |
15 Apr 14 |
nicklas |
103 |
{ |
2364 |
15 Apr 14 |
nicklas |
104 |
ItemQuery<DerivedBioAssay> query = fc.getItem().getDerivedBioAssays(); |
2364 |
15 Apr 14 |
nicklas |
105 |
Subtype.DEMUXED_SEQUENCES.addFilter(dc, query); |
2364 |
15 Apr 14 |
nicklas |
106 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2364 |
15 Apr 14 |
nicklas |
107 |
query.order(Orders.asc(Hql.property("name"))); |
2364 |
15 Apr 14 |
nicklas |
108 |
return toList(query.list(dc)); |
2364 |
15 Apr 14 |
nicklas |
109 |
} |
6193 |
30 Mar 21 |
nicklas |
110 |
|
6193 |
30 Mar 21 |
nicklas |
111 |
public static List<DemuxedSequences> findBySequencingRun(DbControl dc, SequencingRun seqRun) |
6193 |
30 Mar 21 |
nicklas |
112 |
{ |
6193 |
30 Mar 21 |
nicklas |
113 |
ItemQuery<DerivedBioAssay> query = seqRun.getItem().getChildren(); |
6193 |
30 Mar 21 |
nicklas |
114 |
Subtype.DEMUXED_SEQUENCES.addFilter(dc, query); |
6193 |
30 Mar 21 |
nicklas |
115 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
6193 |
30 Mar 21 |
nicklas |
116 |
query.order(Orders.asc(Hql.property("name"))); |
6193 |
30 Mar 21 |
nicklas |
117 |
return toList(query.list(dc)); |
6193 |
30 Mar 21 |
nicklas |
118 |
} |
6193 |
30 Mar 21 |
nicklas |
119 |
|
2364 |
15 Apr 14 |
nicklas |
120 |
public static List<DemuxedSequences> toList(Collection<DerivedBioAssay> bioassays) |
2364 |
15 Apr 14 |
nicklas |
121 |
{ |
2364 |
15 Apr 14 |
nicklas |
122 |
List<DemuxedSequences> lib = new ArrayList<DemuxedSequences>(bioassays.size()); |
2364 |
15 Apr 14 |
nicklas |
123 |
for (DerivedBioAssay ba : bioassays) |
2364 |
15 Apr 14 |
nicklas |
124 |
{ |
2364 |
15 Apr 14 |
nicklas |
125 |
lib.add(new DemuxedSequences(ba)); |
2364 |
15 Apr 14 |
nicklas |
126 |
} |
2364 |
15 Apr 14 |
nicklas |
127 |
return lib; |
2364 |
15 Apr 14 |
nicklas |
128 |
} |
2364 |
15 Apr 14 |
nicklas |
129 |
|
2364 |
15 Apr 14 |
nicklas |
130 |
|
2364 |
15 Apr 14 |
nicklas |
131 |
private DemuxedSequences(DerivedBioAssay bioAssay) |
2364 |
15 Apr 14 |
nicklas |
132 |
{ |
2364 |
15 Apr 14 |
nicklas |
133 |
super(bioAssay); |
2364 |
15 Apr 14 |
nicklas |
134 |
|
2364 |
15 Apr 14 |
nicklas |
135 |
} |
2364 |
15 Apr 14 |
nicklas |
136 |
|
2364 |
15 Apr 14 |
nicklas |
137 |
/** |
2364 |
15 Apr 14 |
nicklas |
Get the derived bioassay that represents the demuxed sequences in BASE. |
2364 |
15 Apr 14 |
nicklas |
139 |
*/ |
2364 |
15 Apr 14 |
nicklas |
140 |
public DerivedBioAssay getDerivedBioAssay() |
2364 |
15 Apr 14 |
nicklas |
141 |
{ |
2364 |
15 Apr 14 |
nicklas |
142 |
return getItem(); |
2364 |
15 Apr 14 |
nicklas |
143 |
} |
2364 |
15 Apr 14 |
nicklas |
144 |
|
2364 |
15 Apr 14 |
nicklas |
145 |
@Override |
2364 |
15 Apr 14 |
nicklas |
146 |
protected void initJSON(JSONObject json) |
2364 |
15 Apr 14 |
nicklas |
147 |
{ |
2364 |
15 Apr 14 |
nicklas |
148 |
super.initJSON(json); |
2364 |
15 Apr 14 |
nicklas |
149 |
} |
2364 |
15 Apr 14 |
nicklas |
150 |
|
2819 |
16 Oct 14 |
nicklas |
151 |
/** |
2819 |
16 Oct 14 |
nicklas |
Load pooled libraries demuxed from the sequencing run. Pools from omitted |
2819 |
16 Oct 14 |
nicklas |
lanes are not included. |
2819 |
16 Oct 14 |
nicklas |
@since 2.16.2 |
2819 |
16 Oct 14 |
nicklas |
155 |
*/ |
2819 |
16 Oct 14 |
nicklas |
156 |
@SuppressWarnings("unchecked") |
2819 |
16 Oct 14 |
nicklas |
157 |
public List<PooledLibrary> getPools(DbControl dc) |
2819 |
16 Oct 14 |
nicklas |
158 |
{ |
2819 |
16 Oct 14 |
nicklas |
159 |
DerivedBioAssay dx = getItem(); |
2819 |
16 Oct 14 |
nicklas |
160 |
List<Integer> omittedLanes = (List<Integer>)Annotationtype.OMIT_LANES.getAnnotationValues(dc, dx); |
2819 |
16 Oct 14 |
nicklas |
161 |
|
2819 |
16 Oct 14 |
nicklas |
162 |
ItemQuery<Extract> query = Extract.getQuery(); |
2819 |
16 Oct 14 |
nicklas |
163 |
Subtype.POOLED_LIBRARY.addFilter(dc, query); |
2819 |
16 Oct 14 |
nicklas |
164 |
query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
2819 |
16 Oct 14 |
nicklas |
165 |
query.setDistinct(true); |
2819 |
16 Oct 14 |
nicklas |
166 |
|
2819 |
16 Oct 14 |
nicklas |
// Join intermediate aliquot |
2819 |
16 Oct 14 |
nicklas |
168 |
query.join(Hql.innerJoin("childCreationEvents", "cce1")); |
2819 |
16 Oct 14 |
nicklas |
169 |
query.join(Hql.innerJoin("cce1", "event", "evt1")); |
2819 |
16 Oct 14 |
nicklas |
170 |
query.join(Hql.innerJoin("evt1", "bioMaterial", "pa")); |
2819 |
16 Oct 14 |
nicklas |
171 |
|
2819 |
16 Oct 14 |
nicklas |
// Join flow cell |
2819 |
16 Oct 14 |
nicklas |
173 |
query.join(Hql.innerJoin("pa", "childCreationEvents", "cce2")); |
2819 |
16 Oct 14 |
nicklas |
174 |
query.join(Hql.innerJoin("cce2", "event", "evt2")); |
2819 |
16 Oct 14 |
nicklas |
175 |
query.join(Hql.innerJoin("evt2", "physicalBioAssay", "fc")); |
2364 |
15 Apr 14 |
nicklas |
176 |
|
2819 |
16 Oct 14 |
nicklas |
// Join demuxed sequences |
2819 |
16 Oct 14 |
nicklas |
178 |
query.join(Hql.innerJoin("fc", "derivedBioAssays", "dx")); |
2819 |
16 Oct 14 |
nicklas |
179 |
|
2819 |
16 Oct 14 |
nicklas |
// Filter on lanes |
2819 |
16 Oct 14 |
nicklas |
181 |
if (omittedLanes != null && omittedLanes.size() > 0) |
2819 |
16 Oct 14 |
nicklas |
182 |
{ |
2819 |
16 Oct 14 |
nicklas |
183 |
query.restrict(Restrictions.not(Restrictions.in(Hql.property("cce2", "position"), Expressions.parameter("lanes", omittedLanes, Type.INT)))); |
2819 |
16 Oct 14 |
nicklas |
184 |
} |
2819 |
16 Oct 14 |
nicklas |
185 |
|
2819 |
16 Oct 14 |
nicklas |
// Filter on this item |
2819 |
16 Oct 14 |
nicklas |
187 |
query.restrict(Restrictions.eq(Hql.alias("dx"), Hql.entity(getItem()))); |
2819 |
16 Oct 14 |
nicklas |
188 |
query.order(Orders.asc(Hql.property("name"))); |
2819 |
16 Oct 14 |
nicklas |
189 |
|
2819 |
16 Oct 14 |
nicklas |
190 |
return PooledLibrary.toList(query.list(dc)); |
2819 |
16 Oct 14 |
nicklas |
191 |
} |
2819 |
16 Oct 14 |
nicklas |
192 |
|
6215 |
16 Apr 21 |
nicklas |
193 |
/** |
6215 |
16 Apr 21 |
nicklas |
Get the library related to this demux. NOTE! This is only |
6215 |
16 Apr 21 |
nicklas |
available for externally sequenced where we get raw FASTQ files |
6215 |
16 Apr 21 |
nicklas |
from the demux. |
6215 |
16 Apr 21 |
nicklas |
@since 4.32 |
6215 |
16 Apr 21 |
nicklas |
198 |
*/ |
6215 |
16 Apr 21 |
nicklas |
199 |
public Library getLibrary(DbControl dc) |
6215 |
16 Apr 21 |
nicklas |
200 |
{ |
6215 |
16 Apr 21 |
nicklas |
201 |
return getItem().getExtract() == null ? null : Library.getById(dc, getItem().getExtract().getId()); |
6215 |
16 Apr 21 |
nicklas |
202 |
} |
2819 |
16 Oct 14 |
nicklas |
203 |
|
2364 |
15 Apr 14 |
nicklas |
204 |
} |