From e0bd902121f74aeaf6f217be3cd0cb727ac8896f Mon Sep 17 00:00:00 2001
From: tpylak <tpylak>
Date: Tue, 1 Mar 2011 09:21:31 +0000
Subject: [PATCH] minor: example dropbox for importing hcs images and creating
 sample and experiment on the fly

SVN: 20161
---
 .../data-set-handler.py                       | 119 ++++++++++++++++++
 .../jython-flexible-images/example-images.zip | Bin 0 -> 10429 bytes
 2 files changed, 119 insertions(+)
 create mode 100755 screening/etc/example-dropbox-configuration/jython-flexible-images/data-set-handler.py
 create mode 100644 screening/etc/example-dropbox-configuration/jython-flexible-images/example-images.zip

diff --git a/screening/etc/example-dropbox-configuration/jython-flexible-images/data-set-handler.py b/screening/etc/example-dropbox-configuration/jython-flexible-images/data-set-handler.py
new file mode 100755
index 00000000000..dcd2d013cfb
--- /dev/null
+++ b/screening/etc/example-dropbox-configuration/jython-flexible-images/data-set-handler.py
@@ -0,0 +1,119 @@
+#! /usr/bin/env python
+# This is an example Jython dropbox for importing HCS image datasets
+
+import os
+from ch.systemsx.cisd.openbis.dss.etl.dto.api.v1 import *
+from ch.systemsx.cisd.openbis.plugin.screening.shared.api.v1.dto import Geometry
+
+    
+class ImageDataSetFlexible(SimpleImageDataConfig):
+    """
+    Extracts tile number, channel code and well code for a given relative path to an image.
+    Will be called for each file found in the incoming directory which has the allowed image extension.
+      
+    Example file name: bDZ01-1A_wD17_s3_z123_t321_cGFP
+    Returns:
+        ImageMetadata
+    """
+    def extractImageMetadata(self, imagePath):
+        image_tokens = ImageMetadata()
+    
+        basename = os.path.splitext(imagePath)[0]
+        # 
+        token_dict = {}
+        for token in basename.split("_"):
+            token_dict[token[:1]] = token[1:]
+        
+        image_tokens.well = token_dict["w"]
+        fieldText = token_dict["s"]
+        try:
+            image_tokens.tileNumber = int(fieldText)
+        except ValueError:
+            raise Exception("Cannot parse field number from '" + fieldText + "' in '" + basename + "' file name.")
+    
+        image_tokens.channelCode = token_dict["c"]
+        return image_tokens
+
+    """
+    Overrides the default implementation which returns (1, maxTileNumber) geometry.
+    
+    Calculates the width and height of the matrix of tiles (a.k.a. fields or sides) in the well.
+    
+    Parameter imageMetadataList: a list of metadata for each encountered image
+    Parameter maxTileNumber: the biggest tile number among all encountered images
+    Returns:
+        Geometry
+    """
+    def getTileGeometry(self, imageTokens, maxTileNumber):
+        return Geometry.createFromRowColDimensions(maxTileNumber / 3, 3);
+    
+    """
+    Overrides the default implementation which does the same thing (to demonstrate how this can be done). 
+    
+    For a given tile number and tiles geometry returns (x,y) which describes where the tile is
+    located on the well.
+    
+    Parameter tileNumber: number of the tile
+    Parameter tileGeometry: the geometry of the well matrix
+    Returns:
+         Location
+    """
+    def getTileCoordinates(self, tileNumber, tileGeometry):
+        columns = tileGeometry.getWidth()
+        row = ((tileNumber - 1) / columns) + 1
+        col = ((tileNumber - 1) % columns) + 1
+        return Location(row, col)
+
+""" sample type code of the plate, needed if a new sample is registered automatically """
+PLATE_TYPE_CODE = "PLATE"
+SIRNA_EXP_TYPE = "SIRNA_HCS"
+DEFAULT_SPACE = "TEST"
+""" project and experiment where new plates will be registered """
+DEFAULT_PROJECT_CODE = "TEST-PROJECT"
+DEFAULT_EXPERIMENT_CODE = "E1"
+
+PLATE_GEOMETRY_PROPERTY_CODE = "$PLATE_GEOMETRY"
+PLATE_GEOMETRY = "384_WELLS_16X24"
+
+if incoming.isDirectory(): 
+    tokens = incoming.getName().split(".")
+    if len(tokens) < 2:
+        print "Invalid name:", incoming.getName()
+        exit
+    plateCode = tokens[0]
+    experimentCode = tokens[1]
+    
+    config = ImageDataSetFlexible()
+    config.setRawImageDatasetType()
+    config.setPlate(DEFAULT_SPACE, plateCode)
+    #factory.registerImageDataset(config, incoming, service)
+    imageRegistrationDetails = factory.createImageRegistrationDetails(config, incoming)
+
+    tr = service.transaction(incoming, factory)
+    
+    sampleIdentifier = "/"+DEFAULT_SPACE+"/"+plateCode
+    plate = tr.getSample(sampleIdentifier)
+    if plate == None:
+        expIdentifier = "/"+DEFAULT_SPACE+"/"+DEFAULT_PROJECT_CODE+"/"+experimentCode
+        #expIdentifier = "/"+DEFAULT_SPACE+"/"+DEFAULT_PROJECT_CODE+"/"+DEFAULT_EXPERIMENT_CODE
+        experiment = tr.getExperiment(expIdentifier)
+        if experiment == None:
+            experiment = tr.createNewExperiment(expIdentifier)
+            experiment.setType(SIRNA_EXP_TYPE)
+            experiment.setPropertyValue("MICROSCOPE", "BD_PATHWAY_855")
+            experiment.setPropertyValue("DESCRIPTION", "koko")
+
+        plate = tr.createNewSample(sampleIdentifier)
+        plate.setType(PLATE_TYPE_CODE)
+        plate.setPropertyValue(PLATE_GEOMETRY_PROPERTY_CODE, PLATE_GEOMETRY)
+        plate.setExperiment(experiment)
+        tr.commit()
+        tr = service.transaction(incoming, factory)
+    
+    imageDataset = tr.createNewDataSet(imageRegistrationDetails)
+    imageDataset.setSample(plate)
+    imageDataSetFolder = tr.moveFile(incoming.getPath(), imageDataset)
+    imageDatasetCode = imageDataset.getDataSetCode()
+    print "Registered dataset:", imageDatasetCode
+    tr.commit()
+
diff --git a/screening/etc/example-dropbox-configuration/jython-flexible-images/example-images.zip b/screening/etc/example-dropbox-configuration/jython-flexible-images/example-images.zip
new file mode 100644
index 0000000000000000000000000000000000000000..cb8a851aaf6029592ae5a69de5cbc32d236fc488
GIT binary patch
literal 10429
zcmWIWW@h1HVBp|jIG>|!#{dLOAOZ-4fY`TEH^9d+#MMa8H&WL%BEU$WnIQnK!>>l&
z?zdtuLp4yPK2W(4Rvk%T6LkH<T!VZZBZK419S!4?on3u=;)@OS3i8rl^L!|N{&do#
zq=bYAU%wP^0_h}%L_RZxuS*}D(r05km_JXiPf@fdUthwAiIrdX$E*3L=iPrep<+Sf
z#F@SBhZGX07@m?y?J;tbT-+0QOd}bC`$U5OiRuhH0|O&t-x<dkSmv#((|bKfXcm%J
z{3-Q{(V+6m{nx5$N{kE)#*$>jiZL->>5PZQO1?#vB|Fy+xsuM68k3Fn9*8}!)-*Z(
z=DpVME`EFMoOfsYx2Hc82q?&~Sa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