Class RawDataBatcher

All Implemented Interfaces:
AutoCloseable, AccessControlled, Batcher

public class RawDataBatcher extends BasicBatcher<RawData>
Batcher class for raw data. A single instance can be used for raw data belonging to a single RawBioAssay. If the raw bioassay is connected to an array design with features the raw data is verified against the features before it is inserted as follows:
  • Find the feature located at the same coordinates as given by the row, column and block or row, column, metaGridX and metaGridY. A block number of zero signals that meta coordinates should be used. All other values use block coordinates.
  • If a feature isn't found, an ItemNotFoundException is thrown
  • If you have specified to verify the external reporter id by using the insert(RawData, String, String) method the external reporter id of the feature is checked against the supplied reporter id. If they don't match an InvalidDataException is thrown.
  • Finally, the position and reporter is copied from the feature to the raw data. Note that any reporter you have set on the raw data yourself is overwritten and never used.

Note that if the raw bioassay isn't connected to an array design no checks are made and none of the above apply. The major difference is that you must alsways set a reporter youself in this case. We recommend that you use the insert(RawData) method if no array design is connected, and the insert(RawData, String, String) method otherwise.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2017-05-22 14:35:27 +0200 (må, 22 maj 2017) $
  • Field Details

    • logSql

      private static final org.slf4j.Logger logSql
      Log all SQL statements.
    • debugSqlEnabled

      private static final boolean debugSqlEnabled
      So we don't always have to call logSql.debug()
    • rawBioAssay

      private final RawBioAssay rawBioAssay
      The raw bioassay this batcher adds raw data to.
    • rawBioAssayData

      private final RawBioAssayData rawBioAssayData
      Just a copy of the data object for the raw bioassay.
    • rawDataType

      private final RawDataType rawDataType
      The type of raw data to batch.
    • arrayDesign

      private final ArrayDesignData arrayDesign
      The array design the raw bioassay is connected to, if any.
    • caseInsensitive

      private final boolean caseInsensitive
      If case should be ignored when comparing strings (external ID)
    • currentPosition

      private int currentPosition
      Keeps track of the position number unless the raw bioassay is connected to an array design with features.
    • bytes

      private long bytes
      The number of bytes the spot data is occupying on disk. This value is calculated by the validate method for each spot and added to the raw bioassay by the close method.
    • findReporter

      private Query<ReporterData> findReporter
      A query to find reporters by the external id.
    • fiMethod

      private FeatureIdentificationMethod fiMethod
      The method to use for identifying features.
    • preloaded

      Holds info about the features of an array design. Using the feature identifier we can look up position number and reporter on each location and verify this against the raw data.
      See Also:
    • reporterProxy

      private RawDataBatcher.ReporterProxy reporterProxy
    • featureProxy

      private RawDataBatcher.FeatureProxy featureProxy
    • usedFeatures

      private Set<Object> usedFeatures
      Keep track of the used features to make sure that no more than raw data spot references the same feature.
    • useNullIfReporterNotFound

      private boolean useNullIfReporterNotFound
      If we should use the null reporter if a reporter isn't found.
    • numReportersNotFound

      private int numReportersNotFound
      The number of reporters that was not found.
    • skipInsertIfMissingFeature

      private boolean skipInsertIfMissingFeature
      If inserts that can't find a matching feature should be skipped or generate an error.
    • numSkippedMissingFeature

      private int numSkippedMissingFeature
      The number of skipped inserts due to missing feature
    • acceptInsertIfNullReporterOnFeature

      private boolean acceptInsertIfNullReporterOnFeature
      If we should always accept inserts when the feature has a NULL reporter.
    • numAcceptedWithNullReporterOnFeature

      private int numAcceptedWithNullReporterOnFeature
      The number of accepted inserts were the feature had a NULL reporter
  • Constructor Details

  • Method Details

    • getNew

      static RawDataBatcher getNew(DbControl dc, RawBioAssay rawBioAssay, FeatureIdentificationMethod fiMethod) throws BaseException
      Create a new batcher for raw data.
      Parameters:
      dc - The DbControl to use for database access and permission checking
      rawBioAssay - The raw bioassay this batcher should add raw data to
      fiMethod - The method to use for identifying features, use null to use the method specified by the array design
      Throws:
      BaseException - If there is an error
      See Also:
    • getType

      public Item getType()
      Description copied from class: BasicBatcher
      Get the type of item supported by the batcher. The returned value is one of the values defined in the Item enumeration.
      Specified by:
      getType in class BasicBatcher<RawData>
      Returns:
      A value indicating the type of item
      See Also:
    • validate

      public void validate(RawData data) throws InvalidDataException
      Validate all properties for the raw data object:
      • The data object is not null
      • The data object belongs to the correct raw bioassay
      • The position value is > 0
      • All of the extra properties using the ExtendedProperty.validateValue(Object) method
      Specified by:
      validate in class BasicBatcher<RawData>
      Parameters:
      data - Data object to validate
      Throws:
      InvalidDataException - If the data object is invalid
    • insert

      public void insert(RawData data) throws BaseException
      Description copied from class: BasicBatcher
      Insert a data object. The data object will not be synchronized with the database. The object values may be modified.
      Overrides:
      insert in class BasicBatcher<RawData>
      Parameters:
      data - Data object to be inserted
      Throws:
      InvalidDataException - If the data is null or it doesn't validate against the BasicBatcher.validate(BatchableData) method
      PermissionDeniedException - If the logged in user doesn't have create permission
      BaseException - If there is another error
    • update

      public void update(RawData data) throws BaseException
      Always throws a PermissionDeniedException, since raw data cannot be modifed once it has been created.
      Overrides:
      update in class BasicBatcher<RawData>
      Parameters:
      data - Data object to be updated
      Throws:
      InvalidDataException - If the data is null or it doesn't validate against the BasicBatcher.validate(BatchableData) method
      PermissionDeniedException - If the logged in user doesn't have write permission
      BaseException - If there is another error
    • delete

      public void delete(int id) throws BaseException
      Always throws a PermissionDeniedException, since raw data cannot be modifed once it has been created, except if all spots are deleted at the same time.
      Overrides:
      delete in class BasicBatcher<RawData>
      Parameters:
      id - Id of the object to be deleted
      Throws:
      PermissionDeniedException - If the logged in user doesn't have delete permission
      BaseException - If there is another error
      See Also:
    • initPermissions

      void initPermissions(int granted, int denied) throws BaseException
      Grant read permission if the logged in user has read permission to the raw bioassay. Grant write, delete and create permission if the logged in user has write permission to the raw bioassay.
      Overrides:
      initPermissions in class BasicBatcher<RawData>
      Parameters:
      granted - Permissions that have been granted by the subclass
      denied - Permissions that have been denied by the subclass
      Throws:
      BaseException - If the permissions couldn't be initialised
    • getPluginPermissions

      PluginPermission getPluginPermissions()
      Overrides:
      getPluginPermissions in class BasicBatcher<RawData>
    • onBeforeClose

      void onBeforeClose() throws BaseException
      Update the spot count and disk usage on the raw bioassay.
      Overrides:
      onBeforeClose in class BasicBatcher<RawData>
      Throws:
      BaseException
    • useNullIfReporterNotFound

      public void useNullIfReporterNotFound(boolean useNull)
      Specify if the insert method should use a null reporter if a reporter with the given external ID isn't found. This setting only affects raw bioassays that are not connected to an array design.
      Parameters:
      useNull - TRUE if the insert should use a null reporter (default), FALSE otherwise
      See Also:
    • getNumReportersNotFound

      public int getNumReportersNotFound()
      Get the number of reporters that was not found.
      Since:
      2.7
      See Also:
    • skipInsertIfMissingFeature

      public void skipInsertIfMissingFeature(boolean skip)
      Specify if the insert method should skip the insert if a feature for the spot can't be found. This setting only affects raw bioassays that are connected to an array design.
      Parameters:
      skip - TRUE if the insert should be skipped, FALSE to throw an ItemNotFoundException (default)
      Since:
      2.7
      See Also:
    • getNumSkippedMissingFeature

      public int getNumSkippedMissingFeature()
      Get the number of skipped inserts because of a missing feature.
      Since:
      2.7
      See Also:
    • acceptInsertIfNullReporterOnFeature

      public void acceptInsertIfNullReporterOnFeature(boolean accept)
      Specify if inserts always should be accepted if there is a matching feature that has a NULL reporter. This settings only affects raw bioassays that are connected to an array design.

      NOTE! The inserted data will also reference the NULL reporter.

      Parameters:
      accept - TRUE to always accept the insert, FALSE to throw an ItemNotFoundException if the insert doesn't specify a NULL reporter (default)
      Since:
      2.7
    • getNumAcceptedWithNullReporterOnFeature

      public int getNumAcceptedWithNullReporterOnFeature()
      Get the number of accepted inserts because of features with a NULL reporter.
      Since:
      2.7
      See Also:
    • getRawBioAssay

      public RawBioAssay getRawBioAssay()
      Get the raw bioassay this batcher is used for.
    • insert

      public void insert(RawData data, String externalReporterId, String externalFeatureId)
      Insert a raw data spot and verify the external id of the reporter. The external id is only verified if it is not null and the raw bioassay is connected to an array design with features. The external id is verified to match the external id of the reporter attached to feature of the spot's position. If the raw bioassay isn't connected to an array design, the batcher will automatically try to load the reporter with the given external ID. If you use this method you don't have the set the reporter with the RawData.setReporter(ReporterData) method.

      The externalFeatureId is only needed if the FeatureIdentificationMethod.FEATURE_ID identification method is used. The other methods will use properties on the RawData object (postion or the coordinates) to find the feature. Feature identification is of course needed when the raw bioassay is connected to an array design but is also used when there is no array design to validate that duplicate spots are not inserted.

      Parameters:
      data - The raw data to insert
      externalReporterId - The external id of the reporter expected to be found at the feature of this spot, or null to use the reporter attached to the feature
      externalFeatureId - The feature ID of the feature if the FeatureIdentificationMethod.FEATURE_ID identification method is used
      Throws:
      BaseException - If the insertion failed
      Since:
      2.6
    • doInsert

      private void doInsert(RawData data, String externalReporterId, String externalFeatureId, boolean validateReporterId) throws BaseException
      Do the actual insert.
      Throws:
      BaseException
    • preloadFeatures

      private void preloadFeatures()
    • newRawData

      public RawData newRawData() throws BaseException
      Create a new raw data object. After you have set all properties, use one of the insert(RawData) or insert(RawData, String, String) methods to insert the raw data. You do not have to set the reporter if the raw bioassay is connected to an array design.
      Returns:
      A raw data object
      Throws:
      BaseException - If there is an error
    • deleteAll

      void deleteAll() throws BaseException
      Delete all raw data.
      Throws:
      BaseException
      See Also: