Changeset 4097


Ignore:
Timestamp:
Jan 23, 2008, 2:43:49 PM (15 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #900: Verify that multiple raw data spots on the same raw bioassay doesn't reference the same feature

Location:
trunk/src
Files:
8 edited

Legend:

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

    r4083 r4097  
    171171    if (featureIds.contains(featureId))
    172172    {
    173       throw new InvalidDataException("Another feature with the same identifier already exists: " +
     173      throw new ItemAlreadyExistsException("Another feature with the same identifier already exists: " +
    174174        fiMethod.toString() + "=" + featureId);
    175175    }
  • trunk/src/core/net/sf/basedb/core/RawDataBatcher.java

    r4083 r4097  
    3333
    3434import java.util.HashMap;
     35import java.util.HashSet;
    3536import java.util.List;
    3637import java.util.Map;
     38import java.util.Set;
    3739import java.sql.Statement;
    3840import java.sql.SQLException;
     
    162164 
    163165  /**
     166    Keep track of the used features to make sure that no more than raw data spot
     167    references the same feature.
     168  */
     169  private Set<Object> usedFeatures;
     170 
     171  /**
    164172    If we should use the null reporter if a reporter isn't found.
    165173  */
     
    180188    }
    181189
    182     // Use the feature identification method set by the array design if none was given
    183190    this.fiMethod = fim;
    184     if (arrayDesign != null && arrayDesign.getHasFeatures())
    185     {
    186       if (fiMethod == null)
    187       {
     191    if (fiMethod == null || fiMethod == FeatureIdentificationMethod.NONE)
     192    {
     193      if (arrayDesign != null && arrayDesign.getHasFeatures())
     194      {
     195        // Use the feature identification method set by the array design if none was given
    188196        fiMethod = FeatureIdentificationMethod.fromValue(arrayDesign.getFeatureIdentificationMethod());
    189197      }
    190       // As a last resort fallback to the coordinates method
    191       if (fiMethod == null || fiMethod == FeatureIdentificationMethod.NONE)
    192       {
     198      else
     199      {
     200        // Otherwise fallback to the coordinates method
    193201        fiMethod = FeatureIdentificationMethod.COORDINATES;
    194202      }
    195     }
    196     else
    197     {
    198       fiMethod = FeatureIdentificationMethod.NONE;
    199203    }
    200204   
    201205    // Preload features
    202     if (fiMethod != FeatureIdentificationMethod.NONE && rawBioAssay.getNumDbSpots() == 0)
     206    if (arrayDesign != null && arrayDesign.getHasFeatures() && rawBioAssay.getNumDbSpots() == 0)
    203207    {
    204208      org.hibernate.Query query = HibernateUtil.getPredefinedQuery(dc.getStatelessSession(), "COUNT_FEATURES_FOR_ARRAYDESIGN");
     
    238242      this.preloaded = null;
    239243    }
     244    this.usedFeatures = new HashSet<Object>(preloaded == null ? 100 : preloaded.size());
    240245    setDbControl(dc);
    241246  }
     
    414419    {
    415420      if (data.getPosition() == 0) data.setPosition(++currentPosition);
     421      Object featureId = fiMethod.getIdentifier(data, externalFeatureId);
     422      if (!usedFeatures.add(featureId))
     423      {
     424        throw new ItemAlreadyExistsException("Feature[" + fiMethod.toString() + "=" + featureId +
     425          "] has already been used by another spot.");
     426      }
    416427      // If no reporter has been set on the RawData object we try to find the external id
    417428      if (externalReporterId != null && data.getReporter() == null)
     
    434445    {
    435446      Object featureId = fiMethod.getIdentifier(data, externalFeatureId);
     447      if (!usedFeatures.add(featureId))
     448      {
     449        throw new ItemAlreadyExistsException("Feature[" + fiMethod.toString() + "=" + featureId +
     450          "] has already been used by another spot.");
     451      }
    436452      FeatureData f = preloaded.get(featureId);
    437453      if (f == null)
    438454      {
    439         throw new ItemNotFoundException("Feature["+ fiMethod.toString() + "=" + featureId + "]");
     455        throw new ItemNotFoundException("Feature["+ fiMethod.toString() + "=" + featureId + "] doesn't exist on array design");
    440456      }
    441457      ReporterData r = f.getReporter();
  • trunk/src/plugins/core/net/sf/basedb/plugins/RawDataFlatFileImporter.java

    r4083 r4097  
    3737import net.sf.basedb.core.FileType;
    3838import net.sf.basedb.core.Item;
     39import net.sf.basedb.core.ItemAlreadyExistsException;
    3940import net.sf.basedb.core.ItemContext;
    4041import net.sf.basedb.core.ItemNotFoundException;
     
    240241        Arrays.asList( new String[] { "skip", "fail"} ))
    241242    );
     243
     244  protected static final PluginParameter<String> duplicateFeatureErrorParameter = new PluginParameter<String>(
     245    "duplicateFeatureError",
     246    "Duplicate feature",
     247    "How to handle errors that are caused by more than data spot matching the same " +
     248      "feature on the array design. This can for example be caused by invalid block and/or " +
     249      "spot coordinates or using an incorrect feature or reporter ID column. " +
     250      "If not specified the default error handling is used.\n\n"+
     251      "skip = Skip the current data line and continue\n"+
     252      "fail = Stop with an error message",
     253      new StringParameterType(255, null, false, 1, 0, 0,
     254        Arrays.asList( new String[] { "skip", "fail"} ))
     255    );
     256 
    242257 
    243258  public static final String COMMAND_CONFIGURE_PARSER = "config_parser";
     
    475490        storeValue(job, request, missingReporterErrorParameter);
    476491        storeValue(job, request, featureMismatchErrorParameter);
     492        storeValue(job, request, duplicateFeatureErrorParameter);
    477493        storeValue(job, request, stringTooLongErrorParameter);
    478494        storeValue(job, request, invalidUseOfNullErrorParameter);
     
    567583      }
    568584    }
     585    // Error handling for "duplicate feature"
     586    String method = (String)job.getValue("duplicateFeatureError");
     587    if (method != null)
     588    {
     589      addErrorHandler(ItemAlreadyExistsException.class, new SimpleErrorHandler("skip".equals(method)));
     590    }
     591
    569592  }
    570593
     
    843866        parameters.add(featureMismatchErrorParameter);
    844867      }
     868      parameters.add(duplicateFeatureErrorParameter);
    845869      parameters.add(stringTooLongErrorParameter);
    846870      parameters.add(invalidUseOfNullErrorParameter);
  • trunk/src/plugins/core/net/sf/basedb/plugins/ReporterMapFlatFileImporter.java

    r4083 r4097  
    4141import net.sf.basedb.core.InvalidDataException;
    4242import net.sf.basedb.core.InvalidUseOfNullException;
     43import net.sf.basedb.core.ItemAlreadyExistsException;
    4344import net.sf.basedb.core.ItemContext;
    4445import net.sf.basedb.core.ItemNotFoundException;
     
    218219      new StringParameterType(255, null, false, 1, 0, 0,
    219220          Arrays.asList( new String[] { "null", "skip", "fail"} ))
     221    );
     222 
     223  protected static final PluginParameter<String> duplicateFeatureErrorParameter = new PluginParameter<String>(
     224    "duplicateFeatureError",
     225    "Duplicate feature",
     226    "How to handle errors that are caused by more than one feature having the same " +
     227      "identifier. If not specified the default error handling is used.\n\n" +
     228      "skip = Skip the current data line and continue\n"+
     229      "fail = Stop with an error message",
     230      new StringParameterType(255, null, false, 1, 0, 0,
     231          Arrays.asList( new String[] {"skip", "fail"} ))
    220232    );
    221233
     
    464476        storeValue(job, request, defaultErrorParameter);
    465477        storeValue(job, request, missingReporterErrorParameter);
     478        storeValue(job, request, duplicateFeatureErrorParameter);
    466479        storeValue(job, request, invalidUseOfNullErrorParameter);
    467480        storeValue(job, request, numberFormatErrorParameter);
     
    509522    reporterBatcher = ReporterBatcher.getNew(dc);
    510523    this.ffp = ffp;
     524    // Error handling for "missing reporter"
    511525    String method = (String)job.getValue("missingReporterError");
    512526    errorIfNotFound = !"null".equals(method);
     
    514528    {
    515529      addErrorHandler(ItemNotFoundException.class, new SimpleErrorHandler("skip".equals(method)));
     530    }
     531    // Error handling for "duplicate feature"
     532    method = (String)job.getValue("duplicateFeatureError");
     533    if (method != null)
     534    {
     535      addErrorHandler(ItemAlreadyExistsException.class, new SimpleErrorHandler("skip".equals(method)));
    516536    }
    517537    if (job.getValue("file") != null)
     
    692712      parameters.add(defaultErrorParameter);
    693713      parameters.add(missingReporterErrorParameter);
     714      parameters.add(duplicateFeatureErrorParameter);
    694715      parameters.add(invalidUseOfNullErrorParameter);
    695716      parameters.add(numberFormatErrorParameter);
  • trunk/src/test/TestArrayDesign.java

    r4093 r4097  
    3636import net.sf.basedb.core.DataFileType;
    3737import net.sf.basedb.core.Item;
     38import net.sf.basedb.core.ItemAlreadyExistsException;
    3839import net.sf.basedb.core.Permission;
    3940import net.sf.basedb.core.ItemQuery;
     
    583584        featureData.setColumn(Integer.valueOf(parsedData.get(colCol)));
    584585
    585         featureBatcher.insert(featureData);
    586         i++;
     586        try
     587        {
     588          featureBatcher.insert(featureData);
     589          i++;
     590        }
     591        catch (ItemAlreadyExistsException ex)
     592        {
     593          // Ignore duplicate features
     594        }
    587595      }
    588596      dc.commit();
  • trunk/src/test/TestRawBioAssay.java

    r4093 r4097  
    509509        extraData.put("ch2PercSat", Integer.valueOf(parsedData.get(25)));
    510510
    511         rawDataBatcher.insert(rawData);
    512         i++;
     511        try
     512        {
     513          rawDataBatcher.insert(rawData);
     514          i++;
     515        }
     516        catch (ItemAlreadyExistsException ex)
     517        {
     518          // Ignore duplicate features
     519        }
    513520      }
    514521      dc.commit();
  • trunk/src/test/TestRawDataFlatFileImporter.java

    r3820 r4097  
    190190      request.setParameterValue("numberFormatError", "null");
    191191      request.setParameterValue("decimalSeparator", "dot");
     192      request.setParameterValue("duplicateFeatureError", "skip");
    192193
    193194      PluginResponse response = request.invoke();
  • trunk/src/test/data/test.rawdata.import.txt

    r2959 r4097  
    6076071 23  24  "EST" "1629538" 6085  6020  130 452 453 57  331 335 23  95  91  0 503 503 74  306 311 18  99  97  0 1.628 1.615 1.660 1.710 1.899 1.615 0.701 540 2091  318 319 0.703 121 197 122 197 244644  271708  5.130 10.667  0 0
    6086081 24  24  "2580289" "B-actin_1/4" 6255  6025  135 1011  1161  391 334 373 434 92  32  0 1506  1743  707 312 383 660 94  42  0 1.764 1.730 1.725 1.707 1.210 1.762 0.962 540 2289  1871  2258  0.819 677 1194  827 1431  627065  941279  1.816 2.061 0 0
     6091 1 1 "2580289" "B-actin_1/4" 2040  1730  135 887 1003  360 320 324 23  100 100 0 1138  1376  592 302 305 11  100 100 0 1.474 1.572 1.568 1.562 1.239 1.614 0.955 540 2328  1403  1757  0.560 567 836 683 1074  541800  743047  29.522  97.364  0 0
Note: See TracChangeset for help on using the changeset viewer.