3937 |
16 May 16 |
nicklas |
1 |
package net.sf.basedb.reggie.plugins.release; |
3937 |
16 May 16 |
nicklas |
2 |
|
3937 |
16 May 16 |
nicklas |
3 |
import java.util.Date; |
4469 |
26 Apr 17 |
nicklas |
4 |
import java.util.List; |
3937 |
16 May 16 |
nicklas |
5 |
|
4389 |
09 Mar 17 |
nicklas |
6 |
import org.json.simple.JSONArray; |
4371 |
02 Mar 17 |
nicklas |
7 |
import org.json.simple.JSONObject; |
4371 |
02 Mar 17 |
nicklas |
8 |
|
5170 |
03 Dec 18 |
nicklas |
9 |
import net.sf.basedb.core.BioMaterialEvent; |
3937 |
16 May 16 |
nicklas |
10 |
import net.sf.basedb.core.DbControl; |
3937 |
16 May 16 |
nicklas |
11 |
import net.sf.basedb.core.Extract; |
4389 |
09 Mar 17 |
nicklas |
12 |
import net.sf.basedb.core.Item; |
4465 |
25 Apr 17 |
nicklas |
13 |
import net.sf.basedb.core.Quantity; |
4389 |
09 Mar 17 |
nicklas |
14 |
import net.sf.basedb.core.Type; |
5170 |
03 Dec 18 |
nicklas |
15 |
import net.sf.basedb.core.Unit; |
4389 |
09 Mar 17 |
nicklas |
16 |
import net.sf.basedb.core.snapshot.SnapshotManager; |
3937 |
16 May 16 |
nicklas |
17 |
import net.sf.basedb.reggie.Reggie; |
3937 |
16 May 16 |
nicklas |
18 |
import net.sf.basedb.reggie.dao.Annotationtype; |
5100 |
15 Nov 18 |
nicklas |
19 |
import net.sf.basedb.reggie.dao.Lysate; |
5100 |
15 Nov 18 |
nicklas |
20 |
import net.sf.basedb.reggie.dao.Rna; |
3937 |
16 May 16 |
nicklas |
21 |
import net.sf.basedb.reggie.dao.RnaQc; |
4389 |
09 Mar 17 |
nicklas |
22 |
import net.sf.basedb.reggie.json.FilteredJSONArray; |
4389 |
09 Mar 17 |
nicklas |
23 |
import net.sf.basedb.util.filter.NotNullFilter; |
4465 |
25 Apr 17 |
nicklas |
24 |
import net.sf.basedb.util.units.UnitUtil; |
3937 |
16 May 16 |
nicklas |
25 |
|
3937 |
16 May 16 |
nicklas |
26 |
/** |
3937 |
16 May 16 |
nicklas |
Cohort writer implementation for the RNA data table. |
3937 |
16 May 16 |
nicklas |
@since 4.5 |
3937 |
16 May 16 |
nicklas |
29 |
*/ |
3937 |
16 May 16 |
nicklas |
30 |
public class RnaWriter |
3937 |
16 May 16 |
nicklas |
31 |
extends CohortWriter |
3937 |
16 May 16 |
nicklas |
32 |
{ |
3937 |
16 May 16 |
nicklas |
33 |
|
5090 |
14 Nov 18 |
nicklas |
34 |
public RnaWriter(DbControl dc, ReleaseWriterOptions options) |
3937 |
16 May 16 |
nicklas |
35 |
{ |
5090 |
14 Nov 18 |
nicklas |
36 |
super(dc, options); |
3937 |
16 May 16 |
nicklas |
37 |
} |
3937 |
16 May 16 |
nicklas |
38 |
|
4371 |
02 Mar 17 |
nicklas |
39 |
@Override |
5091 |
14 Nov 18 |
nicklas |
40 |
public JSONArray toJSONObjects(CohortItem item) |
4371 |
02 Mar 17 |
nicklas |
41 |
{ |
5100 |
15 Nov 18 |
nicklas |
42 |
List<Rna> rnaList = item.getRna(); |
5100 |
15 Nov 18 |
nicklas |
43 |
if (rnaList.size() == 0) return null; |
4371 |
02 Mar 17 |
nicklas |
44 |
|
5100 |
15 Nov 18 |
nicklas |
45 |
List<RnaQc> rnaQcList = item.getRnaQc(); |
5100 |
15 Nov 18 |
nicklas |
46 |
JSONArray json = new JSONArray(); |
5100 |
15 Nov 18 |
nicklas |
47 |
for (int i = 0; i < rnaList.size(); i++) |
4389 |
09 Mar 17 |
nicklas |
48 |
{ |
5100 |
15 Nov 18 |
nicklas |
49 |
Rna r = rnaList.get(i); |
5100 |
15 Nov 18 |
nicklas |
50 |
RnaQc qc = rnaQcList.get(i); |
5100 |
15 Nov 18 |
nicklas |
51 |
Extract rna = r.getItem(); |
5100 |
15 Nov 18 |
nicklas |
52 |
Lysate lys = r.getLysate(); |
5170 |
03 Dec 18 |
nicklas |
53 |
BioMaterialEvent creationEvent = rna.getCreationEvent(); |
5100 |
15 Nov 18 |
nicklas |
54 |
|
5100 |
15 Nov 18 |
nicklas |
55 |
DbControl dc = item.getDbControl(); |
5100 |
15 Nov 18 |
nicklas |
56 |
SnapshotManager manager = item.getSnapshotManager(); |
5100 |
15 Nov 18 |
nicklas |
57 |
|
5100 |
15 Nov 18 |
nicklas |
58 |
JSONObject jsonRna = new JSONObject(); |
5100 |
15 Nov 18 |
nicklas |
59 |
jsonRna.put("name", item.toReleaseId(rna.getName())); |
5100 |
15 Nov 18 |
nicklas |
60 |
jsonRna.put("type", rna.getType().name()); |
5100 |
15 Nov 18 |
nicklas |
61 |
jsonRna.put("subtype", getName(rna.getItemSubtype())); |
5100 |
15 Nov 18 |
nicklas |
62 |
jsonRna.put("parent", item.toReleaseId(lys.getName())); |
5100 |
15 Nov 18 |
nicklas |
63 |
|
5100 |
15 Nov 18 |
nicklas |
64 |
JSONArray jsonAnnotations = new FilteredJSONArray(new NotNullFilter<>(false)); |
5100 |
15 Nov 18 |
nicklas |
65 |
jsonRna.put("annotations", jsonAnnotations); |
5100 |
15 Nov 18 |
nicklas |
66 |
|
5100 |
15 Nov 18 |
nicklas |
67 |
String qiacubeDate = Reggie.CONVERTER_DATE_TO_STRING.convert((Date)item.getAnnotationValue(Annotationtype.QIACUBE_DATE, rna)); |
5100 |
15 Nov 18 |
nicklas |
68 |
Integer qiacubeRunNo = (Integer)item.getAnnotationValue(Annotationtype.QIACUBE_RUN_NO, rna); |
5100 |
15 Nov 18 |
nicklas |
69 |
qiacubeDate += qiacubeRunNo == null ? ":0" : ":"+qiacubeRunNo; |
5100 |
15 Nov 18 |
nicklas |
70 |
|
5100 |
15 Nov 18 |
nicklas |
71 |
jsonAnnotations.add(item.createBatchIndexAnnotationJSON("QiacubeBatchNo", qiacubeDate)); |
5170 |
03 Dec 18 |
nicklas |
72 |
jsonAnnotations.add(item.createAnnotationJSON("Protocol", getName(creationEvent.getProtocol()))); |
5170 |
03 Dec 18 |
nicklas |
73 |
jsonAnnotations.add(item.createAnnotationJSON("RNAOriginalQuantity", rna.getOriginalQuantity())); |
5170 |
03 Dec 18 |
nicklas |
74 |
jsonAnnotations.add(item.createAnnotationJSON("RNARemainingQuantity", rna.getRemainingQuantity())); |
5170 |
03 Dec 18 |
nicklas |
75 |
|
6220 |
20 Apr 21 |
nicklas |
76 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.QUBIT_CONC, rna, null)); |
5100 |
15 Nov 18 |
nicklas |
77 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.ND_CONC, rna, null)); |
5100 |
15 Nov 18 |
nicklas |
78 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.ND_260_BY_230, rna, null)); |
5100 |
15 Nov 18 |
nicklas |
79 |
jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.ND_260_BY_280, rna, null)); |
5100 |
15 Nov 18 |
nicklas |
80 |
if (qc != null) |
5100 |
15 Nov 18 |
nicklas |
81 |
{ |
5100 |
15 Nov 18 |
nicklas |
// It should always be not null but in case the filtering rules are changed... |
5100 |
15 Nov 18 |
nicklas |
83 |
jsonAnnotations.add(item.createAnnotationJSON("RNAQC", qc.getRqsOrRin(dc, manager))); |
5100 |
15 Nov 18 |
nicklas |
84 |
} |
5100 |
15 Nov 18 |
nicklas |
85 |
json.add(jsonRna); |
4389 |
09 Mar 17 |
nicklas |
86 |
} |
4389 |
09 Mar 17 |
nicklas |
87 |
|
5100 |
15 Nov 18 |
nicklas |
88 |
return json; |
4371 |
02 Mar 17 |
nicklas |
89 |
} |
4389 |
09 Mar 17 |
nicklas |
90 |
|
4389 |
09 Mar 17 |
nicklas |
91 |
@Override |
4469 |
26 Apr 17 |
nicklas |
92 |
public List<CohortTypeDef> getTypeDefsInJSON() |
4389 |
09 Mar 17 |
nicklas |
93 |
{ |
4448 |
07 Apr 17 |
nicklas |
94 |
DbControl dc = getDbControl(); |
4469 |
26 Apr 17 |
nicklas |
95 |
CohortTypeDefFactory rnaFactory = new CohortTypeDefFactory(dc, Item.EXTRACT, "RNA"); |
4465 |
25 Apr 17 |
nicklas |
96 |
|
5170 |
03 Dec 18 |
nicklas |
97 |
Unit µg = UnitUtil.getUnit(dc, Quantity.MASS, "µg"); |
5170 |
03 Dec 18 |
nicklas |
98 |
|
4465 |
25 Apr 17 |
nicklas |
// RNA annotation |
4469 |
26 Apr 17 |
nicklas |
100 |
rnaFactory.createAnnotationType("QiacubeBatchNo", Type.INT).setProjectSpecificValues(true); |
5170 |
03 Dec 18 |
nicklas |
101 |
rnaFactory.createAnnotationType("Protocol", Type.STRING); |
5170 |
03 Dec 18 |
nicklas |
102 |
rnaFactory.createAnnotationType("RNAOriginalQuantity", Type.FLOAT).setUnit(µg); |
5170 |
03 Dec 18 |
nicklas |
103 |
rnaFactory.createAnnotationType("RNARemainingQuantity", Type.FLOAT).setUnit(µg).setProjectSpecificValues(true); |
6220 |
20 Apr 21 |
nicklas |
104 |
rnaFactory.createAnnotationType(Annotationtype.QUBIT_CONC).setUnit(UnitUtil.getUnit(dc, Quantity.DENSITY, "ng/µl")); |
4470 |
26 Apr 17 |
nicklas |
105 |
rnaFactory.createAnnotationType(Annotationtype.ND_CONC).setUnit(UnitUtil.getUnit(dc, Quantity.DENSITY, "ng/µl")); |
4469 |
26 Apr 17 |
nicklas |
106 |
rnaFactory.createAnnotationType(Annotationtype.ND_260_BY_230); |
4469 |
26 Apr 17 |
nicklas |
107 |
rnaFactory.createAnnotationType(Annotationtype.ND_260_BY_280); |
4469 |
26 Apr 17 |
nicklas |
108 |
rnaFactory.createAnnotationType("RNAQC", Type.FLOAT).setProjectSpecificValues(true); |
4468 |
26 Apr 17 |
nicklas |
109 |
|
4468 |
26 Apr 17 |
nicklas |
110 |
return rnaFactory.allCreated(); |
4389 |
09 Mar 17 |
nicklas |
111 |
} |
3937 |
16 May 16 |
nicklas |
112 |
|
3937 |
16 May 16 |
nicklas |
113 |
} |