Changeset 6092


Ignore:
Timestamp:
Aug 27, 2012, 11:16:54 AM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #1707: Make it possible for a derived bioassay to have multiple physical bioassays as parents

Fixed the derived bioassay batch importer.

Location:
trunk/src
Files:
4 edited

Legend:

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

    r6085 r6092  
    3434import java.util.Set;
    3535
     36import net.sf.basedb.core.Transactional.Action;
    3637import net.sf.basedb.core.data.ArrayBatchData;
    3738import net.sf.basedb.core.data.ArrayDesignData;
    3839import net.sf.basedb.core.data.ArraySlideData;
    3940import net.sf.basedb.core.data.DerivedBioAssayData;
     41import net.sf.basedb.core.data.ExtractData;
    4042import net.sf.basedb.core.data.HardwareData;
    4143import net.sf.basedb.core.data.PhysicalBioAssayData;
     
    263265    return used || super.isUsed();
    264266  }
     267 
     268  /**
     269    Automatically try to assign an extract from parent items at
     270    creation time.
     271  */
     272  @Override
     273  void onBeforeCommit(Action action)
     274  {
     275    super.onBeforeCommit(action);
     276   
     277    if (action == Action.CREATE && !extractHasBeenSet && !isRoot())
     278    {
     279      ExtractData extract = null;
     280      for (DerivedBioAssayData parent : getData().getParents())
     281      {
     282        ExtractData e = parent.getExtract();
     283        if (extract == null)
     284        {
     285          extract = e;
     286        }
     287        else if (e != null && !extract.equals(e))
     288        {
     289          // Different extracts on different parents --> do not assign
     290          extract = null;
     291          break;
     292        }
     293      }
     294      if (extract != null) getData().setExtract(extract);
     295    }
     296   
     297  }
    265298
    266299  /**
     
    614647  }
    615648 
     649  private boolean extractHasBeenSet;
     650 
    616651  /**
    617652    Set the extract that is the parent of data in this bioassay. The extract
     
    624659    checkPermission(Permission.WRITE);
    625660    if (extract != null) extract.checkPermission(Permission.USE);
     661    extractHasBeenSet = true;
    626662    getData().setExtract(extract == null ? null : extract.getData());
    627663  }
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/DerivedBioAssayImporter.java

    r5986 r6092  
    3030import net.sf.basedb.core.Path;
    3131import net.sf.basedb.core.PathParameterType;
    32 import net.sf.basedb.core.PermissionDeniedException;
    3332import net.sf.basedb.core.PhysicalBioAssay;
    3433import net.sf.basedb.core.Item;
     
    7372        "type is not specified, the importer will try to guess a parent type from the " +
    7473        "item subtype. Example: \\Parent type\\\n\n" +
    75         "NOTE! The parent can't be changed for existing bioassays.",
     74        "NOTE! The parent type can't be changed for existing bioassays.",
    7675        optionalColumnMapping
    7776    );
     
    8685        "Mapping that picks the name or id of the parent item (physical or derived bioassay) " +
    8786        "in the data columns. Example: \\Parent\\\n\n" +
    88         "NOTE! The parent can't be changed for existing bioassays.",
     87        "NOTE! The importer can only add parents, not replace or remove existing parents.",
    8988        optionalColumnMapping
    9089    );
     
    312311      parentType = parentSubtype.getMainItemType();
    313312    }
    314    
    315     DerivedBioAssay bioAssay = null;
    316    
    317     String nameOrId = parentMapper.getValue(data);
    318     if (parentType == Item.DERIVEDBIOASSAY)
    319     {
    320       DerivedBioAssay parent = findDerivedBioAssay(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, parentSubtype);
    321       bioAssay = DerivedBioAssay.getNew(dc, parent, job.getJob());
    322     }
    323     else
    324     {
    325       PhysicalBioAssay pba = findPhysicalBioAssay(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, parentSubtype);
    326       bioAssay = DerivedBioAssay.getNew(dc, pba, job.getJob());
    327     }
    328    
     313    boolean isRoot = parentType != Item.DERIVEDBIOASSAY;
     314    DerivedBioAssay bioAssay = DerivedBioAssay.getNew(dc, isRoot, job.getJob());
     315       
    329316    if (subtype != null) bioAssay.setItemSubtype(subtype);
    330317    updateItem(dc, bioAssay, data);
     
    343330      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.EXTRACT, 0);
    344331      Extract extract = findExtract(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    345       if (extract == null && !bioAssay.isRoot())
    346       {
    347         // No explicit extract found, try the extract on the parent bioassay
    348         try
    349         {
    350           extract = bioAssay.getParent().getExtract();
    351         }
    352         catch (PermissionDeniedException ex)
    353         {}
    354       }
    355332      if (nameOrId == null || extract != null) bioAssay.setExtract(extract);
    356333    }
     
    410387      }
    411388    }
    412   }
     389   
     390    if (parentMapper != null)
     391    {
     392      String nameOrId = parentMapper.getValue(data);
     393      Item parentType = bioAssay.isRoot() ? Item.PHYSICALBIOASSAY : Item.DERIVEDBIOASSAY;
     394     
     395      ItemSubtype parentSubtype = ItemSubtype.getRelatedSubtype(dc, bioAssay, parentType);
     396      if (parentType == Item.DERIVEDBIOASSAY)
     397      {
     398        DerivedBioAssay parent = findDerivedBioAssay(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, parentSubtype);
     399        bioAssay.addParent(parent);
     400      }
     401      else
     402      {
     403        PhysicalBioAssay pba = findPhysicalBioAssay(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, parentSubtype);
     404        bioAssay.addPhysicalBioAssay(pba);
     405      }
     406    }
     407  }
     408 
    413409  /**
    414410    Validate data files if they have been set.
  • trunk/src/test/TestDerivedBioAssay.java

    r6082 r6092  
    2323import net.sf.basedb.core.*;
    2424
     25import java.util.ArrayList;
    2526import java.util.Date;
    2627import java.util.Set;
     
    390391    if (!TestUtil.getSilent())
    391392    {
    392       write("   \tID \tName      \tType\tDescription\tParent\tPhysical bioassay\tProtocol\tHardware\tSoftware");
    393       write("-- \t-- \t--------- \t----\t-----------\t------\t----------------\t---------\t--------\t--------");
     393      write("   \tID \tName      \tType\tDescription\tParents\tPhysical bioassays\tProtocol\tHardware\tSoftware");
     394      write("-- \t-- \t--------- \t----\t-----------\t-------\t------------------\t--------\t--------\t--------");
    394395    }
    395396  }
     
    399400    if (!TestUtil.getSilent())
    400401    {
     402      DbControl dc = dbas.getDbControl();
    401403      System.out.println(i+":\t"+dbas.getId()+"\t"+dbas.getName()+"\t"+dbas.getItemSubtype()+"\t"+dbas.getDescription()+
    402         "\t"+dbas.getParent()+"\t"+dbas.getPhysicalBioAssay()+
     404        "\t"+new ArrayList<DerivedBioAssay>(dbas.getParents().list(dc))+
     405        "\t"+new ArrayList<PhysicalBioAssay>(dbas.getPhysicalBioAssays().list(dc))+
    403406        "\t"+dbas.getProtocol()+"\t"+dbas.getHardware()+"\t"+dbas.getSoftware());
    404407    }
  • trunk/src/test/data/test.batchimport.scans.txt

    r5696 r6092  
    33Scan 2  Scan  The second  Hyb 2 Labeled 2.1 Scanning  Scanner
    44Scan 3  Scan    Hyb all
    5 Child bioassay 1  ChildScan A child to Scan 1 Scan 1 
     5Child bioassay 1  ChildScan Merged scans  Scan 1
     6Child bioassay 1      Scan 2
     7Child bioassay 1      Scan 3 
Note: See TracChangeset for help on using the changeset viewer.