Changeset 1546


Ignore:
Timestamp:
Mar 2, 2012, 1:19:02 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #366: Import annotations and other information from Caliper output

The important features has been implemented. There is still some more to do on the error handling side and maybe also on the usability side.

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

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/css/reggie.css

    r1544 r1546  
    109109  list-style-image: url('../images/ok.png');
    110110}
     111.failure ul
     112{
     113  list-style-image: url('../images/error.png');
     114}
    111115
    112116.reporttable
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/Reggie.java

    r1543 r1546  
    221221  */
    222222  public static final String ANNOTATION_QC_OPERATOR = "QCOperator";
     223
     224  /**
     225    The name of the "BA_RIN" annotation, used
     226    for extract (RNAQC). It is a float annotation type
     227    @since 2.4
     228  */
     229  public static final String ANNOTATION_BA_RIN = "BA_RIN";
     230
    223231 
    224232  /**
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/InstallServlet.java

    r1543 r1546  
    2525import net.sf.basedb.core.ItemKey;
    2626import net.sf.basedb.core.ItemSubtype;
     27import net.sf.basedb.core.MimeType;
    2728import net.sf.basedb.core.MultiPermissions;
    2829import net.sf.basedb.core.Permission;
     
    3435import net.sf.basedb.reggie.Reggie;
    3536import net.sf.basedb.reggie.dao.BioplateType;
     37import net.sf.basedb.reggie.dao.Mimetype;
    3638import net.sf.basedb.reggie.dao.Subtype;
    3739import net.sf.basedb.util.EqualsHelper;
     
    117119        jsonChecks.add(checkBioplateType(dc, BioplateType.CALIPER_RNAQC, createIfMissing));
    118120       
     121        // MIME types
     122        jsonChecks.add(checkMimeType(dc, Mimetype.GDX, createIfMissing));
     123       
    119124        // Annotation type checks
    120125        // -- the first batch need to be shared to the PatientCurator group
     
    179184            null, effectiveOptions, createIfMissing));
    180185        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_QC_OPERATOR, new Item[] { Item.BIOPLATE}, Type.STRING, 1,
     186            null, effectiveOptions, createIfMissing));
     187        jsonChecks.add(checkAnnotationType(dc, Reggie.ANNOTATION_BA_RIN, new Item[] { Item.EXTRACT }, Type.FLOAT, 1,
    181188            null, effectiveOptions, createIfMissing));
    182189       
     
    209216            Reggie.ANNOTATION_QC_RUN_DATE, Reggie.ANNOTATION_QC_OPERATOR));
    210217       
    211 
    212218        jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.DNA, createIfMissing));
    213219
    214         jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.RNAQC, createIfMissing));
     220        jsonChecks.add(checkAnnotationTypeCategory(dc, Subtype.RNAQC, createIfMissing,
     221            Reggie.ANNOTATION_BA_RIN));
    215222       
    216223        json.put("checks", jsonChecks);
     
    854861  }
    855862
     863  /**
     864    Create a MIME type with the given options. The type is created in
     865    a separate transaction.
     866    @since 2.4
     867  */
     868  public MimeType createMimeType(SessionControl sc, Mimetype def)
     869  {
     870    MimeType type = null;
     871    DbControl dc = sc.newDbControl();
     872    try
     873    {
     874      type = MimeType.getNew(dc);
     875      type.setName(def.getMimeType());
     876      type.setExtension(def.getExtension());
     877      type.setDescription(def.getDescription());
     878      if (def.getFileType() != null)
     879      {
     880        type.setFileType(def.getFileType().load(dc));
     881      }
     882     
     883      dc.saveItem(type);
     884      dc.commit();
     885    }
     886    finally
     887    {
     888      if (dc != null) dc.close();
     889    }
     890    return type;
     891  }
     892
     893 
     894  /**
     895    Check for an existing MIME type with the given options.
     896    A JSONObject is returned with the result. The following
     897    keys are used:
     898    <ul>
     899    <li>itemType: MIMETYPE
     900    <li>name: The name of the subtype
     901    <li>id: The id of the subtype if it exists
     902    <li>mainType: The main item type that the subtype applies to
     903    <li>status: ok, error, or missing
     904    <li>message: A descriptive message in case of an error
     905    </ul>
     906    @since 2.4
     907  */
     908  @SuppressWarnings("unchecked")
     909  public JSONObject checkMimeType(DbControl dc, Mimetype mimeType,
     910    boolean createIfMissing)
     911  {
     912 
     913    JSONObject json = new JSONObject();
     914    JSONArray jsonMessages = new JSONArray();
     915    json.put("itemType", Item.MIMETYPE.name());
     916    json.put("name", mimeType.getDescription());
     917    json.put("mimeType", mimeType.getMimeType());
     918    json.put("extension", mimeType.getExtension());
     919     
     920    List<MimeType> result = mimeType.list(dc);
     921    if (result.size() == 0)
     922    {
     923      if (createIfMissing)
     924      {
     925        MimeType type = createMimeType(dc.getSessionControl(), mimeType);
     926        json.put("id", type.getId());
     927        json.put("status", "ok");
     928        jsonMessages.add("Created");
     929      }
     930      else
     931      {
     932        json.put("status", "missing");
     933        jsonMessages.add("Not found");
     934      }
     935    }
     936    else if (result.size() > 1)
     937    {
     938      json.put("status", "error");
     939      jsonMessages.add("Found > 1 MIME type");
     940    }
     941    else
     942    {
     943      MimeType s = result.get(0);
     944      json.put("id", s.getId());
     945      json.put("status", "ok"); // For now -- more checks below
     946     
     947      if (!s.getName().equals(mimeType.getMimeType()))
     948      {
     949        json.put("status", "error");
     950        jsonMessages.add("Should have '" + mimeType.getMimeType() + "' as MIME type.");
     951      }
     952     
     953    }
     954    if (jsonMessages.size() == 0) jsonMessages.add("Ok");
     955    json.put("messages", jsonMessages);
     956    return json;
     957 
     958  }
     959
    856960
    857961  /**
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/RnaQcServlet.java

    r1544 r1546  
    1515import org.json.simple.parser.JSONParser;
    1616
     17import net.sf.basedb.core.AnnotationSet;
     18import net.sf.basedb.core.AnnotationType;
    1719import net.sf.basedb.core.Application;
    1820import net.sf.basedb.core.BioPlate;
     
    2325import net.sf.basedb.core.DbControl;
    2426import net.sf.basedb.core.Extract;
     27import net.sf.basedb.core.File;
     28import net.sf.basedb.core.Item;
    2529import net.sf.basedb.core.ItemNotFoundException;
    2630import net.sf.basedb.core.ItemQuery;
     
    3337import net.sf.basedb.reggie.dao.Rna;
    3438import net.sf.basedb.reggie.dao.Subtype;
     39import net.sf.basedb.reggie.plugins.CaliperPlateImporter;
    3540import net.sf.basedb.reggie.plugins.CaliperSampleNameExporter;
    3641import net.sf.basedb.util.Coordinate;
     
    267272        }
    268273       
     274        dc.commit();
     275      }
     276      else if ("PreValidateCaliperResults".equals(cmd))
     277      {
     278        int csvId = Values.getInt(req.getParameter("csv"));
     279       
     280        dc = sc.newDbControl();
     281        File csv = File.getById(dc, csvId);
     282       
     283        CaliperPlateImporter cpi = new CaliperPlateImporter();
     284        cpi.setAnnotationMapping("RNA Quality Score", null); // safe to use 'null' when validating
     285       
     286        if (cpi.doPreValidate(dc, csv.getDownloadStream(0)))
     287        {
     288          // The validation was ok
     289          BioPlate plate = cpi.getBioPlate();
     290          ReactionPlate rnaQc = ReactionPlate.getById(dc, plate.getId());
     291          AnnotationType qcRunDate = Reggie.findAnnotationType(dc, Item.BIOPLATE, Reggie.ANNOTATION_QC_RUN_DATE, false);
     292          AnnotationType qcOperator = Reggie.findAnnotationType(dc, Item.BIOPLATE, Reggie.ANNOTATION_QC_OPERATOR, false);
     293          if (qcRunDate != null)
     294          {
     295            rnaQc.loadAnnotations("QCRunDate", qcRunDate, Reggie.CONVERTER_DATE_TO_STRING);
     296          }
     297          if (qcOperator != null)
     298          {
     299            rnaQc.loadAnnotations("QCOperator", qcOperator, null);
     300          }
     301          JSONObject jsonPlate = rnaQc.asJSONObject();
     302         
     303          json.put("plate", jsonPlate);
     304        }
     305        else
     306        {
     307          json.put("status", "error");
     308          json.put("message", "Validation failed");
     309          jsonMessages.addAll(cpi.getErrorMessages());
     310        }
     311       
     312      }
     313      else if ("ImportCaliperResults".equals(cmd))
     314      {
     315        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());
     316
     317        Number csvId = (Number)jsonReq.get("csv");
     318        Number gxdId = (Number)jsonReq.get("gxd");
     319        Number pdfId = (Number)jsonReq.get("pdf");
     320       
     321        dc = sc.newDbControl();
     322        AnnotationType qcRunDate = Reggie.findAnnotationType(dc, Item.BIOPLATE, Reggie.ANNOTATION_QC_RUN_DATE, true);
     323        AnnotationType qcOperator = Reggie.findAnnotationType(dc, Item.BIOPLATE, Reggie.ANNOTATION_QC_OPERATOR, true);
     324        AnnotationType rin = Reggie.findAnnotationType(dc, Item.EXTRACT, Reggie.ANNOTATION_BA_RIN, true);
     325       
     326        File csv = File.getById(dc, csvId.intValue());
     327       
     328        CaliperPlateImporter cpi = new CaliperPlateImporter();
     329        cpi.setAnnotationMapping("RNA Quality Score", rin);
     330       
     331        if (cpi.doImport(dc, csv.getDownloadStream(0)))
     332        {
     333          // The import was successful
     334          BioPlate plate = cpi.getBioPlate();
     335          jsonMessages.add("Imported data to " + cpi.getNumImported() + " extracts on plate " + plate.getName());
     336         
     337          // Attach the files we used to the bioplate
     338          cpi.attachFile(dc, csv, "CSV file");
     339          jsonMessages.add("Attached file '" + csv.getName() + "' to plate " + plate.getName());
     340          if (gxdId != null)
     341          {
     342            File gxd = File.getById(dc, gxdId.intValue());
     343            cpi.attachFile(dc, gxd, "LabView GX raw data");
     344            jsonMessages.add("Attached file '" + gxd.getName() + "' to plate " + plate.getName());
     345          }
     346          if (pdfId != null)
     347          {
     348            File pdf = File.getById(dc, pdfId.intValue());
     349            cpi.attachFile(dc, pdf, "PDF printout");
     350            jsonMessages.add("Attached file '" + pdf.getName() + "' to plate " + plate.getName());
     351          }
     352         
     353          AnnotationSet as = plate.getAnnotationSet();
     354          as.getAnnotation(qcRunDate).setValue(Reggie.CONVERTER_STRING_TO_DATE.convert((String)jsonReq.get("QCRunDate")));
     355          as.getAnnotation(qcOperator).setValue(jsonReq.get("QCOperator"));
     356         
     357          plate.setDestroyed(true);
     358          dc.commit();
     359         
     360        }
     361        else
     362        {
     363          jsonMessages.addAll(cpi.getErrorMessages());
     364          json.put("status", "error");
     365          json.put("message", "Import failed from file: " + csv.getName());
     366        }
     367       
    269368      }
    270369     
    271       dc.commit();
     370
    272371      json.put("messages", jsonMessages);
    273 
    274372     
    275373    }
Note: See TracChangeset for help on using the changeset viewer.