Changeset 6998


Ignore:
Timestamp:
Nov 4, 2015, 8:16:05 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1958: Add Kit item

Implemented a Kit batch importer plug-in and added support for setting Kit in other batch importers:

  • Derived bioassay importer
  • Extract Importer
  • Physical bioassay importer
  • Sample importer
Location:
trunk/src
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/core-plugins.xml

    r6520 r6998  
    547547  </plugin-definition>
    548548
     549  <plugin-definition id="KitImporter">
     550    <about>
     551      <name>Kit importer</name>
     552      <description>
     553        Imports and updates kit items in a batch.
     554      </description>
     555    </about>
     556    <plugin-class>net.sf.basedb.plugins.batchimport.KitImporter</plugin-class>
     557    <settings>
     558      <property name="everyone-use">1</property>
     559    </settings>
     560  </plugin-definition>
     561
    549562  <plugin-definition id="BioSourceImporter">
    550563    <about>
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/AbstractItemImporter.java

    r6898 r6998  
    6868import net.sf.basedb.core.ItemSubtype;
    6969import net.sf.basedb.core.Job;
     70import net.sf.basedb.core.Kit;
    7071import net.sf.basedb.core.NumberOutOfRangeException;
    7172import net.sf.basedb.core.Permission;
     
    219220      optionalColumnMapping
    220221      );
     222 
     223  protected static final PluginParameter<String> kitColumnMapping = new PluginParameter<String>(
     224      "kitColumnMapping",
     225      "Kit",
     226      "Mapping that picks the name or internal ID of a kit from the data columns. The plug-in will first " +
     227      "try to find a kit with the given name. If none is found and the value is numeric it will " +
     228      "try to load by internal ID. " +
     229      "Example: \\Kit\\",
     230      optionalColumnMapping
     231      );
    221232
    222233  protected static final PluginParameter<String> permissionTemplateColumnMapping = new PluginParameter<String>(
     
    11991210    }
    12001211    return findReferencedItemWithSubtype(dc, idMethod, protocolQuery, identifier, subtype, false);
     1212  }
     1213
     1214  private ItemQuery<Kit> kitQuery;
     1215  /**
     1216    Find a kit  with a given identifier. This is a utility method that
     1217    subclasses can use when creating or updating items.
     1218    <p>
     1219    NOTE! The first time this method is called a query object is initialised
     1220    using the {@link IdMethod#prepareQuery(DbControl, ItemQuery)} method.
     1221    Subsequent calls uses the same query. Thus, this method should always be
     1222    called with the same id method object, otherwise the result is undefined.
     1223    <p>
     1224    NOTE! If this method is called with a non-null item subtype parameter and
     1225    no kit is found the query will be retried without any subtype.
     1226   
     1227    @param dc The DbControl to use for database access
     1228    @param identifier The identifier protocol
     1229    @param subtype The kit subtype, or null if the type doesn't matter
     1230    @return A kit, or null if no item could be found
     1231    @since 3.7
     1232  */
     1233  protected Kit findKit(DbControl dc, IdMethod idMethod, String identifier, ItemSubtype subtype)
     1234  {
     1235    if (identifier == null) return null;
     1236    if (kitQuery == null)
     1237    {
     1238      kitQuery = initReferenceQuery(dc, idMethod, Kit.getQuery(), true);
     1239    }
     1240    return findReferencedItemWithSubtype(dc, idMethod, kitQuery, identifier, subtype, false);
    12011241  }
    12021242
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/DerivedBioAssayImporter.java

    r6092 r6998  
    3434import net.sf.basedb.core.ItemQuery;
    3535import net.sf.basedb.core.ItemSubtype;
     36import net.sf.basedb.core.Kit;
    3637import net.sf.basedb.core.PluginParameter;
    3738import net.sf.basedb.core.Protocol;
     
    168169  private Mapper descriptionMapper;
    169170  private Mapper protocolMapper;
     171  private Mapper kitMapper;
    170172  private DefaultItemFunction<Protocol> defaultProtocolFunction;
    171173  private Mapper hardwareMapper;
     
    233235    parameters.add(extractColumnMapping);
    234236    parameters.add(protocolColumnMapping);
     237    parameters.add(kitColumnMapping);
    235238    parameters.add(hardwareColumnMapping);
    236239    parameters.add(softwareColumnMapping);
     
    261264    defaultProtocolFunction = getDefaultItemFunction(Item.PROTOCOL);
    262265    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultProtocolFunction);
     266    kitMapper = getMapper(ffp, (String)job.getValue("kitColumnMapping"), null, null);
    263267    defaultHardwareFunction = getDefaultItemFunction(Item.HARDWARE);
    264268    hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null, defaultHardwareFunction);
     
    339343      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    340344      if (nameOrId == null || protocol != null) bioAssay.setProtocol(protocol);
     345    }
     346    if (kitMapper != null)
     347    {
     348      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, bioAssay, Item.KIT, 0);
     349      String nameOrId = kitMapper.getValue(data);
     350      Kit kit = findKit(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
     351      if (nameOrId == null || kit != null) bioAssay.setKit(kit);
    341352    }
    342353    if (hardwareMapper != null)
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ExtractImporter.java

    r5899 r6998  
    3636import net.sf.basedb.core.ItemQuery;
    3737import net.sf.basedb.core.ItemSubtype;
     38import net.sf.basedb.core.Kit;
    3839import net.sf.basedb.core.PluginParameter;
    3940import net.sf.basedb.core.Protocol;
     
    9697  private Mapper createdMapper;
    9798  private Mapper protocolMapper;
     99  private Mapper kitMapper;
    98100  private DefaultItemFunction<Protocol> defaultPrototolFunction;
    99101  private Mapper parentTypeMapper;
     
    141143    parameters.add(descriptionColumnMapping);
    142144    parameters.add(protocolColumnMapping);
     145    parameters.add(kitColumnMapping);
    143146   
    144147    parameters.add(SampleImporter.createdColumnMapping);
     
    176179    defaultPrototolFunction = getDefaultItemFunction(Item.PROTOCOL);
    177180    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultPrototolFunction);
     181    kitMapper = getMapper(ffp, (String)job.getValue("kitColumnMapping"), null, null);
    178182    parentTypeMapper = getMapper(ffp, (String)job.getValue("parentTypeColumnMapping"), null, null);
    179183    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
     
    218222      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    219223      if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol);
     224    }
     225    if (kitMapper != null)
     226    {
     227      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, extract, Item.KIT, SystemItems.getId(Kit.EXTRACTION));
     228      String nameOrId = kitMapper.getValue(data);
     229      Kit kit = findKit(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
     230      if (nameOrId == null || kit != null) creationEvent.setKit(kit);
    220231    }
    221232    if (bioPlateMapper != null && bioWellRowMapper != null && bioWellColMapper != null)
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/PhysicalBioAssayImporter.java

    r5899 r6998  
    3838import net.sf.basedb.core.ItemQuery;
    3939import net.sf.basedb.core.ItemSubtype;
     40import net.sf.basedb.core.Kit;
    4041import net.sf.basedb.core.Permission;
    4142import net.sf.basedb.core.PermissionDeniedException;
     
    144145  private Mapper hardwareMapper;
    145146  private DefaultItemFunction<Hardware> defaultHardwareFunction;
     147  private Mapper kitMapper;
    146148  private Mapper parentMapper;
    147149  private Mapper usedQuantityMapper;
     
    185187    parameters.add(sizeColumnMapping);
    186188    parameters.add(protocolColumnMapping);
     189    parameters.add(kitColumnMapping);
    187190    parameters.add(hardwareColumnMapping);
    188191   
     
    221224    defaultProtocolFunction = getDefaultItemFunction(Item.PROTOCOL);
    222225    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultProtocolFunction);
     226    kitMapper = getMapper(ffp, (String)job.getValue("kitColumnMapping"), null, null);
    223227    defaultHardwareFunction = getDefaultItemFunction(Item.HARDWARE);
    224228    hardwareMapper = getMapper(ffp, (String)job.getValue("hardwareColumnMapping"), null, null, defaultHardwareFunction);
     
    254258      Protocol protocol = findProtocol(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    255259      if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol);
     260    }
     261    if (kitMapper != null)
     262    {
     263      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, pba, Item.KIT, 0);
     264      String nameOrId = kitMapper.getValue(data);
     265      Kit kit = findKit(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
     266      if (nameOrId == null || kit != null) creationEvent.setKit(kit);
    256267    }
    257268    if (hardwareMapper != null)
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/SampleImporter.java

    r5994 r6998  
    3535import net.sf.basedb.core.ItemQuery;
    3636import net.sf.basedb.core.ItemSubtype;
     37import net.sf.basedb.core.Kit;
    3738import net.sf.basedb.core.PluginParameter;
    3839import net.sf.basedb.core.Protocol;
     
    195196  private Mapper createdMapper;
    196197  private Mapper protocolMapper;
     198  private Mapper kitMapper;
    197199  private DefaultItemFunction<Protocol> defaultPrototolFunction;
    198200  private Mapper parentTypeMapper;
     
    239241    parameters.add(descriptionColumnMapping);
    240242    parameters.add(protocolColumnMapping);
     243    parameters.add(kitColumnMapping);
    241244   
    242245    parameters.add(createdColumnMapping);
     
    273276    defaultPrototolFunction = getDefaultItemFunction(Item.PROTOCOL);
    274277    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null, defaultPrototolFunction);
     278    kitMapper = getMapper(ffp, (String)job.getValue("kitColumnMapping"), null, null);
    275279    parentTypeMapper = getMapper(ffp, (String)job.getValue("parentTypeColumnMapping"), null, null);
    276280    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
     
    307311      if (nameOrId == null || protocol != null) creationEvent.setProtocol(protocol);
    308312    }
     313    if (kitMapper != null)
     314    {
     315      ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, sample, Item.KIT, SystemItems.getId(Kit.SAMPLING));
     316      String nameOrId = kitMapper.getValue(data);
     317      Kit kit = findKit(dc, FallbackIdMethod.NAME_OR_ID, nameOrId, type);
     318      if (nameOrId == null || kit != null) creationEvent.setKit(kit);
     319    }
    309320    if (bioPlateMapper != null && bioWellColMapper != null && bioWellRowMapper != null)
    310321    {
  • trunk/src/test/TestItemImporter.java

    r6875 r6998  
    105105    ok = ok & TestFile.test_list("/file-import/ext", 2);  // 'robots.txt' and 'baselogo.png'
    106106   
     107    // Import kits
     108    int kitFileId = TestFile.test_create("data/test.batchimport.kits.txt", false, false);
     109    int kitImporterId = TestPluginDefinition.test_get("net.sf.basedb.plugins.batchimport.KitImporter");
     110    int kitJobId = test_create_item_import_job(Item.KIT, kitImporterId, kitFileId, 0);
     111    ok = ok & TestJob.test_execute(kitJobId, false);
     112    ok = ok & TestKit.test_list(4);
     113   
    107114    // Import bioplates
    108115    int bioPlateFileId = TestFile.test_create("data/test.batchimport.bioplates.txt", false, false);
     
    253260    TestJob.test_delete(bioPlateJobId);
    254261    TestFile.test_delete(bioPlateFileId);
     262   
     263    // Delete kits
     264    TestKit.test_delete_all();
     265    TestJob.test_delete(kitJobId);
     266    TestFile.test_delete(kitFileId);
    255267   
    256268    // Delete files
     
    402414      request.setParameterValue("subtypeColumnMapping", "\\Type\\");
    403415    }
     416    if (itemType == Item.KIT)
     417    {
     418      request.setParameterValue("expirationDateColumnMapping", "\\Expiration date\\");
     419      request.setParameterValue("subtypeColumnMapping", "\\Kit type\\");
     420    }
    404421    if (itemType == Item.BIOPLATE)
    405422    {
     
    417434      request.setParameterValue("externalIdColumnMapping", "\\External ID\\");
    418435      request.setParameterValue("protocolColumnMapping", "=default(col('Protocol'))");
     436      request.setParameterValue("kitColumnMapping", "\\Kit\\");
    419437      request.setParameterValue("createdColumnMapping", "\\Created\\");
    420438      request.setParameterValue("originalQuantityColumnMapping", "\\Original quantity\\");
     
    434452      request.setParameterValue("sizeColumnMapping", "\\Size\\");
    435453      request.setParameterValue("protocolColumnMapping", "=default(col('Protocol'))");
     454      request.setParameterValue("kitColumnMapping", "\\Kit\\");
    436455      request.setParameterValue("hardwareColumnMapping", "=default()");
    437456      request.setParameterValue("createdColumnMapping", "\\Created\\");
  • trunk/src/test/TestKit.java

    r6990 r6998  
    88import net.sf.basedb.core.ItemSubtype;
    99import net.sf.basedb.core.Kit;
     10import net.sf.basedb.core.Trashcan;
    1011import net.sf.basedb.core.ItemResultList;
    1112
     
    5253    int id2 = test_create(0, null, false);
    5354    test_load(id1);
    54     test_list();
     55    test_list(-1);
    5556
    5657    int extractId = TestExtract.test_create(0, "Extract with kit", 0, 0, false);
     
    164165  }
    165166 
    166   static void test_list()
     167  static boolean test_list(int expectedResults)
    167168  {
    168169    DbControl dc = null;
     
    175176        write_item(i, l.get(i));
    176177      }
     178      if (expectedResults >=0 && expectedResults != l.size())
     179      {
     180        throw new BaseException("Expected " + expectedResults + " results, " +
     181            "not " + l.size());
     182      }
    177183      write("--List kits OK ("+l.size()+")");
    178184    }
     
    187193      if (dc != null) dc.close();
    188194    }
     195    return ok;
    189196  }
    190197 
     
    243250    }
    244251  }
     252 
     253  static void test_delete_all()
     254  {
     255    DbControl dc = null;
     256    try
     257    {
     258      dc = TestUtil.getDbControl();
     259      ItemResultList<Kit> l = Kit.getQuery().list(dc);
     260      int numDeleted = Trashcan.delete(dc.getSessionControl(), l, true, null);
     261      if (numDeleted != l.size()) throw new BaseException("Could not delete all items: " + numDeleted + " of " + l.size());
     262      dc.commit();
     263      write("--Delete all kits OK ("+l.size()+")");
     264    }
     265    catch (Throwable ex)
     266    {
     267      write("--Delete all kits FAILED");
     268      ex.printStackTrace();
     269      ok = false;
     270    }
     271    finally
     272    {
     273      if (dc != null) dc.close();
     274    }
     275  }
    245276
    246277}
  • trunk/src/test/data/test.batchimport.extracts.txt

    r5667 r6998  
    1 Name  Description External ID Parent type Parent  Used quantity Created Original quantity Protocol
    2 Extract 1.1 First extract from smp.1.1  ext.1.1   Sample 1.1  50  2008-01-01  200 Extraction
    3 Extract 2.1 Second sample from smp.1.1  ext.2.1   Sample 2.1  50  2008-01-01  350 Extraction
     1Name  Description External ID Parent type Parent  Used quantity Created Original quantity Protocol  Kit
     2Extract 1.1 First extract from smp.1.1  ext.1.1   Sample 1.1  50  2008-01-01  200 Extraction  Extraction kit
     3Extract 2.1 Second sample from smp.1.1  ext.2.1   Sample 2.1  50  2008-01-01  350 Extraction  Extraction kit
    44Extract X An extract with no parent or other info
    55Pooled extract  A pool of 1.1 and 2.1 ext.pooled  EXTRACT Extract 1.1 50  2008-01-02  150 Pooling
  • trunk/src/test/data/test.batchimport.hybridizations.txt

    r5649 r6998  
    1 Name  Description Size  Protocol  Hardware  Array slide Created Parent  Used quantity Position
    2 Hyb 1 The first 1 Hybridization Hybstation  Slide 1.2 2008-01-01  Labeled 1.1 50
    3 Hyb 1             Labeled 1.2 50
    4 Hyb 2 The second  1 Hybridization Hybstation  Slide 2.1 2008-01-01  Labeled 2.1 50
    5 Hyb 2             Labeled 2.2 50
    6 Hyb all Hyb with 2 arrays 2 Hybridization Hybstation  202 2008-01-01  Labeled 1.1 50  1
    7 Hyb all             Labeled 1.2 50  1
    8 Hyb all             Labeled 2.1 50  2
    9 Hyb all             Labeled 2.2 50  2
     1Name  Description Size  Protocol  Kit Hardware  Array slide Created Parent  Used quantity Position
     2Hyb 1 The first 1 Hybridization Hybridization kit Hybstation  Slide 1.2 2008-01-01  Labeled 1.1 50
     3Hyb 1               Labeled 1.2 50
     4Hyb 2 The second  1 Hybridization Hybridization kit Hybstation  Slide 2.1 2008-01-01  Labeled 2.1 50
     5Hyb 2               Labeled 2.2 50
     6Hyb all Hyb with 2 arrays 2 Hybridization Hybridization kit Hybstation  202 2008-01-01  Labeled 1.1 50  1
     7Hyb all               Labeled 1.2 50  1
     8Hyb all               Labeled 2.1 50  2
     9Hyb all               Labeled 2.2 50  2
  • trunk/src/test/data/test.batchimport.labeledextracts.txt

    r5667 r6998  
    1 Name  Label Description External ID Parent  Used quantity Created Original quantity Protocol
    2 Labeled 1.1 cy3 cy3 labeled from ext.1.1  lbl.1.1 Extract 1.1 50  2008-01-01  200 Labeling
    3 Labeled 1.2 cy5 cy5 labeled from ext.1.1  lbl.1.2 Extract 1.1 50  2008-01-01  200 Labeling
    4 Labeled 2.1 cy3 cy3 labeled from ext.2.1  lbl.2.1 Extract 2.1 50  2008-01-01  200 Labeling
    5 Labeled 2.2 cy5 cy5 labeled from ext.2.1  lbl.2.2 Extract 2.1 50  2008-01-01  200 Labeling
     1Name  Label Description External ID Parent  Used quantity Created Original quantity Protocol  Kit
     2Labeled 1.1 cy3 cy3 labeled from ext.1.1  lbl.1.1 Extract 1.1 50  2008-01-01  200 Labeling  Labeling kit
     3Labeled 1.2 cy5 cy5 labeled from ext.1.1  lbl.1.2 Extract 1.1 50  2008-01-01  200 Labeling  Labeling kit
     4Labeled 2.1 cy3 cy3 labeled from ext.2.1  lbl.2.1 Extract 2.1 50  2008-01-01  200 Labeling  Labeling kit
     5Labeled 2.2 cy5 cy5 labeled from ext.2.1  lbl.2.2 Extract 2.1 50  2008-01-01  200 Labeling  Labeling kit
    66Labeled X Biotin  A labeled extract with no parent or other info
    77Pooled labeled 1    A pool of 1.1 and 2.1 lbl.pooled.1  Labeled 1.1 100 2008-01-02  200 Pooling
  • trunk/src/test/data/test.batchimport.samples.txt

    r5667 r6998  
    1 Name  Description External ID Parent type Parent  Used quantity Created Original quantity Protocol
    2 Sample 1.1  First sample from bs.1  smp.1.1   Biosource 1   2008-01-01  200 Sampling.id
    3 Sample 2.1  Second sample from bs.1 smp.2.1   Biosource 2   2008-01-01  350 Sampling
     1Name  Description External ID Parent type Parent  Used quantity Created Original quantity Protocol  Kit
     2Sample 1.1  First sample from bs.1  smp.1.1   Biosource 1   2008-01-01  200 Sampling.id Sampling kit
     3Sample 2.1  Second sample from bs.1 smp.2.1   Biosource 2   2008-01-01  350 Sampling  Sampling kit
    44Sample X  A sample with no parent or other info
    55Pooled sample A pool of 1.1 and 2.1 smp.pooled  SAMPLE  Sample 1.1  50  2008-01-02  150 Pooling
Note: See TracChangeset for help on using the changeset viewer.