Changeset 1966


Ignore:
Timestamp:
May 8, 2013, 9:36:48 AM (9 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #488: Add support for matching RNAQC items using location instead of names from the Caliper Well Table file

A side effect is that a simple change (using the doImport method instead of preValidate) made it possible to display all warnings immediately.

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

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/sampleproc/rnaqc_plate_import.jsp

    r1915 r1966  
    6060  if (lastExtension == 'csv')
    6161  {
    62     preValidateCsvFile();
     62    setTimeout(preValidateCsvFile, 100);
    6363  }
    6464  else
     
    7676  if (!csvId) return;
    7777 
     78  Main.hide('messages');
     79  Main.addClass(document.body, 'please-wait');
     80  setInputStatus('csv', 'Checking...', 'checking');
     81
    7882  var url = '../RnaQc.servlet?ID=<%=ID%>&cmd=PreValidateCaliperResults&csv='+csvId;
    7983 
    8084  var request = Ajax.getXmlHttpRequest();
    81   request.open("POST", url, false);
     85  Ajax.setReadyStateHandler(request, onCsvValidated);
     86  request.open("POST", url, true); 
    8287  request.send('');
    8388 
     89}
     90
     91function onCsvValidated(request)
     92{
     93  Main.removeClass(document.body, 'please-wait');
    8494  if (debug) Main.debug(request.responseText);
    8595  var response = JSON.parse(request.responseText); 
    8696 
     97  var numWarnings = 0;
    8798  if (response.messages && response.messages.length > 0)
    8899  {
     
    90101    for (var i = 0; i < response.messages.length; i++)
    91102    {
    92       messages += '<li>' + response.messages[i];
     103      var msgLine = response.messages[i];
     104      if (msgLine.indexOf('[Warning]') >= 0)
     105      {
     106        messages += '<li class="warning">' + msgLine.replace('[Warning]', '');
     107        numWarnings++;
     108      }
     109      else
     110      {
     111        messages += '<li>' + msgLine;
     112      }
    93113    }
    94114    messages += '</ul>';
     
    110130  }
    111131
    112   setInputStatus('csv', '', 'valid');
     132  setInputStatus('csv', '', numWarnings > 0 ? 'warning' : 'valid');
    113133  hasValidatedCsv = true;
    114134 
     
    167187 
    168188  Main.hide('goimport');
     189  Main.hide('messages');
    169190
    170191  frm['csv.path'].disabled = true;
     
    268289</script>
    269290
     291<style>
     292body.please-wait
     293{
     294  cursor: wait !important;
     295}
     296</style>
    270297
    271298</base:head>
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/plugins/CaliperPlateImporter.java

    r1963 r1966  
    159159  }
    160160 
    161   public boolean doPreValidate(DbControl dc, InputStream in, int maxDataLines)
    162     throws IOException
    163   {
    164     errorMessages.clear();
    165    
    166     FlatFileParser ffp = getFlatFileParser();
    167     ffp.setInputStream(in, "UTF-8");
    168    
    169     if (ffp.parseHeaders() != LineType.DATA_HEADER)
    170     {
    171       addErrorMessage("Could not find header line starting with 'Plate Name,Well Label,Sample Name...'");
    172       return false; // Can't continue if no data is found in the file
    173     }
    174    
    175     // Check that all annotation columns are found
    176     for (String col : annotations.keySet())
    177     {
    178       if (ffp.getColumnHeaderIndex(col) == null)
    179       {
    180         addErrorMessage("Column '" + col + "' not found in column headers.");
    181       }
    182     }
    183    
    184     if (hasError()) return false;
    185    
    186     Mapper plateMapper = ffp.getMapper("\\Plate Name\\");
    187     Mapper wellMapper = ffp.getMapper("\\Well Label\\");
    188     Mapper nameMapper = ffp.getMapper("\\Sample Name\\");
    189     Map<String,Integer> locations = new HashMap<String, Integer>();
    190    
    191     int numExtractsByName = 0;
    192     int numExtractsByLocation = 0;
    193 
    194     while (ffp.hasMoreData() && (maxDataLines == -1 || maxDataLines > ffp.getParsedDataLines()))
    195     {
    196       boolean errorOnThisLine = false;
    197       FlatFileParser.Data data = ffp.nextData();
    198       int lineNo = ffp.getParsedLines();
    199      
    200       // Check that the "Plate Name" is a valid entry
    201       String plateName = plateMapper.getValue(data);
    202       if (plate == null)
    203       {
    204         plate = findBioPlate(dc, plateName, lineNo);
    205         if (plate == null) errorOnThisLine = true;
    206       }
    207       else
    208       {
    209         if (!checkBioPlate(dc, plateName, plate, lineNo))
    210         {
    211           errorOnThisLine = true;
    212         }
    213       }
    214      
    215       if (errorOnThisLine) break; // stop validation
    216      
    217       // Check that the "Sample Name" column maps to a valid extract
    218       String extractName = nameMapper.getValue(data);
    219       String location = wellMapper.getValue(data);
    220      
    221       Extract extract = null;
    222       if (allowMatchAgainstLocation && extractName.matches("\\w\\d\\d?"))
    223       {
    224         extract = findExtractByLocation(dc, plate, extractName, lineNo);
    225         if (extract != null)
    226         {
    227           numExtractsByLocation++;
    228           addWarningMessage("[Warning] Line " + lineNo + ": No sample name, extract '" + extract.getName() + "' found using location '" + extractName + "'");
    229         }
    230       }
    231       else
    232       {
    233         extract = findExtractByName(dc, plate, extractName, lineNo, location);
    234         if (extract != null) numExtractsByName++;
    235       }
    236      
    237       if (extract == null) continue; // with the next line
    238      
    239       // Validate that the location is the same in BASE and the CSV
    240       if (!checkLocation(dc, extract, location, lineNo)) continue; // with the next line
    241      
    242       // Check that the same location has not been seen before in this file
    243       if (locations.containsKey(location))
    244       {
    245         addErrorMessage("Line " + lineNo + ": Duplicate well '" + location + "' with extract '" + extractName + "'. Also found on line " + locations.get(location) + ".");
    246         continue; // with the next line
    247       }
    248       locations.put(location, lineNo);
    249     }
    250    
    251     if (numExtractsByLocation > numExtractsByName)
    252     {
    253       addErrorMessage("Too many lines have location instead of 'Sample name': " + numExtractsByLocation + " of " + (numExtractsByLocation+numExtractsByName));
    254     }
    255     return !hasError();
    256   }
    257  
    258161  /**
    259162    Import data from the input stream.
    260163    @param in
    261164  */
    262   public boolean doImport(DbControl dc, InputStream in)
     165  public boolean doImport(DbControl dc, InputStream in, boolean validateOnly)
    263166    throws IOException
    264167  {
    265168    numImported = 0;
    266169    errorMessages.clear();
     170    warningMessages.clear();
    267171    Map<String,Integer> locations = new HashMap<String, Integer>();
    268172
     
    394298         
    395299          Object val = at.getValueType().parseString(sval);
    396           as.getAnnotation(at).setValue(val);
     300          if (!validateOnly)
     301          {
     302            as.getAnnotation(at).setValue(val);
     303          }
    397304         
    398305          // For debugging
     
    423330          }
    424331         
    425           if (val != null) as.getAnnotation(at).setValue(val);
     332          if (!validateOnly)
     333          {
     334            if (val != null) as.getAnnotation(at).setValue(val);
     335          }
    426336
    427337          // For debugging
     
    441351    if (numExtractsByLocation > numExtractsByName)
    442352    {
    443       addErrorMessage("Too many lines have location instead of 'Sample name': " + numExtractsByLocation);
     353      addErrorMessage("Too many lines have location instead of 'Sample name': " + numExtractsByLocation + " of " + (numExtractsByLocation+numExtractsByName));
    444354    }
    445355
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/LibPrepServlet.java

    r1964 r1966  
    414414        dc = sc.newDbControl();
    415415        File csv = File.getById(dc, csvId);
     416        AnnotationType size = Annotationtype.CA_SIZE.load(dc);
    416417       
    417418        CaliperPlateImporter cpi = new CaliperPlateImporter(BioplateType.LIBRARY.getPlateNamePrefix());
    418         cpi.setAnnotationMapping("Region[180-600] Size [BP]", null); // safe to use 'null' when validating
     419        cpi.setAnnotationMapping("Region[180-600] Size [BP]", size);
    419420        cpi.setBioPlate(BioPlate.getById(dc, libPlateId));
    420421        cpi.setAllowMatchAgainstLocation(true); // Allow a few lines to have location coordinates instead of lib name
    421         if (cpi.doPreValidate(dc, csv.getDownloadStream(0), -1))
     422        if (cpi.doImport(dc, csv.getDownloadStream(0), true))
    422423        {
    423424          // The validation was ok -- but there may be some warnings.
     
    538539          addQubitFileLookups(cpi, qubitCsv, qubitConcType, speedVacConcType);
    539540         
    540           if (cpi.doImport(dc, wellTableCsv.getDownloadStream(0)))
     541          if (cpi.doImport(dc, wellTableCsv.getDownloadStream(0), false))
    541542          {
    542543            // The import was successful
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/RnaQcServlet.java

    r1963 r1966  
    367367        dc = sc.newDbControl();
    368368        File csv = File.getById(dc, csvId);
     369        AnnotationType rqs = Annotationtype.CA_RQS.load(dc);
    369370       
    370371        CaliperPlateImporter cpi = new CaliperPlateImporter(BioplateType.CALIPER_RNAQC.getPlateNamePrefix());
    371         cpi.setAnnotationMapping("RNA Quality Score", null); // safe to use 'null' when validating
    372        
    373         if (cpi.doPreValidate(dc, csv.getDownloadStream(0), 5))
    374         {
     372        cpi.setAnnotationMapping("RNA Quality Score", rqs);
     373        cpi.setAllowMatchAgainstLocation(true); // Allow a few lines to have location coordinates instead of rnaqc name
     374       
     375        if (cpi.doImport(dc, csv.getDownloadStream(0), true))
     376        {
     377          // The validation was ok -- but there may be some warnings.
     378          if (cpi.hasWarning())
     379          {
     380            jsonMessages.addAll(cpi.getWarningMessages());
     381          }
     382         
    375383          // The validation was ok
    376384          BioPlate plate = cpi.getBioPlate();
     
    406414        CaliperPlateImporter cpi = new CaliperPlateImporter(BioplateType.CALIPER_RNAQC.getPlateNamePrefix());
    407415        cpi.setAnnotationMapping("RNA Quality Score", rqs);
    408        
    409         if (cpi.doImport(dc, csv.getDownloadStream(0)))
     416        cpi.setAllowMatchAgainstLocation(true);
     417       
     418        if (cpi.doImport(dc, csv.getDownloadStream(0), false))
    410419        {
    411420          // The import was successful
Note: See TracChangeset for help on using the changeset viewer.