Changeset 4970


Ignore:
Timestamp:
Sep 13, 2018, 1:53:15 PM (3 years ago)
Author:
Nicklas Nordborg
Message:

References #1054: Even more functionality in the Flagged alignment wizard

Extended the "Schedule re-processing" functionality with the ability to add or modify comments (QC_GENOTYPE_COMMENT) and flag more alignments. The functionality is available when a filter has been selected.

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

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/flaggedalignment/search.js

    r4823 r4970  
    245245    }
    246246   
     247    Wizard.hideGoNextConfirmation();
    247248    Wizard.showLoadingAnimation(msg);
    248249    Wizard.asyncJsonRequest(url, search.onAlignmentsLoaded);
     
    423424    {
    424425      html += '<thead class="mode-reprocess"><tr>';
    425       html += '<th colspan="5"></th>';
    426       html += '<th colspan="4" class="mode-reprocess-header">Remaining quantity</th>';
    427       html += '<th colspan="8"></th>';
     426      html += '<th colspan="4"></th>';
     427      html += '<th colspan="3" class="mode-reprocess-header">Remaining quantity</th>';
     428      html += '<th colspan="10"></th>';
    428429      html += '</tr></thead>';
    429430    }
     
    432433    html += '<tr>';
    433434    html += '<th>Patient</th>';
    434     html += '<th>QiaCube</th>';
    435     html += '<th>LibPlate</th>';
     435    html += '<th class="'+(qiacubefilter?'':'mode-genotype')+'">QiaCube</th>';
     436    html += '<th class="'+(libplatefilter||highHetFilter?'':'mode-genotype')+'">LibPlate</th>';
    436437    html += '<th>HET</th>';
    437438    html += '<th>Alignment</th>';
     
    441442      html += '<th class="mode-reprocess num-col">Lysate<br>(µl)</th>';
    442443      html += '<th class="mode-reprocess num-col">RNA<br>(µg)</th>';
    443       html += '<th class="mode-reprocess dottedright" id="reprocess-header">Re-process</th>';
     444      html += '<th class="mode-reprocess" id="reprocess-header">Re-process</th>';
     445      html += '<th class="mode-reprocess comment-col">Comment</th>';
     446      html += '<th class="mode-reprocess flag-col dottedright">Flag</th>';
    444447    }
    445448    html += '<th></th>';
     
    478481        html += '<tbody class="highlight"><tr>';
    479482        html += '<td rowspan="'+tbodySpan+'">'+(sp ? HTMLHelper.colorMatch(sp.patientName, null, 'Click to highlight this patient') : '')+'</td>';
    480         html += '<td rowspan="'+tbodySpan+'">'+(sp ? HTMLHelper.qiaCubeLink(rna.QIACUBE_DATE, rna.QIACUBE_RUN_NO, rna.QIACUBE_POSITION, qiacubefilter, false) : '')+'</td>';
     483        html += '<td rowspan="'+tbodySpan+'" class="'+(qiacubefilter?'':'mode-genotype')+'">'+(sp ? HTMLHelper.qiaCubeLink(rna.QIACUBE_DATE, rna.QIACUBE_RUN_NO, rna.QIACUBE_POSITION, qiacubefilter, false) : '')+'</td>';
    481484        if (libplatefilter)
    482485        {
     
    489492      if (!libplatefilter)
    490493      {
    491         html += '<td rowspan="'+rowspan+'">'+(libPlate ? HTMLHelper.libPlateLink(libPlate.name, lib.bioWell.location, libplatefilter, false):'')+'</td>';
     494        html += '<td rowspan="'+rowspan+'" class="'+(highHetFilter?'':'mode-genotype')+'">'+(libPlate ? HTMLHelper.libPlateLink(libPlate.name, lib.bioWell.location, libplatefilter, false):'')+'</td>';
    492495      }
    493496      html += '<td rowspan="'+rowspan+'">'+Reggie.formatNumber(aligned.QC_GENOTYPE_HET_PCT, '%', -1)+'</td>';
    494497      html += '<td rowspan="'+rowspan+'" class="text-col">'+tmp.name+'</td>';
    495       if (filter && tb.start)
    496       {
    497         html += '<td rowspan="'+tbodySpan+'" class="mode-reprocess dottedleft num-col">'+(sp ? Reggie.formatNumber(sp.remainingQuantity/1000, null, 1, 1) : '')+'</td>';
    498         html += '<td rowspan="'+tbodySpan+'" class="mode-reprocess num-col">'+(lys ? Math.round(lys.remainingQuantity) : '')+'</td>';
    499         html += '<td rowspan="'+tbodySpan+'" class="mode-reprocess num-col">'+(sp ? Reggie.formatNumber(rna.remainingQuantity, null, 2, 2) : '')+'</td>';
    500         html += '<td rowspan="'+tbodySpan+'" class="mode-reprocess dottedright">'+(sp ? HTMLHelper.reprocessOptions(aligned) : '')+'</td>';
     498      if (filter)
     499      {
     500        if (tb.start)
     501        {
     502          html += '<td rowspan="'+tbodySpan+'" class="mode-reprocess dottedleft num-col">'+(sp ? Reggie.formatNumber(sp.remainingQuantity/1000, null, 1, 1) : '')+'</td>';
     503          html += '<td rowspan="'+tbodySpan+'" class="mode-reprocess num-col">'+(lys ? Math.round(lys.remainingQuantity) : '')+'</td>';
     504          html += '<td rowspan="'+tbodySpan+'" class="mode-reprocess num-col">'+(sp ? Reggie.formatNumber(rna.remainingQuantity, null, 2, 2) : '')+'</td>';
     505          html += '<td rowspan="'+tbodySpan+'" class="mode-reprocess">'+(sp ? HTMLHelper.reprocessOptions(aligned) : '')+'</td>';
     506        }
     507       
     508        var flagged = aligned.compare && aligned.compare.flagged;
     509        var isAlignment = aligned.name;
     510        html += '<td rowspan="'+rowspan+'" class="mode-reprocess comment-col">'+(isAlignment ? HTMLHelper.qcCommentInput(aligned) : '')+'</td>';       
     511        html += '<td rowspan="'+rowspan+'" class="mode-reprocess flag-col dottedright">'+(isAlignment && sp && !flagged ? HTMLHelper.qcFlagCheckbox(aligned) : '')+'</td>';
    501512      }
    502513      html += '<td rowspan="'+rowspan+'" class="icon-col">'+tmp.icons+'</td>';
     
    791802      tmp.name += '<img src="../images/case_summary.png" class="link case-summary" data-name="'+Strings.encodeTags(itemName)+'" title="Show case summary">';
    792803    }
     804    if (alignment.QC_GENOTYPE_COMMENT)
     805    {
     806      icons += '<img src="../images/comment.png" title="'+Strings.encodeTags(alignment.QC_GENOTYPE_COMMENT)+'">';
     807    }
    793808    if (alignment.compare && alignment.compare.flagged)
    794809    {
     
    867882    Doc.showHide('goreprocess', mode == 'reprocess');
    868883    // Doc.showHide('goresolve', mode == 'resolve');
     884    Wizard.hideGoNextConfirmation();
    869885  }
    870886 
    871887  search.goReProcess = function()
    872888  {
     889    Wizard.hideGoNextConfirmation();
     890    Doc.hide('wizard-status');
    873891    var frm = document.forms['reggie'];
    874     var selected = [];
    875    
     892    var items = [];
    876893    for (var itemNo = 0; itemNo < alignments.length; itemNo++)
    877894    {
    878895      var aligned = alignments[itemNo];
    879       var list = Doc.element('reprocess.'+aligned.tmpId);
    880       if (list && list.value)
    881       {
    882         var item;
    883         if (list.value == 'specimen')
    884         {
    885           item = {'type': 'SAMPLE', 'id': aligned.specimen.id };
    886         }
    887         else if (list.value == 'lysate')
    888         {
    889           item = {'type': 'EXTRACT', 'id': aligned.lysate.id };
    890         }
    891         else if (list.value == 'rna')
    892         {
    893           item = {'type': 'EXTRACT', 'id': aligned.rna.id };
    894         }
    895         selected[selected.length] = item;
    896       }
    897     }
    898    
    899     if (selected.length == 0)
    900     {
    901       Forms.showNotification('reprocess-header', 'Please selected at least one alignment (that is not already scheduled for re-processing)!', null, 'pointer-below');
     896     
     897      // Get the form elements for this item
     898      var listE = Doc.element('reprocess.'+aligned.tmpId);
     899      var flagE = Doc.element('flag.'+aligned.tmpId);
     900      var commentE = Doc.element('comment.'+aligned.tmpId);
     901     
     902      var item = { 'id': aligned.id };
     903      var changed = false;
     904     
     905      // Check if a re-processing option was selected
     906      if (listE && listE.value)
     907      {
     908        changed = true;
     909        if (listE.value == 'specimen')
     910        {
     911          item.reprocess = {'type': 'SAMPLE', 'id': aligned.specimen.id };
     912        }
     913        else if (listE.value == 'lysate')
     914        {
     915          item.reprocess = {'type': 'EXTRACT', 'id': aligned.lysate.id };
     916        }
     917        else if (listE.value == 'rna')
     918        {
     919          item.reprocess = {'type': 'EXTRACT', 'id': aligned.rna.id };
     920        }
     921      }
     922      if (flagE && flagE.checked)
     923      {
     924        changed = true;
     925        item.flag = true;
     926      }
     927      if (commentE && Strings.trim(commentE.value) != Strings.trim(aligned.QC_GENOTYPE_COMMENT))
     928      {
     929        changed = true;
     930        item.comment = commentE.value;
     931      }
     932     
     933      if (changed) items[items.length] = item;
     934    }
     935   
     936    if (items.length == 0)
     937    {
     938      Wizard.showGoNextConfirmation(false, 'No changes have been made!');
    902939      return;
    903940    }
     941   
     942    Doc.addClass('step-1', 'disabled');
     943    Doc.hide('navigation');
     944   
     945   
     946    // Include filter settings in the registration URL so that a new list can be generated
     947    var highHet = Doc.element('highHetFilter');
     948    var libPlate = Doc.element('libPlateFilter');
     949    var qiaCube = Doc.element('qiaCubeFilter');
    904950   
    905951    var url = '../Genotype.servlet?ID='+App.getSessionId();
    906952    url += '&cmd=ReprocessItems';
     953    if (libPlate.selectedIndex > 0)
     954    {
     955      url += '&libPlateFilter='+encodeURIComponent(libPlate.value);
     956    }
     957    else if (qiaCube.selectedIndex > 0)
     958    {
     959      url += '&qiaCubeFilter='+encodeURIComponent(qiaCube.value);
     960    }
     961    else if (highHet.checked)
     962    {
     963      url += '&highHetFilter=1';
     964    }
    907965   
    908966    var submitInfo = {};
    909     submitInfo.items = selected;
    910     //alert(JSON.stringify(submitInfo));
     967    submitInfo.items = items;
     968    Wizard.showLoadingAnimation('Saving changes...');
    911969    Wizard.asyncJsonRequest(url, search.reprocessResults, 'POST', JSON.stringify(submitInfo));
    912970  }
     
    914972  search.reprocessResults = function(response)
    915973  {
     974    search.onAlignmentsLoaded(response);
     975    Doc.show('navigation');
     976    Doc.removeClass('step-1', 'disabled');
    916977    Wizard.showFinalMessage(response.messages);
    917978  }
     
    11771238    var html = '';
    11781239    html += '<select id="'+id+'" name="'+id+'">';
    1179     html += '<option value="">&nbsp;';
     1240    if (!currentReProcess) html += '<option value="" selected>&nbsp;';
    11801241    html += '<option '+(currentReProcess=='Specimen'?'value="" selected':'value="specimen"')+'>Specimen';
    11811242    html += '<option '+(currentReProcess=='Lysate'?'value="" selected':'value="lysate"')+'>Lysate';
     
    11911252  }
    11921253 
     1254  helper.qcCommentInput = function(aligned)
     1255  {
     1256    var id = 'comment.'+aligned.tmpId;
     1257    html = '<input type="text" id="'+id+'" name="'+id+'" value="'+Strings.encodeTags(aligned.QC_GENOTYPE_COMMENT)+'">';
     1258    return html;
     1259  }
     1260 
     1261  helper.qcFlagCheckbox = function(aligned)
     1262  {
     1263    var id = 'flag.'+aligned.tmpId;
     1264    html = '<input type="checkbox" id="'+id+'" name="'+id+'">';
     1265    return html;
     1266  }
     1267
    11931268  return helper;
    11941269}();
  • extensions/net.sf.basedb.reggie/trunk/resources/flaggedalignment/search.jsp

    r4818 r4970  
    108108  text-align: center;
    109109}
    110 .text-col img.case-summary
     110
     111#itemTable .flag-col
     112{
     113  text-align: center;
     114}
     115
     116#itemTable .comment-col input
     117{
     118  width: 15em;
     119}
     120
     121#itemTable .text-col img.case-summary
    111122{
    112123  float: left;
     
    191202  <form name="reggie" id="wizard" class="wizard">
    192203 
    193   <div class="step auto-hide" id="step-1">
     204  <div class="step" id="step-1">
    194205    <div class="step-no">1</div>
    195206    <div class="step-title" id="step-1-title">Flagged alignments</div>
     
    219230        <td style="padding-top: 3px; padding-bottom: 6px;">
    220231          <label><input type="radio" name="mode" id="mode-genotype" checked value="genotype">Genotype analysis</label>
    221           <label><input type="radio" name="mode" id="mode-reprocess" value="reprocess" disabled>Schedule re-processing</label>
     232          <label><input type="radio" name="mode" id="mode-reprocess" value="reprocess" disabled>Add comments and schedule re-processing</label>
    222233          <label><input type="radio" name="mode" id="mode-resolve" value="resolve" disabled>Resolve problems</label>
    223234        </td>
     
    235246  <tr>
    236247    <td><base:button id="gocancel" title="Cancel" /></td>
    237     <td><base:button id="goreprocess" title="Schedule re-processing&hellip;" image="<%=home+"/images/pipette.png"%>" /></td>
     248    <td><base:button id="goreprocess" title="Register" image="<%=home+"/images/gonext.png"%>" /></td>
    238249    <td id="gonext-message" class="message"></td>
    239250  </tr>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/GenotypeServlet.java

    r4925 r4970  
    145145      else if ("GetFlaggedAlignments".equals(cmd))
    146146      {
    147         GenoTypeChecker checker = new GenoTypeChecker();
     147       
    148148        dc = sc.newDbControl();
    149        
    150         String libPlateFilter = req.getParameter("libPlateFilter");
    151         String qiaCubeFilter = req.getParameter("qiaCubeFilter");
    152         boolean highHetFilter = Values.getBoolean(req.getParameter("highHetFilter"));
    153        
    154         checker.preloadVcfForFlaggedAlignments(dc);
    155         checker.preloadSpecimenData(dc);
    156        
    157         ItemQuery<DerivedBioAssay> query = checker.getFlaggedAlignments(dc);
    158         // When we have a filter we want to load information about all items on the
    159         // given QiaCube/LibPlate. We fill this Set with all RNA/Library items and then
    160         // remove them as we find alignments. Remaining items in this Set have no alignment (that we can use)
    161         Set<Extract> itemsWithoutAlignment = null;
    162         if (qiaCubeFilter != null)
    163         {
    164           Date qcDate = Reggie.CONVERTER_STRING_TO_DATE.convert(qiaCubeFilter.substring(0, 8));
    165           int runNo = Values.getInt(qiaCubeFilter.substring(9));
    166          
    167           ItemQuery<Extract> rnaQuery = checker.getRnaRelatedToQiacube(dc, qcDate, runNo);
    168           itemsWithoutAlignment = new HashSet<>(rnaQuery.list(dc));
    169           query = checker.getAlignmentsRelatedToItems(dc, itemsWithoutAlignment, true, true);
    170         }
    171         else if (libPlateFilter != null)
    172         {
    173           ItemQuery<Extract> libQuery = checker.getLibrariesRelatedToLibPlate(dc, libPlateFilter);
    174           itemsWithoutAlignment = new HashSet<>(libQuery.list(dc));
    175           query = checker.getAlignmentsRelatedToItems(dc, itemsWithoutAlignment, true, true);
    176         }
    177         else if (highHetFilter)
    178         {
    179           query = checker.getAlignmentsWithHighHet(dc, true);
    180         }
    181         query.order(Orders.asc(Hql.property("name")));
    182        
    183         List<AlignedSequences> list = AlignedSequences.toList(query.list(dc));
    184         SnapshotManager manager = new SnapshotManager();
    185 
    186         if (qiaCubeFilter != null || libPlateFilter != null || highHetFilter)
    187         {
    188           for (AlignedSequences as : list)
    189           {
    190             DerivedBioAssay alignment = as.getDerivedBioAssay();
    191             String qcStatus = (String)Annotationtype.QC_GENOTYPE_STATUS.getAnnotationValue(dc, manager, alignment);
    192             if ("Checked".equals(qcStatus))
    193             {
    194               // Only include "Checked" alignments in genotyping
    195               checker.preload(dc, as.getDerivedBioAssay());
    196             }
    197           }
    198         }
    199        
    200         JSONArray jsonAlignments = new JSONArray();       
    201         for (AlignedSequences as : list)
    202         {
    203           String qcStatus = (String)Annotationtype.QC_GENOTYPE_STATUS.getAnnotationValue(dc, manager, as.getItem());
    204           as.loadAnnotations(dc, manager, "QC_GENOTYPE_HET_PCT", Annotationtype.QC_GENOTYPE_HET_PCT, null);
    205           as.loadAnnotations(dc, manager, "QC_GENOTYPE_VERIFIED", Annotationtype.QC_GENOTYPE_VERIFIED, null);
    206           as.setAnnotation("QC_GENOTYPE_STATUS", qcStatus);
    207           Library lib = as.getLibrary(dc);
    208           lib.loadBioPlateLocation();
    209           Rna rna = lib.getRna(dc, false);
    210           Lysate lys = rna != null ? rna.getLysate() : null;
    211           SpecimenTube sp = lys != null ? lys.getSpecimen() : null;
    212          
    213           loadRnaAnnotations(dc, manager, rna);
    214           loadLysateAnnotations(dc, manager, lys);
    215           loadSpecimenAnnotations(dc, manager, sp);
    216           SpecimenData pat = checker.getSpecimenData(as.getItem());
    217           if (pat != null) // Can be null if the item is an external library
    218           {
    219             sp.setAnnotation("patientName", pat.getPatientName());
    220           }
    221          
    222           if (itemsWithoutAlignment != null)
    223           {
    224             // Important that we remove the RNA/Library that we have found and alignment for
    225             if (qiaCubeFilter != null) itemsWithoutAlignment.remove(rna.getExtract());
    226             if (libPlateFilter != null) itemsWithoutAlignment.remove(lib.getExtract());
    227           }
    228          
    229           if (lib != null) as.setAnnotation("lib", lib.asJSONObject());
    230           if (rna != null) as.setAnnotation("rna", rna.asJSONObject());
    231           if (lys != null) as.setAnnotation("lysate", lys.asJSONObject());
    232           if (sp != null) as.setAnnotation("specimen", sp.asJSONObject());
    233           if ("Checked".equals(qcStatus))
    234           {
    235             // Only include "Checked" alignments in genotyping
    236             CompareData cmp = checker.check(dc, as.getItem());
    237             cmp.sortMessages(GenoTypeMessage.SORT_BY_CATEGORY_AND_ALIGNMENT);
    238             JSONObject jsonCompare = cmp.asJSONObject();
    239             as.setAnnotation("compare", jsonCompare);
    240           }
    241           jsonAlignments.add(as.asJSONObject());
    242         }
    243        
    244         if (itemsWithoutAlignment != null && itemsWithoutAlignment.size() > 0)
    245         {
    246           for (Extract e : itemsWithoutAlignment)
    247           {
    248             Library lib = null;
    249             Rna rna = null;
    250             Lysate lys = null;
    251             SpecimenTube sp = null;
    252            
    253             // The item is eiter an RNA or a Library
    254             if (qiaCubeFilter != null)
    255             {
    256               rna = Rna.get(e);
    257               lys = rna.getLysate();
    258               sp = lys.getSpecimen();
    259             }
    260             else if (libPlateFilter != null)
    261             {
    262               lib = Library.get(e);
    263               lib.loadBioPlateLocation();
    264               rna = lib.getRna(dc, false);
    265               // Can be null here if the library is external
    266               if (rna != null) lys = rna.getLysate();
    267               if (lys != null) sp = lys.getSpecimen();
    268             }
    269            
    270             loadRnaAnnotations(dc, manager, rna);
    271             loadLysateAnnotations(dc, manager, lys);
    272             loadSpecimenAnnotations(dc, manager, sp);
    273             SpecimenData pat = checker.getSpecimenData(e);
    274             if (pat != null) // Can be null if the item is an external library
    275             {
    276               sp.setAnnotation("patientName", pat.getPatientName());
    277             }
    278 
    279             JSONObject jsonItemWithoutAlignment = new JSONObject();
    280             if (lib != null) jsonItemWithoutAlignment.put("lib", lib.asJSONObject());
    281             if (rna != null) jsonItemWithoutAlignment.put("rna", rna.asJSONObject());
    282             if (lys != null) jsonItemWithoutAlignment.put("lysate", lys.asJSONObject());
    283             if (sp != null) jsonItemWithoutAlignment.put("specimen", sp.asJSONObject());
    284             jsonAlignments.add(jsonItemWithoutAlignment);
    285           }
    286         }
    287        
    288         json.put("alignments", jsonAlignments);
     149        json.put("alignments", loadFlaggedAlignments(dc, req));
    289150      }
    290151
     
    573434        JSONArray jsonItems = (JSONArray)jsonReq.get("items");
    574435       
    575         int numChanged = 0;
     436        ItemList flagged = BiomaterialList.FLAGGED_ALIGNMENT.get(dc);
     437       
     438        int numReProcess = 0;
     439        int numFlagged = 0;
     440        int numComments = 0;
    576441        for (int itemNo = 0; itemNo < jsonItems.size(); itemNo++)
    577442        {
    578443          JSONObject jsonItem = (JSONObject)jsonItems.get(itemNo);
    579          
    580           Item itemType = Item.valueOf((String)jsonItem.get("type"));
    581           Number itemId = (Number)jsonItem.get("id");
    582          
    583           BioMaterial item = (BioMaterial)itemType.getById(dc, itemId.intValue());
    584           boolean changed = Annotationtype.AUTO_PROCESSING.setAnnotationValue(dc, item, "ReProcess");
    585           if (changed) numChanged++;
    586         }
    587         jsonMessages.add(numChanged + " items has been scheduled for re-processing");
     444          Number alignmentId = (Number)jsonItem.get("id");
     445         
     446          JSONObject jsonReProcess = (JSONObject)jsonItem.get("reprocess");
     447          if (jsonReProcess != null)
     448          {
     449            Item itemType = Item.valueOf((String)jsonReProcess.get("type"));
     450            Number itemId = (Number)jsonReProcess.get("id");
     451            BioMaterial item = (BioMaterial)itemType.getById(dc, itemId.intValue());
     452            boolean changed = Annotationtype.AUTO_PROCESSING.setAnnotationValue(dc, item, "ReProcess");
     453            if (changed) numReProcess++;
     454          }
     455         
     456          DerivedBioAssay alignment = alignmentId != null ? DerivedBioAssay.getById(dc, alignmentId.intValue()) : null;
     457          if (alignment != null)
     458          {
     459            if (Boolean.TRUE.equals(jsonItem.get("flag")))
     460            {
     461              if (flagged.add(alignment)) numFlagged++;
     462            }
     463            if (jsonItem.containsKey("comment"))
     464            {
     465              String comment = (String)jsonItem.get("comment");
     466              boolean changed = Annotationtype.QC_GENOTYPE_COMMENT.setAnnotationValue(dc, alignment, comment);
     467              if (changed) numComments++;
     468            }
     469           
     470          }
     471        }
     472        if (numReProcess > 0) jsonMessages.add(numReProcess + " items has been scheduled for re-processing");
     473        if (numFlagged > 0) jsonMessages.add(numFlagged + " alignments have been flagged");
     474        if (numComments > 0) jsonMessages.add(numComments + " comments have been updated");
     475        dc.commit();
     476       
     477        // Reload flagged alignments so that the browser can update the table
     478        dc = sc.newDbControl();
     479        json.put("alignments", loadFlaggedAlignments(dc, req));
    588480        dc.commit();
    589481      }
     
    705597  }
    706598
     599  @SuppressWarnings("unchecked")
     600  private JSONArray loadFlaggedAlignments(DbControl dc, HttpServletRequest req)
     601  {
     602    GenoTypeChecker checker = new GenoTypeChecker();
     603   
     604    String libPlateFilter = req.getParameter("libPlateFilter");
     605    String qiaCubeFilter = req.getParameter("qiaCubeFilter");
     606    boolean highHetFilter = Values.getBoolean(req.getParameter("highHetFilter"));
     607   
     608    checker.preloadVcfForFlaggedAlignments(dc);
     609    checker.preloadSpecimenData(dc);
     610   
     611    ItemQuery<DerivedBioAssay> query = checker.getFlaggedAlignments(dc);
     612    // When we have a filter we want to load information about all items on the
     613    // given QiaCube/LibPlate. We fill this Set with all RNA/Library items and then
     614    // remove them as we find alignments. Remaining items in this Set have no alignment (that we can use)
     615    Set<Extract> itemsWithoutAlignment = null;
     616    if (qiaCubeFilter != null)
     617    {
     618      Date qcDate = Reggie.CONVERTER_STRING_TO_DATE.convert(qiaCubeFilter.substring(0, 8));
     619      int runNo = Values.getInt(qiaCubeFilter.substring(9));
     620     
     621      ItemQuery<Extract> rnaQuery = checker.getRnaRelatedToQiacube(dc, qcDate, runNo);
     622      itemsWithoutAlignment = new HashSet<>(rnaQuery.list(dc));
     623      query = checker.getAlignmentsRelatedToItems(dc, itemsWithoutAlignment, true, true);
     624    }
     625    else if (libPlateFilter != null)
     626    {
     627      ItemQuery<Extract> libQuery = checker.getLibrariesRelatedToLibPlate(dc, libPlateFilter);
     628      itemsWithoutAlignment = new HashSet<>(libQuery.list(dc));
     629      query = checker.getAlignmentsRelatedToItems(dc, itemsWithoutAlignment, true, true);
     630    }
     631    else if (highHetFilter)
     632    {
     633      query = checker.getAlignmentsWithHighHet(dc, true);
     634    }
     635    query.order(Orders.asc(Hql.property("name")));
     636   
     637    List<AlignedSequences> list = AlignedSequences.toList(query.list(dc));
     638    SnapshotManager manager = new SnapshotManager();
     639
     640    if (qiaCubeFilter != null || libPlateFilter != null || highHetFilter)
     641    {
     642      for (AlignedSequences as : list)
     643      {
     644        DerivedBioAssay alignment = as.getDerivedBioAssay();
     645        String qcStatus = (String)Annotationtype.QC_GENOTYPE_STATUS.getAnnotationValue(dc, manager, alignment);
     646        if ("Checked".equals(qcStatus))
     647        {
     648          // Only include "Checked" alignments in genotyping
     649          checker.preload(dc, as.getDerivedBioAssay());
     650        }
     651      }
     652    }
     653   
     654    JSONArray jsonAlignments = new JSONArray();       
     655    for (AlignedSequences as : list)
     656    {
     657      String qcStatus = (String)Annotationtype.QC_GENOTYPE_STATUS.getAnnotationValue(dc, manager, as.getItem());
     658      as.loadAnnotations(dc, manager, "QC_GENOTYPE_HET_PCT", Annotationtype.QC_GENOTYPE_HET_PCT, null);
     659      as.loadAnnotations(dc, manager, "QC_GENOTYPE_VERIFIED", Annotationtype.QC_GENOTYPE_VERIFIED, null);
     660      as.loadAnnotations(dc, manager, "QC_GENOTYPE_COMMENT", Annotationtype.QC_GENOTYPE_COMMENT, null);
     661      as.setAnnotation("QC_GENOTYPE_STATUS", qcStatus);
     662      Library lib = as.getLibrary(dc);
     663      lib.loadBioPlateLocation();
     664      Rna rna = lib.getRna(dc, false);
     665      Lysate lys = rna != null ? rna.getLysate() : null;
     666      SpecimenTube sp = lys != null ? lys.getSpecimen() : null;
     667     
     668      loadRnaAnnotations(dc, manager, rna);
     669      loadLysateAnnotations(dc, manager, lys);
     670      loadSpecimenAnnotations(dc, manager, sp);
     671      SpecimenData pat = checker.getSpecimenData(as.getItem());
     672      if (pat != null) // Can be null if the item is an external library
     673      {
     674        sp.setAnnotation("patientName", pat.getPatientName());
     675      }
     676     
     677      if (itemsWithoutAlignment != null)
     678      {
     679        // Important that we remove the RNA/Library that we have found and alignment for
     680        if (qiaCubeFilter != null) itemsWithoutAlignment.remove(rna.getExtract());
     681        if (libPlateFilter != null) itemsWithoutAlignment.remove(lib.getExtract());
     682      }
     683     
     684      if (lib != null) as.setAnnotation("lib", lib.asJSONObject());
     685      if (rna != null) as.setAnnotation("rna", rna.asJSONObject());
     686      if (lys != null) as.setAnnotation("lysate", lys.asJSONObject());
     687      if (sp != null) as.setAnnotation("specimen", sp.asJSONObject());
     688      if ("Checked".equals(qcStatus))
     689      {
     690        // Only include "Checked" alignments in genotyping
     691        CompareData cmp = checker.check(dc, as.getItem());
     692        cmp.sortMessages(GenoTypeMessage.SORT_BY_CATEGORY_AND_ALIGNMENT);
     693        JSONObject jsonCompare = cmp.asJSONObject();
     694        as.setAnnotation("compare", jsonCompare);
     695      }
     696      jsonAlignments.add(as.asJSONObject());
     697    }
     698   
     699    if (itemsWithoutAlignment != null && itemsWithoutAlignment.size() > 0)
     700    {
     701      for (Extract e : itemsWithoutAlignment)
     702      {
     703        Library lib = null;
     704        Rna rna = null;
     705        Lysate lys = null;
     706        SpecimenTube sp = null;
     707       
     708        // The item is eiter an RNA or a Library
     709        if (qiaCubeFilter != null)
     710        {
     711          rna = Rna.get(e);
     712          lys = rna.getLysate();
     713          sp = lys.getSpecimen();
     714        }
     715        else if (libPlateFilter != null)
     716        {
     717          lib = Library.get(e);
     718          lib.loadBioPlateLocation();
     719          rna = lib.getRna(dc, false);
     720          // Can be null here if the library is external
     721          if (rna != null) lys = rna.getLysate();
     722          if (lys != null) sp = lys.getSpecimen();
     723        }
     724       
     725        loadRnaAnnotations(dc, manager, rna);
     726        loadLysateAnnotations(dc, manager, lys);
     727        loadSpecimenAnnotations(dc, manager, sp);
     728        SpecimenData pat = checker.getSpecimenData(e);
     729        if (pat != null) // Can be null if the item is an external library
     730        {
     731          sp.setAnnotation("patientName", pat.getPatientName());
     732        }
     733
     734        JSONObject jsonItemWithoutAlignment = new JSONObject();
     735        if (lib != null) jsonItemWithoutAlignment.put("lib", lib.asJSONObject());
     736        if (rna != null) jsonItemWithoutAlignment.put("rna", rna.asJSONObject());
     737        if (lys != null) jsonItemWithoutAlignment.put("lysate", lys.asJSONObject());
     738        if (sp != null) jsonItemWithoutAlignment.put("specimen", sp.asJSONObject());
     739        jsonAlignments.add(jsonItemWithoutAlignment);
     740      }
     741    }
     742   
     743    return jsonAlignments;
     744  }
     745 
    707746}
Note: See TracChangeset for help on using the changeset viewer.