Changeset 1758


Ignore:
Timestamp:
Nov 30, 2012, 8:43:12 AM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #436: Import mRNA quality control results

Implemented a registration that incldues a PDF file, creation date, protocol, operator and comments (for the plate). Need to add a way to add comments per biomaterial if that is needed.

The registration also prepares for the cDNA step by creating the cDNA child plate and biomaterial (without creation date).

Location:
extensions/net.sf.basedb.reggie/branches/ticket-422
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/branches/ticket-422/resources/index.jsp

    r1757 r1758  
    292292            <li><a href="libprep/mrna_protocol.jsp?ID=<%=ID%>">Lab tracking protocol for mRNA and cDNA preparation</a>
    293293            <li><a href="?ID=<%=ID%>">Export files for mRNA quality control</a>
    294             <li><a href="?ID=<%=ID%>">Import mRNA quality control results</a>
     294            <li><a href="libprep/mrna_registration.jsp?ID=<%=ID%>">Import mRNA quality control results</a>
    295295            <li><a href="?ID=<%=ID%>">cDNA registration</a>
    296296            </ul>
  • extensions/net.sf.basedb.reggie/branches/ticket-422/resources/reggie.js

    r1726 r1758  
    2424{
    2525  if (event.keyCode == 9)
     26  {
     27    setTimeout(method, 200);
     28  }
     29  return true;
     30}
     31
     32/**
     33  Execute the given method when the ENTER key is pressed. A short
     34  delay is added so the method doesn't interfer with normal event
     35  handling.
     36 
     37  @param event The event object with information about what happened
     38  @param method The method to execute when ENTER is pressed
     39*/
     40function doOnEnter(event, method)
     41{
     42  if (event.keyCode == 13)
    2643  {
    2744    setTimeout(method, 200);
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/dao/ReactionPlate.java

    r1695 r1758  
    1010import net.sf.basedb.core.BioMaterial;
    1111import net.sf.basedb.core.BioPlate;
     12import net.sf.basedb.core.BioPlateEvent;
    1213import net.sf.basedb.core.BioPlateType;
    1314import net.sf.basedb.core.BioWell;
    1415import net.sf.basedb.core.DbControl;
    1516import net.sf.basedb.core.HasAnnotationRestriction;
     17import net.sf.basedb.core.Include;
    1618import net.sf.basedb.core.InvalidDataException;
     19import net.sf.basedb.core.Item;
    1720import net.sf.basedb.core.ItemQuery;
    1821import net.sf.basedb.core.ItemSubtype;
     
    267270  }
    268271
     272  /**
     273    Find all bioplate events for the current bioplate. If
     274    a role is specified, the list is filter to only
     275    include events where the bioplate has the given role.
     276    @since 2.x
     277  */
     278  public List<BioPlateEvent> findEvents(DbControl dc, String role)
     279  {
     280    ItemQuery<BioPlateEvent> query = getItem().getEvents();
     281    if (role != null)
     282    {
     283      // Restrict on role
     284      query.restrict(Restrictions.eq(
     285        Hql.property(Item.BIOPLATEEVENTPARTICIPANT.getAlias(), "role"), Expressions.string(role)));
     286    }
     287    query.setIncludes(Include.ALL);
     288    return query.list(dc);
     289  }
    269290 
    270291  @SuppressWarnings("unchecked")
  • extensions/net.sf.basedb.reggie/branches/ticket-422/src/net/sf/basedb/reggie/servlet/MRnaServlet.java

    r1745 r1758  
    22
    33import java.io.IOException;
     4import java.util.Date;
    45import java.util.HashMap;
    56import java.util.List;
     
    1516import org.json.simple.parser.JSONParser;
    1617
     18import net.sf.basedb.core.AnyToAny;
    1719import net.sf.basedb.core.Application;
     20import net.sf.basedb.core.BioMaterialEvent;
    1821import net.sf.basedb.core.BioMaterialEventSource;
    1922import net.sf.basedb.core.BioPlate;
     
    2528import net.sf.basedb.core.DbControl;
    2629import net.sf.basedb.core.Extract;
     30import net.sf.basedb.core.File;
    2731import net.sf.basedb.core.Include;
     32import net.sf.basedb.core.InvalidDataException;
    2833import net.sf.basedb.core.ItemQuery;
    2934import net.sf.basedb.core.ItemSubtype;
    3035import net.sf.basedb.core.PlateGeometry;
     36import net.sf.basedb.core.Protocol;
    3137import net.sf.basedb.core.SessionControl;
    3238import net.sf.basedb.core.Type;
     
    3945import net.sf.basedb.reggie.dao.BioplateType;
    4046import net.sf.basedb.reggie.dao.MRna;
     47import net.sf.basedb.reggie.dao.ReactionPlate;
    4148import net.sf.basedb.reggie.dao.Rna;
    4249import net.sf.basedb.reggie.dao.Subtype;
     
    280287        jsonMessages.add("Created " + mRnaPlate.getName() + " with " + jsonWells.size() + " mRNA child items");
    281288      }
     289     
     290      else if ("ImportMRnaQCResults".equals(cmd))
     291      {
     292        JSONObject jsonReq = (JSONObject)new JSONParser().parse(req.getReader());
     293       
     294        Number bioPlateId = (Number)jsonReq.get("bioplate");
     295        Number pdfId = (Number)jsonReq.get("pdf");
     296        Number mrnaProtocolId = (Number)jsonReq.get("mrnaProtocol");
     297
     298        dc = sc.newDbControl();
     299       
     300        // Load mRNA plate and the creation event
     301        ReactionPlate mrnaReactionPlate = ReactionPlate.getById(dc, bioPlateId.intValue(), BioplateType.MRNA);
     302        BioPlate mrnaPlate = mrnaReactionPlate.getBioPlate();
     303       
     304        // Find the creation event for the mRNA plate
     305        List<BioPlateEvent> events = mrnaReactionPlate.findEvents(dc, "destination");
     306        if (events.size() > 1)
     307        {
     308          throw new InvalidDataException("Found > 1 creation event for mRNA plate: " + mrnaReactionPlate.getName());
     309        }
     310        // ...it may not exist if a plate has been created with a batch import...
     311        BioPlateEvent mrnaPlateCreationEvent = events.size() == 0 ? null : events.get(0);
     312       
     313        // Set creation date and protocol
     314        Date mrnaDate = Reggie.CONVERTER_STRING_TO_DATE.convert((String)jsonReq.get("mrnaDate"));
     315        mrnaPlate.setEventDate(mrnaDate);
     316        Protocol mrnaProtocol = mrnaProtocolId == null ? null : Protocol.getById(dc, mrnaProtocolId.intValue());
     317        if (mrnaPlateCreationEvent != null)
     318        {
     319          // This automatically propagated to all mRNA items on the plate
     320          mrnaPlateCreationEvent.setEventDate(mrnaDate);
     321          mrnaPlateCreationEvent.setProtocol(mrnaProtocol);
     322        }
     323
     324        // Link PDF file with the mRNA plate
     325        File pdf = File.getById(dc, pdfId.intValue());
     326        AnyToAny ata = AnyToAny.getNewOrExisting(dc, mrnaPlate, "PDF printout", pdf, true);
     327        if (!ata.isInDatabase()) dc.saveItem(ata);
     328        jsonMessages.add("Attached file '" + pdf.getName() + "' to plate " + mrnaPlate.getName());
     329       
     330        // Operator is an annotation
     331        String operator = Values.getStringOrNull((String)jsonReq.get("mrnaOperator"));
     332        Annotationtype.QC_OPERATOR.setAnnotationValue(dc, mrnaPlate, operator);
     333       
     334       
     335        // Comment about the plate
     336        mrnaPlate.setDescription((String)jsonReq.get("comment"));
     337
     338        // Flag so that it will not appear in the wizards next time
     339        mrnaPlate.setDestroyed(true);
     340     
     341        // Prepare cDNA child plate
     342        String cdnaPlateName = mrnaPlate.getName().replace("mRNA", "cDNA");
     343        BioPlate cdnaPlate = BioPlate.getNew(dc, BioplateType.CDNA.getPlateGeometry(dc), BioplateType.CDNA.load(dc));
     344        cdnaPlate.setName(cdnaPlateName);
     345        dc.saveItem(cdnaPlate);
     346       
     347        // Create plate event...
     348        BioPlateEventType eventType = BioPlateEventType.getById(dc, BioPlateEventType.CREATE_BIOMATERIAL);
     349        BioPlateEvent event = BioPlateEvent.getNew(dc, eventType);
     350        event.setName("Create cDNA child plate");
     351        dc.saveItem(event);
     352       
     353        //... with parent (mRNA) and child (cDNA) plate
     354        BioPlateEventParticipant cdnaCreation = event.addParticipant(cdnaPlate, "child", 1);
     355        event.addParticipant(mrnaPlate, "parent", 1);
     356        dc.saveItem(cdnaCreation);
     357
     358        List<BioWell> wells = mrnaPlate.getBioWells().list(dc);
     359        int numCdna = 0;
     360        ItemSubtype cdnaType = Subtype.CDNA.load(dc);
     361        for (BioWell well : wells)
     362        {
     363          if (!well.isEmpty())
     364          {
     365            Extract mrna = (Extract)well.getBioMaterial();
     366            if (mrnaPlateCreationEvent == null)
     367            {
     368              // If no plate event existed, we must set protocol and date on all mRNA items
     369              BioMaterialEvent evt = mrna.getCreationEvent();
     370              evt.setEventDate(mrnaDate);
     371              evt.setProtocol(mrnaProtocol);
     372            }
     373            Extract cdna = Extract.getNew(dc, cdnaCreation);
     374            cdna.setName(mrna.getName()+".c");
     375            cdna.setItemSubtype(cdnaType);
     376            cdna.setBioWell(cdnaPlate.getBioWell(well.getPlateCoordinate()));
     377            cdna.getCreationEvent().setSource(mrna);
     378            dc.saveItem(cdna);
     379            numCdna++;
     380          }
     381        }
     382       
     383        jsonMessages.add(numCdna + " cDNA items created");
     384       
     385        jsonMessages.add("Prepared child cDNA plate '" + cdnaPlateName + "' for future processing");
     386       
     387        dc.commit();
     388      }
    282389
    283390      json.put("messages", jsonMessages);
     391     
    284392    }
    285393    catch (Throwable t)
Note: See TracChangeset for help on using the changeset viewer.