Changeset 5667


Ignore:
Timestamp:
Jun 23, 2011, 2:06:39 PM (12 years ago)
Author:
Nicklas Nordborg
Message:

References #1153: Handling short read transcript sequence data

Fixes the sample and extract batch importers so that they can import both types of parent items.

Display the 'tag' for an extract in listings and on the view page.

Added 'none' option to parent type filter.

Location:
trunk
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/ExtractImporter.java

    r5663 r5667  
    2626import java.util.Set;
    2727
     28import net.sf.basedb.core.BioMaterial;
    2829import net.sf.basedb.core.BioMaterialEvent;
    2930import net.sf.basedb.core.BioMaterialEventSource;
     
    3738import net.sf.basedb.core.PluginParameter;
    3839import net.sf.basedb.core.Protocol;
    39 import net.sf.basedb.core.Sample;
    4040import net.sf.basedb.core.SystemItems;
    4141import net.sf.basedb.core.Tag;
    4242import net.sf.basedb.core.plugin.GuiContext;
    43 import net.sf.basedb.util.Values;
    4443import net.sf.basedb.util.parser.FlatFileParser;
    4544import net.sf.basedb.util.parser.Mapper;
     
    9695  private Mapper createdMapper;
    9796  private Mapper protocolMapper;
    98   private Mapper pooledMapper;
     97  private Mapper parentTypeMapper;
    9998  private Mapper parentMapper;
    10099  private Mapper usedQuantityMapper;
     
    143142    parameters.add(SampleImporter.createdColumnMapping);
    144143    parameters.add(SampleImporter.originalQuantityColumnMapping);
    145     parameters.add(SampleImporter.pooledColumnMapping);
     144    parameters.add(SampleImporter.parentTypeColumnMapping);
    146145    parameters.add(SampleImporter.parentColumnMapping);
    147146    parameters.add(SampleImporter.usedQuantityColumnMapping);
     
    174173    createdMapper = getMapper(ffp, (String)job.getValue("createdColumnMapping"), null, null);
    175174    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
    176     pooledMapper = getMapper(ffp, (String)job.getValue("pooledColumnMapping"), null, null);
     175    parentTypeMapper = getMapper(ffp, (String)job.getValue("parentTypeColumnMapping"), null, null);
    177176    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
    178177    usedQuantityMapper = getMapper(ffp, (String)job.getValue("usedQuantityColumnMapping"), null, null);
     
    200199    if (createdMapper != null) creationEvent.setEventDate(parseDate(createdMapper.getValue(data)));
    201200    updateItemSubtype(dc, extract, data);
    202     if (pooledMapper != null)
    203     {
    204       //extract.setPooled(Values.getBoolean(pooledMapper.getValue(data)));
    205     }
    206201
    207202    if (tagMapper != null)
     
    232227      }
    233228    }
    234     /*
    235     if (!extract.isPooled())
    236     {
    237     */
    238       if (parentMapper != null)
    239       {
    240         String nameOrId = parentMapper.getValue(data);
    241         ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, extract, Item.SAMPLE, 0);
    242         Sample sample = findSample(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    243         Float usedQuantity = usedQuantityMapper == null ?
    244           null : usedQuantityMapper.getFloat(data);
    245         if (nameOrId == null || sample != null)
     229
     230   
     231    if (parentMapper != null)
     232    {
     233      // Try to find a parent type
     234      Item parentType = extract.getParentType();
     235      // Is it specified in the imported file?
     236      if (parentTypeMapper != null)
     237      {
     238        String type = parentTypeMapper.getValue(data);
     239        if (type != null) parentType = Item.valueOf(type);
     240      }
     241     
     242      // See if we can find a related subtype
     243      ItemSubtype type = null;
     244      if (parentType == null)
     245      {
     246        // If we don't know the parent type, check for both biosurce and sample types
     247        type = ItemSubtype.getRelatedSubtype(dc, extract, Item.SAMPLE, Item.BIOSOURCE);
     248        if (type != null) parentType = type.getMainItemType();
     249      }
     250      else
     251      {
     252        type = ItemSubtype.getRelatedSubtype(dc, extract, parentType);
     253      }
     254
     255      // Try to find either a sample or a biosource
     256      String nameOrId = parentMapper.getValue(data);
     257      BioMaterial parent = null;
     258      if (parentType == Item.EXTRACT)
     259      {
     260        parent = findExtract(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
     261      }
     262      else
     263      {
     264        parent = findSample(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
     265      }
     266      if (nameOrId == null || parent != null)
     267      {
     268        BioMaterialEventSource evtSrc = extract.getCreationEvent().setSource(parent);
     269        if (evtSrc != null)
    246270        {
    247           BioMaterialEventSource evtSrc = extract.getCreationEvent().setSource(sample);
    248           if (evtSrc != null) evtSrc.setUsedQuantity(usedQuantity);
     271          Float usedQuantity = usedQuantityMapper == null ? null : usedQuantityMapper.getFloat(data);
     272          evtSrc.setUsedQuantity(usedQuantity);
    249273        }
    250274      }
    251       /*
    252     }
    253     else
    254     {
    255       updateMultiLineItem(dc, extract, data, 0);
    256     }
    257     */
     275    }
    258276  }
    259277 
     
    265283    FlatFileParser.Data data, int multiLineNum)
    266284  {
    267     if (parentMapper != null) // && extract.isPooled())
     285    if (parentMapper != null && extract.getParentType() == Item.EXTRACT)
    268286    {
    269287      String nameOrId = parentMapper.getValue(data);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/LabeledExtractImporter.java

    r5663 r5667  
    4343import net.sf.basedb.core.query.Hql;
    4444import net.sf.basedb.core.query.Restrictions;
    45 import net.sf.basedb.util.Values;
    4645import net.sf.basedb.util.parser.FlatFileParser;
    4746import net.sf.basedb.util.parser.Mapper;
     
    9998  private Mapper createdMapper;
    10099  private Mapper protocolMapper;
    101   private Mapper pooledMapper;
    102100  private Mapper parentMapper;
    103101  private Mapper usedQuantityMapper;
     
    139137    parameters.add(SampleImporter.createdColumnMapping);
    140138    parameters.add(SampleImporter.originalQuantityColumnMapping);
    141     parameters.add(SampleImporter.pooledColumnMapping);
    142139    parameters.add(SampleImporter.parentColumnMapping);
    143140    parameters.add(SampleImporter.usedQuantityColumnMapping);
     
    178175    createdMapper = getMapper(ffp, (String)job.getValue("createdColumnMapping"), null, null);
    179176    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
    180     pooledMapper = getMapper(ffp, (String)job.getValue("pooledColumnMapping"), null, null);
    181177    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
    182178    usedQuantityMapper = getMapper(ffp, (String)job.getValue("usedQuantityColumnMapping"), null, null);
     
    204200    BioMaterialEvent creationEvent = extract.getCreationEvent();
    205201    if (createdMapper != null) creationEvent.setEventDate(parseDate(createdMapper.getValue(data)));
    206     if (pooledMapper != null)
    207     {
    208       //extract.setPooled(Values.getBoolean(pooledMapper.getValue(data)));
    209     }
     202
    210203    if (protocolMapper != null)
    211204    {
     
    236229      }
    237230    }
    238     /*
    239     if (!extract.isPooled())
    240     {
    241     */
    242       if (parentMapper != null)
     231
     232    if (parentMapper != null)
     233    {
     234      String nameOrId = parentMapper.getValue(data);
     235      Extract parent = findExtract(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId);
     236      Float usedQuantity = usedQuantityMapper == null ?
     237        null : usedQuantityMapper.getFloat(data);
     238      if (nameOrId == null || parent != null)
    243239      {
    244         String nameOrId = parentMapper.getValue(data);
    245         Extract parent = findExtract(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId);
    246         Float usedQuantity = usedQuantityMapper == null ?
    247           null : usedQuantityMapper.getFloat(data);
    248         if (nameOrId == null || parent != null)
    249         {
    250           BioMaterialEventSource evtSrc = extract.getCreationEvent().setSource(parent);
    251           if (evtSrc != null) evtSrc.setUsedQuantity(usedQuantity);
    252         }
     240        BioMaterialEventSource evtSrc = extract.getCreationEvent().setSource(parent);
     241        if (evtSrc != null) evtSrc.setUsedQuantity(usedQuantity);
    253242      }
    254       /*
    255     }
    256     else
    257     {
    258       updateMultiLineItem(dc, extract, data, 0);
    259     }
    260     */
     243    }
    261244  }
    262245 
     
    268251    FlatFileParser.Data data, int multiLineNum)
    269252  {
    270     if (parentMapper != null) // && extract.isPooled())
     253    if (parentMapper != null)
    271254    {
    272255      String nameOrId = parentMapper.getValue(data);
  • trunk/src/plugins/core/net/sf/basedb/plugins/batchimport/SampleImporter.java

    r5663 r5667  
    2626import java.util.Set;
    2727
     28import net.sf.basedb.core.BioMaterial;
    2829import net.sf.basedb.core.BioMaterialEvent;
    2930import net.sf.basedb.core.BioPlate;
    30 import net.sf.basedb.core.BioSource;
    3131import net.sf.basedb.core.BioWell;
    3232import net.sf.basedb.core.DbControl;
     
    3939import net.sf.basedb.core.SystemItems;
    4040import net.sf.basedb.core.plugin.GuiContext;
    41 import net.sf.basedb.util.Values;
    4241import net.sf.basedb.util.parser.FlatFileParser;
    4342import net.sf.basedb.util.parser.Mapper;
     
    8584 
    8685  /**
    87     Column mapping parameter for the pooled property.
    88   */
    89   protected static final PluginParameter<String> pooledColumnMapping =
    90     new PluginParameter<String>(
    91         "pooledColumnMapping",
    92         "Pooled",
    93         "Mapping that picks the data column specifying if an item is pooled or not. " +
    94         "Recognised values are empty, 0, 1, true, false, yes and no. Other values will be " +
    95         "treated as pooled. Example: \\Pooled\\",
    96         optionalColumnMapping
    97     );
    98 
    99   /**
    100     Column mapping parameter for the parent (biosource OR pooled sample)
     86    Column mapping parameter for the parent type.
     87  */
     88  protected static final PluginParameter<String> parentTypeColumnMapping =
     89    new PluginParameter<String>(
     90        "parentTypeColumnMapping",
     91        "Parent type",
     92        "Mapping that picks the data column specifying the type of parent item. " +
     93        "Recognised values are BIOSOURCE, SAMPLE and EXTRACT, but only two of them are " +
     94        "valid for each importer. If the parent type is not specified, the importer will " +
     95        "try to guess a parent type from the item subtype. Example: \\Parent type\\",
     96        optionalColumnMapping
     97    );
     98
     99  /**
     100    Column mapping parameter for the parent (biosource OR sample)
    101101  */
    102102  protected static final PluginParameter<String> parentColumnMapping =
     
    193193  private Mapper createdMapper;
    194194  private Mapper protocolMapper;
    195   private Mapper pooledMapper;
     195  private Mapper parentTypeMapper;
    196196  private Mapper parentMapper;
    197197  private Mapper usedQuantityMapper;
     
    239239    parameters.add(createdColumnMapping);
    240240    parameters.add(originalQuantityColumnMapping);
    241     parameters.add(pooledColumnMapping);
     241    parameters.add(parentTypeColumnMapping);
    242242    parameters.add(parentColumnMapping);
    243243    parameters.add(usedQuantityColumnMapping);
     
    269269    createdMapper = getMapper(ffp, (String)job.getValue("createdColumnMapping"), null, null);
    270270    protocolMapper = getMapper(ffp, (String)job.getValue("protocolColumnMapping"), null, null);
    271     pooledMapper = getMapper(ffp, (String)job.getValue("pooledColumnMapping"), null, null);
     271    parentTypeMapper = getMapper(ffp, (String)job.getValue("parentTypeColumnMapping"), null, null);
    272272    parentMapper = getMapper(ffp, (String)job.getValue("parentColumnMapping"), null, null);
    273273    usedQuantityMapper = getMapper(ffp, (String)job.getValue("usedQuantityColumnMapping"), null, null);
     
    295295    if (createdMapper != null) creationEvent.setEventDate(parseDate(createdMapper.getValue(data)));
    296296    updateItemSubtype(dc, sample, data);
    297     if (pooledMapper != null)
    298     {
    299       //sample.setPooled(Values.getBoolean(pooledMapper.getValue(data)));
    300     }
    301297    if (protocolMapper != null)
    302298    {
     
    318314      }
    319315    }
    320     /*
    321     if (!sample.isPooled())
     316
     317    if (parentMapper != null)
    322318    {
    323     */
    324       if (parentMapper != null)
    325       {
    326         String nameOrId = parentMapper.getValue(data);
    327         ItemSubtype type = ItemSubtype.getRelatedSubtype(dc, sample, Item.BIOSOURCE, 0);
    328         BioSource bioSource = findBioSource(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
    329         if (nameOrId == null || bioSource != null) sample.getCreationEvent().setSource(bioSource);
    330       }
    331       /*
     319      // Try to find a parent type
     320      Item parentType = sample.getParentType();
     321      // Is it specified in the imported file?
     322      if (parentTypeMapper != null)
     323      {
     324        String type = parentTypeMapper.getValue(data);
     325        if (type != null) parentType = Item.valueOf(type);
     326      }
     327     
     328      // See if we can find a related subtype
     329      ItemSubtype type = null;
     330      if (parentType == null)
     331      {
     332        // If we don't know the parent type, check for both biosurce and sample types
     333        type = ItemSubtype.getRelatedSubtype(dc, sample, Item.BIOSOURCE, Item.SAMPLE);
     334        if (type != null) parentType = type.getMainItemType();
     335      }
     336      else
     337      {
     338        type = ItemSubtype.getRelatedSubtype(dc, sample, parentType);
     339      }
     340     
     341      // Try to find either a sample or a biosource
     342      String nameOrId = parentMapper.getValue(data);
     343      BioMaterial parent = null;
     344      if (parentType == Item.SAMPLE)
     345      {
     346        parent = findSample(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
     347      }
     348      else
     349      {
     350        parent = findBioSource(dc, FallbackIdMethod.NAME_OR_EXTERNALID_OR_ID, nameOrId, type);
     351      }
     352      if (nameOrId == null || parent != null) sample.getCreationEvent().setSource(parent);
    332353    }
    333     else
    334     {
    335       updateMultiLineItem(dc, sample, data, 0);
    336     }
    337     */
    338354  }
    339355 
     
    345361    FlatFileParser.Data data, int multiLineNum)
    346362  {
    347     if (parentMapper != null) // && sample.isPooled())
     363    if (parentMapper != null && sample.getParentType() == Item.SAMPLE)
    348364    {
    349365      String nameOrId = parentMapper.getValue(data);
  • trunk/src/test/TestItemImporter.java

    r5652 r5667  
    140140    ok &= TestJob.test_execute(hybJobId, false);
    141141    TestPhysicalBioAssay.test_list(3);
    142    
     142
    143143    // Import scans
    144144    /*
     
    208208    TestJob.test_delete(extractJobId);
    209209    TestFile.test_delete(extractFileId);
    210    
     210
    211211    // Delete samples
    212212    TestSample.test_delete_all();
     
    351351      request.setParameterValue("createdColumnMapping", "\\Created\\");
    352352      request.setParameterValue("originalQuantityColumnMapping", "\\Original quantity\\");
    353       request.setParameterValue("pooledColumnMapping", "\\Pooled\\");
     353      request.setParameterValue("parentTypeColumnMapping", "\\Parent type\\");
    354354      request.setParameterValue("parentColumnMapping", "\\Parent\\");
    355355      request.setParameterValue("usedQuantityColumnMapping", "\\Used quantity\\");
     
    358358    {
    359359      request.setParameterValue("tagColumnMapping", "\\Label\\");
     360      request.setParameterValue("parentTypeColumnMapping", "EXTRACT");
    360361      request.setParameterValue("subtypeColumnMapping", "Labeled extract");
    361       request.setParameterValue("pooledColumnMapping", "1");
    362362    }
    363363    if (itemType == Item.PHYSICALBIOASSAY)
  • trunk/src/test/data/test.batchimport.extracts.txt

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

    r4423 r5667  
    1 Name  Label Description External ID Pooled  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
     2Labeled 1.1 cy3 cy3 labeled from ext.1.1  lbl.1.1 Extract 1.1 50  2008-01-01  200 Labeling
     3Labeled 1.2 cy5 cy5 labeled from ext.1.1  lbl.1.2 Extract 1.1 50  2008-01-01  200 Labeling
     4Labeled 2.1 cy3 cy3 labeled from ext.2.1  lbl.2.1 Extract 2.1 50  2008-01-01  200 Labeling
     5Labeled 2.2 cy5 cy5 labeled from ext.2.1  lbl.2.2 Extract 2.1 50  2008-01-01  200 Labeling
    66Labeled X Biotin  A labeled extract with no parent or other info
    7 Pooled labeled 1    A pool of 1.1 and 2.1 lbl.pooled.1  1 Labeled 1.1 100 2008-01-02  200 Pooling
     7Pooled labeled 1    A pool of 1.1 and 2.1 lbl.pooled.1  Labeled 1.1 100 2008-01-02  200 Pooling
    88Pooled labeled 1          Labeled 2.1 100
    9 Pooled labeled 2    A pool of 1.2 and 2.2 lbl.pooled.2  1 Labeled 1.2 100 2008-01-02  200 Pooling
     9Pooled labeled 2    A pool of 1.2 and 2.2 lbl.pooled.2  Labeled 1.2 100 2008-01-02  200 Pooling
    1010Pooled labeled 2          Labeled 2.2 100
  • trunk/src/test/data/test.batchimport.samples.txt

    r5249 r5667  
    1 Name  Description External ID Pooled  Parent  Used quantity Created Original quantity Protocol
     1Name  Description External ID Parent type Parent  Used quantity Created Original quantity Protocol
    22Sample 1.1  First sample from bs.1  smp.1.1   Biosource 1   2008-01-01  200 Sampling.id
    33Sample 2.1  Second sample from bs.1 smp.2.1   Biosource 2   2008-01-01  350 Sampling
    44Sample X  A sample with no parent or other info
    5 Pooled sample A pool of 1.1 and 2.1 smp.pooled  1 Sample 1.1  50  2008-01-02  150 Pooling
     5Pooled sample A pool of 1.1 and 2.1 smp.pooled  SAMPLE  Sample 1.1  50  2008-01-02  150 Pooling
    66Pooled sample       Sample 2.1  100
  • trunk/www/biomaterials/extracts/list_extracts.jsp

    r5666 r5667  
    353353      />
    354354      <tbl:columndef
     355        id="tag"
     356        property="tag.name"
     357        datatype="string"
     358        title="Tag"
     359        sortable="true"
     360        filterable="true"
     361        exportable="true"
     362      />
     363      <tbl:columndef
    355364        id="protocol"
    356365        property="creationEvent.protocol"
     
    386395      <%
    387396      Enumeration<String, String> parentTypes = new Enumeration<String, String>();
     397      parentTypes.add("", "-none-");
    388398      parentTypes.add(Integer.toString(Item.SAMPLE.getValue()), Item.SAMPLE.toString());
    389399      parentTypes.add(Integer.toString(Item.EXTRACT.getValue()), Item.EXTRACT.toString());
     
    734744                <tbl:cell column="originalQuantity"><%=Values.formatNumber(item.getOriginalQuantity(), 2)%></tbl:cell>
    735745                <tbl:cell column="remainingQuantity"><%=Values.formatNumber(item.getRemainingQuantity(), 2)%></tbl:cell>
     746                <tbl:cell column="tag"
     747                  ><base:propertyvalue
     748                    item="<%=item%>"
     749                    property="tag"
     750                    enableEditLink="<%=mode.hasEditLink()%>"
     751                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
     752                  /></tbl:cell>
    736753                <tbl:cell column="protocol"
    737754                  ><base:propertyvalue
  • trunk/www/biomaterials/extracts/view_extract.jsp

    r5664 r5667  
    326326        <td class="prompt">Registered</td>
    327327        <td><%=dateFormatter.format(creationEvent.getEntryDate())%></td>
     328      </tr>
     329      <tr>
     330        <td class="prompt">Tag</td>
     331        <td><base:propertyvalue item="<%=extract%>" property="tag"/></td>
    328332      </tr>
    329333      <tr>
  • trunk/www/biomaterials/samples/list_samples.jsp

    r5666 r5667  
    384384      <%
    385385      Enumeration<String, String> parentTypes = new Enumeration<String, String>();
     386      parentTypes.add("", "-none-");
    386387      parentTypes.add(Integer.toString(Item.BIOSOURCE.getValue()), Item.BIOSOURCE.toString());
    387388      parentTypes.add(Integer.toString(Item.SAMPLE.getValue()), Item.SAMPLE.toString());
Note: See TracChangeset for help on using the changeset viewer.