3188 |
18 Mar 15 |
nicklas |
1 |
package net.sf.basedb.reggie.dao; |
3188 |
18 Mar 15 |
nicklas |
2 |
|
3188 |
18 Mar 15 |
nicklas |
3 |
import java.util.ArrayList; |
3188 |
18 Mar 15 |
nicklas |
4 |
import java.util.Collection; |
3188 |
18 Mar 15 |
nicklas |
5 |
import java.util.Date; |
3188 |
18 Mar 15 |
nicklas |
6 |
import java.util.List; |
3188 |
18 Mar 15 |
nicklas |
7 |
|
3188 |
18 Mar 15 |
nicklas |
8 |
import net.sf.basedb.core.BioPlate; |
3188 |
18 Mar 15 |
nicklas |
9 |
import net.sf.basedb.core.BioWell; |
3188 |
18 Mar 15 |
nicklas |
10 |
import net.sf.basedb.core.DbControl; |
3188 |
18 Mar 15 |
nicklas |
11 |
import net.sf.basedb.core.Extract; |
3188 |
18 Mar 15 |
nicklas |
12 |
import net.sf.basedb.core.ItemQuery; |
3188 |
18 Mar 15 |
nicklas |
13 |
import net.sf.basedb.core.query.Hql; |
3188 |
18 Mar 15 |
nicklas |
14 |
import net.sf.basedb.core.snapshot.SnapshotManager; |
3188 |
18 Mar 15 |
nicklas |
15 |
import net.sf.basedb.reggie.Reggie; |
3188 |
18 Mar 15 |
nicklas |
16 |
|
3188 |
18 Mar 15 |
nicklas |
17 |
/** |
3188 |
18 Mar 15 |
nicklas |
Class for loading information that is related to RNAQC extracts. |
3188 |
18 Mar 15 |
nicklas |
19 |
|
3188 |
18 Mar 15 |
nicklas |
@author nicklas |
3188 |
18 Mar 15 |
nicklas |
@since 3.2.1 |
3188 |
18 Mar 15 |
nicklas |
22 |
*/ |
3188 |
18 Mar 15 |
nicklas |
23 |
public class RnaQc |
3188 |
18 Mar 15 |
nicklas |
24 |
extends ReggieItem<Extract> |
3188 |
18 Mar 15 |
nicklas |
25 |
{ |
3188 |
18 Mar 15 |
nicklas |
26 |
|
3188 |
18 Mar 15 |
nicklas |
27 |
|
3188 |
18 Mar 15 |
nicklas |
28 |
/** |
3188 |
18 Mar 15 |
nicklas |
Find all 'RNAQC' items associated with a given RNA. |
3188 |
18 Mar 15 |
nicklas |
30 |
*/ |
3188 |
18 Mar 15 |
nicklas |
31 |
public static List<RnaQc> findByRna(DbControl dc, Rna rna) |
3188 |
18 Mar 15 |
nicklas |
32 |
{ |
3188 |
18 Mar 15 |
nicklas |
// Fetch all child RNAQC items |
3188 |
18 Mar 15 |
nicklas |
34 |
ItemQuery<Extract> rnaqcQuery = rna.getExtract().getChildExtracts(); |
3188 |
18 Mar 15 |
nicklas |
35 |
Subtype.RNAQC.addFilter(dc, rnaqcQuery); |
3188 |
18 Mar 15 |
nicklas |
36 |
rnaqcQuery.include(Reggie.INCLUDE_IN_CURRENT_PROJECT); |
3188 |
18 Mar 15 |
nicklas |
37 |
rnaqcQuery.join(Hql.leftJoin(null, "bioWell", "bw", null, true)); |
3188 |
18 Mar 15 |
nicklas |
38 |
rnaqcQuery.join(Hql.leftJoin("bw", "bioPlate", "bp", null, true)); |
3188 |
18 Mar 15 |
nicklas |
39 |
return toRnaQc(rnaqcQuery.list(dc)); |
3188 |
18 Mar 15 |
nicklas |
40 |
} |
3188 |
18 Mar 15 |
nicklas |
41 |
|
3188 |
18 Mar 15 |
nicklas |
42 |
/** |
3188 |
18 Mar 15 |
nicklas |
Find the last RNAQC item in a list of RNAQC. The last is defined as the |
3188 |
18 Mar 15 |
nicklas |
one having the latest QcRunDate annotation on the bioplate the RNAQC is |
3188 |
18 Mar 15 |
nicklas |
located on, or the creation date if the RNAQC is not on a bioplate. |
3188 |
18 Mar 15 |
nicklas |
Only RNAQC items having either a CA_RQS or BA_RIN value are considered |
3188 |
18 Mar 15 |
nicklas |
since some RNAQC items may be extra NanoDrop measurements. |
3188 |
18 Mar 15 |
nicklas |
48 |
*/ |
3188 |
18 Mar 15 |
nicklas |
49 |
public static RnaQc findLast(DbControl dc, SnapshotManager manager, List<RnaQc> qcList) |
3188 |
18 Mar 15 |
nicklas |
50 |
{ |
3188 |
18 Mar 15 |
nicklas |
51 |
RnaQc lastQc = null; |
3188 |
18 Mar 15 |
nicklas |
52 |
Date lastQcDate = null; |
3188 |
18 Mar 15 |
nicklas |
53 |
|
3188 |
18 Mar 15 |
nicklas |
54 |
for (RnaQc qc : qcList) |
3188 |
18 Mar 15 |
nicklas |
55 |
{ |
3188 |
18 Mar 15 |
nicklas |
56 |
Extract qcExtract = qc.getExtract(); |
3188 |
18 Mar 15 |
nicklas |
57 |
Float rqs = (Float)Annotationtype.CA_RQS.getAnnotationValue(dc, manager, qcExtract); |
3188 |
18 Mar 15 |
nicklas |
58 |
Float rin = (Float)Annotationtype.BA_RIN.getAnnotationValue(dc, manager, qcExtract); |
3188 |
18 Mar 15 |
nicklas |
// Skip RNAQC items without any quality score since it may |
3188 |
18 Mar 15 |
nicklas |
// be a new NanoDrop measurement |
3188 |
18 Mar 15 |
nicklas |
61 |
if (rqs == null && rin == null) continue; |
3188 |
18 Mar 15 |
nicklas |
62 |
|
3188 |
18 Mar 15 |
nicklas |
// Use the current RNAQC if this is the first found or if the date is after |
3188 |
18 Mar 15 |
nicklas |
64 |
Date qcDate = qc.getQcRunDate(dc, manager); |
3188 |
18 Mar 15 |
nicklas |
65 |
if (lastQc == null || lastQcDate != null && qcDate != null && qcDate.after(lastQcDate)) |
3188 |
18 Mar 15 |
nicklas |
66 |
{ |
3188 |
18 Mar 15 |
nicklas |
67 |
lastQcDate = qcDate; |
3188 |
18 Mar 15 |
nicklas |
68 |
lastQc = qc; |
3188 |
18 Mar 15 |
nicklas |
69 |
} |
3188 |
18 Mar 15 |
nicklas |
70 |
} |
3188 |
18 Mar 15 |
nicklas |
71 |
return lastQc; |
3188 |
18 Mar 15 |
nicklas |
72 |
} |
3188 |
18 Mar 15 |
nicklas |
73 |
|
3188 |
18 Mar 15 |
nicklas |
74 |
|
3188 |
18 Mar 15 |
nicklas |
75 |
public static List<RnaQc> toRnaQc(Collection<Extract> extracts) |
3188 |
18 Mar 15 |
nicklas |
76 |
{ |
3188 |
18 Mar 15 |
nicklas |
77 |
List<RnaQc> rnaqc = new ArrayList<RnaQc>(extracts.size()); |
3188 |
18 Mar 15 |
nicklas |
78 |
for (Extract e : extracts) |
3188 |
18 Mar 15 |
nicklas |
79 |
{ |
3188 |
18 Mar 15 |
nicklas |
80 |
rnaqc.add(new RnaQc(e)); |
3188 |
18 Mar 15 |
nicklas |
81 |
} |
3188 |
18 Mar 15 |
nicklas |
82 |
return rnaqc; |
3188 |
18 Mar 15 |
nicklas |
83 |
} |
3188 |
18 Mar 15 |
nicklas |
84 |
|
4107 |
15 Sep 16 |
nicklas |
85 |
/** |
4107 |
15 Sep 16 |
nicklas |
Get a RNAQC extract when the id is known. |
4107 |
15 Sep 16 |
nicklas |
@since 4.7 |
4107 |
15 Sep 16 |
nicklas |
88 |
*/ |
4107 |
15 Sep 16 |
nicklas |
89 |
public static RnaQc getById(DbControl dc, int id) |
4107 |
15 Sep 16 |
nicklas |
90 |
{ |
4107 |
15 Sep 16 |
nicklas |
91 |
return new RnaQc(Extract.getById(dc, id)); |
4107 |
15 Sep 16 |
nicklas |
92 |
} |
4107 |
15 Sep 16 |
nicklas |
93 |
|
6207 |
12 Apr 21 |
nicklas |
94 |
public static RnaQc get(Extract extract) |
6207 |
12 Apr 21 |
nicklas |
95 |
{ |
6207 |
12 Apr 21 |
nicklas |
96 |
return new RnaQc(extract); |
6207 |
12 Apr 21 |
nicklas |
97 |
} |
6207 |
12 Apr 21 |
nicklas |
98 |
|
3188 |
18 Mar 15 |
nicklas |
99 |
RnaQc(Extract extract) |
3188 |
18 Mar 15 |
nicklas |
100 |
{ |
3188 |
18 Mar 15 |
nicklas |
101 |
super(extract); |
3188 |
18 Mar 15 |
nicklas |
102 |
|
3188 |
18 Mar 15 |
nicklas |
103 |
} |
3188 |
18 Mar 15 |
nicklas |
104 |
|
3188 |
18 Mar 15 |
nicklas |
105 |
/** |
3188 |
18 Mar 15 |
nicklas |
Get the real extract that represents this RNAQC in BASE. |
3188 |
18 Mar 15 |
nicklas |
107 |
*/ |
3188 |
18 Mar 15 |
nicklas |
108 |
public Extract getExtract() |
3188 |
18 Mar 15 |
nicklas |
109 |
{ |
3188 |
18 Mar 15 |
nicklas |
110 |
return getItem(); |
3188 |
18 Mar 15 |
nicklas |
111 |
} |
3188 |
18 Mar 15 |
nicklas |
112 |
|
3188 |
18 Mar 15 |
nicklas |
113 |
/** |
3188 |
18 Mar 15 |
nicklas |
Get the QcRunDate annotation from the bioplate this RNAQC item is located |
3188 |
18 Mar 15 |
nicklas |
on. If it is not on a bioplate, the creation date is returned (which can be null) |
3188 |
18 Mar 15 |
nicklas |
116 |
*/ |
3188 |
18 Mar 15 |
nicklas |
117 |
public Date getQcRunDate(DbControl dc, SnapshotManager manager) |
3188 |
18 Mar 15 |
nicklas |
118 |
{ |
3188 |
18 Mar 15 |
nicklas |
119 |
Extract qc = getItem(); |
3188 |
18 Mar 15 |
nicklas |
120 |
BioWell well = qc.getBioWell(); |
3188 |
18 Mar 15 |
nicklas |
121 |
Date qcDate = null; |
3188 |
18 Mar 15 |
nicklas |
// Try to get QC date from RNAQC reaction plate |
3188 |
18 Mar 15 |
nicklas |
123 |
if (well != null) |
3188 |
18 Mar 15 |
nicklas |
124 |
{ |
3188 |
18 Mar 15 |
nicklas |
125 |
BioPlate plate = well.getPlate(); |
3188 |
18 Mar 15 |
nicklas |
126 |
qcDate = (Date)Annotationtype.QC_RUN_DATE.getAnnotationValue(dc, manager, plate); |
3188 |
18 Mar 15 |
nicklas |
127 |
} |
3188 |
18 Mar 15 |
nicklas |
// If not found, get creation date from extract |
3188 |
18 Mar 15 |
nicklas |
129 |
if (qcDate == null) |
3188 |
18 Mar 15 |
nicklas |
130 |
{ |
3188 |
18 Mar 15 |
nicklas |
131 |
qcDate = qc.getCreationEvent().getEventDate(); |
3188 |
18 Mar 15 |
nicklas |
132 |
} |
3188 |
18 Mar 15 |
nicklas |
133 |
|
3188 |
18 Mar 15 |
nicklas |
134 |
return qcDate; |
3188 |
18 Mar 15 |
nicklas |
135 |
} |
3188 |
18 Mar 15 |
nicklas |
136 |
|
3937 |
16 May 16 |
nicklas |
137 |
/** |
3937 |
16 May 16 |
nicklas |
Get the RQS value if avilable, otherwise the RIN value. |
3937 |
16 May 16 |
nicklas |
@since 4.5 |
3937 |
16 May 16 |
nicklas |
140 |
*/ |
3937 |
16 May 16 |
nicklas |
141 |
public Float getRqsOrRin(DbControl dc, SnapshotManager manager) |
3937 |
16 May 16 |
nicklas |
142 |
{ |
3937 |
16 May 16 |
nicklas |
143 |
Extract qc = getItem(); |
3937 |
16 May 16 |
nicklas |
144 |
Float rqs = (Float)Annotationtype.CA_RQS.getAnnotationValue(dc, manager, qc); |
3937 |
16 May 16 |
nicklas |
145 |
if (rqs != null) return rqs; |
3937 |
16 May 16 |
nicklas |
146 |
|
3937 |
16 May 16 |
nicklas |
147 |
Float rin = (Float)Annotationtype.BA_RIN.getAnnotationValue(dc, manager, qc); |
3937 |
16 May 16 |
nicklas |
148 |
return rin; |
3937 |
16 May 16 |
nicklas |
149 |
} |
3937 |
16 May 16 |
nicklas |
150 |
|
3188 |
18 Mar 15 |
nicklas |
151 |
} |