Changeset 6205


Ignore:
Timestamp:
Apr 12, 2021, 11:09:03 AM (2 years ago)
Author:
Nicklas Nordborg
Message:

References #1295: Registration of specimen handled by external lab

Moved validation of already existing items that can be referenced (eg. Barcode, Pool, Libplate, Flowcell, etc.) to the initial parsing of the JSON file so that things that will cause the import to fail are displayed immediately.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/batch/import-external-specimen.js

    r6199 r6205  
    101101      if (jsonFile && jsonFile.errors)
    102102      {
    103         html += '<div class="messagecontainer error">'+Strings.encodeTags(jsonFile.errors.join('\n'))+'</div>';
     103        html += '<div class="messagecontainer error"><ol>';
     104        for (var errNo = 0; errNo < jsonFile.errors.length; errNo++)
     105        {
     106          html += '<li>'+Strings.encodeTags(jsonFile.errors[errNo]);
     107        }
     108        html += '</ol><div>';
    104109      }
    105110      else if (jsonFile && jsonFile.warnings)
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/FutureSpecimenImporter.java

    r6203 r6205  
    33import java.text.DateFormat;
    44import java.text.SimpleDateFormat;
    5 import java.util.Date;
    6 import java.util.HashMap;
    7 import java.util.List;
    8 import java.util.Map;
    95import org.json.simple.JSONObject;
    106
     
    1511import net.sf.basedb.core.DerivedBioAssay;
    1612import net.sf.basedb.core.Extract;
    17 import net.sf.basedb.core.ItemQuery;
    1813import net.sf.basedb.core.PhysicalBioAssay;
    1914import net.sf.basedb.core.Sample;
    2015import net.sf.basedb.core.data.PlateCoordinate;
    21 import net.sf.basedb.core.query.Annotations;
    22 import net.sf.basedb.core.query.Expressions;
    23 import net.sf.basedb.core.query.Hql;
    24 import net.sf.basedb.core.query.Restrictions;
    25 import net.sf.basedb.reggie.Reggie;
    2616import net.sf.basedb.reggie.dao.Annotationtype;
    2717import net.sf.basedb.reggie.dao.BioplateType;
     
    4636import net.sf.basedb.reggie.plugins.cmd.PoolInfo;
    4737import net.sf.basedb.reggie.plugins.cmd.SequencingRunInfo;
    48 import net.sf.basedb.util.Coordinate;
    4938import net.sf.basedb.util.MD5;
    5039
     
    6857  private JsonFile currentFile;
    6958 
    70   private Map<String, Extract> poolCache;
    71   private Map<String, PhysicalBioAssay> flowCellCache;
    72   private Map<String, DerivedBioAssay> seqRunCache;
    73   private Map<String, DerivedBioAssay> demuxCache;
    74   private Map<String, BioPlate> libPlateCache;
    7559 
    7660  public FutureSpecimenImporter()
    77   {
    78     this.poolCache = new HashMap<>();
    79     this.flowCellCache = new HashMap<>();
    80     this.seqRunCache = new HashMap<>();
    81     this.demuxCache = new HashMap<>();
    82     this.libPlateCache = new HashMap<>();
    83   }
     61  {}
    8462
    8563
     
    208186    lib.setItemSubtype(Subtype.LIBRARY.get(dc));
    209187    lib.setName(rna.getNextLibOrMRnaName(dc, Subtype.LIBRARY));
    210     Annotationtype.PIPELINE.setAnnotationValue(dc, lib, Pipeline.RNA_SEQ.getName());
     188    Pipeline.RNA_SEQ.setAnnotation(dc, lib);
    211189    BioMaterialEvent creationEvent = lib.getCreationEvent();
    212190    creationEvent.setSource(rna.getItem());
    213191
    214192    // Library annotations
    215     Date libDate = info.libDate;
    216     creationEvent.setEventDate(libDate);
    217     creationEvent.setProtocol(null);  // TODO
     193    if (info.barcode != null) addDebugMessage("Found: " + info.barcode.getName());
     194    lib.setTag(info.barcode);
     195    creationEvent.setEventDate(info.libDate);
     196    if (info.protocol != null) addDebugMessage("Found: " + info.protocol.getName());
     197    creationEvent.setProtocol(info.protocol);
    218198    creationEvent.setHardware(null);
    219199   
     
    221201    Annotationtype.LIBRARY_SIZE_EST.setAnnotationValue(dc, lib, info.libSize);
    222202    Annotationtype.LIBRARY_MOLARITY_EST.setAnnotationValue(dc, lib, info.libMolarity);
    223    
    224203    Annotationtype.EXTERNAL_OPERATOR.setAnnotationValue(dc, lib, info.operator);
    225    
    226204    dc.saveItem(lib);
    227205   
     
    233211      if (pos != null)
    234212      {
    235         String coordinate = Coordinate.numericToAlpha(pos.getRow()+1)+(pos.getColumn()+1);
    236213        BioWell well = libPlate.getBioWell(pos);
    237         if (well == null)
    238         {
    239           addErrorMessage("Well not found: "+libPlate.getName()+"["+ coordinate+"; ref="+info.plateId+"]");
    240         }
    241         else if (!well.isEmpty())
    242         {
    243           addErrorMessage("Well is not empty: "+libPlate.getName()+"["+ coordinate+"; ref="+info.plateId+"]");
    244         }
    245         else
    246         {
    247           lib.setBioWell(well);
    248           addDebugMessage("Using well: "+libPlate.getName()+"["+ coordinate+"; ref="+info.plateId+"]");
    249         }
     214        lib.setBioWell(well);
     215        addDebugMessage("Using well: "+libPlate.getName()+"["+ well.getCoordinate()+"; ref="+info.plateId+"]");
    250216      }
    251217    }
     
    260226    if (plateId == null) return null;
    261227   
    262     BioPlate plate = libPlateCache.get(plateId);
    263     if (plate == null)
    264     {
    265       ItemQuery<BioPlate> query = BioPlate.getQuery();
    266       query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    267       BioplateType.EXTERNAL_LIBRARY.addFilter(dc, query, false);
    268       query.join(Annotations.innerJoin(null, Annotationtype.EXTERNAL_REF.load(dc), "eref"));
    269       query.restrict(Restrictions.eq(Hql.alias("eref"), Expressions.string(plateId)));
    270       List<BioPlate> list = query.list(dc);
    271       if (list.size() > 1)
    272       {
    273         addErrorMessage("Found "+list.size()+" library plates with ExternalRef="+plateId);
    274         return null;
    275       }
    276      
    277       if (list.size() == 1)
    278       {
    279         plate = list.get(0);
    280         addDebugMessage("Found: "+plate.getName()+"[ref="+plateId+"]");
    281       }
    282       else
    283       {
    284         BioplateType plateType = BioplateType.EXTERNAL_LIBRARY;
    285         plate = BioPlate.getNew(dc, plateType.getPlateGeometry(dc), plateType.get(dc));
    286         plate.setName(plateType.getNextPlateName(dc, true));
    287         Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, plate, plateId);
    288         plate.setEventDate(info.libDate);
    289 
    290         Annotationtype.EXTERNAL_OPERATOR.setAnnotationValue(dc, plate, info.operator);
    291         Annotationtype.PLATE_PROCESS_RESULT.setAnnotationValue(dc, plate, ReactionPlate.PROCESS_SUCCESSFUL);
    292         // TODO -- more libplate annotations?
    293        
    294         dc.saveItem(plate);
    295         addDebugMessage("Created: "+plate.getName()+"[ref="+plateId+"]");
    296       }
    297       libPlateCache.put(plateId, plate);
    298     }
    299     else
    300     {
     228    BioPlate plate = info.libPlate;
     229    if (plate != null)
     230    {
     231     
    301232      addDebugMessage("Found: "+plate.getName()+"[ref="+plateId+"]");
    302233    }
     234    else
     235    {
     236      BioplateType plateType = BioplateType.EXTERNAL_LIBRARY;
     237      plate = BioPlate.getNew(dc, plateType.getPlateGeometry(dc), plateType.get(dc));
     238      plate.setName(plateType.getNextPlateName(dc, true));
     239      Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, plate, plateId);
     240      plate.setEventDate(info.libDate);
     241
     242      Annotationtype.EXTERNAL_OPERATOR.setAnnotationValue(dc, plate, info.operator);
     243      Annotationtype.PLATE_PROCESS_RESULT.setAnnotationValue(dc, plate, ReactionPlate.PROCESS_SUCCESSFUL);
     244      // TODO -- more libplate annotations?
     245     
     246      dc.saveItem(plate);
     247      addDebugMessage("Created: "+plate.getName()+"[ref="+plateId+"]");
     248    }
    303249    return plate;
    304   }
    305  
     250  }
    306251 
    307252  private PooledLibrary getOrCreatePool(DbControl dc, Library lib, PoolInfo info)
     
    310255    if (poolId == null) return null;
    311256
    312     Extract pool = poolCache.get(poolId);
    313     if (pool == null)
    314     {
    315       ItemQuery<Extract> query = Extract.getQuery();
    316       query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    317       Subtype.POOLED_LIBRARY.addFilter(dc, query);
    318       query.join(Annotations.innerJoin(null, Annotationtype.EXTERNAL_REF.load(dc), "eref"));
    319       query.restrict(Restrictions.eq(Hql.alias("eref"), Expressions.string(poolId)));
    320       List<Extract> list = query.list(dc);
    321       if (list.size() > 1)
    322       {
    323         addErrorMessage("Found "+list.size()+" pools with ExternalRef="+poolId);
    324         return null;
    325       }
    326      
    327       if (list.size() == 1)
    328       {
    329         pool = list.get(0);
    330         addDebugMessage("Found: "+pool.getName()+"[ref="+poolId+"]");
    331       }
    332       else
    333       {
    334        
    335         pool = Extract.getNew(dc);
    336         pool.setItemSubtype(Subtype.POOLED_LIBRARY.get(dc));
    337         pool.setName(PooledLibrary.getNextNames(dc, 1).get(0));
    338         Pipeline.RNA_SEQ.setAnnotation(dc, pool);
    339         Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, pool, poolId);
    340         Annotationtype.POOL_DATE.setAnnotationValue(dc, pool, info.poolDate);
    341         Annotationtype.POOL_OPERATOR.setAnnotationValue(dc, pool, info.operator);
    342        
    343         BioMaterialEvent poolEvent = pool.getCreationEvent();
    344         poolEvent.setEventDate(info.poolDate);
    345         poolEvent.setProtocol(null); // To avoid that a 'project default' is used
    346         poolEvent.setHardware(null);
    347        
    348         dc.saveItem(pool);
    349         addDebugMessage("Created: "+pool.getName()+"[ref="+poolId+"]");
    350       }
    351       poolCache.put(poolId, pool);
    352     }
    353     else
     257    Extract pool = info.pool;
     258    if (pool != null)
    354259    {
    355260      addDebugMessage("Found: "+pool.getName()+"[ref="+poolId+"]");
    356261    }
    357        
     262    else
     263    {
     264      pool = Extract.getNew(dc);
     265      pool.setItemSubtype(Subtype.POOLED_LIBRARY.get(dc));
     266      pool.setName(PooledLibrary.getNextNames(dc, 1).get(0));
     267      Pipeline.RNA_SEQ.setAnnotation(dc, pool);
     268      Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, pool, poolId);
     269      Annotationtype.POOL_DATE.setAnnotationValue(dc, pool, info.poolDate);
     270      Annotationtype.POOL_OPERATOR.setAnnotationValue(dc, pool, info.operator);
     271     
     272      BioMaterialEvent poolEvent = pool.getCreationEvent();
     273      poolEvent.setEventDate(info.poolDate);
     274      poolEvent.setProtocol(null); // To avoid that a 'project default' is used
     275      poolEvent.setHardware(null);
     276     
     277      dc.saveItem(pool);
     278      addDebugMessage("Created: "+pool.getName()+"[ref="+poolId+"]");
     279    }
     280   
    358281    pool.getCreationEvent().addSource(lib.getItem());
    359282    return PooledLibrary.get(pool);
     
    366289    if (flowCellId == null) return null;
    367290
    368     PhysicalBioAssay flowCell = flowCellCache.get(flowCellId);
    369     if (flowCell == null)
    370     {
    371       ItemQuery<PhysicalBioAssay> query = PhysicalBioAssay.getQuery();
    372       query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    373       Subtype.FLOW_CELL.addFilter(dc, query);
    374       query.join(Annotations.innerJoin(null, Annotationtype.FLOWCELL_ID.load(dc), "ref"));
    375       query.restrict(Restrictions.eq(Hql.alias("ref"), Expressions.string(flowCellId)));
    376       List<PhysicalBioAssay> list = query.list(dc);
    377       if (list.size() > 1)
     291    PhysicalBioAssay flowCell = flowCellInfo.flowCell;
     292    if (flowCell != null)
     293    {
     294      addDebugMessage("Found: "+flowCell.getName()+"[ref="+flowCellId+"]");
     295    }
     296    else
     297    {     
     298      flowCell = PhysicalBioAssay.getNew(dc);
     299      flowCell.setItemSubtype(Subtype.FLOW_CELL.get(dc));
     300      flowCell.setName(FlowCell.getNextNames(dc, 1).get(0));
     301      Pipeline.RNA_SEQ.setAnnotation(dc, flowCell);
     302      flowCell.setSize(flowCellInfo.size);
     303      Annotationtype.FLOWCELL_ID.setAnnotationValue(dc, flowCell, flowCellId);
     304      Annotationtype.SEQUENCING_CYCLES.setAnnotationValue(dc, flowCell, flowCellInfo.sequencingCycles);
     305      Annotationtype.FLOWCELL_TYPE.setAnnotationValue(dc, flowCell, seqRunInfo.sequencer.flowCellType);
     306      Annotationtype.CLUSTER_OPERATOR.setAnnotationValue(dc, flowCell, flowCellInfo.operator);
     307      Annotationtype.PLATE_PROCESS_RESULT.setAnnotationValue(dc, flowCell, ReactionPlate.PROCESS_SUCCESSFUL);
     308      dc.saveItem(flowCell);
     309     
     310      BioMaterialEvent createEvent = flowCell.getCreationEvent();
     311      createEvent.setProtocol(null); // To avoid that a 'project default' is used
     312      createEvent.setHardware(seqRunInfo.sequencer.sequencer);
     313     
     314      // Link with pool
     315      for (int laneNo = 1; laneNo <= flowCell.getSize(); laneNo++)
    378316      {
    379         addErrorMessage("Found "+list.size()+" flow cells with FlowCellID="+flowCellId);
    380         return null;
     317        Extract poolA = Extract.getNew(dc);
     318        poolA.setItemSubtype(Subtype.POOLED_LIBRARY_ALIQUOT.get(dc));
     319        poolA.setName(pool.getNextAliquotName(dc));
     320        poolA.getCreationEvent().setSource(pool.getItem());
     321        createEvent.addSource(poolA).setPosition(laneNo);
     322        dc.saveItem(poolA);
     323        addDebugMessage("Created: "+ poolA.getName());
    381324      }
    382       else if (list.size() == 1)
    383       {
    384         flowCell = list.get(0);
    385         addDebugMessage("Found: "+flowCell.getName()+"[ref="+flowCellId+"]");
    386         // TODO -- it should be linked to pool already -- verify??
    387       }
    388       else
    389       {     
    390         flowCell = PhysicalBioAssay.getNew(dc);
    391         flowCell.setItemSubtype(Subtype.FLOW_CELL.get(dc));
    392         flowCell.setName(FlowCell.getNextNames(dc, 1).get(0));
    393         Pipeline.RNA_SEQ.setAnnotation(dc, flowCell);
    394         flowCell.setSize(flowCellInfo.size);
    395         Annotationtype.FLOWCELL_ID.setAnnotationValue(dc, flowCell, flowCellId);
    396         Annotationtype.SEQUENCING_CYCLES.setAnnotationValue(dc, flowCell, flowCellInfo.sequencingCycles);
    397         Annotationtype.FLOWCELL_TYPE.setAnnotationValue(dc, flowCell, seqRunInfo.sequencer.flowCellType);
    398         Annotationtype.CLUSTER_OPERATOR.setAnnotationValue(dc, flowCell, flowCellInfo.operator);
    399         Annotationtype.PLATE_PROCESS_RESULT.setAnnotationValue(dc, flowCell, ReactionPlate.PROCESS_SUCCESSFUL);
    400         dc.saveItem(flowCell);
    401        
    402         BioMaterialEvent createEvent = flowCell.getCreationEvent();
    403         createEvent.setProtocol(null); // To avoid that a 'project default' is used
    404         createEvent.setHardware(seqRunInfo.sequencer.sequencer);
    405        
    406         // Link with pool
    407         for (int laneNo = 1; laneNo <= flowCell.getSize(); laneNo++)
    408         {
    409           Extract poolA = Extract.getNew(dc);
    410           poolA.setItemSubtype(Subtype.POOLED_LIBRARY_ALIQUOT.get(dc));
    411           poolA.setName(pool.getNextAliquotName(dc));
    412           poolA.getCreationEvent().setSource(pool.getItem());
    413           createEvent.addSource(poolA).setPosition(laneNo);
    414           dc.saveItem(poolA);
    415           addDebugMessage("Created: "+ poolA.getName());
    416         }
    417        
    418         addDebugMessage("Created: "+flowCell.getName()+"[ref="+flowCellId+"]");
    419       }
    420       flowCellCache.put(flowCellId, flowCell);
    421     }
    422     else
    423     {
    424       addDebugMessage("Found: "+flowCell.getName()+"[ref="+flowCellId+"]");
     325     
     326      addDebugMessage("Created: "+flowCell.getName()+"[ref="+flowCellId+"]");
    425327    }
    426328       
     
    433335    if (flowCellId == null) return null;
    434336
    435     DerivedBioAssay seqRun = seqRunCache.get(flowCellId);
    436     if (seqRun == null)
    437     {
    438       if (flowCell.getItem().isInDatabase())
    439       {
    440         ItemQuery<DerivedBioAssay> query = flowCell.getItem().getRootDerivedBioAssays();
    441         query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    442         Subtype.SEQUENCING_RUN.addFilter(dc, query);
    443         List<DerivedBioAssay> list = query.list(dc);
    444         if (list.size() > 1)
    445         {
    446           addErrorMessage("Found "+list.size()+" sequencing runs for FlowCellID="+flowCellId);
    447           return null;
    448         }
    449         else if (list.size() == 1)
    450         {
    451           seqRun = list.get(0);
    452           addDebugMessage("Found: "+seqRun.getName()+"[ref="+flowCellId+"]");
    453         }
    454       }
    455       if (seqRun == null)
    456       {
    457         seqRun = DerivedBioAssay.getNew(dc, flowCell.getItem(), null);
    458         seqRun.setItemSubtype(Subtype.SEQUENCING_RUN.get(dc));
    459         seqRun.setName(SequencingRun.getNextName(dc));
    460         Pipeline.RNA_SEQ.setAnnotation(dc, seqRun);
    461         seqRun.setHardware(seqRunInfo.sequencer.sequencer);
    462         seqRun.setSoftware(null);
    463         seqRun.setProtocol(null);
    464         Annotationtype.HISEQ_POSITION.setAnnotationValue(dc, seqRun, seqRunInfo.position);
    465         Annotationtype.SEQUENCING_RUN_NUMBER.setAnnotationValue(dc, seqRun, seqRunInfo.runNumber);
    466         Annotationtype.SEQUENCING_START.setAnnotationValue(dc, seqRun, seqRunInfo.startDate);
    467         Annotationtype.SEQUENCING_END.setAnnotationValue(dc, seqRun, seqRunInfo.endDate);
    468         Annotationtype.SEQUENCING_OPERATOR.setAnnotationValue(dc, seqRun, seqRunInfo.operator);
    469         Annotationtype.SEQUENCING_CYCLES.setAnnotationValue(dc, seqRun, flowCellInfo.sequencingCycles);
    470         Annotationtype.SEQUENCING_CONFIRMED.setAnnotationValue(dc, seqRun, true);
    471         Annotationtype.SEQUENCING_RESULT.setAnnotationValue(dc, seqRun, SequencingRun.SEQUENCING_SUCCESSFUL);
    472        
    473         DateFormat df = new SimpleDateFormat("yyyy/yyMMdd");
    474         String dataFilesFolder = df.format(seqRunInfo.startDate)+
    475           "_"+seqRunInfo.sequencer.serialNo+
    476           "_"+MD5.leftPad(Integer.toString(seqRunInfo.runNumber), '0', 4)+
    477           "_"+seqRunInfo.position+flowCellInfo.flowCellId;
    478         addDebugMessage(dataFilesFolder);
    479         Annotationtype.DATA_FILES_FOLDER.setAnnotationValue(dc, seqRun, dataFilesFolder);
    480         dc.saveItem(seqRun);
    481        
    482         addDebugMessage("Created: "+ seqRun.getName());
    483       }
    484       seqRunCache.put(flowCellId, seqRun);
    485      
     337    DerivedBioAssay seqRun = seqRunInfo.sequencingRun;
     338    if (seqRun != null)
     339    {
     340      addDebugMessage("Found: "+seqRun.getName()+"[ref="+flowCellId+"]");
     341    }
     342    else
     343    {
     344      seqRun = DerivedBioAssay.getNew(dc, flowCell.getItem(), null);
     345      seqRun.setItemSubtype(Subtype.SEQUENCING_RUN.get(dc));
     346      seqRun.setName(SequencingRun.getNextName(dc));
     347      Pipeline.RNA_SEQ.setAnnotation(dc, seqRun);
     348      seqRun.setHardware(seqRunInfo.sequencer.sequencer);
     349      seqRun.setSoftware(null);
     350      seqRun.setProtocol(null);
     351      Annotationtype.HISEQ_POSITION.setAnnotationValue(dc, seqRun, seqRunInfo.position);
     352      Annotationtype.SEQUENCING_RUN_NUMBER.setAnnotationValue(dc, seqRun, seqRunInfo.runNumber);
     353      Annotationtype.SEQUENCING_START.setAnnotationValue(dc, seqRun, seqRunInfo.startDate);
     354      Annotationtype.SEQUENCING_END.setAnnotationValue(dc, seqRun, seqRunInfo.endDate);
     355      Annotationtype.SEQUENCING_OPERATOR.setAnnotationValue(dc, seqRun, seqRunInfo.operator);
     356      Annotationtype.SEQUENCING_CYCLES.setAnnotationValue(dc, seqRun, flowCellInfo.sequencingCycles);
     357      Annotationtype.SEQUENCING_CONFIRMED.setAnnotationValue(dc, seqRun, true);
     358      Annotationtype.SEQUENCING_RESULT.setAnnotationValue(dc, seqRun, SequencingRun.SEQUENCING_SUCCESSFUL);
     359     
     360      DateFormat df = new SimpleDateFormat("yyyy/yyMMdd");
     361      String dataFilesFolder = df.format(seqRunInfo.startDate)+
     362        "_"+seqRunInfo.sequencer.serialNo+
     363        "_"+MD5.leftPad(Integer.toString(seqRunInfo.runNumber), '0', 4)+
     364        "_"+seqRunInfo.position+flowCellInfo.flowCellId;
     365      addDebugMessage(dataFilesFolder);
     366      Annotationtype.DATA_FILES_FOLDER.setAnnotationValue(dc, seqRun, dataFilesFolder);
     367      dc.saveItem(seqRun);
     368     
     369      addDebugMessage("Created: "+ seqRun.getName());
    486370    }
    487371    return SequencingRun.get(seqRun);
     
    494378    if (flowCellId == null) return null;
    495379
    496     DerivedBioAssay demux = demuxCache.get(flowCellId);
    497     if (demux == null)
    498     {
    499       if (seqRun.getItem().isInDatabase())
    500       {
    501         ItemQuery<DerivedBioAssay> query = seqRun.getItem().getChildren();
    502         query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    503         Subtype.DEMUXED_SEQUENCES.addFilter(dc, query);
    504         List<DerivedBioAssay> list = query.list(dc);
    505         if (list.size() > 1)
    506         {
    507           addErrorMessage("Found "+list.size()+" demux items for FlowCellID="+flowCellId);
    508           return null;
    509         }
    510         else if (list.size() == 1)
    511         {
    512           demux = list.get(0);
    513           addDebugMessage("Found: "+demux.getName()+"[ref="+flowCellId+"]");
    514         }
    515       }
    516       if (demux == null)
    517       {
    518         demux = DerivedBioAssay.getNew(dc, seqRun.getItem(), null);
    519         demux.setItemSubtype(Subtype.DEMUXED_SEQUENCES.get(dc));
    520         demux.setName(seqRun.getNextDemuxedSequencesName(dc));
    521         Pipeline.RNA_SEQ.setAnnotation(dc, demux);
    522         demux.setHardware(null);
    523         demux.setSoftware(demuxInfo.software);
    524         demux.setProtocol(null);
    525         Annotationtype.READ_STRING.setAnnotationValue(dc, demux, demuxInfo.readString);       
    526         dc.saveItem(demux);
    527        
    528         addDebugMessage("Created: "+ demux.getName());
    529       }
    530       demuxCache.put(flowCellId, demux);
     380    DerivedBioAssay demux = demuxInfo.demux;
     381    if (demux != null)
     382    {
     383      addDebugMessage("Found: "+demux.getName()+"[ref="+flowCellId+"]");
     384    }
     385    else
     386    {
     387      demux = DerivedBioAssay.getNew(dc, seqRun.getItem(), null);
     388      demux.setItemSubtype(Subtype.DEMUXED_SEQUENCES.get(dc));
     389      demux.setName(seqRun.getNextDemuxedSequencesName(dc));
     390      Pipeline.RNA_SEQ.setAnnotation(dc, demux);
     391      demux.setHardware(null);
     392      demux.setSoftware(demuxInfo.software);
     393      demux.setProtocol(null);
     394      Annotationtype.READ_STRING.setAnnotationValue(dc, demux, demuxInfo.readString);       
     395      dc.saveItem(demux);
     396     
     397      addDebugMessage("Created: "+ demux.getName());
    531398    }
    532399    return DemuxedSequences.get(demux);
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/DateValidator.java

    r6201 r6205  
    5151    catch (Exception ex)
    5252    {
    53       section.addErrorMessage("Invalid date in JSON: "+entryKey+"="+value + " (expected format: "+format+")");
     53      section.addErrorMessage("Invalid date in JSON: "+entryKey+"="+value+" (expected format: "+format+")");
    5454    }
    5555    return null;
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/DemuxInfo.java

    r6204 r6205  
    44
    55import net.sf.basedb.core.DbControl;
     6import net.sf.basedb.core.DerivedBioAssay;
    67import net.sf.basedb.core.ItemQuery;
    78import net.sf.basedb.core.Software;
     
    2627{
    2728
     29  public DerivedBioAssay demux;
    2830  public Software software;
    2931  public String readString;
     
    3133  public boolean valid;
    3234
    33   public DemuxInfo(JsonSection demux)
     35  public DemuxInfo(JsonSection section, SequencingRunInfo seqRunInfo, FlowCellInfo flowCellInfo)
    3436  {
    35     if (demux != null)
     37    if (section != null)
    3638    {
    37       software = demux.getRequiredEntry("Software", SoftwareValidator.INSTANCE);
    38       readString = demux.getRequiredEntry("ReadString", PatternValidator.READ_STRING);
     39      software = section.getRequiredEntry("Software", SoftwareValidator.INSTANCE);
     40      readString = section.getRequiredEntry("ReadString", PatternValidator.READ_STRING);
     41      if (seqRunInfo.sequencingRun != null)
     42      {
     43        demux = findExistingDemux(seqRunInfo.sequencingRun, flowCellInfo.flowCellId, section);
     44      }
    3945    }
    40     valid = demux != null && !demux.hasError();
     46    valid = section != null && !section.hasError();
     47  }
     48 
     49 
     50  private DerivedBioAssay findExistingDemux(DerivedBioAssay seqRun, String flowCellId, JsonSection section)
     51  {
     52    DerivedBioAssay demux = null;
     53    DbControl dc = section.getFile().dc();
     54    ItemQuery<DerivedBioAssay> query = seqRun.getChildren();
     55    query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     56    Subtype.DEMUXED_SEQUENCES.addFilter(dc, query);
     57    List<DerivedBioAssay> list = query.list(dc);
     58    if (list.size() > 1)
     59    {
     60      section.addErrorMessage("Found "+list.size()+" demux items for FlowCellID="+flowCellId);
     61    }
     62    else if (list.size() == 1)
     63    {
     64      demux = list.get(0);
     65    }
     66    return demux;
    4167  }
    4268
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/FloatValidator.java

    r6201 r6205  
    1212{
    1313 
     14  /**
     15    Allow all values.
     16   */
    1417  public static final FloatValidator INSTANCE = new FloatValidator();
     18 
     19  /**
     20    All positive values >= 0.
     21  */
     22  public static final FloatValidator POSITIVE = new FloatValidator(0f, null);
     23
     24  private Float maxValue;
     25  private Float minValue;
    1526 
    1627  public FloatValidator()
    1728  {}
    1829 
     30  /**
     31    Allow all values between min and max (inclusive).
     32    Null values are allowed and mean no limit.
     33  */
     34  public FloatValidator(Float min, Float max)
     35  {
     36    this.minValue = min;
     37    this.maxValue = max;
     38  }
     39 
    1940  @Override
    2041  public Float isValid(DbControl dc, Object value, JsonSection section, String entryKey)
    2142  {
     43    Float result = null;
    2244    if (value instanceof Number)
    2345    {
    24       return ((Number)value).floatValue();
     46      result = ((Number)value).floatValue();
    2547    }
    2648    else
     
    2850      try
    2951      {
    30         return Float.parseFloat(value.toString());
     52        result = Float.parseFloat(value.toString());
    3153      }
    3254      catch (Exception ex)
     
    3557      }
    3658    }
    37     return null;
     59    if (result != null)
     60    {
     61      if (minValue != null && result < minValue)
     62      {
     63        section.addErrorMessage("Invalid value in JSON: "+entryKey+"="+value+" (expected >="+minValue+")");
     64        result = null;
     65      }
     66      if (maxValue != null && result > maxValue)
     67      {
     68        section.addErrorMessage("Invalid value in JSON: "+entryKey+"="+value+" (expected <="+maxValue+")");
     69        result = null;
     70      }
     71    }
     72    return result;
    3873  }
    3974
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/FlowCellInfo.java

    r6202 r6205  
    11package net.sf.basedb.reggie.plugins.cmd;
    22
     3import java.util.List;
     4
     5import net.sf.basedb.core.DbControl;
     6import net.sf.basedb.core.ItemQuery;
     7import net.sf.basedb.core.PhysicalBioAssay;
     8import net.sf.basedb.core.query.Annotations;
     9import net.sf.basedb.core.query.Expressions;
     10import net.sf.basedb.core.query.Hql;
     11import net.sf.basedb.core.query.Restrictions;
     12import net.sf.basedb.reggie.Reggie;
     13import net.sf.basedb.reggie.dao.Annotationtype;
     14import net.sf.basedb.reggie.dao.FlowCell;
     15import net.sf.basedb.reggie.dao.PooledLibrary;
     16import net.sf.basedb.reggie.dao.Subtype;
    317
    418/**
     
    2034
    2135  public String flowCellId;
     36  public PhysicalBioAssay flowCell;
    2237  public Integer size;
    2338  public String sequencingCycles;
     
    2641  public boolean valid;
    2742
    28   public FlowCellInfo(JsonSection flowCell)
     43  public FlowCellInfo(JsonSection section, PoolInfo poolInfo)
    2944  {
    30     if (flowCell != null)
     45    if (section != null)
    3146    {
    32       flowCellId = flowCell.getRequiredEntry("FlowCellID", PatternValidator.FLOWCELL_ID);
    33       size = flowCell.getRequiredEntry("Size", IntValidator.FLOWCELL_SIZE_2_OR_4);
    34       sequencingCycles = flowCell.getRequiredEntry("SequencingCycles", PatternValidator.CMD_ID);
    35       operator = flowCell.getRequiredEntry("Operator");
     47      flowCellId = section.getRequiredEntry("FlowCellID", PatternValidator.FLOWCELL_ID);
     48      if (flowCellId != null) flowCell = findExistingFlowCell(flowCellId, section);
     49      if (flowCell != null && poolInfo.poolId != null)
     50      {
     51        verifyPoolIsSequencedOnFlowCell(flowCell, poolInfo, section);
     52      }
     53      size = section.getRequiredEntry("Size", IntValidator.FLOWCELL_SIZE_2_OR_4);
     54      sequencingCycles = section.getRequiredEntry("SequencingCycles", PatternValidator.CMD_ID);
     55      operator = section.getRequiredEntry("Operator");
    3656    }
    37     valid = flowCell != null && !flowCell.hasError();
     57    valid = section != null && !section.hasError();
     58  }
     59 
     60  private PhysicalBioAssay findExistingFlowCell(String flowCellId, JsonSection section)
     61  {
     62    PhysicalBioAssay flowCell = null;
     63    DbControl dc = section.getFile().dc();
     64    ItemQuery<PhysicalBioAssay> query = PhysicalBioAssay.getQuery();
     65    query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     66    Subtype.FLOW_CELL.addFilter(dc, query);
     67    query.join(Annotations.innerJoin(null, Annotationtype.FLOWCELL_ID.load(dc), "ref"));
     68    query.restrict(Restrictions.eq(Hql.alias("ref"), Expressions.string(flowCellId)));
     69    List<PhysicalBioAssay> list = query.list(dc);
     70    if (list.size() > 1)
     71    {
     72      section.addErrorMessage("Found "+list.size()+" flow cells with FlowCellID="+flowCellId);
     73    }
     74    else if (list.size() == 1)
     75    {
     76      flowCell = list.get(0);
     77    }
     78    return flowCell;
     79  }
     80
     81  /**
     82    Verify that an existing flow cell is linked to an existing pool. Note
     83    that is it not possible to add a new pool to an existing flow cell.
     84  */
     85  private void verifyPoolIsSequencedOnFlowCell(PhysicalBioAssay flowCell, PoolInfo poolInfo, JsonSection section)
     86  {
     87    if (poolInfo.pool != null)
     88    {
     89      DbControl dc = section.getFile().dc();
     90      // Verify that the flow cell is linked to the pool
     91      List<PooledLibrary> pools = PooledLibrary.getByFlowCell(dc, FlowCell.get(flowCell));
     92      boolean isLinked = false;
     93      for (PooledLibrary p : pools)
     94      {
     95        if (p.getId() == poolInfo.pool.getId()) isLinked = true;
     96      }
     97      if (!isLinked)
     98      {
     99        section.addErrorMessage(poolInfo.pool.getName()+" is not sequenced on "+flowCell.getName());
     100      }
     101    }
     102    else
     103    {
     104      // This is a new pool that can't be added to the existing flow cell
     105      section.addErrorMessage("Pool[ExternalRef="+poolInfo.poolId+"] is not sequenced on "+flowCell.getName());
     106    }
    38107  }
    39108 
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/JsonFile.java

    r6203 r6205  
    225225      if (fastqInfo.valid) fastqInfo.loadFileInfo(session, rootDir);
    226226
     227      libInfo = new LibraryInfo(getRequiredSection("Library"));
     228      poolInfo = new PoolInfo(getRequiredSection("Pool"), libInfo);
     229      flowCellInfo = new FlowCellInfo(getRequiredSection("FlowCell"), poolInfo);
     230      seqRunInfo = new SequencingRunInfo(getRequiredSection("SequencingRun"), flowCellInfo);
     231      demuxInfo = new DemuxInfo(getRequiredSection("DemuxedSequences"), seqRunInfo, flowCellInfo);
    227232      mergeInfo = new MergeInfo(getRequiredSection("MergedSequences"));
    228       demuxInfo = new DemuxInfo(getRequiredSection("DemuxedSequences"));
    229       seqRunInfo = new SequencingRunInfo(getRequiredSection("SequencingRun"));
    230       flowCellInfo = new FlowCellInfo(getRequiredSection("FlowCell"));
    231       poolInfo = new PoolInfo(getRequiredSection("Pool"));
    232       libInfo = new LibraryInfo(getRequiredSection("Library"));
    233233    }
    234234    catch (Exception ex)
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/LibraryInfo.java

    r6201 r6205  
    22
    33import java.util.Date;
     4import java.util.List;
     5import java.util.regex.Matcher;
     6import java.util.regex.Pattern;
    47
     8import net.sf.basedb.core.BioPlate;
     9import net.sf.basedb.core.BioWell;
     10import net.sf.basedb.core.DbControl;
     11import net.sf.basedb.core.ItemQuery;
     12import net.sf.basedb.core.Protocol;
     13import net.sf.basedb.core.Tag;
    514import net.sf.basedb.core.data.PlateCoordinate;
     15import net.sf.basedb.core.query.Annotations;
     16import net.sf.basedb.core.query.Expressions;
     17import net.sf.basedb.core.query.Hql;
     18import net.sf.basedb.core.query.Restrictions;
     19import net.sf.basedb.reggie.Reggie;
     20import net.sf.basedb.reggie.dao.Annotationtype;
     21import net.sf.basedb.reggie.dao.BioplateType;
     22import net.sf.basedb.reggie.dao.Pipeline;
     23import net.sf.basedb.reggie.dao.Subtype;
     24import net.sf.basedb.util.Coordinate;
    625
    726/**
     
    2544  public String operator;
    2645 
     46  public Tag barcode;
     47  public Protocol protocol;
     48  public BioPlate libPlate;
     49 
    2750  public boolean valid;
    2851 
    29   public LibraryInfo(JsonSection lib)
     52  public LibraryInfo(JsonSection section)
    3053  {
    31     if (lib != null)
     54    if (section != null)
    3255    {
    33       plateId = lib.getRequiredEntry("Plate name", PatternValidator.CMD_ID);
    34       well = lib.getRequiredEntry("Plate well", PlateWellValidator.PLATE_8x12);
     56      plateId = section.getRequiredEntry("Plate name", PatternValidator.CMD_ID);
     57      well = section.getRequiredEntry("Plate well", PlateWellValidator.PLATE_8x12);
    3558 
    36       libDate = lib.getRequiredEntry("Date", DateValidator.YYYY_MM_DD);
    37       libSize = lib.getRequiredEntry("Library size", IntValidator.ALL);
    38       libMolarity = lib.getRequiredEntry("Library molarity", FloatValidator.INSTANCE);
    39       qubitConc = lib.getRequiredEntry("Qubit concentration (ng/ul)", FloatValidator.INSTANCE);
    40       operator = lib.getRequiredEntry("Operator");
     59      if (plateId != null) libPlate = findExistingLibPlate(plateId, section);
     60      if (libPlate != null && well != null)
     61      {
     62        verifyEmptyPosition(libPlate, well, section);
     63      }
     64     
     65      libDate = section.getRequiredEntry("Date", DateValidator.YYYY_MM_DD);
     66      libSize = section.getRequiredEntry("Library size", IntValidator.POSITIVE);
     67      libMolarity = section.getRequiredEntry("Library molarity", FloatValidator.POSITIVE);
     68      qubitConc = section.getRequiredEntry("Qubit concentration (ng/ul)", FloatValidator.POSITIVE);
     69      operator = section.getRequiredEntry("Operator");
     70     
     71      barcode = section.getRequiredEntry("Barcode", BarcodeValidator.INSTANCE);
     72      // TODO -- protocol
    4173    }
    42     valid = lib != null && !lib.hasError();
     74    valid = section != null && !section.hasError();
    4375  }
    4476 
     77  private BioPlate findExistingLibPlate(String plateId, JsonSection section)
     78  {
     79    BioPlate libPlate = null;
     80    DbControl dc = section.getFile().dc();
     81    ItemQuery<BioPlate> query = BioPlate.getQuery();
     82    query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     83    BioplateType.EXTERNAL_LIBRARY.addFilter(dc, query, false);
     84    query.join(Annotations.innerJoin(null, Annotationtype.EXTERNAL_REF.load(dc), "eref"));
     85    query.restrict(Restrictions.eq(Hql.alias("eref"), Expressions.string(plateId)));
     86    List<BioPlate> list = query.list(dc);
     87    if (list.size() > 1)
     88    {
     89      section.addErrorMessage("Found "+list.size()+" library plates with ExternalRef="+plateId);
     90    }
     91    else if (list.size() == 1)
     92    {
     93      libPlate = list.get(0);
     94    }
     95    return libPlate;
     96  }
     97 
     98  /**
     99    Verify that the given position on the libplate is empty.
     100  */
     101  private void verifyEmptyPosition(BioPlate libPlate, PlateCoordinate pos, JsonSection section)
     102  {
     103    String coordinate = Coordinate.numericToAlpha(pos.getRow()+1)+(pos.getColumn()+1);
     104    BioWell well = libPlate.getBioWell(pos);
     105    if (well == null)
     106    {
     107      section.addErrorMessage("Well not found: "+libPlate.getName()+"["+ coordinate+"; ref="+plateId+"]");
     108    }
     109    else if (!well.isEmpty())
     110    {
     111      section.addErrorMessage("Well is not empty: "+libPlate.getName()+"["+ coordinate+"; ref="+plateId+"]");
     112    }
     113  }
     114
     115 
     116  /**
     117    Find a barcode by looking at the UDI part of the value from the JSON file.
     118    The entry in the JSON is typically: 04A UDI0025 (ACTAAGAT-AACCGCGG)
     119    If a barcode is found we also check the Barcode sequences and issue
     120    a warning if they don't match.
     121  */
     122  static class BarcodeValidator
     123    implements ValueValidator<String, Tag>
     124  {
     125 
     126    static final BarcodeValidator INSTANCE = new BarcodeValidator();
     127   
     128    @Override
     129    public Class<String> getExpectedClass()
     130    {
     131      return String.class;
     132    }
     133 
     134    @Override
     135    public Tag isValid(DbControl dc, String value, JsonSection section, String entryKey)
     136    {
     137      Pattern p = Pattern.compile(".*(UDI\\d+).*");
     138      Matcher m = p.matcher(value);
     139      if (!m.matches())
     140      {
     141        section.addErrorMessage("Invalid barcode in JSON: "+entryKey+"="+value+" (expected to find 'UDI[0-9]+')");
     142        return null;
     143      }
     144      String name = m.group(1);
     145     
     146      ItemQuery<Tag> query = Tag.getQuery();
     147      query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     148      Subtype.BARCODE.addFilter(dc, query);
     149      Pipeline.RNA_SEQ.addFilter(dc, query);
     150      query.restrict(Restrictions.eq(Hql.property("name"), Expressions.string(name)));
     151      List<Tag> list = query.list(dc);
     152      if (list.size() != 1)
     153      {
     154        if (list.size() > 1)
     155        {
     156          section.addErrorMessage("Found "+list.size()+" barcodes: name="+name);
     157        }
     158        else
     159        {
     160          section.addErrorMessage("Barcode not found: name="+name);
     161        }
     162        return null;
     163      }
     164      Tag barcode = list.get(0);
     165      String seq1 = (String)Annotationtype.BARCODE_SEQUENCE.getAnnotationValue(dc, barcode);
     166      String seq2 = (String)Annotationtype.BARCODE_SEQUENCE_2.getAnnotationValue(dc, barcode);
     167     
     168      if (seq1 != null && seq2 != null)
     169      {
     170        p = Pattern.compile("([ACGT]+\\-[ACGT]+)");
     171        m = p.matcher(value);
     172        if (m.find())
     173        {
     174          String seq = m.group();
     175          if (!seq.equals(seq1+"-"+seq2))
     176          {
     177            section.addWarningMessage("Barcode sequence mismatch: "+entryKey+"="+value+" (expected "+seq1+"-"+seq2+")");
     178          }
     179        }
     180      }
     181      return barcode;
     182    }
     183  }
     184
    45185}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/PoolInfo.java

    r6200 r6205  
    22
    33import java.util.Date;
     4import java.util.List;
     5
     6import net.sf.basedb.core.DbControl;
     7import net.sf.basedb.core.Extract;
     8import net.sf.basedb.core.ItemQuery;
     9import net.sf.basedb.core.Tag;
     10import net.sf.basedb.core.query.Annotations;
     11import net.sf.basedb.core.query.Expressions;
     12import net.sf.basedb.core.query.Hql;
     13import net.sf.basedb.core.query.Restrictions;
     14import net.sf.basedb.reggie.Reggie;
     15import net.sf.basedb.reggie.dao.Annotationtype;
     16import net.sf.basedb.reggie.dao.Subtype;
     17import net.sf.basedb.util.Values;
     18import net.sf.basedb.util.formatter.NameableFormatter;
    419
    520/**
     
    1530
    1631  public String poolId;
     32  public Extract pool;
    1733  public Date poolDate;
    1834  public String operator;
     
    2036  public boolean valid;
    2137 
    22   public PoolInfo(JsonSection pool)
     38  public PoolInfo(JsonSection section, LibraryInfo libInfo)
    2339  {
    24     if (pool != null)
     40    if (section != null)
    2541    {
    26       poolId = pool.getRequiredEntry("Pool ID", PatternValidator.CMD_ID);
    27       poolDate = pool.getRequiredEntry("Date", DateValidator.YYYY_MM_DD);
    28       operator = pool.getRequiredEntry("Operator");
     42      poolId = section.getRequiredEntry("Pool ID", PatternValidator.CMD_ID);
     43      if (poolId != null) pool = findExistingPool(poolId, section);
     44      if (pool != null && libInfo.barcode != null)
     45      {
     46        verifyUnusedBarcode(pool, libInfo.barcode, section);
     47      }
     48      poolDate = section.getRequiredEntry("Date", DateValidator.YYYY_MM_DD);
     49      operator = section.getRequiredEntry("Operator");
    2950    }
    30     valid = pool != null && !pool.hasError();
     51    valid = section != null && !section.hasError();
    3152  }
    3253 
     54  /**
     55    Find an existing pool with the given id.
     56  */
     57  private Extract findExistingPool(String poolId, JsonSection section)
     58  {
     59    Extract pool = null;
     60    DbControl dc = section.getFile().dc();
     61    ItemQuery<Extract> query = Extract.getQuery();
     62    query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     63    Subtype.POOLED_LIBRARY.addFilter(dc, query);
     64    query.join(Annotations.innerJoin(null, Annotationtype.EXTERNAL_REF.load(dc), "eref"));
     65    query.restrict(Restrictions.eq(Hql.alias("eref"), Expressions.string(poolId)));
     66    List<Extract> list = query.list(dc);
     67    if (list.size() > 1)
     68    {
     69      section.addErrorMessage("Found "+list.size()+" pools with ExternalRef="+poolId);
     70    }
     71    else if (list.size() == 1)
     72    {
     73      pool = list.get(0);
     74    }
     75    return pool;
     76  }
     77 
     78  /**
     79    Check if there are any other libs in the pool with the same barcode
     80  */
     81  private void verifyUnusedBarcode(Extract pool, Tag barcode, JsonSection section)
     82  {
     83    DbControl dc = section.getFile().dc();
     84    ItemQuery<Extract> query = Extract.getQuery();
     85    query.join(Hql.innerJoin("childCreationEvents", "cce"));
     86    query.join(Hql.innerJoin("cce", "event", "pool"));
     87    query.restrict(Restrictions.eq(Hql.alias("pool"), Hql.entity(pool.getCreationEvent())));
     88    query.restrict(Restrictions.eq(Hql.property("tag"), Hql.entity(barcode)));
     89    List<Extract> libsInPool = query.list(dc);
     90    if (libsInPool.size() > 0)
     91    {
     92      section.addErrorMessage("Found other libraries in "+pool.getName() +
     93        " with barcode "+barcode.getName()+": " + Values.getString(libsInPool, ", ", true, new NameableFormatter()));
     94    }
     95
     96  }
    3397}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/SequencingRunInfo.java

    r6202 r6205  
    55
    66import net.sf.basedb.core.DbControl;
     7import net.sf.basedb.core.DerivedBioAssay;
    78import net.sf.basedb.core.Hardware;
    89import net.sf.basedb.core.ItemQuery;
     
    3132{
    3233
     34  public DerivedBioAssay sequencingRun;
    3335  public SequencerInfo sequencer;
    3436  public String position;
     
    4042  public boolean valid;
    4143
    42   public SequencingRunInfo(JsonSection seqRun)
     44  public SequencingRunInfo(JsonSection section, FlowCellInfo flowCellInfo)
    4345  {
    44     if (seqRun != null)
     46    if (section != null)
    4547    {
    46       sequencer = seqRun.getRequiredEntry("SerialNumber", new SequencerInfo());
    47       position = seqRun.getRequiredEntry("Position", PatternValidator.SEQUENCER_POSITION);
    48       runNumber = seqRun.getRequiredEntry("RunNumber", IntValidator.POSITIVE);
    49       startDate = seqRun.getRequiredEntry("StartDate", DateValidator.YYMMDD);
    50       endDate = seqRun.getRequiredEntry("EndDate", DateValidator.YYMMDD_HH_MM_SS);
    51       operator = seqRun.getRequiredEntry("Operator");
     48      sequencer = section.getRequiredEntry("SerialNumber", new SequencerInfo());
     49      position = section.getRequiredEntry("Position", PatternValidator.SEQUENCER_POSITION);
     50      runNumber = section.getRequiredEntry("RunNumber", IntValidator.POSITIVE);
     51      startDate = section.getRequiredEntry("StartDate", DateValidator.YYMMDD);
     52      endDate = section.getRequiredEntry("EndDate", DateValidator.YYMMDD_HH_MM_SS);
     53      operator = section.getRequiredEntry("Operator");
     54      if (flowCellInfo.flowCell != null)
     55      {
     56        sequencingRun = findExistingSeqRun(flowCellInfo, section);
     57      }
    5258    }
    53     valid = seqRun != null && !seqRun.hasError();
     59    valid = section != null && !section.hasError();
     60  }
     61 
     62  private DerivedBioAssay findExistingSeqRun(FlowCellInfo flowCellInfo, JsonSection section)
     63  {
     64    DerivedBioAssay seqRun = null;
     65    DbControl dc = section.getFile().dc();
     66    ItemQuery<DerivedBioAssay> query = flowCellInfo.flowCell.getRootDerivedBioAssays();
     67    query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
     68    Subtype.SEQUENCING_RUN.addFilter(dc, query);
     69    List<DerivedBioAssay> list = query.list(dc);
     70    if (list.size() > 1)
     71    {
     72      section.addErrorMessage("Found "+list.size()+" sequencing runs for FlowCellID="+flowCellInfo.flowCellId);
     73    }
     74    else if (list.size() == 1)
     75    {
     76      seqRun = list.get(0);
     77    }
     78    return seqRun;
    5479  }
    5580 
Note: See TracChangeset for help on using the changeset viewer.