Changeset 2492


Ignore:
Timestamp:
Aug 8, 2006, 12:57:45 PM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #196: Transformation.newProduct should create child BioAssays? if possible

Location:
trunk/src
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/core/net/sf/basedb/core/AnnotatedItem.java

    r2304 r2492  
    5959      as = AnnotationSet.getNew(dc, this);
    6060      getData().setAnnotationSet(as.getData());
    61       dc.saveItem(as);
     61      dc.saveItemIf(this, as);
    6262    }
    6363    return as;
  • trunk/src/core/net/sf/basedb/core/AnnotationSet.java

    r2304 r2492  
    258258      a = Annotation.getNew(dc, annotationType, this);
    259259      getData().getAnnotations().put(annotationType.getData(), a.getData());
    260       dc.saveItem(a);
     260      dc.saveItemIf(this, a);
    261261    }
    262262    return a;
  • trunk/src/core/net/sf/basedb/core/DbControl.java

    r2378 r2492  
    3535
    3636import java.util.Iterator;
     37import java.util.LinkedList;
    3738import java.util.List;
    3839import java.util.ArrayList;
     
    9192  private Map<BasicItem, Transactional.Action> commitQueue;
    9293
     94  /**
     95    Lists items that are saved only if the parent item is also saved.
     96    @see #saveItemIf(BasicItem, BasicItem)
     97  */
     98  private Map<BasicItem, List<BasicItem>> saveIfQueue;
     99 
    93100  /**
    94101    A list of batchers that will be closed when <code>DbControl</code> is
     
    288295    itemCache.clear();
    289296    if (batchers != null) batchers.clear();
     297    if (saveIfQueue != null) saveIfQueue.clear();
     298    saveIfQueue = null;
    290299    commitQueue = null;
    291300    itemCache = null;
     
    805814    item.checkPermission(Permission.CREATE);
    806815    commitQueue.put(item, Transactional.Action.CREATE);
     816   
     817    // Check save-if queue
     818    if (saveIfQueue != null)
     819    {
     820      List<BasicItem> items = saveIfQueue.remove(item);
     821      if (items != null)
     822      {
     823        for (BasicItem cItem : items)
     824        {
     825          if (!cItem.isInDatabase()) saveItem(cItem);
     826        }
     827      }
     828    }
     829  }
     830 
     831  /**
     832    Schedule a new item to be saved in the database if another item is also saved.
     833    If the <code>itemIf</code> item is saved then <code>item</code> is also saved,
     834    otherwise it is not. The method is useful for utility methods that creates a lot
     835    of child items to a parent item and we wan't to wait putting them in the real
     836    save queue until the parent item is saved. If the parent item is already in the
     837    database or saveItem(itemIf) has been called this method is the same as
     838    <code>saveItem(item)</code>
     839   
     840    @param itemIf The parent item that must be saved
     841    @param item The item to save when the parent item is saved
     842    @see #saveItem(BasicItem)
     843   */
     844  public void saveItemIf(BasicItem itemIf, BasicItem item)
     845  {
     846    if (itemIf == null || item == null) return;
     847    if (itemIf.isInDatabase() || commitQueue.containsKey(itemIf))
     848    {
     849      saveItem(item);
     850    }
     851    else
     852    {
     853      if (saveIfQueue == null) saveIfQueue = new HashMap<BasicItem, List<BasicItem>>();
     854      List<BasicItem> items = saveIfQueue.get(itemIf);
     855      if (items == null)
     856      {
     857        items = new LinkedList<BasicItem>();
     858        saveIfQueue.put(itemIf, items);
     859      }
     860      items.add(item);
     861    }
    807862  }
    808863 
  • trunk/src/core/net/sf/basedb/core/Directory.java

    r2474 r2492  
    100100
    101101  /**
    102     Create a new <code>Directory</code> from a path. Every directory that doesnt exist is created.
     102    Create a new <code>Directory</code> from a path. Every directory that doesn't
     103    exist is created.
    103104   
    104105    @param dc The {@link DbControl} which will be used for
  • trunk/src/core/net/sf/basedb/core/RawBioAssay.java

    r2474 r2492  
    427427  /**
    428428    Get the {@link SpotImages} item used to generate spot images
    429     for this raw bio assay. If no <code>SpotImages</code> exists
     429    for this raw bioassay. If no <code>SpotImages</code> exists
    430430    a new one is created, and is automatically saved to the database (if
    431431    commit is called).
     
    442442    {
    443443      spotImages = SpotImages.getNew(getDbControl(), this);
    444       getDbControl().saveItem(spotImages);
     444      getDbControl().saveItemIf(this, spotImages);
    445445    }
    446446    else
  • trunk/src/core/net/sf/basedb/core/Transformation.java

    r2382 r2492  
    415415      a new layer is created. Specify 'null' to use the same layer as the
    416416      source bioassayset.
     417    @param createChildBioAssays TRUE to create one child bioassay for
     418      each bioassay in the source bioassay set. This requires that
     419      the product is created in the same data cube as the source
     420      bioassay set, ie. namedCube should be null
    417421    @return The new bioassayset
    418422    @throws PermissionDeniedException If the logged in user doesn't have
     
    423427    @throws BaseException If there is another error
    424428  */
    425   public BioAssaySet newProduct(String namedCube, String namedLayer)
     429  public BioAssaySet newProduct(String namedCube, String namedLayer, boolean createChildBioAssays)
    426430    throws PermissionDeniedException, InvalidDataException, BaseException
    427431  {
     
    453457      namedLayers.put(namedLayer, layer);
    454458    }
    455     return BioAssaySet.getNew(getDbControl(), this, layer);
     459    BioAssaySet newBas = BioAssaySet.getNew(getDbControl(), this, layer);
     460   
     461    if (namedCube == null && createChildBioAssays)
     462    {
     463      DbControl dc = getDbControl();
     464      BioAssaySet source = getSource();
     465      for (BioAssay parentBa : source.getBioAssays().list(dc))
     466      {
     467        BioAssay childBa = newBas.newBioAssay(parentBa);
     468        dc.saveItemIf(newBas, childBa);
     469      }
     470    }
     471    return newBas;
    456472  }
    457473
  • trunk/src/core/net/sf/basedb/core/Well.java

    r2474 r2492  
    128128      as = AnnotationSet.getNew(dc, this);
    129129      getData().setAnnotationSet(as.getData());
    130       dc.saveItem(as);
     130      dc.saveItemIf(this, as);
    131131    }
    132132    return as;
  • trunk/src/core/net/sf/basedb/util/BioAssaySetFilterUtil.java

    r2399 r2492  
    100100    // Create Transformation
    101101    Transformation t = parent.newTransformation(job);
     102    dc.saveItem(t);
    102103
    103104    // Create the filtered BioAssaySet in the same datacube and layer
    104     BioAssaySet child = t.newProduct(null, null);
     105    BioAssaySet child = t.newProduct(null, null, true);
    105106    child.setName("Filtered " + parent.getName());
    106     dc.saveItem(t);
    107107    dc.saveItem(child);
    108108
     
    146146    if (progress != null) progress.display(10, "Filtering spots (0 done; "+spotsTotal+" total)...");
    147147   
    148     // Create child bioassays and filter
     148    // Create filter
    149149    for (BioAssay parentBa : parent.getBioAssays().list(dc))
    150150    {
    151       BioAssay childBa = child.newBioAssay(parentBa);
    152       dc.saveItem(childBa);
    153 
    154151      spotsDone += parentBa.getNumSpots();
    155       query.setParameter("column", (int)childBa.getDataCubeColumnNo(), Type.INT);
     152      query.setParameter("column", (int)parentBa.getDataCubeColumnNo(), Type.INT);
    156153      spotsAfter += filterBatcher.insert(query);
    157154
     
    187184    // Create Transformation
    188185    Transformation t = parent.newTransformation(job);
     186    dc.saveItem(t);
    189187
    190188    // Create the filtered BioAssaySet in the same datacube and layer
    191     BioAssaySet child = t.newProduct(null, null);
     189    BioAssaySet child = t.newProduct(null, null, true);
    192190    child.setName("Filtered " + parent.getName());
    193     dc.saveItem(t);
    194191    dc.saveItem(child);
    195 
    196     // Create child bioassays
    197     for (BioAssay parentBa : parent.getBioAssays().list(dc))
    198     {
    199       BioAssay childBa = child.newBioAssay(parentBa);
    200       dc.saveItem(childBa);
    201     }
    202192   
    203193    // Create the batchers we need
  • trunk/src/core/net/sf/basedb/util/IntensityCalculatorUtil.java

    r2322 r2492  
    141141    // Create Transformation
    142142    Transformation t = experiment.newTransformation(job, rawBioAssays);
     143    dc.saveItem(t);
    143144
    144145    // Create the root BioAssaySet in a new data cube and layer
    145     BioAssaySet root = t.newProduct("new", "new");
     146    BioAssaySet root = t.newProduct("new", "new", false);
    146147    root.setName("New root bioassayset");
    147     dc.saveItem(t);
    148148    dc.saveItem(root);
    149149
     
    242242    // Create Transformation
    243243    Transformation t = experiment.newTransformation(job, rawBioAssays);
     244    dc.saveItem(t);
    244245   
    245246    if (progress != null) progress.display(5, "Initialising...");
    246247
    247248    // Create the root BioAssaySet in a new data cube and layer
    248     BioAssaySet root = t.newProduct("new", "new");
     249    BioAssaySet root = t.newProduct("new", "new", false);
    249250    root.setName("New root bioassayset");
    250     dc.saveItem(t);
    251251    dc.saveItem(root);
    252252
     
    256256    MappingBatcher rawBatcher = root.getMappingBatcher();
    257257
    258     // A cache holding already seen postion --> reporter mappings
     258    // A cache holding already seen position --> reporter mappings
    259259    Map<Integer, ReporterData> positionCache = new HashMap<Integer, ReporterData>();
    260260   
  • trunk/src/plugins/core/net/sf/basedb/plugins/Base1PluginExecuter.java

    r2485 r2492  
    720720      if (section.name().equals("assays"))
    721721      {
    722         bas = t.newProduct("new", "new");
     722        bas = t.newProduct("new", "new", false);
    723723        bas.setName("Something after");
    724724        dc.saveItem(bas);
  • trunk/src/plugins/core/net/sf/basedb/plugins/LowessNormalization.java

    r2474 r2492  
    205205        t.setName(about.getName());
    206206        dc.saveItem(t);
    207         BioAssaySet childBioAssaySet = t.newProduct(null, "new");
     207        BioAssaySet childBioAssaySet = t.newProduct(null, "new", true);
    208208        childBioAssaySet.setName(childName == null ? bioAssaySet.getName() : childName);
    209209        dc.saveItem(childBioAssaySet);
     
    242242        for (BioAssay assay : assays)
    243243        {
    244           dc.saveItem(childBioAssaySet.newBioAssay(assay));
    245 
    246244          query = assay.getSpotData();
    247245          query = assay.getSpotData();
  • trunk/src/plugins/core/net/sf/basedb/plugins/MedianRatioNormalization.java

    r2474 r2492  
    192192        t.setName(about.getName());
    193193        dc.saveItem(t);
    194         BioAssaySet child = t.newProduct(null, "new");
     194        BioAssaySet child = t.newProduct(null, "new", true);
    195195        child.setName(bioAssaySet.getName());
    196196        dc.saveItem(child);
     
    217217        for (BioAssay assay : assays)
    218218        {
    219           dc.saveItem(child.newBioAssay(assay));
    220          
    221219          query = assay.getSpotData();
    222220          query.restrict(intensityRestriction);
  • trunk/src/test/TestExperiment.java

    r2419 r2492  
    612612     
    613613      Transformation t = source.newTransformation(null);
    614       BioAssaySet bas = t.newProduct(null, "new");
     614      dc.saveItem(t);
     615
     616      BioAssaySet bas = t.newProduct(null, "new", true);
    615617      bas.setName("Second bioassayset");
    616       dc.saveItem(t);
    617618      dc.saveItem(bas);
    618619
    619620      int numSpots = 0;
    620       for (BioAssay sourceBa : source.getBioAssays().list(dc))
    621       {
    622         BioAssay ba = bas.newBioAssay(sourceBa);
    623         dc.saveItem(ba);
    624       }
    625 
    626621      SpotBatcher spotBatcher = bas.getSpotBatcher();
    627622     
     
    696691     
    697692      Transformation t = source.newTransformation(null);
    698       BioAssaySet bas = t.newProduct(null, null);
     693      dc.saveItem(t);
     694
     695      BioAssaySet bas = t.newProduct(null, null, true);
    699696      bas.setName("Filtered bioassayset");
    700       dc.saveItem(t);
    701697      dc.saveItem(bas);
    702 
    703       for (BioAssay sourceBa : source.getBioAssays().list(dc))
    704       {
    705         BioAssay ba = bas.newBioAssay(sourceBa);
    706         dc.saveItem(ba);
    707       }
    708698
    709699      DynamicSpotQuery query = source.getSpotData();
     
    765755     
    766756      Transformation t = source.newTransformation(null);
    767       BioAssaySet bas = t.newProduct(null, null);
     757      dc.saveItem(t);
     758
     759      BioAssaySet bas = t.newProduct(null, null, true);
    768760      bas.setName("Extra spot values bioassayset");
    769       dc.saveItem(t);
    770761      dc.saveItem(bas);
    771      
    772       for (BioAssay sourceBa : source.getBioAssays().list(dc))
    773       {
    774         BioAssay ba = bas.newBioAssay(sourceBa);
    775         dc.saveItem(ba);
    776       }
    777      
     762
    778763      SpotExtraValueBatcher<Integer> intBatcher = null;
    779764      if (intExtraId != 0)
     
    847832     
    848833      Transformation t = source.newTransformation(null);
    849       BioAssaySet bas = t.newProduct(null, null);
     834      dc.saveItem(t);
     835
     836      BioAssaySet bas = t.newProduct(null, null, true);
    850837      bas.setName("Extra position values bioassayset");
    851       dc.saveItem(t);
    852838      dc.saveItem(bas);
    853      
    854       for (BioAssay sourceBa : source.getBioAssays().list(dc))
    855       {
    856         BioAssay ba = bas.newBioAssay(sourceBa);
    857         dc.saveItem(ba);
    858       }
    859839     
    860840      PositionExtraValueBatcher<Integer> intBatcher = null;
Note: See TracChangeset for help on using the changeset viewer.