Changeset 6203


Ignore:
Timestamp:
Apr 9, 2021, 1:47:24 PM (14 months ago)
Author:
Nicklas Nordborg
Message:

References #1295: Registration of specimen handled by external lab

Added code for creating DemuxedSequences and MergedSequences items.

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

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/dao/Annotationtype.java

    r6197 r6203  
    19331933  */
    19341934  public static final Annotationtype EXTERNAL_REF =
    1935     new Annotationtype("ExternalRef", Type.STRING, false, Item.SAMPLE, Item.EXTRACT, Item.PHYSICALBIOASSAY, Item.DERIVEDBIOASSAY, Item.BIOPLATE);
     1935    new Annotationtype("ExternalRef", Type.STRING, false, Item.SAMPLE, Item.EXTRACT,
     1936      Item.BIOPLATE, Item.SOFTWARE, Item.PROTOCOL);
    19361937 
    19371938  /**
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/FutureSpecimenImporter.java

    r6201 r6203  
    2626import net.sf.basedb.reggie.dao.Annotationtype;
    2727import net.sf.basedb.reggie.dao.BioplateType;
     28import net.sf.basedb.reggie.dao.DemuxedSequences;
    2829import net.sf.basedb.reggie.dao.FlowCell;
    2930import net.sf.basedb.reggie.dao.Library;
     
    3738import net.sf.basedb.reggie.dao.SpecimenTube;
    3839import net.sf.basedb.reggie.dao.Subtype;
     40import net.sf.basedb.reggie.plugins.cmd.DemuxInfo;
    3941import net.sf.basedb.reggie.plugins.cmd.FlowCellInfo;
    4042import net.sf.basedb.reggie.plugins.cmd.JsonFile;
    4143import net.sf.basedb.reggie.plugins.cmd.JsonSection;
    4244import net.sf.basedb.reggie.plugins.cmd.LibraryInfo;
     45import net.sf.basedb.reggie.plugins.cmd.MergeInfo;
    4346import net.sf.basedb.reggie.plugins.cmd.PoolInfo;
    4447import net.sf.basedb.reggie.plugins.cmd.SequencingRunInfo;
     
    115118    FlowCellInfo flowCellInfo = jsonFile.getFlowCell();
    116119    SequencingRunInfo seqRunInfo = jsonFile.getSequencingRun();
    117    
    118     JSONObject jsonDemux = (JSONObject)json.get("demux");
     120    DemuxInfo demuxInfo = jsonFile.getDemuxInfo();
     121    MergeInfo mergeInfo = jsonFile.getMergeInfo();
    119122
    120123    if (jsonSpecimen == null) return;
     
    140143    SequencingRun seqRun = getOrCreateSequencingRun(dc, flowCell, flowCellInfo, seqRunInfo);
    141144   
    142   //  if (jsonDemux == null) return;
    143   //  MergedSequences merged = createMergedSequences(dc, lib, seqRun, jsonDemux);
     145    if (seqRun == null || !demuxInfo.valid) return;
     146    DemuxedSequences demux = getOrCreateDemux(dc, seqRun, flowCellInfo, demuxInfo);
     147   
     148    if (demux == null) return;
     149    MergedSequences merged = createMergedSequences(dc, lib, demux, mergeInfo);
    144150  }
    145151 
     
    482488  }
    483489 
    484   /*
    485   private SequencingRun getOrCreateSequencing(DbControl dc, PooledLibrary pool, JSONObject jsonSeq)
    486   {
    487     String flowCellId = (String)jsonSeq.get("flowCellId");
    488     PhysicalBioAssay flowCell = null; //findFlowCellByRef(dc, flowCellId);
    489     if (flowCell == null)
    490     {
    491       flowCell = PhysicalBioAssay.getNew(dc);
    492       flowCell.setItemSubtype(Subtype.FLOW_CELL.get(dc));
    493       flowCell.setName(FlowCell.getNextNames(dc, 1).get(0));
    494       Annotationtype.PIPELINE.setAnnotationValue(dc, flowCell, Pipeline.RNA_SEQ.getName());
    495       Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, flowCell, flowCellId);
    496       flowCell.setSize(2); // Can also be 4
    497       dc.saveItem(flowCell);
    498 
    499       flowCellCache.put(flowCellId, flowCell);
    500 
    501       // Link with pool
    502       BioMaterialEvent createEvent = flowCell.getCreationEvent();
    503       for (int laneNo = 1; laneNo <= flowCell.getSize(); laneNo++)
    504       {
    505         Extract poolA = Extract.getNew(dc);
    506         poolA.setItemSubtype(Subtype.POOLED_LIBRARY_ALIQUOT.get(dc));
    507         poolA.setName(pool.getNextAliquotName(dc));
    508         poolA.getCreationEvent().setSource(pool.getItem());
    509         createEvent.addSource(poolA).setPosition(laneNo);
    510         dc.saveItem(poolA);
    511         addDebugMessage("Created: "+ poolA.getName());
    512       }
    513       addDebugMessage("Created: "+ flowCell.getName());
    514      
    515     }
    516     else
    517     {
    518       addDebugMessage("Found: "+flowCell.getName());
    519       // TODO -- It should be linked with POOL already -- verify this??
    520     }
    521    
    522     DerivedBioAssay seqRun = findSeqRunByRef(dc, flowCellId);
    523     if (seqRun == null)
    524     {
    525       seqRun = DerivedBioAssay.getNew(dc, flowCell, null);
    526       seqRun.setItemSubtype(Subtype.SEQUENCING_RUN.get(dc));
    527       seqRun.setName(SequencingRun.getNextName(dc));
    528       Annotationtype.PIPELINE.setAnnotationValue(dc, seqRun, Pipeline.RNA_SEQ.getName());
    529       Annotationtype.EXTERNAL_REF.setAnnotationValue(dc, seqRun, flowCellId);
    530       dc.saveItem(seqRun);
    531      
    532       seqRunCache.put(flowCellId, seqRun);
    533       addDebugMessage("Created: "+ seqRun.getName());
    534     }
    535     else
    536     {
    537       addDebugMessage("Found: "+seqRun.getName());
    538       // verify settings ??
    539     }
    540    
    541     return SequencingRun.get(seqRun);
    542   }
    543  
    544   */
    545 
    546  
    547 
    548   private DerivedBioAssay findSeqRunByRef(DbControl dc, String flowCellId)
    549   {
    550     DerivedBioAssay seqRun = seqRunCache.get(flowCellId);
    551     if (seqRun == null)
    552     {
    553       ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery();
    554       query.setIncludes(Reggie.INCLUDE_IN_CURRENT_PROJECT);
    555       Subtype.SEQUENCING_RUN.addFilter(dc, query);
    556       query.join(Annotations.innerJoin(null, Annotationtype.EXTERNAL_REF.load(dc), "eref"));
    557       query.restrict(Restrictions.eq(Hql.alias("eref"), Expressions.string(flowCellId)));
    558       List<DerivedBioAssay> list = query.list(dc);
    559       if (list.size() > 1)
    560       {
    561         // ERROR
    562       }
    563       else if (list.size() == 1)
    564       {
    565         seqRun = list.get(0);
    566       }
    567     }
    568     return seqRun;
    569   }
    570 
    571  
    572   private MergedSequences createMergedSequences(DbControl dc, Library lib, SequencingRun seqRun, JSONObject jsonDemux)
    573   {
    574     DerivedBioAssay demux = findDemuxBySeqRun(dc, seqRun);
    575    
     490 
     491  private DemuxedSequences getOrCreateDemux(DbControl dc, SequencingRun seqRun, FlowCellInfo flowCellInfo, DemuxInfo demuxInfo)
     492  {
     493    String flowCellId = flowCellInfo.flowCellId;
     494    if (flowCellId == null) return null;
     495
     496    DerivedBioAssay demux = demuxCache.get(flowCellId);
    576497    if (demux == null)
    577498    {
    578       demux = DerivedBioAssay.getNew(dc, seqRun.getItem(), null);
    579       demux.setItemSubtype(Subtype.DEMUXED_SEQUENCES.get(dc));
    580       demux.setName(seqRun.getNextDemuxedSequencesName(dc));
    581       Annotationtype.PIPELINE.setAnnotationValue(dc, demux, Pipeline.RNA_SEQ.getName());
    582       dc.saveItem(demux);
    583       demuxCache.put(seqRun.getName(), demux);
    584       addDebugMessage("Created: "+ demux.getName());
    585     }
    586     else
    587     {
    588       addDebugMessage("Found: "+demux.getName());
    589     }
    590    
    591     DerivedBioAssay merged = DerivedBioAssay.getNew(dc, demux, null);
     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);
     531    }
     532    return DemuxedSequences.get(demux);
     533  }
     534 
     535  private MergedSequences createMergedSequences(DbControl dc, Library lib, DemuxedSequences demux, MergeInfo mergeInfo)
     536  {
     537
     538    DerivedBioAssay merged = DerivedBioAssay.getNew(dc, demux.getItem(), null);
    592539    merged.setItemSubtype(Subtype.MERGED_SEQUENCES.get(dc));
    593540    merged.setName(lib.getNextMergedSequencesName(dc));
    594     Annotationtype.PIPELINE.setAnnotationValue(dc, merged, Pipeline.RNA_SEQ.getName());
     541    Pipeline.RNA_SEQ.setAnnotation(dc, merged);
    595542    merged.setExtract(lib.getItem());
     543    Annotationtype.PF_READS.setAnnotationValue(dc, merged, mergeInfo.pfReads);
    596544    dc.saveItem(merged);
     545   
    597546    addDebugMessage("Created: "+ merged.getName());
    598    
    599547    return MergedSequences.get(merged);
    600548  }
    601  
    602   private DerivedBioAssay findDemuxBySeqRun(DbControl dc, SequencingRun seqRun)
    603   {
    604     DerivedBioAssay demux = demuxCache.get(seqRun.getName());
    605     if (demux == null)
    606     {
    607       // TODO - query database
    608     }
    609     return demux;
    610   }
    611549
    612550}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/IntValidator.java

    r6201 r6203  
    77
    88/**
    9   Validator for Float values. It supports both numeric and string
    10   values in the JSON. String values are parsed with Float.parseFloat().
     9  Validator for Integer values. It supports both numeric and string
     10  values in the JSON. String values are parsed with Integer.parseInt().
    1111  @since 4.32
    1212*/
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/JsonFile.java

    r6201 r6203  
    8484  private FlowCellInfo flowCellInfo;
    8585  private SequencingRunInfo seqRunInfo;
     86  private DemuxInfo demuxInfo;
     87  private MergeInfo mergeInfo;
    8688
    8789  /**
     
    223225      if (fastqInfo.valid) fastqInfo.loadFileInfo(session, rootDir);
    224226
     227      mergeInfo = new MergeInfo(getRequiredSection("MergedSequences"));
     228      demuxInfo = new DemuxInfo(getRequiredSection("DemuxedSequences"));
    225229      seqRunInfo = new SequencingRunInfo(getRequiredSection("SequencingRun"));
    226230      flowCellInfo = new FlowCellInfo(getRequiredSection("FlowCell"));
     
    266270  }
    267271 
     272  public DemuxInfo getDemuxInfo()
     273  {
     274    return demuxInfo;
     275  }
     276 
     277  public MergeInfo getMergeInfo()
     278  {
     279    return mergeInfo;
     280  }
     281 
    268282  public FastqInfo getFastq()
    269283  {
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/cmd/PatternValidator.java

    r6201 r6203  
    3838  */
    3939  public static final PatternValidator SERIAL_NO = new PatternValidator("[A-Z0-9]{2,20}", "serial number", null, "2-20 characters A-Z or 0-9");
     40
     41  /**
     42    At least four groups of [0-9]+[TBS].
     43  */
     44  public static final PatternValidator READ_STRING = new PatternValidator("([0-9]+[TBS]){4,8}", "read string", null, "at least 4 groups of [0-9]+[TBS]");
     45
    4046 
    4147  private final Pattern pattern;
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/InstallServlet.java

    r6197 r6203  
    10041004            Annotationtype.CLUSTER_START, Annotationtype.CLUSTER_OPERATOR,
    10051005            Annotationtype.SEQUENCING_CYCLES, Annotationtype.FAILED_LANES,
    1006             Annotationtype.PIPELINE, Annotationtype.EXTERNAL_REF,
     1006            Annotationtype.PIPELINE,
    10071007            Annotationtype.PLATE_PROCESS_RESULT, Annotationtype.SEQUENCING_RESULT));
    10081008       
     
    10121012            Annotationtype.HISEQ_POSITION, Annotationtype.DATA_FILES_FOLDER, Annotationtype.SEQUENCING_RESULT,
    10131013            Annotationtype.SEQUENCING_CONFIRMED, Annotationtype.AUTO_PROCESSING,
    1014             Annotationtype.PIPELINE, Annotationtype.EXTERNAL_REF
     1014            Annotationtype.PIPELINE
    10151015          ));
    10161016       
     
    10691069       
    10701070        jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.DEMUX_SOFTWARE, createIfMissing,
    1071             Annotationtype.PARAMETER_SET, Annotationtype.PIPELINE
     1071            Annotationtype.PARAMETER_SET, Annotationtype.PIPELINE, Annotationtype.EXTERNAL_REF
    10721072          ));
    10731073        jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.MERGE_SOFTWARE, createIfMissing,
Note: See TracChangeset for help on using the changeset viewer.