extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/release/DnaWriter.java

Code
Comments
Other
Rev Date Author Line
5131 21 Nov 18 nicklas 1 package net.sf.basedb.reggie.plugins.release;
5131 21 Nov 18 nicklas 2
5131 21 Nov 18 nicklas 3 import java.util.Date;
5131 21 Nov 18 nicklas 4 import java.util.List;
5131 21 Nov 18 nicklas 5
5131 21 Nov 18 nicklas 6 import org.json.simple.JSONArray;
5131 21 Nov 18 nicklas 7 import org.json.simple.JSONObject;
5131 21 Nov 18 nicklas 8
5170 03 Dec 18 nicklas 9 import net.sf.basedb.core.BioMaterialEvent;
5131 21 Nov 18 nicklas 10 import net.sf.basedb.core.DbControl;
5131 21 Nov 18 nicklas 11 import net.sf.basedb.core.Extract;
5131 21 Nov 18 nicklas 12 import net.sf.basedb.core.Item;
5131 21 Nov 18 nicklas 13 import net.sf.basedb.core.Quantity;
5131 21 Nov 18 nicklas 14 import net.sf.basedb.core.Type;
5170 03 Dec 18 nicklas 15 import net.sf.basedb.core.Unit;
5131 21 Nov 18 nicklas 16 import net.sf.basedb.core.snapshot.SnapshotManager;
5131 21 Nov 18 nicklas 17 import net.sf.basedb.reggie.Reggie;
5131 21 Nov 18 nicklas 18 import net.sf.basedb.reggie.dao.Annotationtype;
5132 21 Nov 18 nicklas 19 import net.sf.basedb.reggie.dao.Dna;
5132 21 Nov 18 nicklas 20 import net.sf.basedb.reggie.dao.Lysate;
5131 21 Nov 18 nicklas 21 import net.sf.basedb.reggie.json.FilteredJSONArray;
5131 21 Nov 18 nicklas 22 import net.sf.basedb.util.filter.NotNullFilter;
5131 21 Nov 18 nicklas 23 import net.sf.basedb.util.units.UnitUtil;
5131 21 Nov 18 nicklas 24
5131 21 Nov 18 nicklas 25 /**
5131 21 Nov 18 nicklas 26   Cohort writer implementation for the DNA data table.
5131 21 Nov 18 nicklas 27   @since 4.21
5131 21 Nov 18 nicklas 28 */
5131 21 Nov 18 nicklas 29 public class DnaWriter 
5131 21 Nov 18 nicklas 30   extends CohortWriter 
5131 21 Nov 18 nicklas 31 {
5131 21 Nov 18 nicklas 32   
5131 21 Nov 18 nicklas 33   public DnaWriter(DbControl dc, ReleaseWriterOptions options)
5131 21 Nov 18 nicklas 34   {
5131 21 Nov 18 nicklas 35     super(dc, options);
5131 21 Nov 18 nicklas 36   }
5131 21 Nov 18 nicklas 37   
5131 21 Nov 18 nicklas 38   @Override
5131 21 Nov 18 nicklas 39   public JSONArray toJSONObjects(CohortItem item)
5131 21 Nov 18 nicklas 40   {
5132 21 Nov 18 nicklas 41     List<Dna> dnaList = item.getDna();
5131 21 Nov 18 nicklas 42     if (dnaList.size() == 0) return null;
5131 21 Nov 18 nicklas 43     
5131 21 Nov 18 nicklas 44     JSONArray json = new JSONArray();
5132 21 Nov 18 nicklas 45     for (Dna d : dnaList)
5131 21 Nov 18 nicklas 46     {
5132 21 Nov 18 nicklas 47       Extract dna = d.getExtract();
5132 21 Nov 18 nicklas 48       Lysate lys = d.getLysate();
5170 03 Dec 18 nicklas 49       BioMaterialEvent creationEvent = dna.getCreationEvent();
5131 21 Nov 18 nicklas 50       
5131 21 Nov 18 nicklas 51       DbControl dc = item.getDbControl();
5131 21 Nov 18 nicklas 52       SnapshotManager manager = item.getSnapshotManager();
5131 21 Nov 18 nicklas 53       
5131 21 Nov 18 nicklas 54       JSONObject jsonDna = new JSONObject();
5131 21 Nov 18 nicklas 55       jsonDna.put("name", item.toReleaseId(dna.getName()));
5131 21 Nov 18 nicklas 56       jsonDna.put("type", dna.getType().name());
5131 21 Nov 18 nicklas 57       jsonDna.put("subtype", getName(dna.getItemSubtype()));
5131 21 Nov 18 nicklas 58       jsonDna.put("parent", item.toReleaseId(lys.getName()));
5131 21 Nov 18 nicklas 59       
5131 21 Nov 18 nicklas 60       JSONArray jsonAnnotations = new FilteredJSONArray(new NotNullFilter<>(false));
5131 21 Nov 18 nicklas 61       jsonDna.put("annotations", jsonAnnotations);
5131 21 Nov 18 nicklas 62       
5131 21 Nov 18 nicklas 63       String qiacubeDate = Reggie.CONVERTER_DATE_TO_STRING.convert((Date)item.getAnnotationValue(Annotationtype.QIACUBE_DATE, dna));
5131 21 Nov 18 nicklas 64       Integer qiacubeRunNo = (Integer)item.getAnnotationValue(Annotationtype.QIACUBE_RUN_NO, dna);
5131 21 Nov 18 nicklas 65       qiacubeDate += qiacubeRunNo == null ? ":0" : ":"+qiacubeRunNo;
5131 21 Nov 18 nicklas 66   
5131 21 Nov 18 nicklas 67       jsonAnnotations.add(item.createBatchIndexAnnotationJSON("QiacubeBatchNo", qiacubeDate));
5170 03 Dec 18 nicklas 68       jsonAnnotations.add(item.createAnnotationJSON("Protocol", getName(creationEvent.getProtocol())));
5170 03 Dec 18 nicklas 69       jsonAnnotations.add(item.createAnnotationJSON("DNAOriginalQuantity", dna.getOriginalQuantity()));
5170 03 Dec 18 nicklas 70       jsonAnnotations.add(item.createAnnotationJSON("DNARemainingQuantity", dna.getRemainingQuantity()));
6220 20 Apr 21 nicklas 71       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.QUBIT_CONC, dna, null));
5131 21 Nov 18 nicklas 72       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.ND_CONC, dna, null));
5131 21 Nov 18 nicklas 73       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.ND_260_BY_230, dna, null));
5131 21 Nov 18 nicklas 74       jsonAnnotations.add(item.getAnnotationJSON(Annotationtype.ND_260_BY_280, dna, null));
5131 21 Nov 18 nicklas 75
5131 21 Nov 18 nicklas 76       json.add(jsonDna);
5131 21 Nov 18 nicklas 77     }
5131 21 Nov 18 nicklas 78     
5131 21 Nov 18 nicklas 79     return json;
5131 21 Nov 18 nicklas 80   }
5131 21 Nov 18 nicklas 81   
5131 21 Nov 18 nicklas 82   @Override
5131 21 Nov 18 nicklas 83   public List<CohortTypeDef> getTypeDefsInJSON()
5131 21 Nov 18 nicklas 84   {
5131 21 Nov 18 nicklas 85     DbControl dc = getDbControl();
5131 21 Nov 18 nicklas 86     CohortTypeDefFactory dnaFactory = new CohortTypeDefFactory(dc, Item.EXTRACT, "DNA");
5131 21 Nov 18 nicklas 87
5170 03 Dec 18 nicklas 88     Unit µg = UnitUtil.getUnit(dc, Quantity.MASS, "µg");
5170 03 Dec 18 nicklas 89
5131 21 Nov 18 nicklas 90     // DNA annotation
5131 21 Nov 18 nicklas 91     dnaFactory.createAnnotationType("QiacubeBatchNo", Type.INT).setProjectSpecificValues(true);
5170 03 Dec 18 nicklas 92     dnaFactory.createAnnotationType("Protocol", Type.STRING);
5170 03 Dec 18 nicklas 93     dnaFactory.createAnnotationType("DNAOriginalQuantity", Type.FLOAT).setUnit(µg);
5170 03 Dec 18 nicklas 94     dnaFactory.createAnnotationType("DNARemainingQuantity", Type.FLOAT).setUnit(µg).setProjectSpecificValues(true);
6220 20 Apr 21 nicklas 95     dnaFactory.createAnnotationType(Annotationtype.QUBIT_CONC).setUnit(UnitUtil.getUnit(dc, Quantity.DENSITY, "ng/µl"));
5131 21 Nov 18 nicklas 96     dnaFactory.createAnnotationType(Annotationtype.ND_CONC).setUnit(UnitUtil.getUnit(dc, Quantity.DENSITY, "ng/µl"));
5131 21 Nov 18 nicklas 97     dnaFactory.createAnnotationType(Annotationtype.ND_260_BY_230);
5131 21 Nov 18 nicklas 98     dnaFactory.createAnnotationType(Annotationtype.ND_260_BY_280);
5131 21 Nov 18 nicklas 99     
5131 21 Nov 18 nicklas 100     return dnaFactory.allCreated();
5131 21 Nov 18 nicklas 101   }
5131 21 Nov 18 nicklas 102
5131 21 Nov 18 nicklas 103 }